Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-2015 Eyeo GmbH | |
4 * | |
5 * Adblock Plus is free software: you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License version 3 as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * Adblock Plus is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
16 */ | |
17 | |
1 /* | 18 /* |
2 * http://msdn.microsoft.com/en-us/library/bb250436.aspx | 19 * http://msdn.microsoft.com/en-us/library/bb250436.aspx |
3 */ | 20 */ |
4 | 21 |
5 #ifndef _PLUGIN_CLASS_H_ | 22 #ifndef _PLUGIN_CLASS_H_ |
6 #define _PLUGIN_CLASS_H_ | 23 #define _PLUGIN_CLASS_H_ |
7 | 24 |
8 | 25 |
9 #include "PluginTypedef.h" | |
10 #include "Plugin.h" | 26 #include "Plugin.h" |
11 #include "PluginTab.h" | 27 #include "PluginTabBase.h" |
12 #define _CRTDBG_MAP_ALLOC | 28 #define _CRTDBG_MAP_ALLOC |
13 #include <stdlib.h> | 29 #include <stdlib.h> |
14 #include <crtdbg.h> | 30 #include <crtdbg.h> |
15 #include <set> | 31 #include <set> |
16 | 32 |
17 #include "NotificationMessage.h" | 33 #include "NotificationMessage.h" |
18 | 34 |
19 #define ICON_PLUGIN_DISABLED 0 | 35 #define ICON_PLUGIN_DISABLED 0 |
20 #define ICON_PLUGIN_ENABLED 1 | 36 #define ICON_PLUGIN_ENABLED 1 |
21 #define ICON_PLUGIN_DEACTIVATED 2 | 37 #define ICON_PLUGIN_DEACTIVATED 2 |
22 #define ICON_MAX 3 | 38 #define ICON_MAX 3 |
23 | 39 |
24 #define WM_LAUNCH_INFO (WM_APP + 10) | 40 #define WM_LAUNCH_INFO (WM_APP + 10) |
25 #define WM_WHITELIST_DOMAIN (WM_LAUNCH_INFO + 1) | |
26 | 41 |
27 class CPluginMimeFilterClient; | 42 class CPluginMimeFilterClient; |
28 | 43 |
29 | 44 |
30 class ATL_NO_VTABLE CPluginClass : | 45 class ATL_NO_VTABLE CPluginClass : |
31 public ATL::CComObjectRootEx<ATL::CComMultiThreadModel>, | 46 public ATL::CComObjectRootEx<ATL::CComMultiThreadModel>, |
32 public ATL::CComCoClass<CPluginClass, &CLSID_PluginClass>, | 47 public ATL::CComCoClass<CPluginClass, &CLSID_PluginClass>, |
33 public ATL::IObjectWithSiteImpl<CPluginClass>, | 48 public ATL::IObjectWithSiteImpl<CPluginClass>, |
34 public IOleCommandTarget, | 49 public IOleCommandTarget, |
35 public ATL::IDispEventImpl<1, CPluginClass, &DIID_DWebBrowserEvents2, &LIBID_S HDocVw, 1, 1> | 50 public ATL::IDispEventImpl<1, CPluginClass, &DIID_DWebBrowserEvents2, &LIBID_S HDocVw, 1, 1> |
Eric
2014/12/31 17:03:15
From http://msdn.microsoft.com/en-us/library/d7eec
Oleksandr
2015/01/09 00:02:17
For reference: discussion on this moved to the com
| |
36 { | 51 { |
37 | 52 |
38 friend class CPluginTab; | 53 friend class CPluginTab; |
39 | 54 |
40 private: | 55 private: |
41 | 56 |
42 CPluginTab* m_tab; | 57 CPluginTab* m_tab; |
43 | 58 |
44 public: | 59 public: |
45 | 60 |
46 DECLARE_REGISTRY_RESOURCEID(IDR_PLUGIN_CLASS) | 61 DECLARE_REGISTRY_RESOURCEID(IDR_PLUGIN_CLASS) |
47 | 62 |
48 DECLARE_PROTECT_FINAL_CONSTRUCT() | 63 DECLARE_PROTECT_FINAL_CONSTRUCT() |
49 | 64 |
50 BEGIN_COM_MAP(CPluginClass) | 65 BEGIN_COM_MAP(CPluginClass) |
51 COM_INTERFACE_ENTRY(IObjectWithSite) | 66 COM_INTERFACE_ENTRY(IObjectWithSite) |
52 COM_INTERFACE_ENTRY(IOleCommandTarget) | 67 COM_INTERFACE_ENTRY(IOleCommandTarget) |
53 END_COM_MAP() | 68 END_COM_MAP() |
54 | 69 |
55 BEGIN_SINK_MAP(CPluginClass) | 70 BEGIN_SINK_MAP(CPluginClass) |
56 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, OnBeforeNa vigate2) | 71 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, OnBeforeNa vigate2) |
57 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOWNLOADBEGIN, OnDownloadBe gin) | |
58 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOWNLOADCOMPLETE, OnDownloa dComplete) | 72 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOWNLOADCOMPLETE, OnDownloa dComplete) |
59 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, OnDocumen tComplete) | 73 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, OnDocumen tComplete) |
60 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_WINDOWSTATECHANGED, OnWindo wStateChanged) | 74 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_WINDOWSTATECHANGED, OnWindo wStateChanged) |
61 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_COMMANDSTATECHANGE, OnComma ndStateChange) | 75 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_COMMANDSTATECHANGE, OnComma ndStateChange) |
62 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_ONQUIT, Unadvice) | 76 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_ONQUIT, OnOnQuit) |
63 END_SINK_MAP() | 77 END_SINK_MAP() |
64 | 78 |
65 CPluginClass(); | 79 CPluginClass(); |
66 ~CPluginClass(); | 80 ~CPluginClass(); |
67 | 81 |
68 HRESULT FinalConstruct(); | 82 HRESULT FinalConstruct(); |
69 void FinalRelease(); | 83 void FinalRelease(); |
70 | 84 |
71 // IObjectWithSite | 85 // IObjectWithSite |
72 | 86 |
73 STDMETHOD(SetSite)(IUnknown *pUnkSite); | 87 STDMETHOD(SetSite)(IUnknown *pUnkSite); |
74 | 88 |
75 // IOleCommandTarget | 89 // IOleCommandTarget |
76 | 90 |
77 STDMETHOD(QueryStatus)(const GUID* pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[ ], OLECMDTEXT* pCmdText); | 91 STDMETHOD(QueryStatus)(const GUID* pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[ ], OLECMDTEXT* pCmdText); |
78 STDMETHOD(Exec)(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, VARIANTARG* pva Out); | 92 STDMETHOD(Exec)(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, VARIANTARG* pva Out); |
79 | 93 |
80 | 94 |
81 static CPluginTab* GetTab(DWORD dwThreadId); | 95 static CPluginTab* GetTab(DWORD dwThreadId); |
82 CPluginTab* GetTab(); | 96 CPluginTab* GetTab(); |
83 | 97 |
84 void UpdateStatusBar(); | 98 void UpdateStatusBar(); |
85 static DWORD WINAPI MainThreadProc(LPVOID pParam); | 99 static DWORD WINAPI MainThreadProc(LPVOID pParam); |
86 | 100 |
87 private: | 101 private: |
88 | 102 |
89 bool SetMenuBar(HMENU hMenu, const CString& url); | 103 bool SetMenuBar(HMENU hMenu, const std::wstring& url); |
90 HMENU CreatePluginMenu(const CString& url); | 104 HMENU CreatePluginMenu(const std::wstring& url); |
91 | 105 |
92 void DisplayPluginMenu(HMENU hMenu, int nToolbarCmdID, POINT pt, UINT nMenuFla gs); | 106 void DisplayPluginMenu(HMENU hMenu, int nToolbarCmdID, POINT pt, UINT nMenuFla gs); |
93 bool CreateStatusBarPane(); | 107 bool CreateStatusBarPane(); |
94 | 108 |
95 public: | 109 public: |
96 HWND GetBrowserHWND() const; | 110 HWND GetBrowserHWND() const; |
97 HWND GetTabHWND() const; | 111 HWND GetTabHWND() const; |
98 CComQIPtr<IWebBrowser2> GetBrowser() const; | 112 CComQIPtr<IWebBrowser2> GetBrowser() const; |
99 | 113 |
100 | 114 |
101 static CPluginMimeFilterClient* s_mimeFilter; | 115 static CPluginMimeFilterClient* s_mimeFilter; |
102 | 116 |
103 private: | 117 private: |
104 | 118 |
105 CString GetBrowserUrl() const; | 119 std::wstring GetBrowserUrl() const; |
106 | |
107 | 120 |
108 static DWORD WINAPI StartInitObject(LPVOID thisPtr); | 121 static DWORD WINAPI StartInitObject(LPVOID thisPtr); |
109 bool InitObject(bool bBHO); | 122 bool InitObject(bool bBHO); |
110 void CloseTheme(); | 123 void CloseTheme(); |
111 void UpdateTheme(); | 124 void UpdateTheme(); |
112 | 125 |
113 static HICON GetStatusBarIcon(const CString& url); | 126 static HICON GetStatusBarIcon(const std::wstring& url); |
114 static CPluginClass* FindInstance(HWND hStatusBarWnd); | 127 static CPluginClass* FindInstance(HWND hStatusBarWnd); |
115 static LRESULT CALLBACK NewStatusProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); | 128 static LRESULT CALLBACK NewStatusProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); |
116 static LRESULT CALLBACK PaneWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); | 129 static LRESULT CALLBACK PaneWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); |
117 static void FirstRunThread(); | 130 static void FirstRunThread(); |
118 | 131 |
119 void STDMETHODCALLTYPE OnBeforeNavigate2(/* [in] */ IDispatch* pDisp, | 132 void STDMETHODCALLTYPE OnBeforeNavigate2(/* [in] */ IDispatch* pDisp, |
120 /* [in] */ VARIANT* URL, | 133 /* [in] */ VARIANT* URL, |
121 /* [in] */ VARIANT* Flags, | 134 /* [in] */ VARIANT* Flags, |
122 /* [in] */ VARIANT* TargetFrameName, | 135 /* [in] */ VARIANT* TargetFrameName, |
123 /* [in] */ VARIANT* PostData, | 136 /* [in] */ VARIANT* PostData, |
124 /* [in] */ VARIANT* Headers, | 137 /* [in] */ VARIANT* Headers, |
125 /* [in, out] */ VARIANT_BOOL* Cancel); | 138 /* [in, out] */ VARIANT_BOOL* Cancel); |
126 void STDMETHODCALLTYPE OnDownloadBegin(); | |
127 void STDMETHODCALLTYPE OnDownloadComplete(); | 139 void STDMETHODCALLTYPE OnDownloadComplete(); |
128 void STDMETHODCALLTYPE OnDocumentComplete(IDispatch* frameBrowserDisp, VARIANT * /*urlOrPidl*/); | 140 void STDMETHODCALLTYPE OnDocumentComplete(IDispatch* frameBrowserDisp, VARIANT * /*urlOrPidl*/); |
129 void STDMETHODCALLTYPE OnWindowStateChanged(unsigned long flags, unsigned long validFlagsMask); | 141 void STDMETHODCALLTYPE OnWindowStateChanged(unsigned long flags, unsigned long validFlagsMask); |
130 void STDMETHODCALLTYPE OnCommandStateChange(long command, VARIANT_BOOL enable) ; | 142 void STDMETHODCALLTYPE OnCommandStateChange(long command, VARIANT_BOOL enable) ; |
131 // OnOnQuit | 143 void STDMETHODCALLTYPE OnOnQuit(); |
132 void STDMETHODCALLTYPE Unadvice(); | 144 void Unadvise(); |
133 | 145 |
134 void ShowStatusBar(); | 146 void ShowStatusBar(); |
135 bool IsStatusBarEnabled(); | 147 bool IsStatusBarEnabled(); |
136 | 148 |
137 public: | 149 public: |
138 CComQIPtr<IWebBrowser2> m_webBrowser2; | 150 CComQIPtr<IWebBrowser2> m_webBrowser2; |
139 private: | 151 private: |
140 HWND m_hBrowserWnd; | 152 HWND m_hBrowserWnd; |
141 HWND m_hTabWnd; | 153 HWND m_hTabWnd; |
142 HWND m_hStatusBarWnd; | 154 HWND m_hStatusBarWnd; |
143 HWND m_hPaneWnd; | 155 HWND m_hPaneWnd; |
144 | 156 |
145 WNDPROC m_pWndProcStatus; | 157 WNDPROC m_pWndProcStatus; |
146 int m_nPaneWidth; | 158 int m_nPaneWidth; |
147 HANDLE m_hTheme; | 159 HANDLE m_hTheme; |
148 | 160 |
149 CriticalSection m_csStatusBar; | 161 CriticalSection m_csStatusBar; |
150 | 162 |
151 NotificationMessage notificationMessage; | 163 NotificationMessage notificationMessage; |
152 | 164 |
153 bool m_isAdviced; | 165 bool m_isAdvised; |
154 bool m_isInitializedOk; | 166 bool m_isInitializedOk; |
155 | 167 |
156 // Atom pane class | 168 // Atom pane class |
157 static ATOM s_atomPaneClass; | 169 static ATOM s_atomPaneClass; |
158 | 170 |
159 static ATOM GetAtomPaneClass(); | 171 static ATOM GetAtomPaneClass(); |
160 | 172 |
161 // Icons | 173 // Icons |
162 static HICON s_hIcons[ICON_MAX]; | 174 static HICON s_hIcons[ICON_MAX]; |
163 static DWORD s_hIconTypes[ICON_MAX]; | 175 static DWORD s_hIconTypes[ICON_MAX]; |
164 | 176 |
165 static HICON GetIcon(int type); | 177 static HICON GetIcon(int type); |
166 | 178 |
167 // Main thread | 179 // Main thread |
168 static HANDLE s_hMainThread; | 180 static HANDLE s_hMainThread; |
169 static bool s_isMainThreadDone; | 181 static bool s_isMainThreadDone; |
170 | 182 |
171 static HANDLE GetMainThreadHandle(); | 183 static HANDLE GetMainThreadHandle(); |
172 static bool IsMainThreadDone(HANDLE mainThread); | 184 static bool IsMainThreadDone(HANDLE mainThread); |
173 | 185 |
174 static HINSTANCE s_hUxtheme; | 186 static HINSTANCE s_hUxtheme; |
175 static std::set<CPluginClass*> s_instances; | 187 static std::set<CPluginClass*> s_instances; |
176 static std::map<DWORD,CPluginClass*> s_threadInstances; | 188 static std::map<DWORD,CPluginClass*> s_threadInstances; |
177 static std::map<UINT, CString> s_menuDomains; | |
178 static CComAutoCriticalSection s_criticalSectionLocal; | 189 static CComAutoCriticalSection s_criticalSectionLocal; |
179 static CComAutoCriticalSection s_criticalSectionBrowser; | 190 static CComAutoCriticalSection s_criticalSectionBrowser; |
180 static CComAutoCriticalSection s_criticalSectionWindow; | 191 static CComAutoCriticalSection s_criticalSectionWindow; |
181 static CComAutoCriticalSection s_criticalSectionWhiteList; | |
182 | 192 |
183 // Async browser | 193 // Async browser |
184 static CComQIPtr<IWebBrowser2> s_asyncWebBrowser2; | 194 static CComQIPtr<IWebBrowser2> s_asyncWebBrowser2; |
185 static CComQIPtr<IWebBrowser2> GetAsyncBrowser(); | 195 static CComQIPtr<IWebBrowser2> GetAsyncBrowser(); |
186 }; | 196 }; |
187 | 197 |
188 OBJECT_ENTRY_AUTO(__uuidof(PluginClass), CPluginClass) | 198 OBJECT_ENTRY_AUTO(__uuidof(PluginClass), CPluginClass) |
189 | 199 |
190 | 200 |
191 #endif // _PLUGIN_CLASS_H_ | 201 #endif // _PLUGIN_CLASS_H_ |
LEFT | RIGHT |