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

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

Issue 29323561: Issue #3383 - Rewrite and simplify browser-site handling in CPluginClass (Closed)
Left Patch Set: change type of m_webBrowser2 Created Nov. 18, 2015, 6:08 p.m.
Right Patch Set: initialization; shorten comment Created Dec. 3, 2015, 2:23 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') | no next file » | 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-2015 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
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 84
85 int Width() const 85 int Width() const
86 { 86 {
87 return right - left; 87 return right - left;
88 } 88 }
89 }; 89 };
90 } 90 }
91 91
92 CPluginClass::CPluginClass() 92 CPluginClass::CPluginClass()
93 : m_webBrowser2(nullptr) 93 : m_webBrowser2(nullptr)
sergei 2015/11/30 15:52:08 We don't need it because ATL::CComPtr default cons
Eric 2015/11/30 16:31:51 I'd rather have it explicit as a lightweight form
sergei 2015/12/07 10:49:08 ATL::CComPtr initializes it to nullptr in the cons
Eric 2015/12/07 14:04:12 The very-lightweight documentation is that every v
sergei 2015/12/08 09:41:59 I think it will go away in a future and I don't un
sergei 2015/12/08 09:41:59 It sounds not convincing. Why are we not doing it
94 { 94 {
95 //Use this line to debug memory leaks 95 //Use this line to debug memory leaks
96 // _CrtDumpMemoryLeaks(); 96 // _CrtDumpMemoryLeaks();
97 97
98 m_isAdvised = false; 98 m_isAdvised = false;
99 m_hTabWnd = NULL; 99 m_hTabWnd = NULL;
100 m_hStatusBarWnd = NULL; 100 m_hStatusBarWnd = NULL;
101 m_hPaneWnd = NULL; 101 m_hPaneWnd = NULL;
102 m_nPaneWidth = 0; 102 m_nPaneWidth = 0;
103 m_pWndProcStatus = NULL; 103 m_pWndProcStatus = NULL;
(...skipping 11 matching lines...) Expand all
115 delete m_tab; 115 delete m_tab;
116 } 116 }
117 117
118 HWND CPluginClass::GetBrowserHWND() const 118 HWND CPluginClass::GetBrowserHWND() const
119 { 119 {
120 if (!m_webBrowser2) 120 if (!m_webBrowser2)
121 { 121 {
122 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserHWND - Reached with m_webB rowser2 == nullptr"); 122 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserHWND - Reached with m_webB rowser2 == nullptr");
123 return nullptr; 123 return nullptr;
124 } 124 }
125 SHANDLE_PTR hBrowserWndHandle; 125 SHANDLE_PTR hBrowserWndHandle = 0;
sergei 2015/11/30 15:52:09 it would be good to initialize it to NULL.
Eric 2015/11/30 16:31:51 Welcome to MicrosoftLand. SHANDLE_PTR is not a poi
Oleksandr 2015/12/03 11:51:58 We don't check its value now, but we might in futu
Eric 2015/12/03 14:24:54 Initialized it to zero, which matches its type. A
sergei 2015/12/07 10:49:08 Agree, except following some good practices, like
sergei 2015/12/07 10:49:08 Although zero is OK, NULL looks better here.
Eric 2015/12/07 14:04:12 I disagree. Sometimes NULL is defined as '(void*)0
Eric 2015/12/07 14:04:12 Almost always. But even saying that is saying too
126 HRESULT hr = m_webBrowser2->get_HWND(&hBrowserWndHandle); 126 HRESULT hr = m_webBrowser2->get_HWND(&hBrowserWndHandle);
127 if (FAILED(hr)) 127 if (FAILED(hr))
128 { 128 {
129 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, "Cl ass::GetBrowserHWND - failed") 129 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_GET_BROWSER_WINDOW, "Cl ass::GetBrowserHWND - failed");
sergei 2015/11/30 15:52:08 Actually, I think we should return nullptr in case
Eric 2015/11/30 16:31:51 Done. That's a good idea.
130 return nullptr;
130 } 131 }
131 return (HWND)hBrowserWndHandle; 132 return (HWND)hBrowserWndHandle;
132 } 133 }
133 134
134 bool CPluginClass::IsRootBrowser(IWebBrowser2* otherBrowser) 135 bool CPluginClass::IsRootBrowser(IWebBrowser2* otherBrowser)
135 { 136 {
136 return m_webBrowser2.IsEqualObject(otherBrowser); 137 return m_webBrowser2.IsEqualObject(otherBrowser);
137 } 138 }
138 139
139 CComQIPtr<IWebBrowser2> CPluginClass::GetAsyncBrowser() 140 CComQIPtr<IWebBrowser2> CPluginClass::GetAsyncBrowser()
(...skipping 11 matching lines...) Expand all
151 152
152 std::wstring CPluginClass::GetBrowserUrl() const 153 std::wstring CPluginClass::GetBrowserUrl() const
153 { 154 {
154 std::wstring url; 155 std::wstring url;
155 if (m_webBrowser2) 156 if (m_webBrowser2)
156 { 157 {
157 CComBSTR bstrURL; 158 CComBSTR bstrURL;
158 if (SUCCEEDED(m_webBrowser2->get_LocationURL(&bstrURL)) && bstrURL) 159 if (SUCCEEDED(m_webBrowser2->get_LocationURL(&bstrURL)) && bstrURL)
159 { 160 {
160 url = std::wstring(bstrURL, SysStringLen(bstrURL)); 161 url = std::wstring(bstrURL, SysStringLen(bstrURL));
161 UnescapeUrl(url);
162 } 162 }
163 } 163 }
164 else 164 else
165 { 165 {
166 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserUrl - Reached with m_webBr owser2 == nullptr"); 166 DEBUG_ERROR_LOG(0, 0, 0, "CPluginClass::GetBrowserUrl - Reached with m_webBr owser2 == nullptr");
167 url = m_tab->GetDocumentUrl(); 167 url = m_tab->GetDocumentUrl();
168 } 168 }
169 return url; 169 return url;
170 } 170 }
171 171
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 { 290 {
291 s_threadInstances.erase(it); 291 s_threadInstances.erase(it);
292 } 292 }
293 if (s_instances.empty()) 293 if (s_instances.empty())
294 { 294 {
295 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr 295 // TODO: Explicitly releasing a resource when a container becomes empt y looks like a job better suited for shared_ptr
296 CPluginClientFactory::ReleaseMimeFilterClientInstance(); 296 CPluginClientFactory::ReleaseMimeFilterClientInstance();
297 } 297 }
298 } 298 }
299 s_criticalSectionLocal.Unlock(); 299 s_criticalSectionLocal.Unlock();
300
301 m_webBrowser2 = nullptr;
300 302
301 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================") 303 DEBUG_GENERAL("=========================================================== =====================\nNEW TAB UI - END\n======================================= =========================================")
302 304
303 ::CoUninitialize(); 305 ::CoUninitialize();
304 } 306 }
305 307
306 } 308 }
307 catch (...) 309 catch (...)
308 { 310 {
309 } 311 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp; 441 ATL::CComQIPtr<IWebBrowser2> webBrowser = frameBrowserDisp;
440 if (!webBrowser) 442 if (!webBrowser)
441 { 443 {
442 return; 444 return;
443 } 445 }
444 if (!urlVariant || urlVariant->vt != VT_BSTR) 446 if (!urlVariant || urlVariant->vt != VT_BSTR)
445 { 447 {
446 return; 448 return;
447 } 449 }
448 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal)); 450 std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal));
449 UnescapeUrl(url);
450 451
451 // If webbrowser2 is equal to top level browser (as set in SetSite), we are 452 // If webbrowser2 is equal to top level browser (as set in SetSite), we are
452 // navigating new page 453 // navigating new page
453 CPluginClient* client = CPluginClient::GetInstance(); 454 CPluginClient* client = CPluginClient::GetInstance();
454 if (url.find(L"javascript") == 0) 455 if (url.find(L"javascript") == 0)
455 { 456 {
456 } 457 }
457 else if (IsRootBrowser(webBrowser)) 458 else if (IsRootBrowser(webBrowser))
458 { 459 {
459 m_tab->OnNavigate(url); 460 m_tab->OnNavigate(url);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 { 502 {
502 try 503 try
503 { 504 {
504 DEBUG_NAVI(L"Navi::Document Complete"); 505 DEBUG_NAVI(L"Navi::Document Complete");
505 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp; 506 ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp;
506 if (!webBrowser2) 507 if (!webBrowser2)
507 { 508 {
508 return; 509 return;
509 } 510 }
510 std::wstring frameSrc = GetLocationUrl(*webBrowser2); 511 std::wstring frameSrc = GetLocationUrl(*webBrowser2);
511 UnescapeUrl(frameSrc);
512 m_tab->OnDocumentComplete(webBrowser2, frameSrc, IsRootBrowser(webBrowser2)) ; 512 m_tab->OnDocumentComplete(webBrowser2, frameSrc, IsRootBrowser(webBrowser2)) ;
513 } 513 }
514 catch (...) 514 catch (...)
515 { 515 {
516 } 516 }
517 } 517 }
518 518
519 // Entry point 519 // Entry point
520 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask) 520 void STDMETHODCALLTYPE CPluginClass::OnWindowStateChanged(unsigned long flags, u nsigned long validFlagsMask)
521 { 521 {
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 if (FAILED(hr)) 1082 if (FAILED(hr))
1083 { 1083 {
1084 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed") 1084 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_NAVIGATION, PLUGIN_ERROR_NAVIGATION _SETTINGS, "Navigation::Failed")
1085 } 1085 }
1086 } 1086 }
1087 } 1087 }
1088 break; 1088 break;
1089 } 1089 }
1090 case ID_MENU_DISABLE_ON_SITE: 1090 case ID_MENU_DISABLE_ON_SITE:
1091 { 1091 {
1092 CPluginSettings* settings = CPluginSettings::GetInstance();
1093 std::wstring urlString = GetTab()->GetDocumentUrl(); 1092 std::wstring urlString = GetTab()->GetDocumentUrl();
1094 std::string filterText = client->GetWhitelistingFilter(urlString); 1093 std::string filterText = client->GetWhitelistingFilter(urlString);
1095 if (!filterText.empty()) 1094 if (!filterText.empty())
1096 { 1095 {
1097 client->RemoveFilter(filterText); 1096 client->RemoveFilter(filterText);
1098 } 1097 }
1099 else 1098 else
1100 { 1099 {
1101 settings->AddWhiteListedDomain(ToCString(client->GetHostFromUrl(urlStrin g))); 1100 CPluginSettings::GetInstance()->AddWhiteListedDomain(client->GetHostFrom Url(urlString));
1102 } 1101 }
1103 } 1102 }
1104 default: 1103 default:
1105 break; 1104 break;
1106 } 1105 }
1107 1106
1108 // Invalidate and redraw the control 1107 // Invalidate and redraw the control
1109 UpdateStatusBar(); 1108 UpdateStatusBar();
1110 } 1109 }
1111 1110
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 s_criticalSectionLocal.Unlock(); 1633 s_criticalSectionLocal.Unlock();
1635 1634
1636 return icon; 1635 return icon;
1637 } 1636 }
1638 1637
1639 ATOM CPluginClass::GetAtomPaneClass() 1638 ATOM CPluginClass::GetAtomPaneClass()
1640 { 1639 {
1641 return s_atomPaneClass; 1640 return s_atomPaneClass;
1642 } 1641 }
1643 1642
LEFTRIGHT

Powered by Google App Engine
This is Rietveld