Chromium Code Reviews| 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/dispatcher.h" | 5 #include "chrome/renderer/extensions/dispatcher.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/alias.h" | 9 #include "base/debug/alias.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), | 522 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), |
| 523 RenderThread::Get(), &RenderThread::IdleHandler); | 523 RenderThread::Get(), &RenderThread::IdleHandler); |
| 524 } | 524 } |
| 525 | 525 |
| 526 // Initialize host permissions for any extensions that were activated before | 526 // Initialize host permissions for any extensions that were activated before |
| 527 // WebKit was initialized. | 527 // WebKit was initialized. |
| 528 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); | 528 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); |
| 529 iter != active_extension_ids_.end(); ++iter) { | 529 iter != active_extension_ids_.end(); ++iter) { |
| 530 const Extension* extension = extensions_.GetByID(*iter); | 530 const Extension* extension = extensions_.GetByID(*iter); |
| 531 CHECK(extension); | 531 CHECK(extension); |
| 532 InitOriginPermissions(extension); | |
| 533 } | 532 } |
| 534 | 533 |
| 535 EnableCustomElementWhiteList(); | 534 EnableCustomElementWhiteList(); |
| 536 | 535 |
| 537 is_webkit_initialized_ = true; | 536 is_webkit_initialized_ = true; |
| 538 } | 537 } |
| 539 | 538 |
| 540 void Dispatcher::IdleNotification() { | 539 void Dispatcher::IdleNotification() { |
| 541 if (is_extension_process_) { | 540 if (is_extension_process_) { |
| 542 // Dampen the forced delay as well if the extension stays idle for long | 541 // Dampen the forced delay as well if the extension stays idle for long |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1126 Feature::Context context_type = ClassifyJavaScriptContext( | 1125 Feature::Context context_type = ClassifyJavaScriptContext( |
| 1127 extension, | 1126 extension, |
| 1128 extension_group, | 1127 extension_group, |
| 1129 UserScriptSlave::GetDataSourceURLForFrame(frame), | 1128 UserScriptSlave::GetDataSourceURLForFrame(frame), |
| 1130 frame->document().securityOrigin()); | 1129 frame->document().securityOrigin()); |
| 1131 | 1130 |
| 1132 ChromeV8Context* context = | 1131 ChromeV8Context* context = |
| 1133 new ChromeV8Context(v8_context, frame, extension, context_type); | 1132 new ChromeV8Context(v8_context, frame, extension, context_type); |
| 1134 v8_context_set_.Add(context); | 1133 v8_context_set_.Add(context); |
| 1135 | 1134 |
| 1135 if (extension) { | |
| 1136 InitOriginPermissions(extension, context_type); | |
| 1137 } | |
|
not at google - send to devlin
2014/03/03 19:57:48
nit: no curlies.
| |
| 1138 | |
| 1136 { | 1139 { |
| 1137 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(context, | 1140 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(context, |
| 1138 &source_map_)); | 1141 &source_map_)); |
| 1139 context->set_module_system(module_system.Pass()); | 1142 context->set_module_system(module_system.Pass()); |
| 1140 } | 1143 } |
| 1141 ModuleSystem* module_system = context->module_system(); | 1144 ModuleSystem* module_system = context->module_system(); |
| 1142 | 1145 |
| 1143 // Enable natives in startup. | 1146 // Enable natives in startup. |
| 1144 ModuleSystem::NativesEnabledScope natives_enabled_scope( | 1147 ModuleSystem::NativesEnabledScope natives_enabled_scope( |
| 1145 module_system); | 1148 module_system); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1334 | 1337 |
| 1335 active_extension_ids_.insert(extension_id); | 1338 active_extension_ids_.insert(extension_id); |
| 1336 | 1339 |
| 1337 // This is called when starting a new extension page, so start the idle | 1340 // This is called when starting a new extension page, so start the idle |
| 1338 // handler ticking. | 1341 // handler ticking. |
| 1339 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); | 1342 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); |
| 1340 | 1343 |
| 1341 UpdateActiveExtensions(); | 1344 UpdateActiveExtensions(); |
| 1342 | 1345 |
| 1343 if (is_webkit_initialized_) { | 1346 if (is_webkit_initialized_) { |
| 1344 InitOriginPermissions(extension); | |
| 1345 DOMActivityLogger::AttachToWorld(DOMActivityLogger::kMainWorldId, | 1347 DOMActivityLogger::AttachToWorld(DOMActivityLogger::kMainWorldId, |
| 1346 extension_id); | 1348 extension_id); |
| 1347 } | 1349 } |
| 1348 } | 1350 } |
| 1349 | 1351 |
| 1350 void Dispatcher::InitOriginPermissions(const Extension* extension) { | 1352 void Dispatcher::InitOriginPermissions(const Extension* extension, |
| 1353 Feature::Context context_type) { | |
| 1351 // TODO(jstritar): We should try to remove this special case. Also, these | 1354 // TODO(jstritar): We should try to remove this special case. Also, these |
| 1352 // whitelist entries need to be updated when the kManagement permission | 1355 // whitelist entries need to be updated when the kManagement permission |
| 1353 // changes. | 1356 // changes. |
| 1354 if (extension->HasAPIPermission(APIPermission::kManagement)) { | 1357 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT && |
| 1358 extension->HasAPIPermission(APIPermission::kManagement)) { | |
| 1355 WebSecurityPolicy::addOriginAccessWhitelistEntry( | 1359 WebSecurityPolicy::addOriginAccessWhitelistEntry( |
| 1356 extension->url(), | 1360 extension->url(), |
| 1357 WebString::fromUTF8(content::kChromeUIScheme), | 1361 WebString::fromUTF8(content::kChromeUIScheme), |
| 1358 WebString::fromUTF8(chrome::kChromeUIExtensionIconHost), | 1362 WebString::fromUTF8(chrome::kChromeUIExtensionIconHost), |
| 1359 false); | 1363 false); |
| 1360 } | 1364 } |
| 1361 | 1365 |
| 1362 AddOrRemoveOriginPermissions( | 1366 AddOrRemoveOriginPermissions( |
| 1363 UpdatedExtensionPermissionsInfo::ADDED, | 1367 UpdatedExtensionPermissionsInfo::ADDED, |
| 1364 extension, | 1368 extension, |
| 1365 extension->GetActivePermissions()->explicit_hosts()); | 1369 PermissionsData::GetEffectiveHostPermissions(extension)); |
| 1366 } | 1370 } |
| 1367 | 1371 |
| 1368 void Dispatcher::AddOrRemoveOriginPermissions( | 1372 void Dispatcher::AddOrRemoveOriginPermissions( |
| 1369 UpdatedExtensionPermissionsInfo::Reason reason, | 1373 UpdatedExtensionPermissionsInfo::Reason reason, |
| 1370 const Extension* extension, | 1374 const Extension* extension, |
| 1371 const URLPatternSet& origins) { | 1375 const URLPatternSet& origins) { |
| 1372 for (URLPatternSet::const_iterator i = origins.begin(); | 1376 for (URLPatternSet::const_iterator i = origins.begin(); |
| 1373 i != origins.end(); ++i) { | 1377 i != origins.end(); ++i) { |
| 1374 const char* schemes[] = { | 1378 const char* schemes[] = { |
| 1375 content::kHttpScheme, | 1379 content::kHttpScheme, |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1684 } | 1688 } |
| 1685 | 1689 |
| 1686 void Dispatcher::ClearPortData(int port_id) { | 1690 void Dispatcher::ClearPortData(int port_id) { |
| 1687 // Only the target port side has entries in |port_to_tab_id_map_|. If | 1691 // Only the target port side has entries in |port_to_tab_id_map_|. If |
| 1688 // |port_id| is a source port, std::map::erase() will just silently fail | 1692 // |port_id| is a source port, std::map::erase() will just silently fail |
| 1689 // here as a no-op. | 1693 // here as a no-op. |
| 1690 port_to_tab_id_map_.erase(port_id); | 1694 port_to_tab_id_map_.erase(port_id); |
| 1691 } | 1695 } |
| 1692 | 1696 |
| 1693 } // namespace extensions | 1697 } // namespace extensions |
| OLD | NEW |