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/network_login_observer.h" | 5 #include "chrome/browser/chromeos/network_login_observer.h" |
6 | 6 |
7 #include "chrome/browser/chromeos/cros/cros_library.h" | 7 #include "chrome/browser/chromeos/cros/cros_library.h" |
8 #include "chrome/browser/chromeos/cros/network_library.h" | 8 #include "chrome/browser/chromeos/cros/network_library.h" |
9 #include "chrome/browser/chromeos/login/base_login_display_host.h" | |
10 #include "chrome/browser/chromeos/options/network_config_view.h" | 9 #include "chrome/browser/chromeos/options/network_config_view.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | |
12 #include "chrome/browser/ui/browser.h" | |
13 #include "chrome/browser/ui/browser_list.h" | |
14 #include "chrome/browser/ui/browser_window.h" | |
15 #include "ui/views/widget/widget.h" | 10 #include "ui/views/widget/widget.h" |
16 #include "ui/views/widget/widget_delegate.h" | 11 #include "ui/views/widget/widget_delegate.h" |
17 | 12 |
18 namespace chromeos { | 13 namespace chromeos { |
19 | 14 |
20 NetworkLoginObserver::NetworkLoginObserver(NetworkLibrary* netlib) { | 15 NetworkLoginObserver::NetworkLoginObserver(NetworkLibrary* netlib) { |
21 netlib->AddNetworkManagerObserver(this); | 16 netlib->AddNetworkManagerObserver(this); |
22 } | 17 } |
23 | 18 |
24 NetworkLoginObserver::~NetworkLoginObserver() { | 19 NetworkLoginObserver::~NetworkLoginObserver() { |
25 CrosLibrary::Get()->GetNetworkLibrary()->RemoveNetworkManagerObserver(this); | 20 CrosLibrary::Get()->GetNetworkLibrary()->RemoveNetworkManagerObserver(this); |
26 } | 21 } |
27 | 22 |
28 void NetworkLoginObserver::CreateModalPopup(views::WidgetDelegate* view) { | |
29 gfx::NativeWindow parent = NULL; | |
30 if (BaseLoginDisplayHost::default_host()) { | |
31 parent = BaseLoginDisplayHost::default_host()->GetNativeWindow(); | |
32 } else { | |
33 Browser* browser = BrowserList::FindTabbedBrowser( | |
34 ProfileManager::GetDefaultProfileOrOffTheRecord(), true); | |
35 parent = browser ? browser->window()->GetNativeHandle() : NULL; | |
36 } | |
37 views::Widget* window = views::Widget::CreateWindowWithParent(view, parent); | |
38 window->SetAlwaysOnTop(true); | |
39 window->Show(); | |
40 } | |
41 | |
42 void NetworkLoginObserver::OnNetworkManagerChanged(NetworkLibrary* cros) { | 23 void NetworkLoginObserver::OnNetworkManagerChanged(NetworkLibrary* cros) { |
43 const WifiNetworkVector& wifi_networks = cros->wifi_networks(); | 24 const WifiNetworkVector& wifi_networks = cros->wifi_networks(); |
44 const VirtualNetworkVector& virtual_networks = cros->virtual_networks(); | 25 const VirtualNetworkVector& virtual_networks = cros->virtual_networks(); |
45 | 26 |
46 // Check to see if we have any newly failed wifi network. | 27 // Check to see if we have any newly failed wifi network. |
47 for (WifiNetworkVector::const_iterator it = wifi_networks.begin(); | 28 for (WifiNetworkVector::const_iterator it = wifi_networks.begin(); |
48 it != wifi_networks.end(); it++) { | 29 it != wifi_networks.end(); it++) { |
49 WifiNetwork* wifi = *it; | 30 WifiNetwork* wifi = *it; |
50 if (wifi->notify_failure()) { | 31 if (wifi->notify_failure()) { |
51 // Display login dialog again for bad_passphrase and bad_wepkey errors. | 32 // Display login dialog again for bad_passphrase and bad_wepkey errors. |
52 // Always re-display for user initiated connections that fail. | 33 // Always re-display for user initiated connections that fail. |
53 // Always re-display the login dialog for encrypted networks that were | 34 // Always re-display the login dialog for encrypted networks that were |
54 // added and failed to connect for any reason. | 35 // added and failed to connect for any reason. |
55 VLOG(1) << "NotifyFailure: " << wifi->name() | 36 VLOG(1) << "NotifyFailure: " << wifi->name() |
56 << ", error: " << wifi->error() | 37 << ", error: " << wifi->error() |
57 << ", added: " << wifi->added(); | 38 << ", added: " << wifi->added(); |
58 if (wifi->error() == ERROR_BAD_PASSPHRASE || | 39 if (wifi->error() == ERROR_BAD_PASSPHRASE || |
59 wifi->error() == ERROR_BAD_WEPKEY || | 40 wifi->error() == ERROR_BAD_WEPKEY || |
60 wifi->connection_started() || | 41 wifi->connection_started() || |
61 (wifi->encrypted() && wifi->added())) { | 42 (wifi->encrypted() && wifi->added())) { |
62 CreateModalPopup(new NetworkConfigView(wifi)); | 43 NetworkConfigView::Show(wifi, NULL); |
63 return; // Only support one failure per notification. | 44 return; // Only support one failure per notification. |
64 } | 45 } |
65 } | 46 } |
66 } | 47 } |
67 // Check to see if we have any newly failed virtual network. | 48 // Check to see if we have any newly failed virtual network. |
68 for (VirtualNetworkVector::const_iterator it = virtual_networks.begin(); | 49 for (VirtualNetworkVector::const_iterator it = virtual_networks.begin(); |
69 it != virtual_networks.end(); it++) { | 50 it != virtual_networks.end(); it++) { |
70 VirtualNetwork* vpn = *it; | 51 VirtualNetwork* vpn = *it; |
71 if (vpn->notify_failure()) { | 52 if (vpn->notify_failure()) { |
72 VLOG(1) << "NotifyFailure: " << vpn->name() | 53 VLOG(1) << "NotifyFailure: " << vpn->name() |
73 << ", error: " << vpn->error() | 54 << ", error: " << vpn->error() |
74 << ", added: " << vpn->added(); | 55 << ", added: " << vpn->added(); |
75 // Display login dialog for any error or newly added network. | 56 // Display login dialog for any error or newly added network. |
76 if (vpn->error() != ERROR_NO_ERROR || vpn->added()) { | 57 if (vpn->error() != ERROR_NO_ERROR || vpn->added()) { |
77 CreateModalPopup(new NetworkConfigView(vpn)); | 58 NetworkConfigView::Show(vpn, NULL); |
78 return; // Only support one failure per notification. | 59 return; // Only support one failure per notification. |
79 } | 60 } |
80 } | 61 } |
81 } | 62 } |
82 } | 63 } |
83 | 64 |
84 } // namespace chromeos | 65 } // namespace chromeos |
OLD | NEW |