OLD | NEW |
(Empty) | |
| 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 |
| 18 #pragma once |
| 19 #include <functional> |
| 20 #include <memory> |
| 21 |
| 22 class WebBrowserEventsListener; |
| 23 |
| 24 typedef ATL::IDispEventImpl <1, WebBrowserEventsListener, |
| 25 &__uuidof(DWebBrowserEvents2), &LIBID_SHDocVw, 1, 1> WebBrowserEvents2Listener
; |
| 26 |
| 27 typedef ATL::IDispEventImpl <2, WebBrowserEventsListener, |
| 28 &__uuidof(HTMLDocumentEvents2), &LIBID_MSHTML, 4, 0> HTMLDocumentEvents2Listen
er; |
| 29 |
| 30 class ATL_NO_VTABLE WebBrowserEventsListener : |
| 31 public ATL::CComObjectRootEx<ATL::CComMultiThreadModel>, |
| 32 public WebBrowserEvents2Listener, |
| 33 public HTMLDocumentEvents2Listener, |
| 34 public IUnknown |
| 35 { |
| 36 enum class State |
| 37 { |
| 38 FirstTimeLoading, Loading, Loaded |
| 39 }; |
| 40 public: |
| 41 typedef std::function<void()> OnDestroy; |
| 42 typedef std::function<void()> OnReloaded; |
| 43 |
| 44 WebBrowserEventsListener(); |
| 45 ~WebBrowserEventsListener(); |
| 46 BEGIN_COM_MAP(WebBrowserEventsListener) |
| 47 COM_INTERFACE_ENTRY(IUnknown) |
| 48 END_COM_MAP() |
| 49 |
| 50 DECLARE_NOT_AGGREGATABLE(WebBrowserEventsListener) |
| 51 BEGIN_SINK_MAP(WebBrowserEventsListener) |
| 52 SINK_ENTRY_EX(1, __uuidof(DWebBrowserEvents2), DISPID_DOCUMENTCOMPLETE, OnDo
cumentComplete) |
| 53 SINK_ENTRY_EX(1, __uuidof(DWebBrowserEvents2), DISPID_ONQUIT, OnOnQuit) |
| 54 SINK_ENTRY_EX(2, __uuidof(HTMLDocumentEvents2), DISPID_HTMLDOCUMENTEVENTS2_O
NREADYSTATECHANGE, OnReadyStateChange) |
| 55 END_SINK_MAP() |
| 56 |
| 57 STDMETHOD(OnDocumentComplete)(IDispatch* pDisp, VARIANT* urlVariant); |
| 58 STDMETHOD_(void, OnOnQuit)(); |
| 59 STDMETHOD_(void, OnReadyStateChange)(IHTMLEventObj* pEvtObj); |
| 60 |
| 61 DECLARE_PROTECT_FINAL_CONSTRUCT() |
| 62 |
| 63 HRESULT FinalConstruct(){ return S_OK; } |
| 64 void FinalRelease(); |
| 65 HRESULT Init(IWebBrowser2* webBrowser, const OnDestroy& onDestroy, const OnRel
oaded& onReloaded); |
| 66 |
| 67 private: |
| 68 void emitReloaded(); |
| 69 private: |
| 70 ATL::CComPtr<IWebBrowser2> m_browser; |
| 71 OnDestroy m_onDestroy; |
| 72 OnReloaded m_onReloaded; |
| 73 bool m_isDocumentEvents2Connected; |
| 74 State m_state; |
| 75 }; |
OLD | NEW |