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: 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:
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 filterLoaderThread.detach(); // TODO: but actually we should wait for the th read in the dtr. 101 filterLoaderThread.detach(); // TODO: but actually we should wait for the th read in the dtr.
102 } 102 }
103 catch (const std::system_error& ex) 103 catch (const std::system_error& ex)
104 { 104 {
105 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_THREAD_CRE ATE_PROCESS, 105 DEBUG_SYSTEM_EXCEPTION(ex, PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_THREAD_CRE ATE_PROCESS,
106 "Class::Thread - Failed to start filter loader thread"); 106 "Class::Thread - Failed to start filter loader thread");
107 } 107 }
108 m_traverser->ClearCache(); 108 m_traverser->ClearCache();
109 } 109 }
110 110
111 namespace
112 {
113 /**
114 * Determine if the HTML file is one of ours.
115 * The criterion is that it appear in the "html/templates" folder within our i nstallation.
116 *
117 * Warning: This function may fail if the argument is not a "file://" URL.
118 * This is occasionally the case in circumstances yet to be characterized.
119 */
120 bool IsOurHtmlFile(const std::wstring& url)
121 {
122 // Declared static because the value is derived from an installation directo ry, which won't change during run-time.
123 static auto dir = FileUrl(HtmlFolderPath());
124
125 DEBUG_GENERAL([&]() -> std::wstring {
126 std::wstring log = L"InjectABP. Current URL: ";
127 log += url;
128 log += L", template directory URL: ";
129 log += dir;
130 return log;
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 }
141 auto urlCstr = url.c_str();
142 // Check the prefix to match our directory
143 // Check the suffix to be an HTML file
144 return (_wcsnicmp(urlCstr, dir.c_str(), dir.length()) == 0) &&
145 (_wcsnicmp(urlCstr + url.length() - 5, L".html", 5) == 0);
146 }
147 }
148
111 void CPluginTabBase::InjectABP(IWebBrowser2* browser) 149 void CPluginTabBase::InjectABP(IWebBrowser2* browser)
112 { 150 {
113 CriticalSection::Lock lock(m_csInject); 151 CriticalSection::Lock lock(m_csInject);
114 auto url = GetDocumentUrl(); 152 auto url = GetDocumentUrl();
115 153 if (!IsOurHtmlFile(url))
116 std::wstring log = L"InjectABP. Current URL: ";
117 log += url;
118 log += L", settings URL: ";
119 log += UserSettingsFileUrl();
120 DEBUG_GENERAL(log);
121
122 CString urlLegacy = ToCString(url);
123 if (!(0 == urlLegacy.CompareNoCase(CString(UserSettingsFileUrl().c_str())) ||
124 0 == urlLegacy.CompareNoCase(CString(FirstRunPageFileUrl().c_str()))))
125 { 154 {
126 DEBUG_GENERAL(L"Not injecting"); 155 DEBUG_GENERAL(L"InjectABP. Not injecting");
127 return; 156 return;
128 } 157 }
129 DEBUG_GENERAL(L"Going to inject"); 158 DEBUG_GENERAL(L"InjectABP. Injecting");
130 CComPtr<IDispatch> pDocDispatch; 159 CComPtr<IDispatch> pDocDispatch;
131 browser->get_Document(&pDocDispatch); 160 browser->get_Document(&pDocDispatch);
132 CComQIPtr<IHTMLDocument2> pDoc2 = pDocDispatch; 161 CComQIPtr<IHTMLDocument2> pDoc2 = pDocDispatch;
133 if (!pDoc2) 162 if (!pDoc2)
134 { 163 {
135 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CRE ATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to QI docume nt"); 164 DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CRE ATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to QI docume nt");
136 return; 165 return;
137 } 166 }
138 CComPtr<IHTMLWindow2> pWnd2; 167 CComPtr<IHTMLWindow2> pWnd2;
139 pDoc2->get_parentWindow(&pWnd2); 168 pDoc2->get_parentWindow(&pWnd2);
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 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());
357 } 386 }
358 387
359 // Non-hanging sleep 388 // Non-hanging sleep
360 Sleep(50); 389 Sleep(50);
361 } 390 }
362 391
363 tabLoopIteration++; 392 tabLoopIteration++;
364 } 393 }
365 } 394 }
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