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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 | 112 |
113 namespace extensions { | 113 namespace extensions { |
114 | 114 |
115 namespace { | 115 namespace { |
116 | 116 |
117 static const int64 kInitialExtensionIdleHandlerDelayMs = 5 * 1000; | 117 static const int64 kInitialExtensionIdleHandlerDelayMs = 5 * 1000; |
118 static const int64 kMaxExtensionIdleHandlerDelayMs = 5 * 60 * 1000; | 118 static const int64 kMaxExtensionIdleHandlerDelayMs = 5 * 60 * 1000; |
119 static const char kEventDispatchFunction[] = "dispatchEvent"; | 119 static const char kEventDispatchFunction[] = "dispatchEvent"; |
120 static const char kOnSuspendEvent[] = "runtime.onSuspend"; | 120 static const char kOnSuspendEvent[] = "runtime.onSuspend"; |
121 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; | 121 static const char kOnSuspendCanceledEvent[] = "runtime.onSuspendCanceled"; |
122 static base::LazyInstance<ExtensionSet> g_extensions = | |
123 LAZY_INSTANCE_INITIALIZER; | |
not at google - send to devlin
2015/08/13 23:33:55
If we're doing this, ExtensionSet should handle it
not at google - send to devlin
2015/08/13 23:34:31
I mean g_instance variable.
| |
122 | 124 |
123 // Returns the global value for "chrome" from |context|. If one doesn't exist | 125 // Returns the global value for "chrome" from |context|. If one doesn't exist |
124 // creates a new object for it. | 126 // creates a new object for it. |
125 // | 127 // |
126 // Note that this isn't necessarily an object, since webpages can write, for | 128 // Note that this isn't necessarily an object, since webpages can write, for |
127 // example, "window.chrome = true". | 129 // example, "window.chrome = true". |
128 v8::Local<v8::Value> GetOrCreateChrome(ScriptContext* context) { | 130 v8::Local<v8::Value> GetOrCreateChrome(ScriptContext* context) { |
129 v8::Local<v8::String> chrome_string( | 131 v8::Local<v8::String> chrome_string( |
130 v8::String::NewFromUtf8(context->isolate(), "chrome")); | 132 v8::String::NewFromUtf8(context->isolate(), "chrome")); |
131 v8::Local<v8::Object> global(context->v8_context()->Global()); | 133 v8::Local<v8::Object> global(context->v8_context()->Global()); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 set_idle_notifications_ = | 197 set_idle_notifications_ = |
196 command_line.HasSwitch(switches::kExtensionProcess) || | 198 command_line.HasSwitch(switches::kExtensionProcess) || |
197 command_line.HasSwitch(::switches::kSingleProcess); | 199 command_line.HasSwitch(::switches::kSingleProcess); |
198 | 200 |
199 if (set_idle_notifications_) { | 201 if (set_idle_notifications_) { |
200 RenderThread::Get()->SetIdleNotificationDelayInMs( | 202 RenderThread::Get()->SetIdleNotificationDelayInMs( |
201 kInitialExtensionIdleHandlerDelayMs); | 203 kInitialExtensionIdleHandlerDelayMs); |
202 } | 204 } |
203 | 205 |
204 script_context_set_.reset( | 206 script_context_set_.reset( |
205 new ScriptContextSet(&extensions_, &active_extension_ids_)); | 207 new ScriptContextSet(&g_extensions.Get(), &active_extension_ids_)); |
206 user_script_set_manager_.reset(new UserScriptSetManager(&extensions_)); | 208 user_script_set_manager_.reset(new UserScriptSetManager(&g_extensions.Get())); |
207 script_injection_manager_.reset( | 209 script_injection_manager_.reset(new ScriptInjectionManager( |
208 new ScriptInjectionManager(&extensions_, user_script_set_manager_.get())); | 210 &g_extensions.Get(), user_script_set_manager_.get())); |
209 user_script_set_manager_observer_.Add(user_script_set_manager_.get()); | 211 user_script_set_manager_observer_.Add(user_script_set_manager_.get()); |
210 request_sender_.reset(new RequestSender(this)); | 212 request_sender_.reset(new RequestSender(this)); |
211 PopulateSourceMap(); | 213 PopulateSourceMap(); |
212 } | 214 } |
213 | 215 |
214 Dispatcher::~Dispatcher() { | 216 Dispatcher::~Dispatcher() { |
215 } | 217 } |
216 | 218 |
219 const ExtensionSet* Dispatcher::extensions() const { | |
220 return &g_extensions.Get(); | |
221 } | |
222 | |
217 void Dispatcher::OnRenderFrameCreated(content::RenderFrame* render_frame) { | 223 void Dispatcher::OnRenderFrameCreated(content::RenderFrame* render_frame) { |
218 script_injection_manager_->OnRenderFrameCreated(render_frame); | 224 script_injection_manager_->OnRenderFrameCreated(render_frame); |
219 } | 225 } |
220 | 226 |
221 bool Dispatcher::IsExtensionActive(const std::string& extension_id) const { | 227 bool Dispatcher::IsExtensionActive(const std::string& extension_id) const { |
222 bool is_active = | 228 bool is_active = |
223 active_extension_ids_.find(extension_id) != active_extension_ids_.end(); | 229 active_extension_ids_.find(extension_id) != active_extension_ids_.end(); |
224 if (is_active) | 230 if (is_active) |
225 CHECK(extensions_.Contains(extension_id)); | 231 CHECK(g_extensions.Get().Contains(extension_id)); |
226 return is_active; | 232 return is_active; |
227 } | 233 } |
228 | 234 |
229 void Dispatcher::DidCreateScriptContext( | 235 void Dispatcher::DidCreateScriptContext( |
230 blink::WebLocalFrame* frame, | 236 blink::WebLocalFrame* frame, |
231 const v8::Local<v8::Context>& v8_context, | 237 const v8::Local<v8::Context>& v8_context, |
232 int extension_group, | 238 int extension_group, |
233 int world_id) { | 239 int world_id) { |
234 const base::TimeTicks start_time = base::TimeTicks::Now(); | 240 const base::TimeTicks start_time = base::TimeTicks::Now(); |
235 | 241 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 } | 329 } |
324 | 330 |
325 void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) { | 331 void Dispatcher::DidCreateDocumentElement(blink::WebLocalFrame* frame) { |
326 // Note: use GetEffectiveDocumentURL not just frame->document()->url() | 332 // Note: use GetEffectiveDocumentURL not just frame->document()->url() |
327 // so that this also injects the stylesheet on about:blank frames that | 333 // so that this also injects the stylesheet on about:blank frames that |
328 // are hosted in the extension process. | 334 // are hosted in the extension process. |
329 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( | 335 GURL effective_document_url = ScriptContext::GetEffectiveDocumentURL( |
330 frame, frame->document().url(), true /* match_about_blank */); | 336 frame, frame->document().url(), true /* match_about_blank */); |
331 | 337 |
332 const Extension* extension = | 338 const Extension* extension = |
333 extensions_.GetExtensionOrAppByURL(effective_document_url); | 339 g_extensions.Get().GetExtensionOrAppByURL(effective_document_url); |
334 | 340 |
335 if (extension && | 341 if (extension && |
336 (extension->is_extension() || extension->is_platform_app())) { | 342 (extension->is_extension() || extension->is_platform_app())) { |
337 int resource_id = extension->is_platform_app() ? IDR_PLATFORM_APP_CSS | 343 int resource_id = extension->is_platform_app() ? IDR_PLATFORM_APP_CSS |
338 : IDR_EXTENSION_FONTS_CSS; | 344 : IDR_EXTENSION_FONTS_CSS; |
339 std::string stylesheet = ResourceBundle::GetSharedInstance() | 345 std::string stylesheet = ResourceBundle::GetSharedInstance() |
340 .GetRawDataResource(resource_id) | 346 .GetRawDataResource(resource_id) |
341 .as_string(); | 347 .as_string(); |
342 base::ReplaceFirstSubstringAfterOffset( | 348 base::ReplaceFirstSubstringAfterOffset( |
343 &stylesheet, 0, "$FONTFAMILY", system_font_family_); | 349 &stylesheet, 0, "$FONTFAMILY", system_font_family_); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 | 411 |
406 // Reset the idle handler each time there's any activity like event or message | 412 // Reset the idle handler each time there's any activity like event or message |
407 // dispatch, for which Invoke is the chokepoint. | 413 // dispatch, for which Invoke is the chokepoint. |
408 if (set_idle_notifications_) { | 414 if (set_idle_notifications_) { |
409 RenderThread::Get()->ScheduleIdleHandler( | 415 RenderThread::Get()->ScheduleIdleHandler( |
410 kInitialExtensionIdleHandlerDelayMs); | 416 kInitialExtensionIdleHandlerDelayMs); |
411 } | 417 } |
412 | 418 |
413 // Tell the browser process when an event has been dispatched with a lazy | 419 // Tell the browser process when an event has been dispatched with a lazy |
414 // background page active. | 420 // background page active. |
415 const Extension* extension = extensions_.GetByID(extension_id); | 421 const Extension* extension = g_extensions.Get().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 Loading... | |
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(g_extensions.Get().Insert(extension)); |
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 Loading... | |
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 = g_extensions.Get().GetByID(extension_id); |
759 CHECK(extension); | 765 CHECK(extension); |
760 InitOriginPermissions(extension); | 766 InitOriginPermissions(extension); |
761 } | 767 } |
762 | 768 |
763 EnableCustomElementWhiteList(); | 769 EnableCustomElementWhiteList(); |
764 | 770 |
765 is_webkit_initialized_ = true; | 771 is_webkit_initialized_ = true; |
766 } | 772 } |
767 | 773 |
768 void Dispatcher::IdleNotification() { | 774 void Dispatcher::IdleNotification() { |
(...skipping 13 matching lines...) Expand all Loading... | |
782 } | 788 } |
783 } | 789 } |
784 | 790 |
785 void Dispatcher::OnRenderProcessShutdown() { | 791 void Dispatcher::OnRenderProcessShutdown() { |
786 v8_schema_registry_.reset(); | 792 v8_schema_registry_.reset(); |
787 forced_idle_timer_.reset(); | 793 forced_idle_timer_.reset(); |
788 content_watcher_.reset(); | 794 content_watcher_.reset(); |
789 } | 795 } |
790 | 796 |
791 void Dispatcher::OnActivateExtension(const std::string& extension_id) { | 797 void Dispatcher::OnActivateExtension(const std::string& extension_id) { |
792 const Extension* extension = extensions_.GetByID(extension_id); | 798 const Extension* extension = g_extensions.Get().GetByID(extension_id); |
793 if (!extension) { | 799 if (!extension) { |
794 // Extension was activated but was never loaded. This probably means that | 800 // 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 | 801 // 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 | 802 // did). Failures shouldn't happen, but instead of crashing there (which |
797 // executes on all renderers) be conservative and only crash in the renderer | 803 // executes on all renderers) be conservative and only crash in the renderer |
798 // of the extension which failed to load; this one. | 804 // of the extension which failed to load; this one. |
799 std::string& error = extension_load_errors_[extension_id]; | 805 std::string& error = extension_load_errors_[extension_id]; |
800 char minidump[256]; | 806 char minidump[256]; |
801 base::debug::Alias(&minidump); | 807 base::debug::Alias(&minidump); |
802 base::snprintf(minidump, | 808 base::snprintf(minidump, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
881 | 887 |
882 // TODO(kalman): This test is deliberately not a CHECK (though I wish it | 888 // TODO(kalman): This test is deliberately not a CHECK (though I wish it |
883 // could be) and uses extension->id() not params.id: | 889 // 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 | 890 // 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 | 891 // the webstore extension, in tests, and I've spent some time trying to |
886 // figure out why - but cost/benefit won. | 892 // figure out why - but cost/benefit won. |
887 // 2. The browser only sends this IPC to RenderProcessHosts once, but the | 893 // 2. The browser only sends this IPC to RenderProcessHosts once, but the |
888 // Dispatcher is attached to a RenderThread. Presumably there is a | 894 // Dispatcher is attached to a RenderThread. Presumably there is a |
889 // mismatch there. In theory one would think it's possible for the | 895 // mismatch there. In theory one would think it's possible for the |
890 // browser to figure this out itself - but again, cost/benefit. | 896 // browser to figure this out itself - but again, cost/benefit. |
891 if (!extensions_.Contains(extension->id())) | 897 if (!g_extensions.Get().Contains(extension->id())) |
892 extensions_.Insert(extension); | 898 g_extensions.Get().Insert(extension); |
893 } | 899 } |
894 | 900 |
895 // Update the available bindings for all contexts. These may have changed if | 901 // Update the available bindings for all contexts. These may have changed if |
896 // an externally_connectable extension was loaded that can connect to an | 902 // an externally_connectable extension was loaded that can connect to an |
897 // open webpage. | 903 // open webpage. |
898 UpdateBindings(""); | 904 UpdateBindings(""); |
899 } | 905 } |
900 | 906 |
901 void Dispatcher::OnMessageInvoke(const std::string& extension_id, | 907 void Dispatcher::OnMessageInvoke(const std::string& extension_id, |
902 const std::string& module_name, | 908 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)); | 951 RenderThread::Get()->Send(new ExtensionHostMsg_SuspendAck(extension_id)); |
946 } | 952 } |
947 | 953 |
948 void Dispatcher::OnTransferBlobs(const std::vector<std::string>& blob_uuids) { | 954 void Dispatcher::OnTransferBlobs(const std::vector<std::string>& blob_uuids) { |
949 RenderThread::Get()->Send(new ExtensionHostMsg_TransferBlobsAck(blob_uuids)); | 955 RenderThread::Get()->Send(new ExtensionHostMsg_TransferBlobsAck(blob_uuids)); |
950 } | 956 } |
951 | 957 |
952 void Dispatcher::OnUnloaded(const std::string& id) { | 958 void Dispatcher::OnUnloaded(const std::string& id) { |
953 // See comment in OnLoaded for why it would be nice, but perhaps incorrect, | 959 // See comment in OnLoaded for why it would be nice, but perhaps incorrect, |
954 // to CHECK here rather than guarding. | 960 // to CHECK here rather than guarding. |
955 if (!extensions_.Remove(id)) | 961 if (!g_extensions.Get().Remove(id)) |
956 return; | 962 return; |
957 | 963 |
958 active_extension_ids_.erase(id); | 964 active_extension_ids_.erase(id); |
959 | 965 |
960 script_injection_manager_->OnExtensionUnloaded(id); | 966 script_injection_manager_->OnExtensionUnloaded(id); |
961 | 967 |
962 // If the extension is later reloaded with a different set of permissions, | 968 // 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 | 969 // we'd like it to get a new isolated world ID, so that it can pick up the |
964 // changed origin whitelist. | 970 // changed origin whitelist. |
965 ScriptInjection::RemoveIsolatedWorld(id); | 971 ScriptInjection::RemoveIsolatedWorld(id); |
(...skipping 15 matching lines...) Expand all Loading... | |
981 // reloaded with a new messages map. | 987 // reloaded with a new messages map. |
982 EraseL10nMessagesMap(id); | 988 EraseL10nMessagesMap(id); |
983 | 989 |
984 // We don't do anything with existing platform-app stylesheets. They will | 990 // We don't do anything with existing platform-app stylesheets. They will |
985 // stay resident, but the URL pattern corresponding to the unloaded | 991 // stay resident, but the URL pattern corresponding to the unloaded |
986 // extension's URL just won't match anything anymore. | 992 // extension's URL just won't match anything anymore. |
987 } | 993 } |
988 | 994 |
989 void Dispatcher::OnUpdatePermissions( | 995 void Dispatcher::OnUpdatePermissions( |
990 const ExtensionMsg_UpdatePermissions_Params& params) { | 996 const ExtensionMsg_UpdatePermissions_Params& params) { |
991 const Extension* extension = extensions_.GetByID(params.extension_id); | 997 const Extension* extension = g_extensions.Get().GetByID(params.extension_id); |
992 if (!extension) | 998 if (!extension) |
993 return; | 999 return; |
994 | 1000 |
995 scoped_refptr<const PermissionSet> active = | 1001 scoped_refptr<const PermissionSet> active = |
996 params.active_permissions.ToPermissionSet(); | 1002 params.active_permissions.ToPermissionSet(); |
997 scoped_refptr<const PermissionSet> withheld = | 1003 scoped_refptr<const PermissionSet> withheld = |
998 params.withheld_permissions.ToPermissionSet(); | 1004 params.withheld_permissions.ToPermissionSet(); |
999 | 1005 |
1000 if (is_webkit_initialized_) { | 1006 if (is_webkit_initialized_) { |
1001 UpdateOriginPermissions( | 1007 UpdateOriginPermissions( |
1002 extension->url(), | 1008 extension->url(), |
1003 extension->permissions_data()->GetEffectiveHostPermissions(), | 1009 extension->permissions_data()->GetEffectiveHostPermissions(), |
1004 active->effective_hosts()); | 1010 active->effective_hosts()); |
1005 } | 1011 } |
1006 | 1012 |
1007 extension->permissions_data()->SetPermissions(active, withheld); | 1013 extension->permissions_data()->SetPermissions(active, withheld); |
1008 UpdateBindings(extension->id()); | 1014 UpdateBindings(extension->id()); |
1009 } | 1015 } |
1010 | 1016 |
1011 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url, | 1017 void Dispatcher::OnUpdateTabSpecificPermissions(const GURL& visible_url, |
1012 const std::string& extension_id, | 1018 const std::string& extension_id, |
1013 const URLPatternSet& new_hosts, | 1019 const URLPatternSet& new_hosts, |
1014 bool update_origin_whitelist, | 1020 bool update_origin_whitelist, |
1015 int tab_id) { | 1021 int tab_id) { |
1016 const Extension* extension = extensions_.GetByID(extension_id); | 1022 const Extension* extension = g_extensions.Get().GetByID(extension_id); |
1017 if (!extension) | 1023 if (!extension) |
1018 return; | 1024 return; |
1019 | 1025 |
1020 URLPatternSet old_effective = | 1026 URLPatternSet old_effective = |
1021 extension->permissions_data()->GetEffectiveHostPermissions(); | 1027 extension->permissions_data()->GetEffectiveHostPermissions(); |
1022 extension->permissions_data()->UpdateTabSpecificPermissions( | 1028 extension->permissions_data()->UpdateTabSpecificPermissions( |
1023 tab_id, | 1029 tab_id, |
1024 new extensions::PermissionSet(extensions::APIPermissionSet(), | 1030 new extensions::PermissionSet(extensions::APIPermissionSet(), |
1025 extensions::ManifestPermissionSet(), | 1031 extensions::ManifestPermissionSet(), |
1026 new_hosts, | 1032 new_hosts, |
1027 extensions::URLPatternSet())); | 1033 extensions::URLPatternSet())); |
1028 | 1034 |
1029 if (is_webkit_initialized_ && update_origin_whitelist) { | 1035 if (is_webkit_initialized_ && update_origin_whitelist) { |
1030 UpdateOriginPermissions( | 1036 UpdateOriginPermissions( |
1031 extension->url(), | 1037 extension->url(), |
1032 old_effective, | 1038 old_effective, |
1033 extension->permissions_data()->GetEffectiveHostPermissions()); | 1039 extension->permissions_data()->GetEffectiveHostPermissions()); |
1034 } | 1040 } |
1035 } | 1041 } |
1036 | 1042 |
1037 void Dispatcher::OnClearTabSpecificPermissions( | 1043 void Dispatcher::OnClearTabSpecificPermissions( |
1038 const std::vector<std::string>& extension_ids, | 1044 const std::vector<std::string>& extension_ids, |
1039 bool update_origin_whitelist, | 1045 bool update_origin_whitelist, |
1040 int tab_id) { | 1046 int tab_id) { |
1041 for (const std::string& id : extension_ids) { | 1047 for (const std::string& id : extension_ids) { |
1042 const Extension* extension = extensions_.GetByID(id); | 1048 const Extension* extension = g_extensions.Get().GetByID(id); |
1043 if (extension) { | 1049 if (extension) { |
1044 URLPatternSet old_effective = | 1050 URLPatternSet old_effective = |
1045 extension->permissions_data()->GetEffectiveHostPermissions(); | 1051 extension->permissions_data()->GetEffectiveHostPermissions(); |
1046 extension->permissions_data()->ClearTabSpecificPermissions(tab_id); | 1052 extension->permissions_data()->ClearTabSpecificPermissions(tab_id); |
1047 if (is_webkit_initialized_ && update_origin_whitelist) { | 1053 if (is_webkit_initialized_ && update_origin_whitelist) { |
1048 UpdateOriginPermissions( | 1054 UpdateOriginPermissions( |
1049 extension->url(), | 1055 extension->url(), |
1050 old_effective, | 1056 old_effective, |
1051 extension->permissions_data()->GetEffectiveHostPermissions()); | 1057 extension->permissions_data()->GetEffectiveHostPermissions()); |
1052 } | 1058 } |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1273 send_request_disabled))); | 1279 send_request_disabled))); |
1274 | 1280 |
1275 delegate_->RegisterNativeHandlers(this, module_system, context); | 1281 delegate_->RegisterNativeHandlers(this, module_system, context); |
1276 } | 1282 } |
1277 | 1283 |
1278 bool Dispatcher::IsRuntimeAvailableToContext(ScriptContext* context) { | 1284 bool Dispatcher::IsRuntimeAvailableToContext(ScriptContext* context) { |
1279 if (extensions::FeatureSwitch::surface_worker()->IsEnabled() && | 1285 if (extensions::FeatureSwitch::surface_worker()->IsEnabled() && |
1280 context->GetAvailability("surfaceWorkerInternal").is_available()) { | 1286 context->GetAvailability("surfaceWorkerInternal").is_available()) { |
1281 return true; | 1287 return true; |
1282 } | 1288 } |
1283 for (const auto& extension : extensions_) { | 1289 for (const auto& extension : g_extensions.Get()) { |
1284 ExternallyConnectableInfo* info = static_cast<ExternallyConnectableInfo*>( | 1290 ExternallyConnectableInfo* info = static_cast<ExternallyConnectableInfo*>( |
1285 extension->GetManifestData(manifest_keys::kExternallyConnectable)); | 1291 extension->GetManifestData(manifest_keys::kExternallyConnectable)); |
1286 if (info && info->matches.MatchesURL(context->GetURL())) | 1292 if (info && info->matches.MatchesURL(context->GetURL())) |
1287 return true; | 1293 return true; |
1288 } | 1294 } |
1289 return false; | 1295 return false; |
1290 } | 1296 } |
1291 | 1297 |
1292 void Dispatcher::UpdateContentCapabilities(ScriptContext* context) { | 1298 void Dispatcher::UpdateContentCapabilities(ScriptContext* context) { |
1293 APIPermissionSet permissions; | 1299 APIPermissionSet permissions; |
1294 for (const auto& extension : extensions_) { | 1300 for (const auto& extension : g_extensions.Get()) { |
1295 const ContentCapabilitiesInfo& info = | 1301 const ContentCapabilitiesInfo& info = |
1296 ContentCapabilitiesInfo::Get(extension.get()); | 1302 ContentCapabilitiesInfo::Get(extension.get()); |
1297 if (info.url_patterns.MatchesURL(context->GetURL())) { | 1303 if (info.url_patterns.MatchesURL(context->GetURL())) { |
1298 APIPermissionSet new_permissions; | 1304 APIPermissionSet new_permissions; |
1299 APIPermissionSet::Union(permissions, info.permissions, &new_permissions); | 1305 APIPermissionSet::Union(permissions, info.permissions, &new_permissions); |
1300 permissions = new_permissions; | 1306 permissions = new_permissions; |
1301 } | 1307 } |
1302 } | 1308 } |
1303 context->SetContentCapabilities(permissions); | 1309 context->SetContentCapabilities(permissions); |
1304 } | 1310 } |
1305 | 1311 |
1306 void Dispatcher::PopulateSourceMap() { | 1312 void Dispatcher::PopulateSourceMap() { |
1307 const std::vector<std::pair<std::string, int> > resources = GetJsResources(); | 1313 const std::vector<std::pair<std::string, int> > resources = GetJsResources(); |
1308 for (std::vector<std::pair<std::string, int> >::const_iterator resource = | 1314 for (std::vector<std::pair<std::string, int> >::const_iterator resource = |
1309 resources.begin(); | 1315 resources.begin(); |
1310 resource != resources.end(); | 1316 resource != resources.end(); |
1311 ++resource) { | 1317 ++resource) { |
1312 source_map_.RegisterSource(resource->first, resource->second); | 1318 source_map_.RegisterSource(resource->first, resource->second); |
1313 } | 1319 } |
1314 delegate_->PopulateSourceMap(&source_map_); | 1320 delegate_->PopulateSourceMap(&source_map_); |
1315 } | 1321 } |
1316 | 1322 |
1317 bool Dispatcher::IsWithinPlatformApp() { | 1323 bool Dispatcher::IsWithinPlatformApp() { |
1318 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); | 1324 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); |
1319 iter != active_extension_ids_.end(); | 1325 iter != active_extension_ids_.end(); |
1320 ++iter) { | 1326 ++iter) { |
1321 const Extension* extension = extensions_.GetByID(*iter); | 1327 const Extension* extension = g_extensions.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 |