| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/user_script_slave.h" | 5 #include "chrome/renderer/extensions/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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 WebString::fromUTF8(CSPInfo::GetContentSecurityPolicy(extension))); | 69 WebString::fromUTF8(CSPInfo::GetContentSecurityPolicy(extension))); |
| 70 return iter->second; | 70 return iter->second; |
| 71 } | 71 } |
| 72 | 72 |
| 73 int new_id = g_next_isolated_world_id; | 73 int new_id = g_next_isolated_world_id; |
| 74 ++g_next_isolated_world_id; | 74 ++g_next_isolated_world_id; |
| 75 | 75 |
| 76 // This map will tend to pile up over time, but realistically, you're never | 76 // This map will tend to pile up over time, but realistically, you're never |
| 77 // going to have enough extensions for it to matter. | 77 // going to have enough extensions for it to matter. |
| 78 isolated_world_ids_[extension->id()] = new_id; | 78 isolated_world_ids_[extension->id()] = new_id; |
| 79 InitializeIsolatedWorld(new_id, extension); | |
| 80 frame->setIsolatedWorldSecurityOrigin( | 79 frame->setIsolatedWorldSecurityOrigin( |
| 81 new_id, | 80 new_id, |
| 82 WebSecurityOrigin::create(extension->url())); | 81 WebSecurityOrigin::create(extension->url())); |
| 83 frame->setIsolatedWorldContentSecurityPolicy( | 82 frame->setIsolatedWorldContentSecurityPolicy( |
| 84 new_id, | 83 new_id, |
| 85 WebString::fromUTF8(CSPInfo::GetContentSecurityPolicy(extension))); | 84 WebString::fromUTF8(CSPInfo::GetContentSecurityPolicy(extension))); |
| 86 return new_id; | 85 return new_id; |
| 87 } | 86 } |
| 88 | 87 |
| 89 std::string UserScriptSlave::GetExtensionIdForIsolatedWorld( | 88 std::string UserScriptSlave::GetExtensionIdForIsolatedWorld( |
| 90 int isolated_world_id) { | 89 int isolated_world_id) { |
| 91 for (IsolatedWorldMap::iterator iter = isolated_world_ids_.begin(); | 90 for (IsolatedWorldMap::iterator iter = isolated_world_ids_.begin(); |
| 92 iter != isolated_world_ids_.end(); ++iter) { | 91 iter != isolated_world_ids_.end(); ++iter) { |
| 93 if (iter->second == isolated_world_id) | 92 if (iter->second == isolated_world_id) |
| 94 return iter->first; | 93 return iter->first; |
| 95 } | 94 } |
| 96 return std::string(); | 95 return std::string(); |
| 97 } | 96 } |
| 98 | 97 |
| 99 // static | |
| 100 void UserScriptSlave::InitializeIsolatedWorld(int isolated_world_id, | |
| 101 const Extension* extension) { | |
| 102 const URLPatternSet& permissions = | |
| 103 PermissionsData::GetEffectiveHostPermissions(extension); | |
| 104 for (URLPatternSet::const_iterator i = permissions.begin(); | |
| 105 i != permissions.end(); ++i) { | |
| 106 const char* schemes[] = { | |
| 107 content::kHttpScheme, | |
| 108 content::kHttpsScheme, | |
| 109 content::kFileScheme, | |
| 110 content::kChromeUIScheme, | |
| 111 }; | |
| 112 for (size_t j = 0; j < arraysize(schemes); ++j) { | |
| 113 if (i->MatchesScheme(schemes[j])) { | |
| 114 WebSecurityPolicy::addOriginAccessWhitelistEntry( | |
| 115 extension->url(), | |
| 116 WebString::fromUTF8(schemes[j]), | |
| 117 WebString::fromUTF8(i->host()), | |
| 118 i->match_subdomains()); | |
| 119 } | |
| 120 } | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 void UserScriptSlave::RemoveIsolatedWorld(const std::string& extension_id) { | 98 void UserScriptSlave::RemoveIsolatedWorld(const std::string& extension_id) { |
| 125 isolated_world_ids_.erase(extension_id); | 99 isolated_world_ids_.erase(extension_id); |
| 126 } | 100 } |
| 127 | 101 |
| 128 UserScriptSlave::UserScriptSlave(const ExtensionSet* extensions) | 102 UserScriptSlave::UserScriptSlave(const ExtensionSet* extensions) |
| 129 : script_deleter_(&scripts_), extensions_(extensions) { | 103 : script_deleter_(&scripts_), extensions_(extensions) { |
| 130 api_js_ = ResourceBundle::GetSharedInstance().GetRawDataResource( | 104 api_js_ = ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 131 IDR_GREASEMONKEY_API_JS); | 105 IDR_GREASEMONKEY_API_JS); |
| 132 } | 106 } |
| 133 | 107 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 } else if (location == UserScript::DOCUMENT_IDLE) { | 346 } else if (location == UserScript::DOCUMENT_IDLE) { |
| 373 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts); | 347 UMA_HISTOGRAM_COUNTS_100("Extensions.InjectIdle_ScriptCount", num_scripts); |
| 374 if (num_scripts) | 348 if (num_scripts) |
| 375 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); | 349 UMA_HISTOGRAM_TIMES("Extensions.InjectIdle_Time", timer.Elapsed()); |
| 376 } else { | 350 } else { |
| 377 NOTREACHED(); | 351 NOTREACHED(); |
| 378 } | 352 } |
| 379 } | 353 } |
| 380 | 354 |
| 381 } // namespace extensions | 355 } // namespace extensions |
| OLD | NEW |