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/browser/extensions/tab_helper.h" | 5 #include "chrome/browser/extensions/tab_helper.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/extensions/active_script_controller.h" | |
| 12 #include "chrome/browser/extensions/activity_log/activity_log.h" | 13 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| 13 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" | 14 #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" |
| 14 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist ry.h" | 15 #include "chrome/browser/extensions/api/declarative_content/content_rules_regist ry.h" |
| 15 #include "chrome/browser/extensions/api/webstore/webstore_api.h" | 16 #include "chrome/browser/extensions/api/webstore/webstore_api.h" |
| 16 #include "chrome/browser/extensions/bookmark_app_helper.h" | 17 #include "chrome/browser/extensions/bookmark_app_helper.h" |
| 17 #include "chrome/browser/extensions/error_console/error_console.h" | 18 #include "chrome/browser/extensions/error_console/error_console.h" |
| 18 #include "chrome/browser/extensions/extension_action.h" | 19 #include "chrome/browser/extensions/extension_action.h" |
| 19 #include "chrome/browser/extensions/extension_action_manager.h" | 20 #include "chrome/browser/extensions/extension_action_manager.h" |
| 20 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
| 21 #include "chrome/browser/extensions/extension_tab_util.h" | 22 #include "chrome/browser/extensions/extension_tab_util.h" |
| 22 #include "chrome/browser/extensions/image_loader.h" | 23 #include "chrome/browser/extensions/image_loader.h" |
| 23 #include "chrome/browser/extensions/page_action_controller.h" | 24 #include "chrome/browser/extensions/location_bar_controller.h" |
| 24 #include "chrome/browser/extensions/script_executor.h" | 25 #include "chrome/browser/extensions/script_executor.h" |
| 25 #include "chrome/browser/extensions/webstore_inline_installer.h" | 26 #include "chrome/browser/extensions/webstore_inline_installer.h" |
| 26 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" | 27 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/sessions/session_id.h" | 29 #include "chrome/browser/sessions/session_id.h" |
| 29 #include "chrome/browser/sessions/session_tab_helper.h" | 30 #include "chrome/browser/sessions/session_tab_helper.h" |
| 30 #include "chrome/browser/shell_integration.h" | 31 #include "chrome/browser/shell_integration.h" |
| 31 #include "chrome/browser/ui/browser_commands.h" | 32 #include "chrome/browser/ui/browser_commands.h" |
| 32 #include "chrome/browser/ui/browser_dialogs.h" | 33 #include "chrome/browser/ui/browser_dialogs.h" |
| 33 #include "chrome/browser/ui/browser_finder.h" | 34 #include "chrome/browser/ui/browser_finder.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 } | 97 } |
| 97 | 98 |
| 98 TabHelper::TabHelper(content::WebContents* web_contents) | 99 TabHelper::TabHelper(content::WebContents* web_contents) |
| 99 : content::WebContentsObserver(web_contents), | 100 : content::WebContentsObserver(web_contents), |
| 100 extension_app_(NULL), | 101 extension_app_(NULL), |
| 101 extension_function_dispatcher_( | 102 extension_function_dispatcher_( |
| 102 Profile::FromBrowserContext(web_contents->GetBrowserContext()), this), | 103 Profile::FromBrowserContext(web_contents->GetBrowserContext()), this), |
| 103 pending_web_app_action_(NONE), | 104 pending_web_app_action_(NONE), |
| 104 script_executor_(new ScriptExecutor(web_contents, | 105 script_executor_(new ScriptExecutor(web_contents, |
| 105 &script_execution_observers_)), | 106 &script_execution_observers_)), |
| 106 location_bar_controller_(new PageActionController(web_contents)), | 107 location_bar_controller_(new LocationBarController(web_contents)), |
| 107 image_loader_ptr_factory_(this), | 108 image_loader_ptr_factory_(this), |
| 108 webstore_inline_installer_factory_(new WebstoreInlineInstallerFactory()) { | 109 webstore_inline_installer_factory_(new WebstoreInlineInstallerFactory()) { |
| 109 // The ActiveTabPermissionManager requires a session ID; ensure this | 110 // The ActiveTabPermissionManager requires a session ID; ensure this |
| 110 // WebContents has one. | 111 // WebContents has one. |
| 111 SessionTabHelper::CreateForWebContents(web_contents); | 112 SessionTabHelper::CreateForWebContents(web_contents); |
| 112 if (web_contents->GetRenderViewHost()) | 113 if (web_contents->GetRenderViewHost()) |
| 113 SetTabId(web_contents->GetRenderViewHost()); | 114 SetTabId(web_contents->GetRenderViewHost()); |
| 114 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( | 115 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( |
| 115 web_contents, | 116 web_contents, |
| 116 SessionID::IdForTab(web_contents), | 117 SessionID::IdForTab(web_contents), |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 IPC_BEGIN_MESSAGE_MAP(TabHelper, message) | 301 IPC_BEGIN_MESSAGE_MAP(TabHelper, message) |
| 301 IPC_MESSAGE_HANDLER(ChromeExtensionHostMsg_DidGetApplicationInfo, | 302 IPC_MESSAGE_HANDLER(ChromeExtensionHostMsg_DidGetApplicationInfo, |
| 302 OnDidGetApplicationInfo) | 303 OnDidGetApplicationInfo) |
| 303 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, | 304 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, |
| 304 OnInlineWebstoreInstall) | 305 OnInlineWebstoreInstall) |
| 305 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, | 306 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, |
| 306 OnGetAppInstallState); | 307 OnGetAppInstallState); |
| 307 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | 308 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) |
| 308 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, | 309 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, |
| 309 OnContentScriptsExecuting) | 310 OnContentScriptsExecuting) |
| 311 IPC_MESSAGE_HANDLER(ExtensionHostMsg_NotifyExtensionScriptExecution, | |
| 312 OnNotifyExtensionScriptExecution) | |
| 310 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OnWatchedPageChange, | 313 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OnWatchedPageChange, |
| 311 OnWatchedPageChange) | 314 OnWatchedPageChange) |
| 312 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DetailedConsoleMessageAdded, | 315 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DetailedConsoleMessageAdded, |
| 313 OnDetailedConsoleMessageAdded) | 316 OnDetailedConsoleMessageAdded) |
| 314 IPC_MESSAGE_UNHANDLED(handled = false) | 317 IPC_MESSAGE_UNHANDLED(handled = false) |
| 315 IPC_END_MESSAGE_MAP() | 318 IPC_END_MESSAGE_MAP() |
| 316 return handled; | 319 return handled; |
| 317 } | 320 } |
| 318 | 321 |
| 319 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, | 322 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 438 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, | 441 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, |
| 439 int32 on_page_id, | 442 int32 on_page_id, |
| 440 const GURL& on_url) { | 443 const GURL& on_url) { |
| 441 FOR_EACH_OBSERVER(ScriptExecutionObserver, script_execution_observers_, | 444 FOR_EACH_OBSERVER(ScriptExecutionObserver, script_execution_observers_, |
| 442 OnScriptsExecuted(web_contents(), | 445 OnScriptsExecuted(web_contents(), |
| 443 executing_scripts_map, | 446 executing_scripts_map, |
| 444 on_page_id, | 447 on_page_id, |
| 445 on_url)); | 448 on_url)); |
| 446 } | 449 } |
| 447 | 450 |
| 451 void TabHelper::OnNotifyExtensionScriptExecution( | |
| 452 const std::string& extension_id, | |
| 453 int page_id) { | |
| 454 if (Extension::IdIsValid(extension_id)) { | |
| 455 location_bar_controller()->active_script_controller() | |
|
not at google - send to devlin
2014/05/08 20:47:09
Can you make ActiveScriptController a WebContentsO
Devlin
2014/05/08 23:01:00
It makes me sad that now ActiveScriptController in
| |
| 456 ->NotifyScriptExecuting(extension_id, page_id); | |
| 457 } | |
| 458 } | |
| 459 | |
| 448 void TabHelper::OnWatchedPageChange( | 460 void TabHelper::OnWatchedPageChange( |
| 449 const std::vector<std::string>& css_selectors) { | 461 const std::vector<std::string>& css_selectors) { |
| 450 #if defined(ENABLE_EXTENSIONS) | 462 #if defined(ENABLE_EXTENSIONS) |
| 451 if (ExtensionSystem::Get(profile_)->extension_service() && | 463 if (ExtensionSystem::Get(profile_)->extension_service() && |
| 452 RulesRegistryService::Get(profile_)) { | 464 RulesRegistryService::Get(profile_)) { |
| 453 RulesRegistryService::Get(profile_)->content_rules_registry()->Apply( | 465 RulesRegistryService::Get(profile_)->content_rules_registry()->Apply( |
| 454 web_contents(), css_selectors); | 466 web_contents(), css_selectors); |
| 455 } | 467 } |
| 456 #endif // defined(ENABLE_EXTENSIONS) | 468 #endif // defined(ENABLE_EXTENSIONS) |
| 457 } | 469 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 } | 589 } |
| 578 } | 590 } |
| 579 | 591 |
| 580 void TabHelper::SetTabId(RenderViewHost* render_view_host) { | 592 void TabHelper::SetTabId(RenderViewHost* render_view_host) { |
| 581 render_view_host->Send( | 593 render_view_host->Send( |
| 582 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), | 594 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), |
| 583 SessionID::IdForTab(web_contents()))); | 595 SessionID::IdForTab(web_contents()))); |
| 584 } | 596 } |
| 585 | 597 |
| 586 } // namespace extensions | 598 } // namespace extensions |
| OLD | NEW |