summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authornkostylev@google.com <nkostylev@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-21 11:41:38 +0000
committernkostylev@google.com <nkostylev@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-21 11:41:38 +0000
commit598b1ff52fea0f167462f5bd92070756b9a65090 (patch)
tree78c61c52493eb325257fc7729689c1c03e5d53b2 /chrome/browser
parentaea31521c26f36447d3a0b71e08da83b830da342 (diff)
downloadchromium_src-598b1ff52fea0f167462f5bd92070756b9a65090.zip
chromium_src-598b1ff52fea0f167462f5bd92070756b9a65090.tar.gz
chromium_src-598b1ff52fea0f167462f5bd92070756b9a65090.tar.bz2
Relanding http://codereview.chromium.org/3044001.
I've guarded all chromium-os specific stuff at register_page_ui.cc with ifdef. Original CL description: Add getUserInfo, getRegistrationUrl message callback for register screen. Restrict chrome://register to OOBE wizard only. Actually delete about:register. BUG= http://crosbug.com/4813 TEST=none Review URL: http://codereview.chromium.org/2825057 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53177 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browser_about_handler.cc17
-rw-r--r--chrome/browser/chromeos/login/wizard_controller.cc5
-rw-r--r--chrome/browser/chromeos/login/wizard_controller.h6
-rw-r--r--chrome/browser/dom_ui/dom_ui_factory.cc2
-rw-r--r--chrome/browser/dom_ui/register_page_ui.cc130
-rw-r--r--chrome/browser/resources/host_registration_page.html26
6 files changed, 166 insertions, 20 deletions
diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc
index f3f324b..14e748f 100644
--- a/chrome/browser/browser_about_handler.cc
+++ b/chrome/browser/browser_about_handler.cc
@@ -114,7 +114,6 @@ const char kSandboxPath[] = "sandbox";
#if defined(OS_CHROMEOS)
const char kNetworkPath[] = "network";
const char kOSCreditsPath[] = "os-credits";
-const char kRegisterProductPath[] = "register";
const char kSysPath[] = "system";
#endif
@@ -141,7 +140,6 @@ const char *kAllAboutPaths[] = {
#if defined(OS_CHROMEOS)
kNetworkPath,
kOSCreditsPath,
- kRegisterProductPath,
kSysPath,
#endif
};
@@ -601,19 +599,6 @@ std::string AboutSandbox() {
}
#endif
-#if defined(OS_CHROMEOS)
-std::string AboutRegisterProduct() {
- static const base::StringPiece register_html(
- ResourceBundle::GetSharedInstance().GetRawDataResource(
- IDR_HOST_REGISTRATION_PAGE_HTML));
-
- // TODO(nkostylev): Embed registration form URL from startup manifest.
- // http://crosbug.com/4645.
-
- return register_html.as_string();
-}
-#endif
-
std::string AboutVersion(DictionaryValue* localized_strings) {
localized_strings->SetString(L"title",
l10n_util::GetString(IDS_ABOUT_VERSION_TITLE));
@@ -908,8 +893,6 @@ void AboutSource::StartDataRequest(const std::string& path_raw,
#if defined(OS_CHROMEOS)
} else if (path == kSysPath) {
response = AboutSys();
- } else if (path == kRegisterProductPath) {
- response = AboutRegisterProduct();
#endif
}
diff --git a/chrome/browser/chromeos/login/wizard_controller.cc b/chrome/browser/chromeos/login/wizard_controller.cc
index 0aaa2ad..c9550ef 100644
--- a/chrome/browser/chromeos/login/wizard_controller.cc
+++ b/chrome/browser/chromeos/login/wizard_controller.cc
@@ -383,6 +383,11 @@ void WizardController::SetCustomization(
customization_.reset(customization);
}
+const chromeos::StartupCustomizationDocument*
+ WizardController::GetCustomization() {
+ return customization_.get();
+}
+
// static
void WizardController::RegisterPrefs(PrefService* local_state) {
local_state->RegisterBooleanPref(kOobeComplete, false);
diff --git a/chrome/browser/chromeos/login/wizard_controller.h b/chrome/browser/chromeos/login/wizard_controller.h
index d5b69b9..25394ff 100644
--- a/chrome/browser/chromeos/login/wizard_controller.h
+++ b/chrome/browser/chromeos/login/wizard_controller.h
@@ -93,6 +93,9 @@ class WizardController : public chromeos::ScreenObserver,
// screen.
WizardScreen* current_screen() const { return current_screen_; }
+ // True if WizardController is in OOBE mode.
+ bool is_oobe() { return is_out_of_box_; }
+
// Overrides observer for testing.
void set_observer(ScreenObserver* observer) { observer_ = observer; }
@@ -101,6 +104,9 @@ class WizardController : public chromeos::ScreenObserver,
void SetCustomization(
const chromeos::StartupCustomizationDocument* customization);
+ // Returns partner startup customization document owned by WizardController.
+ const chromeos::StartupCustomizationDocument* GetCustomization();
+
// Registers OOBE preferences.
static void RegisterPrefs(PrefService* local_state);
diff --git a/chrome/browser/dom_ui/dom_ui_factory.cc b/chrome/browser/dom_ui/dom_ui_factory.cc
index 3dd1a50..f51fe22 100644
--- a/chrome/browser/dom_ui/dom_ui_factory.cc
+++ b/chrome/browser/dom_ui/dom_ui_factory.cc
@@ -17,7 +17,6 @@
#include "chrome/browser/dom_ui/options_ui.h"
#include "chrome/browser/dom_ui/remoting_ui.h"
#include "chrome/browser/dom_ui/plugins_ui.h"
-#include "chrome/browser/dom_ui/register_page_ui.h"
#include "chrome/browser/dom_ui/slideshow_ui.h"
#include "chrome/browser/extensions/extension_dom_ui.h"
#include "chrome/browser/extensions/extensions_service.h"
@@ -33,6 +32,7 @@
#if defined(OS_CHROMEOS)
#include "chrome/browser/dom_ui/filebrowse_ui.h"
#include "chrome/browser/dom_ui/mediaplayer_ui.h"
+#include "chrome/browser/dom_ui/register_page_ui.h"
#endif
const DOMUITypeID DOMUIFactory::kNoDOMUI = NULL;
diff --git a/chrome/browser/dom_ui/register_page_ui.cc b/chrome/browser/dom_ui/register_page_ui.cc
index 7811b21..3cffc7a 100644
--- a/chrome/browser/dom_ui/register_page_ui.cc
+++ b/chrome/browser/dom_ui/register_page_ui.cc
@@ -1,20 +1,38 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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/dom_ui/register_page_ui.h"
+#include <string>
+
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/callback.h"
+#include "base/logging.h"
#include "base/string_piece.h"
+#include "base/utf_string_conversions.h"
+#include "base/values.h"
#include "base/weak_ptr.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/url_constants.h"
#include "grit/browser_resources.h"
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/browser/chromeos/customization_document.h"
+#include "chrome/browser/chromeos/login/wizard_controller.h"
+#include "chrome/browser/chromeos/version_loader.h"
+#endif
+
+namespace {
+// Constant value for os_name sent in setUserInfo.
+const wchar_t kOSName[] = L"ChromeOS";
+} // namespace
+
class RegisterPageUIHTMLSource : public ChromeURLDataManager::DataSource {
public:
RegisterPageUIHTMLSource();
@@ -49,6 +67,28 @@ class RegisterPageHandler : public DOMMessageHandler,
virtual void RegisterMessages();
private:
+ // Handlers for JS DOMUI messages.
+ void HandleGetRegistrationUrl(const Value* value);
+ void HandleGetUserInfo(const Value* value);
+
+#if defined(OS_CHROMEOS)
+ // Callback from chromeos::VersionLoader giving the version.
+ void OnVersion(chromeos::VersionLoader::Handle handle, std::string version);
+#endif
+
+ // Sends message to host registration page with system/user info data.
+ void SendUserInfo();
+
+#if defined(OS_CHROMEOS)
+ // Handles asynchronously loading the version.
+ chromeos::VersionLoader version_loader_;
+#endif
+
+ // Used to request the version.
+ CancelableRequestConsumer version_consumer_;
+
+ std::string version_;
+
DISALLOW_COPY_AND_ASSIGN(RegisterPageHandler);
};
@@ -65,6 +105,16 @@ RegisterPageUIHTMLSource::RegisterPageUIHTMLSource()
void RegisterPageUIHTMLSource::StartDataRequest(const std::string& path,
bool is_off_the_record,
int request_id) {
+ // Make sure that chrome://register is available only during
+ // OOBE wizard lifetime.
+#if defined(OS_CHROMEOS)
+ if (!WizardController::default_controller() &&
+ !WizardController::default_controller()->is_oobe()) {
+ scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes);
+ SendResponse(request_id, empty_bytes);
+ return;
+ }
+
static const base::StringPiece register_html(
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_HOST_REGISTRATION_PAGE_HTML));
@@ -79,6 +129,10 @@ void RegisterPageUIHTMLSource::StartDataRequest(const std::string& path,
html_bytes->data.begin());
SendResponse(request_id, html_bytes);
+#else
+ scoped_refptr<RefCountedBytes> empty_bytes(new RefCountedBytes);
+ SendResponse(request_id, empty_bytes);
+#endif
}
////////////////////////////////////////////////////////////////////////////////
@@ -100,7 +154,79 @@ void RegisterPageHandler::Init() {
}
void RegisterPageHandler::RegisterMessages() {
- // TODO(nkostylev): Register callback messages.
+#if defined(OS_CHROMEOS)
+ dom_ui_->RegisterMessageCallback("getRegistrationUrl",
+ NewCallback(this, &RegisterPageHandler::HandleGetRegistrationUrl));
+ dom_ui_->RegisterMessageCallback("getUserInfo",
+ NewCallback(this, &RegisterPageHandler::HandleGetUserInfo));
+#endif
+}
+
+void RegisterPageHandler::HandleGetRegistrationUrl(const Value* value) {
+#if defined(OS_CHROMEOS)
+ if (WizardController::default_controller() &&
+ WizardController::default_controller()->GetCustomization()) {
+ StringValue url_value(WizardController::default_controller()->
+ GetCustomization()->registration_url());
+ dom_ui_->CallJavascriptFunction(L"setRegistrationUrl", url_value);
+ } else {
+ LOG(ERROR) << "Startup manifest not defined.";
+ }
+#endif
+}
+
+void RegisterPageHandler::HandleGetUserInfo(const Value* value) {
+#if defined(OS_CHROMEOS)
+ if (chromeos::CrosLibrary::Get()->EnsureLoaded()) {
+ version_loader_.GetVersion(
+ &version_consumer_, NewCallback(this,
+ &RegisterPageHandler::OnVersion));
+ } else {
+ LOG(ERROR) << "Error loading cros library.";
+ }
+#endif
+}
+
+#if defined(OS_CHROMEOS)
+void RegisterPageHandler::OnVersion(chromeos::VersionLoader::Handle handle,
+ std::string version) {
+ version_ = version;
+ SendUserInfo();
+}
+#endif
+
+void RegisterPageHandler::SendUserInfo() {
+#if defined(OS_CHROMEOS)
+ DictionaryValue value;
+ // TODO(nkostylev): Extract all available system/user info.
+ // http://crosbug.com/4813
+
+ std::string system_sku;
+ if (WizardController::default_controller() &&
+ WizardController::default_controller()->GetCustomization()) {
+ system_sku = WizardController::default_controller()->
+ GetCustomization()->product_sku();
+ } else {
+ LOG(ERROR) << "Startup manifest not defined.";
+ }
+
+ // Required info.
+ value.SetString(L"system_hwqual", L"hardware qual identifier");
+ value.SetString(L"system_sku", UTF8ToWide(system_sku));
+ value.SetString(L"system_serial", L"serial number");
+ value.SetString(L"os_language",
+ UTF8ToWide(g_browser_process->GetApplicationLocale()));
+ value.SetString(L"os_name", kOSName);
+ value.SetString(L"os_version", UTF8ToWide(version_));
+ value.SetString(L"os_connection", L"connection type");
+ value.SetString(L"user_email", L"");
+
+ // Optional info.
+ value.SetString(L"user_first_name", L"");
+ value.SetString(L"user_last_name", L"");
+
+ dom_ui_->CallJavascriptFunction(L"setUserInfo", value);
+#endif
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/resources/host_registration_page.html b/chrome/browser/resources/host_registration_page.html
index a6cf0b2..101e812 100644
--- a/chrome/browser/resources/host_registration_page.html
+++ b/chrome/browser/resources/host_registration_page.html
@@ -3,6 +3,32 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Register your computer with Google</title>
+<script>
+
+document.addEventListener('DOMContentLoaded', load);
+
+function load() {
+ chrome.send('getRegistrationUrl', []);
+}
+
+function $(o) {
+ return document.getElementById(o);
+}
+
+function setRegistrationUrl(url) {
+ // TODO(nkostylev): Load URL in iframe.
+}
+
+// Called when document has been loaded in an iframe.
+function onFormLoaded() {
+ chrome.send('getUserInfo', []);
+}
+
+function setUserInfo(data) {
+ // TODO(nkostylev): Pass system/user data to registration iframe.
+}
+
+</script>
</head>
<body>
<!-- TODO(nkostylev): Redirect to cros://register/[success|skipped]. -->