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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/extensions/active_script_controller.h" | 11 #include "chrome/browser/extensions/active_script_controller.h" |
| 12 #include "chrome/browser/extensions/activity_log/activity_log.h" | 12 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| 13 #include "chrome/browser/extensions/api/declarative_content/chrome_content_rules _registry.h" | 13 #include "chrome/browser/extensions/api/declarative_content/chrome_content_rules _registry.h" |
| 14 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 14 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 15 #include "chrome/browser/extensions/api/webstore/webstore_api.h" | 15 #include "chrome/browser/extensions/api/webstore/webstore_api.h" |
| 16 #include "chrome/browser/extensions/bookmark_app_helper.h" | 16 #include "chrome/browser/extensions/bookmark_app_helper.h" |
| 17 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.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_tab_util.h" | 19 #include "chrome/browser/extensions/extension_tab_util.h" |
| 19 #include "chrome/browser/extensions/extension_util.h" | 20 #include "chrome/browser/extensions/extension_util.h" |
| 20 #include "chrome/browser/extensions/location_bar_controller.h" | 21 #include "chrome/browser/extensions/location_bar_controller.h" |
| 21 #include "chrome/browser/extensions/webstore_inline_installer.h" | 22 #include "chrome/browser/extensions/webstore_inline_installer.h" |
| 22 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" | 23 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/sessions/session_tab_helper.h" | 25 #include "chrome/browser/sessions/session_tab_helper.h" |
| 25 #include "chrome/browser/shell_integration.h" | 26 #include "chrome/browser/shell_integration.h" |
| 26 #include "chrome/browser/ui/browser_commands.h" | 27 #include "chrome/browser/ui/browser_commands.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 43 #include "content/public/browser/render_frame_host.h" | 44 #include "content/public/browser/render_frame_host.h" |
| 44 #include "content/public/browser/render_process_host.h" | 45 #include "content/public/browser/render_process_host.h" |
| 45 #include "content/public/browser/render_view_host.h" | 46 #include "content/public/browser/render_view_host.h" |
| 46 #include "content/public/browser/web_contents.h" | 47 #include "content/public/browser/web_contents.h" |
| 47 #include "content/public/common/frame_navigate_params.h" | 48 #include "content/public/common/frame_navigate_params.h" |
| 48 #include "extensions/browser/api/declarative/rules_registry_service.h" | 49 #include "extensions/browser/api/declarative/rules_registry_service.h" |
| 49 #include "extensions/browser/extension_error.h" | 50 #include "extensions/browser/extension_error.h" |
| 50 #include "extensions/browser/extension_prefs.h" | 51 #include "extensions/browser/extension_prefs.h" |
| 51 #include "extensions/browser/extension_registry.h" | 52 #include "extensions/browser/extension_registry.h" |
| 52 #include "extensions/browser/extension_system.h" | 53 #include "extensions/browser/extension_system.h" |
| 54 #include "extensions/browser/extension_web_contents_observer.h" | |
| 53 #include "extensions/browser/image_loader.h" | 55 #include "extensions/browser/image_loader.h" |
| 54 #include "extensions/common/constants.h" | 56 #include "extensions/common/constants.h" |
| 55 #include "extensions/common/extension.h" | 57 #include "extensions/common/extension.h" |
| 56 #include "extensions/common/extension_icon_set.h" | 58 #include "extensions/common/extension_icon_set.h" |
| 57 #include "extensions/common/extension_messages.h" | 59 #include "extensions/common/extension_messages.h" |
| 58 #include "extensions/common/extension_resource.h" | 60 #include "extensions/common/extension_resource.h" |
| 59 #include "extensions/common/extension_urls.h" | 61 #include "extensions/common/extension_urls.h" |
| 60 #include "extensions/common/feature_switch.h" | 62 #include "extensions/common/feature_switch.h" |
| 61 #include "extensions/common/manifest_handlers/icons_handler.h" | 63 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 62 | 64 |
| 63 #if defined(OS_WIN) | 65 #if defined(OS_WIN) |
| 64 #include "chrome/browser/web_applications/web_app_win.h" | 66 #include "chrome/browser/web_applications/web_app_win.h" |
| 65 #endif | 67 #endif |
| 66 | 68 |
| 67 using content::NavigationController; | 69 using content::NavigationController; |
| 68 using content::NavigationEntry; | 70 using content::NavigationEntry; |
| 69 using content::WebContents; | 71 using content::WebContents; |
| 70 | 72 |
| 71 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::TabHelper); | 73 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::TabHelper); |
| 72 | 74 |
| 73 namespace extensions { | 75 namespace extensions { |
| 74 | 76 |
| 75 TabHelper::TabHelper(content::WebContents* web_contents) | 77 TabHelper::TabHelper(content::WebContents* web_contents) |
| 76 : content::WebContentsObserver(web_contents), | 78 : content::WebContentsObserver(web_contents), |
| 77 extension_app_(NULL), | 79 extension_app_(NULL), |
| 78 extension_function_dispatcher_( | |
| 79 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | |
| 80 this), | |
| 81 pending_web_app_action_(NONE), | 80 pending_web_app_action_(NONE), |
| 82 last_committed_nav_entry_unique_id_(0), | 81 last_committed_nav_entry_unique_id_(0), |
| 83 update_shortcut_on_load_complete_(false), | 82 update_shortcut_on_load_complete_(false), |
| 84 script_executor_( | 83 script_executor_( |
| 85 new ScriptExecutor(web_contents, &script_execution_observers_)), | 84 new ScriptExecutor(web_contents, &script_execution_observers_)), |
| 86 location_bar_controller_(new LocationBarController(web_contents)), | 85 location_bar_controller_(new LocationBarController(web_contents)), |
| 87 active_script_controller_(new ActiveScriptController(web_contents)), | 86 active_script_controller_(new ActiveScriptController(web_contents)), |
| 88 webstore_inline_installer_factory_(new WebstoreInlineInstallerFactory()), | 87 webstore_inline_installer_factory_(new WebstoreInlineInstallerFactory()), |
| 89 image_loader_ptr_factory_(this), | 88 image_loader_ptr_factory_(this), |
| 90 weak_ptr_factory_(this) { | 89 weak_ptr_factory_(this) { |
| 91 // The ActiveTabPermissionManager requires a session ID; ensure this | 90 // The ActiveTabPermissionManager requires a session ID; ensure this |
| 92 // WebContents has one. | 91 // WebContents has one. |
| 93 SessionTabHelper::CreateForWebContents(web_contents); | 92 SessionTabHelper::CreateForWebContents(web_contents); |
| 94 // The Unretained() is safe because ForEachFrame is synchronous. | 93 // The Unretained() is safe because ForEachFrame is synchronous. |
| 95 web_contents->ForEachFrame( | 94 web_contents->ForEachFrame( |
| 96 base::Bind(&TabHelper::SetTabId, base::Unretained(this))); | 95 base::Bind(&TabHelper::SetTabId, base::Unretained(this))); |
| 97 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( | 96 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( |
| 98 web_contents, | 97 web_contents, |
| 99 SessionTabHelper::IdForTab(web_contents), | 98 SessionTabHelper::IdForTab(web_contents), |
| 100 Profile::FromBrowserContext(web_contents->GetBrowserContext()))); | 99 Profile::FromBrowserContext(web_contents->GetBrowserContext()))); |
| 101 | 100 |
| 102 // If more classes need to listen to global content script activity, then | 101 // If more classes need to listen to global content script activity, then |
| 103 // a separate routing class with an observer interface should be written. | 102 // a separate routing class with an observer interface should be written. |
| 104 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 103 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 105 | 104 |
| 106 AddScriptExecutionObserver(ActivityLog::GetInstance(profile_)); | 105 AddScriptExecutionObserver(ActivityLog::GetInstance(profile_)); |
| 107 | 106 |
| 107 // We need an ExtensionWebContentsObserver, so make sure one exists (this is | |
| 108 // a no-op if one already does). | |
| 109 ChromeExtensionWebContentsObserver::CreateForWebContents(web_contents); | |
| 110 ExtensionWebContentsObserver::GetForWebContents(web_contents)->dispatcher()-> | |
| 111 set_delegate(this); | |
|
not at google - send to devlin
2015/06/10 20:48:12
This pattern appears a lot:
// maybe there's a co
Devlin
2015/06/10 20:59:20
That would work. My concern is that it makes it a
not at google - send to devlin
2015/06/10 21:37:07
As discussed - since the end game here *is* to mak
| |
| 112 | |
| 108 registrar_.Add(this, | 113 registrar_.Add(this, |
| 109 content::NOTIFICATION_LOAD_STOP, | 114 content::NOTIFICATION_LOAD_STOP, |
| 110 content::Source<NavigationController>( | 115 content::Source<NavigationController>( |
| 111 &web_contents->GetController())); | 116 &web_contents->GetController())); |
| 112 } | 117 } |
| 113 | 118 |
| 114 TabHelper::~TabHelper() { | 119 TabHelper::~TabHelper() { |
| 115 RemoveScriptExecutionObserver(ActivityLog::GetInstance(profile_)); | 120 RemoveScriptExecutionObserver(ActivityLog::GetInstance(profile_)); |
| 116 } | 121 } |
| 117 | 122 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 | 259 |
| 255 bool TabHelper::OnMessageReceived(const IPC::Message& message) { | 260 bool TabHelper::OnMessageReceived(const IPC::Message& message) { |
| 256 bool handled = true; | 261 bool handled = true; |
| 257 IPC_BEGIN_MESSAGE_MAP(TabHelper, message) | 262 IPC_BEGIN_MESSAGE_MAP(TabHelper, message) |
| 258 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidGetWebApplicationInfo, | 263 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidGetWebApplicationInfo, |
| 259 OnDidGetWebApplicationInfo) | 264 OnDidGetWebApplicationInfo) |
| 260 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, | 265 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, |
| 261 OnInlineWebstoreInstall) | 266 OnInlineWebstoreInstall) |
| 262 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, | 267 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, |
| 263 OnGetAppInstallState); | 268 OnGetAppInstallState); |
| 264 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | |
| 265 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OnWatchedPageChange, | 269 IPC_MESSAGE_HANDLER(ExtensionHostMsg_OnWatchedPageChange, |
| 266 OnWatchedPageChange) | 270 OnWatchedPageChange) |
| 267 IPC_MESSAGE_UNHANDLED(handled = false) | 271 IPC_MESSAGE_UNHANDLED(handled = false) |
| 268 IPC_END_MESSAGE_MAP() | 272 IPC_END_MESSAGE_MAP() |
| 269 return handled; | 273 return handled; |
| 270 } | 274 } |
| 271 | 275 |
| 272 bool TabHelper::OnMessageReceived(const IPC::Message& message, | 276 bool TabHelper::OnMessageReceived(const IPC::Message& message, |
| 273 content::RenderFrameHost* render_frame_host) { | 277 content::RenderFrameHost* render_frame_host) { |
| 274 bool handled = true; | 278 bool handled = true; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 state = extension_misc::kAppStateInstalled; | 416 state = extension_misc::kAppStateInstalled; |
| 413 else if (disabled_extensions.GetHostedAppByURL(requestor_url)) | 417 else if (disabled_extensions.GetHostedAppByURL(requestor_url)) |
| 414 state = extension_misc::kAppStateDisabled; | 418 state = extension_misc::kAppStateDisabled; |
| 415 else | 419 else |
| 416 state = extension_misc::kAppStateNotInstalled; | 420 state = extension_misc::kAppStateNotInstalled; |
| 417 | 421 |
| 418 Send(new ExtensionMsg_GetAppInstallStateResponse( | 422 Send(new ExtensionMsg_GetAppInstallStateResponse( |
| 419 return_route_id, state, callback_id)); | 423 return_route_id, state, callback_id)); |
| 420 } | 424 } |
| 421 | 425 |
| 422 void TabHelper::OnRequest(const ExtensionHostMsg_Request_Params& request) { | |
| 423 extension_function_dispatcher_.Dispatch(request, | |
| 424 web_contents()->GetRenderViewHost()); | |
| 425 } | |
| 426 | |
| 427 void TabHelper::OnContentScriptsExecuting( | 426 void TabHelper::OnContentScriptsExecuting( |
| 428 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, | 427 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, |
| 429 const GURL& on_url) { | 428 const GURL& on_url) { |
| 430 FOR_EACH_OBSERVER( | 429 FOR_EACH_OBSERVER( |
| 431 ScriptExecutionObserver, | 430 ScriptExecutionObserver, |
| 432 script_execution_observers_, | 431 script_execution_observers_, |
| 433 OnScriptsExecuted(web_contents(), executing_scripts_map, on_url)); | 432 OnScriptsExecuted(web_contents(), executing_scripts_map, on_url)); |
| 434 } | 433 } |
| 435 | 434 |
| 436 void TabHelper::OnWatchedPageChange( | 435 void TabHelper::OnWatchedPageChange( |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 } | 594 } |
| 596 } | 595 } |
| 597 | 596 |
| 598 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) { | 597 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) { |
| 599 render_frame_host->Send( | 598 render_frame_host->Send( |
| 600 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(), | 599 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(), |
| 601 SessionTabHelper::IdForTab(web_contents()))); | 600 SessionTabHelper::IdForTab(web_contents()))); |
| 602 } | 601 } |
| 603 | 602 |
| 604 } // namespace extensions | 603 } // namespace extensions |
| OLD | NEW |