OLD | NEW |
---|---|
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 Loading... | |
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 | |
87 void NetworkConfigView::InitWithPath(const std::string& service_path) { | |
88 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> | |
89 GetNetworkState(service_path); | |
90 DCHECK(network); | |
91 if (network->type() == flimflam::kTypeWifi) | |
92 child_config_view_ = new WifiConfigView(this, service_path, false); | |
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) { | |
86 child_config_view_ = | 103 child_config_view_ = |
87 new WifiConfigView(this, static_cast<WifiNetwork*>(network)); | 104 new WifiConfigView(this, "" /* service_path */, false /* show_8021x */); |
gauravsh
2013/08/03 01:15:54
NIT: This is more readable if the args on separate
stevenjb
2013/08/06 00:32:48
Done.
| |
88 } else if (network->type() == TYPE_WIMAX) { | 105 advanced_button_ = new views::LabelButton(this, l10n_util::GetStringUTF16( |
89 child_config_view_ = | 106 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADVANCED_BUTTON)); |
90 new WimaxConfigView(this, static_cast<WimaxNetwork*>(network)); | 107 advanced_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
91 } else if (network->type() == TYPE_VPN) { | 108 } else if (type == flimflam::kTypeVPN) { |
92 child_config_view_ = | 109 child_config_view_ = new VPNConfigView(this, "" /* service_path */); |
gauravsh
2013/08/03 01:15:54
NIT: args on separate lines.
stevenjb
2013/08/06 00:32:48
Done.
| |
93 new VPNConfigView(this, static_cast<VirtualNetwork*>(network)); | |
94 } else { | 110 } else { |
95 NOTREACHED(); | 111 NOTREACHED(); |
96 } | 112 } |
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 } | 113 } |
116 | 114 |
117 NetworkConfigView::~NetworkConfigView() { | 115 NetworkConfigView::~NetworkConfigView() { |
118 DCHECK(GetActiveDialog() == this); | 116 DCHECK(GetActiveDialog() == this); |
119 SetActiveDialog(NULL); | 117 SetActiveDialog(NULL); |
120 } | 118 } |
121 | 119 |
122 // static | 120 // static |
123 void NetworkConfigView::Show(Network* network, gfx::NativeWindow parent) { | 121 void NetworkConfigView::Show(const std::string& service_path, |
122 gfx::NativeWindow parent) { | |
124 if (GetActiveDialog() != NULL) | 123 if (GetActiveDialog() != NULL) |
125 return; | 124 return; |
126 NetworkConfigView* view = new NetworkConfigView(network); | 125 NetworkConfigView* view = new NetworkConfigView(); |
126 view->InitWithPath(service_path); | |
127 view->ShowDialog(parent); | 127 view->ShowDialog(parent); |
128 } | 128 } |
129 | 129 |
130 // static | 130 // static |
131 void NetworkConfigView::ShowForType(ConnectionType type, | 131 void NetworkConfigView::ShowForType(const std::string& type, |
132 gfx::NativeWindow parent) { | 132 gfx::NativeWindow parent) { |
133 if (GetActiveDialog() != NULL) | 133 if (GetActiveDialog() != NULL) |
134 return; | 134 return; |
135 NetworkConfigView* view = new NetworkConfigView(type); | 135 NetworkConfigView* view = new NetworkConfigView(); |
136 view->InitWithType(type); | |
136 view->ShowDialog(parent); | 137 view->ShowDialog(parent); |
137 } | 138 } |
138 | 139 |
139 gfx::NativeWindow NetworkConfigView::GetNativeWindow() const { | 140 gfx::NativeWindow NetworkConfigView::GetNativeWindow() const { |
140 return GetWidget()->GetNativeWindow(); | 141 return GetWidget()->GetNativeWindow(); |
141 } | 142 } |
142 | 143 |
143 string16 NetworkConfigView::GetDialogButtonLabel( | 144 string16 NetworkConfigView::GetDialogButtonLabel( |
144 ui::DialogButton button) const { | 145 ui::DialogButton button) const { |
145 if (button == ui::DIALOG_BUTTON_OK) | 146 if (button == ui::DIALOG_BUTTON_OK) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 advanced_button_->SetVisible(false); | 201 advanced_button_->SetVisible(false); |
201 ShowAdvancedView(); | 202 ShowAdvancedView(); |
202 } | 203 } |
203 } | 204 } |
204 | 205 |
205 void NetworkConfigView::ShowAdvancedView() { | 206 void NetworkConfigView::ShowAdvancedView() { |
206 // Clear out the old widgets and build new ones. | 207 // Clear out the old widgets and build new ones. |
207 RemoveChildView(child_config_view_); | 208 RemoveChildView(child_config_view_); |
208 delete child_config_view_; | 209 delete child_config_view_; |
209 // For now, there is only an advanced view for Wi-Fi 802.1X. | 210 // For now, there is only an advanced view for Wi-Fi 802.1X. |
210 child_config_view_ = new WifiConfigView(this, true /* show_8021x */); | 211 child_config_view_ = |
212 new WifiConfigView(this, "" /* service_path */, true /* show_8021x */); | |
gauravsh
2013/08/03 01:15:54
NIT: separate lines if you please
stevenjb
2013/08/06 00:32:48
Done.
| |
211 AddChildView(child_config_view_); | 213 AddChildView(child_config_view_); |
212 // Resize the window to be able to hold the new widgets. | 214 // Resize the window to be able to hold the new widgets. |
213 gfx::Size size = views::Widget::GetLocalizedContentsSize( | 215 gfx::Size size = views::Widget::GetLocalizedContentsSize( |
214 IDS_JOIN_WIFI_NETWORK_DIALOG_ADVANCED_WIDTH_CHARS, | 216 IDS_JOIN_WIFI_NETWORK_DIALOG_ADVANCED_WIDTH_CHARS, |
215 IDS_JOIN_WIFI_NETWORK_DIALOG_ADVANCED_MINIMUM_HEIGHT_LINES); | 217 IDS_JOIN_WIFI_NETWORK_DIALOG_ADVANCED_MINIMUM_HEIGHT_LINES); |
216 // Get the new bounds with desired size at the same center point. | 218 // Get the new bounds with desired size at the same center point. |
217 gfx::Rect bounds = GetWidget()->GetWindowBoundsInScreen(); | 219 gfx::Rect bounds = GetWidget()->GetWindowBoundsInScreen(); |
218 int horiz_padding = bounds.width() - size.width(); | 220 int horiz_padding = bounds.width() - size.width(); |
219 int vert_padding = bounds.height() - size.height(); | 221 int vert_padding = bounds.height() - size.height(); |
220 bounds.Inset(horiz_padding / 2, vert_padding / 2, | 222 bounds.Inset(horiz_padding / 2, vert_padding / 2, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 if (parent == NULL) | 254 if (parent == NULL) |
253 parent = GetDialogParent(); | 255 parent = GetDialogParent(); |
254 // Failed connections may result in a pop-up with no natural parent window, | 256 // Failed connections may result in a pop-up with no natural parent window, |
255 // so provide a fallback context on the active display. | 257 // so provide a fallback context on the active display. |
256 gfx::NativeWindow context = parent ? NULL : ash::Shell::GetActiveRootWindow(); | 258 gfx::NativeWindow context = parent ? NULL : ash::Shell::GetActiveRootWindow(); |
257 Widget* window = DialogDelegate::CreateDialogWidget(this, context, parent); | 259 Widget* window = DialogDelegate::CreateDialogWidget(this, context, parent); |
258 window->SetAlwaysOnTop(true); | 260 window->SetAlwaysOnTop(true); |
259 window->Show(); | 261 window->Show(); |
260 } | 262 } |
261 | 263 |
264 // ChildNetworkConfigView | |
265 | |
266 ChildNetworkConfigView::ChildNetworkConfigView( | |
267 NetworkConfigView* parent, | |
268 const std::string& service_path) | |
269 : parent_(parent), | |
270 service_path_(service_path) { | |
271 } | |
272 | |
273 ChildNetworkConfigView::~ChildNetworkConfigView() { | |
274 } | |
275 | |
276 // ControlledSettingIndicatorView | |
277 | |
262 ControlledSettingIndicatorView::ControlledSettingIndicatorView() | 278 ControlledSettingIndicatorView::ControlledSettingIndicatorView() |
263 : managed_(false), | 279 : managed_(false), |
264 image_view_(NULL) { | 280 image_view_(NULL) { |
265 Init(); | 281 Init(); |
266 } | 282 } |
267 | 283 |
268 ControlledSettingIndicatorView::ControlledSettingIndicatorView( | 284 ControlledSettingIndicatorView::ControlledSettingIndicatorView( |
269 const NetworkPropertyUIData& ui_data) | 285 const NetworkPropertyUIData& ui_data) |
270 : managed_(false), | 286 : managed_(false), |
271 image_view_(NULL) { | 287 image_view_(NULL) { |
(...skipping 10 matching lines...) Expand all Loading... | |
282 | 298 |
283 managed_ = ui_data.IsManaged(); | 299 managed_ = ui_data.IsManaged(); |
284 PreferredSizeChanged(); | 300 PreferredSizeChanged(); |
285 } | 301 } |
286 | 302 |
287 gfx::Size ControlledSettingIndicatorView::GetPreferredSize() { | 303 gfx::Size ControlledSettingIndicatorView::GetPreferredSize() { |
288 return (managed_ && visible()) ? image_view_->GetPreferredSize() | 304 return (managed_ && visible()) ? image_view_->GetPreferredSize() |
289 : gfx::Size(); | 305 : gfx::Size(); |
290 } | 306 } |
291 | 307 |
292 // static | |
293 const base::DictionaryValue* NetworkConfigView::FindPolicyForActiveUser( | |
294 const Network* network, | |
295 onc::ONCSource* onc_source) { | |
296 const User* user = UserManager::Get()->GetActiveUser(); | |
297 std::string username_hash = user ? user->username_hash() : std::string(); | |
298 std::string guid = network->unique_id(); | |
299 return NetworkHandler::Get()->managed_network_configuration_handler() | |
300 ->FindPolicyByGUID(username_hash, guid, onc_source); | |
301 } | |
302 | |
303 void ControlledSettingIndicatorView::Layout() { | 308 void ControlledSettingIndicatorView::Layout() { |
304 image_view_->SetBounds(0, 0, width(), height()); | 309 image_view_->SetBounds(0, 0, width(), height()); |
305 } | 310 } |
306 | 311 |
307 void ControlledSettingIndicatorView::OnMouseEntered( | 312 void ControlledSettingIndicatorView::OnMouseEntered( |
308 const ui::MouseEvent& event) { | 313 const ui::MouseEvent& event) { |
309 image_view_->SetImage(color_image_); | 314 image_view_->SetImage(color_image_); |
310 } | 315 } |
311 | 316 |
312 void ControlledSettingIndicatorView::OnMouseExited( | 317 void ControlledSettingIndicatorView::OnMouseExited( |
313 const ui::MouseEvent& event) { | 318 const ui::MouseEvent& event) { |
314 image_view_->SetImage(gray_image_); | 319 image_view_->SetImage(gray_image_); |
315 } | 320 } |
316 | 321 |
317 void ControlledSettingIndicatorView::Init() { | 322 void ControlledSettingIndicatorView::Init() { |
318 color_image_ = ResourceBundle::GetSharedInstance().GetImageNamed( | 323 color_image_ = ResourceBundle::GetSharedInstance().GetImageNamed( |
319 IDR_CONTROLLED_SETTING_MANDATORY).ToImageSkia(); | 324 IDR_CONTROLLED_SETTING_MANDATORY).ToImageSkia(); |
320 gray_image_ = ResourceBundle::GetSharedInstance().GetImageNamed( | 325 gray_image_ = ResourceBundle::GetSharedInstance().GetImageNamed( |
321 IDR_CONTROLLED_SETTING_MANDATORY_GRAY).ToImageSkia(); | 326 IDR_CONTROLLED_SETTING_MANDATORY_GRAY).ToImageSkia(); |
322 image_view_ = new views::ImageView(); | 327 image_view_ = new views::ImageView(); |
323 // Disable |image_view_| so mouse events propagate to the parent. | 328 // Disable |image_view_| so mouse events propagate to the parent. |
324 image_view_->SetEnabled(false); | 329 image_view_->SetEnabled(false); |
325 image_view_->SetImage(gray_image_); | 330 image_view_->SetImage(gray_image_); |
326 image_view_->SetTooltipText( | 331 image_view_->SetTooltipText( |
327 l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY)); | 332 l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY)); |
328 AddChildView(image_view_); | 333 AddChildView(image_view_); |
329 } | 334 } |
330 | 335 |
331 } // namespace chromeos | 336 } // namespace chromeos |
OLD | NEW |