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

Side by Side Diff: chrome/browser/chromeos/options/network_config_view.cc

Issue 21046008: Convert all connect code to use NetworkHandler instead of NetworkLibrary (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Feedback Round 1 Created 7 years, 4 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
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/options/network_config_view.h" 5 #include "chrome/browser/chromeos/options/network_config_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/chromeos/cros/network_property_ui_data.h" 12 #include "chrome/browser/chromeos/cros/network_property_ui_data.h"
13 #include "chrome/browser/chromeos/login/login_display_host_impl.h" 13 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
14 #include "chrome/browser/chromeos/login/user.h" 14 #include "chrome/browser/chromeos/login/user.h"
15 #include "chrome/browser/chromeos/login/user_manager.h"
16 #include "chrome/browser/chromeos/options/vpn_config_view.h" 15 #include "chrome/browser/chromeos/options/vpn_config_view.h"
17 #include "chrome/browser/chromeos/options/wifi_config_view.h" 16 #include "chrome/browser/chromeos/options/wifi_config_view.h"
18 #include "chrome/browser/chromeos/options/wimax_config_view.h" 17 #include "chrome/browser/chromeos/options/wimax_config_view.h"
19 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_finder.h" 20 #include "chrome/browser/ui/browser_finder.h"
22 #include "chrome/browser/ui/browser_window.h" 21 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/browser/ui/host_desktop.h" 22 #include "chrome/browser/ui/host_desktop.h"
24 #include "chromeos/network/managed_network_configuration_handler.h" 23 #include "chromeos/network/network_state.h"
24 #include "chromeos/network/network_state_handler.h"
25 #include "grit/chromium_strings.h" 25 #include "grit/chromium_strings.h"
26 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
27 #include "grit/locale_settings.h" 27 #include "grit/locale_settings.h"
28 #include "grit/theme_resources.h" 28 #include "grit/theme_resources.h"
29 #include "ui/aura/root_window.h" 29 #include "ui/aura/root_window.h"
30 #include "ui/base/accessibility/accessible_view_state.h" 30 #include "ui/base/accessibility/accessible_view_state.h"
31 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/base/resource/resource_bundle.h" 32 #include "ui/base/resource/resource_bundle.h"
33 #include "ui/gfx/image/image.h" 33 #include "ui/gfx/image/image.h"
34 #include "ui/gfx/rect.h" 34 #include "ui/gfx/rect.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 *(GetActiveDialogPointer()) = dialog; 69 *(GetActiveDialogPointer()) = dialog;
70 } 70 }
71 71
72 } // namespace 72 } // namespace
73 73
74 namespace chromeos { 74 namespace chromeos {
75 75
76 // static 76 // static
77 const int ChildNetworkConfigView::kInputFieldMinWidth = 270; 77 const int ChildNetworkConfigView::kInputFieldMinWidth = 270;
78 78
79 NetworkConfigView::NetworkConfigView(Network* network) 79 NetworkConfigView::NetworkConfigView()
80 : child_config_view_(NULL), 80 : child_config_view_(NULL),
81 delegate_(NULL), 81 delegate_(NULL),
82 advanced_button_(NULL) { 82 advanced_button_(NULL) {
83 DCHECK(GetActiveDialog() == NULL); 83 DCHECK(GetActiveDialog() == NULL);
84 SetActiveDialog(this); 84 SetActiveDialog(this);
85 if (network->type() == TYPE_WIFI) { 85 }
86 child_config_view_ = 86
87 new WifiConfigView(this, static_cast<WifiNetwork*>(network)); 87 void NetworkConfigView::InitWithPath(const std::string& service_path) {
88 } else if (network->type() == TYPE_WIMAX) { 88 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
89 child_config_view_ = 89 GetNetworkState(service_path);
90 new WimaxConfigView(this, static_cast<WimaxNetwork*>(network)); 90 DCHECK(network);
pneubeck (no reviews) 2013/08/06 15:45:19 if you DCHECK anyways, why not pass a NetworkState
stevenjb 2013/08/06 20:23:55 Done.
91 } else if (network->type() == TYPE_VPN) { 91 if (network->type() == flimflam::kTypeWifi)
92 child_config_view_ = 92 child_config_view_ = new WifiConfigView(this, service_path, false);
93 new VPNConfigView(this, static_cast<VirtualNetwork*>(network)); 93 else if (network->type() == flimflam::kTypeWimax)
94 child_config_view_ = new WimaxConfigView(this, service_path);
95 else if (network->type() == flimflam::kTypeVPN)
96 child_config_view_ = new VPNConfigView(this, service_path);
97 else
98 NOTREACHED();
99 }
100
101 void NetworkConfigView::InitWithType(const std::string& type) {
102 if (type == flimflam::kTypeWifi) {
103 child_config_view_ = new WifiConfigView(this,
104 "" /* service_path */,
105 false /* show_8021x */);
106 advanced_button_ = new views::LabelButton(this, l10n_util::GetStringUTF16(
107 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADVANCED_BUTTON));
108 advanced_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
109 } else if (type == flimflam::kTypeVPN) {
110 child_config_view_ = new VPNConfigView(this,
111 "" /* service_path */);
94 } else { 112 } else {
95 NOTREACHED(); 113 NOTREACHED();
96 } 114 }
97 }
98
99 NetworkConfigView::NetworkConfigView(ConnectionType type)
100 : child_config_view_(NULL),
101 delegate_(NULL),
102 advanced_button_(NULL) {
103 DCHECK(GetActiveDialog() == NULL);
104 SetActiveDialog(this);
105 if (type == TYPE_WIFI) {
106 child_config_view_ = new WifiConfigView(this, false /* show_8021x */);
107 advanced_button_ = new views::LabelButton(this, l10n_util::GetStringUTF16(
108 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADVANCED_BUTTON));
109 advanced_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
110 } else if (type == TYPE_VPN) {
111 child_config_view_ = new VPNConfigView(this);
112 } else {
113 NOTREACHED();
114 }
115 } 115 }
116 116
117 NetworkConfigView::~NetworkConfigView() { 117 NetworkConfigView::~NetworkConfigView() {
118 DCHECK(GetActiveDialog() == this); 118 DCHECK(GetActiveDialog() == this);
119 SetActiveDialog(NULL); 119 SetActiveDialog(NULL);
120 } 120 }
121 121
122 // static 122 // static
123 void NetworkConfigView::Show(Network* network, gfx::NativeWindow parent) { 123 void NetworkConfigView::Show(const std::string& service_path,
124 gfx::NativeWindow parent) {
124 if (GetActiveDialog() != NULL) 125 if (GetActiveDialog() != NULL)
125 return; 126 return;
126 NetworkConfigView* view = new NetworkConfigView(network); 127 NetworkConfigView* view = new NetworkConfigView();
128 view->InitWithPath(service_path);
127 view->ShowDialog(parent); 129 view->ShowDialog(parent);
128 } 130 }
129 131
130 // static 132 // static
131 void NetworkConfigView::ShowForType(ConnectionType type, 133 void NetworkConfigView::ShowForType(const std::string& type,
132 gfx::NativeWindow parent) { 134 gfx::NativeWindow parent) {
133 if (GetActiveDialog() != NULL) 135 if (GetActiveDialog() != NULL)
134 return; 136 return;
135 NetworkConfigView* view = new NetworkConfigView(type); 137 NetworkConfigView* view = new NetworkConfigView();
138 view->InitWithType(type);
136 view->ShowDialog(parent); 139 view->ShowDialog(parent);
137 } 140 }
138 141
139 // static
140 void NetworkConfigView::ShowForPath(const std::string& path,
141 gfx::NativeWindow parent) {
142 if (GetActiveDialog() != NULL)
143 return;
144 Network* network = NetworkLibrary::Get()->FindNetworkByPath(path);
145 if (!network)
146 return;
147 NetworkConfigView* view = new NetworkConfigView(network);
148 view->ShowDialog(parent);
149 }
150
151 gfx::NativeWindow NetworkConfigView::GetNativeWindow() const { 142 gfx::NativeWindow NetworkConfigView::GetNativeWindow() const {
152 return GetWidget()->GetNativeWindow(); 143 return GetWidget()->GetNativeWindow();
153 } 144 }
154 145
155 string16 NetworkConfigView::GetDialogButtonLabel( 146 string16 NetworkConfigView::GetDialogButtonLabel(
156 ui::DialogButton button) const { 147 ui::DialogButton button) const {
157 if (button == ui::DIALOG_BUTTON_OK) 148 if (button == ui::DIALOG_BUTTON_OK)
158 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_CONNECT); 149 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_CONNECT);
159 return views::DialogDelegateView::GetDialogButtonLabel(button); 150 return views::DialogDelegateView::GetDialogButtonLabel(button);
160 } 151 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 advanced_button_->SetVisible(false); 203 advanced_button_->SetVisible(false);
213 ShowAdvancedView(); 204 ShowAdvancedView();
214 } 205 }
215 } 206 }
216 207
217 void NetworkConfigView::ShowAdvancedView() { 208 void NetworkConfigView::ShowAdvancedView() {
218 // Clear out the old widgets and build new ones. 209 // Clear out the old widgets and build new ones.
219 RemoveChildView(child_config_view_); 210 RemoveChildView(child_config_view_);
220 delete child_config_view_; 211 delete child_config_view_;
221 // For now, there is only an advanced view for Wi-Fi 802.1X. 212 // For now, there is only an advanced view for Wi-Fi 802.1X.
222 child_config_view_ = new WifiConfigView(this, true /* show_8021x */); 213 child_config_view_ = new WifiConfigView(this,
214 "" /* service_path */,
215 true /* show_8021x */);
223 AddChildView(child_config_view_); 216 AddChildView(child_config_view_);
224 // Resize the window to be able to hold the new widgets. 217 // Resize the window to be able to hold the new widgets.
225 gfx::Size size = views::Widget::GetLocalizedContentsSize( 218 gfx::Size size = views::Widget::GetLocalizedContentsSize(
226 IDS_JOIN_WIFI_NETWORK_DIALOG_ADVANCED_WIDTH_CHARS, 219 IDS_JOIN_WIFI_NETWORK_DIALOG_ADVANCED_WIDTH_CHARS,
227 IDS_JOIN_WIFI_NETWORK_DIALOG_ADVANCED_MINIMUM_HEIGHT_LINES); 220 IDS_JOIN_WIFI_NETWORK_DIALOG_ADVANCED_MINIMUM_HEIGHT_LINES);
228 // Get the new bounds with desired size at the same center point. 221 // Get the new bounds with desired size at the same center point.
229 gfx::Rect bounds = GetWidget()->GetWindowBoundsInScreen(); 222 gfx::Rect bounds = GetWidget()->GetWindowBoundsInScreen();
230 int horiz_padding = bounds.width() - size.width(); 223 int horiz_padding = bounds.width() - size.width();
231 int vert_padding = bounds.height() - size.height(); 224 int vert_padding = bounds.height() - size.height();
232 bounds.Inset(horiz_padding / 2, vert_padding / 2, 225 bounds.Inset(horiz_padding / 2, vert_padding / 2,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 if (parent == NULL) 257 if (parent == NULL)
265 parent = GetDialogParent(); 258 parent = GetDialogParent();
266 // Failed connections may result in a pop-up with no natural parent window, 259 // Failed connections may result in a pop-up with no natural parent window,
267 // so provide a fallback context on the active display. 260 // so provide a fallback context on the active display.
268 gfx::NativeWindow context = parent ? NULL : ash::Shell::GetActiveRootWindow(); 261 gfx::NativeWindow context = parent ? NULL : ash::Shell::GetActiveRootWindow();
269 Widget* window = DialogDelegate::CreateDialogWidget(this, context, parent); 262 Widget* window = DialogDelegate::CreateDialogWidget(this, context, parent);
270 window->SetAlwaysOnTop(true); 263 window->SetAlwaysOnTop(true);
271 window->Show(); 264 window->Show();
272 } 265 }
273 266
267 // ChildNetworkConfigView
268
269 ChildNetworkConfigView::ChildNetworkConfigView(
270 NetworkConfigView* parent,
271 const std::string& service_path)
272 : parent_(parent),
273 service_path_(service_path) {
274 }
275
276 ChildNetworkConfigView::~ChildNetworkConfigView() {
277 }
278
279 // ControlledSettingIndicatorView
280
274 ControlledSettingIndicatorView::ControlledSettingIndicatorView() 281 ControlledSettingIndicatorView::ControlledSettingIndicatorView()
275 : managed_(false), 282 : managed_(false),
276 image_view_(NULL) { 283 image_view_(NULL) {
277 Init(); 284 Init();
278 } 285 }
279 286
280 ControlledSettingIndicatorView::ControlledSettingIndicatorView( 287 ControlledSettingIndicatorView::ControlledSettingIndicatorView(
281 const NetworkPropertyUIData& ui_data) 288 const NetworkPropertyUIData& ui_data)
282 : managed_(false), 289 : managed_(false),
283 image_view_(NULL) { 290 image_view_(NULL) {
(...skipping 10 matching lines...) Expand all
294 301
295 managed_ = ui_data.IsManaged(); 302 managed_ = ui_data.IsManaged();
296 PreferredSizeChanged(); 303 PreferredSizeChanged();
297 } 304 }
298 305
299 gfx::Size ControlledSettingIndicatorView::GetPreferredSize() { 306 gfx::Size ControlledSettingIndicatorView::GetPreferredSize() {
300 return (managed_ && visible()) ? image_view_->GetPreferredSize() 307 return (managed_ && visible()) ? image_view_->GetPreferredSize()
301 : gfx::Size(); 308 : gfx::Size();
302 } 309 }
303 310
304 // static
305 const base::DictionaryValue* NetworkConfigView::FindPolicyForActiveUser(
306 const Network* network,
307 onc::ONCSource* onc_source) {
308 const User* user = UserManager::Get()->GetActiveUser();
309 std::string username_hash = user ? user->username_hash() : std::string();
310 std::string guid = network->unique_id();
311 return NetworkHandler::Get()->managed_network_configuration_handler()
312 ->FindPolicyByGUID(username_hash, guid, onc_source);
313 }
314
315 void ControlledSettingIndicatorView::Layout() { 311 void ControlledSettingIndicatorView::Layout() {
316 image_view_->SetBounds(0, 0, width(), height()); 312 image_view_->SetBounds(0, 0, width(), height());
317 } 313 }
318 314
319 void ControlledSettingIndicatorView::OnMouseEntered( 315 void ControlledSettingIndicatorView::OnMouseEntered(
320 const ui::MouseEvent& event) { 316 const ui::MouseEvent& event) {
321 image_view_->SetImage(color_image_); 317 image_view_->SetImage(color_image_);
322 } 318 }
323 319
324 void ControlledSettingIndicatorView::OnMouseExited( 320 void ControlledSettingIndicatorView::OnMouseExited(
325 const ui::MouseEvent& event) { 321 const ui::MouseEvent& event) {
326 image_view_->SetImage(gray_image_); 322 image_view_->SetImage(gray_image_);
327 } 323 }
328 324
329 void ControlledSettingIndicatorView::Init() { 325 void ControlledSettingIndicatorView::Init() {
330 color_image_ = ResourceBundle::GetSharedInstance().GetImageNamed( 326 color_image_ = ResourceBundle::GetSharedInstance().GetImageNamed(
331 IDR_CONTROLLED_SETTING_MANDATORY).ToImageSkia(); 327 IDR_CONTROLLED_SETTING_MANDATORY).ToImageSkia();
332 gray_image_ = ResourceBundle::GetSharedInstance().GetImageNamed( 328 gray_image_ = ResourceBundle::GetSharedInstance().GetImageNamed(
333 IDR_CONTROLLED_SETTING_MANDATORY_GRAY).ToImageSkia(); 329 IDR_CONTROLLED_SETTING_MANDATORY_GRAY).ToImageSkia();
334 image_view_ = new views::ImageView(); 330 image_view_ = new views::ImageView();
335 // Disable |image_view_| so mouse events propagate to the parent. 331 // Disable |image_view_| so mouse events propagate to the parent.
336 image_view_->SetEnabled(false); 332 image_view_->SetEnabled(false);
337 image_view_->SetImage(gray_image_); 333 image_view_->SetImage(gray_image_);
338 image_view_->SetTooltipText( 334 image_view_->SetTooltipText(
339 l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY)); 335 l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY));
340 AddChildView(image_view_); 336 AddChildView(image_view_);
341 } 337 }
342 338
343 } // namespace chromeos 339 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698