OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/user_script_slave.h" | 5 #include "chrome/renderer/user_script_slave.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/perftimer.h" | 11 #include "base/perftimer.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 UserScript* script = scripts_[i]; | 144 UserScript* script = scripts_[i]; |
145 if (script->css_scripts().empty()) | 145 if (script->css_scripts().empty()) |
146 continue; | 146 continue; |
147 | 147 |
148 WebVector<WebString> patterns; | 148 WebVector<WebString> patterns; |
149 std::vector<WebString> temp_patterns; | 149 std::vector<WebString> temp_patterns; |
150 for (size_t k = 0; k < script->url_patterns().size(); ++k) { | 150 for (size_t k = 0; k < script->url_patterns().size(); ++k) { |
151 std::vector<URLPattern> explicit_patterns = | 151 std::vector<URLPattern> explicit_patterns = |
152 script->url_patterns()[k].ConvertToExplicitSchemes(); | 152 script->url_patterns()[k].ConvertToExplicitSchemes(); |
153 for (size_t m = 0; m < explicit_patterns.size(); ++m) { | 153 for (size_t m = 0; m < explicit_patterns.size(); ++m) { |
154 // Only include file schemes if the user has opted into that. | 154 temp_patterns.push_back(WebString::fromUTF8( |
155 if (!explicit_patterns[m].MatchesScheme(chrome::kFileScheme) || | 155 explicit_patterns[m].GetAsString())); |
156 script->allow_file_access()) { | |
157 temp_patterns.push_back(WebString::fromUTF8( | |
158 explicit_patterns[m].GetAsString())); | |
159 } | |
160 } | 156 } |
161 } | 157 } |
162 patterns.assign(temp_patterns); | 158 patterns.assign(temp_patterns); |
163 | 159 |
164 for (size_t j = 0; j < script->css_scripts().size(); ++j) { | 160 for (size_t j = 0; j < script->css_scripts().size(); ++j) { |
165 const UserScript::File& file = scripts_[i]->css_scripts()[j]; | 161 const UserScript::File& file = scripts_[i]->css_scripts()[j]; |
166 std::string content = file.GetContent().as_string(); | 162 std::string content = file.GetContent().as_string(); |
167 | 163 |
168 WebView::addUserStyleSheet( | 164 WebView::addUserStyleSheet( |
169 WebString::fromUTF8(content), | 165 WebString::fromUTF8(content), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 const Extension* extension = extensions_->GetByID(script->extension_id()); | 203 const Extension* extension = extensions_->GetByID(script->extension_id()); |
208 | 204 |
209 // Since extension info is sent separately from user script info, they can | 205 // Since extension info is sent separately from user script info, they can |
210 // be out of sync. We just ignore this situation. | 206 // be out of sync. We just ignore this situation. |
211 if (!extension) | 207 if (!extension) |
212 continue; | 208 continue; |
213 | 209 |
214 if (!extension->CanExecuteScriptOnPage(frame_url, script, NULL)) | 210 if (!extension->CanExecuteScriptOnPage(frame_url, script, NULL)) |
215 continue; | 211 continue; |
216 | 212 |
217 if (frame_url.SchemeIsFile() && !script->allow_file_access()) | |
218 continue; // This script isn't allowed to run on file URLs. | |
219 | |
220 // We rely on WebCore for CSS injection, but it's still useful to know how | 213 // We rely on WebCore for CSS injection, but it's still useful to know how |
221 // many css files there are. | 214 // many css files there are. |
222 if (location == UserScript::DOCUMENT_START) | 215 if (location == UserScript::DOCUMENT_START) |
223 num_css += script->css_scripts().size(); | 216 num_css += script->css_scripts().size(); |
224 | 217 |
225 if (script->run_location() == location) { | 218 if (script->run_location() == location) { |
226 num_scripts += script->js_scripts().size(); | 219 num_scripts += script->js_scripts().size(); |
227 for (size_t j = 0; j < script->js_scripts().size(); ++j) { | 220 for (size_t j = 0; j < script->js_scripts().size(); ++j) { |
228 UserScript::File &file = script->js_scripts()[j]; | 221 UserScript::File &file = script->js_scripts()[j]; |
229 std::string content = file.GetContent().as_string(); | 222 std::string content = file.GetContent().as_string(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 if (num_scripts) | 268 if (num_scripts) |
276 UMA_HISTOGRAM_TIMES("Extensions.InjectEnd_Time", timer.Elapsed()); | 269 UMA_HISTOGRAM_TIMES("Extensions.InjectEnd_Time", timer.Elapsed()); |
277 } else if (location == UserScript::DOCUMENT_IDLE) { | 270 } else if (location == UserScript::DOCUMENT_IDLE) { |
278 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts); | 271 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts); |
279 if (num_scripts) | 272 if (num_scripts) |
280 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); | 273 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); |
281 } else { | 274 } else { |
282 NOTREACHED(); | 275 NOTREACHED(); |
283 } | 276 } |
284 } | 277 } |
OLD | NEW |