| 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/login/ui/login_display_host_impl.h" | 12 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 13 #include "chrome/browser/chromeos/options/network_property_ui_data.h" | 13 #include "chrome/browser/chromeos/options/network_property_ui_data.h" |
| 14 #include "chrome/browser/chromeos/options/vpn_config_view.h" | 14 #include "chrome/browser/chromeos/options/vpn_config_view.h" |
| 15 #include "chrome/browser/chromeos/options/wifi_config_view.h" | 15 #include "chrome/browser/chromeos/options/wifi_config_view.h" |
| 16 #include "chrome/browser/chromeos/options/wimax_config_view.h" | 16 #include "chrome/browser/chromeos/options/wimax_config_view.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
| 20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
| 21 #include "chrome/browser/ui/host_desktop.h" | 21 #include "chrome/browser/ui/host_desktop.h" |
| 22 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 33 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
| 34 #include "ui/gfx/geometry/rect.h" | 34 #include "ui/gfx/geometry/rect.h" |
| 35 #include "ui/gfx/image/image.h" | 35 #include "ui/gfx/image/image.h" |
| 36 #include "ui/views/controls/button/label_button.h" | 36 #include "ui/views/controls/button/label_button.h" |
| 37 #include "ui/views/controls/image_view.h" | 37 #include "ui/views/controls/image_view.h" |
| 38 #include "ui/views/layout/layout_constants.h" | 38 #include "ui/views/layout/layout_constants.h" |
| 39 #include "ui/views/widget/widget.h" | 39 #include "ui/views/widget/widget.h" |
| 40 | 40 |
| 41 using views::Widget; | 41 using views::Widget; |
| 42 | 42 |
| 43 namespace chromeos { |
| 44 |
| 43 namespace { | 45 namespace { |
| 44 | 46 |
| 45 gfx::NativeWindow GetParentForUnhostedDialog() { | 47 gfx::NativeWindow GetParentForUnhostedDialog() { |
| 46 if (chromeos::LoginDisplayHostImpl::default_host()) { | 48 if (LoginDisplayHost::default_host()) { |
| 47 return chromeos::LoginDisplayHostImpl::default_host()->GetNativeWindow(); | 49 return LoginDisplayHost::default_host()->GetNativeWindow(); |
| 48 } else { | 50 } else { |
| 49 Browser* browser = chrome::FindTabbedBrowser( | 51 Browser* browser = chrome::FindTabbedBrowser( |
| 50 ProfileManager::GetPrimaryUserProfile(), | 52 ProfileManager::GetPrimaryUserProfile(), |
| 51 true, | 53 true, |
| 52 chrome::HOST_DESKTOP_TYPE_ASH); | 54 chrome::HOST_DESKTOP_TYPE_ASH); |
| 53 if (browser) | 55 if (browser) |
| 54 return browser->window()->GetNativeWindow(); | 56 return browser->window()->GetNativeWindow(); |
| 55 } | 57 } |
| 56 return NULL; | 58 return nullptr; |
| 57 } | 59 } |
| 58 | 60 |
| 59 // Avoid global static initializer. | 61 // Avoid global static initializer. |
| 60 chromeos::NetworkConfigView** GetActiveDialogPointer() { | 62 NetworkConfigView** GetActiveDialogPointer() { |
| 61 static chromeos::NetworkConfigView* active_dialog = NULL; | 63 static NetworkConfigView* active_dialog = nullptr; |
| 62 return &active_dialog; | 64 return &active_dialog; |
| 63 } | 65 } |
| 64 | 66 |
| 65 chromeos::NetworkConfigView* GetActiveDialog() { | 67 NetworkConfigView* GetActiveDialog() { |
| 66 return *(GetActiveDialogPointer()); | 68 return *(GetActiveDialogPointer()); |
| 67 } | 69 } |
| 68 | 70 |
| 69 void SetActiveDialog(chromeos::NetworkConfigView* dialog) { | 71 void SetActiveDialog(NetworkConfigView* dialog) { |
| 70 *(GetActiveDialogPointer()) = dialog; | 72 *(GetActiveDialogPointer()) = dialog; |
| 71 } | 73 } |
| 72 | 74 |
| 73 } // namespace | 75 } // namespace |
| 74 | 76 |
| 75 namespace chromeos { | |
| 76 | |
| 77 // static | 77 // static |
| 78 const int ChildNetworkConfigView::kInputFieldMinWidth = 270; | 78 const int ChildNetworkConfigView::kInputFieldMinWidth = 270; |
| 79 | 79 |
| 80 NetworkConfigView::NetworkConfigView() | 80 NetworkConfigView::NetworkConfigView() |
| 81 : child_config_view_(NULL), | 81 : child_config_view_(nullptr), |
| 82 delegate_(NULL), | 82 delegate_(nullptr), |
| 83 advanced_button_(NULL) { | 83 advanced_button_(nullptr) { |
| 84 DCHECK(GetActiveDialog() == NULL); | 84 DCHECK(GetActiveDialog() == nullptr); |
| 85 SetActiveDialog(this); | 85 SetActiveDialog(this); |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool NetworkConfigView::InitWithNetworkState(const NetworkState* network) { | 88 bool NetworkConfigView::InitWithNetworkState(const NetworkState* network) { |
| 89 DCHECK(network); | 89 DCHECK(network); |
| 90 std::string service_path = network->path(); | 90 std::string service_path = network->path(); |
| 91 if (network->type() == shill::kTypeWifi || | 91 if (network->type() == shill::kTypeWifi || |
| 92 network->type() == shill::kTypeEthernet) { | 92 network->type() == shill::kTypeEthernet) { |
| 93 child_config_view_ = new WifiConfigView(this, service_path, false); | 93 child_config_view_ = new WifiConfigView(this, service_path, false); |
| 94 } else if (network->type() == shill::kTypeWimax) { | 94 } else if (network->type() == shill::kTypeWimax) { |
| 95 child_config_view_ = new WimaxConfigView(this, service_path); | 95 child_config_view_ = new WimaxConfigView(this, service_path); |
| 96 } else if (network->type() == shill::kTypeVPN) { | 96 } else if (network->type() == shill::kTypeVPN) { |
| 97 child_config_view_ = new VPNConfigView(this, service_path); | 97 child_config_view_ = new VPNConfigView(this, service_path); |
| 98 } | 98 } |
| 99 return child_config_view_ != NULL; | 99 return child_config_view_ != nullptr; |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool NetworkConfigView::InitWithType(const std::string& type) { | 102 bool NetworkConfigView::InitWithType(const std::string& type) { |
| 103 if (type == shill::kTypeWifi) { | 103 if (type == shill::kTypeWifi) { |
| 104 child_config_view_ = new WifiConfigView(this, | 104 child_config_view_ = new WifiConfigView(this, |
| 105 "" /* service_path */, | 105 "" /* service_path */, |
| 106 false /* show_8021x */); | 106 false /* show_8021x */); |
| 107 advanced_button_ = new views::LabelButton(this, l10n_util::GetStringUTF16( | 107 advanced_button_ = new views::LabelButton(this, l10n_util::GetStringUTF16( |
| 108 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADVANCED_BUTTON)); | 108 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADVANCED_BUTTON)); |
| 109 advanced_button_->SetStyle(views::Button::STYLE_BUTTON); | 109 advanced_button_->SetStyle(views::Button::STYLE_BUTTON); |
| 110 } else if (type == shill::kTypeVPN) { | 110 } else if (type == shill::kTypeVPN) { |
| 111 child_config_view_ = new VPNConfigView(this, | 111 child_config_view_ = new VPNConfigView(this, |
| 112 "" /* service_path */); | 112 "" /* service_path */); |
| 113 } | 113 } |
| 114 return child_config_view_ != NULL; | 114 return child_config_view_ != nullptr; |
| 115 } | 115 } |
| 116 | 116 |
| 117 NetworkConfigView::~NetworkConfigView() { | 117 NetworkConfigView::~NetworkConfigView() { |
| 118 DCHECK(GetActiveDialog() == this); | 118 DCHECK(GetActiveDialog() == this); |
| 119 SetActiveDialog(NULL); | 119 SetActiveDialog(nullptr); |
| 120 } | 120 } |
| 121 | 121 |
| 122 // static | 122 // static |
| 123 void NetworkConfigView::Show(const std::string& service_path, | 123 void NetworkConfigView::Show(const std::string& service_path, |
| 124 gfx::NativeWindow parent) { | 124 gfx::NativeWindow parent) { |
| 125 if (GetActiveDialog() != NULL) | 125 if (GetActiveDialog() != nullptr) |
| 126 return; | 126 return; |
| 127 NetworkConfigView* view = new NetworkConfigView(); | 127 NetworkConfigView* view = new NetworkConfigView(); |
| 128 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> | 128 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> |
| 129 GetNetworkState(service_path); | 129 GetNetworkState(service_path); |
| 130 if (!network) { | 130 if (!network) { |
| 131 LOG(ERROR) << "NetworkConfigView::Show called with invalid service_path"; | 131 LOG(ERROR) << "NetworkConfigView::Show called with invalid service_path"; |
| 132 return; | 132 return; |
| 133 } | 133 } |
| 134 if (!view->InitWithNetworkState(network)) { | 134 if (!view->InitWithNetworkState(network)) { |
| 135 LOG(ERROR) << "NetworkConfigView::Show called with invalid network type: " | 135 LOG(ERROR) << "NetworkConfigView::Show called with invalid network type: " |
| 136 << network->type(); | 136 << network->type(); |
| 137 delete view; | 137 delete view; |
| 138 return; | 138 return; |
| 139 } | 139 } |
| 140 NET_LOG(USER) << "NetworkConfigView::Show: " << service_path; | 140 NET_LOG(USER) << "NetworkConfigView::Show: " << service_path; |
| 141 view->ShowDialog(parent); | 141 view->ShowDialog(parent); |
| 142 } | 142 } |
| 143 | 143 |
| 144 // static | 144 // static |
| 145 void NetworkConfigView::ShowForType(const std::string& type, | 145 void NetworkConfigView::ShowForType(const std::string& type, |
| 146 gfx::NativeWindow parent) { | 146 gfx::NativeWindow parent) { |
| 147 if (GetActiveDialog() != NULL) | 147 if (GetActiveDialog() != nullptr) |
| 148 return; | 148 return; |
| 149 NetworkConfigView* view = new NetworkConfigView(); | 149 NetworkConfigView* view = new NetworkConfigView(); |
| 150 if (!view->InitWithType(type)) { | 150 if (!view->InitWithType(type)) { |
| 151 LOG(ERROR) << "NetworkConfigView::ShowForType called with invalid type: " | 151 LOG(ERROR) << "NetworkConfigView::ShowForType called with invalid type: " |
| 152 << type; | 152 << type; |
| 153 delete view; | 153 delete view; |
| 154 return; | 154 return; |
| 155 } | 155 } |
| 156 NET_LOG(USER) << "NetworkConfigView::ShowForType: " << type; | 156 NET_LOG(USER) << "NetworkConfigView::ShowForType: " << type; |
| 157 view->ShowDialog(parent); | 157 view->ShowDialog(parent); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 const ViewHierarchyChangedDetails& details) { | 269 const ViewHierarchyChangedDetails& details) { |
| 270 // Can't init before we're inserted into a Container, because we require | 270 // Can't init before we're inserted into a Container, because we require |
| 271 // a HWND to parent native child controls to. | 271 // a HWND to parent native child controls to. |
| 272 views::DialogDelegateView::ViewHierarchyChanged(details); | 272 views::DialogDelegateView::ViewHierarchyChanged(details); |
| 273 if (details.is_add && details.child == this) { | 273 if (details.is_add && details.child == this) { |
| 274 AddChildView(child_config_view_); | 274 AddChildView(child_config_view_); |
| 275 } | 275 } |
| 276 } | 276 } |
| 277 | 277 |
| 278 void NetworkConfigView::ShowDialog(gfx::NativeWindow parent) { | 278 void NetworkConfigView::ShowDialog(gfx::NativeWindow parent) { |
| 279 if (parent == NULL) | 279 if (parent == nullptr) |
| 280 parent = GetParentForUnhostedDialog(); | 280 parent = GetParentForUnhostedDialog(); |
| 281 // Failed connections may result in a pop-up with no natural parent window, | 281 // Failed connections may result in a pop-up with no natural parent window, |
| 282 // so provide a fallback context on the primary display. This is necessary | 282 // so provide a fallback context on the primary display. This is necessary |
| 283 // becase one of parent or context must be non NULL. | 283 // becase one of parent or context must be non nullptr. |
| 284 gfx::NativeWindow context = | 284 gfx::NativeWindow context = |
| 285 parent ? NULL : ash::Shell::GetPrimaryRootWindow(); | 285 parent ? nullptr : ash::Shell::GetPrimaryRootWindow(); |
| 286 Widget* window = DialogDelegate::CreateDialogWidget(this, context, parent); | 286 Widget* window = DialogDelegate::CreateDialogWidget(this, context, parent); |
| 287 window->SetAlwaysOnTop(true); | 287 window->SetAlwaysOnTop(true); |
| 288 window->Show(); | 288 window->Show(); |
| 289 } | 289 } |
| 290 | 290 |
| 291 // ChildNetworkConfigView | 291 // ChildNetworkConfigView |
| 292 | 292 |
| 293 ChildNetworkConfigView::ChildNetworkConfigView( | 293 ChildNetworkConfigView::ChildNetworkConfigView( |
| 294 NetworkConfigView* parent, | 294 NetworkConfigView* parent, |
| 295 const std::string& service_path) | 295 const std::string& service_path) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 308 void ChildNetworkConfigView::GetShareStateForLoginState(bool* default_value, | 308 void ChildNetworkConfigView::GetShareStateForLoginState(bool* default_value, |
| 309 bool* modifiable) { | 309 bool* modifiable) { |
| 310 *default_value = !LoginState::Get()->UserHasNetworkProfile(); | 310 *default_value = !LoginState::Get()->UserHasNetworkProfile(); |
| 311 // Allow only authenticated user to change the share state. | 311 // Allow only authenticated user to change the share state. |
| 312 *modifiable = LoginState::Get()->IsUserAuthenticated(); | 312 *modifiable = LoginState::Get()->IsUserAuthenticated(); |
| 313 } | 313 } |
| 314 | 314 |
| 315 // ControlledSettingIndicatorView | 315 // ControlledSettingIndicatorView |
| 316 | 316 |
| 317 ControlledSettingIndicatorView::ControlledSettingIndicatorView() | 317 ControlledSettingIndicatorView::ControlledSettingIndicatorView() |
| 318 : managed_(false), | 318 : managed_(false), image_view_(nullptr) { |
| 319 image_view_(NULL) { | |
| 320 Init(); | 319 Init(); |
| 321 } | 320 } |
| 322 | 321 |
| 323 ControlledSettingIndicatorView::ControlledSettingIndicatorView( | 322 ControlledSettingIndicatorView::ControlledSettingIndicatorView( |
| 324 const NetworkPropertyUIData& ui_data) | 323 const NetworkPropertyUIData& ui_data) |
| 325 : managed_(false), | 324 : managed_(false), image_view_(nullptr) { |
| 326 image_view_(NULL) { | |
| 327 Init(); | 325 Init(); |
| 328 Update(ui_data); | 326 Update(ui_data); |
| 329 } | 327 } |
| 330 | 328 |
| 331 ControlledSettingIndicatorView::~ControlledSettingIndicatorView() {} | 329 ControlledSettingIndicatorView::~ControlledSettingIndicatorView() {} |
| 332 | 330 |
| 333 void ControlledSettingIndicatorView::Update( | 331 void ControlledSettingIndicatorView::Update( |
| 334 const NetworkPropertyUIData& ui_data) { | 332 const NetworkPropertyUIData& ui_data) { |
| 335 if (managed_ == ui_data.IsManaged()) | 333 if (managed_ == ui_data.IsManaged()) |
| 336 return; | 334 return; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 355 image_view_ = new views::ImageView(); | 353 image_view_ = new views::ImageView(); |
| 356 // Disable |image_view_| so mouse events propagate to the parent. | 354 // Disable |image_view_| so mouse events propagate to the parent. |
| 357 image_view_->SetEnabled(false); | 355 image_view_->SetEnabled(false); |
| 358 image_view_->SetImage(image_); | 356 image_view_->SetImage(image_); |
| 359 image_view_->SetTooltipText( | 357 image_view_->SetTooltipText( |
| 360 l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY)); | 358 l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY)); |
| 361 AddChildView(image_view_); | 359 AddChildView(image_view_); |
| 362 } | 360 } |
| 363 | 361 |
| 364 } // namespace chromeos | 362 } // namespace chromeos |
| OLD | NEW |