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

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

Issue 6567422169448448: Issue 119 - Switch to injecting CSS for element hiding (Closed)
Left Patch Set: rebase and address comments Created April 13, 2015, 8:04 a.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/PluginClass.h ('k') | src/plugin/PluginDomTraverserBase.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 19
20 #include "PluginClass.h" 20 #include "PluginClass.h"
21 #include "PluginSettings.h" 21 #include "PluginSettings.h"
22 #include "PluginSystem.h" 22 #include "PluginSystem.h"
23 #include "PluginFilter.h" 23 #include "PluginFilter.h"
24 #include "PluginMimeFilterClient.h" 24 #include "PluginMimeFilterClient.h"
25 #include "PluginClient.h" 25 #include "AdblockPlusClient.h"
26 #include "PluginClientBase.h"
26 #include "PluginClientFactory.h" 27 #include "PluginClientFactory.h"
27 #include "PluginMutex.h"
28 #include "sddl.h"
29 #include "PluginUtil.h" 28 #include "PluginUtil.h"
30 #include "PluginUserSettings.h"
31 #include "../shared/Utils.h" 29 #include "../shared/Utils.h"
32 #include "../shared/Dictionary.h" 30 #include "../shared/Dictionary.h"
33 #include "WebBrowserEventsListener.h" 31 #include "IeVersion.h"
34 #include "../shared/IE_version.h" 32 #include "../shared/Version.h"
35 #include <thread> 33 #include <thread>
36 #include <array> 34 #include <array>
35 #include "WebBrowserEventsListener.h"
37 36
38 #ifdef DEBUG_HIDE_EL 37 #ifdef DEBUG_HIDE_EL
39 DWORD profileTime = 0; 38 DWORD profileTime = 0;
40 #endif 39 #endif
40
41 extern CComModule _Module;
41 42
42 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR); 43 typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR);
43 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR ECT); 44 typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPR ECT);
44 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE); 45 typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE);
45 46
46 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL }; 47 HICON CPluginClass::s_hIcons[ICON_MAX] = { NULL, NULL, NULL };
47 DWORD CPluginClass::s_hIconTypes[ICON_MAX] = { IDI_ICON_DISABLED, IDI_ICON_ENABL ED, IDI_ICON_DEACTIVATED }; 48 DWORD CPluginClass::s_hIconTypes[ICON_MAX] = { IDI_ICON_DISABLED, IDI_ICON_ENABL ED, IDI_ICON_DEACTIVATED };
48 uint32_t iconHeight = 32; 49 uint32_t iconHeight = 32;
49 uint32_t iconWidth = 32; 50 uint32_t iconWidth = 32;
50 51
51 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL; 52 CPluginMimeFilterClient* CPluginClass::s_mimeFilter = NULL;
52 53
53 CLOSETHEMEDATA pfnClose = NULL; 54 CLOSETHEMEDATA pfnClose = NULL;
54 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; 55 DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL;
55 OPENTHEMEDATA pfnOpenThemeData = NULL; 56 OPENTHEMEDATA pfnOpenThemeData = NULL;
56 57
57 ATOM CPluginClass::s_atomPaneClass = NULL; 58 ATOM CPluginClass::s_atomPaneClass = NULL;
58 HINSTANCE CPluginClass::s_hUxtheme = NULL; 59 HINSTANCE CPluginClass::s_hUxtheme = NULL;
59 std::set<CPluginClass*> CPluginClass::s_instances; 60 std::set<CPluginClass*> CPluginClass::s_instances;
60 std::map<DWORD, CPluginClass*> CPluginClass::s_threadInstances; 61 std::map<DWORD, CPluginClass*> CPluginClass::s_threadInstances;
61 62
62 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal; 63 CComAutoCriticalSection CPluginClass::s_criticalSectionLocal;
63 CComAutoCriticalSection CPluginClass::s_criticalSectionBrowser;
64 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow; 64 CComAutoCriticalSection CPluginClass::s_criticalSectionWindow;
65 65
66 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2; 66 CComQIPtr<IWebBrowser2> CPluginClass::s_asyncWebBrowser2;
67 67
68 /* 68 /*
69 * Without namespace declaration, the identifier "Rectangle" is ambiguous 69 * Without namespace declaration, the identifier "Rectangle" is ambiguous
70 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85) .aspx 70 * See http://msdn.microsoft.com/en-us/library/windows/desktop/dd162898(v=vs.85) .aspx
71 */ 71 */
72 namespace AdblockPlus 72 namespace AdblockPlus
73 { 73 {
74 /** 74 /**
75 * Replacement for ATL type CRect. 75 * Replacement for ATL type CRect.
76 */ 76 */
77 class Rectangle 77 class Rectangle
78 : public RECT 78 : public RECT
79 { 79 {
80 public: 80 public:
81 int Height() const 81 unsigned long Height() const
82 { 82 {
83 return bottom - top; 83 if (bottom < top)
84 } 84 {
85 85 throw std::runtime_error("invariant violation: rectangle bottom < top");
86 int Width() const 86 }
87 { 87 return static_cast<unsigned long>(bottom - top);
88 return right - left; 88 }
89
90 unsigned long Width() const
91 {
92 if (right < left)
93 {
94 throw std::runtime_error("invariant violation: rectangle right < left");
95 }
96 return static_cast<unsigned long>(right - left);
89 } 97 }
90 }; 98 };
91 } 99 }
92 100
93 CPluginClass::CPluginClass() 101 CPluginClass::CPluginClass()
94 : m_data(std::make_shared<Data>()) 102 : m_data(std::make_shared<Data>())
95 { 103 {
104 DEBUG_GENERAL([this]() -> std::wstring
105 {
106 std::wstring s = L"CPluginClass::<constructor>, this = ";
107 s += ToHexLiteral(this);
108 return s;
109 }());
110
96 //Use this line to debug memory leaks 111 //Use this line to debug memory leaks
97 // _CrtDumpMemoryLeaks(); 112 // _CrtDumpMemoryLeaks();
98 113
99 m_isAdvised = false; 114 m_isAdvised = false;
100 m_hTabWnd = NULL; 115 m_hTabWnd = NULL;
101 m_hStatusBarWnd = NULL; 116 m_hStatusBarWnd = NULL;
102 m_hPaneWnd = NULL; 117 m_hPaneWnd = NULL;
103 m_nPaneWidth = 0; 118 m_nPaneWidth = 0;
104 m_pWndProcStatus = NULL; 119 m_pWndProcStatus = NULL;
105 m_hTheme = NULL; 120 m_hTheme = NULL;
106 m_isInitializedOk = false; 121 m_isInitializedOk = false;
107 122
108 123
109 m_data->tab.reset(new CPluginTab(this)); 124 m_data->tab.reset(new CPluginTab());
125
110 Dictionary::Create(GetBrowserLanguage()); 126 Dictionary::Create(GetBrowserLanguage());
111 } 127 }
112 128
113 CPluginClass::~CPluginClass() 129 CPluginClass::~CPluginClass()
114 { 130 {
115 } 131 DEBUG_GENERAL([this]() -> std::wstring
116 132 {
117 ///////////////////////////////////////////////////////////////////////////// 133 std::wstring s = L"CPluginClass::<destructor>, this = ";
118 // Initialization 134 s += ToHexLiteral(this);
119 135 return s;
120 HRESULT CPluginClass::FinalConstruct() 136 }());
121 { 137
122 return S_OK; 138 m_data.reset();
123 }
124
125 void CPluginClass::FinalRelease()
126 {
127 s_criticalSectionBrowser.Lock();
128 {
129 m_data.reset();
130 }
131 s_criticalSectionBrowser.Unlock();
132 } 139 }
133 140
134 HWND CPluginClass::GetBrowserHWND() const 141 HWND CPluginClass::GetBrowserHWND() const
135 { 142 {
136 SHANDLE_PTR hBrowserWndHandle = NULL; 143 if (!m_data->webBrowser2)
137 144 {
138 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 145 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserHWND - Reached with webBro wser2 == nullptr");
139 if (browser) 146 return nullptr;
140 { 147 }
141 HRESULT hr = browser->get_HWND(&hBrowserWndHandle); 148 SHANDLE_PTR hBrowserWndHandle = 0;
142 if (FAILED(hr)) 149 HRESULT hr = m_data->webBrowser2->get_HWND(&hBrowserWndHandle);
143 { 150 if (FAILED(hr))
144 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, " Class::GetBrowserHWND - failed") 151 {
145 } 152 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, "Cl ass::GetBrowserHWND - failed");
146 } 153 return nullptr;
147 154 }
148 return (HWND)hBrowserWndHandle; 155 return (HWND)hBrowserWndHandle;
149 } 156 }
150 157
151 158 bool CPluginClass::IsRootBrowser(IWebBrowser2* otherBrowser)
152 CComQIPtr<IWebBrowser2> CPluginClass::GetBrowser() const 159 {
160 return m_data->webBrowser2.IsEqualObject(otherBrowser);
161 }
162
163 CComQIPtr<IWebBrowser2> CPluginClass::GetAsyncBrowser()
153 { 164 {
154 CComQIPtr<IWebBrowser2> browser; 165 CComQIPtr<IWebBrowser2> browser;
155 166
156 s_criticalSectionBrowser.Lock(); 167 s_criticalSectionLocal.Lock();
157 { 168 {
158 browser = m_data->webBrowser2; 169 browser = s_asyncWebBrowser2;
159 } 170 }
160 s_criticalSectionBrowser.Unlock(); 171 s_criticalSectionLocal.Unlock();
161 172
162 return browser; 173 return browser;
163 } 174 }
164 175
165
166 CComQIPtr<IWebBrowser2> CPluginClass::GetAsyncBrowser()
167 {
168 CComQIPtr<IWebBrowser2> browser;
169
170 s_criticalSectionLocal.Lock();
171 {
172 browser = s_asyncWebBrowser2;
173 }
174 s_criticalSectionLocal.Unlock();
175
176 return browser;
177 }
178
179 std::wstring CPluginClass::GetBrowserUrl() const 176 std::wstring CPluginClass::GetBrowserUrl() const
180 { 177 {
181 std::wstring url; 178 std::wstring url;
182 CComQIPtr<IWebBrowser2> browser = GetBrowser(); 179 if (m_data->webBrowser2)
183 if (browser)
184 { 180 {
185 CComBSTR bstrURL; 181 CComBSTR bstrURL;
186 if (SUCCEEDED(browser->get_LocationURL(&bstrURL)) && bstrURL) 182 if (SUCCEEDED(m_data->webBrowser2->get_LocationURL(&bstrURL)))
187 { 183 {
188 url = std::wstring(bstrURL, SysStringLen(bstrURL)); 184 url = ToWstring(bstrURL);
189 UnescapeUrl(url);
190 } 185 }
191 } 186 }
192 else 187 else
188 {
189 DEBUG_GENERAL(L"CPluginClass::GetBrowserUrl - Reached with webBrowser2 == nu llptr (probable invariant violation)");
190 }
191 if (url.empty())
193 { 192 {
194 url = m_data->tab->GetDocumentUrl(); 193 url = m_data->tab->GetDocumentUrl();
195 } 194 }
196 return url; 195 return url;
197 } 196 }
198 197
199 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr) 198 DWORD WINAPI CPluginClass::StartInitObject(LPVOID thisPtr)
200 { 199 {
201 if (thisPtr == NULL) 200 if (thisPtr == NULL)
202 return 0; 201 return 0;
(...skipping 14 matching lines...) Expand all
217 * 'unknownSite' will be null. Extraordinarily, this is sometimes _not_ called w hen IE 216 * 'unknownSite' will be null. Extraordinarily, this is sometimes _not_ called w hen IE
218 * is shutting down. Thus 'SetSite(nullptr)' has some similarities with a destru ctor, 217 * is shutting down. Thus 'SetSite(nullptr)' has some similarities with a destru ctor,
219 * but it is not a proper substitute for one. 218 * but it is not a proper substitute for one.
220 */ 219 */
221 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite) 220 STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite)
222 { 221 {
223 try 222 try
224 { 223 {
225 if (unknownSite) 224 if (unknownSite)
226 { 225 {
227 226 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ====================================");
228 DEBUG_GENERAL(L"========================================================== ======================\nNEW TAB UI\n============================================ ====================================")
229 227
230 HRESULT hr = ::CoInitialize(NULL); 228 HRESULT hr = ::CoInitialize(NULL);
231 if (FAILED(hr)) 229 if (FAILED(hr))
232 { 230 {
233 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize"); 231 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_COINIT, "Class::SetSite - CoInitialize");
234 } 232 }
235 233
236 s_criticalSectionBrowser.Lock(); 234 /*
237 { 235 * We were instantiated as a BHO, so our site is always of type IWebBrowse r2.
238 m_data->webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite); 236 */
239 } 237 m_data->webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite);
240 s_criticalSectionBrowser.Unlock(); 238 if (!m_data->webBrowser2)
239 {
240 throw std::logic_error("CPluginClass::SetSite - Unable to convert site p ointer to IWebBrowser2*");
241 }
242 DEBUG_GENERAL([this]() -> std::wstring
243 {
244 std::wstringstream ss;
245 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this);
246 ss << L", browser = " << ToHexLiteral(m_data->webBrowser2);
247 return ss.str();
248 }());
241 249
242 //register the mimefilter 250 //register the mimefilter
243 //and only mimefilter 251 //and only mimefilter
244 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread 252 //on some few computers the mimefilter does not get properly registered wh en it is done on another thread
245
246 s_criticalSectionLocal.Lock(); 253 s_criticalSectionLocal.Lock();
247 { 254 {
248 // Always register on startup, then check if we need to unregister in a separate thread 255 // Always register on startup, then check if we need to unregister in a separate thread
249 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance(); 256 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
250 s_asyncWebBrowser2 = unknownSite; 257 s_asyncWebBrowser2 = unknownSite;
251 s_instances.insert(this); 258 s_instances.insert(this);
252 } 259 }
253 s_criticalSectionLocal.Unlock(); 260 s_criticalSectionLocal.Unlock();
254 261
255 try 262 try
256 { 263 {
257 auto webBrowser = GetBrowser(); 264 HRESULT hr = DispEventAdvise(m_data->webBrowser2);
258 if (webBrowser) 265 if (SUCCEEDED(hr))
259 { 266 {
260 DEBUG_GENERAL("Loaded as BHO"); 267 m_isAdvised = true;
261 HRESULT hr = DispEventAdvise(webBrowser); 268 try
262 if (SUCCEEDED(hr))
263 { 269 {
264 m_isAdvised = true; 270 std::thread startInitObjectThread(StartInitObject, this);
265 try 271 startInitObjectThread.detach(); // TODO: but actually we should wait for the thread in the dtr.
266 {
267 std::thread startInitObjectThread(StartInitObject, this);
268 startInitObjectThread.detach(); // TODO: but actually we should wa it for the thread in the dtr.
269 }
270 catch (const std::system_error& ex)
271 {
272 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_ THREAD_CREATE_PROCESS,
273 "Class::Thread - Failed to create StartInitObject thread");
274 }
275 } 272 }
276 else 273 catch (const std::system_error& ex)
277 { 274 {
278 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADV ICE, "Class::SetSite - Advise"); 275 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH READ_CREATE_PROCESS,
276 "Class::Thread - Failed to create StartInitObject thread");
279 } 277 }
278 }
279 else
280 {
281 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_ADVIC E, "Class::SetSite - Advise");
280 } 282 }
281 } 283 }
282 catch (const std::runtime_error& ex) 284 catch (const std::runtime_error& ex)
283 { 285 {
284 DEBUG_EXCEPTION(ex); 286 DEBUG_EXCEPTION(ex);
285 Unadvise(); 287 Unadvise();
286 } 288 }
287 } 289 }
288 else 290 else
289 { 291 {
292 DEBUG_GENERAL([this]() -> std::wstring
293 {
294 std::wstringstream ss;
295 ss << L"CPluginClass::SetSite, this = " << ToHexLiteral(this);
296 ss << L", browser = nullptr";
297 return ss.str();
298 }());
299
290 Unadvise(); 300 Unadvise();
301 assert(m_data->connectedWebBrowsersCache.empty() && "Connected web browser cache should be already empty");
291 302
292 // Destroy window 303 // Destroy window
293 if (m_pWndProcStatus) 304 if (m_pWndProcStatus)
294 { 305 {
295 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn dProcStatus); 306 ::SetWindowLongPtr(m_hStatusBarWnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)m_pWn dProcStatus);
296 307
297 m_pWndProcStatus = NULL; 308 m_pWndProcStatus = NULL;
298 } 309 }
299 310
300 if (m_hPaneWnd) 311 if (m_hPaneWnd)
(...skipping 19 matching lines...) Expand all
320 s_threadInstances.erase(it); 331 s_threadInstances.erase(it);
321 } 332 }
322 if (s_instances.empty()) 333 if (s_instances.empty())
323 { 334 {
324 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr 335 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr
325 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 336 CPluginClientFactory::ReleaseMimeFilterClientInstance();
326 } 337 }
327 } 338 }
328 s_criticalSectionLocal.Unlock(); 339 s_criticalSectionLocal.Unlock();
329 340
330 // Release browser interface 341 m_data->webBrowser2 = nullptr;
331 s_criticalSectionBrowser.Lock();
332 {
333 m_data->webBrowser2.Release();
334 }
335 s_criticalSectionBrowser.Unlock();
336 342
337 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================") 343 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================")
338 344
339 ::CoUninitialize(); 345 ::CoUninitialize();
340 } 346 }
341 347
342 IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite);
343 } 348 }
344 catch (...) 349 catch (...)
345 { 350 {
346 } 351 }
352 IObjectWithSiteImpl<CPluginClass>::SetSite(unknownSite);
347 return S_OK; 353 return S_OK;
348 } 354 }
349 355
350 bool CPluginClass::IsStatusBarEnabled() 356 bool CPluginClass::IsStatusBarEnabled()
351 { 357 {
352 DEBUG_GENERAL("IsStatusBarEnabled start"); 358 DEBUG_GENERAL("IsStatusBarEnabled start");
353 HKEY pHkey; 359 HKEY pHkey;
354 HKEY pHkeySub; 360 HKEY pHkeySub;
355 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey); 361 RegOpenCurrentUser(KEY_QUERY_VALUE, &pHkey);
356 DWORD truth = 1; 362 DWORD truth = 1;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 { 480 {
475 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; 481 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp;
476 if (!webBrowser) 482 if (!webBrowser)
477 { 483 {
478 return; 484 return;
479 } 485 }
480 if (!urlVariant || urlVariant->vt != VT_BSTR) 486 if (!urlVariant || urlVariant->vt != VT_BSTR)
481 { 487 {
482 return; 488 return;
483 } 489 }
484 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); 490 std::wstring url = ToWstring(urlVariant->bstrVal);
485 UnescapeUrl(url);
486 EnsureWebBrowserConnected(webBrowser); 491 EnsureWebBrowserConnected(webBrowser);
487 //Register a mime filter if it's not registered yet 492
488 if (s_mimeFilter == nullptr)
489 {
490 s_mimeFilter = CPluginClientFactory::GetMimeFilterClientInstance();
491 }
492 // If webbrowser2 is equal to top level browser (as set in SetSite), we are 493 // If webbrowser2 is equal to top level browser (as set in SetSite), we are
493 // navigating new page 494 // navigating new page
494 CPluginClient* client = CPluginClient::GetInstance(); 495 CPluginClient* client = CPluginClient::GetInstance();
495 if (url.find(L"javascript") == 0) 496 if (url.find(L"javascript") == 0)
496 { 497 {
497 } 498 }
498 else if (GetBrowser().IsEqualObject(webBrowser)) 499 else if (IsRootBrowser(webBrowser))
499 { 500 {
500 m_data->tab->OnNavigate(url); 501 m_data->tab->OnNavigate(url);
501 DEBUG_GENERAL( 502 DEBUG_GENERAL(
502 L"======================================================================== ========\n" 503 L"======================================================================== ========\n"
503 L"Begin main navigation url:" + url + L"\n" 504 L"Begin main navigation url:" + url + L"\n"
504 L"======================================================================== ========") 505 L"======================================================================== ========")
505 506
506 #ifdef ENABLE_DEBUG_RESULT 507 #ifdef ENABLE_DEBUG_RESULT
507 CPluginDebug::DebugResultDomain(url); 508 CPluginDebug::DebugResultDomain(url);
508 #endif 509 #endif
509 UpdateStatusBar(); 510 UpdateStatusBar();
510 } 511 }
511 else 512 else
512 { 513 {
513 DEBUG_NAVI(L"Navi::Begin navigation url:" + url) 514 DEBUG_NAVI(L"Navi::Begin navigation url:" + url)
514 m_data->tab->CacheFrame(url); 515 m_data->tab->CacheFrame(url);
515 } 516 }
516 } 517 }
517 catch (...) 518 catch (...)
518 { 519 {
519 } 520 }
520 } 521 }
521 522
522 // Entry point 523 // Entry point
523 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete() 524 void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete()
524 { 525 {
525 try 526 try
526 { 527 {
528 if (!m_data->webBrowser2)
529 {
530 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::OnDownloadComplete - Reached with webBrowser2 == nullptr");
531 return;
532 }
527 DEBUG_NAVI(L"Navi::Download Complete") 533 DEBUG_NAVI(L"Navi::Download Complete")
528 ATL::CComPtr<IWebBrowser2> browser = GetBrowser(); 534 m_data->tab->OnDownloadComplete(m_data->webBrowser2);
529 if (browser)
530 {
531 m_data->tab->OnDownloadComplete(browser);
532 }
533 } 535 }
534 catch (...) 536 catch (...)
535 { 537 {
536 } 538 }
537 } 539 }
538 540
539 // Entry point 541 // Entry point
540 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask) 542 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask)
541 { 543 {
542 try 544 try
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 { 603 {
602 Unadvise(); 604 Unadvise();
603 } 605 }
604 catch (...) 606 catch (...)
605 { 607 {
606 } 608 }
607 } 609 }
608 610
609 bool CPluginClass::InitObject() 611 bool CPluginClass::InitObject()
610 { 612 {
611 DEBUG_GENERAL("InitObject"); 613 DEBUG_GENERAL("InitObject - begin");
612 CPluginSettings* settings = CPluginSettings::GetInstance(); 614 CPluginSettings* settings = CPluginSettings::GetInstance();
613 615
614 if (!settings->GetPluginEnabled()) 616 if (!settings->GetPluginEnabled())
615 { 617 {
616 s_mimeFilter->Unregister(); 618 s_mimeFilter->Unregister();
617 } 619 }
618 620
619 // Load theme module 621 // Load theme module
620 s_criticalSectionLocal.Lock(); 622 s_criticalSectionLocal.Lock();
621 { 623 {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 if (((m_hPaneWnd == NULL) || !IsStatusBarEnabled()) && isFirstRun) 716 if (((m_hPaneWnd == NULL) || !IsStatusBarEnabled()) && isFirstRun)
715 { 717 {
716 ShowStatusBar(); 718 ShowStatusBar();
717 } 719 }
718 720
719 // Enable acceptable ads by default 721 // Enable acceptable ads by default
720 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_e xceptionsurl", L""); 722 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_e xceptionsurl", L"");
721 CPluginClient::GetInstance()->AddSubscription(aaUrl); 723 CPluginClient::GetInstance()->AddSubscription(aaUrl);
722 } 724 }
723 s_criticalSectionLocal.Unlock(); 725 s_criticalSectionLocal.Unlock();
726
727 DEBUG_GENERAL("InitObject - end");
724 return true; 728 return true;
725 } 729 }
726 730
727 bool CPluginClass::CreateStatusBarPane() 731 bool CPluginClass::CreateStatusBarPane()
728 { 732 {
729 CriticalSection::Lock lock(m_csStatusBar); 733 CriticalSection::Lock lock(m_csStatusBar);
730 734
731 CPluginClient* client = CPluginClient::GetInstance(); 735 CPluginClient* client = CPluginClient::GetInstance();
732 736
733 std::array<wchar_t, MAX_PATH> className; 737 std::array<wchar_t, MAX_PATH> className;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 894
891 HDC hdc = GetWindowDC(m_hStatusBarWnd); 895 HDC hdc = GetWindowDC(m_hStatusBarWnd);
892 SendMessage(m_hStatusBarWnd, WM_PAINT, (WPARAM)hdc, 0); 896 SendMessage(m_hStatusBarWnd, WM_PAINT, (WPARAM)hdc, 0);
893 ReleaseDC(m_hStatusBarWnd, hdc); 897 ReleaseDC(m_hStatusBarWnd, hdc);
894 898
895 return true; 899 return true;
896 } 900 }
897 901
898 void CPluginClass::FirstRunThread() 902 void CPluginClass::FirstRunThread()
899 { 903 {
904 // Just return if the First Run Page should be suppressed
905 if (CPluginClient::GetInstance()->GetPref(L"suppress_first_run_page", false))
906 return;
907
900 CoInitialize(NULL); 908 CoInitialize(NULL);
901 VARIANT vFlags; 909 VARIANT vFlags;
902 vFlags.vt = VT_I4; 910 vFlags.vt = VT_I4;
903 vFlags.intVal = navOpenInNewTab; 911 vFlags.intVal = navOpenInNewTab;
904 912
905 CComBSTR navigatePath = CComBSTR(FirstRunPageFileUrl().c_str()); 913 CComBSTR navigatePath = CComBSTR(FirstRunPageFileUrl().c_str());
906 914
907 HRESULT hr = GetAsyncBrowser()->Navigate(navigatePath, &vFlags, NULL, NULL, NU LL); 915 HRESULT hr = GetAsyncBrowser()->Navigate(navigatePath, &vFlags, NULL, NULL, NU LL);
908 if (FAILED(hr)) 916 if (FAILED(hr))
909 { 917 {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 if (it != s_threadInstances.end()) 986 if (it != s_threadInstances.end())
979 { 987 {
980 tab = it->second->m_data->tab.get(); 988 tab = it->second->m_data->tab.get();
981 } 989 }
982 } 990 }
983 s_criticalSectionLocal.Unlock(); 991 s_criticalSectionLocal.Unlock();
984 992
985 return tab; 993 return tab;
986 } 994 }
987 995
988 996 // Entry point
989 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) 997 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText)
990 { 998 {
991 if (cCmds == 0) return E_INVALIDARG; 999 try
992 if (prgCmds == 0) return E_POINTER; 1000 {
993 1001 if (cCmds == 0) return E_INVALIDARG;
994 prgCmds[0].cmdf = OLECMDF_ENABLED; 1002 if (prgCmds == 0) return E_POINTER;
995 1003
1004 prgCmds[0].cmdf = OLECMDF_ENABLED;
1005 }
1006 catch (...)
1007 {
1008 DEBUG_GENERAL(L"CPluginClass::QueryStatus - exception");
1009 return E_FAIL;
1010 }
996 return S_OK; 1011 return S_OK;
997 } 1012 }
998 1013
999 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) 1014 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url)
1000 { 1015 {
1001 DEBUG_GENERAL("CreatePluginMenu"); 1016 DEBUG_GENERAL("CreatePluginMenu");
1002 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); 1017 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance();
1003 1018
1004 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); 1019 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1));
1005 1020
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 if (FAILED(hr)) 1111 if (FAILED(hr))
1097 { 1112 {
1098 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed") 1113 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed")
1099 } 1114 }
1100 } 1115 }
1101 } 1116 }
1102 break; 1117 break;
1103 } 1118 }
1104 case ID_MENU_DISABLE_ON_SITE: 1119 case ID_MENU_DISABLE_ON_SITE:
1105 { 1120 {
1106 CPluginSettings* settings = CPluginSettings::GetInstance();
1107 std::wstring urlString = GetTab()->GetDocumentUrl(); 1121 std::wstring urlString = GetTab()->GetDocumentUrl();
1108 std::string filterText = client->GetWhitelistingFilter(urlString); 1122 std::string filterText = client->GetWhitelistingFilter(urlString);
1109 if (!filterText.empty()) 1123 if (!filterText.empty())
1110 { 1124 {
1111 client->RemoveFilter(filterText); 1125 client->RemoveFilter(filterText);
1112 } 1126 }
1113 else 1127 else
1114 { 1128 {
1115 settings->AddWhiteListedDomain(ToCString(client->GetHostFromUrl(urlStrin g))); 1129 CPluginSettings::GetInstance()->AddWhiteListedDomain(client->GetHostFrom Url(urlString));
1116 } 1130 }
1117 GetBrowser()->Refresh();
1118 } 1131 }
1119 default: 1132 default:
1120 break; 1133 break;
1121 } 1134 }
1122 1135
1123 // Invalidate and redraw the control 1136 // Invalidate and redraw the control
1124 UpdateStatusBar(); 1137 UpdateStatusBar();
1125 } 1138 }
1126 1139
1127 1140
1128 bool CPluginClass::SetMenuBar(HMENU hMenu, const std::wstring& url) 1141 bool CPluginClass::SetMenuBar(HMENU hMenu, const std::wstring& url)
1129 { 1142 {
1130 DEBUG_GENERAL("SetMenuBar"); 1143 DEBUG_GENERAL("SetMenuBar");
1131 1144
1132 std::wstring ctext; 1145 std::wstring ctext;
1133 Dictionary* dictionary = Dictionary::GetInstance(); 1146 Dictionary* dictionary = Dictionary::GetInstance();
1134 1147
1135 MENUITEMINFOW fmii = {}; 1148 MENUITEMINFOW fmii = {};
1136 fmii.cbSize = sizeof(fmii); 1149 fmii.cbSize = sizeof(fmii);
1137 1150
1138 MENUITEMINFOW miiSep = {}; 1151 MENUITEMINFOW miiSep = {};
1139 miiSep.cbSize = sizeof(miiSep); 1152 miiSep.cbSize = sizeof(miiSep);
1140 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE; 1153 miiSep.fMask = MIIM_TYPE | MIIM_FTYPE;
1141 miiSep.fType = MFT_SEPARATOR; 1154 miiSep.fType = MFT_SEPARATOR;
1142 1155
1143 CPluginClient* client = CPluginClient::GetInstance(); 1156 CPluginClient* client = CPluginClient::GetInstance();
1144 CPluginSettings* settings = CPluginSettings::GetInstance(); 1157 CPluginSettings* settings = CPluginSettings::GetInstance();
1145 { 1158 {
1146 ctext = dictionary->Lookup("menu", "menu-disable-on-site"); 1159 ctext = dictionary->Lookup("menu", "menu-disable-on-site");
1147 // Is domain in white list?
1148 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url)); 1160 ReplaceString(ctext, L"?1?", client->GetHostFromUrl(url));
1149 if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl())) 1161 /*
1150 { 1162 * The display state of the "disable on this site" menu item depends upon ta b content
1163 */
1164 if (!GetTab()->IsPossibleToDisableOnSite())
1165 {
1166 // Since we can't disable the present content,
1167 // it makes no sense to offer the user an option to block it.
1168 fmii.fState = MFS_UNCHECKED | MFS_DISABLED;
1169 }
1170 else if (client->IsWhitelistedUrl(GetTab()->GetDocumentUrl()))
1171 {
1172 // Domain is in white list, indicated by a check mark
1151 fmii.fState = MFS_CHECKED | MFS_ENABLED; 1173 fmii.fState = MFS_CHECKED | MFS_ENABLED;
1152 } 1174 }
1153 else 1175 else
1154 { 1176 {
1155 fmii.fState = MFS_UNCHECKED | MFS_ENABLED; 1177 fmii.fState = MFS_UNCHECKED | MFS_ENABLED;
1156 } 1178 }
1157 fmii.fMask = MIIM_STRING | MIIM_STATE; 1179 fmii.fMask = MIIM_STRING | MIIM_STATE;
1158 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1180 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1159 fmii.cch = static_cast<UINT>(ctext.size()); 1181 fmii.cch = static_cast<UINT>(ctext.size());
1160 1182
(...skipping 28 matching lines...) Expand all
1189 ctext = dictionary->Lookup("menu", "menu-settings"); 1211 ctext = dictionary->Lookup("menu", "menu-settings");
1190 fmii.fMask = MIIM_STATE | MIIM_STRING; 1212 fmii.fMask = MIIM_STATE | MIIM_STRING;
1191 fmii.fState = MFS_ENABLED; 1213 fmii.fState = MFS_ENABLED;
1192 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); 1214 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str());
1193 fmii.cch = static_cast<UINT>(ctext.size()); 1215 fmii.cch = static_cast<UINT>(ctext.size());
1194 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii); 1216 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii);
1195 1217
1196 return true; 1218 return true;
1197 } 1219 }
1198 1220
1199 1221 // Entry point
1200 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V ARIANTARG*) 1222 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V ARIANTARG*)
1201 { 1223 {
1202 HWND hBrowserWnd = GetBrowserHWND(); 1224 try
1203 if (!hBrowserWnd) 1225 {
1204 { 1226 HWND hBrowserWnd = GetBrowserHWND();
1205 return E_FAIL; 1227 if (!hBrowserWnd)
1206 } 1228 {
1207 1229 return E_FAIL;
1208 // Create menu 1230 }
1209 HMENU hMenu = CreatePluginMenu(m_data->tab->GetDocumentUrl()); 1231
1210 if (!hMenu) 1232 // Create menu
1211 { 1233 HMENU hMenu = CreatePluginMenu(m_data->tab->GetDocumentUrl());
1212 return E_FAIL; 1234 if (!hMenu)
1213 } 1235 {
1214 1236 return E_FAIL;
1215 // Check if button in toolbar was pressed 1237 }
1216 int nIDCommand = -1; 1238
1217 BOOL bRightAlign = FALSE; 1239 // Check if button in toolbar was pressed
1218 1240 int nIDCommand = -1;
1219 POINT pt; 1241 BOOL bRightAlign = FALSE;
1220 GetCursorPos(&pt); 1242
1221 1243 POINT pt;
1222 HWND hWndToolBar = ::WindowFromPoint(pt); 1244 GetCursorPos(&pt);
1223 1245
1224 DWORD nProcessId; 1246 HWND hWndToolBar = ::WindowFromPoint(pt);
1225 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); 1247
1226 1248 DWORD nProcessId;
1227 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) 1249 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId);
1228 { 1250
1229 ::ScreenToClient(hWndToolBar, &pt); 1251 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId)
1230 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); 1252 {
1231 1253 ::ScreenToClient(hWndToolBar, &pt);
1232 if (nButton > 0) 1254 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt);
1233 { 1255
1234 TBBUTTON pTBBtn = {}; 1256 if (nButton > 0)
1235 1257 {
1236 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) 1258 TBBUTTON pTBBtn = {};
1237 { 1259
1238 RECT rcButton; 1260 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn))
1239 nIDCommand = pTBBtn.idCommand; 1261 {
1240 1262 RECT rcButton;
1241 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton)) 1263 nIDCommand = pTBBtn.idCommand;
1242 { 1264
1243 pt.x = rcButton.left; 1265 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton ))
1244 pt.y = rcButton.bottom;
1245 ClientToScreen(hWndToolBar, &pt);
1246
1247 RECT rcWorkArea;
1248 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0);
1249 if (rcWorkArea.right - pt.x < 150)
1250 { 1266 {
1251 bRightAlign = TRUE; 1267 pt.x = rcButton.left;
1252 pt.x = rcButton.right;
1253 pt.y = rcButton.bottom; 1268 pt.y = rcButton.bottom;
1254 ClientToScreen(hWndToolBar, &pt); 1269 ClientToScreen(hWndToolBar, &pt);
1270
1271 RECT rcWorkArea;
1272 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0);
1273 if (rcWorkArea.right - pt.x < 150)
1274 {
1275 bRightAlign = TRUE;
1276 pt.x = rcButton.right;
1277 pt.y = rcButton.bottom;
1278 ClientToScreen(hWndToolBar, &pt);
1279 }
1255 } 1280 }
1256 } 1281 }
1257 } 1282 }
1283 else
1284 {
1285 GetCursorPos(&pt);
1286 }
1287 }
1288
1289 // Display menu
1290 UINT nFlags = 0;
1291 if (bRightAlign)
1292 {
1293 nFlags |= TPM_RIGHTALIGN;
1258 } 1294 }
1259 else 1295 else
1260 { 1296 {
1261 GetCursorPos(&pt); 1297 nFlags |= TPM_LEFTALIGN;
1262 } 1298 }
1263 } 1299
1264 1300 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags);
1265 // Display menu 1301 }
1266 UINT nFlags = 0; 1302 catch (...)
1267 if (bRightAlign) 1303 {
1268 { 1304 // Suppress exception, log only
1269 nFlags |= TPM_RIGHTALIGN; 1305 DEBUG_GENERAL(L"CPluginClass::Exec - exception");
1270 } 1306 return E_FAIL;
1271 else 1307 }
1272 {
1273 nFlags |= TPM_LEFTALIGN;
1274 }
1275
1276 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags);
1277 1308
1278 return S_OK; 1309 return S_OK;
1279 } 1310 }
1280 1311
1281 ///////////////////////////////////////////////////////////////////////////// 1312 // Entry point
1282 // Window procedures
1283
1284 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa ram, LPARAM lParam) 1313 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa ram, LPARAM lParam)
1285 { 1314 {
1286 // Find tab 1315 CPluginClass *pClass;
1287 CPluginClass *pClass = FindInstance(hWnd); 1316 try
1288 if (!pClass) 1317 {
1289 { 1318 // Find tab
1290 return DefWindowProc(hWnd, message, wParam, lParam); 1319 pClass = FindInstance(hWnd);
1291 } 1320 if (!pClass)
1292 1321 {
1293 // Process message 1322 /*
1294 switch (message) 1323 * Race condition if reached.
1295 { 1324 * We did not unhook the window procedure for the status bar when the last BHO instance using it terminated.
1296 case SB_SIMPLE: 1325 * The next best thing is to call the system default window function.
1297 { 1326 */
1298 ShowWindow(pClass->m_hPaneWnd, !wParam); 1327 return DefWindowProc(hWnd, message, wParam, lParam);
1328 }
1329
1330 // Process message
1331 switch (message)
1332 {
1333 case SB_SIMPLE:
1334 {
1335 ShowWindow(pClass->m_hPaneWnd, !wParam);
1336 break;
1337 }
1338
1339 case WM_SYSCOLORCHANGE:
1340 {
1341 pClass->UpdateTheme();
1342 break;
1343 }
1344
1345 case SB_SETPARTS:
1346 {
1347 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd))
1348 {
1349 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lParam);
1350 }
1351
1352 WPARAM nParts = wParam;
1353 if (STATUSBAR_PANE_NUMBER >= nParts)
1354 {
1355 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lParam);
1356 }
1357
1358 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts + 1));
1359 LPINT lpParts = (LPINT)LocalLock(hLocal);
1360 memcpy(lpParts, (void*)lParam, wParam*sizeof(int));
1361
1362 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++)
1363 {
1364 lpParts[i] -= pClass->m_nPaneWidth;
1365 }
1366 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, w Param, (LPARAM)lpParts);
1367
1368 AdblockPlus::Rectangle rcPane;
1369 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane);
1370
1371 AdblockPlus::Rectangle rcClient;
1372 ::GetClientRect(hWnd, &rcClient);
1373
1374 ::MoveWindow(
1375 pClass->m_hPaneWnd,
1376 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth,
1377 0,
1378 pClass->m_nPaneWidth,
1379 rcClient.Height(),
1380 TRUE);
1381
1382 ::LocalFree(hLocal);
1383 return hRet;
1384 }
1385
1386 default:
1299 break; 1387 break;
1300 } 1388 }
1301 1389 }
1302 case WM_SYSCOLORCHANGE: 1390 catch (...)
1303 { 1391 {
1304 pClass->UpdateTheme(); 1392 // Suppress exception. Fall through to default handler.
1305 break; 1393 DEBUG_GENERAL(L"CPluginClass::NewStatusProc - exception");
1306 } 1394 }
1307 1395 return ::CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lPara m);
1308 case SB_SETPARTS:
1309 {
1310 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd))
1311 {
1312 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l Param);
1313 }
1314
1315 WPARAM nParts = wParam;
1316 if (STATUSBAR_PANE_NUMBER >= nParts)
1317 {
1318 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l Param);
1319 }
1320
1321 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts+1));
1322 LPINT lpParts = (LPINT)LocalLock(hLocal);
1323 memcpy(lpParts, (void*)lParam, wParam*sizeof(int));
1324
1325 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++)
1326 {
1327 lpParts[i] -= pClass->m_nPaneWidth;
1328 }
1329 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPa ram, (LPARAM)lpParts);
1330
1331 AdblockPlus::Rectangle rcPane;
1332 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane);
1333
1334 AdblockPlus::Rectangle rcClient;
1335 ::GetClientRect(hWnd, &rcClient);
1336
1337 ::MoveWindow(
1338 pClass->m_hPaneWnd,
1339 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth,
1340 0,
1341 pClass->m_nPaneWidth,
1342 rcClient.Height(),
1343 TRUE);
1344
1345 ::LocalFree(hLocal);
1346
1347
1348 return hRet;
1349 }
1350
1351 default:
1352 break;
1353 }
1354
1355 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam);
1356
1357
1358 return result;
1359
1360 } 1396 }
1361 1397
1362 1398
1363 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) 1399 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url)
1364 { 1400 {
1365 // use the disable icon as defualt, if the client doesn't exists 1401 // use the disable icon as defualt, if the client doesn't exists
1366 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); 1402 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED);
1367 1403
1368 CPluginTab* tab = GetTab(::GetCurrentThreadId()); 1404 CPluginTab* tab = GetTab(::GetCurrentThreadId());
1369 if (tab) 1405 if (tab)
1370 { 1406 {
1371 CPluginClient* client = CPluginClient::GetInstance(); 1407 CPluginClient* client = CPluginClient::GetInstance();
1372 if (CPluginSettings::GetInstance()->IsPluginEnabled()) 1408 if (CPluginSettings::GetInstance()->IsPluginEnabled())
1373 { 1409 {
1374 if (client->IsWhitelistedUrl(url)) 1410 if (client->IsWhitelistedUrl(url))
1375 { 1411 {
1376 hIcon = GetIcon(ICON_PLUGIN_DISABLED); 1412 hIcon = GetIcon(ICON_PLUGIN_DISABLED);
1377 } 1413 }
1378 else 1414 else
1379 { 1415 {
1380 CPluginSettings* settings = CPluginSettings::GetInstance(); 1416 CPluginSettings* settings = CPluginSettings::GetInstance();
1381 hIcon = GetIcon(ICON_PLUGIN_ENABLED); 1417 hIcon = GetIcon(ICON_PLUGIN_ENABLED);
1382 } 1418 }
1383 } 1419 }
1384 } 1420 }
1385 return hIcon; 1421 return hIcon;
1386 } 1422 }
1387 1423
1388 1424 // Entry point
1389 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP aram, LPARAM lParam) 1425 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP aram, LPARAM lParam)
1390 { 1426 {
1391 // Find tab 1427 try
1392 CPluginClass *pClass = FindInstance(GetParent(hWnd)); 1428 {
1393 if (!pClass) 1429 // Find tab
1394 { 1430 CPluginClass *pClass = FindInstance(GetParent(hWnd));
1395 return ::DefWindowProc(hWnd, message, wParam, lParam); 1431 if (!pClass)
1396 } 1432 {
1397 1433 return ::DefWindowProc(hWnd, message, wParam, lParam);
1398 // Process message 1434 }
1399 switch (message) 1435
1400 { 1436 // Process message
1401 1437 switch (message)
1402 case WM_SETCURSOR: 1438 {
1403 { 1439 case WM_SETCURSOR:
1404 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); 1440 {
1405 return TRUE; 1441 ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
1406 } 1442 return TRUE;
1407 case WM_PAINT: 1443 }
1408 { 1444 case WM_PAINT:
1409 PAINTSTRUCT ps; 1445 {
1410 HDC hDC = ::BeginPaint(hWnd, &ps); 1446 PAINTSTRUCT ps;
1411 1447 HDC hDC = ::BeginPaint(hWnd, &ps);
1412 AdblockPlus::Rectangle rcClient; 1448
1413 ::GetClientRect(hWnd, &rcClient); 1449 AdblockPlus::Rectangle rcClient;
1414 1450 ::GetClientRect(hWnd, &rcClient);
1415 int nDrawEdge = 0; 1451
1416 1452 int nDrawEdge = 0;
1417 // Old Windows background drawing 1453
1418 if (pClass->m_hTheme == NULL) 1454 // Old Windows background drawing
1419 { 1455 if (pClass->m_hTheme == NULL)
1420 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); 1456 {
1421 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); 1457 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1));
1422 1458 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT);
1423 nDrawEdge = 3; 1459
1424 rcClient.left += 3; 1460 nDrawEdge = 3;
1425 1461 rcClient.left += 3;
1426 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); 1462
1427 } 1463 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT);
1428 // Themed background drawing 1464 }
1429 else 1465 // Themed background drawing
1430 { 1466 else
1431 // Draw background 1467 {
1432 if (pfnDrawThemeBackground) 1468 // Draw background
1433 { 1469 if (pfnDrawThemeBackground)
1434 AdblockPlus::Rectangle rc = rcClient;
1435 rc.right -= 2;
1436 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL);
1437 }
1438
1439 // Copy separator picture to left side
1440 int nHeight = rcClient.Height();
1441 int nWidth = rcClient.Width() - 2;
1442
1443 for (int i = 0; i < 2; i++)
1444 {
1445 for (int j = 0; j < nHeight; j++)
1446 { 1470 {
1447 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); 1471 AdblockPlus::Rectangle rc = rcClient;
1448 1472 rc.right -= 2;
1449 // Ignore black boxes (if source is obscured by other windows) 1473 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL);
1450 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetBVa lue(clr) > 8)) 1474 }
1475
1476 // Copy separator picture to left side
1477 int nHeight = rcClient.Height();
1478 int nWidth = rcClient.Width() - 2;
1479
1480 for (int i = 0; i < 2; i++)
1481 {
1482 for (int j = 0; j < nHeight; j++)
1451 { 1483 {
1452 ::SetPixel(hDC, i, j, clr); 1484 COLORREF clr = ::GetPixel(hDC, i + nWidth, j);
1485
1486 // Ignore black boxes (if source is obscured by other windows)
1487 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetB Value(clr) > 8))
1488 {
1489 ::SetPixel(hDC, i, j, clr);
1490 }
1453 } 1491 }
1454 } 1492 }
1455 } 1493 }
1456 } 1494
1457 1495 // Draw icon
1458 // Draw icon 1496 if (CPluginClient::GetInstance())
1459 if (CPluginClient::GetInstance()) 1497 {
1460 { 1498 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl());
1461 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); 1499
1462 1500 int offx = nDrawEdge;
1463 int offx = nDrawEdge; 1501 if (hIcon)
1464 if (hIcon) 1502 {
1465 { 1503 //Get the RECT for the leftmost pane (the status text pane)
1466 //Get the RECT for the leftmost pane (the status text pane) 1504 RECT rect;
1505 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, (LPARAM)&rect);
1506 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, ico nWidth, iconHeight, NULL, NULL, DI_NORMAL);
1507 offx += iconWidth;
1508 }
1509 #ifdef _DEBUG
1510 // Display version
1511 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT , 0, 0);
1512 HGDIOBJ hOldFont = ::SelectObject(hDC, hFont);
1513
1514 AdblockPlus::Rectangle rcText = rcClient;
1515 rcText.left += offx;
1516 ::SetBkMode(hDC, TRANSPARENT);
1517 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS | DT_ LEFT | DT_SINGLELINE | DT_VCENTER);
1518
1519 ::SelectObject(hDC, hOldFont);
1520 #endif // _DEBUG
1521 }
1522
1523 // Done!
1524 EndPaint(hWnd, &ps);
1525
1526 return 0;
1527 }
1528
1529 case WM_LBUTTONUP:
1530 case WM_RBUTTONUP:
1531 {
1532 std::wstring url = pClass->GetBrowserUrl();
1533 if (url != pClass->GetTab()->GetDocumentUrl())
1534 {
1535 pClass->GetTab()->SetDocumentUrl(url);
1536 }
1537
1538 // Create menu
1539 HMENU hMenu = pClass->CreatePluginMenu(url);
1540 if (!hMenu)
1541 {
1542 return 0;
1543 }
1544
1545 // Display menu
1546 POINT pt;
1547 ::GetCursorPos(&pt);
1548
1549 RECT rc;
1550 ::GetWindowRect(hWnd, &rc);
1551
1552 if (rc.left >= 0 && rc.top >= 0)
1553 {
1554 pt.x = rc.left;
1555 pt.y = rc.top;
1556 }
1557
1558 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN | TPM_BOTTOMALIGN );
1559 break;
1560 }
1561 case WM_DESTROY:
1562 break;
1563 case SC_CLOSE:
1564 break;
1565
1566 case WM_UPDATEUISTATE:
1567 {
1568 CPluginTab* tab = GetTab(::GetCurrentThreadId());
1569 if (tab)
1570 {
1571 tab->OnActivate();
1467 RECT rect; 1572 RECT rect;
1468 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, ( LPARAM)&rect); 1573 GetWindowRect(pClass->m_hPaneWnd, &rect);
1469 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, iconW idth, iconHeight, NULL, NULL, DI_NORMAL); 1574 pClass->notificationMessage.MoveToCenter(rect);
1470 offx += iconWidth; 1575 }
1471 } 1576 if (LOWORD(wParam) == UIS_CLEAR)
1472 #ifdef _DEBUG 1577 {
1473 // Display version 1578 pClass->notificationMessage.Hide();
1474 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT, 0, 0); 1579 }
1475 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont); 1580 break;
1476 1581 }
1477 AdblockPlus::Rectangle rcText = rcClient; 1582 case WM_WINDOWPOSCHANGING:
1478 rcText.left += offx; 1583 {
1479 ::SetBkMode(hDC, TRANSPARENT);
1480 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS|DT_LEFT |DT_SINGLELINE|DT_VCENTER);
1481
1482 ::SelectObject(hDC, hOldFont);
1483 #endif // _DEBUG
1484 }
1485
1486 // Done!
1487 EndPaint(hWnd, &ps);
1488
1489 return 0;
1490 }
1491
1492 case WM_LBUTTONUP:
1493 case WM_RBUTTONUP:
1494 {
1495 std::wstring url = pClass->GetBrowserUrl();
1496 if (url != pClass->GetTab()->GetDocumentUrl())
1497 {
1498 pClass->GetTab()->SetDocumentUrl(url);
1499 }
1500
1501 // Create menu
1502 HMENU hMenu = pClass->CreatePluginMenu(url);
1503 if (!hMenu)
1504 {
1505 return 0;
1506 }
1507
1508 // Display menu
1509 POINT pt;
1510 ::GetCursorPos(&pt);
1511
1512 RECT rc;
1513 ::GetWindowRect(hWnd, &rc);
1514
1515 if (rc.left >= 0 && rc.top >= 0)
1516 {
1517 pt.x = rc.left;
1518 pt.y = rc.top;
1519 }
1520
1521 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN|TPM_BOTTOMALIGN);
1522 }
1523 break;
1524 case WM_DESTROY:
1525 break;
1526 case SC_CLOSE:
1527 break;
1528
1529 case WM_UPDATEUISTATE:
1530 {
1531 CPluginTab* tab = GetTab(::GetCurrentThreadId());
1532 if (tab)
1533 {
1534 tab->OnActivate();
1535 RECT rect; 1584 RECT rect;
1536 GetWindowRect(pClass->m_hPaneWnd, &rect); 1585 GetWindowRect(pClass->m_hPaneWnd, &rect);
1537 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2); 1586 if (pClass->notificationMessage.IsVisible())
1538 } 1587 {
1539 if (LOWORD(wParam) == UIS_CLEAR) 1588 pClass->notificationMessage.MoveToCenter(rect);
1540 { 1589 }
1541 pClass->notificationMessage.Hide(); 1590 break;
1542 } 1591 }
1543 } 1592 case WM_WINDOWPOSCHANGED:
1544 break; 1593 {
1545 case WM_WINDOWPOSCHANGING: 1594 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam);
1546 { 1595 if (wndPos->flags & SWP_HIDEWINDOW)
1547 RECT rect; 1596 {
1548 GetWindowRect(pClass->m_hPaneWnd, &rect); 1597 pClass->notificationMessage.Hide();
1549 if (pClass->notificationMessage.IsVisible()) 1598 }
1550 { 1599 break;
1551 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2); 1600 }
1552 } 1601 case WM_ALREADY_UP_TO_DATE:
1553 } 1602 {
1554 break; 1603 Dictionary* dictionary = Dictionary::GetInstance();
1555 case WM_WINDOWPOSCHANGED: 1604 std::wstring upToDateText = dictionary->Lookup("updater", "update-alread y-up-to-date-text");
1556 { 1605 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-alrea dy-up-to-date-title");
1557 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam); 1606 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle, TTI_INFO);
1558 if (wndPos->flags & SWP_HIDEWINDOW) 1607 break;
1559 { 1608 }
1560 pClass->notificationMessage.Hide(); 1609 case WM_UPDATE_CHECK_ERROR:
1561 } 1610 {
1562 } 1611 Dictionary* dictionary = Dictionary::GetInstance();
1563 break; 1612 std::wstring errorText = dictionary->Lookup("updater", "update-error-tex t");
1564 case WM_ALREADY_UP_TO_DATE: 1613 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-ti tle");
1565 { 1614 pClass->notificationMessage.SetTextAndIcon(errorText, errorTitle, TTI_ER ROR);
1566 Dictionary* dictionary = Dictionary::GetInstance(); 1615 break;
1567 std::wstring upToDateText = dictionary->Lookup("updater", "update-already- up-to-date-text"); 1616 }
1568 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-already -up-to-date-title"); 1617 case WM_DOWNLOADING_UPDATE:
1569 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle, TT I_INFO); 1618 {
1570 } 1619 Dictionary* dictionary = Dictionary::GetInstance();
1571 break; 1620 std::wstring downloadingText = dictionary->Lookup("updater", "downloadin g-update-text");
1572 case WM_UPDATE_CHECK_ERROR: 1621 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloadi ng-update-title");
1573 { 1622 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingT itle, TTI_INFO);
1574 Dictionary* dictionary = Dictionary::GetInstance(); 1623 break;
1575 std::wstring errorText = dictionary->Lookup("updater", "update-error-text" ); 1624 }
1576 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-titl e"); 1625 }
1577 pClass->notificationMessage.SetTextAndIcon(errorText, errorText, TTI_ERROR ); 1626 }
1578 } 1627 catch (...)
1579 break; 1628 {
1580 case WM_DOWNLOADING_UPDATE: 1629 // Suppress exception. Fall through to default handler.
1581 { 1630 DEBUG_GENERAL(L"CPluginClass::PaneWindowProc - exception");
1582 Dictionary* dictionary = Dictionary::GetInstance(); 1631 }
1583 std::wstring downloadingText = dictionary->Lookup("updater", "downloading- update-text"); 1632 return ::DefWindowProc(hWnd, message, wParam, lParam);
1584 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloading -update-title");
1585 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingTit le, TTI_INFO);
1586 }
1587 break;
1588 }
1589
1590 return DefWindowProc(hWnd, message, wParam, lParam);
1591 } 1633 }
1592 1634
1593 1635
1594 void CPluginClass::UpdateStatusBar() 1636 void CPluginClass::UpdateStatusBar()
1595 { 1637 {
1596 DEBUG_GENERAL("*** Updating statusbar") 1638 DEBUG_GENERAL("*** Updating statusbar")
1597 if (m_hPaneWnd == NULL) 1639 if (m_hPaneWnd == NULL)
1598 { 1640 {
1599 CreateStatusBarPane(); 1641 CreateStatusBarPane();
1600 } 1642 }
1601 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE)) 1643 if ((m_hPaneWnd != NULL) && !::InvalidateRect(m_hPaneWnd, NULL, FALSE))
1602 { 1644 {
1603 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar"); 1645 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_INVALID ATE_STATUSBAR, "Class::Invalidate statusbar");
1604 } 1646 }
1605 } 1647 }
1606 1648
1607 void CPluginClass::Unadvise() 1649 void CPluginClass::Unadvise()
1608 { 1650 {
1651 if (!m_data->webBrowser2)
1652 {
1653 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::Unadvise - Reached with webBrowser2 == nullptr");
1654 return;
1655 }
1609 s_criticalSectionLocal.Lock(); 1656 s_criticalSectionLocal.Lock();
1610 { 1657 {
1611 if (m_isAdvised) 1658 if (m_isAdvised)
1612 { 1659 {
1613 HRESULT hr = DispEventUnadvise(GetBrowser()); 1660 HRESULT hr = DispEventUnadvise(m_data->webBrowser2);
1614 if (FAILED(hr)) 1661 if (FAILED(hr))
1615 { 1662 {
1616 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise"); 1663 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SET_SITE, PLUGIN_ERROR_SET_SITE_UNADVIS E, "Class::Unadvise - Unadvise");
1617 } 1664 }
1618 m_isAdvised = false; 1665 m_isAdvised = false;
1619 } 1666 }
1620 } 1667 }
1621 s_criticalSectionLocal.Unlock(); 1668 s_criticalSectionLocal.Unlock();
1622 } 1669 }
1623 1670
(...skipping 11 matching lines...) Expand all
1635 } 1682 }
1636 ATL::CComPtr<IUnknown> listenerRefCounterGuard(listenerImpl->GetUnknown()); 1683 ATL::CComPtr<IUnknown> listenerRefCounterGuard(listenerImpl->GetUnknown());
1637 std::weak_ptr<Data> dataForCapturing = m_data; 1684 std::weak_ptr<Data> dataForCapturing = m_data;
1638 auto onListenerDestroy = [webBrowser, dataForCapturing] 1685 auto onListenerDestroy = [webBrowser, dataForCapturing]
1639 { 1686 {
1640 if (auto data = dataForCapturing.lock()) 1687 if (auto data = dataForCapturing.lock())
1641 { 1688 {
1642 data->connectedWebBrowsersCache.erase(webBrowser); 1689 data->connectedWebBrowsersCache.erase(webBrowser);
1643 } 1690 }
1644 }; 1691 };
1645 if (FAILED(listenerImpl->Init(webBrowser, onListenerDestroy))) 1692 auto onReloaded = [webBrowser, dataForCapturing]
1693 {
1694 if (auto data = dataForCapturing.lock())
1695 {
1696 auto frameSrc = GetLocationUrl(*webBrowser);
1697 data->tab->OnDocumentComplete(webBrowser, frameSrc, data->webBrowser2.IsEq ualObject(webBrowser));
1698 }
1699 };
1700 if (FAILED(listenerImpl->Init(webBrowser, onListenerDestroy, onReloaded)))
1646 { 1701 {
1647 return; 1702 return;
1648 } 1703 }
1649 listenerImpl->reloaded = [webBrowser, dataForCapturing]
1650 {
1651 if (auto data = dataForCapturing.lock())
1652 {
1653 auto frameSrc = GetLocationUrl(*webBrowser);
1654 UnescapeUrl(frameSrc);
1655 data->tab->OnDocumentComplete(webBrowser, frameSrc, data->webBrowser2.IsEq ualObject(webBrowser));
1656 }
1657 };
1658 m_data->connectedWebBrowsersCache.emplace(webBrowser, listenerImpl); 1704 m_data->connectedWebBrowsersCache.emplace(webBrowser, listenerImpl);
1659 } 1705 }
1660 1706
1661 HICON CPluginClass::GetIcon(int type) 1707 HICON CPluginClass::GetIcon(int type)
1662 { 1708 {
1663 HICON icon = NULL; 1709 HICON icon = NULL;
1664 1710
1665 s_criticalSectionLocal.Lock(); 1711 s_criticalSectionLocal.Lock();
1666 { 1712 {
1667 if (!s_hIcons[type]) 1713 if (!s_hIcons[type])
(...skipping 12 matching lines...) Expand all
1680 s_criticalSectionLocal.Unlock(); 1726 s_criticalSectionLocal.Unlock();
1681 1727
1682 return icon; 1728 return icon;
1683 } 1729 }
1684 1730
1685 ATOM CPluginClass::GetAtomPaneClass() 1731 ATOM CPluginClass::GetAtomPaneClass()
1686 { 1732 {
1687 return s_atomPaneClass; 1733 return s_atomPaneClass;
1688 } 1734 }
1689 1735
1690 HWND CPluginClass::GetTabHWND() const
1691 {
1692 std::array<wchar_t, MAX_PATH> className;
1693 // Get browser window and url
1694 HWND hBrowserWnd = GetBrowserHWND();
1695 if (!hBrowserWnd)
1696 {
1697 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_NO_STATUSBAR_BROWSER, "C lass::GetTabWindow - No tab window")
1698 s_criticalSectionWindow.Unlock();
1699
1700 return false;
1701 }
1702
1703 // Looking for a TabWindowClass window in IE7
1704
1705 HWND hTabWnd = ::GetWindow(hBrowserWnd, GW_CHILD);
1706 while (hTabWnd)
1707 {
1708 className[0] = L'\0';
1709 int classNameLength = GetClassNameW(hTabWnd, className.data(), className.siz e());
1710
1711 if (classNameLength && (wcscmp(className.data(), L"TabWindowClass") == 0 || wcscmp(className.data(), L"Frame Tab") == 0))
1712 {
1713 // IE8 support
1714 HWND hTabWnd2 = hTabWnd;
1715 if (wcscmp(className.data(), L"Frame Tab") == 0)
1716 {
1717 hTabWnd2 = ::FindWindowEx(hTabWnd2, NULL, L"TabWindowClass", NULL);
1718 }
1719
1720 if (hTabWnd2)
1721 {
1722 DWORD nProcessId;
1723 ::GetWindowThreadProcessId(hTabWnd2, &nProcessId);
1724 if (::GetCurrentProcessId() == nProcessId)
1725 {
1726 bool bExistingTab = false;
1727 s_criticalSectionLocal.Lock();
1728
1729 {
1730 for (auto instance : s_instances)
1731 {
1732 if (instance->m_hTabWnd == hTabWnd2)
1733 {
1734 bExistingTab = true;
1735 break;
1736 }
1737 }
1738 }
1739
1740 if (!bExistingTab)
1741 {
1742 hBrowserWnd = hTabWnd2;
1743 hTabWnd = hTabWnd2;
1744 s_criticalSectionLocal.Unlock();
1745 break;
1746 }
1747 s_criticalSectionLocal.Unlock();
1748
1749 }
1750 }
1751 }
1752
1753 hTabWnd = ::GetWindow(hTabWnd, GW_HWNDNEXT);
1754 }
1755 return hTabWnd;
1756 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld