OLD | NEW |
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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 /** | 148 /** |
149 * Determine if the HTML file is one of ours. | 149 * Determine if the HTML file is one of ours. |
150 * The criterion is that it appear in the "html/templates" folder within our i
nstallation. | 150 * The criterion is that it appear in the "html/templates" folder within our i
nstallation. |
151 * | 151 * |
152 * Warning: This function may fail if the argument is not a "file://" URL. | 152 * Warning: This function may fail if the argument is not a "file://" URL. |
153 * This is occasionally the case in circumstances yet to be characterized. | 153 * This is occasionally the case in circumstances yet to be characterized. |
154 */ | 154 */ |
155 bool IsOurHtmlFile(const std::wstring& url) | 155 bool IsOurHtmlFile(const std::wstring& url) |
156 { | 156 { |
157 // Declared static because the value is derived from an installation directo
ry, which won't change during run-time. | 157 // Declared static because the value is derived from an installation directo
ry, which won't change during run-time. |
158 static auto dir = FileUrl(HtmlFolderPath()); | 158 static auto dir = CanonicalizeUrl(FileUrl(HtmlFolderPath())); |
159 | 159 |
160 dir = EscapeUrl(CanonicalizeUrl(dir)); | 160 std::wstring urlCanonical = CanonicalizeUrl(url); |
161 std::wstring urlCanonicalized = EscapeUrl(CanonicalizeUrl(url)); | |
162 | 161 |
163 DEBUG_GENERAL([&]() -> std::wstring { | 162 DEBUG_GENERAL([&]() -> std::wstring { |
164 std::wstring log = L"InjectABP. Current URL: "; | 163 std::wstring log = L"InjectABP. Current URL: "; |
165 log += urlCanonicalized; | 164 log += urlCanonical; |
166 log += L", template directory URL: "; | 165 log += L", template directory URL: "; |
167 log += dir; | 166 log += dir; |
168 return log; | 167 return log; |
169 }()); | 168 }()); |
170 | 169 |
171 /* | 170 /* |
172 * The length check here is defensive, in case the document URL is truncated
for some reason. | 171 * The length check here is defensive, in case the document URL is truncated
for some reason. |
173 */ | 172 */ |
174 if (urlCanonicalized.length() < 5) | 173 if (urlCanonical.length() < 5) |
175 { | 174 { |
176 // We can't match ".html" at the end of the URL if it's too short. | 175 // We can't match ".html" at the end of the URL if it's too short. |
177 return false; | 176 return false; |
178 } | 177 } |
179 auto urlCstr = urlCanonicalized.c_str(); | 178 auto urlCstr = urlCanonical.c_str(); |
180 // Check the prefix to match our directory | 179 // Check the prefix to match our directory |
181 // Check the suffix to be an HTML file | 180 // Check the suffix to be an HTML file |
182 // Compare escaped version and return | |
183 return (_wcsnicmp(urlCstr, dir.c_str(), dir.length()) == 0) && | 181 return (_wcsnicmp(urlCstr, dir.c_str(), dir.length()) == 0) && |
184 (_wcsnicmp(urlCstr + url.length() - 5, L".html", 5) == 0); | 182 (_wcsnicmp(urlCstr + urlCanonical.length() - 5, L".html", 5) == 0); |
185 } | 183 } |
186 } | 184 } |
187 | 185 |
188 void CPluginTab::InjectABP(IWebBrowser2* browser) | 186 void CPluginTab::InjectABP(IWebBrowser2* browser) |
189 { | 187 { |
190 CriticalSection::Lock lock(m_csInject); | 188 CriticalSection::Lock lock(m_csInject); |
191 auto url = GetDocumentUrl(); | 189 auto url = GetDocumentUrl(); |
192 if (!IsOurHtmlFile(url)) | 190 if (!IsOurHtmlFile(url)) |
193 { | 191 { |
194 DEBUG_GENERAL(L"InjectABP. Not injecting"); | 192 DEBUG_GENERAL(L"InjectABP. Not injecting"); |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr
rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p
luginError.GetProcessId(), pluginError.GetThreadId()); | 617 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr
rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p
luginError.GetProcessId(), pluginError.GetThreadId()); |
620 } | 618 } |
621 | 619 |
622 // Non-hanging sleep | 620 // Non-hanging sleep |
623 Sleep(50); | 621 Sleep(50); |
624 } | 622 } |
625 | 623 |
626 tabLoopIteration++; | 624 tabLoopIteration++; |
627 } | 625 } |
628 } | 626 } |
OLD | NEW |