LEFT | RIGHT |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2016 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 class WebBrowserEventsListener; | 43 class WebBrowserEventsListener; |
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> |
36 { | 51 { |
37 | 52 |
38 friend class CPluginTab; | 53 friend class CPluginTab; |
39 | 54 |
40 public: | 55 public: |
41 | 56 |
42 DECLARE_REGISTRY_RESOURCEID(IDR_PLUGIN_CLASS) | 57 DECLARE_REGISTRY_RESOURCEID(IDR_PLUGIN_CLASS) |
43 | 58 |
44 DECLARE_PROTECT_FINAL_CONSTRUCT() | 59 DECLARE_PROTECT_FINAL_CONSTRUCT() |
45 | 60 |
46 BEGIN_COM_MAP(CPluginClass) | 61 BEGIN_COM_MAP(CPluginClass) |
47 COM_INTERFACE_ENTRY(IObjectWithSite) | 62 COM_INTERFACE_ENTRY(IObjectWithSite) |
48 COM_INTERFACE_ENTRY(IOleCommandTarget) | 63 COM_INTERFACE_ENTRY(IOleCommandTarget) |
49 END_COM_MAP() | 64 END_COM_MAP() |
50 | 65 |
51 BEGIN_SINK_MAP(CPluginClass) | 66 BEGIN_SINK_MAP(CPluginClass) |
52 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, OnBeforeNa
vigate2) | 67 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, OnBeforeNa
vigate2) |
53 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOWNLOADBEGIN, OnDownloadBe
gin) | |
54 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOWNLOADCOMPLETE, OnDownloa
dComplete) | 68 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOWNLOADCOMPLETE, OnDownloa
dComplete) |
55 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, OnDocumen
tComplete) | |
56 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_WINDOWSTATECHANGED, OnWindo
wStateChanged) | 69 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_WINDOWSTATECHANGED, OnWindo
wStateChanged) |
57 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_COMMANDSTATECHANGE, OnComma
ndStateChange) | 70 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_COMMANDSTATECHANGE, OnComma
ndStateChange) |
58 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_ONQUIT, Unadvice) | 71 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_ONQUIT, OnOnQuit) |
59 END_SINK_MAP() | 72 END_SINK_MAP() |
60 | 73 |
61 CPluginClass(); | 74 CPluginClass(); |
62 ~CPluginClass(); | 75 ~CPluginClass(); |
63 | 76 |
64 HRESULT FinalConstruct(); | |
65 void FinalRelease(); | |
66 | |
67 // IObjectWithSite | 77 // IObjectWithSite |
68 | |
69 STDMETHOD(SetSite)(IUnknown *pUnkSite); | 78 STDMETHOD(SetSite)(IUnknown *pUnkSite); |
70 | 79 |
71 // IOleCommandTarget | 80 // IOleCommandTarget |
72 | |
73 STDMETHOD(QueryStatus)(const GUID* pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[
], OLECMDTEXT* pCmdText); | 81 STDMETHOD(QueryStatus)(const GUID* pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[
], OLECMDTEXT* pCmdText); |
74 STDMETHOD(Exec)(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, VARIANTARG* pva
Out); | 82 STDMETHOD(Exec)(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, VARIANTARG* pva
Out); |
75 | 83 |
76 | 84 |
77 static CPluginTab* GetTab(DWORD dwThreadId); | 85 static CPluginTab* GetTab(DWORD dwThreadId); |
78 CPluginTab* GetTab(); | 86 CPluginTab* GetTab(); |
79 | 87 |
80 void UpdateStatusBar(); | 88 void UpdateStatusBar(); |
81 static DWORD WINAPI MainThreadProc(LPVOID pParam); | |
82 | 89 |
83 private: | 90 private: |
84 | 91 |
85 bool SetMenuBar(HMENU hMenu, const CString& url); | 92 bool SetMenuBar(HMENU hMenu, const std::wstring& url); |
86 HMENU CreatePluginMenu(const CString& url); | 93 HMENU CreatePluginMenu(const std::wstring& url); |
87 | 94 |
88 void DisplayPluginMenu(HMENU hMenu, int nToolbarCmdID, POINT pt, UINT nMenuFla
gs); | 95 void DisplayPluginMenu(HMENU hMenu, int nToolbarCmdID, POINT pt, UINT nMenuFla
gs); |
89 bool CreateStatusBarPane(); | 96 bool CreateStatusBarPane(); |
90 | 97 |
91 public: | 98 public: |
92 HWND GetBrowserHWND() const; | 99 HWND GetBrowserHWND() const; |
93 HWND GetTabHWND() const; | 100 bool IsRootBrowser(IWebBrowser2*); |
94 CComQIPtr<IWebBrowser2> GetBrowser() const; | |
95 | |
96 | 101 |
97 static CPluginMimeFilterClient* s_mimeFilter; | 102 static CPluginMimeFilterClient* s_mimeFilter; |
98 | 103 |
99 private: | 104 private: |
100 | 105 |
101 CString GetBrowserUrl() const; | 106 std::wstring GetBrowserUrl() const; |
102 | |
103 | 107 |
104 static DWORD WINAPI StartInitObject(LPVOID thisPtr); | 108 static DWORD WINAPI StartInitObject(LPVOID thisPtr); |
105 bool InitObject(bool bBHO); | 109 bool InitObject(); |
106 void CloseTheme(); | 110 void CloseTheme(); |
107 void UpdateTheme(); | 111 void UpdateTheme(); |
108 | 112 |
109 static HICON GetStatusBarIcon(const CString& url); | 113 static HICON GetStatusBarIcon(const std::wstring& url); |
110 static CPluginClass* FindInstance(HWND hStatusBarWnd); | 114 static CPluginClass* FindInstance(HWND hStatusBarWnd); |
111 static LRESULT CALLBACK NewStatusProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam); | 115 static LRESULT CALLBACK NewStatusProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam); |
112 static LRESULT CALLBACK PaneWindowProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam); | 116 static LRESULT CALLBACK PaneWindowProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam); |
113 static void FirstRunThread(); | 117 static void FirstRunThread(); |
114 | 118 |
115 void STDMETHODCALLTYPE OnBeforeNavigate2(/* [in] */ IDispatch* pDisp, | 119 void STDMETHODCALLTYPE OnBeforeNavigate2(IDispatch* pDisp /**< [in] */, |
116 /* [in] */ VARIANT* URL, | 120 VARIANT* URL /**< [in] */, |
117 /* [in] */ VARIANT* Flags, | 121 VARIANT* Flags /**< [in] */, |
118 /* [in] */ VARIANT* TargetFrameName, | 122 VARIANT* TargetFrameName /**< [in] */
, |
119 /* [in] */ VARIANT* PostData, | 123 VARIANT* PostData /**< [in] */, |
120 /* [in] */ VARIANT* Headers, | 124 VARIANT* Headers /**< [in] */, |
121 /* [in, out] */ VARIANT_BOOL* Cancel); | 125 VARIANT_BOOL* Cancel /* [in, out] */)
; |
122 void STDMETHODCALLTYPE OnDownloadBegin(); | |
123 void STDMETHODCALLTYPE OnDownloadComplete(); | 126 void STDMETHODCALLTYPE OnDownloadComplete(); |
124 void STDMETHODCALLTYPE OnDocumentComplete(IDispatch* frameBrowserDisp, VARIANT
* /*urlOrPidl*/); | |
125 void STDMETHODCALLTYPE OnWindowStateChanged(unsigned long flags, unsigned long
validFlagsMask); | 127 void STDMETHODCALLTYPE OnWindowStateChanged(unsigned long flags, unsigned long
validFlagsMask); |
126 void STDMETHODCALLTYPE OnCommandStateChange(long command, VARIANT_BOOL enable)
; | 128 void STDMETHODCALLTYPE OnCommandStateChange(long command, VARIANT_BOOL enable)
; |
127 // OnOnQuit | 129 void STDMETHODCALLTYPE OnOnQuit(); |
128 void STDMETHODCALLTYPE Unadvice(); | 130 void Unadvise(); |
| 131 void EnsureWebBrowserConnected(const ATL::CComPtr<IWebBrowser2>& webBrowser); |
129 | 132 |
130 void ShowStatusBar(); | 133 void ShowStatusBar(); |
131 bool IsStatusBarEnabled(); | 134 bool IsStatusBarEnabled(); |
132 | 135 |
133 private: | |
134 HWND m_hBrowserWnd; | 136 HWND m_hBrowserWnd; |
135 HWND m_hTabWnd; | 137 HWND m_hTabWnd; |
136 HWND m_hStatusBarWnd; | 138 HWND m_hStatusBarWnd; |
137 HWND m_hPaneWnd; | 139 HWND m_hPaneWnd; |
138 | 140 |
139 WNDPROC m_pWndProcStatus; | 141 WNDPROC m_pWndProcStatus; |
140 int m_nPaneWidth; | 142 int m_nPaneWidth; |
141 HANDLE m_hTheme; | 143 HANDLE m_hTheme; |
142 struct Data | 144 struct Data |
143 { | 145 { |
144 std::map<IWebBrowser2*, WebBrowserEventsListener*> connectedWebBrowsersCache
; | 146 std::map<IWebBrowser2*, WebBrowserEventsListener*> connectedWebBrowsersCache
; |
145 std::unique_ptr<CPluginTab> tab; | 147 std::unique_ptr<CPluginTab> tab; |
146 ATL::CComPtr<IWebBrowser2> webBrowser2; | 148 ATL::CComPtr<IWebBrowser2> webBrowser2; |
147 }; | 149 }; |
148 // we need to have it as a shared pointer to get weak pointer to it to avoid | 150 // we need to have it as a shared pointer to get weak pointer to it to avoid |
149 // wrong usage after destroying of this class. | 151 // wrong usage after destroying of this class. |
150 std::shared_ptr<Data> m_data; | 152 std::shared_ptr<Data> m_data; |
151 | 153 |
152 CriticalSection m_csStatusBar; | 154 CriticalSection m_csStatusBar; |
153 | 155 |
154 NotificationMessage notificationMessage; | 156 NotificationMessage notificationMessage; |
155 | 157 |
156 bool m_isAdviced; | 158 bool m_isAdvised; |
157 bool m_isInitializedOk; | 159 bool m_isInitializedOk; |
158 | 160 |
159 // Atom pane class | 161 // Atom pane class |
160 static ATOM s_atomPaneClass; | 162 static ATOM s_atomPaneClass; |
161 | 163 |
162 static ATOM GetAtomPaneClass(); | 164 static ATOM GetAtomPaneClass(); |
163 | 165 |
164 // Icons | 166 // Icons |
165 static HICON s_hIcons[ICON_MAX]; | 167 static HICON s_hIcons[ICON_MAX]; |
166 static DWORD s_hIconTypes[ICON_MAX]; | 168 static DWORD s_hIconTypes[ICON_MAX]; |
167 | 169 |
168 static HICON GetIcon(int type); | 170 static HICON GetIcon(int type); |
169 | 171 |
170 // Main thread | 172 // Main thread |
171 static HANDLE s_hMainThread; | 173 static HANDLE s_hMainThread; |
172 static bool s_isMainThreadDone; | 174 static bool s_isMainThreadDone; |
173 | 175 |
174 static HANDLE GetMainThreadHandle(); | |
175 static bool IsMainThreadDone(HANDLE mainThread); | |
176 | |
177 static HINSTANCE s_hUxtheme; | 176 static HINSTANCE s_hUxtheme; |
178 static std::set<CPluginClass*> s_instances; | 177 static std::set<CPluginClass*> s_instances; |
179 static std::map<DWORD,CPluginClass*> s_threadInstances; | 178 static std::map<DWORD,CPluginClass*> s_threadInstances; |
180 static std::map<UINT, CString> s_menuDomains; | |
181 static CComAutoCriticalSection s_criticalSectionLocal; | 179 static CComAutoCriticalSection s_criticalSectionLocal; |
182 static CComAutoCriticalSection s_criticalSectionBrowser; | |
183 static CComAutoCriticalSection s_criticalSectionWindow; | 180 static CComAutoCriticalSection s_criticalSectionWindow; |
184 static CComAutoCriticalSection s_criticalSectionWhiteList; | |
185 | 181 |
186 // Async browser | 182 // Async browser |
187 static CComQIPtr<IWebBrowser2> s_asyncWebBrowser2; | 183 static CComQIPtr<IWebBrowser2> s_asyncWebBrowser2; |
188 static CComQIPtr<IWebBrowser2> GetAsyncBrowser(); | 184 static CComQIPtr<IWebBrowser2> GetAsyncBrowser(); |
189 }; | 185 }; |
190 | 186 |
191 OBJECT_ENTRY_AUTO(__uuidof(PluginClass), CPluginClass) | 187 OBJECT_ENTRY_AUTO(__uuidof(PluginClass), CPluginClass) |
192 | 188 |
193 | 189 |
194 #endif // _PLUGIN_CLASS_H_ | 190 #endif // _PLUGIN_CLASS_H_ |
LEFT | RIGHT |