Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: chrome/browser/extensions/tab_helper.cc

Issue 2791533002: Convert Web Store Inline Install IPCs to mojo (Closed)
Patch Set: Addressed Devlin's comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/extensions/tab_helper.h ('k') | chrome/common/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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(TabHelper* tab_helper,
85 content::BrowserContext* browser_context, 85 content::BrowserContext* browser_context,
86 int routing_id,
87 const ExtensionId& extension_id, 86 const ExtensionId& extension_id,
88 bool observe_download_progress, 87 bool observe_download_progress,
89 bool observe_install_stage) 88 bool observe_install_stage)
90 : tab_helper_(tab_helper), 89 : tab_helper_(tab_helper),
91 routing_id_(routing_id),
92 extension_id_(extension_id), 90 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 DCHECK(tab_helper);
97 DCHECK(observe_download_progress || observe_install_stage); 95 DCHECK(observe_download_progress || observe_install_stage);
98 InstallTracker* install_tracker = 96 InstallTracker* install_tracker =
99 InstallTrackerFactory::GetForBrowserContext(browser_context); 97 InstallTrackerFactory::GetForBrowserContext(browser_context);
100 if (install_tracker) 98 if (install_tracker)
101 install_observer_.Add(install_tracker); 99 install_observer_.Add(install_tracker);
102 } 100 }
103 ~InlineInstallObserver() override {} 101 ~InlineInstallObserver() override {}
104 102
105 private: 103 private:
106 // InstallObserver: 104 // InstallObserver:
107 void OnBeginExtensionDownload(const ExtensionId& extension_id) override { 105 void OnBeginExtensionDownload(const ExtensionId& extension_id) override {
108 SendInstallStageChangedMessage(extension_id, 106 SendInstallStageChangedMessage(extension_id,
109 api::webstore::INSTALL_STAGE_DOWNLOADING); 107 api::webstore::INSTALL_STAGE_DOWNLOADING);
110 } 108 }
111 void OnDownloadProgress(const ExtensionId& extension_id, 109 void OnDownloadProgress(const ExtensionId& extension_id,
112 int percent_downloaded) override { 110 int percent_downloaded) override {
113 if (observe_download_progress_ && extension_id == extension_id_) { 111 if (observe_download_progress_ && extension_id == extension_id_) {
114 tab_helper_->Send(new ExtensionMsg_InlineInstallDownloadProgress( 112 auto iter =
115 routing_id_, percent_downloaded)); 113 tab_helper_->inline_install_progress_listeners_.find(extension_id);
114 DCHECK(iter != tab_helper_->inline_install_progress_listeners_.end());
115 iter->second->InlineInstallDownloadProgress(percent_downloaded);
116 } 116 }
117 } 117 }
118 void OnBeginCrxInstall(const ExtensionId& extension_id) override { 118 void OnBeginCrxInstall(const ExtensionId& extension_id) override {
119 SendInstallStageChangedMessage(extension_id, 119 SendInstallStageChangedMessage(extension_id,
120 api::webstore::INSTALL_STAGE_INSTALLING); 120 api::webstore::INSTALL_STAGE_INSTALLING);
121 } 121 }
122 void OnShutdown() override { install_observer_.RemoveAll(); } 122 void OnShutdown() override { install_observer_.RemoveAll(); }
123 123
124 void SendInstallStageChangedMessage(const ExtensionId& extension_id, 124 void SendInstallStageChangedMessage(const ExtensionId& extension_id,
125 api::webstore::InstallStage stage) { 125 api::webstore::InstallStage stage) {
126 if (observe_install_stage_ && extension_id == extension_id_) { 126 if (observe_install_stage_ && extension_id == extension_id_) {
127 tab_helper_->Send( 127 auto iter =
128 new ExtensionMsg_InlineInstallStageChanged(routing_id_, stage)); 128 tab_helper_->inline_install_progress_listeners_.find(extension_id);
129 DCHECK(iter != tab_helper_->inline_install_progress_listeners_.end());
130 iter->second->InlineInstallStageChanged(stage);
129 } 131 }
130 } 132 }
131 133
132 // The owning TabHelper (guaranteed to be valid). 134 // The owning TabHelper (guaranteed to be valid).
133 TabHelper* const tab_helper_; 135 TabHelper* const tab_helper_;
134 136
135 // The routing id to use in sending IPC updates.
136 int routing_id_;
137
138 // The id of the extension to observe. 137 // The id of the extension to observe.
139 ExtensionId extension_id_; 138 ExtensionId extension_id_;
140 139
141 // Whether or not to observe download/install progress. 140 // Whether or not to observe download/install progress.
142 const bool observe_download_progress_; 141 const bool observe_download_progress_;
143 const bool observe_install_stage_; 142 const bool observe_install_stage_;
144 143
145 ScopedObserver<InstallTracker, InstallObserver> install_observer_; 144 ScopedObserver<InstallTracker, InstallObserver> install_observer_;
146 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
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
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
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 const std::string& webstore_item_id,
413 int return_route_id, 411 int listeners_mask,
414 const std::string& webstore_item_id, 412 mojom::InlineInstallProgressListenerPtr install_progress_listener,
415 int listeners_mask) { 413 DoInlineInstallCallback callback) {
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 (base::ContainsKey(install_callbacks_, webstore_item_id)) {
430 Send(new ExtensionMsg_InlineWebstoreInstallResponse( 433 std::move(callback).Run(false, webstore_install::kInstallInProgressError,
431 return_route_id, install_id, false, 434 webstore_install::INSTALL_IN_PROGRESS);
432 webstore_install::kInstallInProgressError,
433 webstore_install::INSTALL_IN_PROGRESS));
434 return; 435 return;
435 } 436 }
436 437
437 pending_inline_installations_.insert(webstore_item_id); 438 install_callbacks_[webstore_item_id] = std::move(callback);
439 inline_install_progress_listeners_[webstore_item_id] =
440 std::move(install_progress_listener);
438 // Inform the Webstore API that an inline install is happening, in case the 441 // Inform the Webstore API that an inline install is happening, in case the
439 // page requested status updates. 442 // page requested status updates.
440 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); 443 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
441 if (registry->disabled_extensions().Contains(webstore_item_id) && 444 if (registry->disabled_extensions().Contains(webstore_item_id) &&
442 (ExtensionPrefs::Get(profile_)->GetDisableReasons(webstore_item_id) & 445 (ExtensionPrefs::Get(profile_)->GetDisableReasons(webstore_item_id) &
443 Extension::DISABLE_PERMISSIONS_INCREASE) != 0) { 446 Extension::DISABLE_PERMISSIONS_INCREASE) != 0) {
444 // The extension was disabled due to permissions increase. Prompt for 447 // The extension was disabled due to permissions increase. Prompt for
445 // re-enable. 448 // re-enable.
446 // TODO(devlin): We should also prompt for re-enable for other reasons, 449 // TODO(devlin): We should also prompt for re-enable for other reasons,
447 // like user-disabled. 450 // like user-disabled.
448 // For clarity, explicitly end any prior reenable process. 451 // For clarity, explicitly end any prior reenable process.
449 extension_reenabler_.reset(); 452 extension_reenabler_.reset();
450 extension_reenabler_ = ExtensionReenabler::PromptForReenable( 453 extension_reenabler_ = ExtensionReenabler::PromptForReenable(
451 registry->disabled_extensions().GetByID(webstore_item_id), profile_, 454 registry->disabled_extensions().GetByID(webstore_item_id), profile_,
452 web_contents(), requestor_url, 455 web_contents(), requestor_url,
453 base::Bind(&TabHelper::OnReenableComplete, 456 base::Bind(&TabHelper::OnReenableComplete,
454 weak_ptr_factory_.GetWeakPtr(), install_id, 457 weak_ptr_factory_.GetWeakPtr(), webstore_item_id));
455 return_route_id, 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 this, web_contents()->GetBrowserContext(), webstore_item_id,
468 webstore_item_id, observe_download_progress, 470 observe_download_progress, observe_install_stage);
469 observe_install_stage);
470 } 471 }
471 472
472 WebstoreStandaloneInstaller::Callback callback = base::Bind( 473 WebstoreStandaloneInstaller::Callback callback =
473 &TabHelper::OnInlineInstallComplete, weak_ptr_factory_.GetWeakPtr(), 474 base::Bind(&TabHelper::OnInlineInstallComplete,
474 install_id, return_route_id, webstore_item_id); 475 weak_ptr_factory_.GetWeakPtr(), webstore_item_id);
475 scoped_refptr<WebstoreInlineInstaller> installer( 476 scoped_refptr<WebstoreInlineInstaller> installer(
476 webstore_inline_installer_factory_->CreateInstaller( 477 webstore_inline_installer_factory_->CreateInstaller(
477 web_contents(), host, webstore_item_id, requestor_url, callback)); 478 web_contents(), host, webstore_item_id, requestor_url, callback));
478 installer->BeginInstall(); 479 installer->BeginInstall();
479 } 480 }
480 } 481 }
481 482
482 void TabHelper::OnGetAppInstallState(content::RenderFrameHost* host, 483 void TabHelper::OnGetAppInstallState(content::RenderFrameHost* host,
483 const GURL& requestor_url, 484 const GURL& requestor_url,
484 int return_route_id, 485 int return_route_id,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 if (!image.IsEmpty()) { 555 if (!image.IsEmpty()) {
555 extension_app_icon_ = *image.ToSkBitmap(); 556 extension_app_icon_ = *image.ToSkBitmap();
556 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); 557 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
557 } 558 }
558 } 559 }
559 560
560 WindowController* TabHelper::GetExtensionWindowController() const { 561 WindowController* TabHelper::GetExtensionWindowController() const {
561 return ExtensionTabUtil::GetWindowControllerOfTab(web_contents()); 562 return ExtensionTabUtil::GetWindowControllerOfTab(web_contents());
562 } 563 }
563 564
564 void TabHelper::OnReenableComplete(int install_id, 565 void TabHelper::OnReenableComplete(const ExtensionId& extension_id,
565 int return_route_id,
566 const ExtensionId& extension_id,
567 ExtensionReenabler::ReenableResult result) { 566 ExtensionReenabler::ReenableResult result) {
568 // Map the re-enable results to webstore-install results. 567 // Map the re-enable results to webstore-install results.
569 webstore_install::Result webstore_result = webstore_install::SUCCESS; 568 webstore_install::Result webstore_result = webstore_install::SUCCESS;
570 std::string error; 569 std::string error;
571 switch (result) { 570 switch (result) {
572 case ExtensionReenabler::REENABLE_SUCCESS: 571 case ExtensionReenabler::REENABLE_SUCCESS:
573 break; // already set 572 break; // already set
574 case ExtensionReenabler::USER_CANCELED: 573 case ExtensionReenabler::USER_CANCELED:
575 webstore_result = webstore_install::USER_CANCELLED; 574 webstore_result = webstore_install::USER_CANCELLED;
576 error = "User canceled install."; 575 error = "User canceled install.";
577 break; 576 break;
578 case ExtensionReenabler::NOT_ALLOWED: 577 case ExtensionReenabler::NOT_ALLOWED:
579 webstore_result = webstore_install::NOT_PERMITTED; 578 webstore_result = webstore_install::NOT_PERMITTED;
580 error = "Install not permitted."; 579 error = "Install not permitted.";
581 break; 580 break;
582 case ExtensionReenabler::ABORTED: 581 case ExtensionReenabler::ABORTED:
583 webstore_result = webstore_install::ABORTED; 582 webstore_result = webstore_install::ABORTED;
584 error = "Aborted due to tab closing."; 583 error = "Aborted due to tab closing.";
585 break; 584 break;
586 } 585 }
587 586
588 OnInlineInstallComplete(install_id, return_route_id, extension_id, 587 OnInlineInstallComplete(extension_id,
589 result == ExtensionReenabler::REENABLE_SUCCESS, error, 588 result == ExtensionReenabler::REENABLE_SUCCESS, error,
590 webstore_result); 589 webstore_result);
591 // Note: ExtensionReenabler contained the callback with the curried-in 590 // Note: ExtensionReenabler contained the callback with the curried-in
592 // |extension_id|; delete it last. 591 // |extension_id|; delete it last.
593 extension_reenabler_.reset(); 592 extension_reenabler_.reset();
594 } 593 }
595 594
596 void TabHelper::OnInlineInstallComplete(int install_id, 595 void TabHelper::OnInlineInstallComplete(const ExtensionId& extension_id,
597 int return_route_id,
598 const ExtensionId& extension_id,
599 bool success, 596 bool success,
600 const std::string& error, 597 const std::string& error,
601 webstore_install::Result result) { 598 webstore_install::Result result) {
602 DCHECK_EQ(1u, pending_inline_installations_.count(extension_id));
603 pending_inline_installations_.erase(extension_id);
604 install_observers_.erase(extension_id); 599 install_observers_.erase(extension_id);
605 Send(new ExtensionMsg_InlineWebstoreInstallResponse( 600 auto iter = install_callbacks_.find(extension_id);
606 return_route_id, 601 DCHECK(iter != install_callbacks_.end());
607 install_id, 602 std::move(iter->second).Run(success, success ? std::string() : error, result);
608 success, 603 install_callbacks_.erase(iter);
609 success ? std::string() : error,
610 result));
611 } 604 }
612 605
613 WebContents* TabHelper::GetAssociatedWebContents() const { 606 WebContents* TabHelper::GetAssociatedWebContents() const {
614 return web_contents(); 607 return web_contents();
615 } 608 }
616 609
617 void TabHelper::OnExtensionUnloaded(content::BrowserContext* browser_context, 610 void TabHelper::OnExtensionUnloaded(content::BrowserContext* browser_context,
618 const Extension* extension, 611 const Extension* extension,
619 UnloadedExtensionReason reason) { 612 UnloadedExtensionReason reason) {
620 DCHECK(extension_app_); 613 DCHECK(extension_app_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 } 646 }
654 } 647 }
655 648
656 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) { 649 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) {
657 render_frame_host->Send( 650 render_frame_host->Send(
658 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(), 651 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(),
659 SessionTabHelper::IdForTab(web_contents()))); 652 SessionTabHelper::IdForTab(web_contents())));
660 } 653 }
661 654
662 } // namespace extensions 655 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/tab_helper.h ('k') | chrome/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698