Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 callback_.Run(CONSENT_RESPONSE_DENY); |
| 97 return true; | 97 return true; |
| 98 } | 98 } |
| 99 | 99 |
| 100 bool PlatformVerificationDialog::Accept() { | 100 bool PlatformVerificationDialog::Accept() { |
| 101 callback_.Run(PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW); | 101 callback_.Run(CONSENT_RESPONSE_ALLOW); |
| 102 return true; | 102 return true; |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool PlatformVerificationDialog::Close() { | 105 bool PlatformVerificationDialog::Close() { |
| 106 // This method is called when the tab is closed and in that case the decision | 106 // This method is called when the tab is closed and in that case the decision |
| 107 // hasn't been made yet. | 107 // hasn't been made yet. |
|
ddorwin
2015/03/12 00:28:32
Or the 'X' is clicked or "esc" are pressed?
| |
| 108 callback_.Run(PlatformVerificationFlow::CONSENT_RESPONSE_NONE); | 108 callback_.Run(CONSENT_RESPONSE_NONE); |
| 109 return true; | 109 return true; |
| 110 } | 110 } |
| 111 | 111 |
| 112 base::string16 PlatformVerificationDialog::GetDialogButtonLabel( | 112 base::string16 PlatformVerificationDialog::GetDialogButtonLabel( |
| 113 ui::DialogButton button) const { | 113 ui::DialogButton button) const { |
| 114 switch (button) { | 114 switch (button) { |
| 115 case ui::DIALOG_BUTTON_OK: | 115 case ui::DIALOG_BUTTON_OK: |
| 116 return l10n_util::GetStringUTF16(IDS_PLATFORM_VERIFICATION_DIALOG_ALLOW); | 116 return l10n_util::GetStringUTF16(IDS_PLATFORM_VERIFICATION_DIALOG_ALLOW); |
| 117 case ui::DIALOG_BUTTON_CANCEL: | 117 case ui::DIALOG_BUTTON_CANCEL: |
| 118 return l10n_util::GetStringFUTF16( | 118 return l10n_util::GetStringFUTF16( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 void PlatformVerificationDialog::DidStartNavigationToPendingEntry( | 154 void PlatformVerificationDialog::DidStartNavigationToPendingEntry( |
| 155 const GURL& url, | 155 const GURL& url, |
| 156 content::NavigationController::ReloadType reload_type) { | 156 content::NavigationController::ReloadType reload_type) { |
| 157 views::Widget* widget = GetWidget(); | 157 views::Widget* widget = GetWidget(); |
| 158 if (widget) | 158 if (widget) |
| 159 widget->Close(); | 159 widget->Close(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace attestation | 162 } // namespace attestation |
| 163 } // namespace chromeos | 163 } // namespace chromeos |
| OLD | NEW |