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

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

Issue 2791533002: Convert Web Store Inline Install IPCs to mojo (Closed)
Patch Set: WebContentsFrameBindingSet in TabHelper, weak binding in WebstoreBindings Created 3 years, 8 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 15 matching lines...) Expand all
26 #include "chrome/browser/extensions/webstore_inline_installer.h" 26 #include "chrome/browser/extensions/webstore_inline_installer.h"
27 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" 27 #include "chrome/browser/extensions/webstore_inline_installer_factory.h"
28 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/sessions/session_tab_helper.h" 29 #include "chrome/browser/sessions/session_tab_helper.h"
30 #include "chrome/browser/shell_integration.h" 30 #include "chrome/browser/shell_integration.h"
31 #include "chrome/browser/ui/browser_commands.h" 31 #include "chrome/browser/ui/browser_commands.h"
32 #include "chrome/browser/ui/browser_dialogs.h" 32 #include "chrome/browser/ui/browser_dialogs.h"
33 #include "chrome/browser/ui/browser_finder.h" 33 #include "chrome/browser/ui/browser_finder.h"
34 #include "chrome/browser/web_applications/web_app.h" 34 #include "chrome/browser/web_applications/web_app.h"
35 #include "chrome/common/extensions/api/webstore/webstore_api_constants.h" 35 #include "chrome/common/extensions/api/webstore/webstore_api_constants.h"
36 #include "chrome/common/extensions/chrome_extension_messages.h"
37 #include "chrome/common/extensions/extension_constants.h" 36 #include "chrome/common/extensions/extension_constants.h"
38 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 37 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
39 #include "chrome/common/render_messages.h" 38 #include "chrome/common/render_messages.h"
40 #include "chrome/common/url_constants.h" 39 #include "chrome/common/url_constants.h"
41 #include "content/public/browser/invalidate_type.h" 40 #include "content/public/browser/invalidate_type.h"
42 #include "content/public/browser/navigation_controller.h" 41 #include "content/public/browser/navigation_controller.h"
43 #include "content/public/browser/navigation_entry.h" 42 #include "content/public/browser/navigation_entry.h"
44 #include "content/public/browser/navigation_handle.h" 43 #include "content/public/browser/navigation_handle.h"
45 #include "content/public/browser/notification_service.h" 44 #include "content/public/browser/notification_service.h"
46 #include "content/public/browser/notification_source.h" 45 #include "content/public/browser/notification_source.h"
(...skipping 10 matching lines...) Expand all
57 #include "extensions/browser/extension_web_contents_observer.h" 56 #include "extensions/browser/extension_web_contents_observer.h"
58 #include "extensions/browser/image_loader.h" 57 #include "extensions/browser/image_loader.h"
59 #include "extensions/common/constants.h" 58 #include "extensions/common/constants.h"
60 #include "extensions/common/extension.h" 59 #include "extensions/common/extension.h"
61 #include "extensions/common/extension_icon_set.h" 60 #include "extensions/common/extension_icon_set.h"
62 #include "extensions/common/extension_messages.h" 61 #include "extensions/common/extension_messages.h"
63 #include "extensions/common/extension_resource.h" 62 #include "extensions/common/extension_resource.h"
64 #include "extensions/common/extension_urls.h" 63 #include "extensions/common/extension_urls.h"
65 #include "extensions/common/feature_switch.h" 64 #include "extensions/common/feature_switch.h"
66 #include "extensions/common/manifest_handlers/icons_handler.h" 65 #include "extensions/common/manifest_handlers/icons_handler.h"
66 #include "services/service_manager/public/cpp/interface_provider.h"
67 #include "url/url_constants.h" 67 #include "url/url_constants.h"
68 68
69 #if defined(OS_WIN) 69 #if defined(OS_WIN)
70 #include "chrome/browser/web_applications/web_app_win.h" 70 #include "chrome/browser/web_applications/web_app_win.h"
71 #endif 71 #endif
72 72
73 using content::NavigationController; 73 using content::NavigationController;
74 using content::NavigationEntry; 74 using content::NavigationEntry;
75 using content::WebContents; 75 using content::WebContents;
76 76
77 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::TabHelper); 77 DEFINE_WEB_CONTENTS_USER_DATA_KEY(extensions::TabHelper);
78 78
79 namespace extensions { 79 namespace extensions {
80 80
81 // A helper class to watch the progress of inline installation and update the 81 // A helper class to watch the progress of inline installation and update the
82 // renderer. Owned by the TabHelper. 82 // renderer. Owned by the TabHelper.
83 class TabHelper::InlineInstallObserver : public InstallObserver { 83 class TabHelper::InlineInstallObserver : public InstallObserver {
84 public: 84 public:
85 InlineInstallObserver(TabHelper* tab_helper, 85 InlineInstallObserver(TabHelper* tab_helper,
86 content::BrowserContext* browser_context, 86 content::BrowserContext* browser_context,
87 int routing_id, 87 int routing_id,
88 const ExtensionId& extension_id, 88 const ExtensionId& extension_id,
89 bool observe_download_progress, 89 bool observe_download_progress,
90 bool observe_install_stage) 90 bool observe_install_stage)
91 : tab_helper_(tab_helper), 91 : tab_helper_(tab_helper),
92 routing_id_(routing_id),
93 extension_id_(extension_id), 92 extension_id_(extension_id),
94 observe_download_progress_(observe_download_progress), 93 observe_download_progress_(observe_download_progress),
95 observe_install_stage_(observe_install_stage), 94 observe_install_stage_(observe_install_stage),
96 install_observer_(this) { 95 install_observer_(this) {
97 DCHECK(tab_helper); 96 DCHECK(tab_helper);
98 DCHECK(observe_download_progress || observe_install_stage); 97 DCHECK(observe_download_progress || observe_install_stage);
99 InstallTracker* install_tracker = 98 InstallTracker* install_tracker =
100 InstallTrackerFactory::GetForBrowserContext(browser_context); 99 InstallTrackerFactory::GetForBrowserContext(browser_context);
101 if (install_tracker) 100 if (install_tracker)
102 install_observer_.Add(install_tracker); 101 install_observer_.Add(install_tracker);
103 } 102 }
104 ~InlineInstallObserver() override {} 103 ~InlineInstallObserver() override {}
105 104
106 private: 105 private:
107 // InstallObserver: 106 // InstallObserver:
108 void OnBeginExtensionDownload(const ExtensionId& extension_id) override { 107 void OnBeginExtensionDownload(const ExtensionId& extension_id) override {
109 SendInstallStageChangedMessage(extension_id, 108 SendInstallStageChangedMessage(extension_id,
110 api::webstore::INSTALL_STAGE_DOWNLOADING); 109 api::webstore::INSTALL_STAGE_DOWNLOADING);
111 } 110 }
112 void OnDownloadProgress(const ExtensionId& extension_id, 111 void OnDownloadProgress(const ExtensionId& extension_id,
113 int percent_downloaded) override { 112 int percent_downloaded) override {
114 if (observe_download_progress_ && extension_id == extension_id_) { 113 if (observe_download_progress_ && extension_id == extension_id_) {
115 tab_helper_->Send(new ExtensionMsg_InlineInstallDownloadProgress( 114 tab_helper_->inline_install_status_->InlineInstallDownloadProgress(
116 routing_id_, percent_downloaded)); 115 percent_downloaded);
117 } 116 }
118 } 117 }
119 void OnBeginCrxInstall(const ExtensionId& extension_id) override { 118 void OnBeginCrxInstall(const ExtensionId& extension_id) override {
120 SendInstallStageChangedMessage(extension_id, 119 SendInstallStageChangedMessage(extension_id,
121 api::webstore::INSTALL_STAGE_INSTALLING); 120 api::webstore::INSTALL_STAGE_INSTALLING);
122 } 121 }
123 void OnShutdown() override { install_observer_.RemoveAll(); } 122 void OnShutdown() override { install_observer_.RemoveAll(); }
124 123
125 void SendInstallStageChangedMessage(const ExtensionId& extension_id, 124 void SendInstallStageChangedMessage(const ExtensionId& extension_id,
126 api::webstore::InstallStage stage) { 125 api::webstore::InstallStage stage) {
127 if (observe_install_stage_ && extension_id == extension_id_) { 126 if (observe_install_stage_ && extension_id == extension_id_)
128 tab_helper_->Send( 127 tab_helper_->inline_install_status_->InlineInstallStageChanged(stage);
129 new ExtensionMsg_InlineInstallStageChanged(routing_id_, stage));
130 }
131 } 128 }
132 129
133 // The owning TabHelper (guaranteed to be valid). 130 // The owning TabHelper (guaranteed to be valid).
134 TabHelper* const tab_helper_; 131 TabHelper* const tab_helper_;
135 132
136 // The routing id to use in sending IPC updates.
137 int routing_id_;
138
139 // The id of the extension to observe. 133 // The id of the extension to observe.
140 ExtensionId extension_id_; 134 ExtensionId extension_id_;
141 135
142 // Whether or not to observe download/install progress. 136 // Whether or not to observe download/install progress.
143 const bool observe_download_progress_; 137 const bool observe_download_progress_;
144 const bool observe_install_stage_; 138 const bool observe_install_stage_;
145 139
146 ScopedObserver<InstallTracker, InstallObserver> install_observer_; 140 ScopedObserver<InstallTracker, InstallObserver> install_observer_;
147 141
148 DISALLOW_COPY_AND_ASSIGN(InlineInstallObserver); 142 DISALLOW_COPY_AND_ASSIGN(InlineInstallObserver);
149 }; 143 };
150 144
145 TabHelper::~TabHelper() {
146 RemoveScriptExecutionObserver(ActivityLog::GetInstance(profile_));
147 }
148
151 TabHelper::TabHelper(content::WebContents* web_contents) 149 TabHelper::TabHelper(content::WebContents* web_contents)
152 : content::WebContentsObserver(web_contents), 150 : content::WebContentsObserver(web_contents),
153 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), 151 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())),
154 extension_app_(NULL), 152 extension_app_(NULL),
155 pending_web_app_action_(NONE), 153 pending_web_app_action_(NONE),
156 last_committed_nav_entry_unique_id_(0), 154 last_committed_nav_entry_unique_id_(0),
157 update_shortcut_on_load_complete_(false), 155 update_shortcut_on_load_complete_(false),
158 script_executor_( 156 script_executor_(
159 new ScriptExecutor(web_contents, &script_execution_observers_)), 157 new ScriptExecutor(web_contents, &script_execution_observers_)),
160 location_bar_controller_(new LocationBarController(web_contents)), 158 location_bar_controller_(new LocationBarController(web_contents)),
161 extension_action_runner_(new ExtensionActionRunner(web_contents)), 159 extension_action_runner_(new ExtensionActionRunner(web_contents)),
162 webstore_inline_installer_factory_(new WebstoreInlineInstallerFactory()), 160 webstore_inline_installer_factory_(new WebstoreInlineInstallerFactory()),
163 registry_observer_(this), 161 registry_observer_(this),
162 bindings_(web_contents, this),
164 image_loader_ptr_factory_(this), 163 image_loader_ptr_factory_(this),
165 weak_ptr_factory_(this) { 164 weak_ptr_factory_(this) {
166 // The ActiveTabPermissionManager requires a session ID; ensure this 165 // The ActiveTabPermissionManager requires a session ID; ensure this
167 // WebContents has one. 166 // WebContents has one.
168 SessionTabHelper::CreateForWebContents(web_contents); 167 SessionTabHelper::CreateForWebContents(web_contents);
169 // The Unretained() is safe because ForEachFrame is synchronous. 168 // The Unretained() is safe because ForEachFrame is synchronous.
170 web_contents->ForEachFrame( 169 web_contents->ForEachFrame(
171 base::Bind(&TabHelper::SetTabId, base::Unretained(this))); 170 base::Bind(&TabHelper::SetTabId, base::Unretained(this)));
172 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( 171 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter(
173 web_contents, 172 web_contents,
(...skipping 11 matching lines...) Expand all
185 ChromeExtensionWebContentsObserver::CreateForWebContents(web_contents); 184 ChromeExtensionWebContentsObserver::CreateForWebContents(web_contents);
186 ExtensionWebContentsObserver::GetForWebContents(web_contents)->dispatcher()-> 185 ExtensionWebContentsObserver::GetForWebContents(web_contents)->dispatcher()->
187 set_delegate(this); 186 set_delegate(this);
188 187
189 BookmarkManagerPrivateDragEventRouter::CreateForWebContents(web_contents); 188 BookmarkManagerPrivateDragEventRouter::CreateForWebContents(web_contents);
190 189
191 registrar_.Add(this, 190 registrar_.Add(this,
192 content::NOTIFICATION_LOAD_STOP, 191 content::NOTIFICATION_LOAD_STOP,
193 content::Source<NavigationController>( 192 content::Source<NavigationController>(
194 &web_contents->GetController())); 193 &web_contents->GetController()));
195 }
196 194
197 TabHelper::~TabHelper() { 195 content::RenderFrameHost* host = web_contents->GetMainFrame();
198 RemoveScriptExecutionObserver(ActivityLog::GetInstance(profile_)); 196 if (host)
197 host->GetRemoteInterfaces()->GetInterface(&inline_install_status_);
199 } 198 }
200 199
201 void TabHelper::CreateApplicationShortcuts() { 200 void TabHelper::CreateApplicationShortcuts() {
202 DCHECK(CanCreateApplicationShortcuts()); 201 DCHECK(CanCreateApplicationShortcuts());
203 if (pending_web_app_action_ != NONE) 202 if (pending_web_app_action_ != NONE)
204 return; 203 return;
205 204
206 // Start fetching web app info for CreateApplicationShortcut dialog and show 205 // Start fetching web app info for CreateApplicationShortcut dialog and show
207 // the dialog when the data is available in OnDidGetApplicationInfo. 206 // the dialog when the data is available in OnDidGetApplicationInfo.
208 GetApplicationInfo(CREATE_SHORTCUT); 207 GetApplicationInfo(CREATE_SHORTCUT);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 OnDidGetWebApplicationInfo) 358 OnDidGetWebApplicationInfo)
360 IPC_MESSAGE_UNHANDLED(handled = false) 359 IPC_MESSAGE_UNHANDLED(handled = false)
361 IPC_END_MESSAGE_MAP() 360 IPC_END_MESSAGE_MAP()
362 return handled; 361 return handled;
363 } 362 }
364 363
365 bool TabHelper::OnMessageReceived(const IPC::Message& message, 364 bool TabHelper::OnMessageReceived(const IPC::Message& message,
366 content::RenderFrameHost* render_frame_host) { 365 content::RenderFrameHost* render_frame_host) {
367 bool handled = true; 366 bool handled = true;
368 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(TabHelper, message, render_frame_host) 367 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(TabHelper, message, render_frame_host)
369 IPC_MESSAGE_HANDLER(ExtensionHostMsg_InlineWebstoreInstall,
370 OnInlineWebstoreInstall)
371 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState, 368 IPC_MESSAGE_HANDLER(ExtensionHostMsg_GetAppInstallState,
372 OnGetAppInstallState) 369 OnGetAppInstallState)
373 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting, 370 IPC_MESSAGE_HANDLER(ExtensionHostMsg_ContentScriptsExecuting,
374 OnContentScriptsExecuting) 371 OnContentScriptsExecuting)
375 IPC_MESSAGE_UNHANDLED(handled = false) 372 IPC_MESSAGE_UNHANDLED(handled = false)
376 IPC_END_MESSAGE_MAP() 373 IPC_END_MESSAGE_MAP()
377 return handled; 374 return handled;
378 } 375 }
379 376
380 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents, 377 void TabHelper::DidCloneToNewWebContents(WebContents* old_web_contents,
(...skipping 13 matching lines...) Expand all
394 NavigationEntry* entry = 391 NavigationEntry* entry =
395 web_contents()->GetController().GetLastCommittedEntry(); 392 web_contents()->GetController().GetLastCommittedEntry();
396 if (!entry || last_committed_nav_entry_unique_id_ != entry->GetUniqueID()) 393 if (!entry || last_committed_nav_entry_unique_id_ != entry->GetUniqueID())
397 return; 394 return;
398 last_committed_nav_entry_unique_id_ = 0; 395 last_committed_nav_entry_unique_id_ = 0;
399 396
400 switch (pending_web_app_action_) { 397 switch (pending_web_app_action_) {
401 #if !defined(OS_MACOSX) 398 #if !defined(OS_MACOSX)
402 case CREATE_SHORTCUT: { 399 case CREATE_SHORTCUT: {
403 chrome::ShowCreateWebAppShortcutsDialog( 400 chrome::ShowCreateWebAppShortcutsDialog(
404 web_contents()->GetTopLevelNativeWindow(), 401 web_contents()->GetTopLevelNativeWindow(), web_contents());
405 web_contents());
406 break; 402 break;
407 } 403 }
408 #endif 404 #endif
409 case CREATE_HOSTED_APP: { 405 case CREATE_HOSTED_APP: {
410 if (web_app_info_.app_url.is_empty()) 406 if (web_app_info_.app_url.is_empty())
411 web_app_info_.app_url = web_contents()->GetURL(); 407 web_app_info_.app_url = web_contents()->GetURL();
412 408
413 if (web_app_info_.title.empty()) 409 if (web_app_info_.title.empty())
414 web_app_info_.title = web_contents()->GetTitle(); 410 web_app_info_.title = web_contents()->GetTitle();
415 if (web_app_info_.title.empty()) 411 if (web_app_info_.title.empty())
(...skipping 13 matching lines...) Expand all
429 NOTREACHED(); 425 NOTREACHED();
430 break; 426 break;
431 } 427 }
432 428
433 // The hosted app action will be cleared once the installation completes or 429 // The hosted app action will be cleared once the installation completes or
434 // fails. 430 // fails.
435 if (pending_web_app_action_ != CREATE_HOSTED_APP) 431 if (pending_web_app_action_ != CREATE_HOSTED_APP)
436 pending_web_app_action_ = NONE; 432 pending_web_app_action_ = NONE;
437 } 433 }
438 434
439 void TabHelper::OnInlineWebstoreInstall(content::RenderFrameHost* host, 435 void TabHelper::DoInlineInstall(int install_id,
440 int install_id, 436 int return_route_id,
441 int return_route_id, 437 const std::string& webstore_item_id,
442 const std::string& webstore_item_id, 438 int listeners_mask,
443 int listeners_mask) { 439 const DoInlineInstallCallback& callback) {
444 GURL requestor_url(host->GetLastCommittedURL()); 440 content::RenderFrameHost* host = web_contents()->GetMainFrame();
445 // Check that the listener is reasonable. We should never get anything other 441 if (bindings_.GetCurrentTargetFrame() == host) {
Devlin 2017/04/12 01:16:07 We should handle the case of the message not being
catmullings 2017/04/14 20:59:40 Done.
446 // than an install stage listener, a download listener, or both. 442 GURL requestor_url(host->GetLastCommittedURL());
447 // The requestor_url should also be valid, and the renderer should disallow 443 // Check that the listener is reasonable. We should never get anything other
448 // child frames from sending the IPC. 444 // than an install stage listener, a download listener, or both.
449 if ((listeners_mask & ~(api::webstore::INSTALL_STAGE_LISTENER | 445 // The requestor_url should also be valid, and the renderer should disallow
450 api::webstore::DOWNLOAD_PROGRESS_LISTENER)) != 0 || 446 // child frames from sending the IPC.
451 !requestor_url.is_valid() || requestor_url == url::kAboutBlankURL || 447 if ((listeners_mask & ~(api::webstore::INSTALL_STAGE_LISTENER |
452 host->GetParent()) { 448 api::webstore::DOWNLOAD_PROGRESS_LISTENER)) != 0 ||
453 NOTREACHED(); 449 !requestor_url.is_valid() || requestor_url == url::kAboutBlankURL ||
454 return; 450 host->GetParent()) {
Devlin 2017/04/12 01:16:07 if host is the main frame, it can't have a parent.
catmullings 2017/04/14 20:59:40 Done.
455 } 451 NOTREACHED();
452 return;
453 }
456 454
457 if (pending_inline_installations_.count(webstore_item_id) != 0) { 455 if (pending_inline_installations_.count(webstore_item_id) != 0) {
458 Send(new ExtensionMsg_InlineWebstoreInstallResponse( 456 callback.Run(install_id, false, webstore_install::kInstallInProgressError,
459 return_route_id, install_id, false, 457 webstore_install::INSTALL_IN_PROGRESS);
460 webstore_install::kInstallInProgressError, 458 return;
461 webstore_install::INSTALL_IN_PROGRESS)); 459 }
462 return;
463 }
464 460
465 pending_inline_installations_.insert(webstore_item_id); 461 pending_inline_installations_.insert(webstore_item_id);
466 // Inform the Webstore API that an inline install is happening, in case the 462 // Inform the Webstore API that an inline install is happening, in case the
467 // page requested status updates. 463 // page requested status updates.
468 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); 464 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
469 if (registry->disabled_extensions().Contains(webstore_item_id) && 465 if (registry->disabled_extensions().Contains(webstore_item_id) &&
470 (ExtensionPrefs::Get(profile_)->GetDisableReasons(webstore_item_id) & 466 (ExtensionPrefs::Get(profile_)->GetDisableReasons(webstore_item_id) &
471 Extension::DISABLE_PERMISSIONS_INCREASE) != 0) { 467 Extension::DISABLE_PERMISSIONS_INCREASE) != 0) {
472 // The extension was disabled due to permissions increase. Prompt for 468 // The extension was disabled due to permissions increase. Prompt for
473 // re-enable. 469 // re-enable.
474 // TODO(devlin): We should also prompt for re-enable for other reasons, 470 // TODO(devlin): We should also prompt for re-enable for other reasons,
475 // like user-disabled. 471 // like user-disabled.
476 // For clarity, explicitly end any prior reenable process. 472 // For clarity, explicitly end any prior reenable process.
477 extension_reenabler_.reset(); 473 extension_reenabler_.reset();
478 extension_reenabler_ = ExtensionReenabler::PromptForReenable( 474 extension_reenabler_ = ExtensionReenabler::PromptForReenable(
479 registry->disabled_extensions().GetByID(webstore_item_id), profile_, 475 registry->disabled_extensions().GetByID(webstore_item_id), profile_,
480 web_contents(), requestor_url, 476 web_contents(), requestor_url,
481 base::Bind(&TabHelper::OnReenableComplete, 477 base::Bind(&TabHelper::OnReenableComplete,
482 weak_ptr_factory_.GetWeakPtr(), install_id, 478 weak_ptr_factory_.GetWeakPtr(), install_id,
483 return_route_id, webstore_item_id)); 479 return_route_id, webstore_item_id, callback));
484 } else { 480 } else {
485 // TODO(devlin): We should adddress the case of the extension already 481 // TODO(devlin): We should adddress the case of the extension already
486 // being installed and enabled. 482 // being installed and enabled.
487 bool observe_download_progress = 483 bool observe_download_progress =
488 (listeners_mask & api::webstore::DOWNLOAD_PROGRESS_LISTENER) != 0; 484 (listeners_mask & api::webstore::DOWNLOAD_PROGRESS_LISTENER) != 0;
489 bool observe_install_stage = 485 bool observe_install_stage =
490 (listeners_mask & api::webstore::INSTALL_STAGE_LISTENER) != 0; 486 (listeners_mask & api::webstore::INSTALL_STAGE_LISTENER) != 0;
491 if (observe_install_stage || observe_download_progress) { 487 if (observe_install_stage || observe_download_progress) {
492 DCHECK_EQ(0u, install_observers_.count(webstore_item_id)); 488 DCHECK_EQ(0u, install_observers_.count(webstore_item_id));
493 install_observers_[webstore_item_id] = 489 install_observers_[webstore_item_id] =
494 base::MakeUnique<InlineInstallObserver>( 490 base::MakeUnique<InlineInstallObserver>(
495 this, web_contents()->GetBrowserContext(), return_route_id, 491 this, web_contents()->GetBrowserContext(), return_route_id,
Devlin 2017/04/12 01:16:07 Does this compile? InlineInstallObserver doesn't
catmullings 2017/04/14 20:59:40 It does compile. According to the constructor defi
496 webstore_item_id, observe_download_progress, 492 webstore_item_id, observe_download_progress,
497 observe_install_stage); 493 observe_install_stage);
494 }
495
496 WebstoreStandaloneInstaller::Callback completion_callback = base::Bind(
497 &TabHelper::OnInlineInstallComplete, weak_ptr_factory_.GetWeakPtr(),
498 callback, install_id, return_route_id, webstore_item_id);
499 scoped_refptr<WebstoreInlineInstaller> installer(
500 webstore_inline_installer_factory_->CreateInstaller(
501 web_contents(), host, webstore_item_id, requestor_url,
502 completion_callback));
503 installer->BeginInstall();
498 } 504 }
499
500 WebstoreStandaloneInstaller::Callback callback = base::Bind(
501 &TabHelper::OnInlineInstallComplete, weak_ptr_factory_.GetWeakPtr(),
502 install_id, return_route_id, webstore_item_id);
503 scoped_refptr<WebstoreInlineInstaller> installer(
504 webstore_inline_installer_factory_->CreateInstaller(
505 web_contents(), host, webstore_item_id, requestor_url, callback));
506 installer->BeginInstall();
507 } 505 }
508 } 506 }
509 507
510 void TabHelper::OnGetAppInstallState(content::RenderFrameHost* host, 508 void TabHelper::OnGetAppInstallState(content::RenderFrameHost* host,
511 const GURL& requestor_url, 509 const GURL& requestor_url,
512 int return_route_id, 510 int return_route_id,
513 int callback_id) { 511 int callback_id) {
514 ExtensionRegistry* registry = 512 ExtensionRegistry* registry =
515 ExtensionRegistry::Get(web_contents()->GetBrowserContext()); 513 ExtensionRegistry::Get(web_contents()->GetBrowserContext());
516 const ExtensionSet& extensions = registry->enabled_extensions(); 514 const ExtensionSet& extensions = registry->enabled_extensions();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 } 583 }
586 } 584 }
587 585
588 WindowController* TabHelper::GetExtensionWindowController() const { 586 WindowController* TabHelper::GetExtensionWindowController() const {
589 return ExtensionTabUtil::GetWindowControllerOfTab(web_contents()); 587 return ExtensionTabUtil::GetWindowControllerOfTab(web_contents());
590 } 588 }
591 589
592 void TabHelper::OnReenableComplete(int install_id, 590 void TabHelper::OnReenableComplete(int install_id,
593 int return_route_id, 591 int return_route_id,
594 const ExtensionId& extension_id, 592 const ExtensionId& extension_id,
593 const DoInlineInstallCallback& callback,
595 ExtensionReenabler::ReenableResult result) { 594 ExtensionReenabler::ReenableResult result) {
596 // Map the re-enable results to webstore-install results. 595 // Map the re-enable results to webstore-install results.
597 webstore_install::Result webstore_result = webstore_install::SUCCESS; 596 webstore_install::Result webstore_result = webstore_install::SUCCESS;
598 std::string error; 597 std::string error;
599 switch (result) { 598 switch (result) {
600 case ExtensionReenabler::REENABLE_SUCCESS: 599 case ExtensionReenabler::REENABLE_SUCCESS:
601 break; // already set 600 break; // already set
602 case ExtensionReenabler::USER_CANCELED: 601 case ExtensionReenabler::USER_CANCELED:
603 webstore_result = webstore_install::USER_CANCELLED; 602 webstore_result = webstore_install::USER_CANCELLED;
604 error = "User canceled install."; 603 error = "User canceled install.";
605 break; 604 break;
606 case ExtensionReenabler::NOT_ALLOWED: 605 case ExtensionReenabler::NOT_ALLOWED:
607 webstore_result = webstore_install::NOT_PERMITTED; 606 webstore_result = webstore_install::NOT_PERMITTED;
608 error = "Install not permitted."; 607 error = "Install not permitted.";
609 break; 608 break;
610 case ExtensionReenabler::ABORTED: 609 case ExtensionReenabler::ABORTED:
611 webstore_result = webstore_install::ABORTED; 610 webstore_result = webstore_install::ABORTED;
612 error = "Aborted due to tab closing."; 611 error = "Aborted due to tab closing.";
613 break; 612 break;
614 } 613 }
615 614
616 OnInlineInstallComplete(install_id, return_route_id, extension_id, 615 OnInlineInstallComplete(callback, install_id, return_route_id, extension_id,
617 result == ExtensionReenabler::REENABLE_SUCCESS, error, 616 result == ExtensionReenabler::REENABLE_SUCCESS, error,
618 webstore_result); 617 webstore_result);
619 // Note: ExtensionReenabler contained the callback with the curried-in 618 // Note: ExtensionReenabler contained the callback with the curried-in
620 // |extension_id|; delete it last. 619 // |extension_id|; delete it last.
621 extension_reenabler_.reset(); 620 extension_reenabler_.reset();
622 } 621 }
623 622
624 void TabHelper::OnInlineInstallComplete(int install_id, 623 void TabHelper::OnInlineInstallComplete(const DoInlineInstallCallback& callback,
624 int install_id,
625 int return_route_id, 625 int return_route_id,
626 const ExtensionId& extension_id, 626 const ExtensionId& extension_id,
627 bool success, 627 bool success,
628 const std::string& error, 628 const std::string& error,
629 webstore_install::Result result) { 629 webstore_install::Result result) {
630 DCHECK_EQ(1u, pending_inline_installations_.count(extension_id)); 630 DCHECK_EQ(1u, pending_inline_installations_.count(extension_id));
631 pending_inline_installations_.erase(extension_id); 631 pending_inline_installations_.erase(extension_id);
632 install_observers_.erase(extension_id); 632 install_observers_.erase(extension_id);
633 Send(new ExtensionMsg_InlineWebstoreInstallResponse( 633 callback.Run(install_id, success, success ? std::string() : error, result);
634 return_route_id,
635 install_id,
636 success,
637 success ? std::string() : error,
638 result));
639 } 634 }
640 635
641 WebContents* TabHelper::GetAssociatedWebContents() const { 636 WebContents* TabHelper::GetAssociatedWebContents() const {
642 return web_contents(); 637 return web_contents();
643 } 638 }
644 639
645 void TabHelper::OnExtensionUnloaded( 640 void TabHelper::OnExtensionUnloaded(
646 content::BrowserContext* browser_context, 641 content::BrowserContext* browser_context,
647 const Extension* extension, 642 const Extension* extension,
648 UnloadedExtensionInfo::Reason reason) { 643 UnloadedExtensionInfo::Reason reason) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 } 677 }
683 } 678 }
684 679
685 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) { 680 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) {
686 render_frame_host->Send( 681 render_frame_host->Send(
687 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(), 682 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(),
688 SessionTabHelper::IdForTab(web_contents()))); 683 SessionTabHelper::IdForTab(web_contents())));
689 } 684 }
690 685
691 } // namespace extensions 686 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698