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

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

Issue 243463006: Merge 264451 "Fixes the crash for "learn more" link of the dialo..." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1916/src/
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/attestation/platform_verification_dialog.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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->ShowDialog(widget->GetNativeView()); 63 web_contents_modal_dialog_manager->ShowDialog(widget->GetNativeView());
61 widget->Show(); 64 widget->Show();
62 } 65 }
63 66
64 PlatformVerificationDialog::~PlatformVerificationDialog() { 67 PlatformVerificationDialog::~PlatformVerificationDialog() {
65 } 68 }
66 69
67 PlatformVerificationDialog::PlatformVerificationDialog( 70 PlatformVerificationDialog::PlatformVerificationDialog(
68 Browser* browser, 71 content::WebContents* web_contents,
69 const base::string16& domain, 72 const base::string16& domain,
70 const PlatformVerificationFlow::Delegate::ConsentCallback& callback) 73 const PlatformVerificationFlow::Delegate::ConsentCallback& callback)
71 : browser_(browser), 74 : web_contents_(web_contents),
72 domain_(domain), 75 domain_(domain),
73 callback_(callback) { 76 callback_(callback) {
74 SetLayoutManager(new views::FillLayout()); 77 SetLayoutManager(new views::FillLayout());
75 SetBorder(views::Border::CreateEmptyBorder( 78 SetBorder(views::Border::CreateEmptyBorder(
76 0, views::kButtonHEdgeMarginNew, 0, views::kButtonHEdgeMarginNew)); 79 0, views::kButtonHEdgeMarginNew, 0, views::kButtonHEdgeMarginNew));
77 const base::string16 learn_more = l10n_util::GetStringUTF16(IDS_LEARN_MORE); 80 const base::string16 learn_more = l10n_util::GetStringUTF16(IDS_LEARN_MORE);
78 std::vector<size_t> offsets; 81 std::vector<size_t> offsets;
79 base::string16 headline = l10n_util::GetStringFUTF16( 82 base::string16 headline = l10n_util::GetStringFUTF16(
80 IDS_PLATFORM_VERIFICATION_DIALOG_HEADLINE, domain_, learn_more, &offsets); 83 IDS_PLATFORM_VERIFICATION_DIALOG_HEADLINE, domain_, learn_more, &offsets);
81 views::StyledLabel* headline_label = new views::StyledLabel(headline, this); 84 views::StyledLabel* headline_label = new views::StyledLabel(headline, this);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 return ui::MODAL_TYPE_CHILD; 123 return ui::MODAL_TYPE_CHILD;
121 } 124 }
122 125
123 gfx::Size PlatformVerificationDialog::GetPreferredSize() { 126 gfx::Size PlatformVerificationDialog::GetPreferredSize() {
124 return gfx::Size(kDialogMaxWidthInPixel, 127 return gfx::Size(kDialogMaxWidthInPixel,
125 GetHeightForWidth(kDialogMaxWidthInPixel)); 128 GetHeightForWidth(kDialogMaxWidthInPixel));
126 } 129 }
127 130
128 void PlatformVerificationDialog::StyledLabelLinkClicked(const gfx::Range& range, 131 void PlatformVerificationDialog::StyledLabelLinkClicked(const gfx::Range& range,
129 int event_flags) { 132 int event_flags) {
130 chrome::ShowSingletonTab(browser_, GURL( 133 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
131 chrome::kEnhancedPlaybackNotificationLearnMoreURL)); 134 const GURL learn_more_url(chrome::kEnhancedPlaybackNotificationLearnMoreURL);
135
136 // |web_contents_| might not be in a browser in case of v2 apps. In that case,
137 // open a new tab in the usual way.
138 if (!browser) {
139 Profile* profile = Profile::FromBrowserContext(
140 web_contents_->GetBrowserContext());
141 chrome::NavigateParams params(
142 profile, learn_more_url, content::PAGE_TRANSITION_LINK);
143 params.disposition = SINGLETON_TAB;
144 chrome::Navigate(&params);
145 } else {
146 chrome::ShowSingletonTab(browser, learn_more_url);
147 }
132 } 148 }
133 149
134 } // namespace attestation 150 } // namespace attestation
135 } // namespace chromeos 151 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/attestation/platform_verification_dialog.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698