| 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 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 79 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
| 78 extension_app_(NULL), | 80 extension_app_(NULL), |
| 79 extension_function_dispatcher_(profile_, this), | |
| 80 pending_web_app_action_(NONE), | 81 pending_web_app_action_(NONE), |
| 81 last_committed_nav_entry_unique_id_(0), | 82 last_committed_nav_entry_unique_id_(0), |
| 82 update_shortcut_on_load_complete_(false), | 83 update_shortcut_on_load_complete_(false), |
| 83 script_executor_( | 84 script_executor_( |
| 84 new ScriptExecutor(web_contents, &script_execution_observers_)), | 85 new ScriptExecutor(web_contents, &script_execution_observers_)), |
| 85 location_bar_controller_(new LocationBarController(web_contents)), | 86 location_bar_controller_(new LocationBarController(web_contents)), |
| 86 active_script_controller_(new ActiveScriptController(web_contents)), | 87 active_script_controller_(new ActiveScriptController(web_contents)), |
| 87 webstore_inline_installer_factory_(new WebstoreInlineInstallerFactory()), | 88 webstore_inline_installer_factory_(new WebstoreInlineInstallerFactory()), |
| 88 image_loader_ptr_factory_(this), | 89 image_loader_ptr_factory_(this), |
| 89 weak_ptr_factory_(this) { | 90 weak_ptr_factory_(this) { |
| 90 // The ActiveTabPermissionManager requires a session ID; ensure this | 91 // The ActiveTabPermissionManager requires a session ID; ensure this |
| 91 // WebContents has one. | 92 // WebContents has one. |
| 92 SessionTabHelper::CreateForWebContents(web_contents); | 93 SessionTabHelper::CreateForWebContents(web_contents); |
| 93 // The Unretained() is safe because ForEachFrame is synchronous. | 94 // The Unretained() is safe because ForEachFrame is synchronous. |
| 94 web_contents->ForEachFrame( | 95 web_contents->ForEachFrame( |
| 95 base::Bind(&TabHelper::SetTabId, base::Unretained(this))); | 96 base::Bind(&TabHelper::SetTabId, base::Unretained(this))); |
| 96 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( | 97 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( |
| 97 web_contents, | 98 web_contents, |
| 98 SessionTabHelper::IdForTab(web_contents), | 99 SessionTabHelper::IdForTab(web_contents), |
| 99 profile_)); | 100 profile_)); |
| 100 | 101 |
| 101 AddScriptExecutionObserver(ActivityLog::GetInstance(profile_)); | 102 AddScriptExecutionObserver(ActivityLog::GetInstance(profile_)); |
| 102 | 103 |
| 103 InvokeForContentRulesRegistries([this](ContentRulesRegistry* registry) { | 104 InvokeForContentRulesRegistries([this](ContentRulesRegistry* registry) { |
| 104 registry->MonitorWebContentsForRuleEvaluation(this->web_contents()); | 105 registry->MonitorWebContentsForRuleEvaluation(this->web_contents()); |
| 105 }); | 106 }); |
| 106 | 107 |
| 108 // We need an ExtensionWebContentsObserver, so make sure one exists (this is |
| 109 // a no-op if one already does). |
| 110 ChromeExtensionWebContentsObserver::CreateForWebContents(web_contents); |
| 111 ExtensionWebContentsObserver::GetForWebContents(web_contents)->dispatcher()-> |
| 112 set_delegate(this); |
| 113 |
| 107 registrar_.Add(this, | 114 registrar_.Add(this, |
| 108 content::NOTIFICATION_LOAD_STOP, | 115 content::NOTIFICATION_LOAD_STOP, |
| 109 content::Source<NavigationController>( | 116 content::Source<NavigationController>( |
| 110 &web_contents->GetController())); | 117 &web_contents->GetController())); |
| 111 } | 118 } |
| 112 | 119 |
| 113 TabHelper::~TabHelper() { | 120 TabHelper::~TabHelper() { |
| 114 RemoveScriptExecutionObserver(ActivityLog::GetInstance(profile_)); | 121 RemoveScriptExecutionObserver(ActivityLog::GetInstance(profile_)); |
| 115 } | 122 } |
| 116 | 123 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 267 |
| 261 bool TabHelper::OnMessageReceived(const IPC::Message& message) { | 268 bool TabHelper::OnMessageReceived(const IPC::Message& message) { |
| 262 bool handled = true; | 269 bool handled = true; |
| 263 IPC_BEGIN_MESSAGE_MAP(TabHelper, message) | 270 IPC_BEGIN_MESSAGE_MAP(TabHelper, message) |
| 264 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidGetWebApplicationInfo, | 271 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidGetWebApplicationInfo, |
| 265 OnDidGetWebApplicationInfo) | 272 OnDidGetWebApplicationInfo) |
| 266 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, | 273 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, |
| 267 OnInlineWebstoreInstall) | 274 OnInlineWebstoreInstall) |
| 268 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, | 275 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, |
| 269 OnGetAppInstallState); | 276 OnGetAppInstallState); |
| 270 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | |
| 271 IPC_MESSAGE_UNHANDLED(handled = false) | 277 IPC_MESSAGE_UNHANDLED(handled = false) |
| 272 IPC_END_MESSAGE_MAP() | 278 IPC_END_MESSAGE_MAP() |
| 273 return handled; | 279 return handled; |
| 274 } | 280 } |
| 275 | 281 |
| 276 bool TabHelper::OnMessageReceived(const IPC::Message& message, | 282 bool TabHelper::OnMessageReceived(const IPC::Message& message, |
| 277 content::RenderFrameHost* render_frame_host) { | 283 content::RenderFrameHost* render_frame_host) { |
| 278 bool handled = true; | 284 bool handled = true; |
| 279 IPC_BEGIN_MESSAGE_MAP(TabHelper, message) | 285 IPC_BEGIN_MESSAGE_MAP(TabHelper, message) |
| 280 IPC_MESSAGE_HANDLER(ExtensionHostMsg_DetailedConsoleMessageAdded, | 286 IPC_MESSAGE_HANDLER(ExtensionHostMsg_DetailedConsoleMessageAdded, |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 state = extension_misc::kAppStateInstalled; | 419 state = extension_misc::kAppStateInstalled; |
| 414 else if (disabled_extensions.GetHostedAppByURL(requestor_url)) | 420 else if (disabled_extensions.GetHostedAppByURL(requestor_url)) |
| 415 state = extension_misc::kAppStateDisabled; | 421 state = extension_misc::kAppStateDisabled; |
| 416 else | 422 else |
| 417 state = extension_misc::kAppStateNotInstalled; | 423 state = extension_misc::kAppStateNotInstalled; |
| 418 | 424 |
| 419 Send(new ExtensionMsg_GetAppInstallStateResponse( | 425 Send(new ExtensionMsg_GetAppInstallStateResponse( |
| 420 return_route_id, state, callback_id)); | 426 return_route_id, state, callback_id)); |
| 421 } | 427 } |
| 422 | 428 |
| 423 void TabHelper::OnRequest(const ExtensionHostMsg_Request_Params& request) { | |
| 424 extension_function_dispatcher_.Dispatch(request, | |
| 425 web_contents()->GetRenderViewHost()); | |
| 426 } | |
| 427 | |
| 428 void TabHelper::OnContentScriptsExecuting( | 429 void TabHelper::OnContentScriptsExecuting( |
| 429 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, | 430 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, |
| 430 const GURL& on_url) { | 431 const GURL& on_url) { |
| 431 FOR_EACH_OBSERVER( | 432 FOR_EACH_OBSERVER( |
| 432 ScriptExecutionObserver, | 433 ScriptExecutionObserver, |
| 433 script_execution_observers_, | 434 script_execution_observers_, |
| 434 OnScriptsExecuted(web_contents(), executing_scripts_map, on_url)); | 435 OnScriptsExecuted(web_contents(), executing_scripts_map, on_url)); |
| 435 } | 436 } |
| 436 | 437 |
| 437 void TabHelper::OnDetailedConsoleMessageAdded( | 438 void TabHelper::OnDetailedConsoleMessageAdded( |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 } | 586 } |
| 586 } | 587 } |
| 587 | 588 |
| 588 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) { | 589 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) { |
| 589 render_frame_host->Send( | 590 render_frame_host->Send( |
| 590 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(), | 591 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(), |
| 591 SessionTabHelper::IdForTab(web_contents()))); | 592 SessionTabHelper::IdForTab(web_contents()))); |
| 592 } | 593 } |
| 593 | 594 |
| 594 } // namespace extensions | 595 } // namespace extensions |
| OLD | NEW |