Index: src/plugin/WebBrowserEventsListener.h |
diff --git a/src/plugin/WebBrowserEventsListener.h b/src/plugin/WebBrowserEventsListener.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..63ad1e81159da1516959d2607b0eab93c3403313 |
--- /dev/null |
+++ b/src/plugin/WebBrowserEventsListener.h |
@@ -0,0 +1,56 @@ |
+#pragma once |
+#include <functional> |
+#include <memory> |
+ |
+class WebBrowserEventsListener; |
+ |
+typedef ATL::IDispEventImpl <1, WebBrowserEventsListener, |
+ &__uuidof(DWebBrowserEvents2), &LIBID_SHDocVw, 1, 1> WebBrowserEvents2Listener; |
+ |
+typedef ATL::IDispEventImpl <2, WebBrowserEventsListener, |
+ &__uuidof(HTMLDocumentEvents2), &LIBID_MSHTML, 4, 0> HTMLDocumentEvents2Listener; |
+ |
+class ATL_NO_VTABLE WebBrowserEventsListener : |
+ public ATL::CComObjectRootEx<ATL::CComSingleThreadModel>, |
+ public WebBrowserEvents2Listener, |
+ public HTMLDocumentEvents2Listener, |
+ public IUnknown |
+{ |
+ enum class State |
+ { |
+ FirstTimeLoading, Loading, Loaded |
+ }; |
+public: |
+ typedef std::function<void()> OnDestroy; |
+ typedef std::function<void()> OnReloaded; |
+ |
+ WebBrowserEventsListener(); |
+ ~WebBrowserEventsListener(); |
+ BEGIN_COM_MAP(WebBrowserEventsListener) |
+ COM_INTERFACE_ENTRY(IUnknown) |
+ END_COM_MAP() |
+ |
+ DECLARE_NOT_AGGREGATABLE(WebBrowserEventsListener) |
+ BEGIN_SINK_MAP(WebBrowserEventsListener) |
+ SINK_ENTRY_EX(1, __uuidof(DWebBrowserEvents2), DISPID_DOCUMENTCOMPLETE, OnDocumentComplete) |
+ SINK_ENTRY_EX(2, __uuidof(HTMLDocumentEvents2), DISPID_HTMLDOCUMENTEVENTS2_ONREADYSTATECHANGE, OnReadyStateChange) |
+ END_SINK_MAP() |
+ |
+ STDMETHOD(OnDocumentComplete)(IDispatch* pDisp, VARIANT* urlVariant); |
+ STDMETHOD_(void, OnReadyStateChange)(IHTMLEventObj* pEvtObj); |
+ |
+ DECLARE_PROTECT_FINAL_CONSTRUCT() |
+ |
+ HRESULT FinalConstruct(){ return S_OK; } |
+ void FinalRelease(){} |
+ HRESULT Init(IWebBrowser2* webBrowser, const OnDestroy& onDestroy); |
+ |
+ OnReloaded reloaded; |
+private: |
+ void emitReloaded(); |
+private: |
+ ATL::CComPtr<IWebBrowser2> m_browser; |
+ OnDestroy m_onDestroy; |
+ bool m_isDocumentEvents2Connected; |
+ State m_state; |
+}; |