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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(&active_extension_ids_)); |
205 new ScriptContextSet(&extensions_, &active_extension_ids_)); | 206 user_script_set_manager_.reset(new UserScriptSetManager()); |
206 user_script_set_manager_.reset(new UserScriptSetManager(&extensions_)); | |
207 script_injection_manager_.reset( | 207 script_injection_manager_.reset( |
208 new ScriptInjectionManager(&extensions_, user_script_set_manager_.get())); | 208 new ScriptInjectionManager(user_script_set_manager_.get())); |
209 user_script_set_manager_observer_.Add(user_script_set_manager_.get()); | 209 user_script_set_manager_observer_.Add(user_script_set_manager_.get()); |
210 request_sender_.reset(new RequestSender(this)); | 210 request_sender_.reset(new RequestSender(this)); |
211 PopulateSourceMap(); | 211 PopulateSourceMap(); |
212 } | 212 } |
213 | 213 |
214 Dispatcher::~Dispatcher() { | 214 Dispatcher::~Dispatcher() { |
215 } | 215 } |
216 | 216 |
217 void Dispatcher::OnRenderFrameCreated(content::RenderFrame* render_frame) { | 217 void Dispatcher::OnRenderFrameCreated(content::RenderFrame* render_frame) { |
218 script_injection_manager_->OnRenderFrameCreated(render_frame); | 218 script_injection_manager_->OnRenderFrameCreated(render_frame); |
219 } | 219 } |
220 | 220 |
221 bool Dispatcher::IsExtensionActive(const std::string& extension_id) const { | 221 bool Dispatcher::IsExtensionActive(const std::string& extension_id) const { |
222 bool is_active = | 222 bool is_active = |
223 active_extension_ids_.find(extension_id) != active_extension_ids_.end(); | 223 active_extension_ids_.find(extension_id) != active_extension_ids_.end(); |
224 if (is_active) | 224 if (is_active) |
225 CHECK(extensions_.Contains(extension_id)); | 225 CHECK(RendererExtensionRegistry::Get()->Contains(extension_id)); |
226 return is_active; | 226 return is_active; |
227 } | 227 } |
228 | 228 |
229 void Dispatcher::DidCreateScriptContext( | 229 void Dispatcher::DidCreateScriptContext( |
230 blink::WebLocalFrame* frame, | 230 blink::WebLocalFrame* frame, |
231 const v8::Local<v8::Context>& v8_context, | 231 const v8::Local<v8::Context>& v8_context, |
232 int extension_group, | 232 int extension_group, |
233 int world_id) { | 233 int world_id) { |
234 const base::TimeTicks start_time = base::TimeTicks::Now(); | 234 const base::TimeTicks start_time = base::TimeTicks::Now(); |
235 | 235 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 } | 323 } |
324 | 324 |
325 void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) { | 325 void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) { |
326 // Note: use GetEffectiveDocumentURL not just frame->document()->url() | 326 // Note: use GetEffectiveDocumentURL not just frame->document()->url() |
327 // so that this also injects the stylesheet on about:blank frames that | 327 // so that this also injects the stylesheet on about:blank frames that |
328 // are hosted in the extension process. | 328 // are hosted in the extension process. |
329 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( | 329 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
330 frame, frame->document().url(), true /* match_about_blank */); | 330 frame, frame->document().url(), true /* match_about_blank */); |
331 | 331 |
332 const Extension* extension = | 332 const Extension* extension = |
333 extensions_.GetExtensionOrAppByURL(effective_document_url); | 333 RendererExtensionRegistry::Get()->GetExtensionOrAppByURL( |
| 334 effective_document_url); |
334 | 335 |
335 if (extension && | 336 if (extension && |
336 (extension->is_extension() || extension->is_platform_app())) { | 337 (extension->is_extension() || extension->is_platform_app())) { |
337 int resource_id = extension->is_platform_app() ? IDR_PLATFORM_APP_CSS | 338 int resource_id = extension->is_platform_app() ? IDR_PLATFORM_APP_CSS |
338 : IDR_EXTENSION_FONTS_CSS; | 339 : IDR_EXTENSION_FONTS_CSS; |
339 std::string stylesheet = ResourceBundle::GetSharedInstance() | 340 std::string stylesheet = ResourceBundle::GetSharedInstance() |
340 .GetRawDataResource(resource_id) | 341 .GetRawDataResource(resource_id) |
341 .as_string(); | 342 .as_string(); |
342 base::ReplaceFirstSubstringAfterOffset( | 343 base::ReplaceFirstSubstringAfterOffset( |
343 &stylesheet, 0, "$FONTFAMILY", system_font_family_); | 344 &stylesheet, 0, "$FONTFAMILY", system_font_family_); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 | 406 |
406 // Reset the idle handler each time there's any activity like event or message | 407 // Reset the idle handler each time there's any activity like event or message |
407 // dispatch, for which Invoke is the chokepoint. | 408 // dispatch, for which Invoke is the chokepoint. |
408 if (set_idle_notifications_) { | 409 if (set_idle_notifications_) { |
409 RenderThread::Get()->ScheduleIdleHandler( | 410 RenderThread::Get()->ScheduleIdleHandler( |
410 kInitialExtensionIdleHandlerDelayMs); | 411 kInitialExtensionIdleHandlerDelayMs); |
411 } | 412 } |
412 | 413 |
413 // Tell the browser process when an event has been dispatched with a lazy | 414 // Tell the browser process when an event has been dispatched with a lazy |
414 // background page active. | 415 // background page active. |
415 const Extension* extension = extensions_.GetByID(extension_id); | 416 const Extension* extension = |
| 417 RendererExtensionRegistry::Get()->GetByID(extension_id); |
416 if (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && | 418 if (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && |
417 module_name == kEventBindings && | 419 module_name == kEventBindings && |
418 function_name == kEventDispatchFunction) { | 420 function_name == kEventDispatchFunction) { |
419 content::RenderFrame* background_frame = | 421 content::RenderFrame* background_frame = |
420 ExtensionFrameHelper::GetBackgroundPageFrame(extension_id); | 422 ExtensionFrameHelper::GetBackgroundPageFrame(extension_id); |
421 if (background_frame) { | 423 if (background_frame) { |
422 int message_id; | 424 int message_id; |
423 args.GetInteger(3, &message_id); | 425 args.GetInteger(3, &message_id); |
424 background_frame->Send(new ExtensionHostMsg_EventAck( | 426 background_frame->Send(new ExtensionHostMsg_EventAck( |
425 background_frame->GetRoutingID(), message_id)); | 427 background_frame->GetRoutingID(), message_id)); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 new GuestViewInternalCustomBindings(context))); | 695 new GuestViewInternalCustomBindings(context))); |
694 module_system->RegisterNativeHandler( | 696 module_system->RegisterNativeHandler( |
695 "i18n", scoped_ptr<NativeHandler>(new I18NCustomBindings(context))); | 697 "i18n", scoped_ptr<NativeHandler>(new I18NCustomBindings(context))); |
696 module_system->RegisterNativeHandler( | 698 module_system->RegisterNativeHandler( |
697 "id_generator", | 699 "id_generator", |
698 scoped_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); | 700 scoped_ptr<NativeHandler>(new IdGeneratorCustomBindings(context))); |
699 module_system->RegisterNativeHandler( | 701 module_system->RegisterNativeHandler( |
700 "runtime", scoped_ptr<NativeHandler>(new RuntimeCustomBindings(context))); | 702 "runtime", scoped_ptr<NativeHandler>(new RuntimeCustomBindings(context))); |
701 } | 703 } |
702 | 704 |
703 void Dispatcher::LoadExtensionForTest(const Extension* extension) { | |
704 CHECK(extensions_.Insert(extension)); | |
705 } | |
706 | |
707 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { | 705 bool Dispatcher::OnControlMessageReceived(const IPC::Message& message) { |
708 bool handled = true; | 706 bool handled = true; |
709 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) | 707 IPC_BEGIN_MESSAGE_MAP(Dispatcher, message) |
710 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) | 708 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) |
711 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) | 709 IPC_MESSAGE_HANDLER(ExtensionMsg_CancelSuspend, OnCancelSuspend) |
712 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) | 710 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) |
713 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) | 711 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnConnect, OnDispatchOnConnect) |
714 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) | 712 IPC_MESSAGE_HANDLER(ExtensionMsg_DispatchOnDisconnect, OnDispatchOnDisconnect) |
715 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) | 713 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) |
716 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) | 714 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 forced_idle_timer_->Start( | 746 forced_idle_timer_->Start( |
749 FROM_HERE, | 747 FROM_HERE, |
750 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), | 748 base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs), |
751 RenderThread::Get(), | 749 RenderThread::Get(), |
752 &RenderThread::IdleHandler); | 750 &RenderThread::IdleHandler); |
753 } | 751 } |
754 | 752 |
755 // Initialize host permissions for any extensions that were activated before | 753 // Initialize host permissions for any extensions that were activated before |
756 // WebKit was initialized. | 754 // WebKit was initialized. |
757 for (const std::string& extension_id : active_extension_ids_) { | 755 for (const std::string& extension_id : active_extension_ids_) { |
758 const Extension* extension = extensions_.GetByID(extension_id); | 756 const Extension* extension = |
| 757 RendererExtensionRegistry::Get()->GetByID(extension_id); |
759 CHECK(extension); | 758 CHECK(extension); |
760 InitOriginPermissions(extension); | 759 InitOriginPermissions(extension); |
761 } | 760 } |
762 | 761 |
763 EnableCustomElementWhiteList(); | 762 EnableCustomElementWhiteList(); |
764 | 763 |
765 is_webkit_initialized_ = true; | 764 is_webkit_initialized_ = true; |
766 } | 765 } |
767 | 766 |
768 void Dispatcher::IdleNotification() { | 767 void Dispatcher::IdleNotification() { |
(...skipping 13 matching lines...) Expand all Loading... |
782 } | 781 } |
783 } | 782 } |
784 | 783 |
785 void Dispatcher::OnRenderProcessShutdown() { | 784 void Dispatcher::OnRenderProcessShutdown() { |
786 v8_schema_registry_.reset(); | 785 v8_schema_registry_.reset(); |
787 forced_idle_timer_.reset(); | 786 forced_idle_timer_.reset(); |
788 content_watcher_.reset(); | 787 content_watcher_.reset(); |
789 } | 788 } |
790 | 789 |
791 void Dispatcher::OnActivateExtension(const std::string& extension_id) { | 790 void Dispatcher::OnActivateExtension(const std::string& extension_id) { |
792 const Extension* extension = extensions_.GetByID(extension_id); | 791 const Extension* extension = |
| 792 RendererExtensionRegistry::Get()->GetByID(extension_id); |
793 if (!extension) { | 793 if (!extension) { |
794 // Extension was activated but was never loaded. This probably means that | 794 // 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 | 795 // 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 | 796 // did). Failures shouldn't happen, but instead of crashing there (which |
797 // executes on all renderers) be conservative and only crash in the renderer | 797 // executes on all renderers) be conservative and only crash in the renderer |
798 // of the extension which failed to load; this one. | 798 // of the extension which failed to load; this one. |
799 std::string& error = extension_load_errors_[extension_id]; | 799 std::string& error = extension_load_errors_[extension_id]; |
800 char minidump[256]; | 800 char minidump[256]; |
801 base::debug::Alias(&minidump); | 801 base::debug::Alias(&minidump); |
802 base::snprintf(minidump, | 802 base::snprintf(minidump, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 std::string error; | 872 std::string error; |
873 scoped_refptr<const Extension> extension = param.ConvertToExtension(&error); | 873 scoped_refptr<const Extension> extension = param.ConvertToExtension(&error); |
874 if (!extension.get()) { | 874 if (!extension.get()) { |
875 NOTREACHED() << error; | 875 NOTREACHED() << error; |
876 // Note: in tests |param.id| has been observed to be empty (see comment | 876 // Note: in tests |param.id| has been observed to be empty (see comment |
877 // just below) so this isn't all that reliable. | 877 // just below) so this isn't all that reliable. |
878 extension_load_errors_[param.id] = error; | 878 extension_load_errors_[param.id] = error; |
879 continue; | 879 continue; |
880 } | 880 } |
881 | 881 |
| 882 RendererExtensionRegistry* extensions = RendererExtensionRegistry::Get(); |
882 // TODO(kalman): This test is deliberately not a CHECK (though I wish it | 883 // TODO(kalman): This test is deliberately not a CHECK (though I wish it |
883 // could be) and uses extension->id() not params.id: | 884 // 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 | 885 // 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 | 886 // the webstore extension, in tests, and I've spent some time trying to |
886 // figure out why - but cost/benefit won. | 887 // figure out why - but cost/benefit won. |
887 // 2. The browser only sends this IPC to RenderProcessHosts once, but the | 888 // 2. The browser only sends this IPC to RenderProcessHosts once, but the |
888 // Dispatcher is attached to a RenderThread. Presumably there is a | 889 // Dispatcher is attached to a RenderThread. Presumably there is a |
889 // mismatch there. In theory one would think it's possible for the | 890 // mismatch there. In theory one would think it's possible for the |
890 // browser to figure this out itself - but again, cost/benefit. | 891 // browser to figure this out itself - but again, cost/benefit. |
891 if (!extensions_.Contains(extension->id())) | 892 if (!extensions->Contains(extension->id())) |
892 extensions_.Insert(extension); | 893 extensions->Insert(extension); |
893 } | 894 } |
894 | 895 |
895 // Update the available bindings for all contexts. These may have changed if | 896 // Update the available bindings for all contexts. These may have changed if |
896 // an externally_connectable extension was loaded that can connect to an | 897 // an externally_connectable extension was loaded that can connect to an |
897 // open webpage. | 898 // open webpage. |
898 UpdateBindings(""); | 899 UpdateBindings(""); |
899 } | 900 } |
900 | 901 |
901 void Dispatcher::OnMessageInvoke(const std::string& extension_id, | 902 void Dispatcher::OnMessageInvoke(const std::string& extension_id, |
902 const std::string& module_name, | 903 const std::string& module_name, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 RenderThread::Get()->Send(new ExtensionHostMsg_SuspendAck(extension_id)); | 946 RenderThread::Get()->Send(new ExtensionHostMsg_SuspendAck(extension_id)); |
946 } | 947 } |
947 | 948 |
948 void Dispatcher::OnTransferBlobs(const std::vector<std::string>& blob_uuids) { | 949 void Dispatcher::OnTransferBlobs(const std::vector<std::string>& blob_uuids) { |
949 RenderThread::Get()->Send(new ExtensionHostMsg_TransferBlobsAck(blob_uuids)); | 950 RenderThread::Get()->Send(new ExtensionHostMsg_TransferBlobsAck(blob_uuids)); |
950 } | 951 } |
951 | 952 |
952 void Dispatcher::OnUnloaded(const std::string& id) { | 953 void Dispatcher::OnUnloaded(const std::string& id) { |
953 // See comment in OnLoaded for why it would be nice, but perhaps incorrect, | 954 // See comment in OnLoaded for why it would be nice, but perhaps incorrect, |
954 // to CHECK here rather than guarding. | 955 // to CHECK here rather than guarding. |
955 if (!extensions_.Remove(id)) | 956 if (!RendererExtensionRegistry::Get()->Remove(id)) |
956 return; | 957 return; |
957 | 958 |
958 active_extension_ids_.erase(id); | 959 active_extension_ids_.erase(id); |
959 | 960 |
960 script_injection_manager_->OnExtensionUnloaded(id); | 961 script_injection_manager_->OnExtensionUnloaded(id); |
961 | 962 |
962 // If the extension is later reloaded with a different set of permissions, | 963 // 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 | 964 // we'd like it to get a new isolated world ID, so that it can pick up the |
964 // changed origin whitelist. | 965 // changed origin whitelist. |
965 ScriptInjection::RemoveIsolatedWorld(id); | 966 ScriptInjection::RemoveIsolatedWorld(id); |
(...skipping 15 matching lines...) Expand all Loading... |
981 // reloaded with a new messages map. | 982 // reloaded with a new messages map. |
982 EraseL10nMessagesMap(id); | 983 EraseL10nMessagesMap(id); |
983 | 984 |
984 // We don't do anything with existing platform-app stylesheets. They will | 985 // We don't do anything with existing platform-app stylesheets. They will |
985 // stay resident, but the URL pattern corresponding to the unloaded | 986 // stay resident, but the URL pattern corresponding to the unloaded |
986 // extension's URL just won't match anything anymore. | 987 // extension's URL just won't match anything anymore. |
987 } | 988 } |
988 | 989 |
989 void Dispatcher::OnUpdatePermissions( | 990 void Dispatcher::OnUpdatePermissions( |
990 const ExtensionMsg_UpdatePermissions_Params& params) { | 991 const ExtensionMsg_UpdatePermissions_Params& params) { |
991 const Extension* extension = extensions_.GetByID(params.extension_id); | 992 const Extension* extension = |
| 993 RendererExtensionRegistry::Get()->GetByID(params.extension_id); |
992 if (!extension) | 994 if (!extension) |
993 return; | 995 return; |
994 | 996 |
995 scoped_refptr<const PermissionSet> active = | 997 scoped_refptr<const PermissionSet> active = |
996 params.active_permissions.ToPermissionSet(); | 998 params.active_permissions.ToPermissionSet(); |
997 scoped_refptr<const PermissionSet> withheld = | 999 scoped_refptr<const PermissionSet> withheld = |
998 params.withheld_permissions.ToPermissionSet(); | 1000 params.withheld_permissions.ToPermissionSet(); |
999 | 1001 |
1000 if (is_webkit_initialized_) { | 1002 if (is_webkit_initialized_) { |
1001 UpdateOriginPermissions( | 1003 UpdateOriginPermissions( |
1002 extension->url(), | 1004 extension->url(), |
1003 extension->permissions_data()->GetEffectiveHostPermissions(), | 1005 extension->permissions_data()->GetEffectiveHostPermissions(), |
1004 active->effective_hosts()); | 1006 active->effective_hosts()); |
1005 } | 1007 } |
1006 | 1008 |
1007 extension->permissions_data()->SetPermissions(active, withheld); | 1009 extension->permissions_data()->SetPermissions(active, withheld); |
1008 UpdateBindings(extension->id()); | 1010 UpdateBindings(extension->id()); |
1009 } | 1011 } |
1010 | 1012 |
1011 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url, | 1013 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url, |
1012 const std::string& extension_id, | 1014 const std::string& extension_id, |
1013 const URLPatternSet& new_hosts, | 1015 const URLPatternSet& new_hosts, |
1014 bool update_origin_whitelist, | 1016 bool update_origin_whitelist, |
1015 int tab_id) { | 1017 int tab_id) { |
1016 const Extension* extension = extensions_.GetByID(extension_id); | 1018 const Extension* extension = |
| 1019 RendererExtensionRegistry::Get()->GetByID(extension_id); |
1017 if (!extension) | 1020 if (!extension) |
1018 return; | 1021 return; |
1019 | 1022 |
1020 URLPatternSet old_effective = | 1023 URLPatternSet old_effective = |
1021 extension->permissions_data()->GetEffectiveHostPermissions(); | 1024 extension->permissions_data()->GetEffectiveHostPermissions(); |
1022 extension->permissions_data()->UpdateTabSpecificPermissions( | 1025 extension->permissions_data()->UpdateTabSpecificPermissions( |
1023 tab_id, | 1026 tab_id, |
1024 new extensions::PermissionSet(extensions::APIPermissionSet(), | 1027 new extensions::PermissionSet(extensions::APIPermissionSet(), |
1025 extensions::ManifestPermissionSet(), | 1028 extensions::ManifestPermissionSet(), |
1026 new_hosts, | 1029 new_hosts, |
1027 extensions::URLPatternSet())); | 1030 extensions::URLPatternSet())); |
1028 | 1031 |
1029 if (is_webkit_initialized_ && update_origin_whitelist) { | 1032 if (is_webkit_initialized_ && update_origin_whitelist) { |
1030 UpdateOriginPermissions( | 1033 UpdateOriginPermissions( |
1031 extension->url(), | 1034 extension->url(), |
1032 old_effective, | 1035 old_effective, |
1033 extension->permissions_data()->GetEffectiveHostPermissions()); | 1036 extension->permissions_data()->GetEffectiveHostPermissions()); |
1034 } | 1037 } |
1035 } | 1038 } |
1036 | 1039 |
1037 void Dispatcher::OnClearTabSpecificPermissions( | 1040 void Dispatcher::OnClearTabSpecificPermissions( |
1038 const std::vector<std::string>& extension_ids, | 1041 const std::vector<std::string>& extension_ids, |
1039 bool update_origin_whitelist, | 1042 bool update_origin_whitelist, |
1040 int tab_id) { | 1043 int tab_id) { |
1041 for (const std::string& id : extension_ids) { | 1044 for (const std::string& id : extension_ids) { |
1042 const Extension* extension = extensions_.GetByID(id); | 1045 const Extension* extension = RendererExtensionRegistry::Get()->GetByID(id); |
1043 if (extension) { | 1046 if (extension) { |
1044 URLPatternSet old_effective = | 1047 URLPatternSet old_effective = |
1045 extension->permissions_data()->GetEffectiveHostPermissions(); | 1048 extension->permissions_data()->GetEffectiveHostPermissions(); |
1046 extension->permissions_data()->ClearTabSpecificPermissions(tab_id); | 1049 extension->permissions_data()->ClearTabSpecificPermissions(tab_id); |
1047 if (is_webkit_initialized_ && update_origin_whitelist) { | 1050 if (is_webkit_initialized_ && update_origin_whitelist) { |
1048 UpdateOriginPermissions( | 1051 UpdateOriginPermissions( |
1049 extension->url(), | 1052 extension->url(), |
1050 old_effective, | 1053 old_effective, |
1051 extension->permissions_data()->GetEffectiveHostPermissions()); | 1054 extension->permissions_data()->GetEffectiveHostPermissions()); |
1052 } | 1055 } |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1273 send_request_disabled))); | 1276 send_request_disabled))); |
1274 | 1277 |
1275 delegate_->RegisterNativeHandlers(this, module_system, context); | 1278 delegate_->RegisterNativeHandlers(this, module_system, context); |
1276 } | 1279 } |
1277 | 1280 |
1278 bool Dispatcher::IsRuntimeAvailableToContext(ScriptContext* context) { | 1281 bool Dispatcher::IsRuntimeAvailableToContext(ScriptContext* context) { |
1279 if (extensions::FeatureSwitch::surface_worker()->IsEnabled() && | 1282 if (extensions::FeatureSwitch::surface_worker()->IsEnabled() && |
1280 context->GetAvailability("surfaceWorkerInternal").is_available()) { | 1283 context->GetAvailability("surfaceWorkerInternal").is_available()) { |
1281 return true; | 1284 return true; |
1282 } | 1285 } |
1283 for (const auto& extension : extensions_) { | 1286 for (const auto& extension : |
| 1287 *RendererExtensionRegistry::Get()->GetMainThreadExtensionSet()) { |
1284 ExternallyConnectableInfo* info = static_cast<ExternallyConnectableInfo*>( | 1288 ExternallyConnectableInfo* info = static_cast<ExternallyConnectableInfo*>( |
1285 extension->GetManifestData(manifest_keys::kExternallyConnectable)); | 1289 extension->GetManifestData(manifest_keys::kExternallyConnectable)); |
1286 if (info && info->matches.MatchesURL(context->GetURL())) | 1290 if (info && info->matches.MatchesURL(context->GetURL())) |
1287 return true; | 1291 return true; |
1288 } | 1292 } |
1289 return false; | 1293 return false; |
1290 } | 1294 } |
1291 | 1295 |
1292 void Dispatcher::UpdateContentCapabilities(ScriptContext* context) { | 1296 void Dispatcher::UpdateContentCapabilities(ScriptContext* context) { |
1293 APIPermissionSet permissions; | 1297 APIPermissionSet permissions; |
1294 for (const auto& extension : extensions_) { | 1298 for (const auto& extension : |
| 1299 *RendererExtensionRegistry::Get()->GetMainThreadExtensionSet()) { |
1295 const ContentCapabilitiesInfo& info = | 1300 const ContentCapabilitiesInfo& info = |
1296 ContentCapabilitiesInfo::Get(extension.get()); | 1301 ContentCapabilitiesInfo::Get(extension.get()); |
1297 if (info.url_patterns.MatchesURL(context->GetURL())) { | 1302 if (info.url_patterns.MatchesURL(context->GetURL())) { |
1298 APIPermissionSet new_permissions; | 1303 APIPermissionSet new_permissions; |
1299 APIPermissionSet::Union(permissions, info.permissions, &new_permissions); | 1304 APIPermissionSet::Union(permissions, info.permissions, &new_permissions); |
1300 permissions = new_permissions; | 1305 permissions = new_permissions; |
1301 } | 1306 } |
1302 } | 1307 } |
1303 context->SetContentCapabilities(permissions); | 1308 context->SetContentCapabilities(permissions); |
1304 } | 1309 } |
1305 | 1310 |
1306 void Dispatcher::PopulateSourceMap() { | 1311 void Dispatcher::PopulateSourceMap() { |
1307 const std::vector<std::pair<std::string, int> > resources = GetJsResources(); | 1312 const std::vector<std::pair<std::string, int> > resources = GetJsResources(); |
1308 for (std::vector<std::pair<std::string, int> >::const_iterator resource = | 1313 for (std::vector<std::pair<std::string, int> >::const_iterator resource = |
1309 resources.begin(); | 1314 resources.begin(); |
1310 resource != resources.end(); | 1315 resource != resources.end(); |
1311 ++resource) { | 1316 ++resource) { |
1312 source_map_.RegisterSource(resource->first, resource->second); | 1317 source_map_.RegisterSource(resource->first, resource->second); |
1313 } | 1318 } |
1314 delegate_->PopulateSourceMap(&source_map_); | 1319 delegate_->PopulateSourceMap(&source_map_); |
1315 } | 1320 } |
1316 | 1321 |
1317 bool Dispatcher::IsWithinPlatformApp() { | 1322 bool Dispatcher::IsWithinPlatformApp() { |
1318 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); | 1323 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); |
1319 iter != active_extension_ids_.end(); | 1324 iter != active_extension_ids_.end(); |
1320 ++iter) { | 1325 ++iter) { |
1321 const Extension* extension = extensions_.GetByID(*iter); | 1326 const Extension* extension = |
| 1327 RendererExtensionRegistry::Get()->GetByID(*iter); |
1322 if (extension && extension->is_platform_app()) | 1328 if (extension && extension->is_platform_app()) |
1323 return true; | 1329 return true; |
1324 } | 1330 } |
1325 return false; | 1331 return false; |
1326 } | 1332 } |
1327 | 1333 |
1328 v8::Local<v8::Object> Dispatcher::GetOrCreateObject( | 1334 v8::Local<v8::Object> Dispatcher::GetOrCreateObject( |
1329 const v8::Local<v8::Object>& object, | 1335 const v8::Local<v8::Object>& object, |
1330 const std::string& field, | 1336 const std::string& field, |
1331 v8::Isolate* isolate) { | 1337 v8::Isolate* isolate) { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1448 void Dispatcher::AddChannelSpecificFeatures() { | 1454 void Dispatcher::AddChannelSpecificFeatures() { |
1449 // chrome-extension: resources should be allowed to register a Service Worker. | 1455 // chrome-extension: resources should be allowed to register a Service Worker. |
1450 if (FeatureProvider::GetBehaviorFeature(BehaviorFeature::kServiceWorker) | 1456 if (FeatureProvider::GetBehaviorFeature(BehaviorFeature::kServiceWorker) |
1451 ->IsAvailableToEnvironment() | 1457 ->IsAvailableToEnvironment() |
1452 .is_available()) | 1458 .is_available()) |
1453 WebSecurityPolicy::registerURLSchemeAsAllowingServiceWorkers( | 1459 WebSecurityPolicy::registerURLSchemeAsAllowingServiceWorkers( |
1454 WebString::fromUTF8(kExtensionScheme)); | 1460 WebString::fromUTF8(kExtensionScheme)); |
1455 } | 1461 } |
1456 | 1462 |
1457 } // namespace extensions | 1463 } // namespace extensions |
OLD | NEW |