diff options
-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 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 3 | ||||
-rw-r--r-- | chrome/common/notification_type.h | 5 | ||||
-rw-r--r-- | chrome/test/automation/automation_messages_internal.h | 8 | ||||
-rw-r--r-- | chrome/test/automation/automation_proxy.cc | 13 | ||||
-rw-r--r-- | chrome/test/automation/automation_proxy.h | 6 |
15 files changed, 189 insertions, 55 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; } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 45cd438..48e732d 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -162,6 +162,7 @@ 'browser/automation/automation_extension_function.cc', 'browser/automation/automation_profile_impl.cc', 'browser/automation/automation_profile_impl.h', + 'browser/automation/automation_provider_chromeos.cc', 'browser/automation/automation_provider_gtk.cc', 'browser/automation/automation_provider_mac.mm', 'browser/automation/automation_provider_views.cc', @@ -2288,7 +2289,7 @@ }], ['chromeos==0', { 'sources/': [ - ['exclude', '^browser/chromeos'], + ['exclude', '^browser/chromeos'], ], }], ['OS=="linux"', { diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h index 2d288c9..326e2d9 100644 --- a/chrome/common/notification_type.h +++ b/chrome/common/notification_type.h @@ -867,6 +867,11 @@ class NotificationType { #if defined(OS_CHROMEOS) // Sent when a chromium os user logs in. LOGIN_USER_CHANGED, + + // Sent when a chromium os user attempts to log in. The source is + // GoogleAuthenticator and the details are in + // AuthenticationNotificationDetails. + LOGIN_AUTHENTICATION, #endif // Count (must be last) ---------------------------------------------------- diff --git a/chrome/test/automation/automation_messages_internal.h b/chrome/test/automation/automation_messages_internal.h index ddd9eba..26aabfc 100644 --- a/chrome/test/automation/automation_messages_internal.h +++ b/chrome/test/automation/automation_messages_internal.h @@ -1222,4 +1222,12 @@ IPC_BEGIN_MESSAGES(Automation) ContentSetting /* setting */, bool /* success */) +#if defined(OS_CHROMEOS) + // Logs in through the browser's login wizard if available. + IPC_SYNC_MESSAGE_ROUTED2_1(AutomationMsg_LoginWithUserAndPass, + std::string /* username*/, + std::string /* password*/, + bool /* Whether successful*/) +#endif + IPC_END_MESSAGES(Automation) diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc index 7c29ac4..d03bc4d 100644 --- a/chrome/test/automation/automation_proxy.cc +++ b/chrome/test/automation/automation_proxy.cc @@ -472,7 +472,7 @@ bool AutomationProxy::Send(IPC::Message* message) { bool AutomationProxy::SendWithTimeout(IPC::Message* message, int timeout, bool* is_timeout) { - //DCHECK_EQ(listener_thread_id_, PlatformThread::CurrentId()); + // DCHECK_EQ(listener_thread_id_, PlatformThread::CurrentId()); if (is_timeout) *is_timeout = false; @@ -557,3 +557,14 @@ void AutomationProxy::ResetChannel() { tracker_->put_channel(NULL); } +#if defined(OS_CHROMEOS) +bool AutomationProxy::LoginWithUserAndPass(const std::string& username, + const std::string& password) { + bool success; + bool sent = Send(new AutomationMsg_LoginWithUserAndPass(0, username, + password, + &success)); + // If message sending unsuccessful or test failed, return false. + return sent && success; +} +#endif diff --git a/chrome/test/automation/automation_proxy.h b/chrome/test/automation/automation_proxy.h index d012d01..c1f1e46 100644 --- a/chrome/test/automation/automation_proxy.h +++ b/chrome/test/automation/automation_proxy.h @@ -186,6 +186,12 @@ class AutomationProxy : public IPC::Channel::Listener, // Note: Overinstalls will fail. bool InstallExtension(const FilePath& crx_file); +#if defined(OS_CHROMEOS) + // Logs in through the Chrome OS login wizard with given |username| + // and |password|. Returns true on success. + bool LoginWithUserAndPass(const std::string& username, + const std::string& password); +#endif // Returns the ID of the automation IPC channel, so that it can be // passed to the app as a launch parameter. const std::string& channel_id() const { return channel_id_; } |