summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/customization_document.cc135
-rw-r--r--chrome/browser/chromeos/customization_document.h115
-rw-r--r--chrome/browser/chromeos/customization_document_unittest.cc103
-rw-r--r--chrome/browser/chromeos/login/wizard_controller.cc21
-rw-r--r--chrome/browser/chromeos/login/wizard_controller.h9
-rw-r--r--chrome/browser/chromeos/testdata/startup_manifest.json22
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/common/chrome_switches.cc5
-rw-r--r--chrome/common/chrome_switches.h1
10 files changed, 414 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/customization_document.cc b/chrome/browser/chromeos/customization_document.cc
new file mode 100644
index 0000000..883313f
--- /dev/null
+++ b/chrome/browser/chromeos/customization_document.cc
@@ -0,0 +1,135 @@
+// 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/chromeos/customization_document.h"
+
+#include <string>
+
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/json/json_reader.h"
+#include "base/logging.h"
+#include "base/string_util.h"
+#include "base/values.h"
+
+// Manifest attributes names.
+
+namespace {
+
+const wchar_t kVersionAttr[] = L"version";
+const wchar_t kProductSkuAttr[] = L"product_sku";
+const wchar_t kInitialLocaleAttr[] = L"initial_locale";
+const wchar_t kBackgroundColorAttr[] = L"background_color";
+const wchar_t kRegistrationUrlAttr[] = L"registration_url";
+const wchar_t kSetupContentAttr[] = L"setup_content";
+const wchar_t kContentLocaleAttr[] = L"content_locale";
+const wchar_t kHelpPageAttr[] = L"help_page";
+const wchar_t kEulaPageAttr[] = L"eula_page";
+const wchar_t kAppMenuAttr[] = L"app_menu";
+const wchar_t kInitialStartPageAttr[] = L"initial_start_page";
+const wchar_t kSectionTitleAttr[] = L"section_title";
+const wchar_t kWebAppsAttr[] = L"web_apps";
+const wchar_t kSupportPageAttr[] = L"support_page";
+const wchar_t kExtensionsAttr[] = L"extensions";
+
+const char kAcceptedManifestVersion[] = "1.0";
+
+} // anonymous namespace
+
+namespace chromeos {
+
+// CustomizationDocument implementation.
+
+bool CustomizationDocument::LoadManifestFromFile(
+ const FilePath& manifest_path) {
+ std::string manifest;
+ bool read_success = file_util::ReadFileToString(manifest_path, &manifest);
+ if (!read_success) {
+ return false;
+ }
+ return LoadManifestFromString(manifest);
+}
+
+bool CustomizationDocument::LoadManifestFromString(
+ const std::string& manifest) {
+ scoped_ptr<Value> root(base::JSONReader::Read(manifest, true));
+ DCHECK(root.get() != NULL);
+ if (root.get() == NULL)
+ return false;
+ DCHECK(root->GetType() == Value::TYPE_DICTIONARY);
+ return ParseFromJsonValue(static_cast<DictionaryValue*>(root.get()));
+}
+
+bool CustomizationDocument::ParseFromJsonValue(const DictionaryValue* root) {
+ // Partner customization manifests share only one required field -
+ // version string.
+ bool result = root->GetString(kVersionAttr, &version_);
+ return result && version_ == kAcceptedManifestVersion;
+}
+
+// StartupCustomizationDocument implementation.
+
+bool StartupCustomizationDocument::ParseFromJsonValue(
+ const DictionaryValue* root) {
+ if (!CustomizationDocument::ParseFromJsonValue(root))
+ return false;
+ // Rquired fields.
+ if (!root->GetString(kProductSkuAttr, &product_sku_))
+ return false;
+ // Optional fields.
+ root->GetString(kInitialLocaleAttr, &initial_locale_);
+ std::string background_color_string;
+ root->GetString(kBackgroundColorAttr, &background_color_string);
+ if (!background_color_string.empty()) {
+ if (background_color_string[0] == '#') {
+ background_color_ = static_cast<SkColor>(
+ 0xff000000 | HexStringToInt(background_color_string.substr(1)));
+ } else {
+ // Literal color constants are not supported yet.
+ return false;
+ }
+ }
+ root->GetString(kRegistrationUrlAttr, &registration_url_);
+ ListValue* setup_content_value = NULL;
+ root->GetList(kSetupContentAttr, &setup_content_value);
+ if (setup_content_value != NULL) {
+ for (ListValue::const_iterator iter = setup_content_value->begin();
+ iter != setup_content_value->end();
+ ++iter) {
+ const DictionaryValue* dict = NULL;
+ dict = static_cast<const DictionaryValue*>(*iter);
+ DCHECK(dict->GetType() == Value::TYPE_DICTIONARY);
+ std::string content_locale;
+ if (!dict->GetString(kContentLocaleAttr, &content_locale))
+ return false;
+ SetupContent content;
+ if (!dict->GetString(kHelpPageAttr, &content.help_page_path))
+ return false;
+ if (!dict->GetString(kEulaPageAttr, &content.eula_page_path))
+ return false;
+ setup_content_[content_locale] = content;
+ }
+ }
+ return true;
+}
+
+const StartupCustomizationDocument::SetupContent*
+ StartupCustomizationDocument::GetSetupContent(
+ const std::string& locale) const {
+ SetupContentMap::const_iterator content_iter = setup_content_.find(locale);
+ if (content_iter != setup_content_.end()) {
+ return &content_iter->second;
+ }
+ return NULL;
+}
+
+// ServicesCustomizationDocument implementation.
+
+bool ServicesCustomizationDocument::ParseFromJsonValue(
+ const DictionaryValue* root) {
+ return CustomizationDocument::ParseFromJsonValue(root);
+ // TODO(denisromanov): implement.
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/customization_document.h b/chrome/browser/chromeos/customization_document.h
new file mode 100644
index 0000000..ce9d68a
--- /dev/null
+++ b/chrome/browser/chromeos/customization_document.h
@@ -0,0 +1,115 @@
+// 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.
+
+#ifndef CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_
+#define CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_
+
+#include <list>
+#include <map>
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/scoped_ptr.h"
+#include "third_party/skia/include/core/SkColor.h"
+
+class DictionaryValue;
+class FilePath;
+
+namespace chromeos {
+
+class CustomizationDocument {
+ public:
+ CustomizationDocument() {}
+ virtual ~CustomizationDocument() {}
+
+ virtual bool LoadManifestFromFile(const FilePath& manifest_path);
+ virtual bool LoadManifestFromString(const std::string& manifest);
+
+ const std::string& version() const { return version_; }
+
+ protected:
+ // Parses manifest's attributes from the JSON dictionary value.
+ virtual bool ParseFromJsonValue(const DictionaryValue* root);
+
+ // Manifest version string.
+ std::string version_;
+
+ DISALLOW_COPY_AND_ASSIGN(CustomizationDocument);
+};
+
+class StartupCustomizationDocument : public CustomizationDocument {
+ public:
+ struct SetupContent {
+ SetupContent() {}
+ SetupContent(const std::string& help_page_path,
+ const std::string& eula_page_path)
+ : help_page_path(help_page_path),
+ eula_page_path(eula_page_path) {}
+
+ // Partner's help page for specific locale.
+ std::string help_page_path;
+ // Partner's EULA for specific locale.
+ std::string eula_page_path;
+ };
+
+ typedef std::map<std::string, SetupContent> SetupContentMap;
+
+ StartupCustomizationDocument() {}
+
+ const std::string& product_sku() const { return product_sku_; }
+ const std::string& initial_locale() const { return initial_locale_; }
+ SkColor background_color() const { return background_color_; }
+ const std::string& registration_url() const { return registration_url_; }
+
+ const SetupContent* GetSetupContent(const std::string& locale) const;
+
+ protected:
+ virtual bool ParseFromJsonValue(const DictionaryValue* root);
+
+ // Product SKU.
+ std::string product_sku_;
+
+ // Initial locale for the OOBE wizard.
+ std::string initial_locale_;
+
+ // OOBE wizard and login screen background color.
+ SkColor background_color_;
+
+ // Partner's product registration page URL.
+ std::string registration_url_;
+
+ // Setup content for different locales.
+ SetupContentMap setup_content_;
+
+ DISALLOW_COPY_AND_ASSIGN(StartupCustomizationDocument);
+};
+
+class ServicesCustomizationDocument : public CustomizationDocument {
+ public:
+ ServicesCustomizationDocument() {}
+
+ protected:
+ virtual bool ParseFromJsonValue(const DictionaryValue* root);
+
+ // Partner's welcome page that is opened right after the OOBE.
+ std::string initial_start_page_;
+
+ // Title for the partner's apps section in apps menu.
+ std::string app_menu_section_title_;
+
+ // Partner's featured apps URLs.
+ std::list<std::string> web_apps_;
+
+ // Partner's featured extensions URLs.
+ std::list<std::string> extensions_;
+
+ // Partner's apps section support page URL.
+ std::string app_menu_support_page_url_;
+
+ DISALLOW_COPY_AND_ASSIGN(ServicesCustomizationDocument);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_
diff --git a/chrome/browser/chromeos/customization_document_unittest.cc b/chrome/browser/chromeos/customization_document_unittest.cc
new file mode 100644
index 0000000..c57a0c9
--- /dev/null
+++ b/chrome/browser/chromeos/customization_document_unittest.cc
@@ -0,0 +1,103 @@
+// 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/chromeos/customization_document.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+const char kGoodStartupManifest[] =
+ "{"
+ " \"version\": \"1.0\","
+ " \"product_sku\" : \"SKU\","
+ " \"initial_locale\" : \"en_US\","
+ " \"background_color\" : \"#880088\","
+ " \"registration_url\" : \"http://www.google.com\","
+ " \"setup_content\" : ["
+ " {"
+ " \"content_locale\" : \"en_US\","
+ " \"help_page\" : \"setup_content/en_US/help.html\","
+ " \"eula_page\" : \"setup_content/en_US/eula.html\","
+ " },"
+ " {"
+ " \"content_locale\" : \"ru\","
+ " \"help_page\" : \"setup_content/ru/help.html\","
+ " \"eula_page\" : \"setup_content/ru/eula.html\","
+ " },"
+ " ]"
+ "}";
+
+const char kBadStartupManifest1[] = "{}";
+const char kBadStartupManifest2[] = "{ \"version\" : \"1.0\" }";
+const char kBadStartupManifest3[] = "{"
+ " \"version\" : \"0.0\","
+ " \"product_sku\" : \"SKU\","
+ "}";
+
+const char kBadStartupManifest4[] = "{"
+ " \"version\" : \"1.0\","
+ " \"product_sku\" : \"SKU\","
+ " \"setup_content\" : ["
+ " {"
+ " \"help_page\" : \"setup_content/en_US/help.html\","
+ " \"eula_page\" : \"setup_content/en_US/eula.html\","
+ " },"
+ " ]"
+ "}";
+
+const char kBadStartupManifest5[] = "{"
+ " \"version\" : \"1.0\","
+ " \"product_sku\" : \"SKU\","
+ " \"setup_content\" : ["
+ " {"
+ " \"content_locale\" : \"en_US\","
+ " \"eula_page\" : \"setup_content/en_US/eula.html\","
+ " },"
+ " ]"
+ "}";
+
+
+
+} // anonymous namespace
+
+class StartupCustomizationDocumentTest : public testing::Test {
+ public:
+ chromeos::StartupCustomizationDocument customization_;
+};
+
+TEST_F(StartupCustomizationDocumentTest, LoadBadStartupManifestFromString) {
+ bool result = false;
+ result = customization_.LoadManifestFromString(kBadStartupManifest1);
+ EXPECT_EQ(result, false);
+ result = customization_.LoadManifestFromString(kBadStartupManifest2);
+ EXPECT_EQ(result, false);
+ result = customization_.LoadManifestFromString(kBadStartupManifest3);
+ EXPECT_EQ(result, false);
+ result = customization_.LoadManifestFromString(kBadStartupManifest4);
+ EXPECT_EQ(result, false);
+ result = customization_.LoadManifestFromString(kBadStartupManifest5);
+ EXPECT_EQ(result, false);
+}
+
+TEST_F(StartupCustomizationDocumentTest, LoadGoodStartupManifestFromString) {
+ bool result = false;
+ result = customization_.LoadManifestFromString(kGoodStartupManifest);
+ EXPECT_EQ(result, true);
+ EXPECT_EQ(customization_.version(), "1.0");
+ EXPECT_EQ(customization_.product_sku(), "SKU");
+ EXPECT_EQ(customization_.initial_locale(), "en_US");
+ EXPECT_EQ(customization_.background_color(),
+ SkColorSetRGB(0x88, 0x00, 0x88));
+ EXPECT_EQ(customization_.registration_url(), "http://www.google.com");
+
+ EXPECT_EQ(customization_.GetSetupContent("en_US")->help_page_path,
+ "setup_content/en_US/help.html");
+ EXPECT_EQ(customization_.GetSetupContent("en_US")->eula_page_path,
+ "setup_content/en_US/eula.html");
+ EXPECT_EQ(customization_.GetSetupContent("ru")->help_page_path,
+ "setup_content/ru/help.html");
+ EXPECT_EQ(customization_.GetSetupContent("ru")->eula_page_path,
+ "setup_content/ru/eula.html");
+}
diff --git a/chrome/browser/chromeos/login/wizard_controller.cc b/chrome/browser/chromeos/login/wizard_controller.cc
index aba9c94..7f92d0e 100644
--- a/chrome/browser/chromeos/login/wizard_controller.cc
+++ b/chrome/browser/chromeos/login/wizard_controller.cc
@@ -16,6 +16,7 @@
#include "base/logging.h" // For NOTREACHED.
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/login_library.h"
+#include "chrome/browser/chromeos/customization_document.h"
#include "chrome/browser/chromeos/login/account_screen.h"
#include "chrome/browser/chromeos/login/background_view.h"
#include "chrome/browser/chromeos/login/existing_user_controller.h"
@@ -163,6 +164,7 @@ WizardController* WizardController::default_controller_ = NULL;
///////////////////////////////////////////////////////////////////////////////
// WizardController, public:
+
WizardController::WizardController()
: widget_(NULL),
background_widget_(NULL),
@@ -298,6 +300,11 @@ void WizardController::SetStatusAreaVisible(bool visible) {
}
}
+void WizardController::SetCustomization(
+ const chromeos::StartupCustomizationDocument* customization) {
+ customization_.reset(customization);
+}
+
///////////////////////////////////////////////////////////////////////////////
// WizardController, ExitHandlers:
void WizardController::OnLoginSignInSelected() {
@@ -474,7 +481,21 @@ void ShowLoginWizard(const std::string& first_screen_name,
}
}
+ // Load partner customization startup manifest if needed.
+ scoped_ptr<chromeos::StartupCustomizationDocument> customization;
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kStartupManifest)) {
+ customization.reset(new chromeos::StartupCustomizationDocument());
+ FilePath manifest_path =
+ CommandLine::ForCurrentProcess()->GetSwitchValuePath(
+ switches::kStartupManifest);
+ bool manifest_loaded = customization->LoadManifestFromFile(manifest_path);
+ DCHECK(manifest_loaded) << manifest_path.value();
+ }
+
+ // Create and show the wizard.
WizardController* controller = new WizardController();
+ controller->SetCustomization(customization.release());
controller->ShowBackground(screen_bounds);
controller->Init(first_screen_name, screen_bounds, true);
controller->Show();
diff --git a/chrome/browser/chromeos/login/wizard_controller.h b/chrome/browser/chromeos/login/wizard_controller.h
index d66ed15..25d3939 100644
--- a/chrome/browser/chromeos/login/wizard_controller.h
+++ b/chrome/browser/chromeos/login/wizard_controller.h
@@ -22,6 +22,7 @@ class BackgroundView;
class LoginScreen;
class NetworkScreen;
class UpdateScreen;
+class StartupCustomizationDocument;
}
namespace gfx {
@@ -87,6 +88,11 @@ class WizardController : public chromeos::ScreenObserver,
// Overrides observer for testing.
void set_observer(ScreenObserver* observer) { observer_ = observer; }
+ // Sets partner startup customization. WizardController takes ownership
+ // of the document object.
+ void SetCustomization(
+ const chromeos::StartupCustomizationDocument* customization);
+
static const char kNetworkScreenName[];
static const char kLoginScreenName[];
static const char kAccountScreenName[];
@@ -156,6 +162,9 @@ class WizardController : public chromeos::ScreenObserver,
// Default WizardController.
static WizardController* default_controller_;
+ // Partner startup customizations.
+ scoped_ptr<const chromeos::StartupCustomizationDocument> customization_;
+
FRIEND_TEST(WizardControllerFlowTest, ControlFlowErrorNetwork);
FRIEND_TEST(WizardControllerFlowTest, ControlFlowErrorUpdate);
FRIEND_TEST(WizardControllerFlowTest, ControlFlowLanguageOnLogin);
diff --git a/chrome/browser/chromeos/testdata/startup_manifest.json b/chrome/browser/chromeos/testdata/startup_manifest.json
new file mode 100644
index 0000000..ba1faac
--- /dev/null
+++ b/chrome/browser/chromeos/testdata/startup_manifest.json
@@ -0,0 +1,22 @@
+{
+ // Required.
+ "version": "1.0",
+ "product_sku" : "SKU",
+
+ // Optional.
+ "initial_locale" : "en_US",
+ "background_color" : "#880088",
+ "registration_url" : "http://www.google.com",
+ "setup_content" : [
+ {
+ "content_locale" : "en_US",
+ "help_page" : "setup_content/en_US/help.html",
+ "eula_page" : "setup_content/en_US/eula.html",
+ },
+ {
+ "content_locale" : "ru",
+ "help_page" : "setup_content/ru/help.html",
+ "eula_page" : "setup_content/ru/eula.html",
+ },
+ ]
+}
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 053fd28..8478b87 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -371,6 +371,8 @@
'browser/chromeos/cros/synaptics_library.h',
'browser/chromeos/cros/syslogs_library.cc',
'browser/chromeos/cros/syslogs_library.h',
+ 'browser/chromeos/customization_document.h',
+ 'browser/chromeos/customization_document.cc',
'browser/chromeos/external_cookie_handler.cc',
'browser/chromeos/external_cookie_handler.h',
'browser/chromeos/external_metrics.cc',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 5a42f1d..fda62892 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -595,6 +595,7 @@
'browser/chrome_plugin_unittest.cc',
'browser/chrome_thread_unittest.cc',
'browser/chromeos/cros/language_library_test.cc',
+ 'browser/chromeos/customization_document_unittest.cc',
'browser/chromeos/external_cookie_handler_unittest.cc',
'browser/chromeos/external_metrics_unittest.cc',
'browser/chromeos/gview_request_interceptor_unittest.cc',
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 4723d5d..5596e85 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -895,6 +895,11 @@ const char kLoginUser[] = "login-user";
// Use the frame layout used in chromeos.
const char kChromeosFrame[] = "chromeos-frame";
+
+// Specify startup customization manifest.
+// TODO(denisromanov): delete this once it's not needed for testing anymore.
+const char kStartupManifest[] = "startup-manifest";
+
#endif
#if defined(OS_WIN)
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 54534ea..eb50a09 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -256,6 +256,7 @@ extern const char kProfile[];
extern const char kLoginProfile[];
extern const char kLoginUser[];
extern const char kChromeosFrame[];
+extern const char kStartupManifest[];
#endif
#if defined(OS_WIN)