OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/extension_dispatcher.h" | 5 #include "chrome/renderer/extensions/extension_dispatcher.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 using WebKit::WebDataSource; | 68 using WebKit::WebDataSource; |
69 using WebKit::WebDocument; | 69 using WebKit::WebDocument; |
70 using WebKit::WebFrame; | 70 using WebKit::WebFrame; |
71 using WebKit::WebScopedUserGesture; | 71 using WebKit::WebScopedUserGesture; |
72 using WebKit::WebSecurityPolicy; | 72 using WebKit::WebSecurityPolicy; |
73 using WebKit::WebString; | 73 using WebKit::WebString; |
74 using WebKit::WebVector; | 74 using WebKit::WebVector; |
75 using WebKit::WebView; | 75 using WebKit::WebView; |
76 using content::RenderThread; | 76 using content::RenderThread; |
77 using content::RenderView; | 77 using content::RenderView; |
| 78 using extensions::APIPermission; |
78 using extensions::ApiDefinitionsNatives; | 79 using extensions::ApiDefinitionsNatives; |
79 using extensions::AppWindowCustomBindings; | 80 using extensions::AppWindowCustomBindings; |
80 using extensions::ContextMenusCustomBindings; | 81 using extensions::ContextMenusCustomBindings; |
81 using extensions::Extension; | 82 using extensions::Extension; |
82 using extensions::ExperimentalAppCustomBindings; | 83 using extensions::ExperimentalAppCustomBindings; |
83 using extensions::ExperimentalUsbCustomBindings; | 84 using extensions::ExperimentalUsbCustomBindings; |
84 using extensions::ExtensionAPI; | 85 using extensions::ExtensionAPI; |
85 using extensions::ExtensionCustomBindings; | 86 using extensions::ExtensionCustomBindings; |
86 using extensions::Feature; | 87 using extensions::Feature; |
87 using extensions::FileBrowserHandlerCustomBindings; | 88 using extensions::FileBrowserHandlerCustomBindings; |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 source_map_.RegisterSource("fileSystem", | 591 source_map_.RegisterSource("fileSystem", |
591 IDR_FILE_SYSTEM_CUSTOM_BINDINGS_JS); | 592 IDR_FILE_SYSTEM_CUSTOM_BINDINGS_JS); |
592 source_map_.RegisterSource("i18n", IDR_I18N_CUSTOM_BINDINGS_JS); | 593 source_map_.RegisterSource("i18n", IDR_I18N_CUSTOM_BINDINGS_JS); |
593 source_map_.RegisterSource("input.ime", IDR_INPUT_IME_CUSTOM_BINDINGS_JS); | 594 source_map_.RegisterSource("input.ime", IDR_INPUT_IME_CUSTOM_BINDINGS_JS); |
594 source_map_.RegisterSource("omnibox", IDR_OMNIBOX_CUSTOM_BINDINGS_JS); | 595 source_map_.RegisterSource("omnibox", IDR_OMNIBOX_CUSTOM_BINDINGS_JS); |
595 source_map_.RegisterSource("pageActions", | 596 source_map_.RegisterSource("pageActions", |
596 IDR_PAGE_ACTIONS_CUSTOM_BINDINGS_JS); | 597 IDR_PAGE_ACTIONS_CUSTOM_BINDINGS_JS); |
597 source_map_.RegisterSource("pageAction", IDR_PAGE_ACTION_CUSTOM_BINDINGS_JS); | 598 source_map_.RegisterSource("pageAction", IDR_PAGE_ACTION_CUSTOM_BINDINGS_JS); |
598 source_map_.RegisterSource("pageCapture", | 599 source_map_.RegisterSource("pageCapture", |
599 IDR_PAGE_CAPTURE_CUSTOM_BINDINGS_JS); | 600 IDR_PAGE_CAPTURE_CUSTOM_BINDINGS_JS); |
600 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); | |
601 source_map_.RegisterSource("runtime", IDR_RUNTIME_CUSTOM_BINDINGS_JS); | 601 source_map_.RegisterSource("runtime", IDR_RUNTIME_CUSTOM_BINDINGS_JS); |
602 source_map_.RegisterSource("storage", IDR_STORAGE_CUSTOM_BINDINGS_JS); | 602 source_map_.RegisterSource("storage", IDR_STORAGE_CUSTOM_BINDINGS_JS); |
603 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); | 603 source_map_.RegisterSource("tabs", IDR_TABS_CUSTOM_BINDINGS_JS); |
604 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); | 604 source_map_.RegisterSource("tts", IDR_TTS_CUSTOM_BINDINGS_JS); |
605 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); | 605 source_map_.RegisterSource("ttsEngine", IDR_TTS_ENGINE_CUSTOM_BINDINGS_JS); |
606 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); | 606 source_map_.RegisterSource("types", IDR_TYPES_CUSTOM_BINDINGS_JS); |
607 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); | 607 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); |
608 source_map_.RegisterSource("webRequestInternal", | 608 source_map_.RegisterSource("webRequestInternal", |
609 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); | 609 IDR_WEB_REQUEST_INTERNAL_CUSTOM_BINDINGS_JS); |
610 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); | 610 source_map_.RegisterSource("webstore", IDR_WEBSTORE_CUSTOM_BINDINGS_JS); |
| 611 |
| 612 // Platform app sources that are not API-specific.. |
| 613 source_map_.RegisterSource("browserTag", IDR_BROWSER_TAG_JS); |
| 614 source_map_.RegisterSource("platformApp", IDR_PLATFORM_APP_JS); |
611 } | 615 } |
612 | 616 |
613 void ExtensionDispatcher::PopulateLazyBindingsMap() { | 617 void ExtensionDispatcher::PopulateLazyBindingsMap() { |
614 lazy_bindings_map_["app"] = InstallAppBindings; | 618 lazy_bindings_map_["app"] = InstallAppBindings; |
615 lazy_bindings_map_["webstore"] = InstallWebstoreBindings; | 619 lazy_bindings_map_["webstore"] = InstallWebstoreBindings; |
616 } | 620 } |
617 | 621 |
618 void ExtensionDispatcher::InstallBindings(ModuleSystem* module_system, | 622 void ExtensionDispatcher::InstallBindings(ModuleSystem* module_system, |
619 v8::Handle<v8::Context> v8_context, | 623 v8::Handle<v8::Context> v8_context, |
620 const std::string& api) { | 624 const std::string& api) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 | 723 |
720 break; | 724 break; |
721 } | 725 } |
722 } | 726 } |
723 | 727 |
724 // Inject custom JS into the platform app context to block certain features | 728 // Inject custom JS into the platform app context to block certain features |
725 // of the document and window. | 729 // of the document and window. |
726 if (IsWithinPlatformApp(frame)) | 730 if (IsWithinPlatformApp(frame)) |
727 module_system->Require("platformApp"); | 731 module_system->Require("platformApp"); |
728 | 732 |
| 733 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT && |
| 734 extension && extension->HasAPIPermission(APIPermission::kBrowserTag)) { |
| 735 module_system->Require("browserTag"); |
| 736 } |
| 737 |
729 context->set_module_system(module_system.Pass()); | 738 context->set_module_system(module_system.Pass()); |
730 | 739 |
731 int manifest_version = 1; | 740 int manifest_version = 1; |
732 if (extension) | 741 if (extension) |
733 manifest_version = extension->manifest_version(); | 742 manifest_version = extension->manifest_version(); |
734 context->DispatchOnLoadEvent( | 743 context->DispatchOnLoadEvent( |
735 is_extension_process_, | 744 is_extension_process_, |
736 ChromeRenderProcessObserver::is_incognito_process(), | 745 ChromeRenderProcessObserver::is_incognito_process(), |
737 manifest_version); | 746 manifest_version); |
738 | 747 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 return; | 794 return; |
786 | 795 |
787 if (is_webkit_initialized_) | 796 if (is_webkit_initialized_) |
788 InitOriginPermissions(extension); | 797 InitOriginPermissions(extension); |
789 } | 798 } |
790 | 799 |
791 void ExtensionDispatcher::InitOriginPermissions(const Extension* extension) { | 800 void ExtensionDispatcher::InitOriginPermissions(const Extension* extension) { |
792 // TODO(jstritar): We should try to remove this special case. Also, these | 801 // TODO(jstritar): We should try to remove this special case. Also, these |
793 // whitelist entries need to be updated when the kManagement permission | 802 // whitelist entries need to be updated when the kManagement permission |
794 // changes. | 803 // changes. |
795 if (extension->HasAPIPermission(extensions::APIPermission::kManagement)) { | 804 if (extension->HasAPIPermission(APIPermission::kManagement)) { |
796 WebSecurityPolicy::addOriginAccessWhitelistEntry( | 805 WebSecurityPolicy::addOriginAccessWhitelistEntry( |
797 extension->url(), | 806 extension->url(), |
798 WebString::fromUTF8(chrome::kChromeUIScheme), | 807 WebString::fromUTF8(chrome::kChromeUIScheme), |
799 WebString::fromUTF8(chrome::kChromeUIExtensionIconHost), | 808 WebString::fromUTF8(chrome::kChromeUIExtensionIconHost), |
800 false); | 809 false); |
801 } | 810 } |
802 | 811 |
803 AddOrRemoveOriginPermissions( | 812 AddOrRemoveOriginPermissions( |
804 UpdatedExtensionPermissionsInfo::ADDED, | 813 UpdatedExtensionPermissionsInfo::ADDED, |
805 extension, | 814 extension, |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 // APIs, they don't get extension bindings injected. If we end up here it | 1026 // APIs, they don't get extension bindings injected. If we end up here it |
1018 // means that a sandboxed page somehow managed to invoke an API anyway, so | 1027 // means that a sandboxed page somehow managed to invoke an API anyway, so |
1019 // we should abort. | 1028 // we should abort. |
1020 WebKit::WebFrame* frame = context->web_frame(); | 1029 WebKit::WebFrame* frame = context->web_frame(); |
1021 ExtensionURLInfo url_info(frame->document().securityOrigin(), | 1030 ExtensionURLInfo url_info(frame->document().securityOrigin(), |
1022 UserScriptSlave::GetDataSourceURLForFrame(frame)); | 1031 UserScriptSlave::GetDataSourceURLForFrame(frame)); |
1023 CHECK(!extensions_.IsSandboxedPage(url_info)); | 1032 CHECK(!extensions_.IsSandboxedPage(url_info)); |
1024 | 1033 |
1025 return true; | 1034 return true; |
1026 } | 1035 } |
OLD | NEW |