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

Side by Side Diff: chrome/browser/chromeos/login/screens/error_screen.cc

Issue 872633008: Migrate (Network)ErrorScreen to ScreenContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 5 years, 10 months 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/login/screens/error_screen.h" 5 #include "chrome/browser/chromeos/login/screens/error_screen.h"
6 6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
7 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/chromeos/app_mode/app_session_lifetime.h"
13 #include "chrome/browser/chromeos/app_mode/certificate_manager_dialog.h"
8 #include "chrome/browser/chromeos/login/auth/chrome_login_performer.h" 14 #include "chrome/browser/chromeos/login/auth/chrome_login_performer.h"
9 #include "chrome/browser/chromeos/login/chrome_restart_request.h" 15 #include "chrome/browser/chromeos/login/chrome_restart_request.h"
10 #include "chrome/browser/chromeos/login/screens/error_screen_actor.h" 16 #include "chrome/browser/chromeos/login/screens/network_error_view.h"
11 #include "chrome/browser/chromeos/login/startup_utils.h" 17 #include "chrome/browser/chromeos/login/startup_utils.h"
18 #include "chrome/browser/chromeos/login/ui/captive_portal_window_proxy.h"
19 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
20 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
12 #include "chrome/browser/chromeos/login/wizard_controller.h" 21 #include "chrome/browser/chromeos/login/wizard_controller.h"
22 #include "chrome/browser/chromeos/profiles/profile_helper.h"
13 #include "chrome/browser/chromeos/settings/cros_settings.h" 23 #include "chrome/browser/chromeos/settings/cros_settings.h"
24 #include "chrome/browser/chromeos/settings/device_settings_service.h"
25 #include "chrome/browser/extensions/component_loader.h"
26 #include "chrome/browser/extensions/extension_service.h"
27 #include "chrome/browser/ui/extensions/app_launch_params.h"
28 #include "chrome/browser/ui/extensions/application_launch.h"
29 #include "chrome/common/extensions/extension_constants.h"
30 #include "chromeos/dbus/dbus_thread_manager.h"
31 #include "chromeos/dbus/power_manager_client.h"
32 #include "chromeos/dbus/session_manager_client.h"
33 #include "chromeos/network/portal_detector/network_portal_detector.h"
34 #include "chromeos/network/portal_detector/network_portal_detector_strategy.h"
35 #include "components/user_manager/user_manager.h"
36 #include "content/public/browser/notification_service.h"
37 #include "extensions/browser/extension_system.h"
38 #include "extensions/common/constants.h"
39 #include "grit/browser_resources.h"
40 #include "ui/gfx/native_widget_types.h"
14 41
15 namespace chromeos { 42 namespace chromeos {
16 43
17 ErrorScreen::ErrorScreen(BaseScreenDelegate* base_screen_delegate, 44 ErrorScreen::ErrorScreen(BaseScreenDelegate* base_screen_delegate,
18 ErrorScreenActor* actor) 45 NetworkErrorView* view)
19 : BaseScreen(base_screen_delegate), 46 : NetworkErrorModel(base_screen_delegate),
20 actor_(actor), 47 view_(view),
21 parent_screen_(OobeDisplay::SCREEN_UNKNOWN), 48 ui_state_(NetworkError::UI_STATE_UNKNOWN),
49 error_state_(NetworkError::ERROR_STATE_UNKNOWN),
50 parent_screen_(OobeUI::SCREEN_UNKNOWN),
22 weak_factory_(this) { 51 weak_factory_(this) {
23 CHECK(actor_); 52 network_state_informer_ = new NetworkStateInformer();
24 actor_->SetDelegate(this); 53 network_state_informer_->Init();
54 if (view_)
55 view_->Bind(*this);
25 } 56 }
26 57
27 ErrorScreen::~ErrorScreen() { 58 ErrorScreen::~ErrorScreen() {
28 if (actor_) 59 if (view_)
29 actor_->SetDelegate(NULL); 60 view_->Unbind();
30 } 61 }
31 62
32 void ErrorScreen::PrepareToShow() { 63 void ErrorScreen::PrepareToShow() {
64 if (view_)
65 view_->PrepareToShow();
33 } 66 }
34 67
35 void ErrorScreen::Show() { 68 void ErrorScreen::Show() {
36 if (actor_) 69 if (!on_hide_callback_) {
37 actor_->Show(parent_screen(), NULL); 70 SetHideCallback(base::Bind(&ErrorScreen::DefaultHideCallback,
71 weak_factory_.GetWeakPtr()));
72 }
73 if (view_)
74 view_->Show();
38 } 75 }
39 76
40 void ErrorScreen::Hide() { 77 void ErrorScreen::Hide() {
41 if (actor_) 78 if (view_)
42 actor_->Hide(); 79 view_->Hide();
43 } 80 }
44 81
45 std::string ErrorScreen::GetName() const { 82 void ErrorScreen::OnShow() {
46 return WizardController::kErrorScreenName; 83 LOG(WARNING) << "Network error screen message is shown";
84 content::NotificationService::current()->Notify(
85 chrome::NOTIFICATION_LOGIN_NETWORK_ERROR_SHOWN,
86 content::NotificationService::AllSources(),
87 content::NotificationService::NoDetails());
88 NetworkPortalDetector::Get()->SetStrategy(
89 PortalDetectorStrategy::STRATEGY_ID_ERROR_SCREEN);
47 } 90 }
48 91
49 void ErrorScreen::OnErrorShow() {} 92 void ErrorScreen::OnHide() {
50 93 LOG(WARNING) << "Network error screen message is hidden";
51 void ErrorScreen::OnErrorHide() {} 94 if (on_hide_callback_) {
52 95 on_hide_callback_->Run();
53 void ErrorScreen::OnLaunchOobeGuestSession() { 96 on_hide_callback_.reset();
54 DeviceSettingsService::Get()->GetOwnershipStatusAsync( 97 }
55 base::Bind(&ErrorScreen::StartGuestSessionAfterOwnershipCheck, 98 NetworkPortalDetector::Get()->SetStrategy(
56 weak_factory_.GetWeakPtr())); 99 PortalDetectorStrategy::STRATEGY_ID_LOGIN_SCREEN);
57 } 100 }
58 101
59 void ErrorScreen::OnActorDestroyed() { 102 void ErrorScreen::OnUserAction(const std::string& action_id) {
60 actor_ = nullptr; 103 if (action_id == kUserActionShowCaptivePortalClicked)
104 ShowCaptivePortal();
105 else if (action_id == kUserActionConfigureCertsButtonClicked)
106 OnConfigureCerts();
107 else if (action_id == kUserActionDiagnoseButtonClicked)
108 OnDiagnoseButtonClicked();
109 else if (action_id == kUserActionLaunchOobeGuestSessionClicked)
110 OnLaunchOobeGuestSession();
111 else if (action_id == kUserActionLocalStateErrorPowerwashButtonClicked)
112 OnLocalStateErrorPowerwashButtonClicked();
113 else if (action_id == kUserActionRebootButtonClicked)
114 OnRebootButtonClicked();
115 else
116 BaseScreen::OnUserAction(action_id);
117 }
118
119 void ErrorScreen::OnContextKeyUpdated(
120 const ::login::ScreenContext::KeyType& key) {
121 BaseScreen::OnContextKeyUpdated(key);
122 }
123
124 void ErrorScreen::AllowGuestSignin(bool allowed) {
125 GetContextEditor().SetBoolean(kContextKeyGuestSigninAllowed, allowed);
126 }
127
128 void ErrorScreen::AllowOfflineLogin(bool allowed) {
129 GetContextEditor().SetBoolean(kContextKeyOfflineSigninAllowed, allowed);
130 }
131
132 void ErrorScreen::FixCaptivePortal() {
133 if (!captive_portal_window_proxy_.get()) {
134 content::WebContents* web_contents = LoginDisplayHostImpl::default_host()
135 ->GetWebUILoginView()
136 ->GetWebContents();
137 captive_portal_window_proxy_.reset(new CaptivePortalWindowProxy(
138 network_state_informer_.get(), web_contents));
139 }
140 captive_portal_window_proxy_->ShowIfRedirected();
141 }
142
143 NetworkError::UIState ErrorScreen::GetUIState() const {
144 return ui_state_;
145 }
146
147 NetworkError::ErrorState ErrorScreen::GetErrorState() const {
148 return error_state_;
149 }
150
151 OobeUI::Screen ErrorScreen::GetParentScreen() const {
152 return parent_screen_;
153 }
154
155 void ErrorScreen::HideCaptivePortal() {
156 if (captive_portal_window_proxy_.get())
157 captive_portal_window_proxy_->Close();
158 }
159
160 void ErrorScreen::OnViewDestroyed(NetworkErrorView* view) {
161 if (view_ == view)
162 view_ = nullptr;
163 }
164
165 void ErrorScreen::SetUIState(NetworkError::UIState ui_state) {
166 ui_state_ = ui_state;
167 GetContextEditor().SetInteger(kContextKeyUIState,
168 static_cast<int>(ui_state_));
169 }
170
171 void ErrorScreen::SetErrorState(NetworkError::ErrorState error_state,
172 const std::string& network) {
173 error_state_ = error_state;
174 GetContextEditor()
175 .SetInteger(kContextKeyErrorStateCode, static_cast<int>(error_state_))
176 .SetString(kContextKeyErrorStateNetwork, network);
177 }
178
179 void ErrorScreen::SetParentScreen(OobeUI::Screen parent_screen) {
180 parent_screen_ = parent_screen;
181 // Not really used on JS side yet so no need to propagate to screen context.
182 }
183
184 void ErrorScreen::SetHideCallback(const base::Closure& on_hide) {
185 on_hide_callback_.reset(new base::Closure(on_hide));
186 }
187
188 void ErrorScreen::ShowCaptivePortal() {
189 // This call is an explicit user action
190 // i.e. clicking on link so force dialog show.
191 FixCaptivePortal();
192 captive_portal_window_proxy_->Show();
193 }
194
195 void ErrorScreen::ShowConnectingIndicator(bool show) {
196 GetContextEditor().SetBoolean(kContextKeyShowConnectingIndicator, show);
61 } 197 }
62 198
63 void ErrorScreen::OnAuthFailure(const AuthFailure& error) { 199 void ErrorScreen::OnAuthFailure(const AuthFailure& error) {
64 // The only condition leading here is guest mount failure, which should not 200 // The only condition leading here is guest mount failure, which should not
65 // happen in practice. For now, just log an error so this situation is visible 201 // happen in practice. For now, just log an error so this situation is visible
66 // in logs if it ever occurs. 202 // in logs if it ever occurs.
67 NOTREACHED() << "Guest login failed."; 203 NOTREACHED() << "Guest login failed.";
68 guest_login_performer_.reset(); 204 guest_login_performer_.reset();
69 } 205 }
70 206
(...skipping 24 matching lines...) Expand all
95 } 231 }
96 232
97 void ErrorScreen::PolicyLoadFailed() { 233 void ErrorScreen::PolicyLoadFailed() {
98 LOG(FATAL); 234 LOG(FATAL);
99 } 235 }
100 236
101 void ErrorScreen::OnOnlineChecked(const std::string& username, bool success) { 237 void ErrorScreen::OnOnlineChecked(const std::string& username, bool success) {
102 LOG(FATAL); 238 LOG(FATAL);
103 } 239 }
104 240
105 void ErrorScreen::FixCaptivePortal() { 241 void ErrorScreen::DefaultHideCallback() {
106 if (actor_) 242 if (view_)
107 actor_->FixCaptivePortal(); 243 view_->ShowScreen(parent_screen_);
244 SetParentScreen(OobeUI::SCREEN_UNKNOWN);
108 } 245 }
109 246
110 void ErrorScreen::ShowCaptivePortal() { 247 void ErrorScreen::OnConfigureCerts() {
111 if (actor_) 248 gfx::NativeWindow native_window =
112 actor_->ShowCaptivePortal(); 249 LoginDisplayHostImpl::default_host()->GetNativeWindow();
250 CertificateManagerDialog* dialog = new CertificateManagerDialog(
251 ProfileHelper::GetSigninProfile(), NULL, native_window);
252 dialog->Show();
113 } 253 }
114 254
115 void ErrorScreen::HideCaptivePortal() { 255 void ErrorScreen::OnDiagnoseButtonClicked() {
116 if (actor_) 256 Profile* profile = ProfileHelper::GetSigninProfile();
117 actor_->HideCaptivePortal(); 257 ExtensionService* extension_service =
258 extensions::ExtensionSystem::Get(profile)->extension_service();
259
260 std::string extension_id = extension_service->component_loader()->Add(
261 IDR_CONNECTIVITY_DIAGNOSTICS_MANIFEST,
262 base::FilePath(extension_misc::kConnectivityDiagnosticsKioskPath));
263
264 const extensions::Extension* extension =
265 extension_service->GetExtensionById(extension_id, true);
266 OpenApplication(
267 AppLaunchParams(profile, extension, extensions::LAUNCH_CONTAINER_WINDOW,
268 NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL));
269 InitAppSession(profile, extension_id);
270
271 user_manager::UserManager::Get()->SessionStarted();
272
273 LoginDisplayHostImpl::default_host()->Finalize();
118 } 274 }
119 275
120 void ErrorScreen::SetUIState(UIState ui_state) { 276 void ErrorScreen::OnLaunchOobeGuestSession() {
121 if (actor_) 277 DeviceSettingsService::Get()->GetOwnershipStatusAsync(
122 actor_->SetUIState(ui_state); 278 base::Bind(&ErrorScreen::StartGuestSessionAfterOwnershipCheck,
279 weak_factory_.GetWeakPtr()));
123 } 280 }
124 281
125 ErrorScreen::UIState ErrorScreen::GetUIState() const { 282 void ErrorScreen::OnLocalStateErrorPowerwashButtonClicked() {
126 return actor_ ? actor_->ui_state() : UI_STATE_UNKNOWN; 283 chromeos::DBusThreadManager::Get()
284 ->GetSessionManagerClient()
285 ->StartDeviceWipe();
127 } 286 }
128 287
129 void ErrorScreen::SetErrorState(ErrorState error_state, 288 void ErrorScreen::OnRebootButtonClicked() {
130 const std::string& network) { 289 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
131 if (actor_)
132 actor_->SetErrorState(error_state, network);
133 }
134
135 ErrorScreen::ErrorState ErrorScreen::GetErrorState() const {
136 DCHECK(actor_);
137 return actor_->error_state();
138 }
139
140 void ErrorScreen::AllowGuestSignin(bool allow) {
141 if (actor_)
142 actor_->AllowGuestSignin(allow);
143 }
144
145 void ErrorScreen::ShowConnectingIndicator(bool show) {
146 if (actor_)
147 actor_->ShowConnectingIndicator(show);
148 } 290 }
149 291
150 void ErrorScreen::StartGuestSessionAfterOwnershipCheck( 292 void ErrorScreen::StartGuestSessionAfterOwnershipCheck(
151 DeviceSettingsService::OwnershipStatus ownership_status) { 293 DeviceSettingsService::OwnershipStatus ownership_status) {
152 294
153 // Make sure to disallow guest login if it's explicitly disabled. 295 // Make sure to disallow guest login if it's explicitly disabled.
154 CrosSettingsProvider::TrustedStatus trust_status = 296 CrosSettingsProvider::TrustedStatus trust_status =
155 CrosSettings::Get()->PrepareTrustedValues( 297 CrosSettings::Get()->PrepareTrustedValues(
156 base::Bind(&ErrorScreen::StartGuestSessionAfterOwnershipCheck, 298 base::Bind(&ErrorScreen::StartGuestSessionAfterOwnershipCheck,
157 weak_factory_.GetWeakPtr(), 299 weak_factory_.GetWeakPtr(),
(...skipping 18 matching lines...) Expand all
176 } 318 }
177 319
178 if (guest_login_performer_) 320 if (guest_login_performer_)
179 return; 321 return;
180 322
181 guest_login_performer_.reset(new ChromeLoginPerformer(this)); 323 guest_login_performer_.reset(new ChromeLoginPerformer(this));
182 guest_login_performer_->LoginOffTheRecord(); 324 guest_login_performer_->LoginOffTheRecord();
183 } 325 }
184 326
185 } // namespace chromeos 327 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698