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

Side by Side Diff: chrome/browser/chromeos/attestation/platform_verification_dialog.cc

Issue 1001723002: media: Refactor PlatformVerificationFlow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments addressed Created 5 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/chromeos/attestation/platform_verification_dialog.h" 5 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser_finder.h" 9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/browser_navigator.h" 10 #include "chrome/browser/ui/browser_navigator.h"
(...skipping 22 matching lines...) Expand all
33 namespace { 33 namespace {
34 34
35 const int kDialogMaxWidthInPixel = 400; 35 const int kDialogMaxWidthInPixel = 400;
36 36
37 } // namespace 37 } // namespace
38 38
39 // static 39 // static
40 views::Widget* PlatformVerificationDialog::ShowDialog( 40 views::Widget* PlatformVerificationDialog::ShowDialog(
41 content::WebContents* web_contents, 41 content::WebContents* web_contents,
42 const GURL& requesting_origin, 42 const GURL& requesting_origin,
43 const PlatformVerificationFlow::Delegate::ConsentCallback& callback) { 43 const ConsentCallback& callback) {
44 // In the case of an extension or hosted app, the origin of the request is 44 // In the case of an extension or hosted app, the origin of the request is
45 // best described by the extension / app name. 45 // best described by the extension / app name.
46 const extensions::Extension* extension = 46 const extensions::Extension* extension =
47 extensions::ExtensionRegistry::Get(web_contents->GetBrowserContext()) 47 extensions::ExtensionRegistry::Get(web_contents->GetBrowserContext())
48 ->enabled_extensions() 48 ->enabled_extensions()
49 .GetExtensionOrAppByURL(web_contents->GetLastCommittedURL()); 49 .GetExtensionOrAppByURL(web_contents->GetLastCommittedURL());
50 50
51 // TODO(xhwang): We should only show the name if the request if from the 51 // TODO(xhwang): We should only show the name if the request if from the
52 // extension's true frame. See http://crbug.com/455821 52 // extension's true frame. See http://crbug.com/455821
53 std::string origin = extension ? extension->name() : requesting_origin.spec(); 53 std::string origin = extension ? extension->name() : requesting_origin.spec();
(...skipping 13 matching lines...) Expand all
67 67
68 return widget; 68 return widget;
69 } 69 }
70 70
71 PlatformVerificationDialog::~PlatformVerificationDialog() { 71 PlatformVerificationDialog::~PlatformVerificationDialog() {
72 } 72 }
73 73
74 PlatformVerificationDialog::PlatformVerificationDialog( 74 PlatformVerificationDialog::PlatformVerificationDialog(
75 content::WebContents* web_contents, 75 content::WebContents* web_contents,
76 const base::string16& domain, 76 const base::string16& domain,
77 const PlatformVerificationFlow::Delegate::ConsentCallback& callback) 77 const ConsentCallback& callback)
78 : content::WebContentsObserver(web_contents), 78 : content::WebContentsObserver(web_contents),
79 domain_(domain), 79 domain_(domain),
80 callback_(callback) { 80 callback_(callback) {
81 SetLayoutManager(new views::FillLayout()); 81 SetLayoutManager(new views::FillLayout());
82 SetBorder(views::Border::CreateEmptyBorder( 82 SetBorder(views::Border::CreateEmptyBorder(
83 0, views::kButtonHEdgeMarginNew, 0, views::kButtonHEdgeMarginNew)); 83 0, views::kButtonHEdgeMarginNew, 0, views::kButtonHEdgeMarginNew));
84 const base::string16 learn_more = l10n_util::GetStringUTF16(IDS_LEARN_MORE); 84 const base::string16 learn_more = l10n_util::GetStringUTF16(IDS_LEARN_MORE);
85 std::vector<size_t> offsets; 85 std::vector<size_t> offsets;
86 base::string16 headline = l10n_util::GetStringFUTF16( 86 base::string16 headline = l10n_util::GetStringFUTF16(
87 IDS_PLATFORM_VERIFICATION_DIALOG_HEADLINE, domain_, learn_more, &offsets); 87 IDS_PLATFORM_VERIFICATION_DIALOG_HEADLINE, domain_, learn_more, &offsets);
88 views::StyledLabel* headline_label = new views::StyledLabel(headline, this); 88 views::StyledLabel* headline_label = new views::StyledLabel(headline, this);
89 headline_label->AddStyleRange( 89 headline_label->AddStyleRange(
90 gfx::Range(offsets[1], offsets[1] + learn_more.size()), 90 gfx::Range(offsets[1], offsets[1] + learn_more.size()),
91 views::StyledLabel::RangeStyleInfo::CreateForLink()); 91 views::StyledLabel::RangeStyleInfo::CreateForLink());
92 AddChildView(headline_label); 92 AddChildView(headline_label);
93 } 93 }
94 94
95 bool PlatformVerificationDialog::Cancel() { 95 bool PlatformVerificationDialog::Cancel() {
96 callback_.Run(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); 96 // This method is called when user clicked "Disable on <origin>" button or
97 // when user pressed the "Esc" key. See http://crbug.com/467155
98 callback_.Run(CONSENT_RESPONSE_DENY);
97 return true; 99 return true;
98 } 100 }
99 101
100 bool PlatformVerificationDialog::Accept() { 102 bool PlatformVerificationDialog::Accept() {
101 callback_.Run(PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW); 103 // This method is called when user clicked "OK, I got it" button.
104 callback_.Run(CONSENT_RESPONSE_ALLOW);
102 return true; 105 return true;
103 } 106 }
104 107
105 bool PlatformVerificationDialog::Close() { 108 bool PlatformVerificationDialog::Close() {
106 // This method is called when the tab is closed and in that case the decision 109 // This method is called when user clicked "x" to dismiss the dialog, the
107 // hasn't been made yet. 110 // permission request is canceled, or when the tab containing this dialog is
108 callback_.Run(PlatformVerificationFlow::CONSENT_RESPONSE_NONE); 111 // closed.
112 callback_.Run(CONSENT_RESPONSE_NONE);
109 return true; 113 return true;
110 } 114 }
111 115
112 base::string16 PlatformVerificationDialog::GetDialogButtonLabel( 116 base::string16 PlatformVerificationDialog::GetDialogButtonLabel(
113 ui::DialogButton button) const { 117 ui::DialogButton button) const {
114 switch (button) { 118 switch (button) {
115 case ui::DIALOG_BUTTON_OK: 119 case ui::DIALOG_BUTTON_OK:
116 return l10n_util::GetStringUTF16(IDS_PLATFORM_VERIFICATION_DIALOG_ALLOW); 120 return l10n_util::GetStringUTF16(IDS_PLATFORM_VERIFICATION_DIALOG_ALLOW);
117 case ui::DIALOG_BUTTON_CANCEL: 121 case ui::DIALOG_BUTTON_CANCEL:
118 return l10n_util::GetStringFUTF16( 122 return l10n_util::GetStringFUTF16(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 void PlatformVerificationDialog::DidStartNavigationToPendingEntry( 158 void PlatformVerificationDialog::DidStartNavigationToPendingEntry(
155 const GURL& url, 159 const GURL& url,
156 content::NavigationController::ReloadType reload_type) { 160 content::NavigationController::ReloadType reload_type) {
157 views::Widget* widget = GetWidget(); 161 views::Widget* widget = GetWidget();
158 if (widget) 162 if (widget)
159 widget->Close(); 163 widget->Close();
160 } 164 }
161 165
162 } // namespace attestation 166 } // namespace attestation
163 } // namespace chromeos 167 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698