Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: chrome/browser/chromeos/options/network_config_view.cc

Issue 2445843002: chromeos: Convert "show other network" dialog to work with mash (Closed)
Patch Set: tweak Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/public/cpp/shell_window_ids.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "ui/views/layout/fill_layout.h" 42 #include "ui/views/layout/fill_layout.h"
43 #include "ui/views/layout/layout_constants.h" 43 #include "ui/views/layout/layout_constants.h"
44 #include "ui/views/widget/widget.h" 44 #include "ui/views/widget/widget.h"
45 45
46 using views::Widget; 46 using views::Widget;
47 47
48 namespace chromeos { 48 namespace chromeos {
49 49
50 namespace { 50 namespace {
51 51
52 // Used to check if a network config dialog is already showing.
53 NetworkConfigView* g_instance = nullptr;
54
52 gfx::NativeWindow GetParentForUnhostedDialog() { 55 gfx::NativeWindow GetParentForUnhostedDialog() {
53 if (LoginDisplayHost::default_host()) { 56 if (LoginDisplayHost::default_host()) {
54 return LoginDisplayHost::default_host()->GetNativeWindow(); 57 return LoginDisplayHost::default_host()->GetNativeWindow();
55 } else { 58 } else {
56 Browser* browser = chrome::FindTabbedBrowser( 59 Browser* browser = chrome::FindTabbedBrowser(
57 ProfileManager::GetPrimaryUserProfile(), true); 60 ProfileManager::GetPrimaryUserProfile(), true);
58 if (browser) 61 if (browser)
59 return browser->window()->GetNativeWindow(); 62 return browser->window()->GetNativeWindow();
60 } 63 }
61 return nullptr; 64 return nullptr;
62 } 65 }
63 66
64 // Avoid global static initializer.
65 NetworkConfigView** GetActiveDialogPointer() {
66 static NetworkConfigView* active_dialog = nullptr;
James Cook 2016/10/24 20:14:37 I don't think this actually saved anything, so I s
stevenjb 2016/10/24 20:20:51 It should be valid, but g_instace is simpler.
67 return &active_dialog;
68 }
69
70 NetworkConfigView* GetActiveDialog() {
71 return *(GetActiveDialogPointer());
72 }
73
74 void SetActiveDialog(NetworkConfigView* dialog) {
75 *(GetActiveDialogPointer()) = dialog;
76 }
77
78 } // namespace 67 } // namespace
79 68
80 // static 69 // static
81 const int ChildNetworkConfigView::kInputFieldMinWidth = 270; 70 const int ChildNetworkConfigView::kInputFieldMinWidth = 270;
82 71
83 NetworkConfigView::NetworkConfigView() 72 NetworkConfigView::NetworkConfigView()
84 : child_config_view_(nullptr), 73 : child_config_view_(nullptr),
85 delegate_(nullptr), 74 delegate_(nullptr),
86 advanced_button_(nullptr) { 75 advanced_button_(nullptr) {
87 DCHECK(GetActiveDialog() == nullptr); 76 DCHECK(!g_instance);
88 SetActiveDialog(this); 77 g_instance = this;
89 } 78 }
90 79
91 bool NetworkConfigView::InitWithNetworkState(const NetworkState* network) { 80 bool NetworkConfigView::InitWithNetworkState(const NetworkState* network) {
92 DCHECK(network); 81 DCHECK(network);
93 std::string service_path = network->path(); 82 std::string service_path = network->path();
94 if (network->type() == shill::kTypeWifi || 83 if (network->type() == shill::kTypeWifi ||
95 network->type() == shill::kTypeEthernet) { 84 network->type() == shill::kTypeEthernet) {
96 child_config_view_ = new WifiConfigView(this, service_path, false); 85 child_config_view_ = new WifiConfigView(this, service_path, false);
97 } else if (network->type() == shill::kTypeWimax) { 86 } else if (network->type() == shill::kTypeWimax) {
98 child_config_view_ = new WimaxConfigView(this, service_path); 87 child_config_view_ = new WimaxConfigView(this, service_path);
(...skipping 12 matching lines...) Expand all
111 this, l10n_util::GetStringUTF16( 100 this, l10n_util::GetStringUTF16(
112 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADVANCED_BUTTON)); 101 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADVANCED_BUTTON));
113 } else if (type == shill::kTypeVPN) { 102 } else if (type == shill::kTypeVPN) {
114 child_config_view_ = new VPNConfigView(this, 103 child_config_view_ = new VPNConfigView(this,
115 "" /* service_path */); 104 "" /* service_path */);
116 } 105 }
117 return child_config_view_ != nullptr; 106 return child_config_view_ != nullptr;
118 } 107 }
119 108
120 NetworkConfigView::~NetworkConfigView() { 109 NetworkConfigView::~NetworkConfigView() {
121 DCHECK(GetActiveDialog() == this); 110 DCHECK_EQ(g_instance, this);
122 SetActiveDialog(nullptr); 111 g_instance = nullptr;
123 } 112 }
124 113
125 // static 114 // static
126 void NetworkConfigView::ShowInParent(const std::string& network_id, 115 void NetworkConfigView::ShowInParent(const std::string& network_id,
127 gfx::NativeWindow parent) { 116 gfx::NativeWindow parent) {
128 DCHECK(parent); 117 DCHECK(parent);
129 ShowImpl(network_id, parent, ash::kShellWindowId_Invalid); 118 NetworkConfigView* view = CreateForNetworkId(network_id);
119 if (view)
120 view->ShowDialog(parent);
130 } 121 }
131 122
132 // static 123 // static
133 void NetworkConfigView::ShowInContainer(const std::string& network_id, 124 void NetworkConfigView::ShowInContainer(const std::string& network_id,
134 int container_id) { 125 int container_id) {
135 DCHECK_NE(container_id, ash::kShellWindowId_Invalid); 126 DCHECK_NE(container_id, ash::kShellWindowId_Invalid);
136 ShowImpl(network_id, nullptr, container_id); 127 NetworkConfigView* view = CreateForNetworkId(network_id);
128 if (view)
129 view->ShowDialogInContainer(container_id);
137 } 130 }
138 131
139 // static 132 // static
140 void NetworkConfigView::ShowImpl(const std::string& network_id, 133 NetworkConfigView* NetworkConfigView::CreateForNetworkId(
141 gfx::NativeWindow parent, 134 const std::string& network_id) {
142 int container_id) { 135 if (g_instance)
143 DCHECK(parent || container_id != ash::kShellWindowId_Invalid); 136 return nullptr;
144 if (GetActiveDialog() != nullptr)
145 return;
146 const NetworkState* network = 137 const NetworkState* network =
147 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid( 138 NetworkHandler::Get()->network_state_handler()->GetNetworkStateFromGuid(
148 network_id); 139 network_id);
149 if (!network) { 140 if (!network) {
150 LOG(ERROR) << "NetworkConfigView::Show called with invalid network"; 141 LOG(ERROR)
151 return; 142 << "NetworkConfigView::CreateForNetworkId called with invalid network";
143 return nullptr;
152 } 144 }
153 NetworkConfigView* view = new NetworkConfigView(); 145 NetworkConfigView* view = new NetworkConfigView();
154 if (!view->InitWithNetworkState(network)) { 146 if (!view->InitWithNetworkState(network)) {
155 LOG(ERROR) << "NetworkConfigView::Show called with invalid network type: " 147 LOG(ERROR) << "NetworkConfigView::CreateForNetworkId called with invalid "
148 "network type: "
156 << network->type(); 149 << network->type();
157 delete view; 150 delete view;
158 return; 151 return nullptr;
159 } 152 }
160 NET_LOG(USER) << "NetworkConfigView::Show: " << network->path(); 153 NET_LOG(USER) << "NetworkConfigView::CreateForNetworkId: " << network->path();
161 if (parent) 154 return view;
162 view->ShowDialog(parent);
163 else
164 view->ShowDialogInContainer(container_id);
165 } 155 }
166 156
167 // static 157 // static
168 void NetworkConfigView::ShowForType(const std::string& type, 158 void NetworkConfigView::ShowForType(const std::string& type,
169 gfx::NativeWindow parent) { 159 gfx::NativeWindow parent) {
170 if (GetActiveDialog() != nullptr) 160 // |parent| may be null.
171 return; 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) {
James Cook 2016/10/24 20:14:37 I introduced a Create method instead of ShowForTyp
177 if (g_instance)
178 return nullptr;
172 NetworkConfigView* view = new NetworkConfigView(); 179 NetworkConfigView* view = new NetworkConfigView();
173 if (!view->InitWithType(type)) { 180 if (!view->InitWithType(type)) {
174 LOG(ERROR) << "NetworkConfigView::ShowForType called with invalid type: " 181 LOG(ERROR) << "NetworkConfigView::CreateForType called with invalid type: "
175 << type; 182 << type;
176 delete view; 183 delete view;
177 return; 184 return nullptr;
178 } 185 }
179 NET_LOG(USER) << "NetworkConfigView::ShowForType: " << type; 186 NET_LOG(USER) << "NetworkConfigView::CreateForType: " << type;
180 view->ShowDialog(parent); 187 return view;
181 } 188 }
182 189
183 gfx::NativeWindow NetworkConfigView::GetNativeWindow() const { 190 gfx::NativeWindow NetworkConfigView::GetNativeWindow() const {
184 return GetWidget()->GetNativeWindow(); 191 return GetWidget()->GetNativeWindow();
185 } 192 }
186 193
187 base::string16 NetworkConfigView::GetDialogButtonLabel( 194 base::string16 NetworkConfigView::GetDialogButtonLabel(
188 ui::DialogButton button) const { 195 ui::DialogButton button) const {
189 if (button == ui::DIALOG_BUTTON_OK) { 196 if (button == ui::DIALOG_BUTTON_OK) {
190 if (child_config_view_->IsConfigureDialog()) 197 if (child_config_view_->IsConfigureDialog())
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 } 377 }
371 378
372 ControlledSettingIndicatorView::~ControlledSettingIndicatorView() {} 379 ControlledSettingIndicatorView::~ControlledSettingIndicatorView() {}
373 380
374 gfx::Size ControlledSettingIndicatorView::GetPreferredSize() const { 381 gfx::Size ControlledSettingIndicatorView::GetPreferredSize() const {
375 return (managed_ && visible()) ? image_view_->GetPreferredSize() 382 return (managed_ && visible()) ? image_view_->GetPreferredSize()
376 : gfx::Size(); 383 : gfx::Size();
377 } 384 }
378 385
379 } // namespace chromeos 386 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/options/network_config_view.h ('k') | chrome/browser/ui/ash/system_tray_delegate_chromeos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698