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

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

Issue 5670602698391552: Issue #1234 - Remove CString local variable from CPluginTabBase::InjectABP (Closed)
Left Patch Set: Created May 20, 2015, 3:52 p.m.
Right Patch Set: address comments, rebased Created June 10, 2015, 6:27 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 | « no previous file | 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
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 #include "AdblockPlusClient.h"
20 #include "PluginClient.h" 20 #include "PluginClientBase.h"
21 #include "PluginSettings.h" 21 #include "PluginSettings.h"
22 #include "AdblockPlusDomTraverser.h" 22 #include "AdblockPlusDomTraverser.h"
23 #include "PluginClass.h"
24 #include "PluginTabBase.h" 23 #include "PluginTabBase.h"
25 #include "PluginUtil.h"
26 #include "IeVersion.h" 24 #include "IeVersion.h"
27 #include <dispex.h>
28 #include <Mshtmhst.h> 25 #include <Mshtmhst.h>
29 26
30 CPluginTabBase::CPluginTabBase(CPluginClass* plugin) 27 CPluginTabBase::CPluginTabBase(CPluginClass* plugin)
31 : m_plugin(plugin) 28 : m_plugin(plugin)
32 , m_isActivated(false) 29 , m_isActivated(false)
33 , m_continueThreadRunning(true) 30 , m_continueThreadRunning(true)
34 { 31 {
35 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); 32 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter());
36 m_filter->hideFiltersLoadedEvent = CreateEvent(NULL, true, false, NULL); 33 m_filter->hideFiltersLoadedEvent = CreateEvent(NULL, true, false, NULL);
37 34
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 m_traverser->ClearCache(); 108 m_traverser->ClearCache();
112 } 109 }
113 110
114 namespace 111 namespace
115 { 112 {
116 /** 113 /**
117 * Determine if the HTML file is one of ours. 114 * Determine if the HTML file is one of ours.
118 * The criterion is that it appear in the "html/templates" folder within our i nstallation. 115 * The criterion is that it appear in the "html/templates" folder within our i nstallation.
119 * 116 *
120 * Warning: This function may fail if the argument is not a "file://" URL. 117 * Warning: This function may fail if the argument is not a "file://" URL.
121 * This is occasionally the case in circumstances yet to be characterized. 118 * This is occasionally the case in circumstances yet to be characterized.
Eric 2015/05/20 15:56:32 I see this happen under the debugger regularly, bu
sergei 2015/06/01 09:41:30 I see that it's sometimes in MS-DOS/Windows-style
Eric 2015/06/10 18:30:36 If you'd like to add text to the comment, please p
122 */ 119 */
123 bool IsOurHtmlFile(std::wstring url) 120 bool IsOurHtmlFile(const std::wstring& url)
sergei 2015/06/01 09:41:30 const ref
Eric 2015/06/10 18:30:36 Done.
124 { 121 {
125 // Declared static because the value is derived from an installation directo ry, which won't change during run-time. 122 // Declared static because the value is derived from an installation directo ry, which won't change during run-time.
126 static auto dir = FileUrl(HtmlFolderPath()); 123 static auto dir = FileUrl(HtmlFolderPath());
127 static auto dirLength = dir.length(); 124
sergei 2015/06/01 09:41:30 I would say we don't need `dirLength` variable.
Eric 2015/06/10 18:30:36 Done.
128 125 DEBUG_GENERAL([&]() -> std::wstring {
129 std::wstring log = L"InjectABP. Current URL: "; 126 std::wstring log = L"InjectABP. Current URL: ";
130 log += url; 127 log += url;
131 log += L", template directory URL: "; 128 log += L", template directory URL: ";
132 log += dir; 129 log += dir;
133 DEBUG_GENERAL(log); 130 return log;
134 131 }());
132
133 /*
134 * The length check here is defensive, in case the document URL is truncated for some reason.
135 */
136 if (url.length() < 5)
137 {
138 // We can't match ".html" at the end of the URL if it's too short.
139 return false;
140 }
135 auto urlCstr = url.c_str(); 141 auto urlCstr = url.c_str();
sergei 2015/06/01 09:41:30 Actually, this variable is also not necessary.
Eric 2015/06/10 18:30:36 Not strictly, no; it's a small optimization. But e
136 // Check the prefix to match our directory 142 // Check the prefix to match our directory
137 // Check the suffix to be an HTML file 143 // Check the suffix to be an HTML file
138 return (_wcsnicmp(urlCstr, dir.c_str(), dirLength) == 0) && 144 return (_wcsnicmp(urlCstr, dir.c_str(), dir.length()) == 0) &&
139 (_wcsnicmp(urlCstr + url.length() - 5, L".html", 5) == 0); 145 (_wcsnicmp(urlCstr + url.length() - 5, L".html", 5) == 0);
sergei 2015/06/01 09:41:30 It would be great to have a comment here explainin
Eric 2015/06/10 18:30:36 We actually need an explicit check, which I've add
140 } 146 }
141 } 147 }
142 148
143 void CPluginTabBase::InjectABP(IWebBrowser2* browser) 149 void CPluginTabBase::InjectABP(IWebBrowser2* browser)
144 { 150 {
145 CriticalSection::Lock lock(m_csInject); 151 CriticalSection::Lock lock(m_csInject);
146 auto url = GetDocumentUrl(); 152 auto url = GetDocumentUrl();
147 if (!IsOurHtmlFile(url)) 153 if (!IsOurHtmlFile(url))
148 { 154 {
149 DEBUG_GENERAL(L"InjectABP. Not injecting"); 155 DEBUG_GENERAL(L"InjectABP. Not injecting");
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p luginError.GetProcessId(), pluginError.GetThreadId()); 385 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p luginError.GetProcessId(), pluginError.GetThreadId());
380 } 386 }
381 387
382 // Non-hanging sleep 388 // Non-hanging sleep
383 Sleep(50); 389 Sleep(50);
384 } 390 }
385 391
386 tabLoopIteration++; 392 tabLoopIteration++;
387 } 393 }
388 } 394 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld