| 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/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/browser_navigator.h" |
| 9 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
| 10 #include "chrome/browser/ui/singleton_tabs.h" | 12 #include "chrome/browser/ui/singleton_tabs.h" |
| 11 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
| 12 #include "components/web_modal/web_contents_modal_dialog_host.h" | 14 #include "components/web_modal/web_contents_modal_dialog_host.h" |
| 13 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 15 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 14 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 16 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
| 15 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/common/page_transition_types.h" |
| 16 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
| 17 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 18 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 19 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/views/border.h" | 24 #include "ui/views/border.h" |
| 22 #include "ui/views/controls/styled_label.h" | 25 #include "ui/views/controls/styled_label.h" |
| 23 #include "ui/views/layout/fill_layout.h" | 26 #include "ui/views/layout/fill_layout.h" |
| 24 #include "ui/views/layout/layout_constants.h" | 27 #include "ui/views/layout/layout_constants.h" |
| 25 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 39 const PlatformVerificationFlow::Delegate::ConsentCallback& callback) { | 42 const PlatformVerificationFlow::Delegate::ConsentCallback& callback) { |
| 40 GURL url = web_contents->GetLastCommittedURL(); | 43 GURL url = web_contents->GetLastCommittedURL(); |
| 41 // 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 |
| 42 // best described by the extension / app name. | 45 // best described by the extension / app name. |
| 43 const extensions::Extension* extension = | 46 const extensions::Extension* extension = |
| 44 extensions::ExtensionRegistry::Get(web_contents->GetBrowserContext())-> | 47 extensions::ExtensionRegistry::Get(web_contents->GetBrowserContext())-> |
| 45 enabled_extensions().GetExtensionOrAppByURL(url); | 48 enabled_extensions().GetExtensionOrAppByURL(url); |
| 46 std::string origin = extension ? extension->name() : url.GetOrigin().spec(); | 49 std::string origin = extension ? extension->name() : url.GetOrigin().spec(); |
| 47 | 50 |
| 48 PlatformVerificationDialog* dialog = new PlatformVerificationDialog( | 51 PlatformVerificationDialog* dialog = new PlatformVerificationDialog( |
| 49 chrome::FindBrowserWithWebContents(web_contents), | 52 web_contents, |
| 50 base::UTF8ToUTF16(origin), | 53 base::UTF8ToUTF16(origin), |
| 51 callback); | 54 callback); |
| 52 | 55 |
| 53 // Sets up the dialog widget and shows it. | 56 // Sets up the dialog widget and shows it. |
| 54 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 57 web_modal::WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 55 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); | 58 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents); |
| 56 web_modal::WebContentsModalDialogManagerDelegate* modal_delegate = | 59 web_modal::WebContentsModalDialogManagerDelegate* modal_delegate = |
| 57 web_contents_modal_dialog_manager->delegate(); | 60 web_contents_modal_dialog_manager->delegate(); |
| 58 views::Widget* widget = views::Widget::CreateWindowAsFramelessChild( | 61 views::Widget* widget = views::Widget::CreateWindowAsFramelessChild( |
| 59 dialog, modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); | 62 dialog, modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); |
| 60 web_contents_modal_dialog_manager->ShowModalDialog( | 63 web_contents_modal_dialog_manager->ShowModalDialog( |
| 61 widget->GetNativeView()); | 64 widget->GetNativeView()); |
| 62 widget->Show(); | 65 widget->Show(); |
| 63 } | 66 } |
| 64 | 67 |
| 65 PlatformVerificationDialog::~PlatformVerificationDialog() { | 68 PlatformVerificationDialog::~PlatformVerificationDialog() { |
| 66 } | 69 } |
| 67 | 70 |
| 68 PlatformVerificationDialog::PlatformVerificationDialog( | 71 PlatformVerificationDialog::PlatformVerificationDialog( |
| 69 Browser* browser, | 72 content::WebContents* web_contents, |
| 70 const base::string16& domain, | 73 const base::string16& domain, |
| 71 const PlatformVerificationFlow::Delegate::ConsentCallback& callback) | 74 const PlatformVerificationFlow::Delegate::ConsentCallback& callback) |
| 72 : browser_(browser), | 75 : web_contents_(web_contents), |
| 73 domain_(domain), | 76 domain_(domain), |
| 74 callback_(callback) { | 77 callback_(callback) { |
| 75 SetLayoutManager(new views::FillLayout()); | 78 SetLayoutManager(new views::FillLayout()); |
| 76 SetBorder(views::Border::CreateEmptyBorder( | 79 SetBorder(views::Border::CreateEmptyBorder( |
| 77 0, views::kButtonHEdgeMarginNew, 0, views::kButtonHEdgeMarginNew)); | 80 0, views::kButtonHEdgeMarginNew, 0, views::kButtonHEdgeMarginNew)); |
| 78 const base::string16 learn_more = l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 81 const base::string16 learn_more = l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 79 std::vector<size_t> offsets; | 82 std::vector<size_t> offsets; |
| 80 base::string16 headline = l10n_util::GetStringFUTF16( | 83 base::string16 headline = l10n_util::GetStringFUTF16( |
| 81 IDS_PLATFORM_VERIFICATION_DIALOG_HEADLINE, domain_, learn_more, &offsets); | 84 IDS_PLATFORM_VERIFICATION_DIALOG_HEADLINE, domain_, learn_more, &offsets); |
| 82 views::StyledLabel* headline_label = new views::StyledLabel(headline, this); | 85 views::StyledLabel* headline_label = new views::StyledLabel(headline, this); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 return ui::MODAL_TYPE_CHILD; | 124 return ui::MODAL_TYPE_CHILD; |
| 122 } | 125 } |
| 123 | 126 |
| 124 gfx::Size PlatformVerificationDialog::GetPreferredSize() { | 127 gfx::Size PlatformVerificationDialog::GetPreferredSize() { |
| 125 return gfx::Size(kDialogMaxWidthInPixel, | 128 return gfx::Size(kDialogMaxWidthInPixel, |
| 126 GetHeightForWidth(kDialogMaxWidthInPixel)); | 129 GetHeightForWidth(kDialogMaxWidthInPixel)); |
| 127 } | 130 } |
| 128 | 131 |
| 129 void PlatformVerificationDialog::StyledLabelLinkClicked(const gfx::Range& range, | 132 void PlatformVerificationDialog::StyledLabelLinkClicked(const gfx::Range& range, |
| 130 int event_flags) { | 133 int event_flags) { |
| 131 chrome::ShowSingletonTab(browser_, GURL( | 134 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
| 132 chrome::kEnhancedPlaybackNotificationLearnMoreURL)); | 135 const GURL learn_more_url(chrome::kEnhancedPlaybackNotificationLearnMoreURL); |
| 136 |
| 137 // |web_contents_| might not be in a browser in case of v2 apps. In that case, |
| 138 // open a new tab in the usual way. |
| 139 if (!browser) { |
| 140 Profile* profile = Profile::FromBrowserContext( |
| 141 web_contents_->GetBrowserContext()); |
| 142 chrome::NavigateParams params( |
| 143 profile, learn_more_url, content::PAGE_TRANSITION_LINK); |
| 144 params.disposition = SINGLETON_TAB; |
| 145 chrome::Navigate(¶ms); |
| 146 } else { |
| 147 chrome::ShowSingletonTab(browser, learn_more_url); |
| 148 } |
| 133 } | 149 } |
| 134 | 150 |
| 135 } // namespace attestation | 151 } // namespace attestation |
| 136 } // namespace chromeos | 152 } // namespace chromeos |
| OLD | NEW |