| 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" |
| 11 #include "chrome/common/child_process_logging.h" | 11 #include "chrome/common/child_process_logging.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
| 14 #include "chrome/common/extensions/extension_messages.h" | 14 #include "chrome/common/extensions/extension_messages.h" |
| 15 #include "chrome/common/extensions/extension_permission_set.h" | 15 #include "chrome/common/extensions/extension_permission_set.h" |
| 16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 17 #include "chrome/renderer/chrome_render_process_observer.h" | 17 #include "chrome/renderer/chrome_render_process_observer.h" |
| 18 #include "chrome/renderer/extensions/app_bindings.h" | 18 #include "chrome/renderer/extensions/app_bindings.h" |
| 19 #include "chrome/renderer/extensions/chrome_v8_context.h" | 19 #include "chrome/renderer/extensions/chrome_v8_context.h" |
| 20 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 20 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
| 21 #include "chrome/renderer/extensions/custom_bindings_util.h" | 21 #include "chrome/renderer/extensions/chrome_private_custom_bindings.h" |
| 22 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" |
| 22 #include "chrome/renderer/extensions/event_bindings.h" | 23 #include "chrome/renderer/extensions/event_bindings.h" |
| 24 #include "chrome/renderer/extensions/experimental.socket_custom_bindings.h" |
| 25 #include "chrome/renderer/extensions/extension_custom_bindings.h" |
| 23 #include "chrome/renderer/extensions/extension_groups.h" | 26 #include "chrome/renderer/extensions/extension_groups.h" |
| 27 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" |
| 28 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" |
| 29 #include "chrome/renderer/extensions/i18n_custom_bindings.h" |
| 24 #include "chrome/renderer/extensions/miscellaneous_bindings.h" | 30 #include "chrome/renderer/extensions/miscellaneous_bindings.h" |
| 31 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" |
| 32 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" |
| 25 #include "chrome/renderer/extensions/schema_generated_bindings.h" | 33 #include "chrome/renderer/extensions/schema_generated_bindings.h" |
| 34 #include "chrome/renderer/extensions/tabs_custom_bindings.h" |
| 35 #include "chrome/renderer/extensions/tts_custom_bindings.h" |
| 26 #include "chrome/renderer/extensions/user_script_slave.h" | 36 #include "chrome/renderer/extensions/user_script_slave.h" |
| 37 #include "chrome/renderer/extensions/web_request_custom_bindings.h" |
| 27 #include "chrome/renderer/extensions/webstore_bindings.h" | 38 #include "chrome/renderer/extensions/webstore_bindings.h" |
| 28 #include "chrome/renderer/module_system.h" | 39 #include "chrome/renderer/module_system.h" |
| 29 #include "chrome/renderer/native_handler.h" | 40 #include "chrome/renderer/native_handler.h" |
| 30 #include "chrome/renderer/resource_bundle_source_map.h" | 41 #include "chrome/renderer/resource_bundle_source_map.h" |
| 31 #include "content/public/renderer/render_thread.h" | 42 #include "content/public/renderer/render_thread.h" |
| 32 #include "grit/renderer_resources.h" | 43 #include "grit/renderer_resources.h" |
| 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedUserGesture.
h" |
| 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" | 48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
| 49 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 37 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 50 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 38 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" | 51 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" |
| 39 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedUserGesture.
h" | |
| 40 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
| 41 #include "ui/base/resource/resource_bundle.h" | 52 #include "ui/base/resource/resource_bundle.h" |
| 42 #include "v8/include/v8.h" | 53 #include "v8/include/v8.h" |
| 43 | 54 |
| 44 #include "chrome/renderer/extensions/chrome_private_custom_bindings.h" | |
| 45 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" | |
| 46 #include "chrome/renderer/extensions/experimental.socket_custom_bindings.h" | |
| 47 #include "chrome/renderer/extensions/extension_custom_bindings.h" | |
| 48 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" | |
| 49 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" | |
| 50 #include "chrome/renderer/extensions/i18n_custom_bindings.h" | |
| 51 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" | |
| 52 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" | |
| 53 #include "chrome/renderer/extensions/tabs_custom_bindings.h" | |
| 54 #include "chrome/renderer/extensions/tts_custom_bindings.h" | |
| 55 #include "chrome/renderer/extensions/web_request_custom_bindings.h" | |
| 56 | |
| 57 using content::RenderThread; | 55 using content::RenderThread; |
| 58 using extensions::ChromePrivateCustomBindings; | 56 using extensions::ChromePrivateCustomBindings; |
| 59 using extensions::ContextMenusCustomBindings; | 57 using extensions::ContextMenusCustomBindings; |
| 60 using extensions::ExperimentalSocketCustomBindings; | 58 using extensions::ExperimentalSocketCustomBindings; |
| 61 using extensions::ExtensionCustomBindings; | 59 using extensions::ExtensionCustomBindings; |
| 60 using extensions::Feature; |
| 62 using extensions::FileBrowserHandlerCustomBindings; | 61 using extensions::FileBrowserHandlerCustomBindings; |
| 63 using extensions::FileBrowserPrivateCustomBindings; | 62 using extensions::FileBrowserPrivateCustomBindings; |
| 64 using extensions::I18NCustomBindings; | 63 using extensions::I18NCustomBindings; |
| 65 using extensions::MiscellaneousBindings; | 64 using extensions::MiscellaneousBindings; |
| 66 using extensions::PageActionsCustomBindings; | 65 using extensions::PageActionsCustomBindings; |
| 67 using extensions::PageCaptureCustomBindings; | 66 using extensions::PageCaptureCustomBindings; |
| 68 using extensions::SchemaGeneratedBindings; | 67 using extensions::SchemaGeneratedBindings; |
| 69 using extensions::TTSCustomBindings; | 68 using extensions::TTSCustomBindings; |
| 70 using extensions::TabsCustomBindings; | 69 using extensions::TabsCustomBindings; |
| 71 using extensions::WebRequestCustomBindings; | 70 using extensions::WebRequestCustomBindings; |
| 72 using WebKit::WebDataSource; | 71 using WebKit::WebDataSource; |
| 73 using WebKit::WebDocument; | 72 using WebKit::WebDocument; |
| 74 using WebKit::WebFrame; | 73 using WebKit::WebFrame; |
| 75 using WebKit::WebSecurityPolicy; | 74 using WebKit::WebSecurityPolicy; |
| 76 using WebKit::WebString; | 75 using WebKit::WebString; |
| 77 using WebKit::WebScopedUserGesture; | 76 using WebKit::WebScopedUserGesture; |
| 78 using WebKit::WebVector; | 77 using WebKit::WebVector; |
| 79 using WebKit::WebView; | 78 using WebKit::WebView; |
| 80 | 79 |
| 81 namespace util = extensions::custom_bindings_util; | |
| 82 | |
| 83 namespace { | 80 namespace { |
| 84 | 81 |
| 85 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; | 82 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; |
| 86 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; | 83 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; |
| 87 | 84 |
| 88 ChromeV8Context::ContextType ExtensionGroupToContextType(int extension_group) { | |
| 89 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) | |
| 90 return ChromeV8Context::CONTENT_SCRIPT; | |
| 91 return ChromeV8Context::OTHER; | |
| 92 } | |
| 93 | |
| 94 class ChromeHiddenNativeHandler : public NativeHandler { | 85 class ChromeHiddenNativeHandler : public NativeHandler { |
| 95 public: | 86 public: |
| 96 ChromeHiddenNativeHandler() { | 87 ChromeHiddenNativeHandler() { |
| 97 RouteFunction("GetChromeHidden", | 88 RouteFunction("GetChromeHidden", |
| 98 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, | 89 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, |
| 99 base::Unretained(this))); | 90 base::Unretained(this))); |
| 100 } | 91 } |
| 101 | 92 |
| 102 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) { | 93 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) { |
| 103 return ChromeV8Context::GetOrCreateChromeHidden(v8::Context::GetCurrent()); | 94 return ChromeV8Context::GetOrCreateChromeHidden(v8::Context::GetCurrent()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 118 | 109 |
| 119 std::vector<std::string> components; | 110 std::vector<std::string> components; |
| 120 for (int i = 0; i < args.Length(); ++i) | 111 for (int i = 0; i < args.Length(); ++i) |
| 121 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); | 112 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); |
| 122 | 113 |
| 123 LOG(ERROR) << JoinString(components, ','); | 114 LOG(ERROR) << JoinString(components, ','); |
| 124 return v8::Undefined(); | 115 return v8::Undefined(); |
| 125 } | 116 } |
| 126 }; | 117 }; |
| 127 | 118 |
| 128 class ContextInfoNativeHandler : public NativeHandler { | |
| 129 public: | |
| 130 explicit ContextInfoNativeHandler(ExtensionDispatcher* extension_dispatcher, | |
| 131 bool is_bindings_allowed, | |
| 132 WebKit::WebFrame* frame, | |
| 133 int world_id) | |
| 134 : extension_dispatcher_(extension_dispatcher), | |
| 135 is_bindings_allowed_(is_bindings_allowed), | |
| 136 frame_(frame), | |
| 137 world_id_(world_id) { | |
| 138 RouteFunction("IsBindingsAllowed", | |
| 139 base::Bind(&ContextInfoNativeHandler::IsBindingsAllowed, | |
| 140 base::Unretained(this))); | |
| 141 RouteFunction("IsAPIAllowed", | |
| 142 base::Bind(&ContextInfoNativeHandler::IsAPIAllowed, | |
| 143 base::Unretained(this))); | |
| 144 } | |
| 145 | |
| 146 v8::Handle<v8::Value> IsBindingsAllowed(const v8::Arguments& args) { | |
| 147 return v8::Boolean::New(is_bindings_allowed_); | |
| 148 } | |
| 149 | |
| 150 v8::Handle<v8::Value> IsAPIAllowed(const v8::Arguments& args) { | |
| 151 std::string custom_api_name = *v8::String::AsciiValue(args[0]->ToString()); | |
| 152 return v8::Boolean::New(extension_dispatcher_->AllowCustomAPI( | |
| 153 frame_, custom_api_name, world_id_)); | |
| 154 } | |
| 155 | |
| 156 private: | |
| 157 ExtensionDispatcher* extension_dispatcher_; | |
| 158 bool is_bindings_allowed_; | |
| 159 WebKit::WebFrame* frame_; | |
| 160 int world_id_; | |
| 161 }; | |
| 162 | |
| 163 } | 119 } |
| 164 | 120 |
| 165 ExtensionDispatcher::ExtensionDispatcher() | 121 ExtensionDispatcher::ExtensionDispatcher() |
| 166 : is_webkit_initialized_(false), | 122 : is_webkit_initialized_(false), |
| 167 webrequest_adblock_(false), | 123 webrequest_adblock_(false), |
| 168 webrequest_adblock_plus_(false), | 124 webrequest_adblock_plus_(false), |
| 169 webrequest_other_(false), | 125 webrequest_other_(false), |
| 170 source_map_(&ResourceBundle::GetSharedInstance()) { | 126 source_map_(&ResourceBundle::GetSharedInstance()) { |
| 171 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); | 127 const CommandLine& command_line = *(CommandLine::ForCurrentProcess()); |
| 172 is_extension_process_ = | 128 is_extension_process_ = |
| (...skipping 17 matching lines...) Expand all Loading... |
| 190 bool handled = true; | 146 bool handled = true; |
| 191 IPC_BEGIN_MESSAGE_MAP(ExtensionDispatcher, message) | 147 IPC_BEGIN_MESSAGE_MAP(ExtensionDispatcher, message) |
| 192 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) | 148 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) |
| 193 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) | 149 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) |
| 194 IPC_MESSAGE_HANDLER(ExtensionMsg_SetFunctionNames, OnSetFunctionNames) | 150 IPC_MESSAGE_HANDLER(ExtensionMsg_SetFunctionNames, OnSetFunctionNames) |
| 195 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) | 151 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) |
| 196 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) | 152 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) |
| 197 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, | 153 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, |
| 198 OnSetScriptingWhitelist) | 154 OnSetScriptingWhitelist) |
| 199 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) | 155 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) |
| 200 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateApplication, OnActivateApplication) | |
| 201 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) | 156 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) |
| 202 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) | 157 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) |
| 203 IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI) | 158 IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI) |
| 204 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldClose, OnShouldClose) | 159 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldClose, OnShouldClose) |
| 205 IPC_MESSAGE_UNHANDLED(handled = false) | 160 IPC_MESSAGE_UNHANDLED(handled = false) |
| 206 IPC_END_MESSAGE_MAP() | 161 IPC_END_MESSAGE_MAP() |
| 207 | 162 |
| 208 return handled; | 163 return handled; |
| 209 } | 164 } |
| 210 | 165 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 // We don't do anything with existing platform-app stylesheets. They will | 295 // We don't do anything with existing platform-app stylesheets. They will |
| 341 // stay resident, but the URL pattern corresponding to the unloaded | 296 // stay resident, but the URL pattern corresponding to the unloaded |
| 342 // extension's URL just won't match anything anymore. | 297 // extension's URL just won't match anything anymore. |
| 343 } | 298 } |
| 344 | 299 |
| 345 void ExtensionDispatcher::OnSetScriptingWhitelist( | 300 void ExtensionDispatcher::OnSetScriptingWhitelist( |
| 346 const Extension::ScriptingWhitelist& extension_ids) { | 301 const Extension::ScriptingWhitelist& extension_ids) { |
| 347 Extension::SetScriptingWhitelist(extension_ids); | 302 Extension::SetScriptingWhitelist(extension_ids); |
| 348 } | 303 } |
| 349 | 304 |
| 350 bool ExtensionDispatcher::IsApplicationActive( | |
| 351 const std::string& extension_id) const { | |
| 352 return active_application_ids_.find(extension_id) != | |
| 353 active_application_ids_.end(); | |
| 354 } | |
| 355 | |
| 356 bool ExtensionDispatcher::IsExtensionActive( | 305 bool ExtensionDispatcher::IsExtensionActive( |
| 357 const std::string& extension_id) const { | 306 const std::string& extension_id) const { |
| 358 return active_extension_ids_.find(extension_id) != | 307 return active_extension_ids_.find(extension_id) != |
| 359 active_extension_ids_.end(); | 308 active_extension_ids_.end(); |
| 360 } | 309 } |
| 361 | 310 |
| 362 bool ExtensionDispatcher::AllowScriptExtension( | 311 bool ExtensionDispatcher::AllowScriptExtension( |
| 363 WebFrame* frame, | 312 WebFrame* frame, |
| 364 const std::string& v8_extension_name, | 313 const std::string& v8_extension_name, |
| 365 int extension_group) { | 314 int extension_group) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 380 | 329 |
| 381 bool ExtensionDispatcher::AllowScriptExtension( | 330 bool ExtensionDispatcher::AllowScriptExtension( |
| 382 WebFrame* frame, | 331 WebFrame* frame, |
| 383 const std::string& v8_extension_name, | 332 const std::string& v8_extension_name, |
| 384 int extension_group, | 333 int extension_group, |
| 385 int world_id) { | 334 int world_id) { |
| 386 g_hack_extension_group = extension_group; | 335 g_hack_extension_group = extension_group; |
| 387 return true; | 336 return true; |
| 388 } | 337 } |
| 389 | 338 |
| 390 bool ExtensionDispatcher::AllowCustomAPI( | |
| 391 WebFrame* frame, | |
| 392 const std::string& custom_binding_api_name, | |
| 393 int world_id) { | |
| 394 std::string extension_id = GetExtensionID(frame, world_id); | |
| 395 if (IsTestExtensionId(extension_id)) | |
| 396 return true; | |
| 397 const Extension* extension = extensions_.GetByID(extension_id); | |
| 398 if (!extension) { | |
| 399 // This can happen when a resource is blocked due to CSP; a valid | |
| 400 // chrome-extension:// URL is navigated to, so it passes the initial | |
| 401 // checks, but the URL gets changed to "chrome-extension://invalid" | |
| 402 // afterwards (see chrome_content_renderer_client.cc). An extension | |
| 403 // page still gets loaded, just for the extension with ID "invalid", | |
| 404 // which of course isn't found so GetById extension will be NULL. | |
| 405 // | |
| 406 // Reference: http://crbug.com/111614. | |
| 407 CHECK_EQ("invalid", extension_id); | |
| 408 return false; | |
| 409 } | |
| 410 return util::AllowAPIInjection( | |
| 411 custom_binding_api_name, *extension, this); | |
| 412 } | |
| 413 | |
| 414 void ExtensionDispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 339 void ExtensionDispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
| 415 ChromeV8Context* context) { | 340 ChromeV8Context* context) { |
| 416 module_system->RegisterNativeHandler("app", | |
| 417 scoped_ptr<NativeHandler>(new AppBindings(this, context))); | |
| 418 module_system->RegisterNativeHandler("webstore", | 341 module_system->RegisterNativeHandler("webstore", |
| 419 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); | 342 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); |
| 420 module_system->RegisterNativeHandler("event_bindings", | 343 module_system->RegisterNativeHandler("event_bindings", |
| 421 scoped_ptr<NativeHandler>(EventBindings::Get(this))); | 344 scoped_ptr<NativeHandler>(EventBindings::Get(this))); |
| 422 module_system->RegisterNativeHandler("miscellaneous_bindings", | 345 module_system->RegisterNativeHandler("miscellaneous_bindings", |
| 423 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); | 346 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); |
| 424 module_system->RegisterNativeHandler("schema_generated_bindings", | 347 module_system->RegisterNativeHandler("schema_generated_bindings", |
| 425 scoped_ptr<NativeHandler>(SchemaGeneratedBindings::Get(this))); | 348 scoped_ptr<NativeHandler>(SchemaGeneratedBindings::Get(this))); |
| 426 | 349 |
| 427 // Custom bindings. | 350 // Custom bindings. |
| 351 module_system->RegisterNativeHandler("app", |
| 352 scoped_ptr<NativeHandler>(new AppBindings(this, context))); |
| 428 module_system->RegisterNativeHandler("chrome_private", | 353 module_system->RegisterNativeHandler("chrome_private", |
| 429 scoped_ptr<NativeHandler>( | 354 scoped_ptr<NativeHandler>( |
| 430 new ChromePrivateCustomBindings(this))); | 355 new ChromePrivateCustomBindings(this))); |
| 431 module_system->RegisterNativeHandler("context_menus", | 356 module_system->RegisterNativeHandler("context_menus", |
| 432 scoped_ptr<NativeHandler>(new ContextMenusCustomBindings())); | 357 scoped_ptr<NativeHandler>(new ContextMenusCustomBindings())); |
| 433 module_system->RegisterNativeHandler("extension", | 358 module_system->RegisterNativeHandler("extension", |
| 434 scoped_ptr<NativeHandler>( | 359 scoped_ptr<NativeHandler>( |
| 435 new ExtensionCustomBindings(this))); | 360 new ExtensionCustomBindings(this))); |
| 436 module_system->RegisterNativeHandler("experimental_socket", | 361 module_system->RegisterNativeHandler("experimental_socket", |
| 437 scoped_ptr<NativeHandler>(new ExperimentalSocketCustomBindings())); | 362 scoped_ptr<NativeHandler>(new ExperimentalSocketCustomBindings())); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 448 scoped_ptr<NativeHandler>(new PageCaptureCustomBindings())); | 373 scoped_ptr<NativeHandler>(new PageCaptureCustomBindings())); |
| 449 module_system->RegisterNativeHandler("tabs", | 374 module_system->RegisterNativeHandler("tabs", |
| 450 scoped_ptr<NativeHandler>(new TabsCustomBindings())); | 375 scoped_ptr<NativeHandler>(new TabsCustomBindings())); |
| 451 module_system->RegisterNativeHandler("tts", | 376 module_system->RegisterNativeHandler("tts", |
| 452 scoped_ptr<NativeHandler>(new TTSCustomBindings())); | 377 scoped_ptr<NativeHandler>(new TTSCustomBindings())); |
| 453 module_system->RegisterNativeHandler("web_request", | 378 module_system->RegisterNativeHandler("web_request", |
| 454 scoped_ptr<NativeHandler>(new WebRequestCustomBindings())); | 379 scoped_ptr<NativeHandler>(new WebRequestCustomBindings())); |
| 455 } | 380 } |
| 456 | 381 |
| 457 void ExtensionDispatcher::PopulateSourceMap() { | 382 void ExtensionDispatcher::PopulateSourceMap() { |
| 458 source_map_.RegisterSource("app", IDR_APP_BINDINGS_JS); | |
| 459 source_map_.RegisterSource("webstore", IDR_WEBSTORE_BINDINGS_JS); | 383 source_map_.RegisterSource("webstore", IDR_WEBSTORE_BINDINGS_JS); |
| 460 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); | 384 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); |
| 461 source_map_.RegisterSource("miscellaneous_bindings", | 385 source_map_.RegisterSource("miscellaneous_bindings", |
| 462 IDR_MISCELLANEOUS_BINDINGS_JS); | 386 IDR_MISCELLANEOUS_BINDINGS_JS); |
| 463 source_map_.RegisterSource("schema_generated_bindings", | 387 source_map_.RegisterSource("schema_generated_bindings", |
| 464 IDR_SCHEMA_GENERATED_BINDINGS_JS); | 388 IDR_SCHEMA_GENERATED_BINDINGS_JS); |
| 465 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); | 389 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); |
| 466 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS); | 390 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS); |
| 467 source_map_.RegisterSource("setup_bindings", IDR_SETUP_BINDINGS_JS); | 391 source_map_.RegisterSource("setup_bindings", IDR_SETUP_BINDINGS_JS); |
| 468 | 392 |
| 469 // Custom bindings. | 393 // Custom bindings. |
| 394 source_map_.RegisterSource("app", IDR_APP_CUSTOM_BINDINGS_JS); |
| 470 source_map_.RegisterSource("browserAction", | 395 source_map_.RegisterSource("browserAction", |
| 471 IDR_BROWSER_ACTION_CUSTOM_BINDINGS_JS); | 396 IDR_BROWSER_ACTION_CUSTOM_BINDINGS_JS); |
| 472 source_map_.RegisterSource("chromePrivate", | 397 source_map_.RegisterSource("chromePrivate", |
| 473 IDR_CHROME_PRIVATE_CUSTOM_BINDINGS_JS); | 398 IDR_CHROME_PRIVATE_CUSTOM_BINDINGS_JS); |
| 474 source_map_.RegisterSource("contentSettings", | 399 source_map_.RegisterSource("contentSettings", |
| 475 IDR_CONTENT_SETTINGS_CUSTOM_BINDINGS_JS); | 400 IDR_CONTENT_SETTINGS_CUSTOM_BINDINGS_JS); |
| 476 source_map_.RegisterSource("contextMenus", | 401 source_map_.RegisterSource("contextMenus", |
| 477 IDR_CONTEXT_MENUS_CUSTOM_BINDINGS_JS); | 402 IDR_CONTEXT_MENUS_CUSTOM_BINDINGS_JS); |
| 478 source_map_.RegisterSource("devtools", IDR_DEVTOOLS_CUSTOM_BINDINGS_JS); | 403 source_map_.RegisterSource("devtools", IDR_DEVTOOLS_CUSTOM_BINDINGS_JS); |
| 479 source_map_.RegisterSource("experimental.declarative", | 404 source_map_.RegisterSource("experimental.declarative", |
| (...skipping 22 matching lines...) Expand all Loading... |
| 502 } | 427 } |
| 503 | 428 |
| 504 void ExtensionDispatcher::DidCreateScriptContext( | 429 void ExtensionDispatcher::DidCreateScriptContext( |
| 505 WebFrame* frame, v8::Handle<v8::Context> v8_context, int extension_group, | 430 WebFrame* frame, v8::Handle<v8::Context> v8_context, int extension_group, |
| 506 int world_id) { | 431 int world_id) { |
| 507 // TODO(koz): If the caller didn't pass extension_group, use the last value. | 432 // TODO(koz): If the caller didn't pass extension_group, use the last value. |
| 508 if (extension_group == -1) | 433 if (extension_group == -1) |
| 509 extension_group = g_hack_extension_group; | 434 extension_group = g_hack_extension_group; |
| 510 | 435 |
| 511 std::string extension_id = GetExtensionID(frame, world_id); | 436 std::string extension_id = GetExtensionID(frame, world_id); |
| 437 ExtensionURLInfo url_info(frame->document().securityOrigin(), |
| 438 UserScriptSlave::GetDataSourceURLForFrame(frame)); |
| 439 Feature::Context context_type = |
| 440 ClassifyJavaScriptContext(extension_id, extension_group, url_info); |
| 441 |
| 512 ChromeV8Context* context = | 442 ChromeV8Context* context = |
| 513 new ChromeV8Context( | 443 new ChromeV8Context(v8_context, frame, extension_id, context_type); |
| 514 v8_context, | |
| 515 frame, | |
| 516 extension_id, | |
| 517 ExtensionGroupToContextType(extension_group)); | |
| 518 v8_context_set_.Add(context); | 444 v8_context_set_.Add(context); |
| 519 | 445 |
| 520 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(&source_map_)); | 446 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(&source_map_)); |
| 521 RegisterNativeHandlers(module_system.get(), context); | 447 RegisterNativeHandlers(module_system.get(), context); |
| 522 | 448 |
| 523 bool is_bindings_allowed = | |
| 524 IsTestExtensionId(extension_id) || | |
| 525 context->context_type() == ChromeV8Context::CONTENT_SCRIPT || | |
| 526 extensions_.ExtensionBindingsAllowed(ExtensionURLInfo( | |
| 527 frame->document().securityOrigin(), | |
| 528 UserScriptSlave::GetDataSourceURLForFrame(frame))); | |
| 529 | |
| 530 module_system->RegisterNativeHandler("chrome_hidden", | 449 module_system->RegisterNativeHandler("chrome_hidden", |
| 531 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); | 450 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); |
| 532 module_system->RegisterNativeHandler("context_info", | |
| 533 scoped_ptr<NativeHandler>(new ContextInfoNativeHandler( | |
| 534 this, | |
| 535 is_bindings_allowed, | |
| 536 frame, | |
| 537 world_id))); | |
| 538 module_system->RegisterNativeHandler("print", | 451 module_system->RegisterNativeHandler("print", |
| 539 scoped_ptr<NativeHandler>(new PrintNativeHandler())); | 452 scoped_ptr<NativeHandler>(new PrintNativeHandler())); |
| 540 | 453 |
| 541 const Extension* extension = extensions_.GetByID(context->extension_id()); | |
| 542 int manifest_version = 1; | 454 int manifest_version = 1; |
| 543 if (extension) | 455 { |
| 544 manifest_version = extension->manifest_version(); | 456 const Extension* extension = extensions_.GetByID(extension_id); |
| 457 if (extension) |
| 458 manifest_version = extension->manifest_version(); |
| 459 } |
| 545 | 460 |
| 546 // Create the 'chrome' variable if it doesn't already exist. | 461 // Create the 'chrome' variable if it doesn't already exist. |
| 547 { | 462 { |
| 548 v8::HandleScope handle_scope; | 463 v8::HandleScope handle_scope; |
| 549 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); | 464 v8::Handle<v8::String> chrome_string(v8::String::New("chrome")); |
| 550 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global()); | 465 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global()); |
| 551 if (global->Get(chrome_string)->IsUndefined()) | 466 if (global->Get(chrome_string)->IsUndefined()) |
| 552 global->Set(chrome_string, v8::Object::New()); | 467 global->Set(chrome_string, v8::Object::New()); |
| 553 } | 468 } |
| 554 module_system->Require("app"); | |
| 555 module_system->Require("webstore"); | 469 module_system->Require("webstore"); |
| 556 if (is_bindings_allowed) { | 470 module_system->Require("setup_bindings"); |
| 557 module_system->Require("setup_bindings"); | |
| 558 } | |
| 559 module_system->set_natives_enabled(false); | 471 module_system->set_natives_enabled(false); |
| 560 | 472 |
| 561 context->set_module_system(module_system.Pass()); | 473 context->set_module_system(module_system.Pass()); |
| 562 | 474 |
| 563 context->DispatchOnLoadEvent( | 475 context->DispatchOnLoadEvent( |
| 564 is_extension_process_, | 476 is_extension_process_, |
| 565 ChromeRenderProcessObserver::is_incognito_process(), | 477 ChromeRenderProcessObserver::is_incognito_process(), |
| 566 manifest_version); | 478 manifest_version); |
| 567 | 479 |
| 568 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); | 480 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 588 if (!context) | 500 if (!context) |
| 589 return; | 501 return; |
| 590 | 502 |
| 591 context->DispatchOnUnloadEvent(); | 503 context->DispatchOnUnloadEvent(); |
| 592 | 504 |
| 593 v8_context_set_.Remove(context); | 505 v8_context_set_.Remove(context); |
| 594 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); | 506 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); |
| 595 } | 507 } |
| 596 | 508 |
| 597 void ExtensionDispatcher::SetTestExtensionId(const std::string& id) { | 509 void ExtensionDispatcher::SetTestExtensionId(const std::string& id) { |
| 510 CHECK(!id.empty()); |
| 598 test_extension_id_ = id; | 511 test_extension_id_ = id; |
| 599 } | 512 } |
| 600 | 513 |
| 601 bool ExtensionDispatcher::IsTestExtensionId(const std::string& id) { | 514 bool ExtensionDispatcher::IsTestExtensionId(const std::string& id) { |
| 602 return !test_extension_id_.empty() && id == test_extension_id_; | 515 return !test_extension_id_.empty() && id == test_extension_id_; |
| 603 } | 516 } |
| 604 | 517 |
| 605 void ExtensionDispatcher::OnActivateApplication( | |
| 606 const std::string& extension_id) { | |
| 607 active_application_ids_.insert(extension_id); | |
| 608 } | |
| 609 | |
| 610 void ExtensionDispatcher::OnActivateExtension( | 518 void ExtensionDispatcher::OnActivateExtension( |
| 611 const std::string& extension_id) { | 519 const std::string& extension_id) { |
| 612 active_extension_ids_.insert(extension_id); | 520 active_extension_ids_.insert(extension_id); |
| 613 | 521 |
| 614 // This is called when starting a new extension page, so start the idle | 522 // This is called when starting a new extension page, so start the idle |
| 615 // handler ticking. | 523 // handler ticking. |
| 616 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); | 524 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); |
| 617 | 525 |
| 618 UpdateActiveExtensions(); | 526 UpdateActiveExtensions(); |
| 619 | 527 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 webrequest_adblock_ = adblock; | 635 webrequest_adblock_ = adblock; |
| 728 webrequest_adblock_plus_ = adblock_plus; | 636 webrequest_adblock_plus_ = adblock_plus; |
| 729 webrequest_other_ = other; | 637 webrequest_other_ = other; |
| 730 } | 638 } |
| 731 | 639 |
| 732 void ExtensionDispatcher::OnShouldClose(const std::string& extension_id, | 640 void ExtensionDispatcher::OnShouldClose(const std::string& extension_id, |
| 733 int sequence_id) { | 641 int sequence_id) { |
| 734 RenderThread::Get()->Send( | 642 RenderThread::Get()->Send( |
| 735 new ExtensionHostMsg_ShouldCloseAck(extension_id, sequence_id)); | 643 new ExtensionHostMsg_ShouldCloseAck(extension_id, sequence_id)); |
| 736 } | 644 } |
| 645 |
| 646 Feature::Context ExtensionDispatcher::ClassifyJavaScriptContext( |
| 647 const std::string& extension_id, |
| 648 int extension_group, |
| 649 const ExtensionURLInfo& url_info) { |
| 650 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) |
| 651 return Feature::CONTENT_SCRIPT_CONTEXT; |
| 652 |
| 653 if (IsExtensionActive(extension_id)) |
| 654 return Feature::PRIVILEGED_CONTEXT; |
| 655 |
| 656 if (extensions_.ExtensionBindingsAllowed(url_info)) |
| 657 return Feature::UNPRIVILEGED_CONTEXT; |
| 658 |
| 659 if (url_info.url().is_valid()) |
| 660 return Feature::WEB_PAGE_CONTEXT; |
| 661 |
| 662 return Feature::UNSPECIFIED_CONTEXT; |
| 663 } |
| OLD | NEW |