Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/plugin/WebBrowserEventsListener.cpp

Issue 6567422169448448: Issue 119 - Switch to injecting CSS for element hiding (Closed)
Left Patch Set: rebase Created Feb. 25, 2016, 5:38 p.m.
Right Patch Set: rename OnQuit Created Sept. 30, 2016, 3:25 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/plugin/WebBrowserEventsListener.h ('k') | src/shared/EventWithSetter.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include "PluginStdAfx.h" 18 #include "PluginStdAfx.h"
19 #include "WebBrowserEventsListener.h" 19 #include "WebBrowserEventsListener.h"
20 20
21 WebBrowserEventsListener::WebBrowserEventsListener() 21 WebBrowserEventsListener::WebBrowserEventsListener()
22 : m_isDocumentEvents2Connected(false) 22 : m_isDocumentEvents2Connected(false)
23 , m_state(State::FirstTimeLoading) 23 , m_state(State::FirstTimeLoading)
24 { 24 {
25 } 25 }
26 26
27 WebBrowserEventsListener::~WebBrowserEventsListener() 27 WebBrowserEventsListener::~WebBrowserEventsListener()
28 { 28 {
29 if (!!m_onDestroy)
30 {
31 m_onDestroy();
32 }
33 } 29 }
34 30
35 HRESULT STDMETHODCALLTYPE WebBrowserEventsListener::OnDocumentComplete(IDispatch * dispFrameBrowser, VARIANT* /*variantUrl*/) 31 HRESULT STDMETHODCALLTYPE WebBrowserEventsListener::OnDocumentComplete(IDispatch * dispFrameBrowser, VARIANT* /*variantUrl*/)
36 { 32 {
37 if (!dispFrameBrowser) 33 if (!dispFrameBrowser)
38 { 34 {
39 return E_POINTER; 35 return E_POINTER;
40 } 36 }
41 37
42 // 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
54 } 50 }
55 51
56 // We can get here when readyStateChanged("complete") is already received, 52 // We can get here when readyStateChanged("complete") is already received,
57 // don't emit reloaded, because it's already emitted from OnReadyStateChange. 53 // don't emit reloaded, because it's already emitted from OnReadyStateChange.
58 if (m_state == State::FirstTimeLoading) 54 if (m_state == State::FirstTimeLoading)
59 { 55 {
60 m_state = State::Loaded; 56 m_state = State::Loaded;
61 emitReloaded(); 57 emitReloaded();
62 } 58 }
63 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);
64 } 74 }
65 75
66 void STDMETHODCALLTYPE WebBrowserEventsListener::OnReadyStateChange(IHTMLEventOb j* /*pEvtObj*/) 76 void STDMETHODCALLTYPE WebBrowserEventsListener::OnReadyStateChange(IHTMLEventOb j* /*pEvtObj*/)
67 { 77 {
68 auto documentReadyState = [this]()->std::wstring 78 auto documentReadyState = [this]()->std::wstring
69 { 79 {
70 std::wstring notAvailableReadyState; 80 std::wstring notAvailableReadyState;
71 ATL::CComPtr<IDispatch> pDocDispatch; 81 ATL::CComPtr<IDispatch> pDocDispatch;
72 m_browser->get_Document(&pDocDispatch); 82 m_browser->get_Document(&pDocDispatch);
73 ATL::CComQIPtr<IHTMLDocument2> htmlDocument2 = pDocDispatch; 83 ATL::CComQIPtr<IHTMLDocument2> htmlDocument2 = pDocDispatch;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 125 }
116 else if (documentReadyState == L"uninitialized") 126 else if (documentReadyState == L"uninitialized")
117 { 127 {
118 } 128 }
119 else 129 else
120 { 130 {
121 assert(false); 131 assert(false);
122 } 132 }
123 } 133 }
124 134
135 void WebBrowserEventsListener::FinalRelease()
136 {
137 if (!!m_onDestroy)
138 {
139 m_onDestroy();
140 }
141 }
142
125 HRESULT WebBrowserEventsListener::Init(IWebBrowser2* webBrowser, const OnDestroy & onDestroy, const OnReloaded& onReloaded) 143 HRESULT WebBrowserEventsListener::Init(IWebBrowser2* webBrowser, const OnDestroy & onDestroy, const OnReloaded& onReloaded)
126 { 144 {
127 if (!(m_browser = webBrowser)) 145 if (!(m_browser = webBrowser))
128 { 146 {
129 return E_POINTER; 147 return E_POINTER;
130 } 148 }
131 m_onDestroy = onDestroy; 149 m_onDestroy = onDestroy;
132 m_onReloaded = onReloaded; 150 m_onReloaded = onReloaded;
133 if (FAILED(WebBrowserEvents2Listener::DispEventAdvise(m_browser, &DIID_DWebBro wserEvents2))) 151 if (FAILED(WebBrowserEvents2Listener::DispEventAdvise(m_browser, &DIID_DWebBro wserEvents2)))
134 { 152 {
135 return E_FAIL; 153 return E_FAIL;
136 } 154 }
137 return S_OK; 155 return S_OK;
138 } 156 }
139 157
140 void WebBrowserEventsListener::emitReloaded() 158 void WebBrowserEventsListener::emitReloaded()
141 { 159 {
142 if (m_onReloaded) 160 if (m_onReloaded)
143 { 161 {
144 m_onReloaded(); 162 m_onReloaded();
145 } 163 }
146 } 164 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld