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

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

Issue 5187613258416128: Issue #1234 - Rewrite internals of debug facility (Closed)
Left Patch Set: rebase + address comments Created March 31, 2015, 1:56 p.m.
Right Patch Set: rebase only Created Nov. 26, 2015, 1:02 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
« src/plugin/PluginDebug.cpp ('K') | « src/plugin/PluginStdAfx.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
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" 24 #include "IeVersion.h"
26 #include "../shared/IE_version.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 66 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. 101 filterLoaderThread.detach(); // TODO: but actually we should wait for the th read in the dtr.
105 } 102 }
106 catch (const std::system_error& ex) 103 catch (const std::system_error& ex)
107 { 104 {
108 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,
109 "Class::Thread - Failed to start filter loader thread"); 106 "Class::Thread - Failed to start filter loader thread");
110 } 107 }
111 m_traverser->ClearCache(); 108 m_traverser->ClearCache();
112 } 109 }
113 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
114 void CPluginTabBase::InjectABP(IWebBrowser2* browser) 149 void CPluginTabBase::InjectABP(IWebBrowser2* browser)
115 { 150 {
116 CriticalSection::Lock lock(m_csInject); 151 CriticalSection::Lock lock(m_csInject);
117 auto url = GetDocumentUrl(); 152 auto url = GetDocumentUrl();
118 153 if (!IsOurHtmlFile(url))
119 std::wstring log = L"InjectABP. Current URL: "; 154 {
120 log += url; 155 DEBUG_GENERAL(L"InjectABP. Not injecting");
121 log += L", settings URL: "; 156 return;
122 log += UserSettingsFileUrl(); 157 }
123 DEBUG_GENERAL(log); 158 DEBUG_GENERAL(L"InjectABP. Injecting");
124
125 CString urlLegacy = ToCString(url);
126 if (!(0 == urlLegacy.CompareNoCase(CString(UserSettingsFileUrl().c_str())) ||
127 0 == urlLegacy.CompareNoCase(CString(FirstRunPageFileUrl().c_str()))))
128 {
129 DEBUG_GENERAL(L"Not injecting");
130 return;
131 }
132 DEBUG_GENERAL(L"Going to inject");
133 CComPtr<IDispatch> pDocDispatch; 159 CComPtr<IDispatch> pDocDispatch;
134 browser->get_Document(&pDocDispatch); 160 browser->get_Document(&pDocDispatch);
135 CComQIPtr<IHTMLDocument2> pDoc2 = pDocDispatch; 161 CComQIPtr<IHTMLDocument2> pDoc2 = pDocDispatch;
136 if (!pDoc2) 162 if (!pDoc2)
137 { 163 {
138 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");
139 return; 165 return;
140 } 166 }
141 CComPtr<IHTMLWindow2> pWnd2; 167 CComPtr<IHTMLWindow2> pWnd2;
142 pDoc2->get_parentWindow(&pWnd2); 168 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()); 385 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p luginError.GetProcessId(), pluginError.GetThreadId());
360 } 386 }
361 387
362 // Non-hanging sleep 388 // Non-hanging sleep
363 Sleep(50); 389 Sleep(50);
364 } 390 }
365 391
366 tabLoopIteration++; 392 tabLoopIteration++;
367 } 393 }
368 } 394 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld