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