| 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/chrome_private_custom_bindings.h" | 21 #include "chrome/renderer/extensions/custom_bindings_util.h" |
| 22 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" | |
| 23 #include "chrome/renderer/extensions/event_bindings.h" | 22 #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" | |
| 26 #include "chrome/renderer/extensions/extension_groups.h" | 23 #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" | |
| 30 #include "chrome/renderer/extensions/miscellaneous_bindings.h" | 24 #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" | |
| 33 #include "chrome/renderer/extensions/schema_generated_bindings.h" | 25 #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" | |
| 36 #include "chrome/renderer/extensions/user_script_slave.h" | 26 #include "chrome/renderer/extensions/user_script_slave.h" |
| 37 #include "chrome/renderer/extensions/web_request_custom_bindings.h" | |
| 38 #include "chrome/renderer/extensions/webstore_bindings.h" | 27 #include "chrome/renderer/extensions/webstore_bindings.h" |
| 39 #include "chrome/renderer/module_system.h" | 28 #include "chrome/renderer/module_system.h" |
| 40 #include "chrome/renderer/native_handler.h" | 29 #include "chrome/renderer/native_handler.h" |
| 41 #include "chrome/renderer/resource_bundle_source_map.h" | 30 #include "chrome/renderer/resource_bundle_source_map.h" |
| 42 #include "content/public/renderer/render_thread.h" | 31 #include "content/public/renderer/render_thread.h" |
| 43 #include "grit/renderer_resources.h" | 32 #include "grit/renderer_resources.h" |
| 44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedUserGesture.
h" | |
| 48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h" |
| 49 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | |
| 50 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 37 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 51 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" | 38 #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" |
| 52 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
| 53 #include "v8/include/v8.h" | 42 #include "v8/include/v8.h" |
| 54 | 43 |
| 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 |
| 55 namespace { | 57 namespace { |
| 56 | 58 |
| 57 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; | 59 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; |
| 58 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; | 60 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; |
| 59 | 61 |
| 62 ChromeV8Context::ContextType ExtensionGroupToContextType(int extension_group) { |
| 63 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) |
| 64 return ChromeV8Context::CONTENT_SCRIPT; |
| 65 return ChromeV8Context::OTHER; |
| 66 } |
| 67 |
| 60 class ChromeHiddenNativeHandler : public NativeHandler { | 68 class ChromeHiddenNativeHandler : public NativeHandler { |
| 61 public: | 69 public: |
| 62 ChromeHiddenNativeHandler() { | 70 ChromeHiddenNativeHandler() { |
| 63 RouteFunction("GetChromeHidden", | 71 RouteFunction("GetChromeHidden", |
| 64 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, | 72 base::Bind(&ChromeHiddenNativeHandler::GetChromeHidden, |
| 65 base::Unretained(this))); | 73 base::Unretained(this))); |
| 66 } | 74 } |
| 67 | 75 |
| 68 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) { | 76 v8::Handle<v8::Value> GetChromeHidden(const v8::Arguments& args) { |
| 69 return ChromeV8Context::GetOrCreateChromeHidden(v8::Context::GetCurrent()); | 77 return ChromeV8Context::GetOrCreateChromeHidden(v8::Context::GetCurrent()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 84 | 92 |
| 85 std::vector<std::string> components; | 93 std::vector<std::string> components; |
| 86 for (int i = 0; i < args.Length(); ++i) | 94 for (int i = 0; i < args.Length(); ++i) |
| 87 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); | 95 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); |
| 88 | 96 |
| 89 LOG(ERROR) << JoinString(components, ','); | 97 LOG(ERROR) << JoinString(components, ','); |
| 90 return v8::Undefined(); | 98 return v8::Undefined(); |
| 91 } | 99 } |
| 92 }; | 100 }; |
| 93 | 101 |
| 102 class ContextInfoNativeHandler : public NativeHandler { |
| 103 public: |
| 104 explicit ContextInfoNativeHandler(ExtensionDispatcher* extension_dispatcher, |
| 105 bool is_bindings_allowed, |
| 106 WebKit::WebFrame* frame, |
| 107 int world_id) |
| 108 : extension_dispatcher_(extension_dispatcher), |
| 109 is_bindings_allowed_(is_bindings_allowed), |
| 110 frame_(frame), |
| 111 world_id_(world_id) { |
| 112 RouteFunction("IsBindingsAllowed", |
| 113 base::Bind(&ContextInfoNativeHandler::IsBindingsAllowed, |
| 114 base::Unretained(this))); |
| 115 RouteFunction("IsAPIAllowed", |
| 116 base::Bind(&ContextInfoNativeHandler::IsAPIAllowed, |
| 117 base::Unretained(this))); |
| 118 } |
| 119 |
| 120 v8::Handle<v8::Value> IsBindingsAllowed(const v8::Arguments& args) { |
| 121 return v8::Boolean::New(is_bindings_allowed_); |
| 122 } |
| 123 |
| 124 v8::Handle<v8::Value> IsAPIAllowed(const v8::Arguments& args) { |
| 125 std::string custom_api_name = *v8::String::AsciiValue(args[0]->ToString()); |
| 126 return v8::Boolean::New(extension_dispatcher_->AllowCustomAPI( |
| 127 frame_, custom_api_name, world_id_)); |
| 128 } |
| 129 |
| 130 private: |
| 131 ExtensionDispatcher* extension_dispatcher_; |
| 132 bool is_bindings_allowed_; |
| 133 WebKit::WebFrame* frame_; |
| 134 int world_id_; |
| 135 }; |
| 136 |
| 94 } | 137 } |
| 95 | 138 |
| 96 using namespace extensions; | 139 using namespace extensions; |
| 97 | 140 |
| 98 using WebKit::WebDataSource; | 141 using WebKit::WebDataSource; |
| 99 using WebKit::WebDocument; | 142 using WebKit::WebDocument; |
| 100 using WebKit::WebFrame; | 143 using WebKit::WebFrame; |
| 101 using WebKit::WebSecurityPolicy; | 144 using WebKit::WebSecurityPolicy; |
| 102 using WebKit::WebString; | 145 using WebKit::WebString; |
| 103 using WebKit::WebScopedUserGesture; | 146 using WebKit::WebScopedUserGesture; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 133 bool handled = true; | 176 bool handled = true; |
| 134 IPC_BEGIN_MESSAGE_MAP(ExtensionDispatcher, message) | 177 IPC_BEGIN_MESSAGE_MAP(ExtensionDispatcher, message) |
| 135 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) | 178 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) |
| 136 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) | 179 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) |
| 137 IPC_MESSAGE_HANDLER(ExtensionMsg_SetFunctionNames, OnSetFunctionNames) | 180 IPC_MESSAGE_HANDLER(ExtensionMsg_SetFunctionNames, OnSetFunctionNames) |
| 138 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) | 181 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) |
| 139 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) | 182 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) |
| 140 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, | 183 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, |
| 141 OnSetScriptingWhitelist) | 184 OnSetScriptingWhitelist) |
| 142 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) | 185 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) |
| 186 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateApplication, OnActivateApplication) |
| 143 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) | 187 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) |
| 144 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) | 188 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) |
| 145 IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI) | 189 IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI) |
| 146 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldClose, OnShouldClose) | 190 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldClose, OnShouldClose) |
| 147 IPC_MESSAGE_UNHANDLED(handled = false) | 191 IPC_MESSAGE_UNHANDLED(handled = false) |
| 148 IPC_END_MESSAGE_MAP() | 192 IPC_END_MESSAGE_MAP() |
| 149 | 193 |
| 150 return handled; | 194 return handled; |
| 151 } | 195 } |
| 152 | 196 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 // We don't do anything with existing platform-app stylesheets. They will | 326 // We don't do anything with existing platform-app stylesheets. They will |
| 283 // stay resident, but the URL pattern corresponding to the unloaded | 327 // stay resident, but the URL pattern corresponding to the unloaded |
| 284 // extension's URL just won't match anything anymore. | 328 // extension's URL just won't match anything anymore. |
| 285 } | 329 } |
| 286 | 330 |
| 287 void ExtensionDispatcher::OnSetScriptingWhitelist( | 331 void ExtensionDispatcher::OnSetScriptingWhitelist( |
| 288 const Extension::ScriptingWhitelist& extension_ids) { | 332 const Extension::ScriptingWhitelist& extension_ids) { |
| 289 Extension::SetScriptingWhitelist(extension_ids); | 333 Extension::SetScriptingWhitelist(extension_ids); |
| 290 } | 334 } |
| 291 | 335 |
| 336 bool ExtensionDispatcher::IsApplicationActive( |
| 337 const std::string& extension_id) const { |
| 338 return active_application_ids_.find(extension_id) != |
| 339 active_application_ids_.end(); |
| 340 } |
| 341 |
| 292 bool ExtensionDispatcher::IsExtensionActive( | 342 bool ExtensionDispatcher::IsExtensionActive( |
| 293 const std::string& extension_id) const { | 343 const std::string& extension_id) const { |
| 294 return active_extension_ids_.find(extension_id) != | 344 return active_extension_ids_.find(extension_id) != |
| 295 active_extension_ids_.end(); | 345 active_extension_ids_.end(); |
| 296 } | 346 } |
| 297 | 347 |
| 298 bool ExtensionDispatcher::AllowScriptExtension( | 348 bool ExtensionDispatcher::AllowScriptExtension( |
| 299 WebFrame* frame, | 349 WebFrame* frame, |
| 300 const std::string& v8_extension_name, | 350 const std::string& v8_extension_name, |
| 301 int extension_group) { | 351 int extension_group) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 316 | 366 |
| 317 bool ExtensionDispatcher::AllowScriptExtension( | 367 bool ExtensionDispatcher::AllowScriptExtension( |
| 318 WebFrame* frame, | 368 WebFrame* frame, |
| 319 const std::string& v8_extension_name, | 369 const std::string& v8_extension_name, |
| 320 int extension_group, | 370 int extension_group, |
| 321 int world_id) { | 371 int world_id) { |
| 322 g_hack_extension_group = extension_group; | 372 g_hack_extension_group = extension_group; |
| 323 return true; | 373 return true; |
| 324 } | 374 } |
| 325 | 375 |
| 376 bool ExtensionDispatcher::AllowCustomAPI( |
| 377 WebFrame* frame, |
| 378 const std::string& custom_binding_api_name, |
| 379 int world_id) { |
| 380 std::string extension_id = GetExtensionID(frame, world_id); |
| 381 if (test_extension_id_ == extension_id) |
| 382 return true; |
| 383 const Extension* extension = extensions_.GetByID(extension_id); |
| 384 if (!extension) { |
| 385 // This can happen when a resource is blocked due to CSP; a valid |
| 386 // chrome-extension:// URL is navigated to, so it passes the initial |
| 387 // checks, but the URL gets changed to "chrome-extension://invalid" |
| 388 // afterwards (see chrome_content_renderer_client.cc). An extension |
| 389 // page still gets loaded, just for the extension with ID "invalid", |
| 390 // which of course isn't found so GetById extension will be NULL. |
| 391 // |
| 392 // Reference: http://crbug.com/111614. |
| 393 CHECK_EQ("invalid", extension_id); |
| 394 return false; |
| 395 } |
| 396 return custom_bindings_util::AllowAPIInjection( |
| 397 custom_binding_api_name, *extension, this); |
| 398 } |
| 399 |
| 326 void ExtensionDispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 400 void ExtensionDispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
| 327 ChromeV8Context* context) { | 401 ChromeV8Context* context) { |
| 402 module_system->RegisterNativeHandler("app", |
| 403 scoped_ptr<NativeHandler>(new AppBindings(this, context))); |
| 328 module_system->RegisterNativeHandler("webstore", | 404 module_system->RegisterNativeHandler("webstore", |
| 329 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); | 405 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); |
| 330 module_system->RegisterNativeHandler("event_bindings", | 406 module_system->RegisterNativeHandler("event_bindings", |
| 331 scoped_ptr<NativeHandler>(EventBindings::Get(this))); | 407 scoped_ptr<NativeHandler>(EventBindings::Get(this))); |
| 332 module_system->RegisterNativeHandler("miscellaneous_bindings", | 408 module_system->RegisterNativeHandler("miscellaneous_bindings", |
| 333 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); | 409 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); |
| 334 module_system->RegisterNativeHandler("schema_generated_bindings", | 410 module_system->RegisterNativeHandler("schema_generated_bindings", |
| 335 scoped_ptr<NativeHandler>(SchemaGeneratedBindings::Get(this))); | 411 scoped_ptr<NativeHandler>(SchemaGeneratedBindings::Get(this))); |
| 336 | 412 |
| 337 // Custom bindings. | 413 // Custom bindings. |
| 338 module_system->RegisterNativeHandler("app", | |
| 339 scoped_ptr<NativeHandler>(new AppBindings(this, context))); | |
| 340 module_system->RegisterNativeHandler("chrome_private", | 414 module_system->RegisterNativeHandler("chrome_private", |
| 341 scoped_ptr<NativeHandler>( | 415 scoped_ptr<NativeHandler>( |
| 342 new ChromePrivateCustomBindings(this))); | 416 new ChromePrivateCustomBindings(this))); |
| 343 module_system->RegisterNativeHandler("context_menus", | 417 module_system->RegisterNativeHandler("context_menus", |
| 344 scoped_ptr<NativeHandler>(new ContextMenusCustomBindings())); | 418 scoped_ptr<NativeHandler>(new ContextMenusCustomBindings())); |
| 345 module_system->RegisterNativeHandler("extension", | 419 module_system->RegisterNativeHandler("extension", |
| 346 scoped_ptr<NativeHandler>( | 420 scoped_ptr<NativeHandler>( |
| 347 new ExtensionCustomBindings(this))); | 421 new ExtensionCustomBindings(this))); |
| 348 module_system->RegisterNativeHandler("experimental_socket", | 422 module_system->RegisterNativeHandler("experimental_socket", |
| 349 scoped_ptr<NativeHandler>(new ExperimentalSocketCustomBindings())); | 423 scoped_ptr<NativeHandler>(new ExperimentalSocketCustomBindings())); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 360 scoped_ptr<NativeHandler>(new PageCaptureCustomBindings())); | 434 scoped_ptr<NativeHandler>(new PageCaptureCustomBindings())); |
| 361 module_system->RegisterNativeHandler("tabs", | 435 module_system->RegisterNativeHandler("tabs", |
| 362 scoped_ptr<NativeHandler>(new TabsCustomBindings())); | 436 scoped_ptr<NativeHandler>(new TabsCustomBindings())); |
| 363 module_system->RegisterNativeHandler("tts", | 437 module_system->RegisterNativeHandler("tts", |
| 364 scoped_ptr<NativeHandler>(new TTSCustomBindings())); | 438 scoped_ptr<NativeHandler>(new TTSCustomBindings())); |
| 365 module_system->RegisterNativeHandler("web_request", | 439 module_system->RegisterNativeHandler("web_request", |
| 366 scoped_ptr<NativeHandler>(new WebRequestCustomBindings())); | 440 scoped_ptr<NativeHandler>(new WebRequestCustomBindings())); |
| 367 } | 441 } |
| 368 | 442 |
| 369 void ExtensionDispatcher::PopulateSourceMap() { | 443 void ExtensionDispatcher::PopulateSourceMap() { |
| 444 source_map_.RegisterSource("app", IDR_APP_BINDINGS_JS); |
| 370 source_map_.RegisterSource("webstore", IDR_WEBSTORE_BINDINGS_JS); | 445 source_map_.RegisterSource("webstore", IDR_WEBSTORE_BINDINGS_JS); |
| 371 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); | 446 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); |
| 372 source_map_.RegisterSource("miscellaneous_bindings", | 447 source_map_.RegisterSource("miscellaneous_bindings", |
| 373 IDR_MISCELLANEOUS_BINDINGS_JS); | 448 IDR_MISCELLANEOUS_BINDINGS_JS); |
| 374 source_map_.RegisterSource("schema_generated_bindings", | 449 source_map_.RegisterSource("schema_generated_bindings", |
| 375 IDR_SCHEMA_GENERATED_BINDINGS_JS); | 450 IDR_SCHEMA_GENERATED_BINDINGS_JS); |
| 376 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); | 451 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); |
| 377 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS); | 452 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS); |
| 378 source_map_.RegisterSource("setup_bindings", IDR_SETUP_BINDINGS_JS); | 453 source_map_.RegisterSource("setup_bindings", IDR_SETUP_BINDINGS_JS); |
| 379 | 454 |
| 380 // Custom bindings. | 455 // Custom bindings. |
| 381 source_map_.RegisterSource("app", IDR_APP_CUSTOM_BINDINGS_JS); | |
| 382 source_map_.RegisterSource("browserAction", | 456 source_map_.RegisterSource("browserAction", |
| 383 IDR_BROWSER_ACTION_CUSTOM_BINDINGS_JS); | 457 IDR_BROWSER_ACTION_CUSTOM_BINDINGS_JS); |
| 384 source_map_.RegisterSource("chromePrivate", | 458 source_map_.RegisterSource("chromePrivate", |
| 385 IDR_CHROME_PRIVATE_CUSTOM_BINDINGS_JS); | 459 IDR_CHROME_PRIVATE_CUSTOM_BINDINGS_JS); |
| 386 source_map_.RegisterSource("contentSettings", | 460 source_map_.RegisterSource("contentSettings", |
| 387 IDR_CONTENT_SETTINGS_CUSTOM_BINDINGS_JS); | 461 IDR_CONTENT_SETTINGS_CUSTOM_BINDINGS_JS); |
| 388 source_map_.RegisterSource("contextMenus", | 462 source_map_.RegisterSource("contextMenus", |
| 389 IDR_CONTEXT_MENUS_CUSTOM_BINDINGS_JS); | 463 IDR_CONTEXT_MENUS_CUSTOM_BINDINGS_JS); |
| 390 source_map_.RegisterSource("devtools", IDR_DEVTOOLS_CUSTOM_BINDINGS_JS); | 464 source_map_.RegisterSource("devtools", IDR_DEVTOOLS_CUSTOM_BINDINGS_JS); |
| 391 source_map_.RegisterSource("experimental.declarative", | 465 source_map_.RegisterSource("experimental.declarative", |
| (...skipping 22 matching lines...) Expand all Loading... |
| 414 } | 488 } |
| 415 | 489 |
| 416 void ExtensionDispatcher::DidCreateScriptContext( | 490 void ExtensionDispatcher::DidCreateScriptContext( |
| 417 WebFrame* frame, v8::Handle<v8::Context> v8_context, int extension_group, | 491 WebFrame* frame, v8::Handle<v8::Context> v8_context, int extension_group, |
| 418 int world_id) { | 492 int world_id) { |
| 419 // TODO(koz): If the caller didn't pass extension_group, use the last value. | 493 // TODO(koz): If the caller didn't pass extension_group, use the last value. |
| 420 if (extension_group == -1) | 494 if (extension_group == -1) |
| 421 extension_group = g_hack_extension_group; | 495 extension_group = g_hack_extension_group; |
| 422 | 496 |
| 423 std::string extension_id = GetExtensionID(frame, world_id); | 497 std::string extension_id = GetExtensionID(frame, world_id); |
| 424 ExtensionURLInfo url_info(frame->document().securityOrigin(), | |
| 425 UserScriptSlave::GetDataSourceURLForFrame(frame)); | |
| 426 Feature::Context context_type = | |
| 427 ClassifyJavaScriptContext(extension_id, extension_group, url_info); | |
| 428 | |
| 429 ChromeV8Context* context = | 498 ChromeV8Context* context = |
| 430 new ChromeV8Context(v8_context, frame, extension_id, context_type); | 499 new ChromeV8Context( |
| 500 v8_context, |
| 501 frame, |
| 502 extension_id, |
| 503 ExtensionGroupToContextType(extension_group)); |
| 431 v8_context_set_.Add(context); | 504 v8_context_set_.Add(context); |
| 432 | 505 |
| 433 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(&source_map_)); | 506 scoped_ptr<ModuleSystem> module_system(new ModuleSystem(&source_map_)); |
| 434 RegisterNativeHandlers(module_system.get(), context); | 507 RegisterNativeHandlers(module_system.get(), context); |
| 435 | 508 |
| 509 bool is_bindings_allowed = |
| 510 IsTestExtensionId(extension_id) || |
| 511 context->context_type() == ChromeV8Context::CONTENT_SCRIPT || |
| 512 extensions_.ExtensionBindingsAllowed(ExtensionURLInfo( |
| 513 frame->document().securityOrigin(), |
| 514 UserScriptSlave::GetDataSourceURLForFrame(frame))); |
| 515 |
| 436 module_system->RegisterNativeHandler("chrome_hidden", | 516 module_system->RegisterNativeHandler("chrome_hidden", |
| 437 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); | 517 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); |
| 518 module_system->RegisterNativeHandler("context_info", |
| 519 scoped_ptr<NativeHandler>(new ContextInfoNativeHandler( |
| 520 this, |
| 521 is_bindings_allowed, |
| 522 frame, |
| 523 world_id))); |
| 438 module_system->RegisterNativeHandler("print", | 524 module_system->RegisterNativeHandler("print", |
| 439 scoped_ptr<NativeHandler>(new PrintNativeHandler())); | 525 scoped_ptr<NativeHandler>(new PrintNativeHandler())); |
| 440 | 526 |
| 527 const Extension* extension = extensions_.GetByID(context->extension_id()); |
| 441 int manifest_version = 1; | 528 int manifest_version = 1; |
| 442 { | 529 if (extension) |
| 443 const Extension* extension = extensions_.GetByID(extension_id); | 530 manifest_version = extension->manifest_version(); |
| 444 if (extension) | |
| 445 manifest_version = extension->manifest_version(); | |
| 446 } | |
| 447 | 531 |
| 448 module_system->RunString("var chrome; chrome = chrome || {};", | 532 module_system->RunString("var chrome; chrome = chrome || {};", |
| 449 "setup-chrome-object"); | 533 "setup-chrome-object"); |
| 450 module_system->Require("setup_bindings"); | 534 module_system->Require("setup_bindings"); |
| 451 module_system->set_natives_enabled(false); | 535 module_system->set_natives_enabled(false); |
| 452 | 536 |
| 453 context->set_module_system(module_system.Pass()); | 537 context->set_module_system(module_system.Pass()); |
| 454 | 538 |
| 455 context->DispatchOnLoadEvent( | 539 context->DispatchOnLoadEvent( |
| 456 is_extension_process_, | 540 is_extension_process_, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 480 if (!context) | 564 if (!context) |
| 481 return; | 565 return; |
| 482 | 566 |
| 483 context->DispatchOnUnloadEvent(); | 567 context->DispatchOnUnloadEvent(); |
| 484 | 568 |
| 485 v8_context_set_.Remove(context); | 569 v8_context_set_.Remove(context); |
| 486 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); | 570 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); |
| 487 } | 571 } |
| 488 | 572 |
| 489 void ExtensionDispatcher::SetTestExtensionId(const std::string& id) { | 573 void ExtensionDispatcher::SetTestExtensionId(const std::string& id) { |
| 490 CHECK(!id.empty()); | |
| 491 test_extension_id_ = id; | 574 test_extension_id_ = id; |
| 492 } | 575 } |
| 493 | 576 |
| 494 bool ExtensionDispatcher::IsTestExtensionId(const std::string& id) { | 577 bool ExtensionDispatcher::IsTestExtensionId(const std::string& id) { |
| 495 return !test_extension_id_.empty() && id == test_extension_id_; | 578 return !test_extension_id_.empty() && id == test_extension_id_; |
| 496 } | 579 } |
| 497 | 580 |
| 581 void ExtensionDispatcher::OnActivateApplication( |
| 582 const std::string& extension_id) { |
| 583 active_application_ids_.insert(extension_id); |
| 584 } |
| 585 |
| 498 void ExtensionDispatcher::OnActivateExtension( | 586 void ExtensionDispatcher::OnActivateExtension( |
| 499 const std::string& extension_id) { | 587 const std::string& extension_id) { |
| 500 active_extension_ids_.insert(extension_id); | 588 active_extension_ids_.insert(extension_id); |
| 501 | 589 |
| 502 // This is called when starting a new extension page, so start the idle | 590 // This is called when starting a new extension page, so start the idle |
| 503 // handler ticking. | 591 // handler ticking. |
| 504 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); | 592 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); |
| 505 | 593 |
| 506 UpdateActiveExtensions(); | 594 UpdateActiveExtensions(); |
| 507 | 595 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 webrequest_adblock_ = adblock; | 703 webrequest_adblock_ = adblock; |
| 616 webrequest_adblock_plus_ = adblock_plus; | 704 webrequest_adblock_plus_ = adblock_plus; |
| 617 webrequest_other_ = other; | 705 webrequest_other_ = other; |
| 618 } | 706 } |
| 619 | 707 |
| 620 void ExtensionDispatcher::OnShouldClose(const std::string& extension_id, | 708 void ExtensionDispatcher::OnShouldClose(const std::string& extension_id, |
| 621 int sequence_id) { | 709 int sequence_id) { |
| 622 RenderThread::Get()->Send( | 710 RenderThread::Get()->Send( |
| 623 new ExtensionHostMsg_ShouldCloseAck(extension_id, sequence_id)); | 711 new ExtensionHostMsg_ShouldCloseAck(extension_id, sequence_id)); |
| 624 } | 712 } |
| 625 | |
| 626 Feature::Context ExtensionDispatcher::ClassifyJavaScriptContext( | |
| 627 const std::string& extension_id, | |
| 628 int extension_group, | |
| 629 const ExtensionURLInfo& url_info) { | |
| 630 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) | |
| 631 return Feature::CONTENT_SCRIPT_CONTEXT; | |
| 632 | |
| 633 if (IsExtensionActive(extension_id)) | |
| 634 return Feature::PRIVILEGED_CONTEXT; | |
| 635 | |
| 636 if (extensions_.ExtensionBindingsAllowed(url_info)) | |
| 637 return Feature::UNPRIVILEGED_CONTEXT; | |
| 638 | |
| 639 if (url_info.url().is_valid()) | |
| 640 return Feature::WEB_PAGE_CONTEXT; | |
| 641 | |
| 642 return Feature::UNSPECIFIED_CONTEXT; | |
| 643 } | |
| OLD | NEW |