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

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

Issue 10851002: In ExtensionDispatcher, maintain the active extensions as a subset of installed (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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 | « no previous file | no next file » | 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/extension_dispatcher.h" 5 #include "chrome/renderer/extensions/extension_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/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/string_piece.h" 10 #include "base/string_piece.h"
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 forced_idle_timer_.Start(FROM_HERE, 390 forced_idle_timer_.Start(FROM_HERE,
391 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), 391 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs),
392 RenderThread::Get(), &RenderThread::IdleHandler); 392 RenderThread::Get(), &RenderThread::IdleHandler);
393 } 393 }
394 394
395 // Initialize host permissions for any extensions that were activated before 395 // Initialize host permissions for any extensions that were activated before
396 // WebKit was initialized. 396 // WebKit was initialized.
397 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); 397 for (std::set<std::string>::iterator iter = active_extension_ids_.begin();
398 iter != active_extension_ids_.end(); ++iter) { 398 iter != active_extension_ids_.end(); ++iter) {
399 const Extension* extension = extensions_.GetByID(*iter); 399 const Extension* extension = extensions_.GetByID(*iter);
400 if (extension) 400 CHECK(extension);
401 InitOriginPermissions(extension); 401 InitOriginPermissions(extension);
402 } 402 }
403 403
404 is_webkit_initialized_ = true; 404 is_webkit_initialized_ = true;
405 } 405 }
406 406
407 void ExtensionDispatcher::IdleNotification() { 407 void ExtensionDispatcher::IdleNotification() {
408 if (is_extension_process_) { 408 if (is_extension_process_) {
409 // Dampen the forced delay as well if the extension stays idle for long 409 // Dampen the forced delay as well if the extension stays idle for long
410 // periods of time. 410 // periods of time.
411 int64 forced_delay_ms = std::max( 411 int64 forced_delay_ms = std::max(
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 GetRawDataResource(IDR_PLATFORM_APP_CSS, 530 GetRawDataResource(IDR_PLATFORM_APP_CSS,
531 ui::SCALE_FACTOR_NONE)), 531 ui::SCALE_FACTOR_NONE)),
532 patterns, 532 patterns,
533 WebView::UserContentInjectInAllFrames, 533 WebView::UserContentInjectInAllFrames,
534 WebView::UserStyleInjectInExistingDocuments); 534 WebView::UserStyleInjectInExistingDocuments);
535 } 535 }
536 } 536 }
537 537
538 void ExtensionDispatcher::OnUnloaded(const std::string& id) { 538 void ExtensionDispatcher::OnUnloaded(const std::string& id) {
539 extensions_.Remove(id); 539 extensions_.Remove(id);
540 active_extension_ids_.erase(id);
541
540 // If the extension is later reloaded with a different set of permissions, 542 // If the extension is later reloaded with a different set of permissions,
541 // we'd like it to get a new isolated world ID, so that it can pick up the 543 // we'd like it to get a new isolated world ID, so that it can pick up the
542 // changed origin whitelist. 544 // changed origin whitelist.
543 user_script_slave_->RemoveIsolatedWorld(id); 545 user_script_slave_->RemoveIsolatedWorld(id);
544 546
545 // We don't do anything with existing platform-app stylesheets. They will 547 // We don't do anything with existing platform-app stylesheets. They will
546 // stay resident, but the URL pattern corresponding to the unloaded 548 // stay resident, but the URL pattern corresponding to the unloaded
547 // extension's URL just won't match anything anymore. 549 // extension's URL just won't match anything anymore.
548 } 550 }
549 551
550 void ExtensionDispatcher::OnSetScriptingWhitelist( 552 void ExtensionDispatcher::OnSetScriptingWhitelist(
551 const Extension::ScriptingWhitelist& extension_ids) { 553 const Extension::ScriptingWhitelist& extension_ids) {
552 Extension::SetScriptingWhitelist(extension_ids); 554 Extension::SetScriptingWhitelist(extension_ids);
553 } 555 }
554 556
555 bool ExtensionDispatcher::IsExtensionActive( 557 bool ExtensionDispatcher::IsExtensionActive(
556 const std::string& extension_id) const { 558 const std::string& extension_id) const {
557 return active_extension_ids_.find(extension_id) != 559 bool is_active =
558 active_extension_ids_.end(); 560 active_extension_ids_.find(extension_id) != active_extension_ids_.end();
561 if (is_active)
562 CHECK(extensions_.Contains(extension_id));
563 return is_active;
559 } 564 }
560 565
561 bool ExtensionDispatcher::AllowScriptExtension( 566 bool ExtensionDispatcher::AllowScriptExtension(
562 WebFrame* frame, 567 WebFrame* frame,
563 const std::string& v8_extension_name, 568 const std::string& v8_extension_name,
564 int extension_group) { 569 int extension_group) {
565 return AllowScriptExtension(frame, v8_extension_name, extension_group, 0); 570 return AllowScriptExtension(frame, v8_extension_name, extension_group, 0);
566 } 571 }
567 572
568 namespace { 573 namespace {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 836
832 break; 837 break;
833 } 838 }
834 } 839 }
835 840
836 // Inject custom JS into the platform app context. 841 // Inject custom JS into the platform app context.
837 if (IsWithinPlatformApp(frame)) 842 if (IsWithinPlatformApp(frame))
838 module_system->Require("platformApp"); 843 module_system->Require("platformApp");
839 844
840 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT && 845 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT &&
841 extension && extension->HasAPIPermission(APIPermission::kBrowserTag)) { 846 extension->HasAPIPermission(APIPermission::kBrowserTag)) {
842 module_system->Require("browserTag"); 847 module_system->Require("browserTag");
843 } 848 }
844 849
845 context->set_module_system(module_system.Pass()); 850 context->set_module_system(module_system.Pass());
846 851
847 context->DispatchOnLoadEvent( 852 context->DispatchOnLoadEvent(
848 ChromeRenderProcessObserver::is_incognito_process(), 853 ChromeRenderProcessObserver::is_incognito_process(),
849 manifest_version); 854 manifest_version);
850 855
851 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); 856 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size();
(...skipping 26 matching lines...) Expand all
878 883
879 context->DispatchOnUnloadEvent(); 884 context->DispatchOnUnloadEvent();
880 885
881 v8_context_set_.Remove(context); 886 v8_context_set_.Remove(context);
882 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); 887 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size();
883 } 888 }
884 889
885 void ExtensionDispatcher::OnActivateExtension( 890 void ExtensionDispatcher::OnActivateExtension(
886 const std::string& extension_id) { 891 const std::string& extension_id) {
887 active_extension_ids_.insert(extension_id); 892 active_extension_ids_.insert(extension_id);
893 const Extension* extension = extensions_.GetByID(extension_id);
894 CHECK(extension);
888 895
889 // This is called when starting a new extension page, so start the idle 896 // This is called when starting a new extension page, so start the idle
890 // handler ticking. 897 // handler ticking.
891 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); 898 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs);
892 899
893 UpdateActiveExtensions(); 900 UpdateActiveExtensions();
894 901
895 const Extension* extension = extensions_.GetByID(extension_id);
896 if (!extension)
897 return;
898
899 if (is_webkit_initialized_) 902 if (is_webkit_initialized_)
900 InitOriginPermissions(extension); 903 InitOriginPermissions(extension);
901 } 904 }
902 905
903 void ExtensionDispatcher::InitOriginPermissions(const Extension* extension) { 906 void ExtensionDispatcher::InitOriginPermissions(const Extension* extension) {
904 // TODO(jstritar): We should try to remove this special case. Also, these 907 // TODO(jstritar): We should try to remove this special case. Also, these
905 // whitelist entries need to be updated when the kManagement permission 908 // whitelist entries need to be updated when the kManagement permission
906 // changes. 909 // changes.
907 if (extension->HasAPIPermission(APIPermission::kManagement)) { 910 if (extension->HasAPIPermission(APIPermission::kManagement)) {
908 WebSecurityPolicy::addOriginAccessWhitelistEntry( 911 WebSecurityPolicy::addOriginAccessWhitelistEntry(
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 args.Set(0, Value::CreateStringValue(kOnSuspendCanceledEvent)); 1068 args.Set(0, Value::CreateStringValue(kOnSuspendCanceledEvent));
1066 args.Set(1, Value::CreateStringValue("[]")); 1069 args.Set(1, Value::CreateStringValue("[]"));
1067 v8_context_set_.DispatchChromeHiddenMethod( 1070 v8_context_set_.DispatchChromeHiddenMethod(
1068 extension_id, kEventDispatchFunction, args, NULL, GURL()); 1071 extension_id, kEventDispatchFunction, args, NULL, GURL());
1069 } 1072 }
1070 1073
1071 Feature::Context ExtensionDispatcher::ClassifyJavaScriptContext( 1074 Feature::Context ExtensionDispatcher::ClassifyJavaScriptContext(
1072 const std::string& extension_id, 1075 const std::string& extension_id,
1073 int extension_group, 1076 int extension_group,
1074 const ExtensionURLInfo& url_info) { 1077 const ExtensionURLInfo& url_info) {
1075 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) 1078 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) {
1076 return Feature::CONTENT_SCRIPT_CONTEXT; 1079 return extensions_.Contains(extension_id) ?
Aaron Boodman 2012/08/02 09:42:42 Have you seen this continue to happen after the ex
not at google - send to devlin 2012/08/02 09:53:55 No I haven't seen it. I could CHECK but I'm not 10
1080 Feature::CONTENT_SCRIPT_CONTEXT : Feature::UNSPECIFIED_CONTEXT;
1081 }
1077 1082
1078 // We have an explicit check for sandboxed pages first since: 1083 // We have an explicit check for sandboxed pages first since:
1079 // 1. Sandboxed pages run in the same process as regular extension pages, so 1084 // 1. Sandboxed pages run in the same process as regular extension pages, so
1080 // the extension is considered active. 1085 // the extension is considered active.
1081 // 2. ScriptContext creation (which triggers bindings injection) happens 1086 // 2. ScriptContext creation (which triggers bindings injection) happens
1082 // before the SecurityContext is updated with the sandbox flags (after 1087 // before the SecurityContext is updated with the sandbox flags (after
1083 // reading the CSP header), so url_info.url().securityOrigin() is not 1088 // reading the CSP header), so url_info.url().securityOrigin() is not
1084 // unique yet. 1089 // unique yet.
1085 if (extensions_.IsSandboxedPage(url_info)) 1090 if (extensions_.IsSandboxedPage(url_info))
1086 return Feature::WEB_PAGE_CONTEXT; 1091 return Feature::WEB_PAGE_CONTEXT;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 // APIs, they don't get extension bindings injected. If we end up here it 1142 // APIs, they don't get extension bindings injected. If we end up here it
1138 // means that a sandboxed page somehow managed to invoke an API anyway, so 1143 // means that a sandboxed page somehow managed to invoke an API anyway, so
1139 // we should abort. 1144 // we should abort.
1140 WebKit::WebFrame* frame = context->web_frame(); 1145 WebKit::WebFrame* frame = context->web_frame();
1141 ExtensionURLInfo url_info(frame->document().securityOrigin(), 1146 ExtensionURLInfo url_info(frame->document().securityOrigin(),
1142 extensions::UserScriptSlave::GetDataSourceURLForFrame(frame)); 1147 extensions::UserScriptSlave::GetDataSourceURLForFrame(frame));
1143 CHECK(!extensions_.IsSandboxedPage(url_info)); 1148 CHECK(!extensions_.IsSandboxedPage(url_info));
1144 1149
1145 return true; 1150 return true;
1146 } 1151 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698