Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: chrome/renderer/extensions/dispatcher.cc

Issue 169053005: Allow cross-origin XHR in unblessed extension context (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove curly braces Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/renderer/extensions/dispatcher.h ('k') | chrome/renderer/extensions/user_script_slave.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
1136 { 1138 {
1137 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(context, 1139 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(context,
1138 &source_map_)); 1140 &source_map_));
1139 context->set_module_system(module_system.Pass()); 1141 context->set_module_system(module_system.Pass());
1140 } 1142 }
1141 ModuleSystem* module_system = context->module_system(); 1143 ModuleSystem* module_system = context->module_system();
1142 1144
1143 // Enable natives in startup. 1145 // Enable natives in startup.
1144 ModuleSystem::NativesEnabledScope natives_enabled_scope( 1146 ModuleSystem::NativesEnabledScope natives_enabled_scope(
1145 module_system); 1147 module_system);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 1336
1335 active_extension_ids_.insert(extension_id); 1337 active_extension_ids_.insert(extension_id);
1336 1338
1337 // This is called when starting a new extension page, so start the idle 1339 // This is called when starting a new extension page, so start the idle
1338 // handler ticking. 1340 // handler ticking.
1339 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); 1341 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs);
1340 1342
1341 UpdateActiveExtensions(); 1343 UpdateActiveExtensions();
1342 1344
1343 if (is_webkit_initialized_) { 1345 if (is_webkit_initialized_) {
1344 InitOriginPermissions(extension);
1345 DOMActivityLogger::AttachToWorld(DOMActivityLogger::kMainWorldId, 1346 DOMActivityLogger::AttachToWorld(DOMActivityLogger::kMainWorldId,
1346 extension_id); 1347 extension_id);
1347 } 1348 }
1348 } 1349 }
1349 1350
1350 void Dispatcher::InitOriginPermissions(const Extension* extension) { 1351 void Dispatcher::InitOriginPermissions(const Extension* extension,
1352 Feature::Context context_type) {
1351 // TODO(jstritar): We should try to remove this special case. Also, these 1353 // TODO(jstritar): We should try to remove this special case. Also, these
1352 // whitelist entries need to be updated when the kManagement permission 1354 // whitelist entries need to be updated when the kManagement permission
1353 // changes. 1355 // changes.
1354 if (extension->HasAPIPermission(APIPermission::kManagement)) { 1356 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT &&
1357 extension->HasAPIPermission(APIPermission::kManagement)) {
1355 WebSecurityPolicy::addOriginAccessWhitelistEntry( 1358 WebSecurityPolicy::addOriginAccessWhitelistEntry(
1356 extension->url(), 1359 extension->url(),
1357 WebString::fromUTF8(content::kChromeUIScheme), 1360 WebString::fromUTF8(content::kChromeUIScheme),
1358 WebString::fromUTF8(chrome::kChromeUIExtensionIconHost), 1361 WebString::fromUTF8(chrome::kChromeUIExtensionIconHost),
1359 false); 1362 false);
1360 } 1363 }
1361 1364
1362 AddOrRemoveOriginPermissions( 1365 AddOrRemoveOriginPermissions(
1363 UpdatedExtensionPermissionsInfo::ADDED, 1366 UpdatedExtensionPermissionsInfo::ADDED,
1364 extension, 1367 extension,
1365 extension->GetActivePermissions()->explicit_hosts()); 1368 PermissionsData::GetEffectiveHostPermissions(extension));
1366 } 1369 }
1367 1370
1368 void Dispatcher::AddOrRemoveOriginPermissions( 1371 void Dispatcher::AddOrRemoveOriginPermissions(
1369 UpdatedExtensionPermissionsInfo::Reason reason, 1372 UpdatedExtensionPermissionsInfo::Reason reason,
1370 const Extension* extension, 1373 const Extension* extension,
1371 const URLPatternSet& origins) { 1374 const URLPatternSet& origins) {
1372 for (URLPatternSet::const_iterator i = origins.begin(); 1375 for (URLPatternSet::const_iterator i = origins.begin();
1373 i != origins.end(); ++i) { 1376 i != origins.end(); ++i) {
1374 const char* schemes[] = { 1377 const char* schemes[] = {
1375 content::kHttpScheme, 1378 content::kHttpScheme,
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 } 1687 }
1685 1688
1686 void Dispatcher::ClearPortData(int port_id) { 1689 void Dispatcher::ClearPortData(int port_id) {
1687 // Only the target port side has entries in |port_to_tab_id_map_|. If 1690 // 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 1691 // |port_id| is a source port, std::map::erase() will just silently fail
1689 // here as a no-op. 1692 // here as a no-op.
1690 port_to_tab_id_map_.erase(port_id); 1693 port_to_tab_id_map_.erase(port_id);
1691 } 1694 }
1692 1695
1693 } // namespace extensions 1696 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/dispatcher.h ('k') | chrome/renderer/extensions/user_script_slave.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698