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 child_config_view_ = | 86 |
87 new WifiConfigView(this, static_cast<WifiNetwork*>(network)); | 87 void NetworkConfigView::InitWithNetworkState(const NetworkState* network) { |
88 } else if (network->type() == TYPE_WIMAX) { | 88 DCHECK(network); |
89 child_config_view_ = | 89 std::string service_path = network->path(); |
90 new WimaxConfigView(this, static_cast<WimaxNetwork*>(network)); | 90 if (network->type() == flimflam::kTypeWifi) |
91 } else if (network->type() == TYPE_VPN) { | 91 child_config_view_ = new WifiConfigView(this, service_path, false); |
92 child_config_view_ = | 92 else if (network->type() == flimflam::kTypeWimax) |
93 new VPNConfigView(this, static_cast<VirtualNetwork*>(network)); | 93 child_config_view_ = new WimaxConfigView(this, service_path); |
| 94 else if (network->type() == flimflam::kTypeVPN) |
| 95 child_config_view_ = new VPNConfigView(this, service_path); |
| 96 else |
| 97 NOTREACHED(); |
| 98 } |
| 99 |
| 100 void NetworkConfigView::InitWithType(const std::string& type) { |
| 101 if (type == flimflam::kTypeWifi) { |
| 102 child_config_view_ = new WifiConfigView(this, |
| 103 "" /* service_path */, |
| 104 false /* show_8021x */); |
| 105 advanced_button_ = new views::LabelButton(this, l10n_util::GetStringUTF16( |
| 106 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADVANCED_BUTTON)); |
| 107 advanced_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 108 } else if (type == flimflam::kTypeVPN) { |
| 109 child_config_view_ = new VPNConfigView(this, |
| 110 "" /* service_path */); |
94 } else { | 111 } else { |
95 NOTREACHED(); | 112 NOTREACHED(); |
96 } | 113 } |
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 } | 114 } |
116 | 115 |
117 NetworkConfigView::~NetworkConfigView() { | 116 NetworkConfigView::~NetworkConfigView() { |
118 DCHECK(GetActiveDialog() == this); | 117 DCHECK(GetActiveDialog() == this); |
119 SetActiveDialog(NULL); | 118 SetActiveDialog(NULL); |
120 } | 119 } |
121 | 120 |
122 // static | 121 // static |
123 void NetworkConfigView::Show(Network* network, gfx::NativeWindow parent) { | 122 void NetworkConfigView::Show(const std::string& service_path, |
| 123 gfx::NativeWindow parent) { |
124 if (GetActiveDialog() != NULL) | 124 if (GetActiveDialog() != NULL) |
125 return; | 125 return; |
126 NetworkConfigView* view = new NetworkConfigView(network); | 126 NetworkConfigView* view = new NetworkConfigView(); |
| 127 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> |
| 128 GetNetworkState(service_path); |
| 129 if (!network) { |
| 130 LOG(ERROR) << "NetworkConfigView::Show called with invalid service_path"; |
| 131 return; |
| 132 } |
| 133 view->InitWithNetworkState(network); |
127 view->ShowDialog(parent); | 134 view->ShowDialog(parent); |
128 } | 135 } |
129 | 136 |
130 // static | 137 // static |
131 void NetworkConfigView::ShowForType(ConnectionType type, | 138 void NetworkConfigView::ShowForType(const std::string& type, |
132 gfx::NativeWindow parent) { | 139 gfx::NativeWindow parent) { |
133 if (GetActiveDialog() != NULL) | 140 if (GetActiveDialog() != NULL) |
134 return; | 141 return; |
135 NetworkConfigView* view = new NetworkConfigView(type); | 142 NetworkConfigView* view = new NetworkConfigView(); |
| 143 view->InitWithType(type); |
136 view->ShowDialog(parent); | 144 view->ShowDialog(parent); |
137 } | 145 } |
138 | 146 |
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 { | 147 gfx::NativeWindow NetworkConfigView::GetNativeWindow() const { |
152 return GetWidget()->GetNativeWindow(); | 148 return GetWidget()->GetNativeWindow(); |
153 } | 149 } |
154 | 150 |
155 string16 NetworkConfigView::GetDialogButtonLabel( | 151 string16 NetworkConfigView::GetDialogButtonLabel( |
156 ui::DialogButton button) const { | 152 ui::DialogButton button) const { |
157 if (button == ui::DIALOG_BUTTON_OK) | 153 if (button == ui::DIALOG_BUTTON_OK) |
158 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_CONNECT); | 154 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_CONNECT); |
159 return views::DialogDelegateView::GetDialogButtonLabel(button); | 155 return views::DialogDelegateView::GetDialogButtonLabel(button); |
160 } | 156 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 advanced_button_->SetVisible(false); | 208 advanced_button_->SetVisible(false); |
213 ShowAdvancedView(); | 209 ShowAdvancedView(); |
214 } | 210 } |
215 } | 211 } |
216 | 212 |
217 void NetworkConfigView::ShowAdvancedView() { | 213 void NetworkConfigView::ShowAdvancedView() { |
218 // Clear out the old widgets and build new ones. | 214 // Clear out the old widgets and build new ones. |
219 RemoveChildView(child_config_view_); | 215 RemoveChildView(child_config_view_); |
220 delete child_config_view_; | 216 delete child_config_view_; |
221 // For now, there is only an advanced view for Wi-Fi 802.1X. | 217 // For now, there is only an advanced view for Wi-Fi 802.1X. |
222 child_config_view_ = new WifiConfigView(this, true /* show_8021x */); | 218 child_config_view_ = new WifiConfigView(this, |
| 219 "" /* service_path */, |
| 220 true /* show_8021x */); |
223 AddChildView(child_config_view_); | 221 AddChildView(child_config_view_); |
224 // Resize the window to be able to hold the new widgets. | 222 // Resize the window to be able to hold the new widgets. |
225 gfx::Size size = views::Widget::GetLocalizedContentsSize( | 223 gfx::Size size = views::Widget::GetLocalizedContentsSize( |
226 IDS_JOIN_WIFI_NETWORK_DIALOG_ADVANCED_WIDTH_CHARS, | 224 IDS_JOIN_WIFI_NETWORK_DIALOG_ADVANCED_WIDTH_CHARS, |
227 IDS_JOIN_WIFI_NETWORK_DIALOG_ADVANCED_MINIMUM_HEIGHT_LINES); | 225 IDS_JOIN_WIFI_NETWORK_DIALOG_ADVANCED_MINIMUM_HEIGHT_LINES); |
228 // Get the new bounds with desired size at the same center point. | 226 // Get the new bounds with desired size at the same center point. |
229 gfx::Rect bounds = GetWidget()->GetWindowBoundsInScreen(); | 227 gfx::Rect bounds = GetWidget()->GetWindowBoundsInScreen(); |
230 int horiz_padding = bounds.width() - size.width(); | 228 int horiz_padding = bounds.width() - size.width(); |
231 int vert_padding = bounds.height() - size.height(); | 229 int vert_padding = bounds.height() - size.height(); |
232 bounds.Inset(horiz_padding / 2, vert_padding / 2, | 230 bounds.Inset(horiz_padding / 2, vert_padding / 2, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 if (parent == NULL) | 262 if (parent == NULL) |
265 parent = GetDialogParent(); | 263 parent = GetDialogParent(); |
266 // Failed connections may result in a pop-up with no natural parent window, | 264 // Failed connections may result in a pop-up with no natural parent window, |
267 // so provide a fallback context on the active display. | 265 // so provide a fallback context on the active display. |
268 gfx::NativeWindow context = parent ? NULL : ash::Shell::GetActiveRootWindow(); | 266 gfx::NativeWindow context = parent ? NULL : ash::Shell::GetActiveRootWindow(); |
269 Widget* window = DialogDelegate::CreateDialogWidget(this, context, parent); | 267 Widget* window = DialogDelegate::CreateDialogWidget(this, context, parent); |
270 window->SetAlwaysOnTop(true); | 268 window->SetAlwaysOnTop(true); |
271 window->Show(); | 269 window->Show(); |
272 } | 270 } |
273 | 271 |
| 272 // ChildNetworkConfigView |
| 273 |
| 274 ChildNetworkConfigView::ChildNetworkConfigView( |
| 275 NetworkConfigView* parent, |
| 276 const std::string& service_path) |
| 277 : parent_(parent), |
| 278 service_path_(service_path) { |
| 279 } |
| 280 |
| 281 ChildNetworkConfigView::~ChildNetworkConfigView() { |
| 282 } |
| 283 |
| 284 // ControlledSettingIndicatorView |
| 285 |
274 ControlledSettingIndicatorView::ControlledSettingIndicatorView() | 286 ControlledSettingIndicatorView::ControlledSettingIndicatorView() |
275 : managed_(false), | 287 : managed_(false), |
276 image_view_(NULL) { | 288 image_view_(NULL) { |
277 Init(); | 289 Init(); |
278 } | 290 } |
279 | 291 |
280 ControlledSettingIndicatorView::ControlledSettingIndicatorView( | 292 ControlledSettingIndicatorView::ControlledSettingIndicatorView( |
281 const NetworkPropertyUIData& ui_data) | 293 const NetworkPropertyUIData& ui_data) |
282 : managed_(false), | 294 : managed_(false), |
283 image_view_(NULL) { | 295 image_view_(NULL) { |
(...skipping 10 matching lines...) Expand all Loading... |
294 | 306 |
295 managed_ = ui_data.IsManaged(); | 307 managed_ = ui_data.IsManaged(); |
296 PreferredSizeChanged(); | 308 PreferredSizeChanged(); |
297 } | 309 } |
298 | 310 |
299 gfx::Size ControlledSettingIndicatorView::GetPreferredSize() { | 311 gfx::Size ControlledSettingIndicatorView::GetPreferredSize() { |
300 return (managed_ && visible()) ? image_view_->GetPreferredSize() | 312 return (managed_ && visible()) ? image_view_->GetPreferredSize() |
301 : gfx::Size(); | 313 : gfx::Size(); |
302 } | 314 } |
303 | 315 |
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() { | 316 void ControlledSettingIndicatorView::Layout() { |
316 image_view_->SetBounds(0, 0, width(), height()); | 317 image_view_->SetBounds(0, 0, width(), height()); |
317 } | 318 } |
318 | 319 |
319 void ControlledSettingIndicatorView::OnMouseEntered( | 320 void ControlledSettingIndicatorView::OnMouseEntered( |
320 const ui::MouseEvent& event) { | 321 const ui::MouseEvent& event) { |
321 image_view_->SetImage(color_image_); | 322 image_view_->SetImage(color_image_); |
322 } | 323 } |
323 | 324 |
324 void ControlledSettingIndicatorView::OnMouseExited( | 325 void ControlledSettingIndicatorView::OnMouseExited( |
325 const ui::MouseEvent& event) { | 326 const ui::MouseEvent& event) { |
326 image_view_->SetImage(gray_image_); | 327 image_view_->SetImage(gray_image_); |
327 } | 328 } |
328 | 329 |
329 void ControlledSettingIndicatorView::Init() { | 330 void ControlledSettingIndicatorView::Init() { |
330 color_image_ = ResourceBundle::GetSharedInstance().GetImageNamed( | 331 color_image_ = ResourceBundle::GetSharedInstance().GetImageNamed( |
331 IDR_CONTROLLED_SETTING_MANDATORY).ToImageSkia(); | 332 IDR_CONTROLLED_SETTING_MANDATORY).ToImageSkia(); |
332 gray_image_ = ResourceBundle::GetSharedInstance().GetImageNamed( | 333 gray_image_ = ResourceBundle::GetSharedInstance().GetImageNamed( |
333 IDR_CONTROLLED_SETTING_MANDATORY_GRAY).ToImageSkia(); | 334 IDR_CONTROLLED_SETTING_MANDATORY_GRAY).ToImageSkia(); |
334 image_view_ = new views::ImageView(); | 335 image_view_ = new views::ImageView(); |
335 // Disable |image_view_| so mouse events propagate to the parent. | 336 // Disable |image_view_| so mouse events propagate to the parent. |
336 image_view_->SetEnabled(false); | 337 image_view_->SetEnabled(false); |
337 image_view_->SetImage(gray_image_); | 338 image_view_->SetImage(gray_image_); |
338 image_view_->SetTooltipText( | 339 image_view_->SetTooltipText( |
339 l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY)); | 340 l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY)); |
340 AddChildView(image_view_); | 341 AddChildView(image_view_); |
341 } | 342 } |
342 | 343 |
343 } // namespace chromeos | 344 } // namespace chromeos |
OLD | NEW |