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

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

Issue 2791533002: Convert Web Store Inline Install IPCs to mojo (Closed)
Patch Set: Added map of InlineInstallProgressListenerPtrs in TabHelper 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 DCHECK(tab_helper_->inline_install_progress_listeners_[extension_id]);
Devlin 2017/05/05 20:43:46 This will cause a double lookup into the map. Pre
catmullings 2017/05/06 00:12:57 Done.
115 routing_id_, percent_downloaded)); 113 tab_helper_->inline_install_progress_listeners_[extension_id]
114 ->InlineInstallDownloadProgress(percent_downloaded);
116 } 115 }
117 } 116 }
118 void OnBeginCrxInstall(const ExtensionId& extension_id) override { 117 void OnBeginCrxInstall(const ExtensionId& extension_id) override {
119 SendInstallStageChangedMessage(extension_id, 118 SendInstallStageChangedMessage(extension_id,
120 api::webstore::INSTALL_STAGE_INSTALLING); 119 api::webstore::INSTALL_STAGE_INSTALLING);
121 } 120 }
122 void OnShutdown() override { install_observer_.RemoveAll(); } 121 void OnShutdown() override { install_observer_.RemoveAll(); }
123 122
124 void SendInstallStageChangedMessage(const ExtensionId& extension_id, 123 void SendInstallStageChangedMessage(const ExtensionId& extension_id,
125 api::webstore::InstallStage stage) { 124 api::webstore::InstallStage stage) {
126 if (observe_install_stage_ && extension_id == extension_id_) { 125 if (observe_install_stage_ && extension_id == extension_id_) {
127 tab_helper_->Send( 126 DCHECK(tab_helper_->inline_install_progress_listeners_[extension_id]);
Devlin 2017/05/05 20:43:47 ditto
catmullings 2017/05/06 00:12:57 Done.
128 new ExtensionMsg_InlineInstallStageChanged(routing_id_, stage)); 127 tab_helper_->inline_install_progress_listeners_[extension_id]->InlineInsta llStageChanged(
128 stage);
129 } 129 }
130 } 130 }
131 131
132 // The owning TabHelper (guaranteed to be valid). 132 // The owning TabHelper (guaranteed to be valid).
133 TabHelper* const tab_helper_; 133 TabHelper* const tab_helper_;
134 134
135 // The routing id to use in sending IPC updates.
136 int routing_id_;
137
138 // The id of the extension to observe. 135 // The id of the extension to observe.
139 ExtensionId extension_id_; 136 ExtensionId extension_id_;
140 137
141 // Whether or not to observe download/install progress. 138 // Whether or not to observe download/install progress.
142 const bool observe_download_progress_; 139 const bool observe_download_progress_;
143 const bool observe_install_stage_; 140 const bool observe_install_stage_;
144 141
145 ScopedObserver<InstallTracker, InstallObserver> install_observer_; 142 ScopedObserver<InstallTracker, InstallObserver> install_observer_;
146 143
147 DISALLOW_COPY_AND_ASSIGN(InlineInstallObserver); 144 DISALLOW_COPY_AND_ASSIGN(InlineInstallObserver);
148 }; 145 };
149 146
147 TabHelper::~TabHelper() {
148 RemoveScriptExecutionObserver(ActivityLog::GetInstance(profile_));
149 }
150
150 TabHelper::TabHelper(content::WebContents* web_contents) 151 TabHelper::TabHelper(content::WebContents* web_contents)
151 : content::WebContentsObserver(web_contents), 152 : content::WebContentsObserver(web_contents),
152 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), 153 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())),
153 extension_app_(NULL), 154 extension_app_(NULL),
154 pending_web_app_action_(NONE), 155 pending_web_app_action_(NONE),
155 last_committed_nav_entry_unique_id_(0), 156 last_committed_nav_entry_unique_id_(0),
156 update_shortcut_on_load_complete_(false), 157 update_shortcut_on_load_complete_(false),
157 script_executor_( 158 script_executor_(
158 new ScriptExecutor(web_contents, &script_execution_observers_)), 159 new ScriptExecutor(web_contents, &script_execution_observers_)),
159 extension_action_runner_(new ExtensionActionRunner(web_contents)), 160 extension_action_runner_(new ExtensionActionRunner(web_contents)),
160 webstore_inline_installer_factory_(new WebstoreInlineInstallerFactory()), 161 webstore_inline_installer_factory_(new WebstoreInlineInstallerFactory()),
161 registry_observer_(this), 162 registry_observer_(this),
163 bindings_(web_contents, this),
162 image_loader_ptr_factory_(this), 164 image_loader_ptr_factory_(this),
163 weak_ptr_factory_(this) { 165 weak_ptr_factory_(this) {
164 // The ActiveTabPermissionManager requires a session ID; ensure this 166 // The ActiveTabPermissionManager requires a session ID; ensure this
165 // WebContents has one. 167 // WebContents has one.
166 SessionTabHelper::CreateForWebContents(web_contents); 168 SessionTabHelper::CreateForWebContents(web_contents);
167 // The Unretained() is safe because ForEachFrame is synchronous. 169 // The Unretained() is safe because ForEachFrame is synchronous.
168 web_contents->ForEachFrame( 170 web_contents->ForEachFrame(
169 base::Bind(&TabHelper::SetTabId, base::Unretained(this))); 171 base::Bind(&TabHelper::SetTabId, base::Unretained(this)));
170 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( 172 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter(
171 web_contents, 173 web_contents,
(...skipping 13 matching lines...) Expand all
185 set_delegate(this); 187 set_delegate(this);
186 188
187 BookmarkManagerPrivateDragEventRouter::CreateForWebContents(web_contents); 189 BookmarkManagerPrivateDragEventRouter::CreateForWebContents(web_contents);
188 190
189 registrar_.Add(this, 191 registrar_.Add(this,
190 content::NOTIFICATION_LOAD_STOP, 192 content::NOTIFICATION_LOAD_STOP,
191 content::Source<NavigationController>( 193 content::Source<NavigationController>(
192 &web_contents->GetController())); 194 &web_contents->GetController()));
193 } 195 }
194 196
195 TabHelper::~TabHelper() {
196 RemoveScriptExecutionObserver(ActivityLog::GetInstance(profile_));
197 }
198
199 void TabHelper::CreateHostedAppFromWebContents() { 197 void TabHelper::CreateHostedAppFromWebContents() {
200 DCHECK(CanCreateBookmarkApp()); 198 DCHECK(CanCreateBookmarkApp());
201 if (pending_web_app_action_ != NONE) 199 if (pending_web_app_action_ != NONE)
202 return; 200 return;
203 201
204 // Start fetching web app info for CreateApplicationShortcut dialog and show 202 // Start fetching web app info for CreateApplicationShortcut dialog and show
205 // the dialog when the data is available in OnDidGetApplicationInfo. 203 // the dialog when the data is available in OnDidGetApplicationInfo.
206 GetApplicationInfo(CREATE_HOSTED_APP); 204 GetApplicationInfo(CREATE_HOSTED_APP);
207 } 205 }
208 206
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 OnDidGetWebApplicationInfo) 337 OnDidGetWebApplicationInfo)
340 IPC_MESSAGE_UNHANDLED(handled = false) 338 IPC_MESSAGE_UNHANDLED(handled = false)
341 IPC_END_MESSAGE_MAP() 339 IPC_END_MESSAGE_MAP()
342 return handled; 340 return handled;
343 } 341 }
344 342
345 bool TabHelper::OnMessageReceived(const IPC::Message& message, 343 bool TabHelper::OnMessageReceived(const IPC::Message& message,
346 content::RenderFrameHost* render_frame_host) { 344 content::RenderFrameHost* render_frame_host) {
347 bool handled = true; 345 bool handled = true;
348 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(TabHelper, message, render_frame_host) 346 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, 347 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState,
352 OnGetAppInstallState) 348 OnGetAppInstallState)
353 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, 349 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting,
354 OnContentScriptsExecuting) 350 OnContentScriptsExecuting)
355 IPC_MESSAGE_UNHANDLED(handled = false) 351 IPC_MESSAGE_UNHANDLED(handled = false)
356 IPC_END_MESSAGE_MAP() 352 IPC_END_MESSAGE_MAP()
357 return handled; 353 return handled;
358 } 354 }
359 355
360 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, 356 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 NOTREACHED(); 397 NOTREACHED();
402 break; 398 break;
403 } 399 }
404 400
405 // The hosted app action will be cleared once the installation completes or 401 // The hosted app action will be cleared once the installation completes or
406 // fails. 402 // fails.
407 if (pending_web_app_action_ != CREATE_HOSTED_APP) 403 if (pending_web_app_action_ != CREATE_HOSTED_APP)
408 pending_web_app_action_ = NONE; 404 pending_web_app_action_ = NONE;
409 } 405 }
410 406
411 void TabHelper::OnInlineWebstoreInstall(content::RenderFrameHost* host, 407 void TabHelper::DoInlineInstall(
412 int install_id, 408 int install_id,
413 int return_route_id, 409 const std::string& webstore_item_id,
414 const std::string& webstore_item_id, 410 int listeners_mask,
415 int listeners_mask) { 411 mojom::InlineInstallProgressListenerPtr install_progress_listener) {
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) {
Devlin 2017/05/05 20:43:46 With the map of pointers, we can actually just use
catmullings 2017/05/06 00:12:57 Removed. Documentation: pending_inline_installati
catmullings 2017/05/06 00:12:57 Done.
430 Send(new ExtensionMsg_InlineWebstoreInstallResponse( 431 install_progress_listener->InlineInstallResponse(
431 return_route_id, install_id, false, 432 install_id, false, webstore_install::kInstallInProgressError,
432 webstore_install::kInstallInProgressError, 433 webstore_install::INSTALL_IN_PROGRESS);
433 webstore_install::INSTALL_IN_PROGRESS));
434 return; 434 return;
435 } 435 }
436 436
437 inline_install_progress_listeners_[webstore_item_id] = std::move(install_progr ess_listener);
Devlin 2017/05/05 20:43:46 don't forget git cl format :)
catmullings 2017/05/06 00:12:57 Done.
437 pending_inline_installations_.insert(webstore_item_id); 438 pending_inline_installations_.insert(webstore_item_id);
438 // Inform the Webstore API that an inline install is happening, in case the 439 // Inform the Webstore API that an inline install is happening, in case the
439 // page requested status updates. 440 // page requested status updates.
440 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); 441 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
441 if (registry->disabled_extensions().Contains(webstore_item_id) && 442 if (registry->disabled_extensions().Contains(webstore_item_id) &&
442 (ExtensionPrefs::Get(profile_)->GetDisableReasons(webstore_item_id) & 443 (ExtensionPrefs::Get(profile_)->GetDisableReasons(webstore_item_id) &
443 Extension::DISABLE_PERMISSIONS_INCREASE) != 0) { 444 Extension::DISABLE_PERMISSIONS_INCREASE) != 0) {
444 // The extension was disabled due to permissions increase. Prompt for 445 // The extension was disabled due to permissions increase. Prompt for
445 // re-enable. 446 // re-enable.
446 // TODO(devlin): We should also prompt for re-enable for other reasons, 447 // TODO(devlin): We should also prompt for re-enable for other reasons,
447 // like user-disabled. 448 // like user-disabled.
448 // For clarity, explicitly end any prior reenable process. 449 // For clarity, explicitly end any prior reenable process.
449 extension_reenabler_.reset(); 450 extension_reenabler_.reset();
450 extension_reenabler_ = ExtensionReenabler::PromptForReenable( 451 extension_reenabler_ = ExtensionReenabler::PromptForReenable(
451 registry->disabled_extensions().GetByID(webstore_item_id), profile_, 452 registry->disabled_extensions().GetByID(webstore_item_id), profile_,
452 web_contents(), requestor_url, 453 web_contents(), requestor_url,
453 base::Bind(&TabHelper::OnReenableComplete, 454 base::Bind(&TabHelper::OnReenableComplete,
454 weak_ptr_factory_.GetWeakPtr(), install_id, 455 weak_ptr_factory_.GetWeakPtr(), install_id,
455 return_route_id, webstore_item_id)); 456 webstore_item_id));
456 } else { 457 } else {
457 // TODO(devlin): We should adddress the case of the extension already 458 // TODO(devlin): We should adddress the case of the extension already
458 // being installed and enabled. 459 // being installed and enabled.
459 bool observe_download_progress = 460 bool observe_download_progress =
460 (listeners_mask & api::webstore::DOWNLOAD_PROGRESS_LISTENER) != 0; 461 (listeners_mask & api::webstore::DOWNLOAD_PROGRESS_LISTENER) != 0;
461 bool observe_install_stage = 462 bool observe_install_stage =
462 (listeners_mask & api::webstore::INSTALL_STAGE_LISTENER) != 0; 463 (listeners_mask & api::webstore::INSTALL_STAGE_LISTENER) != 0;
463 if (observe_install_stage || observe_download_progress) { 464 if (observe_install_stage || observe_download_progress) {
464 DCHECK_EQ(0u, install_observers_.count(webstore_item_id)); 465 DCHECK_EQ(0u, install_observers_.count(webstore_item_id));
465 install_observers_[webstore_item_id] = 466 install_observers_[webstore_item_id] =
466 base::MakeUnique<InlineInstallObserver>( 467 base::MakeUnique<InlineInstallObserver>(
467 this, web_contents()->GetBrowserContext(), return_route_id, 468 this, web_contents()->GetBrowserContext(), webstore_item_id,
468 webstore_item_id, observe_download_progress, 469 observe_download_progress, observe_install_stage);
469 observe_install_stage);
470 } 470 }
471 471
472 WebstoreStandaloneInstaller::Callback callback = base::Bind( 472 WebstoreStandaloneInstaller::Callback callback = base::Bind(
473 &TabHelper::OnInlineInstallComplete, weak_ptr_factory_.GetWeakPtr(), 473 &TabHelper::OnInlineInstallComplete, weak_ptr_factory_.GetWeakPtr(),
474 install_id, return_route_id, webstore_item_id); 474 install_id, webstore_item_id);
475 scoped_refptr<WebstoreInlineInstaller> installer( 475 scoped_refptr<WebstoreInlineInstaller> installer(
476 webstore_inline_installer_factory_->CreateInstaller( 476 webstore_inline_installer_factory_->CreateInstaller(
477 web_contents(), host, webstore_item_id, requestor_url, callback)); 477 web_contents(), host, webstore_item_id, requestor_url, 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,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
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,
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(install_id, 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(int install_id,
597 int return_route_id,
598 const ExtensionId& extension_id, 596 const ExtensionId& extension_id,
599 bool success, 597 bool success,
600 const std::string& error, 598 const std::string& error,
601 webstore_install::Result result) { 599 webstore_install::Result result) {
602 DCHECK_EQ(1u, pending_inline_installations_.count(extension_id)); 600 DCHECK_EQ(1u, pending_inline_installations_.count(extension_id));
603 pending_inline_installations_.erase(extension_id); 601 pending_inline_installations_.erase(extension_id);
604 install_observers_.erase(extension_id); 602 install_observers_.erase(extension_id);
605 Send(new ExtensionMsg_InlineWebstoreInstallResponse( 603 DCHECK(inline_install_progress_listeners_[extension_id]);
Devlin 2017/05/05 20:43:46 ditto re the double lookup
catmullings 2017/05/06 00:12:57 Done.
606 return_route_id, 604 inline_install_progress_listeners_[extension_id]->InlineInstallResponse(
607 install_id, 605 install_id, success, success ? std::string() : error, result);
608 success, 606 inline_install_progress_listeners_.erase(extension_id);
609 success ? std::string() : error,
610 result));
611 } 607 }
612 608
613 WebContents* TabHelper::GetAssociatedWebContents() const { 609 WebContents* TabHelper::GetAssociatedWebContents() const {
614 return web_contents(); 610 return web_contents();
615 } 611 }
616 612
617 void TabHelper::OnExtensionUnloaded( 613 void TabHelper::OnExtensionUnloaded(
618 content::BrowserContext* browser_context, 614 content::BrowserContext* browser_context,
619 const Extension* extension, 615 const Extension* extension,
620 UnloadedExtensionInfo::Reason reason) { 616 UnloadedExtensionInfo::Reason reason) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 } 650 }
655 } 651 }
656 652
657 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) { 653 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) {
658 render_frame_host->Send( 654 render_frame_host->Send(
659 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(), 655 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(),
660 SessionTabHelper::IdForTab(web_contents()))); 656 SessionTabHelper::IdForTab(web_contents())));
661 } 657 }
662 658
663 } // namespace extensions 659 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698