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

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

Issue 2791533002: Convert Web Store Inline Install IPCs to mojo (Closed)
Patch Set: Rebase master; Addressed Ken's and mostly palmer's comments Created 3 years, 7 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
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 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 DoInlineInstallCallback callback) {
415 content::RenderFrameHost* host = web_contents()->GetMainFrame();
416 if (bindings_.GetCurrentTargetFrame() != host) {
417 NOTREACHED();
418 return;
419 }
420
416 GURL requestor_url(host->GetLastCommittedURL()); 421 GURL requestor_url(host->GetLastCommittedURL());
417 // Check that the listener is reasonable. We should never get anything other 422 // Check that the listener is reasonable. We should never get anything other
418 // than an install stage listener, a download listener, or both. 423 // than an install stage listener, a download listener, or both.
419 // The requestor_url should also be valid, and the renderer should disallow 424 // The requestor_url should also be valid, and the renderer should disallow
420 // child frames from sending the IPC. 425 // child frames from sending the IPC.
421 if ((listeners_mask & ~(api::webstore::INSTALL_STAGE_LISTENER | 426 if ((listeners_mask & ~(api::webstore::INSTALL_STAGE_LISTENER |
422 api::webstore::DOWNLOAD_PROGRESS_LISTENER)) != 0 || 427 api::webstore::DOWNLOAD_PROGRESS_LISTENER)) != 0 ||
423 !requestor_url.is_valid() || requestor_url == url::kAboutBlankURL || 428 !requestor_url.is_valid() || requestor_url == url::kAboutBlankURL) {
424 host->GetParent()) {
425 NOTREACHED(); 429 NOTREACHED();
426 return; 430 return;
427 } 431 }
428 432
429 if (pending_inline_installations_.count(webstore_item_id) != 0) { 433 if (base::ContainsKey(install_callbacks_, webstore_item_id)) {
430 Send(new ExtensionMsg_InlineWebstoreInstallResponse( 434 std::move(callback).Run(install_id, false,
431 return_route_id, install_id, false, 435 webstore_install::kInstallInProgressError,
432 webstore_install::kInstallInProgressError, 436 webstore_install::INSTALL_IN_PROGRESS);
433 webstore_install::INSTALL_IN_PROGRESS));
434 return; 437 return;
435 } 438 }
436 439
437 pending_inline_installations_.insert(webstore_item_id); 440 install_callbacks_[webstore_item_id] = std::move(callback);
441 inline_install_progress_listeners_[webstore_item_id] =
442 std::move(install_progress_listener);
438 // Inform the Webstore API that an inline install is happening, in case the 443 // Inform the Webstore API that an inline install is happening, in case the
439 // page requested status updates. 444 // page requested status updates.
440 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); 445 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
441 if (registry->disabled_extensions().Contains(webstore_item_id) && 446 if (registry->disabled_extensions().Contains(webstore_item_id) &&
442 (ExtensionPrefs::Get(profile_)->GetDisableReasons(webstore_item_id) & 447 (ExtensionPrefs::Get(profile_)->GetDisableReasons(webstore_item_id) &
443 Extension::DISABLE_PERMISSIONS_INCREASE) != 0) { 448 Extension::DISABLE_PERMISSIONS_INCREASE) != 0) {
444 // The extension was disabled due to permissions increase. Prompt for 449 // The extension was disabled due to permissions increase. Prompt for
445 // re-enable. 450 // re-enable.
446 // TODO(devlin): We should also prompt for re-enable for other reasons, 451 // TODO(devlin): We should also prompt for re-enable for other reasons,
447 // like user-disabled. 452 // like user-disabled.
448 // For clarity, explicitly end any prior reenable process. 453 // For clarity, explicitly end any prior reenable process.
449 extension_reenabler_.reset(); 454 extension_reenabler_.reset();
450 extension_reenabler_ = ExtensionReenabler::PromptForReenable( 455 extension_reenabler_ = ExtensionReenabler::PromptForReenable(
451 registry->disabled_extensions().GetByID(webstore_item_id), profile_, 456 registry->disabled_extensions().GetByID(webstore_item_id), profile_,
452 web_contents(), requestor_url, 457 web_contents(), requestor_url,
453 base::Bind(&TabHelper::OnReenableComplete, 458 base::Bind(&TabHelper::OnReenableComplete,
454 weak_ptr_factory_.GetWeakPtr(), install_id, 459 weak_ptr_factory_.GetWeakPtr(), install_id,
455 return_route_id, webstore_item_id)); 460 webstore_item_id));
456 } else { 461 } else {
457 // TODO(devlin): We should adddress the case of the extension already 462 // TODO(devlin): We should adddress the case of the extension already
458 // being installed and enabled. 463 // being installed and enabled.
459 bool observe_download_progress = 464 bool observe_download_progress =
460 (listeners_mask & api::webstore::DOWNLOAD_PROGRESS_LISTENER) != 0; 465 (listeners_mask & api::webstore::DOWNLOAD_PROGRESS_LISTENER) != 0;
461 bool observe_install_stage = 466 bool observe_install_stage =
462 (listeners_mask & api::webstore::INSTALL_STAGE_LISTENER) != 0; 467 (listeners_mask & api::webstore::INSTALL_STAGE_LISTENER) != 0;
463 if (observe_install_stage || observe_download_progress) { 468 if (observe_install_stage || observe_download_progress) {
464 DCHECK_EQ(0u, install_observers_.count(webstore_item_id)); 469 DCHECK_EQ(0u, install_observers_.count(webstore_item_id));
465 install_observers_[webstore_item_id] = 470 install_observers_[webstore_item_id] =
466 base::MakeUnique<InlineInstallObserver>( 471 base::MakeUnique<InlineInstallObserver>(
467 this, web_contents()->GetBrowserContext(), return_route_id, 472 this, web_contents()->GetBrowserContext(), webstore_item_id,
468 webstore_item_id, observe_download_progress, 473 observe_download_progress, observe_install_stage);
469 observe_install_stage);
470 } 474 }
471 475
472 WebstoreStandaloneInstaller::Callback callback = base::Bind( 476 WebstoreStandaloneInstaller::Callback callback = base::Bind(
473 &TabHelper::OnInlineInstallComplete, weak_ptr_factory_.GetWeakPtr(), 477 &TabHelper::OnInlineInstallComplete, weak_ptr_factory_.GetWeakPtr(),
474 install_id, return_route_id, webstore_item_id); 478 install_id, webstore_item_id);
475 scoped_refptr<WebstoreInlineInstaller> installer( 479 scoped_refptr<WebstoreInlineInstaller> installer(
476 webstore_inline_installer_factory_->CreateInstaller( 480 webstore_inline_installer_factory_->CreateInstaller(
477 web_contents(), host, webstore_item_id, requestor_url, callback)); 481 web_contents(), host, webstore_item_id, requestor_url, callback));
478 installer->BeginInstall(); 482 installer->BeginInstall();
479 } 483 }
480 } 484 }
481 485
482 void TabHelper::OnGetAppInstallState(content::RenderFrameHost* host, 486 void TabHelper::OnGetAppInstallState(content::RenderFrameHost* host,
483 const GURL& requestor_url, 487 const GURL& requestor_url,
484 int return_route_id, 488 int return_route_id,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 extension_app_icon_ = *image.ToSkBitmap(); 559 extension_app_icon_ = *image.ToSkBitmap();
556 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); 560 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
557 } 561 }
558 } 562 }
559 563
560 WindowController* TabHelper::GetExtensionWindowController() const { 564 WindowController* TabHelper::GetExtensionWindowController() const {
561 return ExtensionTabUtil::GetWindowControllerOfTab(web_contents()); 565 return ExtensionTabUtil::GetWindowControllerOfTab(web_contents());
562 } 566 }
563 567
564 void TabHelper::OnReenableComplete(int install_id, 568 void TabHelper::OnReenableComplete(int install_id,
565 int return_route_id,
566 const ExtensionId& extension_id, 569 const ExtensionId& extension_id,
567 ExtensionReenabler::ReenableResult result) { 570 ExtensionReenabler::ReenableResult result) {
568 // Map the re-enable results to webstore-install results. 571 // Map the re-enable results to webstore-install results.
569 webstore_install::Result webstore_result = webstore_install::SUCCESS; 572 webstore_install::Result webstore_result = webstore_install::SUCCESS;
570 std::string error; 573 std::string error;
571 switch (result) { 574 switch (result) {
572 case ExtensionReenabler::REENABLE_SUCCESS: 575 case ExtensionReenabler::REENABLE_SUCCESS:
573 break; // already set 576 break; // already set
574 case ExtensionReenabler::USER_CANCELED: 577 case ExtensionReenabler::USER_CANCELED:
575 webstore_result = webstore_install::USER_CANCELLED; 578 webstore_result = webstore_install::USER_CANCELLED;
576 error = "User canceled install."; 579 error = "User canceled install.";
577 break; 580 break;
578 case ExtensionReenabler::NOT_ALLOWED: 581 case ExtensionReenabler::NOT_ALLOWED:
579 webstore_result = webstore_install::NOT_PERMITTED; 582 webstore_result = webstore_install::NOT_PERMITTED;
580 error = "Install not permitted."; 583 error = "Install not permitted.";
581 break; 584 break;
582 case ExtensionReenabler::ABORTED: 585 case ExtensionReenabler::ABORTED:
583 webstore_result = webstore_install::ABORTED; 586 webstore_result = webstore_install::ABORTED;
584 error = "Aborted due to tab closing."; 587 error = "Aborted due to tab closing.";
585 break; 588 break;
586 } 589 }
587 590
588 OnInlineInstallComplete(install_id, return_route_id, extension_id, 591 OnInlineInstallComplete(install_id, extension_id,
589 result == ExtensionReenabler::REENABLE_SUCCESS, error, 592 result == ExtensionReenabler::REENABLE_SUCCESS, error,
590 webstore_result); 593 webstore_result);
591 // Note: ExtensionReenabler contained the callback with the curried-in 594 // Note: ExtensionReenabler contained the callback with the curried-in
592 // |extension_id|; delete it last. 595 // |extension_id|; delete it last.
593 extension_reenabler_.reset(); 596 extension_reenabler_.reset();
594 } 597 }
595 598
596 void TabHelper::OnInlineInstallComplete(int install_id, 599 void TabHelper::OnInlineInstallComplete(int install_id,
597 int return_route_id,
598 const ExtensionId& extension_id, 600 const ExtensionId& extension_id,
599 bool success, 601 bool success,
600 const std::string& error, 602 const std::string& error,
601 webstore_install::Result result) { 603 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); 604 install_observers_.erase(extension_id);
605 Send(new ExtensionMsg_InlineWebstoreInstallResponse( 605 auto iter = install_callbacks_.find(extension_id);
606 return_route_id, 606 DCHECK(iter != install_callbacks_.end());
607 install_id, 607 std::move(iter->second)
608 success, 608 .Run(install_id, success, success ? std::string() : error, result);
609 success ? std::string() : error, 609 install_callbacks_.erase(iter);
610 result));
611 } 610 }
612 611
613 WebContents* TabHelper::GetAssociatedWebContents() const { 612 WebContents* TabHelper::GetAssociatedWebContents() const {
614 return web_contents(); 613 return web_contents();
615 } 614 }
616 615
617 void TabHelper::OnExtensionUnloaded(content::BrowserContext* browser_context, 616 void TabHelper::OnExtensionUnloaded(content::BrowserContext* browser_context,
618 const Extension* extension, 617 const Extension* extension,
619 UnloadedExtensionReason reason) { 618 UnloadedExtensionReason reason) {
620 DCHECK(extension_app_); 619 DCHECK(extension_app_);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 } 652 }
654 } 653 }
655 654
656 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) { 655 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) {
657 render_frame_host->Send( 656 render_frame_host->Send(
658 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(), 657 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(),
659 SessionTabHelper::IdForTab(web_contents()))); 658 SessionTabHelper::IdForTab(web_contents())));
660 } 659 }
661 660
662 } // namespace extensions 661 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698