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

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

Issue 1293673002: Create thread-safe RendererExtensionRegistry from ExtensionSet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/renderer/dispatcher.h" 5 #include "extensions/renderer/dispatcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/alias.h" 10 #include "base/debug/alias.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 #include "extensions/renderer/guest_view/guest_view_internal_custom_bindings.h" 63 #include "extensions/renderer/guest_view/guest_view_internal_custom_bindings.h"
64 #include "extensions/renderer/i18n_custom_bindings.h" 64 #include "extensions/renderer/i18n_custom_bindings.h"
65 #include "extensions/renderer/id_generator_custom_bindings.h" 65 #include "extensions/renderer/id_generator_custom_bindings.h"
66 #include "extensions/renderer/lazy_background_page_native_handler.h" 66 #include "extensions/renderer/lazy_background_page_native_handler.h"
67 #include "extensions/renderer/logging_native_handler.h" 67 #include "extensions/renderer/logging_native_handler.h"
68 #include "extensions/renderer/messaging_bindings.h" 68 #include "extensions/renderer/messaging_bindings.h"
69 #include "extensions/renderer/module_system.h" 69 #include "extensions/renderer/module_system.h"
70 #include "extensions/renderer/print_native_handler.h" 70 #include "extensions/renderer/print_native_handler.h"
71 #include "extensions/renderer/process_info_native_handler.h" 71 #include "extensions/renderer/process_info_native_handler.h"
72 #include "extensions/renderer/render_frame_observer_natives.h" 72 #include "extensions/renderer/render_frame_observer_natives.h"
73 #include "extensions/renderer/renderer_extension_registry.h"
73 #include "extensions/renderer/request_sender.h" 74 #include "extensions/renderer/request_sender.h"
74 #include "extensions/renderer/runtime_custom_bindings.h" 75 #include "extensions/renderer/runtime_custom_bindings.h"
75 #include "extensions/renderer/safe_builtins.h" 76 #include "extensions/renderer/safe_builtins.h"
76 #include "extensions/renderer/script_context.h" 77 #include "extensions/renderer/script_context.h"
77 #include "extensions/renderer/script_context_set.h" 78 #include "extensions/renderer/script_context_set.h"
78 #include "extensions/renderer/script_injection.h" 79 #include "extensions/renderer/script_injection.h"
79 #include "extensions/renderer/script_injection_manager.h" 80 #include "extensions/renderer/script_injection_manager.h"
80 #include "extensions/renderer/send_request_natives.h" 81 #include "extensions/renderer/send_request_natives.h"
81 #include "extensions/renderer/set_icon_natives.h" 82 #include "extensions/renderer/set_icon_natives.h"
82 #include "extensions/renderer/test_features_native_handler.h" 83 #include "extensions/renderer/test_features_native_handler.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 *(base::CommandLine::ForCurrentProcess()); 195 *(base::CommandLine::ForCurrentProcess());
195 set_idle_notifications_ = 196 set_idle_notifications_ =
196 command_line.HasSwitch(switches::kExtensionProcess) || 197 command_line.HasSwitch(switches::kExtensionProcess) ||
197 command_line.HasSwitch(::switches::kSingleProcess); 198 command_line.HasSwitch(::switches::kSingleProcess);
198 199
199 if (set_idle_notifications_) { 200 if (set_idle_notifications_) {
200 RenderThread::Get()->SetIdleNotificationDelayInMs( 201 RenderThread::Get()->SetIdleNotificationDelayInMs(
201 kInitialExtensionIdleHandlerDelayMs); 202 kInitialExtensionIdleHandlerDelayMs);
202 } 203 }
203 204
204 script_context_set_.reset( 205 script_context_set_.reset(new ScriptContextSet(
205 new ScriptContextSet(&extensions_, &active_extension_ids_)); 206 RendererExtensionRegistry::GetRegistry()->GetMainThreadExtensionSet(),
not at google - send to devlin 2015/08/17 20:43:05 It's dangerous to be sending in a thread-unsafe ve
annekao 2015/08/17 23:51:10 Done. The main thread version has to be passed in
206 user_script_set_manager_.reset(new UserScriptSetManager(&extensions_)); 207 &active_extension_ids_));
207 script_injection_manager_.reset( 208 user_script_set_manager_.reset(new UserScriptSetManager(
208 new ScriptInjectionManager(&extensions_, user_script_set_manager_.get())); 209 RendererExtensionRegistry::GetRegistry()->GetMainThreadExtensionSet()));
210 script_injection_manager_.reset(new ScriptInjectionManager(
211 RendererExtensionRegistry::GetRegistry()->GetMainThreadExtensionSet(),
212 user_script_set_manager_.get()));
209 user_script_set_manager_observer_.Add(user_script_set_manager_.get()); 213 user_script_set_manager_observer_.Add(user_script_set_manager_.get());
210 request_sender_.reset(new RequestSender(this)); 214 request_sender_.reset(new RequestSender(this));
211 PopulateSourceMap(); 215 PopulateSourceMap();
212 } 216 }
213 217
214 Dispatcher::~Dispatcher() { 218 Dispatcher::~Dispatcher() {
215 } 219 }
216 220
217 void Dispatcher::OnRenderFrameCreated(content::RenderFrame* render_frame) { 221 void Dispatcher::OnRenderFrameCreated(content::RenderFrame* render_frame) {
218 script_injection_manager_->OnRenderFrameCreated(render_frame); 222 script_injection_manager_->OnRenderFrameCreated(render_frame);
219 } 223 }
220 224
221 bool Dispatcher::IsExtensionActive(const std::string& extension_id) const { 225 bool Dispatcher::IsExtensionActive(const std::string& extension_id) const {
222 bool is_active = 226 bool is_active =
223 active_extension_ids_.find(extension_id) != active_extension_ids_.end(); 227 active_extension_ids_.find(extension_id) != active_extension_ids_.end();
224 if (is_active) 228 if (is_active)
225 CHECK(extensions_.Contains(extension_id)); 229 CHECK(RendererExtensionRegistry::GetRegistry()->Contains(extension_id));
226 return is_active; 230 return is_active;
227 } 231 }
228 232
229 void Dispatcher::DidCreateScriptContext( 233 void Dispatcher::DidCreateScriptContext(
230 blink::WebLocalFrame* frame, 234 blink::WebLocalFrame* frame,
231 const v8::Local<v8::Context>& v8_context, 235 const v8::Local<v8::Context>& v8_context,
232 int extension_group, 236 int extension_group,
233 int world_id) { 237 int world_id) {
234 const base::TimeTicks start_time = base::TimeTicks::Now(); 238 const base::TimeTicks start_time = base::TimeTicks::Now();
235 239
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 } 327 }
324 328
325 void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) { 329 void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) {
326 // Note: use GetEffectiveDocumentURL not just frame->document()->url() 330 // Note: use GetEffectiveDocumentURL not just frame->document()->url()
327 // so that this also injects the stylesheet on about:blank frames that 331 // so that this also injects the stylesheet on about:blank frames that
328 // are hosted in the extension process. 332 // are hosted in the extension process.
329 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( 333 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL(
330 frame, frame->document().url(), true /* match_about_blank */); 334 frame, frame->document().url(), true /* match_about_blank */);
331 335
332 const Extension* extension = 336 const Extension* extension =
333 extensions_.GetExtensionOrAppByURL(effective_document_url); 337 RendererExtensionRegistry::GetRegistry()->GetExtensionOrAppByURL(
338 effective_document_url);
334 339
335 if (extension && 340 if (extension &&
336 (extension->is_extension() || extension->is_platform_app())) { 341 (extension->is_extension() || extension->is_platform_app())) {
337 int resource_id = extension->is_platform_app() ? IDR_PLATFORM_APP_CSS 342 int resource_id = extension->is_platform_app() ? IDR_PLATFORM_APP_CSS
338 : IDR_EXTENSION_FONTS_CSS; 343 : IDR_EXTENSION_FONTS_CSS;
339 std::string stylesheet = ResourceBundle::GetSharedInstance() 344 std::string stylesheet = ResourceBundle::GetSharedInstance()
340 .GetRawDataResource(resource_id) 345 .GetRawDataResource(resource_id)
341 .as_string(); 346 .as_string();
342 base::ReplaceFirstSubstringAfterOffset( 347 base::ReplaceFirstSubstringAfterOffset(
343 &stylesheet, 0, "$FONTFAMILY", system_font_family_); 348 &stylesheet, 0, "$FONTFAMILY", system_font_family_);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 410
406 // Reset the idle handler each time there's any activity like event or message 411 // Reset the idle handler each time there's any activity like event or message
407 // dispatch, for which Invoke is the chokepoint. 412 // dispatch, for which Invoke is the chokepoint.
408 if (set_idle_notifications_) { 413 if (set_idle_notifications_) {
409 RenderThread::Get()->ScheduleIdleHandler( 414 RenderThread::Get()->ScheduleIdleHandler(
410 kInitialExtensionIdleHandlerDelayMs); 415 kInitialExtensionIdleHandlerDelayMs);
411 } 416 }
412 417
413 // Tell the browser process when an event has been dispatched with a lazy 418 // Tell the browser process when an event has been dispatched with a lazy
414 // background page active. 419 // background page active.
415 const Extension* extension = extensions_.GetByID(extension_id); 420 const Extension* extension =
421 RendererExtensionRegistry::GetRegistry()->GetByID(extension_id);
416 if (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && 422 if (extension && BackgroundInfo::HasLazyBackgroundPage(extension) &&
417 module_name == kEventBindings && 423 module_name == kEventBindings &&
418 function_name == kEventDispatchFunction) { 424 function_name == kEventDispatchFunction) {
419 content::RenderFrame* background_frame = 425 content::RenderFrame* background_frame =
420 ExtensionFrameHelper::GetBackgroundPageFrame(extension_id); 426 ExtensionFrameHelper::GetBackgroundPageFrame(extension_id);
421 if (background_frame) { 427 if (background_frame) {
422 int message_id; 428 int message_id;
423 args.GetInteger(3, &message_id); 429 args.GetInteger(3, &message_id);
424 background_frame->Send(new ExtensionHostMsg_EventAck( 430 background_frame->Send(new ExtensionHostMsg_EventAck(
425 background_frame->GetRoutingID(), message_id)); 431 background_frame->GetRoutingID(), message_id));
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 module_system->RegisterNativeHandler( 700 module_system->RegisterNativeHandler(
695 "i18n", scoped_ptr<NativeHandler>(new I18NCustomBindings(context))); 701 "i18n", scoped_ptr<NativeHandler>(new I18NCustomBindings(context)));
696 module_system->RegisterNativeHandler( 702 module_system->RegisterNativeHandler(
697 "id_generator", 703 "id_generator",
698 scoped_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); 704 scoped_ptr<NativeHandler>(new IdGeneratorCustomBindings(context)));
699 module_system->RegisterNativeHandler( 705 module_system->RegisterNativeHandler(
700 "runtime", scoped_ptr<NativeHandler>(new RuntimeCustomBindings(context))); 706 "runtime", scoped_ptr<NativeHandler>(new RuntimeCustomBindings(context)));
701 } 707 }
702 708
703 void Dispatcher::LoadExtensionForTest(const Extension* extension) { 709 void Dispatcher::LoadExtensionForTest(const Extension* extension) {
704 CHECK(extensions_.Insert(extension)); 710 CHECK(RendererExtensionRegistry::GetRegistry()->Insert(extension));
not at google - send to devlin 2015/08/17 20:43:05 You could even just delete LoadExtensionForTest an
annekao 2015/08/17 23:51:10 Done.
705 } 711 }
706 712
707 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { 713 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) {
708 bool handled = true; 714 bool handled = true;
709 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) 715 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message)
710 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) 716 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension)
711 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) 717 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend)
712 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) 718 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage)
713 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) 719 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect)
714 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) 720 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 forced_idle_timer_->Start( 754 forced_idle_timer_->Start(
749 FROM_HERE, 755 FROM_HERE,
750 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), 756 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs),
751 RenderThread::Get(), 757 RenderThread::Get(),
752 &RenderThread::IdleHandler); 758 &RenderThread::IdleHandler);
753 } 759 }
754 760
755 // Initialize host permissions for any extensions that were activated before 761 // Initialize host permissions for any extensions that were activated before
756 // WebKit was initialized. 762 // WebKit was initialized.
757 for (const std::string& extension_id : active_extension_ids_) { 763 for (const std::string& extension_id : active_extension_ids_) {
758 const Extension* extension = extensions_.GetByID(extension_id); 764 const Extension* extension =
765 RendererExtensionRegistry::GetRegistry()->GetByID(extension_id);
759 CHECK(extension); 766 CHECK(extension);
760 InitOriginPermissions(extension); 767 InitOriginPermissions(extension);
761 } 768 }
762 769
763 EnableCustomElementWhiteList(); 770 EnableCustomElementWhiteList();
764 771
765 is_webkit_initialized_ = true; 772 is_webkit_initialized_ = true;
766 } 773 }
767 774
768 void Dispatcher::IdleNotification() { 775 void Dispatcher::IdleNotification() {
(...skipping 13 matching lines...) Expand all
782 } 789 }
783 } 790 }
784 791
785 void Dispatcher::OnRenderProcessShutdown() { 792 void Dispatcher::OnRenderProcessShutdown() {
786 v8_schema_registry_.reset(); 793 v8_schema_registry_.reset();
787 forced_idle_timer_.reset(); 794 forced_idle_timer_.reset();
788 content_watcher_.reset(); 795 content_watcher_.reset();
789 } 796 }
790 797
791 void Dispatcher::OnActivateExtension(const std::string& extension_id) { 798 void Dispatcher::OnActivateExtension(const std::string& extension_id) {
792 const Extension* extension = extensions_.GetByID(extension_id); 799 const Extension* extension =
800 RendererExtensionRegistry::GetRegistry()->GetByID(extension_id);
793 if (!extension) { 801 if (!extension) {
794 // Extension was activated but was never loaded. This probably means that 802 // Extension was activated but was never loaded. This probably means that
795 // the renderer failed to load it (or the browser failed to tell us when it 803 // the renderer failed to load it (or the browser failed to tell us when it
796 // did). Failures shouldn't happen, but instead of crashing there (which 804 // did). Failures shouldn't happen, but instead of crashing there (which
797 // executes on all renderers) be conservative and only crash in the renderer 805 // executes on all renderers) be conservative and only crash in the renderer
798 // of the extension which failed to load; this one. 806 // of the extension which failed to load; this one.
799 std::string& error = extension_load_errors_[extension_id]; 807 std::string& error = extension_load_errors_[extension_id];
800 char minidump[256]; 808 char minidump[256];
801 base::debug::Alias(&minidump); 809 base::debug::Alias(&minidump);
802 base::snprintf(minidump, 810 base::snprintf(minidump,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 889
882 // TODO(kalman): This test is deliberately not a CHECK (though I wish it 890 // TODO(kalman): This test is deliberately not a CHECK (though I wish it
883 // could be) and uses extension->id() not params.id: 891 // could be) and uses extension->id() not params.id:
884 // 1. For some reason params.id can be empty. I've only seen it with 892 // 1. For some reason params.id can be empty. I've only seen it with
885 // the webstore extension, in tests, and I've spent some time trying to 893 // the webstore extension, in tests, and I've spent some time trying to
886 // figure out why - but cost/benefit won. 894 // figure out why - but cost/benefit won.
887 // 2. The browser only sends this IPC to RenderProcessHosts once, but the 895 // 2. The browser only sends this IPC to RenderProcessHosts once, but the
888 // Dispatcher is attached to a RenderThread. Presumably there is a 896 // Dispatcher is attached to a RenderThread. Presumably there is a
889 // mismatch there. In theory one would think it's possible for the 897 // mismatch there. In theory one would think it's possible for the
890 // browser to figure this out itself - but again, cost/benefit. 898 // browser to figure this out itself - but again, cost/benefit.
891 if (!extensions_.Contains(extension->id())) 899 if (!RendererExtensionRegistry::GetRegistry()->Contains(extension->id()))
not at google - send to devlin 2015/08/17 20:43:05 When you use RendererExtensionRegistry multiple ti
annekao 2015/08/17 23:51:10 Done.
892 extensions_.Insert(extension); 900 RendererExtensionRegistry::GetRegistry()->Insert(extension);
893 } 901 }
894 902
895 // Update the available bindings for all contexts. These may have changed if 903 // Update the available bindings for all contexts. These may have changed if
896 // an externally_connectable extension was loaded that can connect to an 904 // an externally_connectable extension was loaded that can connect to an
897 // open webpage. 905 // open webpage.
898 UpdateBindings(""); 906 UpdateBindings("");
899 } 907 }
900 908
901 void Dispatcher::OnMessageInvoke(const std::string& extension_id, 909 void Dispatcher::OnMessageInvoke(const std::string& extension_id,
902 const std::string& module_name, 910 const std::string& module_name,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 RenderThread::Get()->Send(new ExtensionHostMsg_SuspendAck(extension_id)); 953 RenderThread::Get()->Send(new ExtensionHostMsg_SuspendAck(extension_id));
946 } 954 }
947 955
948 void Dispatcher::OnTransferBlobs(const std::vector<std::string>& blob_uuids) { 956 void Dispatcher::OnTransferBlobs(const std::vector<std::string>& blob_uuids) {
949 RenderThread::Get()->Send(new ExtensionHostMsg_TransferBlobsAck(blob_uuids)); 957 RenderThread::Get()->Send(new ExtensionHostMsg_TransferBlobsAck(blob_uuids));
950 } 958 }
951 959
952 void Dispatcher::OnUnloaded(const std::string& id) { 960 void Dispatcher::OnUnloaded(const std::string& id) {
953 // See comment in OnLoaded for why it would be nice, but perhaps incorrect, 961 // See comment in OnLoaded for why it would be nice, but perhaps incorrect,
954 // to CHECK here rather than guarding. 962 // to CHECK here rather than guarding.
955 if (!extensions_.Remove(id)) 963 if (!RendererExtensionRegistry::GetRegistry()->Remove(id))
956 return; 964 return;
957 965
958 active_extension_ids_.erase(id); 966 active_extension_ids_.erase(id);
959 967
960 script_injection_manager_->OnExtensionUnloaded(id); 968 script_injection_manager_->OnExtensionUnloaded(id);
961 969
962 // If the extension is later reloaded with a different set of permissions, 970 // If the extension is later reloaded with a different set of permissions,
963 // we'd like it to get a new isolated world ID, so that it can pick up the 971 // we'd like it to get a new isolated world ID, so that it can pick up the
964 // changed origin whitelist. 972 // changed origin whitelist.
965 ScriptInjection::RemoveIsolatedWorld(id); 973 ScriptInjection::RemoveIsolatedWorld(id);
(...skipping 15 matching lines...) Expand all
981 // reloaded with a new messages map. 989 // reloaded with a new messages map.
982 EraseL10nMessagesMap(id); 990 EraseL10nMessagesMap(id);
983 991
984 // We don't do anything with existing platform-app stylesheets. They will 992 // We don't do anything with existing platform-app stylesheets. They will
985 // stay resident, but the URL pattern corresponding to the unloaded 993 // stay resident, but the URL pattern corresponding to the unloaded
986 // extension's URL just won't match anything anymore. 994 // extension's URL just won't match anything anymore.
987 } 995 }
988 996
989 void Dispatcher::OnUpdatePermissions( 997 void Dispatcher::OnUpdatePermissions(
990 const ExtensionMsg_UpdatePermissions_Params& params) { 998 const ExtensionMsg_UpdatePermissions_Params& params) {
991 const Extension* extension = extensions_.GetByID(params.extension_id); 999 const Extension* extension =
1000 RendererExtensionRegistry::GetRegistry()->GetByID(params.extension_id);
992 if (!extension) 1001 if (!extension)
993 return; 1002 return;
994 1003
995 scoped_refptr<const PermissionSet> active = 1004 scoped_refptr<const PermissionSet> active =
996 params.active_permissions.ToPermissionSet(); 1005 params.active_permissions.ToPermissionSet();
997 scoped_refptr<const PermissionSet> withheld = 1006 scoped_refptr<const PermissionSet> withheld =
998 params.withheld_permissions.ToPermissionSet(); 1007 params.withheld_permissions.ToPermissionSet();
999 1008
1000 if (is_webkit_initialized_) { 1009 if (is_webkit_initialized_) {
1001 UpdateOriginPermissions( 1010 UpdateOriginPermissions(
1002 extension->url(), 1011 extension->url(),
1003 extension->permissions_data()->GetEffectiveHostPermissions(), 1012 extension->permissions_data()->GetEffectiveHostPermissions(),
1004 active->effective_hosts()); 1013 active->effective_hosts());
1005 } 1014 }
1006 1015
1007 extension->permissions_data()->SetPermissions(active, withheld); 1016 extension->permissions_data()->SetPermissions(active, withheld);
1008 UpdateBindings(extension->id()); 1017 UpdateBindings(extension->id());
1009 } 1018 }
1010 1019
1011 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url, 1020 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url,
1012 const std::string& extension_id, 1021 const std::string& extension_id,
1013 const URLPatternSet& new_hosts, 1022 const URLPatternSet& new_hosts,
1014 bool update_origin_whitelist, 1023 bool update_origin_whitelist,
1015 int tab_id) { 1024 int tab_id) {
1016 const Extension* extension = extensions_.GetByID(extension_id); 1025 const Extension* extension =
1026 RendererExtensionRegistry::GetRegistry()->GetByID(extension_id);
1017 if (!extension) 1027 if (!extension)
1018 return; 1028 return;
1019 1029
1020 URLPatternSet old_effective = 1030 URLPatternSet old_effective =
1021 extension->permissions_data()->GetEffectiveHostPermissions(); 1031 extension->permissions_data()->GetEffectiveHostPermissions();
1022 extension->permissions_data()->UpdateTabSpecificPermissions( 1032 extension->permissions_data()->UpdateTabSpecificPermissions(
1023 tab_id, 1033 tab_id,
1024 new extensions::PermissionSet(extensions::APIPermissionSet(), 1034 new extensions::PermissionSet(extensions::APIPermissionSet(),
1025 extensions::ManifestPermissionSet(), 1035 extensions::ManifestPermissionSet(),
1026 new_hosts, 1036 new_hosts,
1027 extensions::URLPatternSet())); 1037 extensions::URLPatternSet()));
1028 1038
1029 if (is_webkit_initialized_ && update_origin_whitelist) { 1039 if (is_webkit_initialized_ && update_origin_whitelist) {
1030 UpdateOriginPermissions( 1040 UpdateOriginPermissions(
1031 extension->url(), 1041 extension->url(),
1032 old_effective, 1042 old_effective,
1033 extension->permissions_data()->GetEffectiveHostPermissions()); 1043 extension->permissions_data()->GetEffectiveHostPermissions());
1034 } 1044 }
1035 } 1045 }
1036 1046
1037 void Dispatcher::OnClearTabSpecificPermissions( 1047 void Dispatcher::OnClearTabSpecificPermissions(
1038 const std::vector<std::string>& extension_ids, 1048 const std::vector<std::string>& extension_ids,
1039 bool update_origin_whitelist, 1049 bool update_origin_whitelist,
1040 int tab_id) { 1050 int tab_id) {
1041 for (const std::string& id : extension_ids) { 1051 for (const std::string& id : extension_ids) {
1042 const Extension* extension = extensions_.GetByID(id); 1052 const Extension* extension =
1053 RendererExtensionRegistry::GetRegistry()->GetByID(id);
1043 if (extension) { 1054 if (extension) {
1044 URLPatternSet old_effective = 1055 URLPatternSet old_effective =
1045 extension->permissions_data()->GetEffectiveHostPermissions(); 1056 extension->permissions_data()->GetEffectiveHostPermissions();
1046 extension->permissions_data()->ClearTabSpecificPermissions(tab_id); 1057 extension->permissions_data()->ClearTabSpecificPermissions(tab_id);
1047 if (is_webkit_initialized_ && update_origin_whitelist) { 1058 if (is_webkit_initialized_ && update_origin_whitelist) {
1048 UpdateOriginPermissions( 1059 UpdateOriginPermissions(
1049 extension->url(), 1060 extension->url(),
1050 old_effective, 1061 old_effective,
1051 extension->permissions_data()->GetEffectiveHostPermissions()); 1062 extension->permissions_data()->GetEffectiveHostPermissions());
1052 } 1063 }
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 send_request_disabled))); 1284 send_request_disabled)));
1274 1285
1275 delegate_->RegisterNativeHandlers(this, module_system, context); 1286 delegate_->RegisterNativeHandlers(this, module_system, context);
1276 } 1287 }
1277 1288
1278 bool Dispatcher::IsRuntimeAvailableToContext(ScriptContext* context) { 1289 bool Dispatcher::IsRuntimeAvailableToContext(ScriptContext* context) {
1279 if (extensions::FeatureSwitch::surface_worker()->IsEnabled() && 1290 if (extensions::FeatureSwitch::surface_worker()->IsEnabled() &&
1280 context->GetAvailability("surfaceWorkerInternal").is_available()) { 1291 context->GetAvailability("surfaceWorkerInternal").is_available()) {
1281 return true; 1292 return true;
1282 } 1293 }
1283 for (const auto& extension : extensions_) { 1294 for (const auto& extension : *RendererExtensionRegistry::GetRegistry()) {
1284 ExternallyConnectableInfo* info = static_cast<ExternallyConnectableInfo*>( 1295 ExternallyConnectableInfo* info = static_cast<ExternallyConnectableInfo*>(
1285 extension->GetManifestData(manifest_keys::kExternallyConnectable)); 1296 extension->GetManifestData(manifest_keys::kExternallyConnectable));
1286 if (info && info->matches.MatchesURL(context->GetURL())) 1297 if (info && info->matches.MatchesURL(context->GetURL()))
1287 return true; 1298 return true;
1288 } 1299 }
1289 return false; 1300 return false;
1290 } 1301 }
1291 1302
1292 void Dispatcher::UpdateContentCapabilities(ScriptContext* context) { 1303 void Dispatcher::UpdateContentCapabilities(ScriptContext* context) {
1293 APIPermissionSet permissions; 1304 APIPermissionSet permissions;
1294 for (const auto& extension : extensions_) { 1305 for (const auto& extension : *RendererExtensionRegistry::GetRegistry()) {
1295 const ContentCapabilitiesInfo& info = 1306 const ContentCapabilitiesInfo& info =
1296 ContentCapabilitiesInfo::Get(extension.get()); 1307 ContentCapabilitiesInfo::Get(extension.get());
1297 if (info.url_patterns.MatchesURL(context->GetURL())) { 1308 if (info.url_patterns.MatchesURL(context->GetURL())) {
1298 APIPermissionSet new_permissions; 1309 APIPermissionSet new_permissions;
1299 APIPermissionSet::Union(permissions, info.permissions, &new_permissions); 1310 APIPermissionSet::Union(permissions, info.permissions, &new_permissions);
1300 permissions = new_permissions; 1311 permissions = new_permissions;
1301 } 1312 }
1302 } 1313 }
1303 context->SetContentCapabilities(permissions); 1314 context->SetContentCapabilities(permissions);
1304 } 1315 }
1305 1316
1306 void Dispatcher::PopulateSourceMap() { 1317 void Dispatcher::PopulateSourceMap() {
1307 const std::vector<std::pair<std::string, int> > resources = GetJsResources(); 1318 const std::vector<std::pair<std::string, int> > resources = GetJsResources();
1308 for (std::vector<std::pair<std::string, int> >::const_iterator resource = 1319 for (std::vector<std::pair<std::string, int> >::const_iterator resource =
1309 resources.begin(); 1320 resources.begin();
1310 resource != resources.end(); 1321 resource != resources.end();
1311 ++resource) { 1322 ++resource) {
1312 source_map_.RegisterSource(resource->first, resource->second); 1323 source_map_.RegisterSource(resource->first, resource->second);
1313 } 1324 }
1314 delegate_->PopulateSourceMap(&source_map_); 1325 delegate_->PopulateSourceMap(&source_map_);
1315 } 1326 }
1316 1327
1317 bool Dispatcher::IsWithinPlatformApp() { 1328 bool Dispatcher::IsWithinPlatformApp() {
1318 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); 1329 for (std::set<std::string>::iterator iter = active_extension_ids_.begin();
1319 iter != active_extension_ids_.end(); 1330 iter != active_extension_ids_.end();
1320 ++iter) { 1331 ++iter) {
1321 const Extension* extension = extensions_.GetByID(*iter); 1332 const Extension* extension =
1333 RendererExtensionRegistry::GetRegistry()->GetByID(*iter);
1322 if (extension && extension->is_platform_app()) 1334 if (extension && extension->is_platform_app())
1323 return true; 1335 return true;
1324 } 1336 }
1325 return false; 1337 return false;
1326 } 1338 }
1327 1339
1328 v8::Local<v8::Object> Dispatcher::GetOrCreateObject( 1340 v8::Local<v8::Object> Dispatcher::GetOrCreateObject(
1329 const v8::Local<v8::Object>& object, 1341 const v8::Local<v8::Object>& object,
1330 const std::string& field, 1342 const std::string& field,
1331 v8::Isolate* isolate) { 1343 v8::Isolate* isolate) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 void Dispatcher::AddChannelSpecificFeatures() { 1460 void Dispatcher::AddChannelSpecificFeatures() {
1449 // chrome-extension: resources should be allowed to register a Service Worker. 1461 // chrome-extension: resources should be allowed to register a Service Worker.
1450 if (FeatureProvider::GetBehaviorFeature(BehaviorFeature::kServiceWorker) 1462 if (FeatureProvider::GetBehaviorFeature(BehaviorFeature::kServiceWorker)
1451 ->IsAvailableToEnvironment() 1463 ->IsAvailableToEnvironment()
1452 .is_available()) 1464 .is_available())
1453 WebSecurityPolicy::registerURLSchemeAsAllowingServiceWorkers( 1465 WebSecurityPolicy::registerURLSchemeAsAllowingServiceWorkers(
1454 WebString::fromUTF8(kExtensionScheme)); 1466 WebString::fromUTF8(kExtensionScheme));
1455 } 1467 }
1456 1468
1457 } // namespace extensions 1469 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698