| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 | 34 |
| 35 #define ICON_PLUGIN_DISABLED 0 | 35 #define ICON_PLUGIN_DISABLED 0 |
| 36 #define ICON_PLUGIN_ENABLED 1 | 36 #define ICON_PLUGIN_ENABLED 1 |
| 37 #define ICON_PLUGIN_DEACTIVATED 2 | 37 #define ICON_PLUGIN_DEACTIVATED 2 |
| 38 #define ICON_MAX 3 | 38 #define ICON_MAX 3 |
| 39 | 39 |
| 40 #define WM_LAUNCH_INFO (WM_APP + 10) | 40 #define WM_LAUNCH_INFO (WM_APP + 10) |
| 41 | 41 |
| 42 class CPluginMimeFilterClient; | 42 class CPluginMimeFilterClient; |
| 43 | 43 |
| 44 /** | |
| 45 * Resource class for COM events. | |
| 46 * If an instance exists, there's an active connection behind it. | |
| 47 * | |
| 48 * \tparam Sink | |
| 49 * subclass of ATL::IDispEventImpl. | |
| 50 * \tparam Source | |
| 51 * Type of event source. Implements IConnectionPoint | |
| 52 */ | |
| 53 template<class Sink, class Source> | |
| 54 class AtlEventRegistration | |
| 55 { | |
| 56 CComPtr<Sink> consumer; | |
| 57 CComPtr<Source> producer; | |
| 58 public: | |
| 59 /** | |
| 60 * \throw std::runtime_error | |
| 61 * If connection is not established | |
| 62 * | |
| 63 * \par Precondition | |
| 64 * - consumer is not nullptr (not checked) | |
| 65 * - producer is not nullptr (not checked) | |
| 66 */ | |
| 67 AtlEventRegistration(Sink* consumer, Source* producer) | |
|
sergei
2016/02/04 13:45:50
Just noticed, it would be better to call them as l
Eric
2016/02/04 17:00:28
Neither pair of words "source/sink" and "listener/
sergei
2016/02/04 19:41:57
I think we should not write the code how it would
Eric
2016/02/04 20:13:25
We've entered bikeshedding territory here. You hav
| |
| 68 : consumer(consumer), producer(producer) | |
| 69 { | |
| 70 auto hr = consumer->DispEventAdvise(producer); | |
| 71 if (FAILED(hr)) | |
| 72 { | |
| 73 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVICE, " AtlEventRegistrationImpl::<constructor> - Advise"); | |
| 74 throw std::runtime_error("DispEventAdvise() failed"); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 ~AtlEventRegistration() // noexcept | |
| 79 { | |
| 80 try | |
| 81 { | |
| 82 // Smart pointer members ensure that this statement does not fail because of life span | |
| 83 auto hr = consumer->DispEventUnadvise(producer); | |
| 84 if (FAILED(hr)) | |
| 85 { | |
| 86 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "AtlEventRegistrationImpl::<destructor> - Unadvise"); | |
| 87 } | |
| 88 } | |
| 89 catch (...) | |
| 90 { | |
| 91 // Suppress exceptions | |
| 92 } | |
| 93 } | |
| 94 }; | |
| 95 | |
| 96 /** | |
| 97 * Resource holder for COM events. | |
| 98 * | |
| 99 * Manages the life time of an 'AtlEventRegistration' instance. | |
| 100 * Allows events to be started and stopped at some time other than construction/ destruction. | |
| 101 * | |
| 102 * \tparam Sink | |
| 103 * subclass of ATL::IDispEventImpl. | |
| 104 * \tparam Source | |
| 105 * Type of event source. Implements IConnectionPoint | |
| 106 */ | |
| 107 template<class Sink, class Source> | |
| 108 class AtlEventRegistrationHolder | |
| 109 { | |
| 110 typedef AtlEventRegistration<Sink, Source> ImplType; | |
| 111 std::unique_ptr<ImplType> impl; | |
| 112 | |
| 113 public: | |
| 114 bool Start(Sink* consumer, Source* producer) // noexcept | |
| 115 { | |
| 116 try | |
| 117 { | |
| 118 impl.reset(new ImplType(consumer, producer)); | |
| 119 } | |
| 120 catch (...) | |
| 121 { | |
| 122 impl.reset(); | |
| 123 return false; | |
| 124 } | |
| 125 return true; | |
| 126 } | |
| 127 | |
| 128 void Stop() // noexcept | |
| 129 { | |
| 130 impl.reset(); | |
| 131 } | |
| 132 }; | |
| 44 | 133 |
| 45 class ATL_NO_VTABLE CPluginClass : | 134 class ATL_NO_VTABLE CPluginClass : |
| 46 public ATL::CComObjectRootEx<ATL::CComMultiThreadModel>, | 135 public ATL::CComObjectRootEx<ATL::CComMultiThreadModel>, |
| 47 public ATL::CComCoClass<CPluginClass, &CLSID_PluginClass>, | 136 public ATL::CComCoClass<CPluginClass, &CLSID_PluginClass>, |
| 48 public ATL::IObjectWithSiteImpl<CPluginClass>, | 137 public ATL::IObjectWithSiteImpl<CPluginClass>, |
| 49 public IOleCommandTarget, | 138 public IOleCommandTarget, |
| 50 public ATL::IDispEventImpl<1, CPluginClass, &DIID_DWebBrowserEvents2, &LIBID_S HDocVw, 1, 1> | 139 public ATL::IDispEventImpl<1, CPluginClass, &DIID_DWebBrowserEvents2, &LIBID_S HDocVw, 1, 1> |
| 51 { | 140 { |
| 52 | 141 |
| 53 friend class CPluginTab; | 142 friend class CPluginTab; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 66 COM_INTERFACE_ENTRY(IObjectWithSite) | 155 COM_INTERFACE_ENTRY(IObjectWithSite) |
| 67 COM_INTERFACE_ENTRY(IOleCommandTarget) | 156 COM_INTERFACE_ENTRY(IOleCommandTarget) |
| 68 END_COM_MAP() | 157 END_COM_MAP() |
| 69 | 158 |
| 70 BEGIN_SINK_MAP(CPluginClass) | 159 BEGIN_SINK_MAP(CPluginClass) |
| 71 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, OnBeforeNa vigate2) | 160 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, OnBeforeNa vigate2) |
| 72 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOWNLOADCOMPLETE, OnDownloa dComplete) | 161 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOWNLOADCOMPLETE, OnDownloa dComplete) |
| 73 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, OnDocumen tComplete) | 162 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, OnDocumen tComplete) |
| 74 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_WINDOWSTATECHANGED, OnWindo wStateChanged) | 163 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_WINDOWSTATECHANGED, OnWindo wStateChanged) |
| 75 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_COMMANDSTATECHANGE, OnComma ndStateChange) | 164 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_COMMANDSTATECHANGE, OnComma ndStateChange) |
| 76 SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_ONQUIT, OnOnQuit) | |
| 77 END_SINK_MAP() | 165 END_SINK_MAP() |
| 78 | 166 |
| 79 CPluginClass(); | 167 CPluginClass(); |
| 80 ~CPluginClass(); | 168 ~CPluginClass(); |
| 81 | 169 |
| 82 // IObjectWithSite | 170 // IObjectWithSite |
| 83 STDMETHOD(SetSite)(IUnknown *pUnkSite); | 171 STDMETHOD(SetSite)(IUnknown *pUnkSite); |
| 84 | 172 |
| 85 // IOleCommandTarget | 173 // IOleCommandTarget |
| 86 STDMETHOD(QueryStatus)(const GUID* pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[ ], OLECMDTEXT* pCmdText); | 174 STDMETHOD(QueryStatus)(const GUID* pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[ ], OLECMDTEXT* pCmdText); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 VARIANT* URL /**< [in] */, | 213 VARIANT* URL /**< [in] */, |
| 126 VARIANT* Flags /**< [in] */, | 214 VARIANT* Flags /**< [in] */, |
| 127 VARIANT* TargetFrameName /**< [in] */ , | 215 VARIANT* TargetFrameName /**< [in] */ , |
| 128 VARIANT* PostData /**< [in] */, | 216 VARIANT* PostData /**< [in] */, |
| 129 VARIANT* Headers /**< [in] */, | 217 VARIANT* Headers /**< [in] */, |
| 130 VARIANT_BOOL* Cancel /* [in, out] */) ; | 218 VARIANT_BOOL* Cancel /* [in, out] */) ; |
| 131 void STDMETHODCALLTYPE OnDownloadComplete(); | 219 void STDMETHODCALLTYPE OnDownloadComplete(); |
| 132 void STDMETHODCALLTYPE OnDocumentComplete(IDispatch* frameBrowserDisp, VARIANT * /*urlOrPidl*/); | 220 void STDMETHODCALLTYPE OnDocumentComplete(IDispatch* frameBrowserDisp, VARIANT * /*urlOrPidl*/); |
| 133 void STDMETHODCALLTYPE OnWindowStateChanged(unsigned long flags, unsigned long validFlagsMask); | 221 void STDMETHODCALLTYPE OnWindowStateChanged(unsigned long flags, unsigned long validFlagsMask); |
| 134 void STDMETHODCALLTYPE OnCommandStateChange(long command, VARIANT_BOOL enable) ; | 222 void STDMETHODCALLTYPE OnCommandStateChange(long command, VARIANT_BOOL enable) ; |
| 135 void STDMETHODCALLTYPE OnOnQuit(); | 223 |
| 136 void Unadvise(); | |
| 137 | |
| 138 void ShowStatusBar(); | 224 void ShowStatusBar(); |
| 139 bool IsStatusBarEnabled(); | 225 bool IsStatusBarEnabled(); |
| 140 | 226 |
| 141 /** | 227 /** |
| 142 * A browser interface pointer to our site object | 228 * A browser interface pointer to our site object |
| 143 * | 229 * |
| 144 * It's values are set and reset solely in SetSite(). | 230 * It's values are set and reset solely in SetSite(). |
| 145 */ | 231 */ |
| 146 CComPtr<IWebBrowser2> m_webBrowser2; | 232 CComPtr<IWebBrowser2> m_webBrowser2; |
| 233 /** | |
| 234 * Event manager for events coming from our site object. | |
| 235 */ | |
| 236 AtlEventRegistrationHolder<CPluginClass, IWebBrowser2> browserEvents; | |
| 237 bool detachedInitializationFailed; | |
| 238 | |
| 147 HWND m_hBrowserWnd; | 239 HWND m_hBrowserWnd; |
| 148 HWND m_hTabWnd; | 240 HWND m_hTabWnd; |
| 149 HWND m_hStatusBarWnd; | 241 HWND m_hStatusBarWnd; |
| 150 HWND m_hPaneWnd; | 242 HWND m_hPaneWnd; |
| 151 | 243 |
| 152 WNDPROC m_pWndProcStatus; | 244 WNDPROC m_pWndProcStatus; |
| 153 int m_nPaneWidth; | 245 int m_nPaneWidth; |
| 154 HANDLE m_hTheme; | 246 HANDLE m_hTheme; |
| 155 | 247 |
| 156 CriticalSection m_csStatusBar; | 248 CriticalSection m_csStatusBar; |
| 157 | 249 |
| 158 NotificationMessage notificationMessage; | 250 NotificationMessage notificationMessage; |
| 159 | 251 |
| 160 bool m_isAdvised; | |
| 161 bool m_isInitializedOk; | 252 bool m_isInitializedOk; |
| 162 | 253 |
| 163 // Atom pane class | 254 // Atom pane class |
| 164 static ATOM s_atomPaneClass; | 255 static ATOM s_atomPaneClass; |
| 165 | 256 |
| 166 static ATOM GetAtomPaneClass(); | 257 static ATOM GetAtomPaneClass(); |
| 167 | 258 |
| 168 // Icons | 259 // Icons |
| 169 static HICON s_hIcons[ICON_MAX]; | 260 static HICON s_hIcons[ICON_MAX]; |
| 170 static DWORD s_hIconTypes[ICON_MAX]; | 261 static DWORD s_hIconTypes[ICON_MAX]; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 183 | 274 |
| 184 // Async browser | 275 // Async browser |
| 185 static CComQIPtr<IWebBrowser2> s_asyncWebBrowser2; | 276 static CComQIPtr<IWebBrowser2> s_asyncWebBrowser2; |
| 186 static CComQIPtr<IWebBrowser2> GetAsyncBrowser(); | 277 static CComQIPtr<IWebBrowser2> GetAsyncBrowser(); |
| 187 }; | 278 }; |
| 188 | 279 |
| 189 OBJECT_ENTRY_AUTO(__uuidof(PluginClass), CPluginClass) | 280 OBJECT_ENTRY_AUTO(__uuidof(PluginClass), CPluginClass) |
| 190 | 281 |
| 191 | 282 |
| 192 #endif // _PLUGIN_CLASS_H_ | 283 #endif // _PLUGIN_CLASS_H_ |
| OLD | NEW |