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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 const Extension* extension) { | 189 const Extension* extension) { |
190 if (!render_view) | 190 if (!render_view) |
191 return false; | 191 return false; |
192 | 192 |
193 ExtensionHelper* helper = ExtensionHelper::Get(render_view); | 193 ExtensionHelper* helper = ExtensionHelper::Get(render_view); |
194 return (extension && extension->has_lazy_background_page() && | 194 return (extension && extension->has_lazy_background_page() && |
195 helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); | 195 helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
196 } | 196 } |
197 }; | 197 }; |
198 | 198 |
| 199 class ProcessInfoNativeHandler : public ChromeV8Extension { |
| 200 public: |
| 201 explicit ProcessInfoNativeHandler( |
| 202 ExtensionDispatcher* dispatcher, |
| 203 const std::string& extension_id, |
| 204 const std::string& context_type, |
| 205 bool is_incognito_context, |
| 206 int manifest_version) |
| 207 : ChromeV8Extension(dispatcher), |
| 208 extension_id_(extension_id), |
| 209 context_type_(context_type), |
| 210 is_incognito_context_(is_incognito_context), |
| 211 manifest_version_(manifest_version) { |
| 212 RouteFunction("GetExtensionId", |
| 213 base::Bind(&ProcessInfoNativeHandler::GetExtensionId, |
| 214 base::Unretained(this))); |
| 215 RouteFunction("GetContextType", |
| 216 base::Bind(&ProcessInfoNativeHandler::GetContextType, |
| 217 base::Unretained(this))); |
| 218 RouteFunction("InIncognitoContext", |
| 219 base::Bind(&ProcessInfoNativeHandler::InIncognitoContext, |
| 220 base::Unretained(this))); |
| 221 RouteFunction("GetManifestVersion", |
| 222 base::Bind(&ProcessInfoNativeHandler::GetManifestVersion, |
| 223 base::Unretained(this))); |
| 224 } |
| 225 |
| 226 v8::Handle<v8::Value> GetExtensionId(const v8::Arguments& args) { |
| 227 return v8::String::New(extension_id_.c_str()); |
| 228 } |
| 229 |
| 230 v8::Handle<v8::Value> GetContextType(const v8::Arguments& args) { |
| 231 return v8::String::New(context_type_.c_str()); |
| 232 } |
| 233 |
| 234 v8::Handle<v8::Value> InIncognitoContext(const v8::Arguments& args) { |
| 235 return v8::Boolean::New(is_incognito_context_); |
| 236 } |
| 237 |
| 238 v8::Handle<v8::Value> GetManifestVersion(const v8::Arguments& args) { |
| 239 return v8::Integer::New(manifest_version_); |
| 240 } |
| 241 |
| 242 private: |
| 243 std::string extension_id_; |
| 244 std::string context_type_; |
| 245 bool is_incognito_context_; |
| 246 int manifest_version_; |
| 247 }; |
| 248 |
199 class ChannelNativeHandler : public NativeHandler { | 249 class ChannelNativeHandler : public NativeHandler { |
200 public: | 250 public: |
201 explicit ChannelNativeHandler(chrome::VersionInfo::Channel channel) | 251 explicit ChannelNativeHandler(chrome::VersionInfo::Channel channel) |
202 : channel_(channel) { | 252 : channel_(channel) { |
203 RouteFunction("IsDevChannel", | 253 RouteFunction("IsDevChannel", |
204 base::Bind(&ChannelNativeHandler::IsDevChannel, | 254 base::Bind(&ChannelNativeHandler::IsDevChannel, |
205 base::Unretained(this))); | 255 base::Unretained(this))); |
206 } | 256 } |
207 | 257 |
208 v8::Handle<v8::Value> IsDevChannel(const v8::Arguments& args) { | 258 v8::Handle<v8::Value> IsDevChannel(const v8::Arguments& args) { |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); | 781 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); |
732 module_system->RegisterNativeHandler("print", | 782 module_system->RegisterNativeHandler("print", |
733 scoped_ptr<NativeHandler>(new PrintNativeHandler())); | 783 scoped_ptr<NativeHandler>(new PrintNativeHandler())); |
734 module_system->RegisterNativeHandler("lazy_background_page", | 784 module_system->RegisterNativeHandler("lazy_background_page", |
735 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); | 785 scoped_ptr<NativeHandler>(new LazyBackgroundPageNativeHandler(this))); |
736 module_system->RegisterNativeHandler("channel", | 786 module_system->RegisterNativeHandler("channel", |
737 scoped_ptr<NativeHandler>(new ChannelNativeHandler( | 787 scoped_ptr<NativeHandler>(new ChannelNativeHandler( |
738 static_cast<chrome::VersionInfo::Channel>(chrome_channel_)))); | 788 static_cast<chrome::VersionInfo::Channel>(chrome_channel_)))); |
739 module_system->RegisterNativeHandler("logging", | 789 module_system->RegisterNativeHandler("logging", |
740 scoped_ptr<NativeHandler>(new LoggingNativeHandler())); | 790 scoped_ptr<NativeHandler>(new LoggingNativeHandler())); |
| 791 |
| 792 |
| 793 int manifest_version = extension ? extension->manifest_version() : 1; |
| 794 module_system->RegisterNativeHandler("process", |
| 795 scoped_ptr<NativeHandler>(new ProcessInfoNativeHandler( |
| 796 this, context->GetExtensionID(), |
| 797 context->GetContextTypeDescription(), |
| 798 ChromeRenderProcessObserver::is_incognito_process(), |
| 799 manifest_version))); |
| 800 |
741 GetOrCreateChrome(v8_context); | 801 GetOrCreateChrome(v8_context); |
742 | 802 |
743 // Loading JavaScript is expensive, so only run the full API bindings | 803 // Loading JavaScript is expensive, so only run the full API bindings |
744 // generation mechanisms in extension pages (NOT all web pages). | 804 // generation mechanisms in extension pages (NOT all web pages). |
745 switch (context_type) { | 805 switch (context_type) { |
746 case Feature::UNSPECIFIED_CONTEXT: | 806 case Feature::UNSPECIFIED_CONTEXT: |
747 case Feature::WEB_PAGE_CONTEXT: | 807 case Feature::WEB_PAGE_CONTEXT: |
748 // TODO(kalman): see comment below about ExtensionAPI. | 808 // TODO(kalman): see comment below about ExtensionAPI. |
749 InstallBindings(module_system.get(), v8_context, "app"); | 809 InstallBindings(module_system.get(), v8_context, "app"); |
750 InstallBindings(module_system.get(), v8_context, "webstore"); | 810 InstallBindings(module_system.get(), v8_context, "webstore"); |
(...skipping 26 matching lines...) Expand all Loading... |
777 if (IsWithinPlatformApp(frame)) | 837 if (IsWithinPlatformApp(frame)) |
778 module_system->Require("platformApp"); | 838 module_system->Require("platformApp"); |
779 | 839 |
780 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT && | 840 if (context_type == Feature::BLESSED_EXTENSION_CONTEXT && |
781 extension && extension->HasAPIPermission(APIPermission::kBrowserTag)) { | 841 extension && extension->HasAPIPermission(APIPermission::kBrowserTag)) { |
782 module_system->Require("browserTag"); | 842 module_system->Require("browserTag"); |
783 } | 843 } |
784 | 844 |
785 context->set_module_system(module_system.Pass()); | 845 context->set_module_system(module_system.Pass()); |
786 | 846 |
787 int manifest_version = 1; | |
788 if (extension) | |
789 manifest_version = extension->manifest_version(); | |
790 context->DispatchOnLoadEvent( | 847 context->DispatchOnLoadEvent( |
791 ChromeRenderProcessObserver::is_incognito_process(), | 848 ChromeRenderProcessObserver::is_incognito_process(), |
792 manifest_version); | 849 manifest_version); |
793 | 850 |
794 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); | 851 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); |
795 } | 852 } |
796 | 853 |
797 std::string ExtensionDispatcher::GetExtensionID(const WebFrame* frame, | 854 std::string ExtensionDispatcher::GetExtensionID(const WebFrame* frame, |
798 int world_id) { | 855 int world_id) { |
799 if (world_id != 0) { | 856 if (world_id != 0) { |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 // APIs, they don't get extension bindings injected. If we end up here it | 1137 // APIs, they don't get extension bindings injected. If we end up here it |
1081 // means that a sandboxed page somehow managed to invoke an API anyway, so | 1138 // means that a sandboxed page somehow managed to invoke an API anyway, so |
1082 // we should abort. | 1139 // we should abort. |
1083 WebKit::WebFrame* frame = context->web_frame(); | 1140 WebKit::WebFrame* frame = context->web_frame(); |
1084 ExtensionURLInfo url_info(frame->document().securityOrigin(), | 1141 ExtensionURLInfo url_info(frame->document().securityOrigin(), |
1085 extensions::UserScriptSlave::GetDataSourceURLForFrame(frame)); | 1142 extensions::UserScriptSlave::GetDataSourceURLForFrame(frame)); |
1086 CHECK(!extensions_.IsSandboxedPage(url_info)); | 1143 CHECK(!extensions_.IsSandboxedPage(url_info)); |
1087 | 1144 |
1088 return true; | 1145 return true; |
1089 } | 1146 } |
OLD | NEW |