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/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.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" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #include "chrome/browser/extensions/webstore_inline_installer.h" | 25 #include "chrome/browser/extensions/webstore_inline_installer.h" |
| 26 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" | 26 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/sessions/session_tab_helper.h" | 28 #include "chrome/browser/sessions/session_tab_helper.h" |
| 29 #include "chrome/browser/shell_integration.h" | 29 #include "chrome/browser/shell_integration.h" |
| 30 #include "chrome/browser/ui/browser_commands.h" | 30 #include "chrome/browser/ui/browser_commands.h" |
| 31 #include "chrome/browser/ui/browser_dialogs.h" | 31 #include "chrome/browser/ui/browser_dialogs.h" |
| 32 #include "chrome/browser/ui/browser_finder.h" | 32 #include "chrome/browser/ui/browser_finder.h" |
| 33 #include "chrome/browser/web_applications/web_app.h" | 33 #include "chrome/browser/web_applications/web_app.h" |
| 34 #include "chrome/common/extensions/api/webstore/webstore_api_constants.h" | 34 #include "chrome/common/extensions/api/webstore/webstore_api_constants.h" |
| 35 #include "chrome/common/extensions/chrome_extension_messages.h" | |
| 36 #include "chrome/common/extensions/extension_constants.h" | 35 #include "chrome/common/extensions/extension_constants.h" |
| 37 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 36 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 38 #include "chrome/common/render_messages.h" | 37 #include "chrome/common/render_messages.h" |
| 39 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
| 40 #include "content/public/browser/invalidate_type.h" | 39 #include "content/public/browser/invalidate_type.h" |
| 41 #include "content/public/browser/navigation_controller.h" | 40 #include "content/public/browser/navigation_controller.h" |
| 42 #include "content/public/browser/navigation_entry.h" | 41 #include "content/public/browser/navigation_entry.h" |
| 43 #include "content/public/browser/navigation_handle.h" | 42 #include "content/public/browser/navigation_handle.h" |
| 44 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
| 45 #include "content/public/browser/notification_source.h" | 44 #include "content/public/browser/notification_source.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 56 #include "extensions/browser/extension_web_contents_observer.h" | 55 #include "extensions/browser/extension_web_contents_observer.h" |
| 57 #include "extensions/browser/image_loader.h" | 56 #include "extensions/browser/image_loader.h" |
| 58 #include "extensions/common/constants.h" | 57 #include "extensions/common/constants.h" |
| 59 #include "extensions/common/extension.h" | 58 #include "extensions/common/extension.h" |
| 60 #include "extensions/common/extension_icon_set.h" | 59 #include "extensions/common/extension_icon_set.h" |
| 61 #include "extensions/common/extension_messages.h" | 60 #include "extensions/common/extension_messages.h" |
| 62 #include "extensions/common/extension_resource.h" | 61 #include "extensions/common/extension_resource.h" |
| 63 #include "extensions/common/extension_urls.h" | 62 #include "extensions/common/extension_urls.h" |
| 64 #include "extensions/common/feature_switch.h" | 63 #include "extensions/common/feature_switch.h" |
| 65 #include "extensions/common/manifest_handlers/icons_handler.h" | 64 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 65 #include "services/service_manager/public/cpp/interface_provider.h" | |
| 66 #include "url/url_constants.h" | 66 #include "url/url_constants.h" |
| 67 | 67 |
| 68 #if defined(OS_WIN) | 68 #if defined(OS_WIN) |
| 69 #include "chrome/browser/web_applications/web_app_win.h" | 69 #include "chrome/browser/web_applications/web_app_win.h" |
| 70 #endif | 70 #endif |
| 71 | 71 |
| 72 using content::NavigationController; | 72 using content::NavigationController; |
| 73 using content::NavigationEntry; | 73 using content::NavigationEntry; |
| 74 using content::WebContents; | 74 using content::WebContents; |
| 75 | 75 |
| 76 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::TabHelper); | 76 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::TabHelper); |
| 77 | 77 |
| 78 namespace extensions { | 78 namespace extensions { |
| 79 | 79 |
| 80 // A helper class to watch the progress of inline installation and update the | 80 // A helper class to watch the progress of inline installation and update the |
| 81 // renderer. Owned by the TabHelper. | 81 // renderer. Owned by the TabHelper. |
| 82 class TabHelper::InlineInstallObserver : public InstallObserver { | 82 class TabHelper::InlineInstallObserver : public InstallObserver { |
| 83 public: | 83 public: |
| 84 InlineInstallObserver(TabHelper* tab_helper, | 84 InlineInstallObserver( |
| 85 content::BrowserContext* browser_context, | 85 TabHelper* tab_helper, |
|
Devlin
2017/04/28 18:33:02
nit: no need to pass a TabHelper here now.
catmullings
2017/05/02 19:02:14
Done.
| |
| 86 int routing_id, | 86 content::BrowserContext* browser_context, |
| 87 const ExtensionId& extension_id, | 87 const ExtensionId& extension_id, |
| 88 bool observe_download_progress, | 88 bool observe_download_progress, |
| 89 bool observe_install_stage) | 89 bool observe_install_stage, |
| 90 : tab_helper_(tab_helper), | 90 mojom::InlineInstallProgressListenerPtr install_progress_listener) |
| 91 routing_id_(routing_id), | 91 : extension_id_(extension_id), |
| 92 extension_id_(extension_id), | |
| 93 observe_download_progress_(observe_download_progress), | 92 observe_download_progress_(observe_download_progress), |
| 94 observe_install_stage_(observe_install_stage), | 93 observe_install_stage_(observe_install_stage), |
| 95 install_observer_(this) { | 94 install_observer_(this), |
| 95 inline_install_progress_listener_( | |
| 96 std::move(install_progress_listener)) { | |
| 96 DCHECK(tab_helper); | 97 DCHECK(tab_helper); |
| 97 DCHECK(observe_download_progress || observe_install_stage); | 98 DCHECK(observe_download_progress || observe_install_stage); |
| 98 InstallTracker* install_tracker = | 99 InstallTracker* install_tracker = |
| 99 InstallTrackerFactory::GetForBrowserContext(browser_context); | 100 InstallTrackerFactory::GetForBrowserContext(browser_context); |
| 100 if (install_tracker) | 101 if (install_tracker) |
| 101 install_observer_.Add(install_tracker); | 102 install_observer_.Add(install_tracker); |
| 102 } | 103 } |
| 103 ~InlineInstallObserver() override {} | 104 ~InlineInstallObserver() override {} |
| 104 | 105 |
| 105 private: | 106 private: |
| 106 // InstallObserver: | 107 // InstallObserver: |
| 107 void OnBeginExtensionDownload(const ExtensionId& extension_id) override { | 108 void OnBeginExtensionDownload(const ExtensionId& extension_id) override { |
| 108 SendInstallStageChangedMessage(extension_id, | 109 SendInstallStageChangedMessage(extension_id, |
| 109 api::webstore::INSTALL_STAGE_DOWNLOADING); | 110 api::webstore::INSTALL_STAGE_DOWNLOADING); |
| 110 } | 111 } |
| 111 void OnDownloadProgress(const ExtensionId& extension_id, | 112 void OnDownloadProgress(const ExtensionId& extension_id, |
| 112 int percent_downloaded) override { | 113 int percent_downloaded) override { |
| 113 if (observe_download_progress_ && extension_id == extension_id_) { | 114 if (observe_download_progress_ && extension_id == extension_id_) { |
| 114 tab_helper_->Send(new ExtensionMsg_InlineInstallDownloadProgress( | 115 inline_install_progress_listener_->InlineInstallDownloadProgress( |
| 115 routing_id_, percent_downloaded)); | 116 percent_downloaded); |
| 116 } | 117 } |
| 117 } | 118 } |
| 118 void OnBeginCrxInstall(const ExtensionId& extension_id) override { | 119 void OnBeginCrxInstall(const ExtensionId& extension_id) override { |
| 119 SendInstallStageChangedMessage(extension_id, | 120 SendInstallStageChangedMessage(extension_id, |
| 120 api::webstore::INSTALL_STAGE_INSTALLING); | 121 api::webstore::INSTALL_STAGE_INSTALLING); |
| 121 } | 122 } |
| 122 void OnShutdown() override { install_observer_.RemoveAll(); } | 123 void OnShutdown() override { install_observer_.RemoveAll(); } |
| 123 | 124 |
| 124 void SendInstallStageChangedMessage(const ExtensionId& extension_id, | 125 void SendInstallStageChangedMessage(const ExtensionId& extension_id, |
| 125 api::webstore::InstallStage stage) { | 126 api::webstore::InstallStage stage) { |
| 126 if (observe_install_stage_ && extension_id == extension_id_) { | 127 if (observe_install_stage_ && extension_id == extension_id_) |
| 127 tab_helper_->Send( | 128 inline_install_progress_listener_->InlineInstallStageChanged(stage); |
| 128 new ExtensionMsg_InlineInstallStageChanged(routing_id_, stage)); | |
| 129 } | |
| 130 } | 129 } |
| 131 | 130 |
| 132 // The owning TabHelper (guaranteed to be valid). | |
| 133 TabHelper* const tab_helper_; | |
| 134 | |
| 135 // The routing id to use in sending IPC updates. | |
| 136 int routing_id_; | |
| 137 | |
| 138 // The id of the extension to observe. | 131 // The id of the extension to observe. |
| 139 ExtensionId extension_id_; | 132 ExtensionId extension_id_; |
| 140 | 133 |
| 141 // Whether or not to observe download/install progress. | 134 // Whether or not to observe download/install progress. |
| 142 const bool observe_download_progress_; | 135 const bool observe_download_progress_; |
| 143 const bool observe_install_stage_; | 136 const bool observe_install_stage_; |
| 144 | 137 |
| 145 ScopedObserver<InstallTracker, InstallObserver> install_observer_; | 138 ScopedObserver<InstallTracker, InstallObserver> install_observer_; |
| 146 | 139 |
| 140 extensions::mojom::InlineInstallProgressListenerPtr | |
| 141 inline_install_progress_listener_; | |
| 142 | |
| 147 DISALLOW_COPY_AND_ASSIGN(InlineInstallObserver); | 143 DISALLOW_COPY_AND_ASSIGN(InlineInstallObserver); |
| 148 }; | 144 }; |
| 149 | 145 |
| 146 TabHelper::~TabHelper() { | |
| 147 RemoveScriptExecutionObserver(ActivityLog::GetInstance(profile_)); | |
| 148 } | |
| 149 | |
| 150 TabHelper::TabHelper(content::WebContents* web_contents) | 150 TabHelper::TabHelper(content::WebContents* web_contents) |
| 151 : content::WebContentsObserver(web_contents), | 151 : content::WebContentsObserver(web_contents), |
| 152 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), | 152 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), |
| 153 extension_app_(NULL), | 153 extension_app_(NULL), |
| 154 pending_web_app_action_(NONE), | 154 pending_web_app_action_(NONE), |
| 155 last_committed_nav_entry_unique_id_(0), | 155 last_committed_nav_entry_unique_id_(0), |
| 156 update_shortcut_on_load_complete_(false), | 156 update_shortcut_on_load_complete_(false), |
| 157 script_executor_( | 157 script_executor_( |
| 158 new ScriptExecutor(web_contents, &script_execution_observers_)), | 158 new ScriptExecutor(web_contents, &script_execution_observers_)), |
| 159 extension_action_runner_(new ExtensionActionRunner(web_contents)), | 159 extension_action_runner_(new ExtensionActionRunner(web_contents)), |
| 160 webstore_inline_installer_factory_(new WebstoreInlineInstallerFactory()), | 160 webstore_inline_installer_factory_(new WebstoreInlineInstallerFactory()), |
| 161 registry_observer_(this), | 161 registry_observer_(this), |
| 162 bindings_(web_contents, this), | |
| 162 image_loader_ptr_factory_(this), | 163 image_loader_ptr_factory_(this), |
| 163 weak_ptr_factory_(this) { | 164 weak_ptr_factory_(this) { |
| 164 // The ActiveTabPermissionManager requires a session ID; ensure this | 165 // The ActiveTabPermissionManager requires a session ID; ensure this |
| 165 // WebContents has one. | 166 // WebContents has one. |
| 166 SessionTabHelper::CreateForWebContents(web_contents); | 167 SessionTabHelper::CreateForWebContents(web_contents); |
| 167 // The Unretained() is safe because ForEachFrame is synchronous. | 168 // The Unretained() is safe because ForEachFrame is synchronous. |
| 168 web_contents->ForEachFrame( | 169 web_contents->ForEachFrame( |
| 169 base::Bind(&TabHelper::SetTabId, base::Unretained(this))); | 170 base::Bind(&TabHelper::SetTabId, base::Unretained(this))); |
| 170 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( | 171 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( |
| 171 web_contents, | 172 web_contents, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 185 set_delegate(this); | 186 set_delegate(this); |
| 186 | 187 |
| 187 BookmarkManagerPrivateDragEventRouter::CreateForWebContents(web_contents); | 188 BookmarkManagerPrivateDragEventRouter::CreateForWebContents(web_contents); |
| 188 | 189 |
| 189 registrar_.Add(this, | 190 registrar_.Add(this, |
| 190 content::NOTIFICATION_LOAD_STOP, | 191 content::NOTIFICATION_LOAD_STOP, |
| 191 content::Source<NavigationController>( | 192 content::Source<NavigationController>( |
| 192 &web_contents->GetController())); | 193 &web_contents->GetController())); |
| 193 } | 194 } |
| 194 | 195 |
| 195 TabHelper::~TabHelper() { | |
| 196 RemoveScriptExecutionObserver(ActivityLog::GetInstance(profile_)); | |
| 197 } | |
| 198 | |
| 199 void TabHelper::CreateHostedAppFromWebContents() { | 196 void TabHelper::CreateHostedAppFromWebContents() { |
| 200 DCHECK(CanCreateBookmarkApp()); | 197 DCHECK(CanCreateBookmarkApp()); |
| 201 if (pending_web_app_action_ != NONE) | 198 if (pending_web_app_action_ != NONE) |
| 202 return; | 199 return; |
| 203 | 200 |
| 204 // Start fetching web app info for CreateApplicationShortcut dialog and show | 201 // Start fetching web app info for CreateApplicationShortcut dialog and show |
| 205 // the dialog when the data is available in OnDidGetApplicationInfo. | 202 // the dialog when the data is available in OnDidGetApplicationInfo. |
| 206 GetApplicationInfo(CREATE_HOSTED_APP); | 203 GetApplicationInfo(CREATE_HOSTED_APP); |
| 207 } | 204 } |
| 208 | 205 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 OnDidGetWebApplicationInfo) | 336 OnDidGetWebApplicationInfo) |
| 340 IPC_MESSAGE_UNHANDLED(handled = false) | 337 IPC_MESSAGE_UNHANDLED(handled = false) |
| 341 IPC_END_MESSAGE_MAP() | 338 IPC_END_MESSAGE_MAP() |
| 342 return handled; | 339 return handled; |
| 343 } | 340 } |
| 344 | 341 |
| 345 bool TabHelper::OnMessageReceived(const IPC::Message& message, | 342 bool TabHelper::OnMessageReceived(const IPC::Message& message, |
| 346 content::RenderFrameHost* render_frame_host) { | 343 content::RenderFrameHost* render_frame_host) { |
| 347 bool handled = true; | 344 bool handled = true; |
| 348 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(TabHelper, message, render_frame_host) | 345 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(TabHelper, message, render_frame_host) |
| 349 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall, | |
| 350 OnInlineWebstoreInstall) | |
| 351 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, | 346 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, |
| 352 OnGetAppInstallState) | 347 OnGetAppInstallState) |
| 353 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, | 348 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, |
| 354 OnContentScriptsExecuting) | 349 OnContentScriptsExecuting) |
| 355 IPC_MESSAGE_UNHANDLED(handled = false) | 350 IPC_MESSAGE_UNHANDLED(handled = false) |
| 356 IPC_END_MESSAGE_MAP() | 351 IPC_END_MESSAGE_MAP() |
| 357 return handled; | 352 return handled; |
| 358 } | 353 } |
| 359 | 354 |
| 360 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, | 355 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 NOTREACHED(); | 396 NOTREACHED(); |
| 402 break; | 397 break; |
| 403 } | 398 } |
| 404 | 399 |
| 405 // The hosted app action will be cleared once the installation completes or | 400 // The hosted app action will be cleared once the installation completes or |
| 406 // fails. | 401 // fails. |
| 407 if (pending_web_app_action_ != CREATE_HOSTED_APP) | 402 if (pending_web_app_action_ != CREATE_HOSTED_APP) |
| 408 pending_web_app_action_ = NONE; | 403 pending_web_app_action_ = NONE; |
| 409 } | 404 } |
| 410 | 405 |
| 411 void TabHelper::OnInlineWebstoreInstall(content::RenderFrameHost* host, | 406 void TabHelper::DoInlineInstall( |
| 412 int install_id, | 407 int install_id, |
| 413 int return_route_id, | 408 const std::string& webstore_item_id, |
| 414 const std::string& webstore_item_id, | 409 int listeners_mask, |
| 415 int listeners_mask) { | 410 mojom::InlineInstallProgressListenerPtr install_progress_listener, |
| 411 const DoInlineInstallCallback& callback) { | |
| 412 content::RenderFrameHost* host = web_contents()->GetMainFrame(); | |
| 413 if (bindings_.GetCurrentTargetFrame() != host) { | |
| 414 NOTREACHED(); | |
| 415 return; | |
| 416 } | |
| 417 | |
| 416 GURL requestor_url(host->GetLastCommittedURL()); | 418 GURL requestor_url(host->GetLastCommittedURL()); |
| 417 // Check that the listener is reasonable. We should never get anything other | 419 // Check that the listener is reasonable. We should never get anything other |
| 418 // than an install stage listener, a download listener, or both. | 420 // than an install stage listener, a download listener, or both. |
| 419 // The requestor_url should also be valid, and the renderer should disallow | 421 // The requestor_url should also be valid, and the renderer should disallow |
| 420 // child frames from sending the IPC. | 422 // child frames from sending the IPC. |
| 421 if ((listeners_mask & ~(api::webstore::INSTALL_STAGE_LISTENER | | 423 if ((listeners_mask & ~(api::webstore::INSTALL_STAGE_LISTENER | |
| 422 api::webstore::DOWNLOAD_PROGRESS_LISTENER)) != 0 || | 424 api::webstore::DOWNLOAD_PROGRESS_LISTENER)) != 0 || |
| 423 !requestor_url.is_valid() || requestor_url == url::kAboutBlankURL || | 425 !requestor_url.is_valid() || requestor_url == url::kAboutBlankURL) { |
| 424 host->GetParent()) { | |
| 425 NOTREACHED(); | 426 NOTREACHED(); |
| 426 return; | 427 return; |
| 427 } | 428 } |
| 428 | 429 |
| 429 if (pending_inline_installations_.count(webstore_item_id) != 0) { | 430 if (pending_inline_installations_.count(webstore_item_id) != 0) { |
| 430 Send(new ExtensionMsg_InlineWebstoreInstallResponse( | 431 callback.Run(install_id, false, webstore_install::kInstallInProgressError, |
| 431 return_route_id, install_id, false, | 432 webstore_install::INSTALL_IN_PROGRESS); |
| 432 webstore_install::kInstallInProgressError, | |
| 433 webstore_install::INSTALL_IN_PROGRESS)); | |
| 434 return; | 433 return; |
| 435 } | 434 } |
| 436 | 435 |
| 437 pending_inline_installations_.insert(webstore_item_id); | 436 pending_inline_installations_.insert(webstore_item_id); |
| 438 // Inform the Webstore API that an inline install is happening, in case the | 437 // Inform the Webstore API that an inline install is happening, in case the |
| 439 // page requested status updates. | 438 // page requested status updates. |
| 440 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); | 439 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); |
| 441 if (registry->disabled_extensions().Contains(webstore_item_id) && | 440 if (registry->disabled_extensions().Contains(webstore_item_id) && |
| 442 (ExtensionPrefs::Get(profile_)->GetDisableReasons(webstore_item_id) & | 441 (ExtensionPrefs::Get(profile_)->GetDisableReasons(webstore_item_id) & |
| 443 Extension::DISABLE_PERMISSIONS_INCREASE) != 0) { | 442 Extension::DISABLE_PERMISSIONS_INCREASE) != 0) { |
| 444 // The extension was disabled due to permissions increase. Prompt for | 443 // The extension was disabled due to permissions increase. Prompt for |
| 445 // re-enable. | 444 // re-enable. |
| 446 // TODO(devlin): We should also prompt for re-enable for other reasons, | 445 // TODO(devlin): We should also prompt for re-enable for other reasons, |
| 447 // like user-disabled. | 446 // like user-disabled. |
| 448 // For clarity, explicitly end any prior reenable process. | 447 // For clarity, explicitly end any prior reenable process. |
| 449 extension_reenabler_.reset(); | 448 extension_reenabler_.reset(); |
| 450 extension_reenabler_ = ExtensionReenabler::PromptForReenable( | 449 extension_reenabler_ = ExtensionReenabler::PromptForReenable( |
| 451 registry->disabled_extensions().GetByID(webstore_item_id), profile_, | 450 registry->disabled_extensions().GetByID(webstore_item_id), profile_, |
| 452 web_contents(), requestor_url, | 451 web_contents(), requestor_url, |
| 453 base::Bind(&TabHelper::OnReenableComplete, | 452 base::Bind(&TabHelper::OnReenableComplete, |
| 454 weak_ptr_factory_.GetWeakPtr(), install_id, | 453 weak_ptr_factory_.GetWeakPtr(), install_id, webstore_item_id, |
| 455 return_route_id, webstore_item_id)); | 454 callback)); |
| 456 } else { | 455 } else { |
| 457 // TODO(devlin): We should adddress the case of the extension already | 456 // TODO(devlin): We should adddress the case of the extension already |
| 458 // being installed and enabled. | 457 // being installed and enabled. |
| 459 bool observe_download_progress = | 458 bool observe_download_progress = |
| 460 (listeners_mask & api::webstore::DOWNLOAD_PROGRESS_LISTENER) != 0; | 459 (listeners_mask & api::webstore::DOWNLOAD_PROGRESS_LISTENER) != 0; |
| 461 bool observe_install_stage = | 460 bool observe_install_stage = |
| 462 (listeners_mask & api::webstore::INSTALL_STAGE_LISTENER) != 0; | 461 (listeners_mask & api::webstore::INSTALL_STAGE_LISTENER) != 0; |
| 463 if (observe_install_stage || observe_download_progress) { | 462 if (observe_install_stage || observe_download_progress) { |
| 464 DCHECK_EQ(0u, install_observers_.count(webstore_item_id)); | 463 DCHECK_EQ(0u, install_observers_.count(webstore_item_id)); |
| 465 install_observers_[webstore_item_id] = | 464 install_observers_[webstore_item_id] = |
| 466 base::MakeUnique<InlineInstallObserver>( | 465 base::MakeUnique<InlineInstallObserver>( |
| 467 this, web_contents()->GetBrowserContext(), return_route_id, | 466 this, web_contents()->GetBrowserContext(), webstore_item_id, |
| 468 webstore_item_id, observe_download_progress, | 467 observe_download_progress, observe_install_stage, |
| 469 observe_install_stage); | 468 std::move(install_progress_listener)); |
| 470 } | 469 } |
| 471 | 470 |
| 472 WebstoreStandaloneInstaller::Callback callback = base::Bind( | 471 WebstoreStandaloneInstaller::Callback completion_callback = base::Bind( |
| 473 &TabHelper::OnInlineInstallComplete, weak_ptr_factory_.GetWeakPtr(), | 472 &TabHelper::OnInlineInstallComplete, weak_ptr_factory_.GetWeakPtr(), |
| 474 install_id, return_route_id, webstore_item_id); | 473 callback, install_id, webstore_item_id); |
| 475 scoped_refptr<WebstoreInlineInstaller> installer( | 474 scoped_refptr<WebstoreInlineInstaller> installer( |
| 476 webstore_inline_installer_factory_->CreateInstaller( | 475 webstore_inline_installer_factory_->CreateInstaller( |
| 477 web_contents(), host, webstore_item_id, requestor_url, callback)); | 476 web_contents(), host, webstore_item_id, requestor_url, |
| 477 completion_callback)); | |
| 478 installer->BeginInstall(); | 478 installer->BeginInstall(); |
| 479 } | 479 } |
| 480 } | 480 } |
| 481 | 481 |
| 482 void TabHelper::OnGetAppInstallState(content::RenderFrameHost* host, | 482 void TabHelper::OnGetAppInstallState(content::RenderFrameHost* host, |
| 483 const GURL& requestor_url, | 483 const GURL& requestor_url, |
| 484 int return_route_id, | 484 int return_route_id, |
| 485 int callback_id) { | 485 int callback_id) { |
| 486 ExtensionRegistry* registry = | 486 ExtensionRegistry* registry = |
| 487 ExtensionRegistry::Get(web_contents()->GetBrowserContext()); | 487 ExtensionRegistry::Get(web_contents()->GetBrowserContext()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 extension_app_icon_ = *image.ToSkBitmap(); | 555 extension_app_icon_ = *image.ToSkBitmap(); |
| 556 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); | 556 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
| 557 } | 557 } |
| 558 } | 558 } |
| 559 | 559 |
| 560 WindowController* TabHelper::GetExtensionWindowController() const { | 560 WindowController* TabHelper::GetExtensionWindowController() const { |
| 561 return ExtensionTabUtil::GetWindowControllerOfTab(web_contents()); | 561 return ExtensionTabUtil::GetWindowControllerOfTab(web_contents()); |
| 562 } | 562 } |
| 563 | 563 |
| 564 void TabHelper::OnReenableComplete(int install_id, | 564 void TabHelper::OnReenableComplete(int install_id, |
| 565 int return_route_id, | |
| 566 const ExtensionId& extension_id, | 565 const ExtensionId& extension_id, |
| 566 const DoInlineInstallCallback& callback, | |
| 567 ExtensionReenabler::ReenableResult result) { | 567 ExtensionReenabler::ReenableResult result) { |
| 568 // Map the re-enable results to webstore-install results. | 568 // Map the re-enable results to webstore-install results. |
| 569 webstore_install::Result webstore_result = webstore_install::SUCCESS; | 569 webstore_install::Result webstore_result = webstore_install::SUCCESS; |
| 570 std::string error; | 570 std::string error; |
| 571 switch (result) { | 571 switch (result) { |
| 572 case ExtensionReenabler::REENABLE_SUCCESS: | 572 case ExtensionReenabler::REENABLE_SUCCESS: |
| 573 break; // already set | 573 break; // already set |
| 574 case ExtensionReenabler::USER_CANCELED: | 574 case ExtensionReenabler::USER_CANCELED: |
| 575 webstore_result = webstore_install::USER_CANCELLED; | 575 webstore_result = webstore_install::USER_CANCELLED; |
| 576 error = "User canceled install."; | 576 error = "User canceled install."; |
| 577 break; | 577 break; |
| 578 case ExtensionReenabler::NOT_ALLOWED: | 578 case ExtensionReenabler::NOT_ALLOWED: |
| 579 webstore_result = webstore_install::NOT_PERMITTED; | 579 webstore_result = webstore_install::NOT_PERMITTED; |
| 580 error = "Install not permitted."; | 580 error = "Install not permitted."; |
| 581 break; | 581 break; |
| 582 case ExtensionReenabler::ABORTED: | 582 case ExtensionReenabler::ABORTED: |
| 583 webstore_result = webstore_install::ABORTED; | 583 webstore_result = webstore_install::ABORTED; |
| 584 error = "Aborted due to tab closing."; | 584 error = "Aborted due to tab closing."; |
| 585 break; | 585 break; |
| 586 } | 586 } |
| 587 | 587 |
| 588 OnInlineInstallComplete(install_id, return_route_id, extension_id, | 588 OnInlineInstallComplete(callback, install_id, extension_id, |
| 589 result == ExtensionReenabler::REENABLE_SUCCESS, error, | 589 result == ExtensionReenabler::REENABLE_SUCCESS, error, |
| 590 webstore_result); | 590 webstore_result); |
| 591 // Note: ExtensionReenabler contained the callback with the curried-in | 591 // Note: ExtensionReenabler contained the callback with the curried-in |
| 592 // |extension_id|; delete it last. | 592 // |extension_id|; delete it last. |
| 593 extension_reenabler_.reset(); | 593 extension_reenabler_.reset(); |
| 594 } | 594 } |
| 595 | 595 |
| 596 void TabHelper::OnInlineInstallComplete(int install_id, | 596 void TabHelper::OnInlineInstallComplete(const DoInlineInstallCallback& callback, |
| 597 int return_route_id, | 597 int install_id, |
| 598 const ExtensionId& extension_id, | 598 const ExtensionId& extension_id, |
| 599 bool success, | 599 bool success, |
| 600 const std::string& error, | 600 const std::string& error, |
| 601 webstore_install::Result result) { | 601 webstore_install::Result result) { |
| 602 DCHECK_EQ(1u, pending_inline_installations_.count(extension_id)); | 602 DCHECK_EQ(1u, pending_inline_installations_.count(extension_id)); |
| 603 pending_inline_installations_.erase(extension_id); | 603 pending_inline_installations_.erase(extension_id); |
| 604 install_observers_.erase(extension_id); | 604 install_observers_.erase(extension_id); |
| 605 Send(new ExtensionMsg_InlineWebstoreInstallResponse( | 605 callback.Run(install_id, success, success ? std::string() : error, result); |
| 606 return_route_id, | |
| 607 install_id, | |
| 608 success, | |
| 609 success ? std::string() : error, | |
| 610 result)); | |
| 611 } | 606 } |
| 612 | 607 |
| 613 WebContents* TabHelper::GetAssociatedWebContents() const { | 608 WebContents* TabHelper::GetAssociatedWebContents() const { |
| 614 return web_contents(); | 609 return web_contents(); |
| 615 } | 610 } |
| 616 | 611 |
| 617 void TabHelper::OnExtensionUnloaded( | 612 void TabHelper::OnExtensionUnloaded( |
| 618 content::BrowserContext* browser_context, | 613 content::BrowserContext* browser_context, |
| 619 const Extension* extension, | 614 const Extension* extension, |
| 620 UnloadedExtensionInfo::Reason reason) { | 615 UnloadedExtensionInfo::Reason reason) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 } | 649 } |
| 655 } | 650 } |
| 656 | 651 |
| 657 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) { | 652 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) { |
| 658 render_frame_host->Send( | 653 render_frame_host->Send( |
| 659 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(), | 654 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(), |
| 660 SessionTabHelper::IdForTab(web_contents()))); | 655 SessionTabHelper::IdForTab(web_contents()))); |
| 661 } | 656 } |
| 662 | 657 |
| 663 } // namespace extensions | 658 } // namespace extensions |
| OLD | NEW |