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

Side by Side Diff: chrome/browser/chromeos/enrollment_dialog_view.cc

Issue 12089026: Fixing opening a new tab if none exists to show the enrollment URI for certificates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Sky's comment. Some more cleanup. Created 7 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
« no previous file with comments | « chrome/browser/chromeos/enrollment_dialog_view.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 (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/chromeos/enrollment_dialog_view.h" 5 #include "chrome/browser/chromeos/enrollment_dialog_view.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/chromeos/cros/network_library.h" 9 #include "chrome/browser/chromeos/cros/network_library.h"
10 #include "chrome/browser/extensions/extension_host.h" 10 #include "chrome/browser/extensions/extension_host.h"
11 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser_finder.h" 12 #include "chrome/browser/ui/browser_navigator.h"
13 #include "chrome/browser/ui/browser_tabstrip.h"
14 #include "chrome/browser/ui/host_desktop.h"
15 #include "content/public/common/page_transition_types.h" 13 #include "content/public/common/page_transition_types.h"
16 #include "extensions/common/constants.h" 14 #include "extensions/common/constants.h"
17 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
18 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/views/controls/label.h" 18 #include "ui/views/controls/label.h"
21 #include "ui/views/layout/grid_layout.h" 19 #include "ui/views/layout/grid_layout.h"
22 #include "ui/views/layout/layout_constants.h" 20 #include "ui/views/layout/layout_constants.h"
23 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
22 #include "ui/views/window/dialog_delegate.h"
24 23
25 namespace chromeos { 24 namespace chromeos {
26 25
27 namespace { 26 namespace {
28 27
29 // Default width/height of the dialog. 28 // Default width/height of the dialog.
30 const int kDefaultWidth = 350; 29 const int kDefaultWidth = 350;
31 const int kDefaultHeight = 100; 30 const int kDefaultHeight = 100;
32 31
33 //////////////////////////////////////////////////////////////////////////////// 32 ////////////////////////////////////////////////////////////////////////////////
34 // Dialog for certificate enrollment. This displays the content from the 33 // Dialog for certificate enrollment. This displays the content from the
35 // certificate enrollment URI. 34 // certificate enrollment URI.
36 class EnrollmentDialogView : public views::DialogDelegateView { 35 class EnrollmentDialogView : public views::DialogDelegateView {
37 public: 36 public:
38 virtual ~EnrollmentDialogView(); 37 virtual ~EnrollmentDialogView();
39 38
40 static void ShowDialog(gfx::NativeWindow owning_window, 39 static void ShowDialog(gfx::NativeWindow owning_window,
41 const std::string& network_name, 40 const std::string& network_name,
42 Profile* profile, 41 Profile* profile,
43 const GURL& target_uri, 42 const GURL& target_uri,
44 const base::Closure& connect); 43 const base::Closure& connect);
45 44
46 // views::DialogDelegateView overrides 45 // views::DialogDelegateView overrides
47 virtual int GetDialogButtons() const OVERRIDE; 46 virtual int GetDialogButtons() const OVERRIDE;
48 virtual bool Accept() OVERRIDE; 47 virtual bool Accept() OVERRIDE;
48 virtual void OnClose() OVERRIDE;
49 virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE; 49 virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE;
50 50
51 // views::WidgetDelegate overrides 51 // views::WidgetDelegate overrides
52 virtual ui::ModalType GetModalType() const OVERRIDE; 52 virtual ui::ModalType GetModalType() const OVERRIDE;
53 virtual string16 GetWindowTitle() const OVERRIDE; 53 virtual string16 GetWindowTitle() const OVERRIDE;
54 54
55 // views::View overrides 55 // views::View overrides
56 virtual gfx::Size GetPreferredSize() OVERRIDE; 56 virtual gfx::Size GetPreferredSize() OVERRIDE;
57 57
58 private: 58 private:
59 EnrollmentDialogView(const std::string& network_name, 59 EnrollmentDialogView(const std::string& network_name,
60 Profile* profile, 60 Profile* profile,
61 const GURL& target_uri, 61 const GURL& target_uri,
62 const base::Closure& connect); 62 const base::Closure& connect);
63 void InitDialog(); 63 void InitDialog();
64 64
65 bool accepted_;
65 std::string network_name_; 66 std::string network_name_;
66 Profile* profile_; 67 Profile* profile_;
67 GURL target_uri_; 68 GURL target_uri_;
68 base::Closure connect_; 69 base::Closure connect_;
69 bool added_cert_; 70 bool added_cert_;
70 }; 71 };
71 72
72 //////////////////////////////////////////////////////////////////////////////// 73 ////////////////////////////////////////////////////////////////////////////////
73 // EnrollmentDialogView implementation. 74 // EnrollmentDialogView implementation.
74 75
75 EnrollmentDialogView::EnrollmentDialogView(const std::string& network_name, 76 EnrollmentDialogView::EnrollmentDialogView(const std::string& network_name,
76 Profile* profile, 77 Profile* profile,
77 const GURL& target_uri, 78 const GURL& target_uri,
78 const base::Closure& connect) 79 const base::Closure& connect)
79 : network_name_(network_name), 80 : accepted_(false),
81 network_name_(network_name),
80 profile_(profile), 82 profile_(profile),
81 target_uri_(target_uri), 83 target_uri_(target_uri),
82 connect_(connect), 84 connect_(connect),
83 added_cert_(false) { 85 added_cert_(false) {
84 } 86 }
85 87
86 EnrollmentDialogView::~EnrollmentDialogView() { 88 EnrollmentDialogView::~EnrollmentDialogView() {
87 } 89 }
88 90
89 // static 91 // static
90 void EnrollmentDialogView::ShowDialog(gfx::NativeWindow owning_window, 92 void EnrollmentDialogView::ShowDialog(gfx::NativeWindow owning_window,
91 const std::string& network_name, 93 const std::string& network_name,
92 Profile* profile, 94 Profile* profile,
93 const GURL& target_uri, 95 const GURL& target_uri,
94 const base::Closure& connect) { 96 const base::Closure& connect) {
95 EnrollmentDialogView* dialog_view = 97 EnrollmentDialogView* dialog_view =
96 new EnrollmentDialogView(network_name, profile, target_uri, connect); 98 new EnrollmentDialogView(network_name, profile, target_uri, connect);
97 views::Widget::CreateWindowWithParent(dialog_view, owning_window); 99 views::Widget::CreateWindowWithParent(dialog_view, owning_window);
98 dialog_view->InitDialog(); 100 dialog_view->InitDialog();
99 views::Widget* widget = dialog_view->GetWidget(); 101 views::Widget* widget = dialog_view->GetWidget();
100 DCHECK(widget); 102 DCHECK(widget);
101 widget->Show(); 103 widget->Show();
102 } 104 }
103 105
104 int EnrollmentDialogView::GetDialogButtons() const { 106 int EnrollmentDialogView::GetDialogButtons() const {
105 return ui::DIALOG_BUTTON_CANCEL | ui::DIALOG_BUTTON_OK; 107 return ui::DIALOG_BUTTON_CANCEL | ui::DIALOG_BUTTON_OK;
106 } 108 }
107 109
108 bool EnrollmentDialogView::Accept() { 110 bool EnrollmentDialogView::Accept() {
109 // TODO(beng): use Navigate(). 111 accepted_ = true;
110 // Navigate to the target URI in a browser tab. 112 return true;
111 Browser* browser = chrome::FindTabbedBrowser(profile_, false, 113 }
112 chrome::HOST_DESKTOP_TYPE_ASH); 114
113 if (!browser) { 115 void EnrollmentDialogView::OnClose() {
114 // Couldn't find a tabbed browser: create one. 116 if (!accepted_)
115 browser = new Browser( 117 return;
116 Browser::CreateParams(Browser::TYPE_TABBED, 118 chrome::NavigateParams params(profile_,
117 profile_, 119 GURL(target_uri_),
118 chrome::HOST_DESKTOP_TYPE_ASH));
119 }
120 DCHECK(browser);
121 chrome::AddSelectedTabWithURL(browser, target_uri_,
122 content::PAGE_TRANSITION_LINK); 120 content::PAGE_TRANSITION_LINK);
123 return true; 121 params.disposition = NEW_FOREGROUND_TAB;
122 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
123 chrome::Navigate(&params);
124 } 124 }
125 125
126 string16 EnrollmentDialogView::GetDialogButtonLabel( 126 string16 EnrollmentDialogView::GetDialogButtonLabel(
127 ui::DialogButton button) const { 127 ui::DialogButton button) const {
128 if (button == ui::DIALOG_BUTTON_OK) 128 if (button == ui::DIALOG_BUTTON_OK)
129 return l10n_util::GetStringUTF16(IDS_NETWORK_ENROLLMENT_HANDLER_BUTTON); 129 return l10n_util::GetStringUTF16(IDS_NETWORK_ENROLLMENT_HANDLER_BUTTON);
130 return views::DialogDelegateView::GetDialogButtonLabel(button); 130 return views::DialogDelegateView::GetDialogButtonLabel(button);
131 } 131 }
132 132
133 ui::ModalType EnrollmentDialogView::GetModalType() const { 133 ui::ModalType EnrollmentDialogView::GetModalType() const {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 //////////////////////////////////////////////////////////////////////////////// 246 ////////////////////////////////////////////////////////////////////////////////
247 // Factory function. 247 // Factory function.
248 248
249 EnrollmentDelegate* CreateEnrollmentDelegate(gfx::NativeWindow owning_window, 249 EnrollmentDelegate* CreateEnrollmentDelegate(gfx::NativeWindow owning_window,
250 const std::string& network_name, 250 const std::string& network_name,
251 Profile* profile) { 251 Profile* profile) {
252 return new DialogEnrollmentDelegate(owning_window, network_name, profile); 252 return new DialogEnrollmentDelegate(owning_window, network_name, profile);
253 } 253 }
254 254
255 } // namespace chromeos 255 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/enrollment_dialog_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698