From 8bab85c6c6fc5404e36e760c77c2ad27704c3236 Mon Sep 17 00:00:00 2001 From: "avayvod@chromium.org" Date: Wed, 8 Jun 2011 14:34:11 +0000 Subject: [PATCH] Initial implementation of network screen WebUI handler. R=altimofeev@chromium.org BUG=chromium-os:15923 TEST=Manual Review URL: http://codereview.chromium.org/7121013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88332 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/chromeos/login/network_screen_actor.h | 8 +- .../chromeos/login/network_screen_browsertest.cc | 7 +- .../chromeos/login/views_network_screen_actor.cc | 28 +++--- .../chromeos/login/views_network_screen_actor.h | 6 +- .../ui/webui/chromeos/login/eula_screen_handler.cc | 4 +- .../ui/webui/chromeos/login/eula_screen_handler.h | 2 +- .../webui/chromeos/login/network_screen_handler.cc | 102 +++++++++++++++++++++ .../webui/chromeos/login/network_screen_handler.h | 54 +++++++++++ chrome/browser/ui/webui/chromeos/login/oobe_ui.cc | 30 ++---- chrome/chrome_browser.gypi | 6 +- 10 files changed, 196 insertions(+), 51 deletions(-) create mode 100644 chrome/browser/ui/webui/chromeos/login/network_screen_handler.cc create mode 100644 chrome/browser/ui/webui/chromeos/login/network_screen_handler.h diff --git a/chrome/browser/chromeos/login/network_screen_actor.h b/chrome/browser/chromeos/login/network_screen_actor.h index f7801421e7fa..7507e75b3582 100644 --- a/chrome/browser/chromeos/login/network_screen_actor.h +++ b/chrome/browser/chromeos/login/network_screen_actor.h @@ -6,6 +6,8 @@ #define CHROME_BROWSER_CHROMEOS_LOGIN_NETWORK_SCREEN_ACTOR_H_ #pragma once +#include "base/string16.h" + namespace chromeos { class HelpAppLauncher; @@ -48,12 +50,6 @@ class NetworkScreenActor { // Sets whether continue control is enabled. virtual void EnableContinue(bool enabled) = 0; - - // Returns if continue control is enabled. - virtual bool IsContinueEnabled() const = 0; - - // Returns true if we're in the connecting state. - virtual bool IsConnecting() const = 0; }; } // namespace chromeos diff --git a/chrome/browser/chromeos/login/network_screen_browsertest.cc b/chrome/browser/chromeos/login/network_screen_browsertest.cc index 67908ec1fa12..67f565abc35f 100644 --- a/chrome/browser/chromeos/login/network_screen_browsertest.cc +++ b/chrome/browser/chromeos/login/network_screen_browsertest.cc @@ -17,6 +17,7 @@ #include "chrome/browser/chromeos/login/network_screen.h" #include "chrome/browser/chromeos/login/network_selection_view.h" #include "chrome/browser/chromeos/login/view_screen.h" +#include "chrome/browser/chromeos/login/views_network_screen_actor.h" #include "chrome/browser/chromeos/login/wizard_controller.h" #include "chrome/browser/chromeos/login/wizard_in_process_browser_test.h" #include "chrome/browser/chromeos/login/wizard_screen.h" @@ -115,7 +116,9 @@ class NetworkScreenTest : public WizardInProcessBrowserTest { ASSERT_TRUE(network_screen_ != NULL); ASSERT_EQ(controller()->current_screen(), network_screen_); network_screen_->screen_observer_ = mock_screen_observer_.get(); - actor_ = network_screen_->actor(); + // We need a couple of methods defined only in views version. + // TODO(avayvod): Refactor this when WebUI implementation is finished. + actor_ = static_cast(network_screen_->actor()); ASSERT_TRUE(actor_ != NULL); } @@ -140,7 +143,7 @@ class NetworkScreenTest : public WizardInProcessBrowserTest { MockNetworkLibrary* mock_network_library_; scoped_ptr cellular_; NetworkScreen* network_screen_; - NetworkScreenActor* actor_; + ViewsNetworkScreenActor* actor_; private: DISALLOW_COPY_AND_ASSIGN(NetworkScreenTest); diff --git a/chrome/browser/chromeos/login/views_network_screen_actor.cc b/chrome/browser/chromeos/login/views_network_screen_actor.cc index 14702d71ba48..31946523126d 100644 --- a/chrome/browser/chromeos/login/views_network_screen_actor.cc +++ b/chrome/browser/chromeos/login/views_network_screen_actor.cc @@ -59,6 +59,20 @@ bool ViewsNetworkScreenActor::IsErrorShown() const { return bubble_ != NULL; } +bool ViewsNetworkScreenActor::IsContinueEnabled() const { + DCHECK(view()); + if (view()) + return view()->IsContinueEnabled(); + return false; +} + +bool ViewsNetworkScreenActor::IsConnecting() const { + DCHECK(view()); + if (view()) + return view()->IsConnecting(); + return false; +} + //////////////////////////////////////////////////////////////////////////////// // ViewsNetworkScreenActor, NetworkScreenActor implementation: void ViewsNetworkScreenActor::PrepareToShow() { @@ -114,20 +128,6 @@ void ViewsNetworkScreenActor::EnableContinue(bool enabled) { view()->EnableContinue(enabled); } -bool ViewsNetworkScreenActor::IsContinueEnabled() const { - DCHECK(view()); - if (view()) - return view()->IsContinueEnabled(); - return false; -} - -bool ViewsNetworkScreenActor::IsConnecting() const { - DCHECK(view()); - if (view()) - return view()->IsConnecting(); - return false; -} - /////////////////////////////////////////////////////////////////////////////// // views::ButtonListener implementation: diff --git a/chrome/browser/chromeos/login/views_network_screen_actor.h b/chrome/browser/chromeos/login/views_network_screen_actor.h index 6c223f259c14..0505e9691238 100644 --- a/chrome/browser/chromeos/login/views_network_screen_actor.h +++ b/chrome/browser/chromeos/login/views_network_screen_actor.h @@ -47,8 +47,6 @@ class ViewsNetworkScreenActor : public ViewScreen, bool connecting, const string16& network_id); virtual void EnableContinue(bool enabled); - virtual bool IsContinueEnabled() const; - virtual bool IsConnecting() const; // views::ButtonListener implementation: virtual void ButtonPressed(views::Button* sender, const views::Event& event); @@ -66,6 +64,10 @@ class ViewsNetworkScreenActor : public ViewScreen, return &keyboard_switch_menu_; } + // For tests. + virtual bool IsContinueEnabled() const; + virtual bool IsConnecting() const; + private: // Overridden views::BubbleDelegate. virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape); diff --git a/chrome/browser/ui/webui/chromeos/login/eula_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/eula_screen_handler.cc index e6faf4543fbd..c29fce27b0dc 100644 --- a/chrome/browser/ui/webui/chromeos/login/eula_screen_handler.cc +++ b/chrome/browser/ui/webui/chromeos/login/eula_screen_handler.cc @@ -59,6 +59,8 @@ void EulaScreenHandler::RegisterMessages() { } void EulaScreenHandler::OnExit(const ListValue* args) { + DCHECK(args->GetSize() == 2); + bool accepted = false; if (!args->GetBoolean(0, &accepted)) NOTREACHED(); @@ -67,8 +69,6 @@ void EulaScreenHandler::OnExit(const ListValue* args) { if (!args->GetBoolean(1, &is_usage_stats_checked)) NOTREACHED(); - DCHECK(args->GetSize() == 2); - if (!delegate_) return; diff --git a/chrome/browser/ui/webui/chromeos/login/eula_screen_handler.h b/chrome/browser/ui/webui/chromeos/login/eula_screen_handler.h index 97330711d970..67d9e1606fcc 100644 --- a/chrome/browser/ui/webui/chromeos/login/eula_screen_handler.h +++ b/chrome/browser/ui/webui/chromeos/login/eula_screen_handler.h @@ -15,7 +15,7 @@ class ListValue; namespace chromeos { -// WebUI implementation of the EulaScreenActor. It is used to interract +// WebUI implementation of EulaScreenActor. It is used to interact // with the eula part of the JS page. class EulaScreenHandler : public EulaScreenActor, public OobeMessageHandler { diff --git a/chrome/browser/ui/webui/chromeos/login/network_screen_handler.cc b/chrome/browser/ui/webui/chromeos/login/network_screen_handler.cc new file mode 100644 index 000000000000..7161af1167ca --- /dev/null +++ b/chrome/browser/ui/webui/chromeos/login/network_screen_handler.cc @@ -0,0 +1,102 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/webui/chromeos/login/network_screen_handler.h" + +#include "base/memory/scoped_ptr.h" +#include "base/values.h" +#include "grit/chromium_strings.h" +#include "grit/generated_resources.h" +#include "ui/base/l10n/l10n_util.h" + +namespace chromeos { + +NetworkScreenHandler::NetworkScreenHandler() + : screen_(NULL) { +} + +NetworkScreenHandler::~NetworkScreenHandler() { + ClearErrors(); +} + +void NetworkScreenHandler::SetDelegate(NetworkScreenActor::Delegate* screen) { + screen_ = screen; +} + +void NetworkScreenHandler::PrepareToShow() { +} + +void NetworkScreenHandler::Show() { + scoped_ptr value(Value::CreateIntegerValue(0)); + web_ui_->CallJavascriptFunction("cr.ui.Oobe.toggleStep", *value); +} + +void NetworkScreenHandler::Hide() { +} + +void NetworkScreenHandler::ShowError(const string16& message) { + // scoped_ptr message_value(Value::CreateStringValue(message)); + // web_ui_->CallJavascriptFunction("cr.ui.Oobe.showError", *message_value); +} + +void NetworkScreenHandler::ClearErrors() { + // web_ui_->CallJavascriptFunction("cr.ui.Oobe.clearErrors"); +} + +void NetworkScreenHandler::ShowConnectingStatus( + bool connecting, + const string16& network_id) { + // string16 connecting_label = + // l10n_util::GetStringFUTF16(IDS_NETWORK_SELECTION_CONNECTING, + // network_id); + // scoped_ptr connecting_value(Value::CreateBooleanValue(connecting)); + // scoped_ptr network_id_value(Value::CreateStringValue(network_id)); + // scoped_ptr connecting_label_value( + // Value::CreateStringValue(connecting_label)); + // web_ui_->CallJavascriptFunction("cr.ui.Oobe.showConnectingStatus", + // *connecting_value, + // *network_id_value, + // *connecting_label_value); +} + +void NetworkScreenHandler::EnableContinue(bool enabled) { + // scoped_ptr enabled_value(Value::CreateBooleanValue(enabled)); + // web_ui_->CallJavascriptFunction("cr.ui.Oobe.enableContinue", + // *enabled_value); +} + +void NetworkScreenHandler::GetLocalizedSettings( + DictionaryValue* localized_strings) { + localized_strings->SetString("networkScreenTitle", + l10n_util::GetStringFUTF16( + IDS_WELCOME_SCREEN_TITLE, + l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); + localized_strings->SetString("selectLanguage", + l10n_util::GetStringUTF16(IDS_LANGUAGE_SELECTION_SELECT)); + localized_strings->SetString("selectKeyboard", + l10n_util::GetStringUTF16(IDS_KEYBOARD_SELECTION_SELECT)); + localized_strings->SetString("selectNetwork", + l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_SELECT)); + localized_strings->SetString("proxySettings", + l10n_util::GetStringUTF16(IDS_OPTIONS_PROXIES_CONFIGURE_BUTTON)); + localized_strings->SetString("continueButton", + l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_CONTINUE_BUTTON)); +} + +void NetworkScreenHandler::Initialize() { + // TODO(avayvod): Set necessary data. + // TODO(avayvod): Initialize languages, keyboards and networks lists. +} + +void NetworkScreenHandler::RegisterMessages() { + web_ui_->RegisterMessageCallback("networkOnExit", + NewCallback(this, &NetworkScreenHandler::OnExit)); +} + +void NetworkScreenHandler::OnExit(const ListValue* args) { + ClearErrors(); + screen_->OnContinuePressed(); +} + +} // namespace chromeos diff --git a/chrome/browser/ui/webui/chromeos/login/network_screen_handler.h b/chrome/browser/ui/webui/chromeos/login/network_screen_handler.h new file mode 100644 index 000000000000..c198a5042383 --- /dev/null +++ b/chrome/browser/ui/webui/chromeos/login/network_screen_handler.h @@ -0,0 +1,54 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_SCREEN_HANDLER_H_ +#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_SCREEN_HANDLER_H_ +#pragma once + +#include "chrome/browser/chromeos/login/network_screen_actor.h" +#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" +#include "content/browser/webui/web_ui.h" + +class ListValue; + +namespace chromeos { + +// WebUI implementation of NetworkScreenActor. It is used to interact with +// the welcome screen (part of the page) of the OOBE. +class NetworkScreenHandler : public NetworkScreenActor, + public OobeMessageHandler { + public: + NetworkScreenHandler(); + virtual ~NetworkScreenHandler(); + + // NetworkScreenActor implementation: + virtual void SetDelegate(NetworkScreenActor::Delegate* screen); + virtual void PrepareToShow(); + virtual void Show(); + virtual void Hide(); + virtual void ShowError(const string16& message); + virtual void ClearErrors(); + virtual void ShowConnectingStatus(bool connecting, + const string16& network_id); + virtual void EnableContinue(bool enabled); + + // OobeMessageHandler implementation: + virtual void GetLocalizedSettings(DictionaryValue* localized_strings); + virtual void Initialize(); + + // WebUIMessageHandler implementation: + virtual void RegisterMessages(); + + private: + // Handles moving off the screen. + void OnExit(const ListValue* args); + + NetworkScreenActor::Delegate* screen_; + + DISALLOW_COPY_AND_ASSIGN(NetworkScreenHandler); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_NETWORK_SCREEN_HANDLER_H_ diff --git a/chrome/browser/ui/webui/chromeos/login/oobe_ui.cc b/chrome/browser/ui/webui/chromeos/login/oobe_ui.cc index aa2f47d84708..5ab9f6e1c022 100644 --- a/chrome/browser/ui/webui/chromeos/login/oobe_ui.cc +++ b/chrome/browser/ui/webui/chromeos/login/oobe_ui.cc @@ -7,18 +7,17 @@ #include #include "base/logging.h" +#include "base/memory/ref_counted_memory.h" #include "base/values.h" #include "chrome/browser/chromeos/login/wizard_controller.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/webui/chrome_url_data_manager.h" #include "chrome/browser/ui/webui/chromeos/login/eula_screen_handler.h" +#include "chrome/browser/ui/webui/chromeos/login/network_screen_handler.h" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/url_constants.h" #include "content/browser/tab_contents/tab_contents.h" #include "grit/browser_resources.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" namespace { @@ -115,22 +114,6 @@ CoreOobeHandler::~CoreOobeHandler() { } void CoreOobeHandler::GetLocalizedSettings(DictionaryValue* localized_strings) { - // OOBE title is not actually seen in UI, use title of the welcome screen. - // TODO(altimofeev): move the strings to the corresponding handlers, when - // they will be ready. - localized_strings->SetString("title", - l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_TITLE)); - localized_strings->SetString("welcomeScreenTitle", - l10n_util::GetStringFUTF16(IDS_WELCOME_SCREEN_TITLE, - l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); - localized_strings->SetString("languageSelect", - l10n_util::GetStringUTF16(IDS_LANGUAGE_SELECTION_SELECT)); - localized_strings->SetString("keyboardSelect", - l10n_util::GetStringUTF16(IDS_KEYBOARD_SELECTION_SELECT)); - localized_strings->SetString("networkSelect", - l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_SELECT)); - localized_strings->SetString("continue", - l10n_util::GetStringUTF16(IDS_NETWORK_SELECTION_CONTINUE_BUTTON)); } void CoreOobeHandler::Initialize() { @@ -156,6 +139,10 @@ OobeUI::OobeUI(TabContents* contents) AddOobeMessageHandler(new CoreOobeHandler(this), localized_strings.get()); + NetworkScreenHandler* network_screen_handler = new NetworkScreenHandler; + network_screen_actor_ = network_screen_handler; + AddOobeMessageHandler(network_screen_handler, localized_strings.get()); + EulaScreenHandler* eula_screen_handler = new EulaScreenHandler; eula_screen_actor_ = eula_screen_handler; AddOobeMessageHandler(eula_screen_handler, localized_strings.get()); @@ -213,10 +200,9 @@ void OobeUI::AddOobeMessageHandler(OobeMessageHandler* handler, } void OobeUI::InitializeHandlers() { - std::vector::iterator iter; // Note, handlers_[0] is a GenericHandler used by the WebUI. - for (iter = handlers_.begin() + 1; iter != handlers_.end(); ++iter) { - (static_cast(*iter))->Initialize(); + for (size_t i = 1; i < handlers_.size(); ++i) { + static_cast(handlers_[i])->Initialize(); } } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 2e00b6e678ff..306cef9dc5c1 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3295,12 +3295,14 @@ 'browser/ui/webui/chromeos/keyboard_overlay_ui.h', 'browser/ui/webui/chromeos/login/eula_screen_handler.cc', 'browser/ui/webui/chromeos/login/eula_screen_handler.h', - 'browser/ui/webui/chromeos/login/oobe_ui.cc', - 'browser/ui/webui/chromeos/login/oobe_ui.h', 'browser/ui/webui/chromeos/login/login_ui.cc', 'browser/ui/webui/chromeos/login/login_ui.h', 'browser/ui/webui/chromeos/login/login_ui_helpers.cc', 'browser/ui/webui/chromeos/login/login_ui_helpers.h', + 'browser/ui/webui/chromeos/login/network_screen_handler.cc', + 'browser/ui/webui/chromeos/login/network_screen_handler.h', + 'browser/ui/webui/chromeos/login/oobe_ui.cc', + 'browser/ui/webui/chromeos/login/oobe_ui.h', 'browser/ui/webui/chromeos/mobile_setup_ui.cc', 'browser/ui/webui/chromeos/mobile_setup_ui.h', 'browser/ui/webui/chromeos/proxy_settings_ui.cc', -- 2.11.4.GIT