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

Side by Side Diff: chrome/browser/ui/views/extensions/extension_install_dialog_view.cc

Issue 1534123002: [Extensions] Migrate ExtensionInstallPrompt::Delegate to be a callback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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/ui/views/extensions/extension_install_dialog_view.h" 5 #include "chrome/browser/ui/views/extensions/extension_install_dialog_view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback_helpers.h"
13 #include "base/command_line.h" 14 #include "base/command_line.h"
14 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
15 #include "base/i18n/rtl.h" 16 #include "base/i18n/rtl.h"
16 #include "base/macros.h" 17 #include "base/macros.h"
17 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
18 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
19 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
20 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h" 22 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h"
22 #include "chrome/browser/extensions/bundle_installer.h" 23 #include "chrome/browser/extensions/bundle_installer.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // like a entry in a bullet point list, one is added. 97 // like a entry in a bullet point list, one is added.
97 base::string16 PrepareForDisplay(const base::string16& message, 98 base::string16 PrepareForDisplay(const base::string16& message,
98 bool bullet_point) { 99 bool bullet_point) {
99 return bullet_point ? l10n_util::GetStringFUTF16( 100 return bullet_point ? l10n_util::GetStringFUTF16(
100 IDS_EXTENSION_PERMISSION_LINE, 101 IDS_EXTENSION_PERMISSION_LINE,
101 message) : message; 102 message) : message;
102 } 103 }
103 104
104 void ShowExtensionInstallDialogImpl( 105 void ShowExtensionInstallDialogImpl(
105 ExtensionInstallPromptShowParams* show_params, 106 ExtensionInstallPromptShowParams* show_params,
106 ExtensionInstallPrompt::Delegate* delegate, 107 const ExtensionInstallPrompt::DoneCallback& done_callback,
107 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt) { 108 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt) {
108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 109 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
109 bool use_tab_modal_dialog = prompt->ShouldUseTabModalDialog(); 110 bool use_tab_modal_dialog = prompt->ShouldUseTabModalDialog();
110 ExtensionInstallDialogView* dialog = new ExtensionInstallDialogView( 111 ExtensionInstallDialogView* dialog = new ExtensionInstallDialogView(
111 show_params->profile(), show_params->GetParentWebContents(), delegate, 112 show_params->profile(), show_params->GetParentWebContents(),
112 std::move(prompt)); 113 done_callback, std::move(prompt));
113 if (use_tab_modal_dialog) { 114 if (use_tab_modal_dialog) {
114 content::WebContents* parent_web_contents = 115 content::WebContents* parent_web_contents =
115 show_params->GetParentWebContents(); 116 show_params->GetParentWebContents();
116 if (parent_web_contents) 117 if (parent_web_contents)
117 constrained_window::ShowWebModalDialogViews(dialog, parent_web_contents); 118 constrained_window::ShowWebModalDialogViews(dialog, parent_web_contents);
118 } else { 119 } else {
119 constrained_window::CreateBrowserModalDialogViews( 120 constrained_window::CreateBrowserModalDialogViews(
120 dialog, show_params->GetParentWindow()) 121 dialog, show_params->GetParentWindow())
121 ->Show(); 122 ->Show();
122 } 123 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 image_view->SetImage(image); 192 image_view->SetImage(image);
192 image_view->SetImageSize(size); 193 image_view->SetImageSize(size);
193 194
194 layout->AddView(image_view); 195 layout->AddView(image_view);
195 layout->AddView(view); 196 layout->AddView(view);
196 } 197 }
197 198
198 ExtensionInstallDialogView::ExtensionInstallDialogView( 199 ExtensionInstallDialogView::ExtensionInstallDialogView(
199 Profile* profile, 200 Profile* profile,
200 content::PageNavigator* navigator, 201 content::PageNavigator* navigator,
201 ExtensionInstallPrompt::Delegate* delegate, 202 const ExtensionInstallPrompt::DoneCallback& done_callback,
202 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt) 203 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt)
203 : profile_(profile), 204 : profile_(profile),
204 navigator_(navigator), 205 navigator_(navigator),
205 delegate_(delegate), 206 done_callback_(done_callback),
206 prompt_(std::move(prompt)), 207 prompt_(std::move(prompt)),
207 container_(NULL), 208 container_(NULL),
208 scroll_view_(NULL), 209 scroll_view_(NULL),
209 handled_result_(false) { 210 handled_result_(false) {
210 InitView(); 211 InitView();
211 } 212 }
212 213
213 ExtensionInstallDialogView::~ExtensionInstallDialogView() { 214 ExtensionInstallDialogView::~ExtensionInstallDialogView() {
214 if (!handled_result_) 215 if (!handled_result_ && !done_callback_.is_null()) {
215 delegate_->InstallUIAbort(true); 216 base::ResetAndReturn(&done_callback_)
217 .Run(ExtensionInstallPrompt::Result::USER_CANCELED);
218 }
216 } 219 }
217 220
218 void ExtensionInstallDialogView::InitView() { 221 void ExtensionInstallDialogView::InitView() {
219 // Possible grid layouts: 222 // Possible grid layouts:
220 // With webstore data (inline install, external install, repair) 223 // With webstore data (inline install, external install, repair)
221 // w/ permissions no permissions 224 // w/ permissions no permissions
222 // +--------------+------+ +--------------+------+ 225 // +--------------+------+ +--------------+------+
223 // | title | icon | | title | icon | 226 // | title | icon | | title | icon |
224 // +--------------| | +--------------| | 227 // +--------------| | +--------------| |
225 // | rating | | | rating | | 228 // | rating | | | rating | |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 589 }
587 590
588 bool ExtensionInstallDialogView::Cancel() { 591 bool ExtensionInstallDialogView::Cancel() {
589 if (handled_result_) 592 if (handled_result_)
590 return true; 593 return true;
591 594
592 handled_result_ = true; 595 handled_result_ = true;
593 UpdateInstallResultHistogram(false); 596 UpdateInstallResultHistogram(false);
594 if (sampling_event_) 597 if (sampling_event_)
595 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny); 598 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kDeny);
596 delegate_->InstallUIAbort(true); 599 base::ResetAndReturn(&done_callback_)
600 .Run(ExtensionInstallPrompt::Result::USER_CANCELED);
597 return true; 601 return true;
598 } 602 }
599 603
600 bool ExtensionInstallDialogView::Accept() { 604 bool ExtensionInstallDialogView::Accept() {
601 DCHECK(!handled_result_); 605 DCHECK(!handled_result_);
602 606
603 handled_result_ = true; 607 handled_result_ = true;
604 UpdateInstallResultHistogram(true); 608 UpdateInstallResultHistogram(true);
605 if (sampling_event_) 609 if (sampling_event_)
606 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed); 610 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed);
607 delegate_->InstallUIProceed(); 611 base::ResetAndReturn(&done_callback_)
612 .Run(ExtensionInstallPrompt::Result::ACCEPTED);
608 return true; 613 return true;
609 } 614 }
610 615
611 ui::ModalType ExtensionInstallDialogView::GetModalType() const { 616 ui::ModalType ExtensionInstallDialogView::GetModalType() const {
612 return prompt_->ShouldUseTabModalDialog() ? ui::MODAL_TYPE_CHILD 617 return prompt_->ShouldUseTabModalDialog() ? ui::MODAL_TYPE_CHILD
613 : ui::MODAL_TYPE_WINDOW; 618 : ui::MODAL_TYPE_WINDOW;
614 } 619 }
615 620
616 void ExtensionInstallDialogView::LinkClicked(views::Link* source, 621 void ExtensionInstallDialogView::LinkClicked(views::Link* source,
617 int event_flags) { 622 int event_flags) {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 expanded ? gfx::VectorIconId::FIND_PREV : gfx::VectorIconId::FIND_NEXT, 835 expanded ? gfx::VectorIconId::FIND_PREV : gfx::VectorIconId::FIND_NEXT,
831 16, gfx::kChromeIconGrey); 836 16, gfx::kChromeIconGrey);
832 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon); 837 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon);
833 } 838 }
834 839
835 // static 840 // static
836 ExtensionInstallPrompt::ShowDialogCallback 841 ExtensionInstallPrompt::ShowDialogCallback
837 ExtensionInstallPrompt::GetDefaultShowDialogCallback() { 842 ExtensionInstallPrompt::GetDefaultShowDialogCallback() {
838 return base::Bind(&ShowExtensionInstallDialogImpl); 843 return base::Bind(&ShowExtensionInstallDialogImpl);
839 } 844 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698