| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 int new_id = g_next_isolated_world_id; | 54 int new_id = g_next_isolated_world_id; |
| 55 ++g_next_isolated_world_id; | 55 ++g_next_isolated_world_id; |
| 56 | 56 |
| 57 // This map will tend to pile up over time, but realistically, you're never | 57 // This map will tend to pile up over time, but realistically, you're never |
| 58 // going to have enough extensions for it to matter. | 58 // going to have enough extensions for it to matter. |
| 59 g_isolated_world_ids[extension_id] = new_id; | 59 g_isolated_world_ids[extension_id] = new_id; |
| 60 return new_id; | 60 return new_id; |
| 61 } | 61 } |
| 62 | 62 |
| 63 UserScriptSlave::UserScriptSlave() | 63 UserScriptSlave::UserScriptSlave(const ExtensionRendererInfo* extensions) |
| 64 : shared_memory_(NULL), | 64 : shared_memory_(NULL), |
| 65 script_deleter_(&scripts_) { | 65 script_deleter_(&scripts_), |
| 66 extensions_(extensions) { |
| 66 api_js_ = ResourceBundle::GetSharedInstance().GetRawDataResource( | 67 api_js_ = ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 67 IDR_GREASEMONKEY_API_JS); | 68 IDR_GREASEMONKEY_API_JS); |
| 68 } | 69 } |
| 69 | 70 |
| 70 UserScriptSlave::~UserScriptSlave() {} | 71 UserScriptSlave::~UserScriptSlave() {} |
| 71 | 72 |
| 72 void UserScriptSlave::GetActiveExtensions( | 73 void UserScriptSlave::GetActiveExtensions( |
| 73 std::set<std::string>* extension_ids) { | 74 std::set<std::string>* extension_ids) { |
| 74 for (size_t i = 0; i < scripts_.size(); ++i) { | 75 for (size_t i = 0; i < scripts_.size(); ++i) { |
| 75 DCHECK(!scripts_[i]->extension_id().empty()); | 76 DCHECK(!scripts_[i]->extension_id().empty()); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 int num_css = 0; | 197 int num_css = 0; |
| 197 int num_scripts = 0; | 198 int num_scripts = 0; |
| 198 | 199 |
| 199 for (size_t i = 0; i < scripts_.size(); ++i) { | 200 for (size_t i = 0; i < scripts_.size(); ++i) { |
| 200 std::vector<WebScriptSource> sources; | 201 std::vector<WebScriptSource> sources; |
| 201 UserScript* script = scripts_[i]; | 202 UserScript* script = scripts_[i]; |
| 202 | 203 |
| 203 if (frame->parent() && !script->match_all_frames()) | 204 if (frame->parent() && !script->match_all_frames()) |
| 204 continue; // Only match subframes if the script declared it wanted to. | 205 continue; // Only match subframes if the script declared it wanted to. |
| 205 | 206 |
| 206 ExtensionRendererInfo* extension = | 207 const Extension* extension = extensions_->GetByID(script->extension_id()); |
| 207 ExtensionRendererInfo::GetByID(script->extension_id()); | |
| 208 | 208 |
| 209 // Since extension info is sent separately from user script info, they can | 209 // Since extension info is sent separately from user script info, they can |
| 210 // be out of sync. We just ignore this situation. | 210 // be out of sync. We just ignore this situation. |
| 211 if (!extension) | 211 if (!extension) |
| 212 continue; | 212 continue; |
| 213 | 213 |
| 214 if (!Extension::CanExecuteScriptOnPage( | 214 if (!extension->CanExecuteScriptOnPage(frame_url, script, NULL)) |
| 215 frame_url, | |
| 216 extension->allowed_to_execute_script_everywhere(), | |
| 217 NULL, | |
| 218 script, | |
| 219 NULL)) { | |
| 220 continue; | 215 continue; |
| 221 } | |
| 222 | 216 |
| 223 if (frame_url.SchemeIsFile() && !script->allow_file_access()) | 217 if (frame_url.SchemeIsFile() && !script->allow_file_access()) |
| 224 continue; // This script isn't allowed to run on file URLs. | 218 continue; // This script isn't allowed to run on file URLs. |
| 225 | 219 |
| 226 // We rely on WebCore for CSS injection, but it's still useful to know how | 220 // We rely on WebCore for CSS injection, but it's still useful to know how |
| 227 // many css files there are. | 221 // many css files there are. |
| 228 if (location == UserScript::DOCUMENT_START) | 222 if (location == UserScript::DOCUMENT_START) |
| 229 num_css += script->css_scripts().size(); | 223 num_css += script->css_scripts().size(); |
| 230 | 224 |
| 231 if (script->run_location() == location) { | 225 if (script->run_location() == location) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 if (num_scripts) | 275 if (num_scripts) |
| 282 UMA_HISTOGRAM_TIMES("Extensions.InjectEnd_Time", timer.Elapsed()); | 276 UMA_HISTOGRAM_TIMES("Extensions.InjectEnd_Time", timer.Elapsed()); |
| 283 } else if (location == UserScript::DOCUMENT_IDLE) { | 277 } else if (location == UserScript::DOCUMENT_IDLE) { |
| 284 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts); | 278 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts); |
| 285 if (num_scripts) | 279 if (num_scripts) |
| 286 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); | 280 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); |
| 287 } else { | 281 } else { |
| 288 NOTREACHED(); | 282 NOTREACHED(); |
| 289 } | 283 } |
| 290 } | 284 } |
| OLD | NEW |