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 InitOriginPermissions(extension); | 274 UpdateOriginPermissions(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 InitOriginPermissions(extension); | 509 UpdateOriginPermissions(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 InitOriginPermissions(extension); | 568 UpdateOriginPermissions(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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 // reloaded with a new messages map. | 725 // reloaded with a new messages map. |
726 EraseL10nMessagesMap(id); | 726 EraseL10nMessagesMap(id); |
727 | 727 |
728 // We don't do anything with existing platform-app stylesheets. They will | 728 // We don't do anything with existing platform-app stylesheets. They will |
729 // stay resident, but the URL pattern corresponding to the unloaded | 729 // stay resident, but the URL pattern corresponding to the unloaded |
730 // extension's URL just won't match anything anymore. | 730 // extension's URL just won't match anything anymore. |
731 } | 731 } |
732 | 732 |
733 void Dispatcher::OnUpdatePermissions( | 733 void Dispatcher::OnUpdatePermissions( |
734 const ExtensionMsg_UpdatePermissions_Params& params) { | 734 const ExtensionMsg_UpdatePermissions_Params& params) { |
735 int reason_id = params.reason_id; | 735 const Extension* extension = extensions_.GetByID(params.extension_id); |
736 const std::string& extension_id = params.extension_id; | |
737 const APIPermissionSet& apis = params.apis; | |
738 const ManifestPermissionSet& manifest_permissions = | |
739 params.manifest_permissions; | |
740 const URLPatternSet& explicit_hosts = params.explicit_hosts; | |
741 const URLPatternSet& scriptable_hosts = params.scriptable_hosts; | |
742 | |
743 const Extension* extension = extensions_.GetByID(extension_id); | |
744 if (!extension) | 736 if (!extension) |
745 return; | 737 return; |
746 | 738 |
747 scoped_refptr<const PermissionSet> delta = new PermissionSet( | 739 scoped_refptr<const PermissionSet> active = |
748 apis, manifest_permissions, explicit_hosts, scriptable_hosts); | 740 params.active_permissions.ToPermissionSet(); |
749 scoped_refptr<const PermissionSet> old_active = | 741 scoped_refptr<const PermissionSet> withheld = |
750 extension->permissions_data()->active_permissions(); | 742 params.withheld_permissions.ToPermissionSet(); |
751 UpdatedExtensionPermissionsInfo::Reason reason = | |
752 static_cast<UpdatedExtensionPermissionsInfo::Reason>(reason_id); | |
753 | 743 |
754 const PermissionSet* new_active = NULL; | 744 extension->permissions_data()->SetPermissions(active, withheld); |
755 switch (reason) { | 745 UpdateOriginPermissions(extension); |
756 case UpdatedExtensionPermissionsInfo::ADDED: | |
757 new_active = PermissionSet::CreateUnion(old_active.get(), delta.get()); | |
758 break; | |
759 case UpdatedExtensionPermissionsInfo::REMOVED: | |
760 new_active = | |
761 PermissionSet::CreateDifference(old_active.get(), delta.get()); | |
762 break; | |
763 } | |
764 | |
765 extension->permissions_data()->SetActivePermissions(new_active); | |
766 UpdateOriginPermissions(reason, extension, explicit_hosts); | |
767 UpdateBindings(extension->id()); | 746 UpdateBindings(extension->id()); |
768 } | 747 } |
769 | 748 |
770 void Dispatcher::OnUpdateTabSpecificPermissions( | 749 void Dispatcher::OnUpdateTabSpecificPermissions( |
771 int page_id, | 750 int page_id, |
772 int tab_id, | 751 int tab_id, |
773 const std::string& extension_id, | 752 const std::string& extension_id, |
774 const URLPatternSet& origin_set) { | 753 const URLPatternSet& origin_set) { |
775 delegate_->UpdateTabSpecificPermissions( | 754 delegate_->UpdateTabSpecificPermissions( |
776 this, page_id, tab_id, extension_id, origin_set); | 755 this, page_id, tab_id, extension_id, origin_set); |
777 } | 756 } |
778 | 757 |
779 void Dispatcher::OnUsingWebRequestAPI(bool webrequest_used) { | 758 void Dispatcher::OnUsingWebRequestAPI(bool webrequest_used) { |
780 delegate_->HandleWebRequestAPIUsage(webrequest_used); | 759 delegate_->HandleWebRequestAPIUsage(webrequest_used); |
781 } | 760 } |
782 | 761 |
783 void Dispatcher::OnUserScriptsUpdated( | 762 void Dispatcher::OnUserScriptsUpdated( |
784 const std::set<std::string>& changed_extensions, | 763 const std::set<std::string>& changed_extensions, |
785 const std::vector<UserScript*>& scripts) { | 764 const std::vector<UserScript*>& scripts) { |
786 UpdateActiveExtensions(); | 765 UpdateActiveExtensions(); |
787 } | 766 } |
788 | 767 |
789 void Dispatcher::UpdateActiveExtensions() { | 768 void Dispatcher::UpdateActiveExtensions() { |
790 std::set<std::string> active_extensions = active_extension_ids_; | 769 std::set<std::string> active_extensions = active_extension_ids_; |
791 user_script_set_->GetActiveExtensionIds(&active_extensions); | 770 user_script_set_->GetActiveExtensionIds(&active_extensions); |
792 delegate_->OnActiveExtensionsUpdated(active_extensions); | 771 delegate_->OnActiveExtensionsUpdated(active_extensions); |
793 } | 772 } |
794 | 773 |
795 void Dispatcher::InitOriginPermissions(const Extension* extension) { | 774 void Dispatcher::UpdateOriginPermissions(const Extension* extension) { |
| 775 const URLPatternSet& hosts = |
| 776 extension->permissions_data()->GetEffectiveHostPermissions(); |
| 777 WebSecurityPolicy::resetOriginAccessWhitelists(); |
796 delegate_->InitOriginPermissions(extension, | 778 delegate_->InitOriginPermissions(extension, |
797 IsExtensionActive(extension->id())); | 779 IsExtensionActive(extension->id())); |
798 UpdateOriginPermissions( | 780 for (URLPatternSet::const_iterator iter = hosts.begin(); iter != hosts.end(); |
799 UpdatedExtensionPermissionsInfo::ADDED, | 781 ++iter) { |
800 extension, | |
801 extension->permissions_data()->GetEffectiveHostPermissions()); | |
802 } | |
803 | |
804 void Dispatcher::UpdateOriginPermissions( | |
805 UpdatedExtensionPermissionsInfo::Reason reason, | |
806 const Extension* extension, | |
807 const URLPatternSet& origins) { | |
808 for (URLPatternSet::const_iterator i = origins.begin(); i != origins.end(); | |
809 ++i) { | |
810 const char* schemes[] = { | 782 const char* schemes[] = { |
811 url::kHttpScheme, | 783 url::kHttpScheme, |
812 url::kHttpsScheme, | 784 url::kHttpsScheme, |
813 url::kFileScheme, | 785 url::kFileScheme, |
814 content::kChromeUIScheme, | 786 content::kChromeUIScheme, |
815 url::kFtpScheme, | 787 url::kFtpScheme, |
816 }; | 788 }; |
817 for (size_t j = 0; j < arraysize(schemes); ++j) { | 789 for (size_t j = 0; j < arraysize(schemes); ++j) { |
818 if (i->MatchesScheme(schemes[j])) { | 790 if (iter->MatchesScheme(schemes[j])) { |
819 ((reason == UpdatedExtensionPermissionsInfo::REMOVED) | 791 WebSecurityPolicy::addOriginAccessWhitelistEntry( |
820 ? WebSecurityPolicy::removeOriginAccessWhitelistEntry | |
821 : WebSecurityPolicy::addOriginAccessWhitelistEntry)( | |
822 extension->url(), | 792 extension->url(), |
823 WebString::fromUTF8(schemes[j]), | 793 WebString::fromUTF8(schemes[j]), |
824 WebString::fromUTF8(i->host()), | 794 WebString::fromUTF8(iter->host()), |
825 i->match_subdomains()); | 795 iter->match_subdomains()); |
826 } | 796 } |
827 } | 797 } |
828 } | 798 } |
829 } | 799 } |
830 | 800 |
831 void Dispatcher::EnableCustomElementWhiteList() { | 801 void Dispatcher::EnableCustomElementWhiteList() { |
832 blink::WebCustomElement::addEmbedderCustomElementName("webview"); | 802 blink::WebCustomElement::addEmbedderCustomElementName("webview"); |
833 blink::WebCustomElement::addEmbedderCustomElementName("browser-plugin"); | 803 blink::WebCustomElement::addEmbedderCustomElementName("browser-plugin"); |
834 } | 804 } |
835 | 805 |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 return v8::Handle<v8::Object>(); | 1195 return v8::Handle<v8::Object>(); |
1226 | 1196 |
1227 if (bind_name) | 1197 if (bind_name) |
1228 *bind_name = split.back(); | 1198 *bind_name = split.back(); |
1229 | 1199 |
1230 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) | 1200 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) |
1231 : bind_object; | 1201 : bind_object; |
1232 } | 1202 } |
1233 | 1203 |
1234 } // namespace extensions | 1204 } // namespace extensions |
OLD | NEW |