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

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: Addressing comments and calling navigate after dialog closed. Created 7 years, 10 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 | « no previous file | 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_manager.h"
12 #include "chrome/browser/ui/browser_finder.h" 12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_tabstrip.h" 13 #include "chrome/browser/ui/browser_navigator.h"
14 #include "chrome/browser/ui/host_desktop.h" 14 #include "chrome/browser/ui/host_desktop.h"
15 #include "content/public/common/page_transition_types.h" 15 #include "content/public/common/page_transition_types.h"
16 #include "extensions/common/constants.h" 16 #include "extensions/common/constants.h"
17 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
18 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/views/controls/label.h" 20 #include "ui/views/controls/label.h"
21 #include "ui/views/layout/grid_layout.h" 21 #include "ui/views/layout/grid_layout.h"
22 #include "ui/views/layout/layout_constants.h" 22 #include "ui/views/layout/layout_constants.h"
23 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
(...skipping 15 matching lines...) Expand all
39 39
40 static void ShowDialog(gfx::NativeWindow owning_window, 40 static void ShowDialog(gfx::NativeWindow owning_window,
41 const std::string& network_name, 41 const std::string& network_name,
42 Profile* profile, 42 Profile* profile,
43 const GURL& target_uri, 43 const GURL& target_uri,
44 const base::Closure& connect); 44 const base::Closure& connect);
45 45
46 // views::DialogDelegateView overrides 46 // views::DialogDelegateView overrides
47 virtual int GetDialogButtons() const OVERRIDE; 47 virtual int GetDialogButtons() const OVERRIDE;
48 virtual bool Accept() OVERRIDE; 48 virtual bool Accept() OVERRIDE;
49 virtual void OnClose() OVERRIDE;
49 virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE; 50 virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE;
50 51
51 // views::WidgetDelegate overrides 52 // views::WidgetDelegate overrides
52 virtual ui::ModalType GetModalType() const OVERRIDE; 53 virtual ui::ModalType GetModalType() const OVERRIDE;
53 virtual string16 GetWindowTitle() const OVERRIDE; 54 virtual string16 GetWindowTitle() const OVERRIDE;
54 55
55 // views::View overrides 56 // views::View overrides
56 virtual gfx::Size GetPreferredSize() OVERRIDE; 57 virtual gfx::Size GetPreferredSize() OVERRIDE;
57 58
58 private: 59 private:
59 EnrollmentDialogView(const std::string& network_name, 60 EnrollmentDialogView(const std::string& network_name,
60 Profile* profile, 61 Profile* profile,
61 const GURL& target_uri, 62 const GURL& target_uri,
62 const base::Closure& connect); 63 const base::Closure& connect);
63 void InitDialog(); 64 void InitDialog();
64 65
66 bool accepted_;
65 std::string network_name_; 67 std::string network_name_;
66 Profile* profile_; 68 Profile* profile_;
67 GURL target_uri_; 69 GURL target_uri_;
68 base::Closure connect_; 70 base::Closure connect_;
69 bool added_cert_; 71 bool added_cert_;
70 }; 72 };
71 73
72 //////////////////////////////////////////////////////////////////////////////// 74 ////////////////////////////////////////////////////////////////////////////////
73 // EnrollmentDialogView implementation. 75 // EnrollmentDialogView implementation.
74 76
75 EnrollmentDialogView::EnrollmentDialogView(const std::string& network_name, 77 EnrollmentDialogView::EnrollmentDialogView(const std::string& network_name,
76 Profile* profile, 78 Profile* profile,
77 const GURL& target_uri, 79 const GURL& target_uri,
78 const base::Closure& connect) 80 const base::Closure& connect)
79 : network_name_(network_name), 81 : accepted_(false),
82 network_name_(network_name),
80 profile_(profile), 83 profile_(profile),
81 target_uri_(target_uri), 84 target_uri_(target_uri),
82 connect_(connect), 85 connect_(connect),
83 added_cert_(false) { 86 added_cert_(false) {
84 } 87 }
85 88
86 EnrollmentDialogView::~EnrollmentDialogView() { 89 EnrollmentDialogView::~EnrollmentDialogView() {
87 } 90 }
88 91
89 // static 92 // static
90 void EnrollmentDialogView::ShowDialog(gfx::NativeWindow owning_window, 93 void EnrollmentDialogView::ShowDialog(gfx::NativeWindow owning_window,
91 const std::string& network_name, 94 const std::string& network_name,
92 Profile* profile, 95 Profile* profile,
93 const GURL& target_uri, 96 const GURL& target_uri,
94 const base::Closure& connect) { 97 const base::Closure& connect) {
95 EnrollmentDialogView* dialog_view = 98 EnrollmentDialogView* dialog_view =
96 new EnrollmentDialogView(network_name, profile, target_uri, connect); 99 new EnrollmentDialogView(network_name, profile, target_uri, connect);
97 views::Widget::CreateWindowWithParent(dialog_view, owning_window); 100 views::Widget::CreateWindowWithParent(dialog_view, owning_window);
98 dialog_view->InitDialog(); 101 dialog_view->InitDialog();
99 views::Widget* widget = dialog_view->GetWidget(); 102 views::Widget* widget = dialog_view->GetWidget();
100 DCHECK(widget); 103 DCHECK(widget);
101 widget->Show(); 104 widget->Show();
102 } 105 }
103 106
104 int EnrollmentDialogView::GetDialogButtons() const { 107 int EnrollmentDialogView::GetDialogButtons() const {
105 return ui::DIALOG_BUTTON_CANCEL | ui::DIALOG_BUTTON_OK; 108 return ui::DIALOG_BUTTON_CANCEL | ui::DIALOG_BUTTON_OK;
106 } 109 }
107 110
108 bool EnrollmentDialogView::Accept() { 111 bool EnrollmentDialogView::Accept() {
109 // TODO(beng): use Navigate(). 112 accepted_ = true;
110 // Navigate to the target URI in a browser tab.
111 Browser* browser = chrome::FindTabbedBrowser(profile_, false,
112 chrome::HOST_DESKTOP_TYPE_ASH);
113 if (!browser) {
114 // Couldn't find a tabbed browser: create one.
115 browser = new Browser(
116 Browser::CreateParams(Browser::TYPE_TABBED,
117 profile_,
118 chrome::HOST_DESKTOP_TYPE_ASH));
119 }
120 DCHECK(browser);
121 chrome::AddSelectedTabWithURL(browser, target_uri_,
122 content::PAGE_TRANSITION_LINK);
123 return true; 113 return true;
124 } 114 }
125 115
116 void EnrollmentDialogView::OnClose() {
117 if (!accepted_)
118 return;
119 Browser* browser = chrome::FindOrCreateTabbedBrowser(
120 profile_,
121 chrome::HOST_DESKTOP_TYPE_ASH);
122 DCHECK(browser);
123 chrome::NavigateParams params(browser,
124 GURL(target_uri_),
125 content::PAGE_TRANSITION_LINK);
126 params.disposition = NEW_FOREGROUND_TAB;
127 chrome::Navigate(&params);
128 }
sky 2013/03/18 16:10:48 This should set params.window_action to SHOW_WINDO
129
126 string16 EnrollmentDialogView::GetDialogButtonLabel( 130 string16 EnrollmentDialogView::GetDialogButtonLabel(
127 ui::DialogButton button) const { 131 ui::DialogButton button) const {
128 if (button == ui::DIALOG_BUTTON_OK) 132 if (button == ui::DIALOG_BUTTON_OK)
129 return l10n_util::GetStringUTF16(IDS_NETWORK_ENROLLMENT_HANDLER_BUTTON); 133 return l10n_util::GetStringUTF16(IDS_NETWORK_ENROLLMENT_HANDLER_BUTTON);
130 return views::DialogDelegateView::GetDialogButtonLabel(button); 134 return views::DialogDelegateView::GetDialogButtonLabel(button);
131 } 135 }
132 136
133 ui::ModalType EnrollmentDialogView::GetModalType() const { 137 ui::ModalType EnrollmentDialogView::GetModalType() const {
134 return ui::MODAL_TYPE_SYSTEM; 138 return ui::MODAL_TYPE_SYSTEM;
135 } 139 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 //////////////////////////////////////////////////////////////////////////////// 250 ////////////////////////////////////////////////////////////////////////////////
247 // Factory function. 251 // Factory function.
248 252
249 EnrollmentDelegate* CreateEnrollmentDelegate(gfx::NativeWindow owning_window, 253 EnrollmentDelegate* CreateEnrollmentDelegate(gfx::NativeWindow owning_window,
250 const std::string& network_name, 254 const std::string& network_name,
251 Profile* profile) { 255 Profile* profile) {
252 return new DialogEnrollmentDelegate(owning_window, network_name, profile); 256 return new DialogEnrollmentDelegate(owning_window, network_name, profile);
253 } 257 }
254 258
255 } // namespace chromeos 259 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698