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 webkit isn't initialized, this will be done when it finishes starting | |
not at google - send to devlin
2014/07/23 01:18:54
s/webkit/blink/
though I think the comment isn't
Devlin
2014/07/23 15:41:51
Done.
| |
745 // up. | |
746 if (is_webkit_initialized_) { | |
747 bool was_added = params.was_added; | |
not at google - send to devlin
2014/07/23 01:18:54
this alias seems like overkill.
Devlin
2014/07/23 15:41:51
Done.
| |
748 URLPatternSet difference; | |
749 if (was_added) { | |
750 URLPatternSet::CreateDifference( | |
751 active->effective_hosts(), | |
752 extension->permissions_data()->GetEffectiveHostPermissions(), | |
753 &difference); | |
754 } else { | |
755 URLPatternSet::CreateDifference( | |
756 extension->permissions_data()->GetEffectiveHostPermissions(), | |
757 active->effective_hosts(), | |
758 &difference); | |
759 } | |
760 | |
761 UpdateOriginPermissions(extension, was_added, difference); | |
762 } | |
763 | |
744 extension->permissions_data()->SetPermissions(active, withheld); | 764 extension->permissions_data()->SetPermissions(active, withheld); |
745 UpdateOriginPermissions(extension); | |
746 UpdateBindings(extension->id()); | 765 UpdateBindings(extension->id()); |
747 } | 766 } |
748 | 767 |
749 void Dispatcher::OnUpdateTabSpecificPermissions( | 768 void Dispatcher::OnUpdateTabSpecificPermissions( |
750 const GURL& url, | 769 const GURL& url, |
751 int tab_id, | 770 int tab_id, |
752 const std::string& extension_id, | 771 const std::string& extension_id, |
753 const URLPatternSet& origin_set) { | 772 const URLPatternSet& origin_set) { |
754 delegate_->UpdateTabSpecificPermissions( | 773 delegate_->UpdateTabSpecificPermissions( |
755 this, url, tab_id, extension_id, origin_set); | 774 this, url, tab_id, extension_id, origin_set); |
756 } | 775 } |
757 | 776 |
758 void Dispatcher::OnUsingWebRequestAPI(bool webrequest_used) { | 777 void Dispatcher::OnUsingWebRequestAPI(bool webrequest_used) { |
759 delegate_->HandleWebRequestAPIUsage(webrequest_used); | 778 delegate_->HandleWebRequestAPIUsage(webrequest_used); |
760 } | 779 } |
761 | 780 |
762 void Dispatcher::OnUserScriptsUpdated( | 781 void Dispatcher::OnUserScriptsUpdated( |
763 const std::set<std::string>& changed_extensions, | 782 const std::set<std::string>& changed_extensions, |
764 const std::vector<UserScript*>& scripts) { | 783 const std::vector<UserScript*>& scripts) { |
765 UpdateActiveExtensions(); | 784 UpdateActiveExtensions(); |
766 } | 785 } |
767 | 786 |
768 void Dispatcher::UpdateActiveExtensions() { | 787 void Dispatcher::UpdateActiveExtensions() { |
769 std::set<std::string> active_extensions = active_extension_ids_; | 788 std::set<std::string> active_extensions = active_extension_ids_; |
770 user_script_set_->GetActiveExtensionIds(&active_extensions); | 789 user_script_set_->GetActiveExtensionIds(&active_extensions); |
771 delegate_->OnActiveExtensionsUpdated(active_extensions); | 790 delegate_->OnActiveExtensionsUpdated(active_extensions); |
772 } | 791 } |
773 | 792 |
774 void Dispatcher::UpdateOriginPermissions(const Extension* extension) { | 793 void Dispatcher::InitOriginPermissions(const Extension* extension) { |
775 const URLPatternSet& hosts = | |
776 extension->permissions_data()->GetEffectiveHostPermissions(); | |
777 WebSecurityPolicy::resetOriginAccessWhitelists(); | |
Devlin
2014/07/22 21:56:47
This was introduced in https://codereview.chromium
not at google - send to devlin
2014/07/23 01:18:54
right... good point.
This would be such a simpler
Devlin
2014/07/23 15:41:51
But to add the new ones, we add the new ones for _
not at google - send to devlin
2014/07/23 15:45:35
I don't think so? add/remove take the origin which
Devlin
2014/07/23 16:14:01
Ahhh, I see, I misunderstood (thought you meant st
| |
778 delegate_->InitOriginPermissions(extension, | 794 delegate_->InitOriginPermissions(extension, |
779 IsExtensionActive(extension->id())); | 795 IsExtensionActive(extension->id())); |
780 for (URLPatternSet::const_iterator iter = hosts.begin(); iter != hosts.end(); | 796 UpdateOriginPermissions( |
781 ++iter) { | 797 extension, |
782 const char* schemes[] = { | 798 true, // was added |
783 url::kHttpScheme, | 799 extension->permissions_data()->GetEffectiveHostPermissions()); |
784 url::kHttpsScheme, | 800 } |
785 url::kFileScheme, | 801 |
786 content::kChromeUIScheme, | 802 void Dispatcher::UpdateOriginPermissions( |
787 url::kFtpScheme, | 803 const Extension* extension, |
788 }; | 804 bool was_added, |
805 const URLPatternSet& patterns) { | |
806 static const char* schemes[] = { | |
not at google - send to devlin
2014/07/23 01:18:55
kSchemes?
Devlin
2014/07/23 15:41:51
Done.
| |
807 url::kHttpScheme, | |
808 url::kHttpsScheme, | |
809 url::kFileScheme, | |
810 content::kChromeUIScheme, | |
811 url::kFtpScheme, | |
812 }; | |
813 for (URLPatternSet::const_iterator iter = patterns.begin(); | |
814 iter != patterns.end(); ++iter) { | |
789 for (size_t j = 0; j < arraysize(schemes); ++j) { | 815 for (size_t j = 0; j < arraysize(schemes); ++j) { |
790 if (iter->MatchesScheme(schemes[j])) { | 816 if (iter->MatchesScheme(schemes[j])) { |
791 WebSecurityPolicy::addOriginAccessWhitelistEntry( | 817 (was_added ? WebSecurityPolicy::addOriginAccessWhitelistEntry |
818 : WebSecurityPolicy::removeOriginAccessWhitelistEntry)( | |
792 extension->url(), | 819 extension->url(), |
793 WebString::fromUTF8(schemes[j]), | 820 WebString::fromUTF8(schemes[j]), |
794 WebString::fromUTF8(iter->host()), | 821 WebString::fromUTF8(iter->host()), |
795 iter->match_subdomains()); | 822 iter->match_subdomains()); |
796 } | 823 } |
797 } | 824 } |
798 } | 825 } |
799 } | 826 } |
800 | 827 |
801 void Dispatcher::EnableCustomElementWhiteList() { | 828 void Dispatcher::EnableCustomElementWhiteList() { |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1197 return v8::Handle<v8::Object>(); | 1224 return v8::Handle<v8::Object>(); |
1198 | 1225 |
1199 if (bind_name) | 1226 if (bind_name) |
1200 *bind_name = split.back(); | 1227 *bind_name = split.back(); |
1201 | 1228 |
1202 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) | 1229 return bind_object.IsEmpty() ? AsObjectOrEmpty(GetOrCreateChrome(context)) |
1203 : bind_object; | 1230 : bind_object; |
1204 } | 1231 } |
1205 | 1232 |
1206 } // namespace extensions | 1233 } // namespace extensions |
OLD | NEW |