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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 frame->document().securityOrigin()); | 264 frame->document().securityOrigin()); |
265 | 265 |
266 ScriptContext* context = | 266 ScriptContext* context = |
267 delegate_->CreateScriptContext(v8_context, frame, extension, context_type) | 267 delegate_->CreateScriptContext(v8_context, frame, extension, context_type) |
268 .release(); | 268 .release(); |
269 script_context_set_.Add(context); | 269 script_context_set_.Add(context); |
270 | 270 |
271 // Initialize origin permissions for content scripts, which can't be | 271 // Initialize origin permissions for content scripts, which can't be |
272 // initialized in |OnActivateExtension|. | 272 // initialized in |OnActivateExtension|. |
273 if (context_type == Feature::CONTENT_SCRIPT_CONTEXT) | 273 if (context_type == Feature::CONTENT_SCRIPT_CONTEXT) |
274 UpdateOriginPermissions(extension); | 274 InitOriginPermissions(extension); |
275 | 275 |
276 { | 276 { |
277 scoped_ptr<ModuleSystem> module_system( | 277 scoped_ptr<ModuleSystem> module_system( |
278 new ModuleSystem(context, &source_map_)); | 278 new ModuleSystem(context, &source_map_)); |
279 context->set_module_system(module_system.Pass()); | 279 context->set_module_system(module_system.Pass()); |
280 } | 280 } |
281 ModuleSystem* module_system = context->module_system(); | 281 ModuleSystem* module_system = context->module_system(); |
282 | 282 |
283 // Enable natives in startup. | 283 // Enable natives in startup. |
284 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); | 284 ModuleSystem::NativesEnabledScope natives_enabled_scope(module_system); |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 } | 499 } |
500 | 500 |
501 // Initialize host permissions for any extensions that were activated before | 501 // Initialize host permissions for any extensions that were activated before |
502 // WebKit was initialized. | 502 // WebKit was initialized. |
503 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); | 503 for (std::set<std::string>::iterator iter = active_extension_ids_.begin(); |
504 iter != active_extension_ids_.end(); | 504 iter != active_extension_ids_.end(); |
505 ++iter) { | 505 ++iter) { |
506 const Extension* extension = extensions_.GetByID(*iter); | 506 const Extension* extension = extensions_.GetByID(*iter); |
507 CHECK(extension); | 507 CHECK(extension); |
508 | 508 |
509 UpdateOriginPermissions(extension); | 509 InitOriginPermissions(extension); |
510 } | 510 } |
511 | 511 |
512 EnableCustomElementWhiteList(); | 512 EnableCustomElementWhiteList(); |
513 | 513 |
514 is_webkit_initialized_ = true; | 514 is_webkit_initialized_ = true; |
515 } | 515 } |
516 | 516 |
517 void Dispatcher::IdleNotification() { | 517 void Dispatcher::IdleNotification() { |
518 if (is_extension_process_ && forced_idle_timer_) { | 518 if (is_extension_process_ && forced_idle_timer_) { |
519 // Dampen the forced delay as well if the extension stays idle for long | 519 // Dampen the forced delay as well if the extension stays idle for long |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 active_extension_ids_.insert(extension_id); | 558 active_extension_ids_.insert(extension_id); |
559 | 559 |
560 // This is called when starting a new extension page, so start the idle | 560 // This is called when starting a new extension page, so start the idle |
561 // handler ticking. | 561 // handler ticking. |
562 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); | 562 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); |
563 | 563 |
564 if (is_webkit_initialized_) { | 564 if (is_webkit_initialized_) { |
565 extensions::DOMActivityLogger::AttachToWorld( | 565 extensions::DOMActivityLogger::AttachToWorld( |
566 extensions::DOMActivityLogger::kMainWorldId, extension_id); | 566 extensions::DOMActivityLogger::kMainWorldId, extension_id); |
567 | 567 |
568 UpdateOriginPermissions(extension); | 568 InitOriginPermissions(extension); |
569 } | 569 } |
570 | 570 |
571 UpdateActiveExtensions(); | 571 UpdateActiveExtensions(); |
572 } | 572 } |
573 | 573 |
574 void Dispatcher::OnCancelSuspend(const std::string& extension_id) { | 574 void Dispatcher::OnCancelSuspend(const std::string& extension_id) { |
575 DispatchEvent(extension_id, kOnSuspendCanceledEvent); | 575 DispatchEvent(extension_id, kOnSuspendCanceledEvent); |
576 } | 576 } |
577 | 577 |
578 void Dispatcher::OnClearTabSpecificPermissions( | 578 void Dispatcher::OnClearTabSpecificPermissions( |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
734 const ExtensionMsg_UpdatePermissions_Params& params) { | 734 const ExtensionMsg_UpdatePermissions_Params& params) { |
735 const Extension* extension = extensions_.GetByID(params.extension_id); | 735 const Extension* extension = extensions_.GetByID(params.extension_id); |
736 if (!extension) | 736 if (!extension) |
737 return; | 737 return; |
738 | 738 |
739 scoped_refptr<const PermissionSet> active = | 739 scoped_refptr<const PermissionSet> active = |
740 params.active_permissions.ToPermissionSet(); | 740 params.active_permissions.ToPermissionSet(); |
741 scoped_refptr<const PermissionSet> withheld = | 741 scoped_refptr<const PermissionSet> withheld = |
742 params.withheld_permissions.ToPermissionSet(); | 742 params.withheld_permissions.ToPermissionSet(); |
743 | 743 |
744 if (is_webkit_initialized_) { | |
745 UpdateOriginPermissions( | |
746 extension, | |
747 active->effective_hosts(), | |
748 extension->permissions_data()->GetEffectiveHostPermissions()); | |
749 } | |
750 | |
744 extension->permissions_data()->SetPermissions(active, withheld); | 751 extension->permissions_data()->SetPermissions(active, withheld); |
745 UpdateOriginPermissions(extension); | |
746 UpdateBindings(extension->id()); | 752 UpdateBindings(extension->id()); |
747 } | 753 } |
748 | 754 |
749 void Dispatcher::OnUpdateTabSpecificPermissions( | 755 void Dispatcher::OnUpdateTabSpecificPermissions( |
750 const GURL& url, | 756 const GURL& url, |
751 int tab_id, | 757 int tab_id, |
752 const std::string& extension_id, | 758 const std::string& extension_id, |
753 const URLPatternSet& origin_set) { | 759 const URLPatternSet& origin_set) { |
754 delegate_->UpdateTabSpecificPermissions( | 760 delegate_->UpdateTabSpecificPermissions( |
755 this, url, tab_id, extension_id, origin_set); | 761 this, url, tab_id, extension_id, origin_set); |
756 } | 762 } |
757 | 763 |
758 void Dispatcher::OnUsingWebRequestAPI(bool webrequest_used) { | 764 void Dispatcher::OnUsingWebRequestAPI(bool webrequest_used) { |
759 delegate_->HandleWebRequestAPIUsage(webrequest_used); | 765 delegate_->HandleWebRequestAPIUsage(webrequest_used); |
760 } | 766 } |
761 | 767 |
762 void Dispatcher::OnUserScriptsUpdated( | 768 void Dispatcher::OnUserScriptsUpdated( |
763 const std::set<std::string>& changed_extensions, | 769 const std::set<std::string>& changed_extensions, |
764 const std::vector<UserScript*>& scripts) { | 770 const std::vector<UserScript*>& scripts) { |
765 UpdateActiveExtensions(); | 771 UpdateActiveExtensions(); |
766 } | 772 } |
767 | 773 |
768 void Dispatcher::UpdateActiveExtensions() { | 774 void Dispatcher::UpdateActiveExtensions() { |
769 std::set<std::string> active_extensions = active_extension_ids_; | 775 std::set<std::string> active_extensions = active_extension_ids_; |
770 user_script_set_->GetActiveExtensionIds(&active_extensions); | 776 user_script_set_->GetActiveExtensionIds(&active_extensions); |
771 delegate_->OnActiveExtensionsUpdated(active_extensions); | 777 delegate_->OnActiveExtensionsUpdated(active_extensions); |
772 } | 778 } |
773 | 779 |
774 void Dispatcher::UpdateOriginPermissions(const Extension* extension) { | 780 void Dispatcher::InitOriginPermissions(const Extension* extension) { |
775 const URLPatternSet& hosts = | |
776 extension->permissions_data()->GetEffectiveHostPermissions(); | |
777 WebSecurityPolicy::resetOriginAccessWhitelists(); | |
778 delegate_->InitOriginPermissions(extension, | 781 delegate_->InitOriginPermissions(extension, |
779 IsExtensionActive(extension->id())); | 782 IsExtensionActive(extension->id())); |
780 for (URLPatternSet::const_iterator iter = hosts.begin(); iter != hosts.end(); | 783 UpdateOriginPermissions( |
781 ++iter) { | 784 extension, |
782 const char* schemes[] = { | 785 extension->permissions_data()->GetEffectiveHostPermissions(), |
783 url::kHttpScheme, | 786 URLPatternSet()); // No old permissions. |
784 url::kHttpsScheme, | 787 } |
785 url::kFileScheme, | 788 |
786 content::kChromeUIScheme, | 789 void Dispatcher::UpdateOriginPermissions( |
787 url::kFtpScheme, | 790 const Extension* extension, |
788 }; | 791 const URLPatternSet& new_patterns, |
not at google - send to devlin
2014/07/23 17:01:17
nit: could you swap new_patterns and old_patterns?
Devlin
2014/07/23 17:20:58
Done.
| |
789 for (size_t j = 0; j < arraysize(schemes); ++j) { | 792 const URLPatternSet& old_patterns) { |
790 if (iter->MatchesScheme(schemes[j])) { | 793 static const char* kSchemes[] = { |
794 url::kHttpScheme, | |
795 url::kHttpsScheme, | |
796 url::kFileScheme, | |
797 content::kChromeUIScheme, | |
798 url::kFtpScheme, | |
799 }; | |
800 for (size_t i = 0; i < arraysize(kSchemes); ++i) { | |
801 const char* scheme = kSchemes[i]; | |
802 // Remove all old patterns that aren't also in the new patterns. | |
803 for (URLPatternSet::const_iterator pattern = old_patterns.begin(); | |
804 pattern != old_patterns.end(); ++pattern) { | |
805 if (pattern->MatchesScheme(scheme) && | |
806 !new_patterns.ContainsPattern(*pattern)) { | |
807 WebSecurityPolicy::removeOriginAccessWhitelistEntry( | |
808 extension->url(), | |
809 WebString::fromUTF8(scheme), | |
810 WebString::fromUTF8(pattern->host()), | |
811 pattern->match_subdomains()); | |
812 } | |
813 } | |
814 for (URLPatternSet::const_iterator pattern = new_patterns.begin(); | |
815 pattern != new_patterns.end(); ++pattern) { | |
816 // Add any new patterns that weren't in the old patterns. | |
not at google - send to devlin
2014/07/23 17:01:17
nit: this comment should be up a couple of lines t
Devlin
2014/07/23 17:20:58
Done.
| |
817 if (pattern->MatchesScheme(scheme) && | |
818 !old_patterns.ContainsPattern(*pattern)) { | |
791 WebSecurityPolicy::addOriginAccessWhitelistEntry( | 819 WebSecurityPolicy::addOriginAccessWhitelistEntry( |
792 extension->url(), | 820 extension->url(), |
793 WebString::fromUTF8(schemes[j]), | 821 WebString::fromUTF8(scheme), |
794 WebString::fromUTF8(iter->host()), | 822 WebString::fromUTF8(pattern->host()), |
795 iter->match_subdomains()); | 823 pattern->match_subdomains()); |
796 } | 824 } |
797 } | 825 } |
798 } | 826 } |
799 } | 827 } |
800 | 828 |
801 void Dispatcher::EnableCustomElementWhiteList() { | 829 void Dispatcher::EnableCustomElementWhiteList() { |
802 blink::WebCustomElement::addEmbedderCustomElementName("webview"); | 830 blink::WebCustomElement::addEmbedderCustomElementName("webview"); |
803 blink::WebCustomElement::addEmbedderCustomElementName("appview"); | 831 blink::WebCustomElement::addEmbedderCustomElementName("appview"); |
804 blink::WebCustomElement::addEmbedderCustomElementName("appplugin"); | 832 blink::WebCustomElement::addEmbedderCustomElementName("appplugin"); |
805 blink::WebCustomElement::addEmbedderCustomElementName("browserplugin"); | 833 blink::WebCustomElement::addEmbedderCustomElementName("browserplugin"); |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1197 return v8::Handle<v8::Object>(); | 1225 return v8::Handle<v8::Object>(); |
1198 | 1226 |
1199 if (bind_name) | 1227 if (bind_name) |
1200 *bind_name = split.back(); | 1228 *bind_name = split.back(); |
1201 | 1229 |
1202 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) | 1230 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) |
1203 : bind_object; | 1231 : bind_object; |
1204 } | 1232 } |
1205 | 1233 |
1206 } // namespace extensions | 1234 } // namespace extensions |
OLD | NEW |