Chromium Code Reviews| 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/api/extension_api.h" | |
| 13 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 14 #include "chrome/common/extensions/extension_messages.h" | 15 #include "chrome/common/extensions/extension_messages.h" |
| 15 #include "chrome/common/extensions/extension_permission_set.h" | 16 #include "chrome/common/extensions/extension_permission_set.h" |
| 16 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 17 #include "chrome/renderer/chrome_render_process_observer.h" | 18 #include "chrome/renderer/chrome_render_process_observer.h" |
| 18 #include "chrome/renderer/extensions/app_bindings.h" | 19 #include "chrome/renderer/extensions/app_bindings.h" |
| 20 #include "chrome/renderer/extensions/chrome_private_custom_bindings.h" | |
| 19 #include "chrome/renderer/extensions/chrome_v8_context.h" | 21 #include "chrome/renderer/extensions/chrome_v8_context.h" |
| 20 #include "chrome/renderer/extensions/chrome_v8_extension.h" | 22 #include "chrome/renderer/extensions/chrome_v8_extension.h" |
| 21 #include "chrome/renderer/extensions/custom_bindings_util.h" | 23 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" |
| 22 #include "chrome/renderer/extensions/event_bindings.h" | 24 #include "chrome/renderer/extensions/event_bindings.h" |
| 25 #include "chrome/renderer/extensions/experimental.socket_custom_bindings.h" | |
| 26 #include "chrome/renderer/extensions/extension_custom_bindings.h" | |
| 23 #include "chrome/renderer/extensions/extension_groups.h" | 27 #include "chrome/renderer/extensions/extension_groups.h" |
| 28 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" | |
| 29 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" | |
| 30 #include "chrome/renderer/extensions/i18n_custom_bindings.h" | |
| 24 #include "chrome/renderer/extensions/miscellaneous_bindings.h" | 31 #include "chrome/renderer/extensions/miscellaneous_bindings.h" |
| 32 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" | |
| 33 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" | |
| 25 #include "chrome/renderer/extensions/schema_generated_bindings.h" | 34 #include "chrome/renderer/extensions/schema_generated_bindings.h" |
| 35 #include "chrome/renderer/extensions/tabs_custom_bindings.h" | |
| 36 #include "chrome/renderer/extensions/tts_custom_bindings.h" | |
| 26 #include "chrome/renderer/extensions/user_script_slave.h" | 37 #include "chrome/renderer/extensions/user_script_slave.h" |
| 38 #include "chrome/renderer/extensions/web_request_custom_bindings.h" | |
| 27 #include "chrome/renderer/extensions/webstore_bindings.h" | 39 #include "chrome/renderer/extensions/webstore_bindings.h" |
| 28 #include "chrome/renderer/module_system.h" | 40 #include "chrome/renderer/module_system.h" |
| 29 #include "chrome/renderer/native_handler.h" | 41 #include "chrome/renderer/native_handler.h" |
| 30 #include "chrome/renderer/resource_bundle_source_map.h" | 42 #include "chrome/renderer/resource_bundle_source_map.h" |
| 31 #include "content/public/renderer/render_thread.h" | 43 #include "content/public/renderer/render_thread.h" |
| 32 #include "grit/renderer_resources.h" | 44 #include "grit/renderer_resources.h" |
| 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" | 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.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/WebView.h" | |
| 40 #include "ui/base/resource/resource_bundle.h" | 52 #include "ui/base/resource/resource_bundle.h" |
| 41 #include "v8/include/v8.h" | 53 #include "v8/include/v8.h" |
| 42 | 54 |
| 43 #include "chrome/renderer/extensions/chrome_private_custom_bindings.h" | |
| 44 #include "chrome/renderer/extensions/context_menus_custom_bindings.h" | |
| 45 #include "chrome/renderer/extensions/experimental.socket_custom_bindings.h" | |
| 46 #include "chrome/renderer/extensions/extension_custom_bindings.h" | |
| 47 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" | |
| 48 #include "chrome/renderer/extensions/file_browser_private_custom_bindings.h" | |
| 49 #include "chrome/renderer/extensions/i18n_custom_bindings.h" | |
| 50 #include "chrome/renderer/extensions/page_actions_custom_bindings.h" | |
| 51 #include "chrome/renderer/extensions/page_capture_custom_bindings.h" | |
| 52 #include "chrome/renderer/extensions/tabs_custom_bindings.h" | |
| 53 #include "chrome/renderer/extensions/tts_custom_bindings.h" | |
| 54 #include "chrome/renderer/extensions/web_request_custom_bindings.h" | |
| 55 | |
| 56 namespace { | 55 namespace { |
| 57 | 56 |
| 58 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; | 57 static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000; |
| 59 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; | 58 static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000; |
| 60 | 59 |
| 61 ChromeV8Context::ContextType ExtensionGroupToContextType(int extension_group) { | |
| 62 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) | |
| 63 return ChromeV8Context::CONTENT_SCRIPT; | |
| 64 return ChromeV8Context::OTHER; | |
| 65 } | |
| 66 | |
| 67 } | 60 } |
| 68 | 61 |
| 69 using namespace extensions; | 62 using namespace extensions; |
| 70 | 63 |
| 71 using WebKit::WebDataSource; | 64 using WebKit::WebDataSource; |
| 72 using WebKit::WebDocument; | 65 using WebKit::WebDocument; |
| 73 using WebKit::WebFrame; | 66 using WebKit::WebFrame; |
| 74 using WebKit::WebSecurityPolicy; | 67 using WebKit::WebSecurityPolicy; |
| 75 using WebKit::WebString; | 68 using WebKit::WebString; |
| 76 using WebKit::WebVector; | 69 using WebKit::WebVector; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 105 bool handled = true; | 98 bool handled = true; |
| 106 IPC_BEGIN_MESSAGE_MAP(ExtensionDispatcher, message) | 99 IPC_BEGIN_MESSAGE_MAP(ExtensionDispatcher, message) |
| 107 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) | 100 IPC_MESSAGE_HANDLER(ExtensionMsg_MessageInvoke, OnMessageInvoke) |
| 108 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) | 101 IPC_MESSAGE_HANDLER(ExtensionMsg_DeliverMessage, OnDeliverMessage) |
| 109 IPC_MESSAGE_HANDLER(ExtensionMsg_SetFunctionNames, OnSetFunctionNames) | 102 IPC_MESSAGE_HANDLER(ExtensionMsg_SetFunctionNames, OnSetFunctionNames) |
| 110 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) | 103 IPC_MESSAGE_HANDLER(ExtensionMsg_Loaded, OnLoaded) |
| 111 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) | 104 IPC_MESSAGE_HANDLER(ExtensionMsg_Unloaded, OnUnloaded) |
| 112 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, | 105 IPC_MESSAGE_HANDLER(ExtensionMsg_SetScriptingWhitelist, |
| 113 OnSetScriptingWhitelist) | 106 OnSetScriptingWhitelist) |
| 114 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) | 107 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateExtension, OnActivateExtension) |
| 115 IPC_MESSAGE_HANDLER(ExtensionMsg_ActivateApplication, OnActivateApplication) | |
| 116 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) | 108 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdatePermissions, OnUpdatePermissions) |
| 117 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) | 109 IPC_MESSAGE_HANDLER(ExtensionMsg_UpdateUserScripts, OnUpdateUserScripts) |
| 118 IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI) | 110 IPC_MESSAGE_HANDLER(ExtensionMsg_UsingWebRequestAPI, OnUsingWebRequestAPI) |
| 119 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldClose, OnShouldClose) | 111 IPC_MESSAGE_HANDLER(ExtensionMsg_ShouldClose, OnShouldClose) |
| 120 IPC_MESSAGE_UNHANDLED(handled = false) | 112 IPC_MESSAGE_UNHANDLED(handled = false) |
| 121 IPC_END_MESSAGE_MAP() | 113 IPC_END_MESSAGE_MAP() |
| 122 | 114 |
| 123 return handled; | 115 return handled; |
| 124 } | 116 } |
| 125 | 117 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 // We don't do anything with existing platform-app stylesheets. They will | 241 // We don't do anything with existing platform-app stylesheets. They will |
| 250 // stay resident, but the URL pattern corresponding to the unloaded | 242 // stay resident, but the URL pattern corresponding to the unloaded |
| 251 // extension's URL just won't match anything anymore. | 243 // extension's URL just won't match anything anymore. |
| 252 } | 244 } |
| 253 | 245 |
| 254 void ExtensionDispatcher::OnSetScriptingWhitelist( | 246 void ExtensionDispatcher::OnSetScriptingWhitelist( |
| 255 const Extension::ScriptingWhitelist& extension_ids) { | 247 const Extension::ScriptingWhitelist& extension_ids) { |
| 256 Extension::SetScriptingWhitelist(extension_ids); | 248 Extension::SetScriptingWhitelist(extension_ids); |
| 257 } | 249 } |
| 258 | 250 |
| 259 bool ExtensionDispatcher::IsApplicationActive( | |
| 260 const std::string& extension_id) const { | |
| 261 return active_application_ids_.find(extension_id) != | |
| 262 active_application_ids_.end(); | |
| 263 } | |
| 264 | |
| 265 bool ExtensionDispatcher::IsExtensionActive( | 251 bool ExtensionDispatcher::IsExtensionActive( |
| 266 const std::string& extension_id) const { | 252 const std::string& extension_id) const { |
| 267 return active_extension_ids_.find(extension_id) != | 253 return active_extension_ids_.find(extension_id) != |
| 268 active_extension_ids_.end(); | 254 active_extension_ids_.end(); |
| 269 } | 255 } |
| 270 | 256 |
| 271 bool ExtensionDispatcher::AllowScriptExtension( | 257 bool ExtensionDispatcher::AllowScriptExtension( |
| 272 WebFrame* frame, | 258 WebFrame* frame, |
| 273 const std::string& v8_extension_name, | 259 const std::string& v8_extension_name, |
| 274 int extension_group) { | 260 int extension_group) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 289 | 275 |
| 290 bool ExtensionDispatcher::AllowScriptExtension( | 276 bool ExtensionDispatcher::AllowScriptExtension( |
| 291 WebFrame* frame, | 277 WebFrame* frame, |
| 292 const std::string& v8_extension_name, | 278 const std::string& v8_extension_name, |
| 293 int extension_group, | 279 int extension_group, |
| 294 int world_id) { | 280 int world_id) { |
| 295 g_hack_extension_group = extension_group; | 281 g_hack_extension_group = extension_group; |
| 296 return true; | 282 return true; |
| 297 } | 283 } |
| 298 | 284 |
| 299 bool ExtensionDispatcher::AllowCustomAPI(WebFrame* frame, | |
| 300 const std::string& custom_binding_api_name, | |
| 301 int world_id) { | |
| 302 std::string extension_id = GetExtensionID(frame, world_id); | |
| 303 const Extension* extension = extensions_.GetByID(extension_id); | |
| 304 if (!extension) { | |
| 305 // This can happen when a resource is blocked due to CSP; a valid | |
| 306 // chrome-extension:// URL is navigated to, so it passes the initial | |
| 307 // checks, but the URL gets changed to "chrome-extension://invalid" | |
| 308 // afterwards (see chrome_content_renderer_client.cc). An extension | |
| 309 // page still gets loaded, just for the extension with ID "invalid", | |
| 310 // which of course isn't found so GetById extension will be NULL. | |
| 311 // | |
| 312 // Reference: http://crbug.com/111614. | |
| 313 CHECK_EQ("invalid", extension_id); | |
| 314 return false; | |
| 315 } | |
| 316 return custom_bindings_util::AllowAPIInjection( | |
| 317 custom_binding_api_name, *extension, this); | |
| 318 } | |
| 319 | |
| 320 base::StringPiece GetResource(int resource_id) { | 285 base::StringPiece GetResource(int resource_id) { |
| 321 return ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); | 286 return ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id); |
| 322 } | 287 } |
| 323 | 288 |
| 324 SourceMap* GetOrCreateSourceMap() { | 289 SourceMap* GetOrCreateSourceMap() { |
| 325 static ResourceBundleSourceMap* source_map; | 290 static ResourceBundleSourceMap* source_map; |
| 326 if (source_map == NULL) { | 291 if (source_map == NULL) { |
| 327 source_map = | 292 source_map = |
| 328 new ResourceBundleSourceMap(&ResourceBundle::GetSharedInstance()); | 293 new ResourceBundleSourceMap(&ResourceBundle::GetSharedInstance()); |
| 329 } | 294 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); | 326 components.push_back(*v8::String::Utf8Value(args[i]->ToString())); |
| 362 | 327 |
| 363 LOG(ERROR) << JoinString(components, ','); | 328 LOG(ERROR) << JoinString(components, ','); |
| 364 return v8::Undefined(); | 329 return v8::Undefined(); |
| 365 } | 330 } |
| 366 }; | 331 }; |
| 367 | 332 |
| 368 class ContextInfoNativeHandler : public NativeHandler { | 333 class ContextInfoNativeHandler : public NativeHandler { |
| 369 public: | 334 public: |
| 370 explicit ContextInfoNativeHandler(ExtensionDispatcher* extension_dispatcher, | 335 explicit ContextInfoNativeHandler(ExtensionDispatcher* extension_dispatcher, |
| 371 bool is_bindings_allowed, | 336 const std::string& extension_id, |
| 372 WebFrame* frame, | 337 const GURL& url, |
| 373 int world_id) | 338 Feature::Context context_type) |
| 374 : extension_dispatcher_(extension_dispatcher), | 339 : extension_dispatcher_(extension_dispatcher), |
| 375 is_bindings_allowed_(is_bindings_allowed), | 340 extension_id_(extension_id), |
| 376 frame_(frame), | 341 url_(url), |
| 377 world_id_(world_id) { | 342 context_type_(context_type) { |
| 378 RouteFunction("IsBindingsAllowed", | |
| 379 base::Bind(&ContextInfoNativeHandler::IsBindingsAllowed, | |
| 380 base::Unretained(this))); | |
| 381 RouteFunction("IsAPIAllowed", | 343 RouteFunction("IsAPIAllowed", |
| 382 base::Bind(&ContextInfoNativeHandler::IsAPIAllowed, | 344 base::Bind(&ContextInfoNativeHandler::IsAPIAllowed, |
| 383 base::Unretained(this))); | 345 base::Unretained(this))); |
| 384 } | 346 } |
| 385 | 347 |
| 386 v8::Handle<v8::Value> IsBindingsAllowed(const v8::Arguments& args) { | 348 v8::Handle<v8::Value> IsAPIAllowed(const v8::Arguments& args) { |
| 387 return v8::Boolean::New(is_bindings_allowed_); | 349 std::string api_name = *v8::String::AsciiValue(args[0]->ToString()); |
| 388 } | |
| 389 | 350 |
| 390 v8::Handle<v8::Value> IsAPIAllowed(const v8::Arguments& args) { | 351 // The extension or URL might not exist / be valid, but one of them must |
| 391 std::string custom_api_name = *v8::String::AsciiValue(args[0]->ToString()); | 352 // be for GetAPIsForContext (which depends on the context type). |
| 392 return v8::Boolean::New(extension_dispatcher_->AllowCustomAPI( | 353 const Extension* extension = |
| 393 frame_, custom_api_name, world_id_)); | 354 extension_dispatcher_->extensions()->GetByID(extension_id_); |
| 355 scoped_ptr<std::set<std::string> > allowed_apis = | |
| 356 ExtensionAPI::GetInstance()->GetAPIsForContext( | |
| 357 context_type_, extension, url_); | |
| 358 return v8::Boolean::New(!!allowed_apis->count(api_name)); | |
| 394 } | 359 } |
| 395 | 360 |
| 396 private: | 361 private: |
| 397 ExtensionDispatcher* extension_dispatcher_; | 362 ExtensionDispatcher* extension_dispatcher_; |
| 398 bool is_bindings_allowed_; | 363 std::string extension_id_; |
| 399 WebFrame* frame_; | 364 GURL url_; |
| 400 int world_id_; | 365 extensions::Feature::Context context_type_; |
| 401 }; | 366 }; |
| 402 | 367 |
| 403 void ExtensionDispatcher::RegisterNativeHandlers(ModuleSystem* module_system, | 368 void ExtensionDispatcher::RegisterNativeHandlers(ModuleSystem* module_system, |
| 404 ChromeV8Context* context, | 369 ChromeV8Context* context) { |
| 405 bool is_bindings_allowed) { | |
| 406 module_system->RegisterNativeHandler("app", | |
| 407 scoped_ptr<NativeHandler>(new AppBindings(this, context))); | |
| 408 module_system->RegisterNativeHandler("webstore", | 370 module_system->RegisterNativeHandler("webstore", |
| 409 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); | 371 scoped_ptr<NativeHandler>(new WebstoreBindings(this, context))); |
| 410 module_system->RegisterNativeHandler("event_bindings", | 372 module_system->RegisterNativeHandler("event_bindings", |
| 411 scoped_ptr<NativeHandler>(EventBindings::Get(this))); | 373 scoped_ptr<NativeHandler>(EventBindings::Get(this))); |
| 412 module_system->RegisterNativeHandler("miscellaneous_bindings", | 374 module_system->RegisterNativeHandler("miscellaneous_bindings", |
| 413 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); | 375 scoped_ptr<NativeHandler>(MiscellaneousBindings::Get(this))); |
| 414 module_system->RegisterNativeHandler("schema_generated_bindings", | 376 module_system->RegisterNativeHandler("schema_generated_bindings", |
| 415 scoped_ptr<NativeHandler>(SchemaGeneratedBindings::Get(this))); | 377 scoped_ptr<NativeHandler>(SchemaGeneratedBindings::Get(this))); |
| 416 | 378 |
| 417 // Custom bindings. | 379 // Custom bindings. |
| 380 module_system->RegisterNativeHandler("app", | |
| 381 scoped_ptr<NativeHandler>(new AppBindings(this, context))); | |
| 418 module_system->RegisterNativeHandler("chrome_private", | 382 module_system->RegisterNativeHandler("chrome_private", |
| 419 scoped_ptr<NativeHandler>( | 383 scoped_ptr<NativeHandler>( |
| 420 new ChromePrivateCustomBindings(this))); | 384 new ChromePrivateCustomBindings(this))); |
| 421 module_system->RegisterNativeHandler("context_menus", | 385 module_system->RegisterNativeHandler("context_menus", |
| 422 scoped_ptr<NativeHandler>(new ContextMenusCustomBindings())); | 386 scoped_ptr<NativeHandler>(new ContextMenusCustomBindings())); |
| 423 module_system->RegisterNativeHandler("extension", | 387 module_system->RegisterNativeHandler("extension", |
| 424 scoped_ptr<NativeHandler>( | 388 scoped_ptr<NativeHandler>( |
| 425 new ExtensionCustomBindings(this))); | 389 new ExtensionCustomBindings(this))); |
| 426 module_system->RegisterNativeHandler("experimental_socket", | 390 module_system->RegisterNativeHandler("experimental_socket", |
| 427 scoped_ptr<NativeHandler>(new ExperimentalSocketCustomBindings())); | 391 scoped_ptr<NativeHandler>(new ExperimentalSocketCustomBindings())); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 438 scoped_ptr<NativeHandler>(new PageCaptureCustomBindings())); | 402 scoped_ptr<NativeHandler>(new PageCaptureCustomBindings())); |
| 439 module_system->RegisterNativeHandler("tabs", | 403 module_system->RegisterNativeHandler("tabs", |
| 440 scoped_ptr<NativeHandler>(new TabsCustomBindings())); | 404 scoped_ptr<NativeHandler>(new TabsCustomBindings())); |
| 441 module_system->RegisterNativeHandler("tts", | 405 module_system->RegisterNativeHandler("tts", |
| 442 scoped_ptr<NativeHandler>(new TTSCustomBindings())); | 406 scoped_ptr<NativeHandler>(new TTSCustomBindings())); |
| 443 module_system->RegisterNativeHandler("web_request", | 407 module_system->RegisterNativeHandler("web_request", |
| 444 scoped_ptr<NativeHandler>(new WebRequestCustomBindings())); | 408 scoped_ptr<NativeHandler>(new WebRequestCustomBindings())); |
| 445 } | 409 } |
| 446 | 410 |
| 447 void ExtensionDispatcher::PopulateSourceMap() { | 411 void ExtensionDispatcher::PopulateSourceMap() { |
| 448 source_map_.RegisterSource("app", IDR_APP_BINDINGS_JS); | |
| 449 source_map_.RegisterSource("webstore", IDR_WEBSTORE_BINDINGS_JS); | 412 source_map_.RegisterSource("webstore", IDR_WEBSTORE_BINDINGS_JS); |
| 450 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); | 413 source_map_.RegisterSource("event_bindings", IDR_EVENT_BINDINGS_JS); |
| 451 source_map_.RegisterSource("miscellaneous_bindings", | 414 source_map_.RegisterSource("miscellaneous_bindings", |
| 452 IDR_MISCELLANEOUS_BINDINGS_JS); | 415 IDR_MISCELLANEOUS_BINDINGS_JS); |
| 453 source_map_.RegisterSource("schema_generated_bindings", | 416 source_map_.RegisterSource("schema_generated_bindings", |
| 454 IDR_SCHEMA_GENERATED_BINDINGS_JS); | 417 IDR_SCHEMA_GENERATED_BINDINGS_JS); |
| 455 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); | 418 source_map_.RegisterSource("json_schema", IDR_JSON_SCHEMA_JS); |
| 456 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS); | 419 source_map_.RegisterSource("apitest", IDR_EXTENSION_APITEST_JS); |
| 457 source_map_.RegisterSource("setup_bindings", IDR_SETUP_BINDINGS_JS); | 420 source_map_.RegisterSource("setup_bindings", IDR_SETUP_BINDINGS_JS); |
| 458 | 421 |
| 459 // Custom bindings. | 422 // Custom bindings. |
| 423 source_map_.RegisterSource("app", IDR_APP_CUSTOM_BINDINGS_JS); | |
| 460 source_map_.RegisterSource("browserAction", | 424 source_map_.RegisterSource("browserAction", |
| 461 IDR_BROWSER_ACTION_CUSTOM_BINDINGS_JS); | 425 IDR_BROWSER_ACTION_CUSTOM_BINDINGS_JS); |
| 462 source_map_.RegisterSource("chromePrivate", | 426 source_map_.RegisterSource("chromePrivate", |
| 463 IDR_CHROME_PRIVATE_CUSTOM_BINDINGS_JS); | 427 IDR_CHROME_PRIVATE_CUSTOM_BINDINGS_JS); |
| 464 source_map_.RegisterSource("contentSettings", | 428 source_map_.RegisterSource("contentSettings", |
| 465 IDR_CONTENT_SETTINGS_CUSTOM_BINDINGS_JS); | 429 IDR_CONTENT_SETTINGS_CUSTOM_BINDINGS_JS); |
| 466 source_map_.RegisterSource("contextMenus", | 430 source_map_.RegisterSource("contextMenus", |
| 467 IDR_CONTEXT_MENUS_CUSTOM_BINDINGS_JS); | 431 IDR_CONTEXT_MENUS_CUSTOM_BINDINGS_JS); |
| 468 source_map_.RegisterSource("devtools", IDR_DEVTOOLS_CUSTOM_BINDINGS_JS); | 432 source_map_.RegisterSource("devtools", IDR_DEVTOOLS_CUSTOM_BINDINGS_JS); |
| 469 source_map_.RegisterSource("experimental.declarative", | 433 source_map_.RegisterSource("experimental.declarative", |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 491 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); | 455 source_map_.RegisterSource("webRequest", IDR_WEB_REQUEST_CUSTOM_BINDINGS_JS); |
| 492 source_map_.RegisterSource("windows", IDR_WINDOWS_CUSTOM_BINDINGS_JS); | 456 source_map_.RegisterSource("windows", IDR_WINDOWS_CUSTOM_BINDINGS_JS); |
| 493 } | 457 } |
| 494 | 458 |
| 495 void ExtensionDispatcher::DidCreateScriptContext( | 459 void ExtensionDispatcher::DidCreateScriptContext( |
| 496 WebFrame* frame, v8::Handle<v8::Context> v8_context, int extension_group, | 460 WebFrame* frame, v8::Handle<v8::Context> v8_context, int extension_group, |
| 497 int world_id) { | 461 int world_id) { |
| 498 // TODO(koz): If the caller didn't pass extension_group, use the last value. | 462 // TODO(koz): If the caller didn't pass extension_group, use the last value. |
| 499 if (extension_group == -1) | 463 if (extension_group == -1) |
| 500 extension_group = g_hack_extension_group; | 464 extension_group = g_hack_extension_group; |
| 465 | |
| 466 std::string extension_id = GetExtensionID(frame, world_id); | |
| 467 ExtensionURLInfo url_info(frame->document().securityOrigin(), | |
| 468 UserScriptSlave::GetDataSourceURLForFrame(frame)); | |
| 469 Feature::Context context_type = | |
| 470 ClassifyJavaScriptContext(extension_id, extension_group, url_info); | |
| 471 | |
| 472 // Sanity checking - | |
| 473 // | |
| 474 // This can happen when a resource is blocked due to CSP; a valid | |
| 475 // chrome-extension:// URL is navigated to, so it passes the initial checks, | |
| 476 // but the URL gets changed to "chrome-extension://invalid" afterwards (see | |
| 477 // chrome_content_renderer_client.cc). An extension page still gets loaded, | |
| 478 // just for the extension with ID "invalid", which of course isn't found so | |
| 479 // GetById extension will be NULL. | |
| 480 // | |
| 481 // Reference: http://crbug.com/111614. | |
| 482 if (extension_id == "invalid") | |
| 483 CHECK_EQ(Feature::UNSPECIFIED_CONTEXT, context_type); | |
| 484 | |
| 501 ChromeV8Context* context = | 485 ChromeV8Context* context = |
| 502 new ChromeV8Context( | 486 new ChromeV8Context(v8_context, frame, extension_id, context_type); |
| 503 v8_context, | |
| 504 frame, | |
| 505 GetExtensionID(frame, world_id), | |
| 506 ExtensionGroupToContextType(extension_group)); | |
| 507 v8_context_set_.Add(context); | 487 v8_context_set_.Add(context); |
| 508 | 488 |
| 509 bool is_bindings_allowed = | |
| 510 context->context_type() == ChromeV8Context::CONTENT_SCRIPT || | |
| 511 extensions_.ExtensionBindingsAllowed(ExtensionURLInfo( | |
| 512 frame->document().securityOrigin(), | |
| 513 UserScriptSlave::GetDataSourceURLForFrame(frame))); | |
| 514 | |
| 515 ModuleSystem* module_system = new ModuleSystem(&source_map_); | 489 ModuleSystem* module_system = new ModuleSystem(&source_map_); |
| 516 RegisterNativeHandlers(module_system, context, is_bindings_allowed); | 490 RegisterNativeHandlers(module_system, context); |
| 517 | 491 |
| 518 module_system->RegisterNativeHandler("chrome_hidden", | 492 module_system->RegisterNativeHandler("chrome_hidden", |
| 519 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); | 493 scoped_ptr<NativeHandler>(new ChromeHiddenNativeHandler())); |
| 520 module_system->RegisterNativeHandler("print", | 494 module_system->RegisterNativeHandler("print", |
| 521 scoped_ptr<NativeHandler>(new PrintNativeHandler())); | 495 scoped_ptr<NativeHandler>(new PrintNativeHandler())); |
| 522 module_system->RegisterNativeHandler("context_info", | 496 module_system->RegisterNativeHandler("context_info", |
| 523 scoped_ptr<NativeHandler>(new ContextInfoNativeHandler( | 497 scoped_ptr<NativeHandler>(new ContextInfoNativeHandler( |
| 524 this, | 498 this, extension_id, url_info.url(), context_type))); |
| 525 is_bindings_allowed, | |
| 526 frame, | |
| 527 world_id))); | |
| 528 | 499 |
| 529 context->set_module_system(scoped_ptr<ModuleSystem>(module_system)); | 500 context->set_module_system(scoped_ptr<ModuleSystem>(module_system)); |
| 530 | 501 |
| 531 const Extension* extension = extensions_.GetByID(context->extension_id()); | 502 const Extension* extension = extensions_.GetByID(extension_id); |
| 532 int manifest_version = 1; | 503 int manifest_version = 1; |
| 533 if (extension) | 504 if (extension) |
| 534 manifest_version = extension->manifest_version(); | 505 manifest_version = extension->manifest_version(); |
| 535 | 506 |
| 536 module_system->Require("setup_bindings"); | 507 module_system->Require("setup_bindings"); |
| 537 | 508 |
| 538 context->DispatchOnLoadEvent( | 509 context->DispatchOnLoadEvent( |
| 539 is_extension_process_, | 510 is_extension_process_, |
| 540 ChromeRenderProcessObserver::is_incognito_process(), | 511 ChromeRenderProcessObserver::is_incognito_process(), |
| 541 manifest_version); | 512 manifest_version); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 563 if (!context) | 534 if (!context) |
| 564 return; | 535 return; |
| 565 | 536 |
| 566 context->DispatchOnUnloadEvent(); | 537 context->DispatchOnUnloadEvent(); |
| 567 | 538 |
| 568 v8_context_set_.Remove(context); | 539 v8_context_set_.Remove(context); |
| 569 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); | 540 VLOG(1) << "Num tracked contexts: " << v8_context_set_.size(); |
| 570 } | 541 } |
| 571 | 542 |
| 572 void ExtensionDispatcher::SetTestExtensionId(const std::string& id) { | 543 void ExtensionDispatcher::SetTestExtensionId(const std::string& id) { |
| 544 CHECK(!id.empty()); | |
| 573 test_extension_id_ = id; | 545 test_extension_id_ = id; |
| 574 } | 546 } |
| 575 | 547 |
| 576 bool ExtensionDispatcher::IsTestExtensionId(const std::string& id) { | 548 bool ExtensionDispatcher::IsTestExtensionId(const std::string& id) { |
| 577 return id == test_extension_id_; | 549 return !test_extension_id_.empty() && id == test_extension_id_; |
| 578 } | |
| 579 | |
| 580 void ExtensionDispatcher::OnActivateApplication( | |
| 581 const std::string& extension_id) { | |
| 582 active_application_ids_.insert(extension_id); | |
| 583 } | 550 } |
| 584 | 551 |
| 585 void ExtensionDispatcher::OnActivateExtension( | 552 void ExtensionDispatcher::OnActivateExtension( |
| 586 const std::string& extension_id) { | 553 const std::string& extension_id) { |
| 587 active_extension_ids_.insert(extension_id); | 554 active_extension_ids_.insert(extension_id); |
| 588 | 555 |
| 589 // This is called when starting a new extension page, so start the idle | 556 // This is called when starting a new extension page, so start the idle |
| 590 // handler ticking. | 557 // handler ticking. |
| 591 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); | 558 RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs); |
| 592 | 559 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 webrequest_adblock_ = adblock; | 669 webrequest_adblock_ = adblock; |
| 703 webrequest_adblock_plus_ = adblock_plus; | 670 webrequest_adblock_plus_ = adblock_plus; |
| 704 webrequest_other_ = other; | 671 webrequest_other_ = other; |
| 705 } | 672 } |
| 706 | 673 |
| 707 void ExtensionDispatcher::OnShouldClose(const std::string& extension_id, | 674 void ExtensionDispatcher::OnShouldClose(const std::string& extension_id, |
| 708 int sequence_id) { | 675 int sequence_id) { |
| 709 RenderThread::Get()->Send( | 676 RenderThread::Get()->Send( |
| 710 new ExtensionHostMsg_ShouldCloseAck(extension_id, sequence_id)); | 677 new ExtensionHostMsg_ShouldCloseAck(extension_id, sequence_id)); |
| 711 } | 678 } |
| 679 | |
| 680 Feature::Context ExtensionDispatcher::ClassifyJavaScriptContext( | |
| 681 const std::string& extension_id, | |
| 682 int extension_group, | |
| 683 const ExtensionURLInfo& url_info) { | |
| 684 if (extension_group == EXTENSION_GROUP_CONTENT_SCRIPTS) | |
| 685 return Feature::CONTENT_SCRIPT_CONTEXT; | |
| 686 | |
| 687 if (IsExtensionActive(extension_id)) | |
| 688 return Feature::PRIVILEGED_CONTEXT; | |
| 689 | |
| 690 if (extensions_.ExtensionBindingsAllowed(url_info)) | |
| 691 return Feature::UNPRIVILEGED_CONTEXT; | |
|
Aaron Boodman
2012/03/06 01:17:21
OK, but this name is terrible. After this CL, can
not at google - send to devlin
2012/03/06 03:53:00
Yep. Added TODO to feature.h
Does s/PRIVILEGED/BL
Aaron Boodman
2012/03/06 08:18:12
Yes.
| |
| 692 | |
| 693 if (url_info.url().is_valid()) | |
| 694 return Feature::WEB_PAGE_CONTEXT; | |
| 695 | |
| 696 return Feature::UNSPECIFIED_CONTEXT; | |
| 697 } | |
| OLD | NEW |