| 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" | |
| 10 #include "ash/shell.h" | |
| 11 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 11 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 14 #include "chrome/browser/chromeos/options/network_property_ui_data.h" | 12 #include "chrome/browser/chromeos/options/network_property_ui_data.h" |
| 15 #include "chrome/browser/chromeos/options/vpn_config_view.h" | 13 #include "chrome/browser/chromeos/options/vpn_config_view.h" |
| 16 #include "chrome/browser/chromeos/options/wifi_config_view.h" | 14 #include "chrome/browser/chromeos/options/wifi_config_view.h" |
| 17 #include "chrome/browser/chromeos/options/wimax_config_view.h" | 15 #include "chrome/browser/chromeos/options/wimax_config_view.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/browser/ui/ash/ash_util.h" | 17 #include "chrome/browser/ui/ash/ash_util.h" |
| 18 #include "chrome/browser/ui/ash/system_tray_client.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/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
| 24 #include "chrome/grit/locale_settings.h" | 23 #include "chrome/grit/locale_settings.h" |
| 25 #include "chromeos/login/login_state.h" | 24 #include "chromeos/login/login_state.h" |
| 26 #include "chromeos/network/network_state.h" | 25 #include "chromeos/network/network_state.h" |
| 27 #include "chromeos/network/network_state_handler.h" | 26 #include "chromeos/network/network_state_handler.h" |
| 28 #include "components/device_event_log/device_event_log.h" | 27 #include "components/device_event_log/device_event_log.h" |
| 29 #include "components/user_manager/user.h" | 28 #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" | |
| 32 #include "ui/accessibility/ax_view_state.h" | 29 #include "ui/accessibility/ax_view_state.h" |
| 33 #include "ui/aura/window_event_dispatcher.h" | 30 #include "ui/aura/window_event_dispatcher.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 35 #include "ui/gfx/color_palette.h" | 32 #include "ui/gfx/color_palette.h" |
| 36 #include "ui/gfx/geometry/rect.h" | 33 #include "ui/gfx/geometry/rect.h" |
| 37 #include "ui/gfx/image/image.h" | 34 #include "ui/gfx/image/image.h" |
| 38 #include "ui/gfx/paint_vector_icon.h" | 35 #include "ui/gfx/paint_vector_icon.h" |
| 39 #include "ui/gfx/vector_icons_public.h" | 36 #include "ui/gfx/vector_icons_public.h" |
| 40 #include "ui/views/controls/button/md_text_button.h" | 37 #include "ui/views/controls/button/md_text_button.h" |
| 41 #include "ui/views/controls/image_view.h" | 38 #include "ui/views/controls/image_view.h" |
| 42 #include "ui/views/layout/fill_layout.h" | 39 #include "ui/views/layout/fill_layout.h" |
| 43 #include "ui/views/layout/layout_constants.h" | 40 #include "ui/views/layout/layout_constants.h" |
| 44 #include "ui/views/widget/widget.h" | 41 #include "ui/views/widget/widget.h" |
| 45 | 42 |
| 46 using views::Widget; | 43 using views::Widget; |
| 47 | 44 |
| 48 namespace chromeos { | 45 namespace chromeos { |
| 49 | 46 |
| 50 namespace { | 47 namespace { |
| 51 | 48 |
| 52 // Used to check if a network config dialog is already showing. | 49 // Used to check if a network config dialog is already showing. |
| 53 NetworkConfigView* g_instance = nullptr; | 50 NetworkConfigView* g_instance = nullptr; |
| 54 | 51 |
| 55 gfx::NativeWindow GetParentForUnhostedDialog() { | 52 gfx::NativeWindow GetParentForUnhostedDialog() { |
| 56 if (LoginDisplayHost::default_host()) { | 53 if (LoginDisplayHost::default_host()) { |
| 57 return LoginDisplayHost::default_host()->GetNativeWindow(); | 54 // TODO(jamescook): LoginDisplayHost has the wrong native window in mash. |
| 55 // This will fix itself when mash converts from ui::Window to aura::Window. |
| 56 // http://crbug.com/659155 |
| 57 if (!chrome::IsRunningInMash()) |
| 58 return LoginDisplayHost::default_host()->GetNativeWindow(); |
| 58 } else { | 59 } else { |
| 59 Browser* browser = chrome::FindTabbedBrowser( | 60 Browser* browser = chrome::FindTabbedBrowser( |
| 60 ProfileManager::GetPrimaryUserProfile(), true); | 61 ProfileManager::GetPrimaryUserProfile(), true); |
| 61 if (browser) | 62 if (browser) |
| 62 return browser->window()->GetNativeWindow(); | 63 return browser->window()->GetNativeWindow(); |
| 63 } | 64 } |
| 64 return nullptr; | 65 return nullptr; |
| 65 } | 66 } |
| 66 | 67 |
| 67 } // namespace | 68 } // namespace |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 106 } |
| 106 return child_config_view_ != nullptr; | 107 return child_config_view_ != nullptr; |
| 107 } | 108 } |
| 108 | 109 |
| 109 NetworkConfigView::~NetworkConfigView() { | 110 NetworkConfigView::~NetworkConfigView() { |
| 110 DCHECK_EQ(g_instance, this); | 111 DCHECK_EQ(g_instance, this); |
| 111 g_instance = nullptr; | 112 g_instance = nullptr; |
| 112 } | 113 } |
| 113 | 114 |
| 114 // static | 115 // static |
| 115 void NetworkConfigView::ShowInParent(const std::string& network_id, | 116 void NetworkConfigView::ShowForNetworkId(const std::string& network_id, |
| 116 gfx::NativeWindow parent) { | 117 gfx::NativeWindow parent) { |
| 117 DCHECK(parent); | |
| 118 NetworkConfigView* view = CreateForNetworkId(network_id); | |
| 119 if (view) | |
| 120 view->ShowDialog(parent); | |
| 121 } | |
| 122 | |
| 123 // static | |
| 124 void NetworkConfigView::ShowInContainer(const std::string& network_id, | |
| 125 int container_id) { | |
| 126 DCHECK_NE(container_id, ash::kShellWindowId_Invalid); | |
| 127 NetworkConfigView* view = CreateForNetworkId(network_id); | |
| 128 if (view) | |
| 129 view->ShowDialogInContainer(container_id); | |
| 130 } | |
| 131 | |
| 132 // static | |
| 133 NetworkConfigView* NetworkConfigView::CreateForNetworkId( | |
| 134 const std::string& network_id) { | |
| 135 if (g_instance) | 118 if (g_instance) |
| 136 return nullptr; | 119 return; |
| 137 const NetworkState* network = | 120 const NetworkState* network = |
| 138 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid( | 121 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid( |
| 139 network_id); | 122 network_id); |
| 140 if (!network) { | 123 if (!network) { |
| 141 LOG(ERROR) | 124 LOG(ERROR) |
| 142 << "NetworkConfigView::CreateForNetworkId called with invalid network"; | 125 << "NetworkConfigView::ShowForNetworkId called with invalid network"; |
| 143 return nullptr; | 126 return; |
| 144 } | 127 } |
| 145 NetworkConfigView* view = new NetworkConfigView(); | 128 NetworkConfigView* view = new NetworkConfigView(); |
| 146 if (!view->InitWithNetworkState(network)) { | 129 if (!view->InitWithNetworkState(network)) { |
| 147 LOG(ERROR) << "NetworkConfigView::CreateForNetworkId called with invalid " | 130 LOG(ERROR) << "NetworkConfigView::ShowForNetworkId called with invalid " |
| 148 "network type: " | 131 "network type: " |
| 149 << network->type(); | 132 << network->type(); |
| 150 delete view; | 133 delete view; |
| 151 return nullptr; | 134 return; |
| 152 } | 135 } |
| 153 NET_LOG(USER) << "NetworkConfigView::CreateForNetworkId: " << network->path(); | 136 NET_LOG(USER) << "NetworkConfigView::ShowForNetworkId: " << network->path(); |
| 154 return view; | 137 view->ShowDialog(parent); |
| 155 } | 138 } |
| 156 | 139 |
| 157 // static | 140 // static |
| 158 void NetworkConfigView::ShowForType(const std::string& type, | 141 void NetworkConfigView::ShowForType(const std::string& type, |
| 159 gfx::NativeWindow parent) { | 142 gfx::NativeWindow parent) { |
| 160 // |parent| may be null. | |
| 161 NetworkConfigView* view = CreateForType(type); | |
| 162 if (view) | |
| 163 view->ShowDialog(parent); | |
| 164 } | |
| 165 | |
| 166 // static | |
| 167 void NetworkConfigView::ShowForTypeInContainer(const std::string& type, | |
| 168 int container_id) { | |
| 169 DCHECK_NE(container_id, ash::kShellWindowId_Invalid); | |
| 170 NetworkConfigView* view = CreateForType(type); | |
| 171 if (view) | |
| 172 view->ShowDialogInContainer(container_id); | |
| 173 } | |
| 174 | |
| 175 // static | |
| 176 NetworkConfigView* NetworkConfigView::CreateForType(const std::string& type) { | |
| 177 if (g_instance) | 143 if (g_instance) |
| 178 return nullptr; | 144 return; |
| 179 NetworkConfigView* view = new NetworkConfigView(); | 145 NetworkConfigView* view = new NetworkConfigView(); |
| 180 if (!view->InitWithType(type)) { | 146 if (!view->InitWithType(type)) { |
| 181 LOG(ERROR) << "NetworkConfigView::CreateForType called with invalid type: " | 147 LOG(ERROR) << "NetworkConfigView::ShowForType called with invalid type: " |
| 182 << type; | 148 << type; |
| 183 delete view; | 149 delete view; |
| 184 return nullptr; | 150 return; |
| 185 } | 151 } |
| 186 NET_LOG(USER) << "NetworkConfigView::CreateForType: " << type; | 152 NET_LOG(USER) << "NetworkConfigView::ShowForType: " << type; |
| 187 return view; | 153 view->ShowDialog(parent); |
| 188 } | 154 } |
| 189 | 155 |
| 190 gfx::NativeWindow NetworkConfigView::GetNativeWindow() const { | 156 gfx::NativeWindow NetworkConfigView::GetNativeWindow() const { |
| 191 return GetWidget()->GetNativeWindow(); | 157 return GetWidget()->GetNativeWindow(); |
| 192 } | 158 } |
| 193 | 159 |
| 194 base::string16 NetworkConfigView::GetDialogButtonLabel( | 160 base::string16 NetworkConfigView::GetDialogButtonLabel( |
| 195 ui::DialogButton button) const { | 161 ui::DialogButton button) const { |
| 196 if (button == ui::DIALOG_BUTTON_OK) { | 162 if (button == ui::DIALOG_BUTTON_OK) { |
| 197 if (child_config_view_->IsConfigureDialog()) | 163 if (child_config_view_->IsConfigureDialog()) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 const ViewHierarchyChangedDetails& details) { | 265 const ViewHierarchyChangedDetails& details) { |
| 300 // Can't init before we're inserted into a Container, because we require | 266 // Can't init before we're inserted into a Container, because we require |
| 301 // a HWND to parent native child controls to. | 267 // a HWND to parent native child controls to. |
| 302 views::DialogDelegateView::ViewHierarchyChanged(details); | 268 views::DialogDelegateView::ViewHierarchyChanged(details); |
| 303 if (details.is_add && details.child == this) { | 269 if (details.is_add && details.child == this) { |
| 304 AddChildView(child_config_view_); | 270 AddChildView(child_config_view_); |
| 305 } | 271 } |
| 306 } | 272 } |
| 307 | 273 |
| 308 void NetworkConfigView::ShowDialog(gfx::NativeWindow parent) { | 274 void NetworkConfigView::ShowDialog(gfx::NativeWindow parent) { |
| 275 // Attempt to find a fallback parent window. |
| 309 if (parent == nullptr) | 276 if (parent == nullptr) |
| 310 parent = GetParentForUnhostedDialog(); | 277 parent = GetParentForUnhostedDialog(); |
| 311 // Failed connections may result in a pop-up with no natural parent window, | 278 |
| 312 // so provide a fallback context on the primary display. This is necessary | 279 Widget* window = nullptr; |
| 313 // becase one of parent or context must be non nullptr. | 280 if (parent) { |
| 314 gfx::NativeWindow context = | 281 // Create as a child of |parent|. |
| 315 parent ? nullptr : ash::Shell::GetPrimaryRootWindow(); | 282 window = DialogDelegate::CreateDialogWidget(this, nullptr, parent); |
| 316 Widget* window = DialogDelegate::CreateDialogWidget(this, context, parent); | 283 } else { |
| 284 // Fall back to default window container on primary display. |
| 285 window = SystemTrayClient::CreateUnownedDialogWidget(this); |
| 286 } |
| 317 window->SetAlwaysOnTop(true); | 287 window->SetAlwaysOnTop(true); |
| 318 window->Show(); | 288 window->Show(); |
| 319 } | 289 } |
| 320 | |
| 321 void NetworkConfigView::ShowDialogInContainer(int container_id) { | |
| 322 DCHECK_NE(container_id, ash::kShellWindowId_Invalid); | |
| 323 Widget::InitParams params = DialogDelegate::GetDialogWidgetInitParams( | |
| 324 this, nullptr, nullptr, gfx::Rect()); | |
| 325 Widget* window = new Widget; | |
| 326 if (chrome::IsRunningInMash()) { | |
| 327 using ui::mojom::WindowManager; | |
| 328 params.mus_properties[WindowManager::kInitialContainerId_Property] = | |
| 329 mojo::ConvertTo<std::vector<uint8_t>>(container_id); | |
| 330 } else { | |
| 331 params.parent = ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(), | |
| 332 container_id); | |
| 333 } | |
| 334 window->Init(params); | |
| 335 window->SetAlwaysOnTop(true); | |
| 336 window->Show(); | |
| 337 } | |
| 338 | 290 |
| 339 // ChildNetworkConfigView | 291 // ChildNetworkConfigView |
| 340 | 292 |
| 341 ChildNetworkConfigView::ChildNetworkConfigView( | 293 ChildNetworkConfigView::ChildNetworkConfigView( |
| 342 NetworkConfigView* parent, | 294 NetworkConfigView* parent, |
| 343 const std::string& service_path) | 295 const std::string& service_path) |
| 344 : parent_(parent), | 296 : parent_(parent), |
| 345 service_path_(service_path) { | 297 service_path_(service_path) { |
| 346 } | 298 } |
| 347 | 299 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 377 } | 329 } |
| 378 | 330 |
| 379 ControlledSettingIndicatorView::~ControlledSettingIndicatorView() {} | 331 ControlledSettingIndicatorView::~ControlledSettingIndicatorView() {} |
| 380 | 332 |
| 381 gfx::Size ControlledSettingIndicatorView::GetPreferredSize() const { | 333 gfx::Size ControlledSettingIndicatorView::GetPreferredSize() const { |
| 382 return (managed_ && visible()) ? image_view_->GetPreferredSize() | 334 return (managed_ && visible()) ? image_view_->GetPreferredSize() |
| 383 : gfx::Size(); | 335 : gfx::Size(); |
| 384 } | 336 } |
| 385 | 337 |
| 386 } // namespace chromeos | 338 } // namespace chromeos |
| OLD | NEW |