diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-10 04:14:57 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-10 04:14:57 +0000 |
commit | 566a0f768fae66db79d3f5386e1fdc65e4dd6825 (patch) | |
tree | ec95e77dd30668681371b7e010a197fa5e2c127c /chrome/browser | |
parent | 087256b5dedb480c7d2358d590f164b523726e1f (diff) | |
download | chromium_src-566a0f768fae66db79d3f5386e1fdc65e4dd6825.zip chromium_src-566a0f768fae66db79d3f5386e1fdc65e4dd6825.tar.gz chromium_src-566a0f768fae66db79d3f5386e1fdc65e4dd6825.tar.bz2 |
Lands http://codereview.chromium.org/668105 for sosa:
Changes to add basic automation proxy support to chromeos login wizard
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/783003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41129 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 4 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.h | 8 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider_observers.cc | 27 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider_observers.h | 21 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/login_manager_view.cc | 59 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/login_manager_view.h | 11 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/view_screen.h | 3 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/wizard_controller.cc | 54 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/wizard_controller.h | 20 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/wizard_window.cc | 2 |
10 files changed, 156 insertions, 53 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 6a29cba..47db0d6 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -472,6 +472,10 @@ void AutomationProvider::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(AutomationMsg_BrowserMove, OnBrowserMoved) #endif IPC_MESSAGE_HANDLER(AutomationMsg_SetContentSetting, SetContentSetting) +#if defined(OS_CHROMEOS) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_LoginWithUserAndPass, + LoginWithUserAndPass) +#endif IPC_END_MESSAGE_MAP() } diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index 66b82f7..6d08f38 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -520,6 +520,14 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, ExternalTabContainer* GetExternalTabForHandle(int handle); +#if defined(OS_CHROMEOS) + // Logs in through the Chrome OS Login Wizard with given |username| and + // password. Returns true via |reply_message| on success. + void LoginWithUserAndPass(const std::string& username, + const std::string& password, + IPC::Message* reply_message); +#endif + // Callback for history redirect queries. virtual void OnRedirectQueryComplete( HistoryService::Handle request_handle, diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index 63fcb22..9c5f656 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -18,6 +18,10 @@ #include "chrome/browser/printing/print_job.h" #endif // defined(OS_WIN) +#if defined(OS_CHROMEOS) +#include "chrome/browser/chromeos/login/authentication_notification_details.h" +#endif + InitialLoadObserver::InitialLoadObserver(size_t tab_count, AutomationProvider* automation) : automation_(automation), @@ -716,3 +720,26 @@ void MetricEventDurationObserver::Observe(NotificationType type, durations_[metric_event_duration->event_name] = metric_event_duration->duration_ms; } + +#if defined(OS_CHROMEOS) +LoginManagerObserver::LoginManagerObserver( + AutomationProvider* automation, + IPC::Message* reply_message) + : automation_(automation), + reply_message_(reply_message) { + + registrar_.Add(this, NotificationType::LOGIN_AUTHENTICATION, + NotificationService::AllSources()); +} + +void LoginManagerObserver::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK(type == NotificationType::LOGIN_AUTHENTICATION); + Details<AuthenticationNotificationDetails> auth_details(details); + AutomationMsg_LoginWithUserAndPass::WriteReplyParams(reply_message_, + auth_details->success()); + automation_->Send(reply_message_); + delete this; +} +#endif diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h index d5411e5..79c824d 100644 --- a/chrome/browser/automation/automation_provider_observers.h +++ b/chrome/browser/automation/automation_provider_observers.h @@ -384,4 +384,25 @@ class MetricEventDurationObserver : public NotificationObserver { DISALLOW_COPY_AND_ASSIGN(MetricEventDurationObserver); }; +#if defined(OS_CHROMEOS) +// Collects LOGIN_AUTHENTICATION notifications and returns +// whether authentication succeeded to the automation provider. +class LoginManagerObserver : public NotificationObserver { + public: + LoginManagerObserver(AutomationProvider* automation, + IPC::Message* reply_message); + + // NotificationObserver interface. + virtual void Observe(NotificationType type, const NotificationSource& source, + const NotificationDetails& details); + + private: + NotificationRegistrar registrar_; + AutomationProvider* automation_; + IPC::Message* reply_message_; + + DISALLOW_COPY_AND_ASSIGN(LoginManagerObserver); +}; +#endif + #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_ diff --git a/chrome/browser/chromeos/login/login_manager_view.cc b/chrome/browser/chromeos/login/login_manager_view.cc index 4a7ab00..2b41847 100644 --- a/chrome/browser/chromeos/login/login_manager_view.cc +++ b/chrome/browser/chromeos/login/login_manager_view.cc @@ -24,6 +24,7 @@ #include "chrome/browser/chromeos/cros/login_library.h" #include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/external_cookie_handler.h" +#include "chrome/browser/chromeos/login/authentication_notification_details.h" #include "chrome/browser/chromeos/login/google_authenticator.h" #include "chrome/browser/chromeos/login/pam_google_authenticator.h" #include "chrome/browser/chromeos/login/rounded_rect_painter.h" @@ -32,6 +33,7 @@ #include "chrome/browser/profile_manager.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/notification_service.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" #include "views/controls/button/native_button.h" @@ -275,6 +277,32 @@ views::View* LoginManagerView::GetContentsView() { return this; } +void LoginManagerView::SetUsername(const std::string& username) { + username_field_->SetText(UTF8ToUTF16(username)); +} + +void LoginManagerView::SetPassword(const std::string& password) { + password_field_->SetText(UTF8ToUTF16(password)); +} + +void LoginManagerView::Login() { + // Disallow 0 size username. + if (username_field_->text().empty()) { + // Return true so that processing ends + return; + } + std::string username = UTF16ToUTF8(username_field_->text()); + // todo(cmasone) Need to sanitize memory used to store password. + std::string password = UTF16ToUTF8(password_field_->text()); + + if (username.find('@') == std::string::npos) { + username += kDefaultDomain; + username_field_->SetText(UTF8ToUTF16(username)); + } + + authenticator_->Authenticate(username, password); +} + // Sign in button causes a login attempt. void LoginManagerView::ButtonPressed( views::Button* sender, const views::Event& event) { @@ -284,6 +312,13 @@ void LoginManagerView::ButtonPressed( void LoginManagerView::OnLoginFailure() { LOG(INFO) << "LoginManagerView: OnLoginFailure()"; NetworkLibrary* network = NetworkLibrary::Get(); + + // Send notification of failure + AuthenticationNotificationDetails details(false); + NotificationService::current()->Notify( + NotificationType::LOGIN_AUTHENTICATION, Source<LoginManagerView>(this), + Details<AuthenticationNotificationDetails>(&details)); + // Check networking after trying to login in case user is // cached locally or the local admin account. if (!network || !CrosLibrary::EnsureLoaded()) @@ -300,6 +335,12 @@ void LoginManagerView::OnLoginSuccess(const std::string& username) { SetupSession(username); UserManager::Get()->UserLoggedIn(username); + // Send notification of success + AuthenticationNotificationDetails details(true); + NotificationService::current()->Notify( + NotificationType::LOGIN_AUTHENTICATION, Source<LoginManagerView>(this), + Details<AuthenticationNotificationDetails>(&details)); + // Now launch the initial browser window. BrowserInit browser_init; const CommandLine& command_line = *CommandLine::ForCurrentProcess(); @@ -328,24 +369,6 @@ void LoginManagerView::SetupSession(const std::string& username) { LoginLibrary::Get()->StartSession(username, ""); } -void LoginManagerView::Login() { - // Disallow 0 size username. - if (username_field_->text().empty()) { - // Return true so that processing ends - return; - } - std::string username = UTF16ToUTF8(username_field_->text()); - // todo(cmasone) Need to sanitize memory used to store password. - std::string password = UTF16ToUTF8(password_field_->text()); - - if (username.find('@') == std::string::npos) { - username += kDefaultDomain; - username_field_->SetText(UTF8ToUTF16(username)); - } - - authenticator_->Authenticate(username, password); -} - void LoginManagerView::ShowError(int error_id) { error_id_ = error_id; error_label_->SetText((error_id_ == -1) diff --git a/chrome/browser/chromeos/login/login_manager_view.h b/chrome/browser/chromeos/login/login_manager_view.h index 8d91a2b..92475b3 100644 --- a/chrome/browser/chromeos/login/login_manager_view.h +++ b/chrome/browser/chromeos/login/login_manager_view.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_MANAGER_VIEW_H_ #include <string> + #include "base/scoped_ptr.h" #include "chrome/browser/chromeos/login/authenticator.h" #include "chrome/browser/chromeos/login/login_status_consumer.h" @@ -44,6 +45,13 @@ class LoginManagerView : public views::View, // Overridden from views::WindowDelegate: virtual views::View* GetContentsView(); + // Setters for textfields. + void SetUsername(const std::string& username); + void SetPassword(const std::string& password); + + // Attempt to login with the current field values. + void Login(); + // Overridden from views::Textfield::Controller // Not thread-safe, by virtue of using SetupSession(). virtual bool HandleKeystroke(views::Textfield* sender, @@ -86,9 +94,6 @@ class LoginManagerView : public views::View, void OnOSVersion(VersionLoader::Handle handle, std::string version); - // Attempt to login with the current field values. - void Login(); - // Shows error message with the specified message id. // -1 stands for no error. void ShowError(int error_id); diff --git a/chrome/browser/chromeos/login/view_screen.h b/chrome/browser/chromeos/login/view_screen.h index 38b5795..33f4ba7 100644 --- a/chrome/browser/chromeos/login/view_screen.h +++ b/chrome/browser/chromeos/login/view_screen.h @@ -29,6 +29,9 @@ class ViewScreen : public WizardScreen { V* view() { return view_; } private: + // For testing automation + friend class AutomationProvider; + V* view_; DISALLOW_COPY_AND_ASSIGN(ViewScreen); diff --git a/chrome/browser/chromeos/login/wizard_controller.cc b/chrome/browser/chromeos/login/wizard_controller.cc index 2504ffb..f0f1696 100644 --- a/chrome/browser/chromeos/login/wizard_controller.cc +++ b/chrome/browser/chromeos/login/wizard_controller.cc @@ -32,6 +32,9 @@ const char kUpdateScreenName[] = "update"; } // namespace +// Initialize default controller. +WizardController* WizardController::default_controller_ = NULL; + // Contents view for wizard's window. Parents screen views and status area // view. class WizardContentsView : public views::View { @@ -97,9 +100,12 @@ class WizardContentsView : public views::View { WizardController::WizardController() : contents_(NULL), current_screen_(NULL) { + DCHECK(default_controller_ == NULL); + default_controller_ = this; } WizardController::~WizardController() { + default_controller_ = NULL; } void WizardController::ShowFirstScreen(const std::string& first_screen_name) { @@ -120,6 +126,30 @@ void WizardController::ShowFirstScreen(const std::string& first_screen_name) { } } +NetworkScreen* WizardController::GetNetworkScreen() { + if (!network_screen_.get()) + network_screen_.reset(new NetworkScreen(this)); + return network_screen_.get(); +} + +LoginScreen* WizardController::GetLoginScreen() { + if (!login_screen_.get()) + login_screen_.reset(new LoginScreen(this)); + return login_screen_.get(); +} + +AccountScreen* WizardController::GetAccountScreen() { + if (!account_screen_.get()) + account_screen_.reset(new AccountScreen(this)); + return account_screen_.get(); +} + +UpdateScreen* WizardController::GetUpdateScreen() { + if (!update_screen_.get()) + update_screen_.reset(new UpdateScreen(this)); + return update_screen_.get(); +} + /////////////////////////////////////////////////////////////////////////////// // WizardController, ExitHandlers: void WizardController::OnLoginSignInSelected() { @@ -149,30 +179,6 @@ void WizardController::InitContents() { contents_->Init(this); } -NetworkScreen* WizardController::GetNetworkScreen() { - if (!network_screen_.get()) - network_screen_.reset(new NetworkScreen(this)); - return network_screen_.get(); -} - -LoginScreen* WizardController::GetLoginScreen() { - if (!login_screen_.get()) - login_screen_.reset(new LoginScreen(this)); - return login_screen_.get(); -} - -AccountScreen* WizardController::GetAccountScreen() { - if (!account_screen_.get()) - account_screen_.reset(new AccountScreen(this)); - return account_screen_.get(); -} - -UpdateScreen* WizardController::GetUpdateScreen() { - if (!update_screen_.get()) - update_screen_.reset(new UpdateScreen(this)); - return update_screen_.get(); -} - void WizardController::OnSwitchLanguage(std::string lang) { // Delete all views that may may reference locale-specific data. SetCurrentScreen(NULL); diff --git a/chrome/browser/chromeos/login/wizard_controller.h b/chrome/browser/chromeos/login/wizard_controller.h index b7d3396..aec0093 100644 --- a/chrome/browser/chromeos/login/wizard_controller.h +++ b/chrome/browser/chromeos/login/wizard_controller.h @@ -32,10 +32,21 @@ class WizardController : public views::WindowDelegate, WizardController(); virtual ~WizardController(); + // Returns the default wizard controller if it has been created. + static WizardController* default_controller() { + return default_controller_; + } + // Shows the first screen defined by |first_screen_name| or by default // if the parameter is empty. void ShowFirstScreen(const std::string& first_screen_name); + // Lazy initializers and getters for screens. + NetworkScreen* GetNetworkScreen(); + LoginScreen* GetLoginScreen(); + AccountScreen* GetAccountScreen(); + UpdateScreen* GetUpdateScreen(); + private: // Exit handlers: void OnLoginSignInSelected(); @@ -65,12 +76,6 @@ class WizardController : public views::WindowDelegate, // Initializes contents view and status area. void InitContents(); - // Lazy initializers and getters for screens. - NetworkScreen* GetNetworkScreen(); - LoginScreen* GetLoginScreen(); - AccountScreen* GetAccountScreen(); - UpdateScreen* GetUpdateScreen(); - // Switches from one screen to another. void SetCurrentScreen(WizardScreen* screen); @@ -86,6 +91,9 @@ class WizardController : public views::WindowDelegate, // Screen that's currently active. WizardScreen* current_screen_; + // Default WizardController. + static WizardController* default_controller_; + DISALLOW_COPY_AND_ASSIGN(WizardController); }; diff --git a/chrome/browser/chromeos/login/wizard_window.cc b/chrome/browser/chromeos/login/wizard_window.cc index ffd7cc1..eaa184a 100644 --- a/chrome/browser/chromeos/login/wizard_window.cc +++ b/chrome/browser/chromeos/login/wizard_window.cc @@ -61,7 +61,6 @@ class WizardWindow : public views::WindowGtk { static WizardWindow* Create(const std::string& first_screen_name, const gfx::Size& size) { WizardController* controller = new WizardController(); - WizardWindow* wizard_window = new WizardWindow(controller); wizard_window->GetNonClientView()->SetFrameView( new WizardNonClientFrameView()); @@ -91,7 +90,6 @@ class WizardWindow : public views::WindowGtk { XSetWindowAttributes attr; attr.cursor = cursor; XChangeWindowAttributes(display, root_window, CWCursor, &attr); - return wizard_window; } |