| 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/public/cpp/shell_window_ids.h" |
| 9 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 13 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 13 #include "chrome/browser/chromeos/options/network_property_ui_data.h" | 14 #include "chrome/browser/chromeos/options/network_property_ui_data.h" |
| 14 #include "chrome/browser/chromeos/options/vpn_config_view.h" | 15 #include "chrome/browser/chromeos/options/vpn_config_view.h" |
| 15 #include "chrome/browser/chromeos/options/wifi_config_view.h" | 16 #include "chrome/browser/chromeos/options/wifi_config_view.h" |
| 16 #include "chrome/browser/chromeos/options/wimax_config_view.h" | 17 #include "chrome/browser/chromeos/options/wimax_config_view.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/browser/ui/ash/ash_util.h" |
| 18 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
| 20 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
| 21 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
| 22 #include "chrome/grit/locale_settings.h" | 24 #include "chrome/grit/locale_settings.h" |
| 23 #include "chromeos/login/login_state.h" | 25 #include "chromeos/login/login_state.h" |
| 24 #include "chromeos/network/network_state.h" | 26 #include "chromeos/network/network_state.h" |
| 25 #include "chromeos/network/network_state_handler.h" | 27 #include "chromeos/network/network_state_handler.h" |
| 26 #include "components/device_event_log/device_event_log.h" | 28 #include "components/device_event_log/device_event_log.h" |
| 27 #include "components/user_manager/user.h" | 29 #include "components/user_manager/user.h" |
| 30 #include "services/ui/public/cpp/property_type_converters.h" |
| 31 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 28 #include "ui/accessibility/ax_view_state.h" | 32 #include "ui/accessibility/ax_view_state.h" |
| 29 #include "ui/aura/window_event_dispatcher.h" | 33 #include "ui/aura/window_event_dispatcher.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 31 #include "ui/gfx/color_palette.h" | 35 #include "ui/gfx/color_palette.h" |
| 32 #include "ui/gfx/geometry/rect.h" | 36 #include "ui/gfx/geometry/rect.h" |
| 33 #include "ui/gfx/image/image.h" | 37 #include "ui/gfx/image/image.h" |
| 34 #include "ui/gfx/paint_vector_icon.h" | 38 #include "ui/gfx/paint_vector_icon.h" |
| 35 #include "ui/gfx/vector_icons_public.h" | 39 #include "ui/gfx/vector_icons_public.h" |
| 36 #include "ui/views/controls/button/md_text_button.h" | 40 #include "ui/views/controls/button/md_text_button.h" |
| 37 #include "ui/views/controls/image_view.h" | 41 #include "ui/views/controls/image_view.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 116 } |
| 113 return child_config_view_ != nullptr; | 117 return child_config_view_ != nullptr; |
| 114 } | 118 } |
| 115 | 119 |
| 116 NetworkConfigView::~NetworkConfigView() { | 120 NetworkConfigView::~NetworkConfigView() { |
| 117 DCHECK(GetActiveDialog() == this); | 121 DCHECK(GetActiveDialog() == this); |
| 118 SetActiveDialog(nullptr); | 122 SetActiveDialog(nullptr); |
| 119 } | 123 } |
| 120 | 124 |
| 121 // static | 125 // static |
| 122 void NetworkConfigView::Show(const std::string& service_path, | 126 void NetworkConfigView::ShowInParent(const std::string& network_id, |
| 123 gfx::NativeWindow parent) { | 127 gfx::NativeWindow parent) { |
| 124 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> | 128 DCHECK(parent); |
| 125 GetNetworkState(service_path); | 129 ShowImpl(network_id, parent, ash::kShellWindowId_Invalid); |
| 126 ShowByNetwork(network, parent); | |
| 127 } | 130 } |
| 128 | 131 |
| 129 // static | 132 // static |
| 130 void NetworkConfigView::ShowByNetworkId(const std::string& network_id, | 133 void NetworkConfigView::ShowInContainer(const std::string& network_id, |
| 131 gfx::NativeWindow parent) { | 134 int container_id) { |
| 135 DCHECK_NE(container_id, ash::kShellWindowId_Invalid); |
| 136 ShowImpl(network_id, nullptr, container_id); |
| 137 } |
| 138 |
| 139 // static |
| 140 void NetworkConfigView::ShowImpl(const std::string& network_id, |
| 141 gfx::NativeWindow parent, |
| 142 int container_id) { |
| 143 DCHECK(parent || container_id != ash::kShellWindowId_Invalid); |
| 144 if (GetActiveDialog() != nullptr) |
| 145 return; |
| 132 const NetworkState* network = | 146 const NetworkState* network = |
| 133 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid( | 147 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid( |
| 134 network_id); | 148 network_id); |
| 135 ShowByNetwork(network, parent); | |
| 136 } | |
| 137 | |
| 138 // static | |
| 139 void NetworkConfigView::ShowByNetwork(const NetworkState* network, | |
| 140 gfx::NativeWindow parent) { | |
| 141 if (GetActiveDialog() != nullptr) | |
| 142 return; | |
| 143 if (!network) { | 149 if (!network) { |
| 144 LOG(ERROR) << "NetworkConfigView::Show called with invalid network"; | 150 LOG(ERROR) << "NetworkConfigView::Show called with invalid network"; |
| 145 return; | 151 return; |
| 146 } | 152 } |
| 147 NetworkConfigView* view = new NetworkConfigView(); | 153 NetworkConfigView* view = new NetworkConfigView(); |
| 148 if (!view->InitWithNetworkState(network)) { | 154 if (!view->InitWithNetworkState(network)) { |
| 149 LOG(ERROR) << "NetworkConfigView::Show called with invalid network type: " | 155 LOG(ERROR) << "NetworkConfigView::Show called with invalid network type: " |
| 150 << network->type(); | 156 << network->type(); |
| 151 delete view; | 157 delete view; |
| 152 return; | 158 return; |
| 153 } | 159 } |
| 154 NET_LOG(USER) << "NetworkConfigView::Show: " << network->path(); | 160 NET_LOG(USER) << "NetworkConfigView::Show: " << network->path(); |
| 155 view->ShowDialog(parent); | 161 if (parent) |
| 162 view->ShowDialog(parent); |
| 163 else |
| 164 view->ShowDialogInContainer(container_id); |
| 156 } | 165 } |
| 157 | 166 |
| 158 // static | 167 // static |
| 159 void NetworkConfigView::ShowForType(const std::string& type, | 168 void NetworkConfigView::ShowForType(const std::string& type, |
| 160 gfx::NativeWindow parent) { | 169 gfx::NativeWindow parent) { |
| 161 if (GetActiveDialog() != nullptr) | 170 if (GetActiveDialog() != nullptr) |
| 162 return; | 171 return; |
| 163 NetworkConfigView* view = new NetworkConfigView(); | 172 NetworkConfigView* view = new NetworkConfigView(); |
| 164 if (!view->InitWithType(type)) { | 173 if (!view->InitWithType(type)) { |
| 165 LOG(ERROR) << "NetworkConfigView::ShowForType called with invalid type: " | 174 LOG(ERROR) << "NetworkConfigView::ShowForType called with invalid type: " |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 // Failed connections may result in a pop-up with no natural parent window, | 304 // Failed connections may result in a pop-up with no natural parent window, |
| 296 // so provide a fallback context on the primary display. This is necessary | 305 // so provide a fallback context on the primary display. This is necessary |
| 297 // becase one of parent or context must be non nullptr. | 306 // becase one of parent or context must be non nullptr. |
| 298 gfx::NativeWindow context = | 307 gfx::NativeWindow context = |
| 299 parent ? nullptr : ash::Shell::GetPrimaryRootWindow(); | 308 parent ? nullptr : ash::Shell::GetPrimaryRootWindow(); |
| 300 Widget* window = DialogDelegate::CreateDialogWidget(this, context, parent); | 309 Widget* window = DialogDelegate::CreateDialogWidget(this, context, parent); |
| 301 window->SetAlwaysOnTop(true); | 310 window->SetAlwaysOnTop(true); |
| 302 window->Show(); | 311 window->Show(); |
| 303 } | 312 } |
| 304 | 313 |
| 314 void NetworkConfigView::ShowDialogInContainer(int container_id) { |
| 315 DCHECK_NE(container_id, ash::kShellWindowId_Invalid); |
| 316 Widget::InitParams params = DialogDelegate::GetDialogWidgetInitParams( |
| 317 this, nullptr, nullptr, gfx::Rect()); |
| 318 Widget* window = new Widget; |
| 319 if (chrome::IsRunningInMash()) { |
| 320 using ui::mojom::WindowManager; |
| 321 params.mus_properties[WindowManager::kInitialContainerId_Property] = |
| 322 mojo::ConvertTo<std::vector<uint8_t>>(container_id); |
| 323 } else { |
| 324 params.parent = ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(), |
| 325 container_id); |
| 326 } |
| 327 window->Init(params); |
| 328 window->SetAlwaysOnTop(true); |
| 329 window->Show(); |
| 330 } |
| 331 |
| 305 // ChildNetworkConfigView | 332 // ChildNetworkConfigView |
| 306 | 333 |
| 307 ChildNetworkConfigView::ChildNetworkConfigView( | 334 ChildNetworkConfigView::ChildNetworkConfigView( |
| 308 NetworkConfigView* parent, | 335 NetworkConfigView* parent, |
| 309 const std::string& service_path) | 336 const std::string& service_path) |
| 310 : parent_(parent), | 337 : parent_(parent), |
| 311 service_path_(service_path) { | 338 service_path_(service_path) { |
| 312 } | 339 } |
| 313 | 340 |
| 314 ChildNetworkConfigView::~ChildNetworkConfigView() { | 341 ChildNetworkConfigView::~ChildNetworkConfigView() { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 343 } | 370 } |
| 344 | 371 |
| 345 ControlledSettingIndicatorView::~ControlledSettingIndicatorView() {} | 372 ControlledSettingIndicatorView::~ControlledSettingIndicatorView() {} |
| 346 | 373 |
| 347 gfx::Size ControlledSettingIndicatorView::GetPreferredSize() const { | 374 gfx::Size ControlledSettingIndicatorView::GetPreferredSize() const { |
| 348 return (managed_ && visible()) ? image_view_->GetPreferredSize() | 375 return (managed_ && visible()) ? image_view_->GetPreferredSize() |
| 349 : gfx::Size(); | 376 : gfx::Size(); |
| 350 } | 377 } |
| 351 | 378 |
| 352 } // namespace chromeos | 379 } // namespace chromeos |
| OLD | NEW |