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

Side by Side Diff: src/plugin/PluginTabBase.cpp

Issue 5670602698391552: Issue #1234 - Remove CString local variable from CPluginTabBase::InjectABP (Closed)
Patch Set: Created May 20, 2015, 3:52 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 filterLoaderThread.detach(); // TODO: but actually we should wait for the th read in the dtr. 104 filterLoaderThread.detach(); // TODO: but actually we should wait for the th read in the dtr.
105 } 105 }
106 catch (const std::system_error& ex) 106 catch (const std::system_error& ex)
107 { 107 {
108 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_THREAD_CRE ATE_PROCESS, 108 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_THREAD_CRE ATE_PROCESS,
109 "Class::Thread - Failed to start filter loader thread"); 109 "Class::Thread - Failed to start filter loader thread");
110 } 110 }
111 m_traverser->ClearCache(); 111 m_traverser->ClearCache();
112 } 112 }
113 113
114 namespace
115 {
116 /**
117 * 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.
119 *
120 * 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.
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 */
123 bool IsOurHtmlFile(std::wstring url)
sergei 2015/06/01 09:41:30 const ref
Eric 2015/06/10 18:30:36 Done.
124 {
125 // 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());
127 static auto dirLength = dir.length();
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
129 std::wstring log = L"InjectABP. Current URL: ";
130 log += url;
131 log += L", template directory URL: ";
132 log += dir;
133 DEBUG_GENERAL(log);
134
135 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
137 // Check the suffix to be an HTML file
138 return (_wcsnicmp(urlCstr, dir.c_str(), dirLength) == 0) &&
139 (_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 }
141 }
142
114 void CPluginTabBase::InjectABP(IWebBrowser2* browser) 143 void CPluginTabBase::InjectABP(IWebBrowser2* browser)
115 { 144 {
116 CriticalSection::Lock lock(m_csInject); 145 CriticalSection::Lock lock(m_csInject);
117 auto url = GetDocumentUrl(); 146 auto url = GetDocumentUrl();
118 147 if (!IsOurHtmlFile(url))
119 std::wstring log = L"InjectABP. Current URL: ";
120 log += url;
121 log += L", settings URL: ";
122 log += UserSettingsFileUrl();
123 DEBUG_GENERAL(log);
124
125 CString urlLegacy = ToCString(url);
126 if (!(0 == urlLegacy.CompareNoCase(CString(UserSettingsFileUrl().c_str())) ||
127 0 == urlLegacy.CompareNoCase(CString(FirstRunPageFileUrl().c_str()))))
128 { 148 {
129 DEBUG_GENERAL(L"Not injecting"); 149 DEBUG_GENERAL(L"InjectABP. Not injecting");
130 return; 150 return;
131 } 151 }
132 DEBUG_GENERAL(L"Going to inject"); 152 DEBUG_GENERAL(L"InjectABP. Injecting");
133 CComPtr<IDispatch> pDocDispatch; 153 CComPtr<IDispatch> pDocDispatch;
134 browser->get_Document(&pDocDispatch); 154 browser->get_Document(&pDocDispatch);
135 CComQIPtr<IHTMLDocument2> pDoc2 = pDocDispatch; 155 CComQIPtr<IHTMLDocument2> pDoc2 = pDocDispatch;
136 if (!pDoc2) 156 if (!pDoc2)
137 { 157 {
138 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CRE ATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to QI docume nt"); 158 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CRE ATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to QI docume nt");
139 return; 159 return;
140 } 160 }
141 CComPtr<IHTMLWindow2> pWnd2; 161 CComPtr<IHTMLWindow2> pWnd2;
142 pDoc2->get_parentWindow(&pWnd2); 162 pDoc2->get_parentWindow(&pWnd2);
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p luginError.GetProcessId(), pluginError.GetThreadId()); 379 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p luginError.GetProcessId(), pluginError.GetThreadId());
360 } 380 }
361 381
362 // Non-hanging sleep 382 // Non-hanging sleep
363 Sleep(50); 383 Sleep(50);
364 } 384 }
365 385
366 tabLoopIteration++; 386 tabLoopIteration++;
367 } 387 }
368 } 388 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld