OLD | NEW |
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 Loading... |
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 *(base::CommandLine::ForCurrentProcess()); | 196 *(base::CommandLine::ForCurrentProcess()); |
196 set_idle_notifications_ = | 197 set_idle_notifications_ = |
197 command_line.HasSwitch(switches::kExtensionProcess) || | 198 command_line.HasSwitch(switches::kExtensionProcess) || |
198 command_line.HasSwitch(::switches::kSingleProcess); | 199 command_line.HasSwitch(::switches::kSingleProcess); |
199 | 200 |
200 if (set_idle_notifications_) { | 201 if (set_idle_notifications_) { |
201 RenderThread::Get()->SetIdleNotificationDelayInMs( | 202 RenderThread::Get()->SetIdleNotificationDelayInMs( |
202 kInitialExtensionIdleHandlerDelayMs); | 203 kInitialExtensionIdleHandlerDelayMs); |
203 } | 204 } |
204 | 205 |
205 script_context_set_.reset( | 206 script_context_set_.reset(new ScriptContextSet(&active_extension_ids_)); |
206 new ScriptContextSet(&extensions_, &active_extension_ids_)); | 207 user_script_set_manager_.reset(new UserScriptSetManager()); |
207 user_script_set_manager_.reset(new UserScriptSetManager(&extensions_)); | |
208 script_injection_manager_.reset( | 208 script_injection_manager_.reset( |
209 new ScriptInjectionManager(&extensions_, user_script_set_manager_.get())); | 209 new ScriptInjectionManager(user_script_set_manager_.get())); |
210 user_script_set_manager_observer_.Add(user_script_set_manager_.get()); | 210 user_script_set_manager_observer_.Add(user_script_set_manager_.get()); |
211 request_sender_.reset(new RequestSender(this)); | 211 request_sender_.reset(new RequestSender(this)); |
212 PopulateSourceMap(); | 212 PopulateSourceMap(); |
213 } | 213 } |
214 | 214 |
215 Dispatcher::~Dispatcher() { | 215 Dispatcher::~Dispatcher() { |
216 } | 216 } |
217 | 217 |
218 void Dispatcher::OnRenderFrameCreated(content::RenderFrame* render_frame) { | 218 void Dispatcher::OnRenderFrameCreated(content::RenderFrame* render_frame) { |
219 script_injection_manager_->OnRenderFrameCreated(render_frame); | 219 script_injection_manager_->OnRenderFrameCreated(render_frame); |
220 } | 220 } |
221 | 221 |
222 bool Dispatcher::IsExtensionActive(const std::string& extension_id) const { | 222 bool Dispatcher::IsExtensionActive(const std::string& extension_id) const { |
223 bool is_active = | 223 bool is_active = |
224 active_extension_ids_.find(extension_id) != active_extension_ids_.end(); | 224 active_extension_ids_.find(extension_id) != active_extension_ids_.end(); |
225 if (is_active) | 225 if (is_active) |
226 CHECK(extensions_.Contains(extension_id)); | 226 CHECK(RendererExtensionRegistry::Get()->Contains(extension_id)); |
227 return is_active; | 227 return is_active; |
228 } | 228 } |
229 | 229 |
230 void Dispatcher::DidCreateScriptContext( | 230 void Dispatcher::DidCreateScriptContext( |
231 blink::WebLocalFrame* frame, | 231 blink::WebLocalFrame* frame, |
232 const v8::Local<v8::Context>& v8_context, | 232 const v8::Local<v8::Context>& v8_context, |
233 int extension_group, | 233 int extension_group, |
234 int world_id) { | 234 int world_id) { |
235 const base::TimeTicks start_time = base::TimeTicks::Now(); | 235 const base::TimeTicks start_time = base::TimeTicks::Now(); |
236 | 236 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 } | 334 } |
335 | 335 |
336 void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) { | 336 void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) { |
337 // Note: use GetEffectiveDocumentURL not just frame->document()->url() | 337 // Note: use GetEffectiveDocumentURL not just frame->document()->url() |
338 // so that this also injects the stylesheet on about:blank frames that | 338 // so that this also injects the stylesheet on about:blank frames that |
339 // are hosted in the extension process. | 339 // are hosted in the extension process. |
340 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( | 340 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
341 frame, frame->document().url(), true /* match_about_blank */); | 341 frame, frame->document().url(), true /* match_about_blank */); |
342 | 342 |
343 const Extension* extension = | 343 const Extension* extension = |
344 extensions_.GetExtensionOrAppByURL(effective_document_url); | 344 RendererExtensionRegistry::Get()->GetExtensionOrAppByURL( |
| 345 effective_document_url); |
345 | 346 |
346 if (extension && | 347 if (extension && |
347 (extension->is_extension() || extension->is_platform_app())) { | 348 (extension->is_extension() || extension->is_platform_app())) { |
348 int resource_id = extension->is_platform_app() ? IDR_PLATFORM_APP_CSS | 349 int resource_id = extension->is_platform_app() ? IDR_PLATFORM_APP_CSS |
349 : IDR_EXTENSION_FONTS_CSS; | 350 : IDR_EXTENSION_FONTS_CSS; |
350 std::string stylesheet = ResourceBundle::GetSharedInstance() | 351 std::string stylesheet = ResourceBundle::GetSharedInstance() |
351 .GetRawDataResource(resource_id) | 352 .GetRawDataResource(resource_id) |
352 .as_string(); | 353 .as_string(); |
353 base::ReplaceFirstSubstringAfterOffset( | 354 base::ReplaceFirstSubstringAfterOffset( |
354 &stylesheet, 0, "$FONTFAMILY", system_font_family_); | 355 &stylesheet, 0, "$FONTFAMILY", system_font_family_); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 | 417 |
417 // Reset the idle handler each time there's any activity like event or message | 418 // Reset the idle handler each time there's any activity like event or message |
418 // dispatch, for which Invoke is the chokepoint. | 419 // dispatch, for which Invoke is the chokepoint. |
419 if (set_idle_notifications_) { | 420 if (set_idle_notifications_) { |
420 RenderThread::Get()->ScheduleIdleHandler( | 421 RenderThread::Get()->ScheduleIdleHandler( |
421 kInitialExtensionIdleHandlerDelayMs); | 422 kInitialExtensionIdleHandlerDelayMs); |
422 } | 423 } |
423 | 424 |
424 // Tell the browser process when an event has been dispatched with a lazy | 425 // Tell the browser process when an event has been dispatched with a lazy |
425 // background page active. | 426 // background page active. |
426 const Extension* extension = extensions_.GetByID(extension_id); | 427 const Extension* extension = |
| 428 RendererExtensionRegistry::Get()->GetByID(extension_id); |
427 if (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && | 429 if (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && |
428 module_name == kEventBindings && | 430 module_name == kEventBindings && |
429 function_name == kEventDispatchFunction) { | 431 function_name == kEventDispatchFunction) { |
430 content::RenderFrame* background_frame = | 432 content::RenderFrame* background_frame = |
431 ExtensionFrameHelper::GetBackgroundPageFrame(extension_id); | 433 ExtensionFrameHelper::GetBackgroundPageFrame(extension_id); |
432 if (background_frame) { | 434 if (background_frame) { |
433 int message_id; | 435 int message_id; |
434 args.GetInteger(3, &message_id); | 436 args.GetInteger(3, &message_id); |
435 background_frame->Send(new ExtensionHostMsg_EventAck( | 437 background_frame->Send(new ExtensionHostMsg_EventAck( |
436 background_frame->GetRoutingID(), message_id)); | 438 background_frame->GetRoutingID(), message_id)); |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 new GuestViewInternalCustomBindings(context))); | 705 new GuestViewInternalCustomBindings(context))); |
704 module_system->RegisterNativeHandler( | 706 module_system->RegisterNativeHandler( |
705 "i18n", scoped_ptr<NativeHandler>(new I18NCustomBindings(context))); | 707 "i18n", scoped_ptr<NativeHandler>(new I18NCustomBindings(context))); |
706 module_system->RegisterNativeHandler( | 708 module_system->RegisterNativeHandler( |
707 "id_generator", | 709 "id_generator", |
708 scoped_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); | 710 scoped_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); |
709 module_system->RegisterNativeHandler( | 711 module_system->RegisterNativeHandler( |
710 "runtime", scoped_ptr<NativeHandler>(new RuntimeCustomBindings(context))); | 712 "runtime", scoped_ptr<NativeHandler>(new RuntimeCustomBindings(context))); |
711 } | 713 } |
712 | 714 |
713 void Dispatcher::LoadExtensionForTest(const Extension* extension) { | |
714 CHECK(extensions_.Insert(extension)); | |
715 } | |
716 | |
717 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { | 715 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { |
718 bool handled = true; | 716 bool handled = true; |
719 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) | 717 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) |
720 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) | 718 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) |
721 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) | 719 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) |
722 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) | 720 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) |
723 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) | 721 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) |
724 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) | 722 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) |
725 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) | 723 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) |
726 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) | 724 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 forced_idle_timer_->Start( | 756 forced_idle_timer_->Start( |
759 FROM_HERE, | 757 FROM_HERE, |
760 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), | 758 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), |
761 RenderThread::Get(), | 759 RenderThread::Get(), |
762 &RenderThread::IdleHandler); | 760 &RenderThread::IdleHandler); |
763 } | 761 } |
764 | 762 |
765 // Initialize host permissions for any extensions that were activated before | 763 // Initialize host permissions for any extensions that were activated before |
766 // WebKit was initialized. | 764 // WebKit was initialized. |
767 for (const std::string& extension_id : active_extension_ids_) { | 765 for (const std::string& extension_id : active_extension_ids_) { |
768 const Extension* extension = extensions_.GetByID(extension_id); | 766 const Extension* extension = |
| 767 RendererExtensionRegistry::Get()->GetByID(extension_id); |
769 CHECK(extension); | 768 CHECK(extension); |
770 InitOriginPermissions(extension); | 769 InitOriginPermissions(extension); |
771 } | 770 } |
772 | 771 |
773 EnableCustomElementWhiteList(); | 772 EnableCustomElementWhiteList(); |
774 | 773 |
775 is_webkit_initialized_ = true; | 774 is_webkit_initialized_ = true; |
776 } | 775 } |
777 | 776 |
778 void Dispatcher::IdleNotification() { | 777 void Dispatcher::IdleNotification() { |
(...skipping 13 matching lines...) Expand all Loading... |
792 } | 791 } |
793 } | 792 } |
794 | 793 |
795 void Dispatcher::OnRenderProcessShutdown() { | 794 void Dispatcher::OnRenderProcessShutdown() { |
796 v8_schema_registry_.reset(); | 795 v8_schema_registry_.reset(); |
797 forced_idle_timer_.reset(); | 796 forced_idle_timer_.reset(); |
798 content_watcher_.reset(); | 797 content_watcher_.reset(); |
799 } | 798 } |
800 | 799 |
801 void Dispatcher::OnActivateExtension(const std::string& extension_id) { | 800 void Dispatcher::OnActivateExtension(const std::string& extension_id) { |
802 const Extension* extension = extensions_.GetByID(extension_id); | 801 const Extension* extension = |
| 802 RendererExtensionRegistry::Get()->GetByID(extension_id); |
803 if (!extension) { | 803 if (!extension) { |
804 // Extension was activated but was never loaded. This probably means that | 804 // Extension was activated but was never loaded. This probably means that |
805 // the renderer failed to load it (or the browser failed to tell us when it | 805 // the renderer failed to load it (or the browser failed to tell us when it |
806 // did). Failures shouldn't happen, but instead of crashing there (which | 806 // did). Failures shouldn't happen, but instead of crashing there (which |
807 // executes on all renderers) be conservative and only crash in the renderer | 807 // executes on all renderers) be conservative and only crash in the renderer |
808 // of the extension which failed to load; this one. | 808 // of the extension which failed to load; this one. |
809 std::string& error = extension_load_errors_[extension_id]; | 809 std::string& error = extension_load_errors_[extension_id]; |
810 char minidump[256]; | 810 char minidump[256]; |
811 base::debug::Alias(&minidump); | 811 base::debug::Alias(&minidump); |
812 base::snprintf(minidump, | 812 base::snprintf(minidump, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 std::string error; | 882 std::string error; |
883 scoped_refptr<const Extension> extension = param.ConvertToExtension(&error); | 883 scoped_refptr<const Extension> extension = param.ConvertToExtension(&error); |
884 if (!extension.get()) { | 884 if (!extension.get()) { |
885 NOTREACHED() << error; | 885 NOTREACHED() << error; |
886 // Note: in tests |param.id| has been observed to be empty (see comment | 886 // Note: in tests |param.id| has been observed to be empty (see comment |
887 // just below) so this isn't all that reliable. | 887 // just below) so this isn't all that reliable. |
888 extension_load_errors_[param.id] = error; | 888 extension_load_errors_[param.id] = error; |
889 continue; | 889 continue; |
890 } | 890 } |
891 | 891 |
| 892 RendererExtensionRegistry* extension_registry = |
| 893 RendererExtensionRegistry::Get(); |
892 // TODO(kalman): This test is deliberately not a CHECK (though I wish it | 894 // TODO(kalman): This test is deliberately not a CHECK (though I wish it |
893 // could be) and uses extension->id() not params.id: | 895 // could be) and uses extension->id() not params.id: |
894 // 1. For some reason params.id can be empty. I've only seen it with | 896 // 1. For some reason params.id can be empty. I've only seen it with |
895 // the webstore extension, in tests, and I've spent some time trying to | 897 // the webstore extension, in tests, and I've spent some time trying to |
896 // figure out why - but cost/benefit won. | 898 // figure out why - but cost/benefit won. |
897 // 2. The browser only sends this IPC to RenderProcessHosts once, but the | 899 // 2. The browser only sends this IPC to RenderProcessHosts once, but the |
898 // Dispatcher is attached to a RenderThread. Presumably there is a | 900 // Dispatcher is attached to a RenderThread. Presumably there is a |
899 // mismatch there. In theory one would think it's possible for the | 901 // mismatch there. In theory one would think it's possible for the |
900 // browser to figure this out itself - but again, cost/benefit. | 902 // browser to figure this out itself - but again, cost/benefit. |
901 if (!extensions_.Contains(extension->id())) | 903 if (!extension_registry->Contains(extension->id())) |
902 extensions_.Insert(extension); | 904 extension_registry->Insert(extension); |
903 } | 905 } |
904 | 906 |
905 // Update the available bindings for all contexts. These may have changed if | 907 // Update the available bindings for all contexts. These may have changed if |
906 // an externally_connectable extension was loaded that can connect to an | 908 // an externally_connectable extension was loaded that can connect to an |
907 // open webpage. | 909 // open webpage. |
908 UpdateBindings(""); | 910 UpdateBindings(""); |
909 } | 911 } |
910 | 912 |
911 void Dispatcher::OnMessageInvoke(const std::string& extension_id, | 913 void Dispatcher::OnMessageInvoke(const std::string& extension_id, |
912 const std::string& module_name, | 914 const std::string& module_name, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 RenderThread::Get()->Send(new ExtensionHostMsg_SuspendAck(extension_id)); | 957 RenderThread::Get()->Send(new ExtensionHostMsg_SuspendAck(extension_id)); |
956 } | 958 } |
957 | 959 |
958 void Dispatcher::OnTransferBlobs(const std::vector<std::string>& blob_uuids) { | 960 void Dispatcher::OnTransferBlobs(const std::vector<std::string>& blob_uuids) { |
959 RenderThread::Get()->Send(new ExtensionHostMsg_TransferBlobsAck(blob_uuids)); | 961 RenderThread::Get()->Send(new ExtensionHostMsg_TransferBlobsAck(blob_uuids)); |
960 } | 962 } |
961 | 963 |
962 void Dispatcher::OnUnloaded(const std::string& id) { | 964 void Dispatcher::OnUnloaded(const std::string& id) { |
963 // See comment in OnLoaded for why it would be nice, but perhaps incorrect, | 965 // See comment in OnLoaded for why it would be nice, but perhaps incorrect, |
964 // to CHECK here rather than guarding. | 966 // to CHECK here rather than guarding. |
965 if (!extensions_.Remove(id)) | 967 if (!RendererExtensionRegistry::Get()->Remove(id)) |
966 return; | 968 return; |
967 | 969 |
968 active_extension_ids_.erase(id); | 970 active_extension_ids_.erase(id); |
969 | 971 |
970 script_injection_manager_->OnExtensionUnloaded(id); | 972 script_injection_manager_->OnExtensionUnloaded(id); |
971 | 973 |
972 // If the extension is later reloaded with a different set of permissions, | 974 // If the extension is later reloaded with a different set of permissions, |
973 // we'd like it to get a new isolated world ID, so that it can pick up the | 975 // we'd like it to get a new isolated world ID, so that it can pick up the |
974 // changed origin whitelist. | 976 // changed origin whitelist. |
975 ScriptInjection::RemoveIsolatedWorld(id); | 977 ScriptInjection::RemoveIsolatedWorld(id); |
(...skipping 15 matching lines...) Expand all Loading... |
991 // reloaded with a new messages map. | 993 // reloaded with a new messages map. |
992 EraseL10nMessagesMap(id); | 994 EraseL10nMessagesMap(id); |
993 | 995 |
994 // We don't do anything with existing platform-app stylesheets. They will | 996 // We don't do anything with existing platform-app stylesheets. They will |
995 // stay resident, but the URL pattern corresponding to the unloaded | 997 // stay resident, but the URL pattern corresponding to the unloaded |
996 // extension's URL just won't match anything anymore. | 998 // extension's URL just won't match anything anymore. |
997 } | 999 } |
998 | 1000 |
999 void Dispatcher::OnUpdatePermissions( | 1001 void Dispatcher::OnUpdatePermissions( |
1000 const ExtensionMsg_UpdatePermissions_Params& params) { | 1002 const ExtensionMsg_UpdatePermissions_Params& params) { |
1001 const Extension* extension = extensions_.GetByID(params.extension_id); | 1003 const Extension* extension = |
| 1004 RendererExtensionRegistry::Get()->GetByID(params.extension_id); |
1002 if (!extension) | 1005 if (!extension) |
1003 return; | 1006 return; |
1004 | 1007 |
1005 scoped_refptr<const PermissionSet> active = | 1008 scoped_refptr<const PermissionSet> active = |
1006 params.active_permissions.ToPermissionSet(); | 1009 params.active_permissions.ToPermissionSet(); |
1007 scoped_refptr<const PermissionSet> withheld = | 1010 scoped_refptr<const PermissionSet> withheld = |
1008 params.withheld_permissions.ToPermissionSet(); | 1011 params.withheld_permissions.ToPermissionSet(); |
1009 | 1012 |
1010 if (is_webkit_initialized_) { | 1013 if (is_webkit_initialized_) { |
1011 UpdateOriginPermissions( | 1014 UpdateOriginPermissions( |
1012 extension->url(), | 1015 extension->url(), |
1013 extension->permissions_data()->GetEffectiveHostPermissions(), | 1016 extension->permissions_data()->GetEffectiveHostPermissions(), |
1014 active->effective_hosts()); | 1017 active->effective_hosts()); |
1015 } | 1018 } |
1016 | 1019 |
1017 extension->permissions_data()->SetPermissions(active, withheld); | 1020 extension->permissions_data()->SetPermissions(active, withheld); |
1018 UpdateBindings(extension->id()); | 1021 UpdateBindings(extension->id()); |
1019 } | 1022 } |
1020 | 1023 |
1021 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url, | 1024 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url, |
1022 const std::string& extension_id, | 1025 const std::string& extension_id, |
1023 const URLPatternSet& new_hosts, | 1026 const URLPatternSet& new_hosts, |
1024 bool update_origin_whitelist, | 1027 bool update_origin_whitelist, |
1025 int tab_id) { | 1028 int tab_id) { |
1026 const Extension* extension = extensions_.GetByID(extension_id); | 1029 const Extension* extension = |
| 1030 RendererExtensionRegistry::Get()->GetByID(extension_id); |
1027 if (!extension) | 1031 if (!extension) |
1028 return; | 1032 return; |
1029 | 1033 |
1030 URLPatternSet old_effective = | 1034 URLPatternSet old_effective = |
1031 extension->permissions_data()->GetEffectiveHostPermissions(); | 1035 extension->permissions_data()->GetEffectiveHostPermissions(); |
1032 extension->permissions_data()->UpdateTabSpecificPermissions( | 1036 extension->permissions_data()->UpdateTabSpecificPermissions( |
1033 tab_id, | 1037 tab_id, |
1034 new extensions::PermissionSet(extensions::APIPermissionSet(), | 1038 new extensions::PermissionSet(extensions::APIPermissionSet(), |
1035 extensions::ManifestPermissionSet(), | 1039 extensions::ManifestPermissionSet(), |
1036 new_hosts, | 1040 new_hosts, |
1037 extensions::URLPatternSet())); | 1041 extensions::URLPatternSet())); |
1038 | 1042 |
1039 if (is_webkit_initialized_ && update_origin_whitelist) { | 1043 if (is_webkit_initialized_ && update_origin_whitelist) { |
1040 UpdateOriginPermissions( | 1044 UpdateOriginPermissions( |
1041 extension->url(), | 1045 extension->url(), |
1042 old_effective, | 1046 old_effective, |
1043 extension->permissions_data()->GetEffectiveHostPermissions()); | 1047 extension->permissions_data()->GetEffectiveHostPermissions()); |
1044 } | 1048 } |
1045 } | 1049 } |
1046 | 1050 |
1047 void Dispatcher::OnClearTabSpecificPermissions( | 1051 void Dispatcher::OnClearTabSpecificPermissions( |
1048 const std::vector<std::string>& extension_ids, | 1052 const std::vector<std::string>& extension_ids, |
1049 bool update_origin_whitelist, | 1053 bool update_origin_whitelist, |
1050 int tab_id) { | 1054 int tab_id) { |
1051 for (const std::string& id : extension_ids) { | 1055 for (const std::string& id : extension_ids) { |
1052 const Extension* extension = extensions_.GetByID(id); | 1056 const Extension* extension = RendererExtensionRegistry::Get()->GetByID(id); |
1053 if (extension) { | 1057 if (extension) { |
1054 URLPatternSet old_effective = | 1058 URLPatternSet old_effective = |
1055 extension->permissions_data()->GetEffectiveHostPermissions(); | 1059 extension->permissions_data()->GetEffectiveHostPermissions(); |
1056 extension->permissions_data()->ClearTabSpecificPermissions(tab_id); | 1060 extension->permissions_data()->ClearTabSpecificPermissions(tab_id); |
1057 if (is_webkit_initialized_ && update_origin_whitelist) { | 1061 if (is_webkit_initialized_ && update_origin_whitelist) { |
1058 UpdateOriginPermissions( | 1062 UpdateOriginPermissions( |
1059 extension->url(), | 1063 extension->url(), |
1060 old_effective, | 1064 old_effective, |
1061 extension->permissions_data()->GetEffectiveHostPermissions()); | 1065 extension->permissions_data()->GetEffectiveHostPermissions()); |
1062 } | 1066 } |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 context->GetContextTypeDescription(), | 1280 context->GetContextTypeDescription(), |
1277 ExtensionsRendererClient::Get()->IsIncognitoProcess(), | 1281 ExtensionsRendererClient::Get()->IsIncognitoProcess(), |
1278 is_component_extension, | 1282 is_component_extension, |
1279 manifest_version, | 1283 manifest_version, |
1280 send_request_disabled))); | 1284 send_request_disabled))); |
1281 | 1285 |
1282 delegate_->RegisterNativeHandlers(this, module_system, context); | 1286 delegate_->RegisterNativeHandlers(this, module_system, context); |
1283 } | 1287 } |
1284 | 1288 |
1285 bool Dispatcher::IsRuntimeAvailableToContext(ScriptContext* context) { | 1289 bool Dispatcher::IsRuntimeAvailableToContext(ScriptContext* context) { |
1286 for (const auto& extension : extensions_) { | 1290 for (const auto& extension : |
| 1291 *RendererExtensionRegistry::Get()->GetMainThreadExtensionSet()) { |
1287 ExternallyConnectableInfo* info = static_cast<ExternallyConnectableInfo*>( | 1292 ExternallyConnectableInfo* info = static_cast<ExternallyConnectableInfo*>( |
1288 extension->GetManifestData(manifest_keys::kExternallyConnectable)); | 1293 extension->GetManifestData(manifest_keys::kExternallyConnectable)); |
1289 if (info && info->matches.MatchesURL(context->GetURL())) | 1294 if (info && info->matches.MatchesURL(context->GetURL())) |
1290 return true; | 1295 return true; |
1291 } | 1296 } |
1292 return false; | 1297 return false; |
1293 } | 1298 } |
1294 | 1299 |
1295 void Dispatcher::UpdateContentCapabilities(ScriptContext* context) { | 1300 void Dispatcher::UpdateContentCapabilities(ScriptContext* context) { |
1296 APIPermissionSet permissions; | 1301 APIPermissionSet permissions; |
1297 for (const auto& extension : extensions_) { | 1302 for (const auto& extension : |
| 1303 *RendererExtensionRegistry::Get()->GetMainThreadExtensionSet()) { |
1298 const ContentCapabilitiesInfo& info = | 1304 const ContentCapabilitiesInfo& info = |
1299 ContentCapabilitiesInfo::Get(extension.get()); | 1305 ContentCapabilitiesInfo::Get(extension.get()); |
1300 if (info.url_patterns.MatchesURL(context->GetURL())) { | 1306 if (info.url_patterns.MatchesURL(context->GetURL())) { |
1301 APIPermissionSet new_permissions; | 1307 APIPermissionSet new_permissions; |
1302 APIPermissionSet::Union(permissions, info.permissions, &new_permissions); | 1308 APIPermissionSet::Union(permissions, info.permissions, &new_permissions); |
1303 permissions = new_permissions; | 1309 permissions = new_permissions; |
1304 } | 1310 } |
1305 } | 1311 } |
1306 context->SetContentCapabilities(permissions); | 1312 context->SetContentCapabilities(permissions); |
1307 } | 1313 } |
1308 | 1314 |
1309 void Dispatcher::PopulateSourceMap() { | 1315 void Dispatcher::PopulateSourceMap() { |
1310 const std::vector<std::pair<std::string, int> > resources = GetJsResources(); | 1316 const std::vector<std::pair<std::string, int> > resources = GetJsResources(); |
1311 for (std::vector<std::pair<std::string, int> >::const_iterator resource = | 1317 for (std::vector<std::pair<std::string, int> >::const_iterator resource = |
1312 resources.begin(); | 1318 resources.begin(); |
1313 resource != resources.end(); | 1319 resource != resources.end(); |
1314 ++resource) { | 1320 ++resource) { |
1315 source_map_.RegisterSource(resource->first, resource->second); | 1321 source_map_.RegisterSource(resource->first, resource->second); |
1316 } | 1322 } |
1317 delegate_->PopulateSourceMap(&source_map_); | 1323 delegate_->PopulateSourceMap(&source_map_); |
1318 } | 1324 } |
1319 | 1325 |
1320 bool Dispatcher::IsWithinPlatformApp() { | 1326 bool Dispatcher::IsWithinPlatformApp() { |
1321 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); | 1327 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); |
1322 iter != active_extension_ids_.end(); | 1328 iter != active_extension_ids_.end(); |
1323 ++iter) { | 1329 ++iter) { |
1324 const Extension* extension = extensions_.GetByID(*iter); | 1330 const Extension* extension = |
| 1331 RendererExtensionRegistry::Get()->GetByID(*iter); |
1325 if (extension && extension->is_platform_app()) | 1332 if (extension && extension->is_platform_app()) |
1326 return true; | 1333 return true; |
1327 } | 1334 } |
1328 return false; | 1335 return false; |
1329 } | 1336 } |
1330 | 1337 |
1331 v8::Local<v8::Object> Dispatcher::GetOrCreateObject( | 1338 v8::Local<v8::Object> Dispatcher::GetOrCreateObject( |
1332 const v8::Local<v8::Object>& object, | 1339 const v8::Local<v8::Object>& object, |
1333 const std::string& field, | 1340 const std::string& field, |
1334 v8::Isolate* isolate) { | 1341 v8::Isolate* isolate) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1445 void Dispatcher::AddChannelSpecificFeatures() { | 1452 void Dispatcher::AddChannelSpecificFeatures() { |
1446 // chrome-extension: resources should be allowed to register a Service Worker. | 1453 // chrome-extension: resources should be allowed to register a Service Worker. |
1447 if (FeatureProvider::GetBehaviorFeature(BehaviorFeature::kServiceWorker) | 1454 if (FeatureProvider::GetBehaviorFeature(BehaviorFeature::kServiceWorker) |
1448 ->IsAvailableToEnvironment() | 1455 ->IsAvailableToEnvironment() |
1449 .is_available()) | 1456 .is_available()) |
1450 WebSecurityPolicy::registerURLSchemeAsAllowingServiceWorkers( | 1457 WebSecurityPolicy::registerURLSchemeAsAllowingServiceWorkers( |
1451 WebString::fromUTF8(kExtensionScheme)); | 1458 WebString::fromUTF8(kExtensionScheme)); |
1452 } | 1459 } |
1453 | 1460 |
1454 } // namespace extensions | 1461 } // namespace extensions |
OLD | NEW |