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 #include "PluginStdAfx.h" | 18 #include "PluginStdAfx.h" |
2 #include "WebBrowserEventsListener.h" | 19 #include "WebBrowserEventsListener.h" |
3 #include "PluginClientBase.h" // for UnescapeUrl | |
4 | 20 |
5 WebBrowserEventsListener::WebBrowserEventsListener() | 21 WebBrowserEventsListener::WebBrowserEventsListener() |
6 : m_isDocumentEvents2Connected(false) | 22 : m_isDocumentEvents2Connected(false) |
7 , m_state(State::FirstTimeLoading) | 23 , m_state(State::FirstTimeLoading) |
8 { | 24 { |
9 } | 25 } |
10 | 26 |
11 WebBrowserEventsListener::~WebBrowserEventsListener() | 27 WebBrowserEventsListener::~WebBrowserEventsListener() |
12 { | 28 { |
13 if (!!m_onDestroy) | |
14 { | |
15 m_onDestroy(); | |
16 } | |
17 } | 29 } |
18 | 30 |
19 HRESULT STDMETHODCALLTYPE WebBrowserEventsListener::OnDocumentComplete(IDispatch
* dispFrameBrowser, VARIANT* /*variantUrl*/) | 31 HRESULT STDMETHODCALLTYPE WebBrowserEventsListener::OnDocumentComplete(IDispatch
* dispFrameBrowser, VARIANT* /*variantUrl*/) |
20 { | 32 { |
21 if (!dispFrameBrowser) | 33 if (!dispFrameBrowser) |
22 { | 34 { |
23 return E_POINTER; | 35 return E_POINTER; |
24 } | 36 } |
25 | 37 |
26 // if it's a signal from another browser (sub-frame for-example) then ignore i
t. | 38 // if it's a signal from another browser (sub-frame for-example) then ignore i
t. |
(...skipping 11 matching lines...) Expand all Loading... |
38 } | 50 } |
39 | 51 |
40 // We can get here when readyStateChanged("complete") is already received, | 52 // We can get here when readyStateChanged("complete") is already received, |
41 // don't emit reloaded, because it's already emitted from OnReadyStateChange. | 53 // don't emit reloaded, because it's already emitted from OnReadyStateChange. |
42 if (m_state == State::FirstTimeLoading) | 54 if (m_state == State::FirstTimeLoading) |
43 { | 55 { |
44 m_state = State::Loaded; | 56 m_state = State::Loaded; |
45 emitReloaded(); | 57 emitReloaded(); |
46 } | 58 } |
47 return S_OK; | 59 return S_OK; |
| 60 } |
| 61 |
| 62 void STDMETHODCALLTYPE WebBrowserEventsListener::OnQuit() |
| 63 { |
| 64 if (m_isDocumentEvents2Connected) |
| 65 { |
| 66 ATL::CComPtr<IDispatch> dispDocument; |
| 67 ATL::CComQIPtr<IHTMLDocument2> htmlDocument2; |
| 68 if (SUCCEEDED(m_browser->get_Document(&dispDocument)) && (htmlDocument2 = di
spDocument)) |
| 69 { |
| 70 HTMLDocumentEvents2Listener::DispEventUnadvise(htmlDocument2); |
| 71 } |
| 72 } |
| 73 WebBrowserEvents2Listener::DispEventUnadvise(m_browser); |
48 } | 74 } |
49 | 75 |
50 void STDMETHODCALLTYPE WebBrowserEventsListener::OnReadyStateChange(IHTMLEventOb
j* /*pEvtObj*/) | 76 void STDMETHODCALLTYPE WebBrowserEventsListener::OnReadyStateChange(IHTMLEventOb
j* /*pEvtObj*/) |
51 { | 77 { |
52 auto documentReadyState = [this]()->std::wstring | 78 auto documentReadyState = [this]()->std::wstring |
53 { | 79 { |
54 std::wstring notAvailableReadyState; | 80 std::wstring notAvailableReadyState; |
55 ATL::CComPtr<IDispatch> pDocDispatch; | 81 ATL::CComPtr<IDispatch> pDocDispatch; |
56 m_browser->get_Document(&pDocDispatch); | 82 m_browser->get_Document(&pDocDispatch); |
57 ATL::CComQIPtr<IHTMLDocument2> htmlDocument2 = pDocDispatch; | 83 ATL::CComQIPtr<IHTMLDocument2> htmlDocument2 = pDocDispatch; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 125 } |
100 else if (documentReadyState == L"uninitialized") | 126 else if (documentReadyState == L"uninitialized") |
101 { | 127 { |
102 } | 128 } |
103 else | 129 else |
104 { | 130 { |
105 assert(false); | 131 assert(false); |
106 } | 132 } |
107 } | 133 } |
108 | 134 |
109 HRESULT WebBrowserEventsListener::Init(IWebBrowser2* webBrowser, const OnDestroy
& onDestroy) | 135 void WebBrowserEventsListener::FinalRelease() |
| 136 { |
| 137 if (!!m_onDestroy) |
| 138 { |
| 139 m_onDestroy(); |
| 140 } |
| 141 } |
| 142 |
| 143 HRESULT WebBrowserEventsListener::Init(IWebBrowser2* webBrowser, const OnDestroy
& onDestroy, const OnReloaded& onReloaded) |
110 { | 144 { |
111 if (!(m_browser = webBrowser)) | 145 if (!(m_browser = webBrowser)) |
112 { | 146 { |
113 return E_POINTER; | 147 return E_POINTER; |
114 } | 148 } |
115 m_onDestroy = onDestroy; | 149 m_onDestroy = onDestroy; |
| 150 m_onReloaded = onReloaded; |
116 if (FAILED(WebBrowserEvents2Listener::DispEventAdvise(m_browser, &DIID_DWebBro
wserEvents2))) | 151 if (FAILED(WebBrowserEvents2Listener::DispEventAdvise(m_browser, &DIID_DWebBro
wserEvents2))) |
117 { | 152 { |
118 return E_FAIL; | 153 return E_FAIL; |
119 } | 154 } |
120 return S_OK; | 155 return S_OK; |
121 } | 156 } |
122 | 157 |
123 void WebBrowserEventsListener::emitReloaded() | 158 void WebBrowserEventsListener::emitReloaded() |
124 { | 159 { |
125 if (reloaded) | 160 if (m_onReloaded) |
126 { | 161 { |
127 reloaded(); | 162 m_onReloaded(); |
128 } | 163 } |
129 } | 164 } |
LEFT | RIGHT |