1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
// 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 "base/file_util.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/string_util.h"
// Manifest attributes names.
namespace {
const char kVersionAttr[] = "version";
const char kDefaultAttr[] = "default";
const char kInitialLocaleAttr[] = "initial_locale";
const char kInitialTimezoneAttr[] = "initial_timezone";
const char kKeyboardLayoutAttr[] = "keyboard_layout";
const char kRegistrationUrlAttr[] = "registration_url";
const char kHwidMapAttr[] = "hwid_map";
const char kHwidMaskAttr[] = "hwid_mask";
const char kSetupContentAttr[] = "setup_content";
const char kHelpPageAttr[] = "help_page";
const char kEulaPageAttr[] = "eula_page";
const char kAppContentAttr[] = "app_content";
const char kInitialStartPageAttr[] = "initial_start_page";
const char kSupportPageAttr[] = "support_page";
const char kAcceptedManifestVersion[] = "1.0";
const char kHWIDPath[] = "/sys/devices/platform/chromeos_acpi/HWID";
} // anonymous namespace
namespace chromeos {
// CustomizationDocument implementation.
bool CustomizationDocument::LoadManifestFromFile(
const FilePath& manifest_path) {
std::string manifest;
if (!file_util::ReadFileToString(manifest_path, &manifest))
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);
if (root->GetType() == Value::TYPE_DICTIONARY) {
root_.reset(static_cast<DictionaryValue*>(root.release()));
std::string result;
if (root_->GetString(kVersionAttr, &result) &&
result == kAcceptedManifestVersion)
return true;
LOG(ERROR) << "Wrong customization manifest version";
root_.reset(NULL);
}
return false;
}
std::string CustomizationDocument::GetLocaleSpecificString(
const std::string& locale,
const std::string& dictionary_name,
const std::string& entry_name) const {
DictionaryValue* dictionary_content = NULL;
if (!root_->GetDictionary(dictionary_name, &dictionary_content))
return std::string();
DictionaryValue* locale_dictionary = NULL;
if (dictionary_content->GetDictionary(locale, &locale_dictionary)) {
std::string result;
if (locale_dictionary->GetString(entry_name, &result))
return result;
}
DictionaryValue* default_dictionary = NULL;
if (dictionary_content->GetDictionary(kDefaultAttr, &default_dictionary)) {
std::string result;
if (default_dictionary->GetString(entry_name, &result))
return result;
}
return std::string();
}
// StartupCustomizationDocument implementation.
bool StartupCustomizationDocument::LoadManifestFromString(
const std::string& manifest) {
if (!CustomizationDocument::LoadManifestFromString(manifest)) {
return false;
}
root_->GetString(kInitialLocaleAttr, &initial_locale_);
root_->GetString(kInitialTimezoneAttr, &initial_timezone_);
root_->GetString(kKeyboardLayoutAttr, &keyboard_layout_);
root_->GetString(kRegistrationUrlAttr, ®istration_url_);
std::string hwid = GetHWID();
if (!hwid.empty()) {
ListValue* hwid_list = NULL;
if (root_->GetList(kHwidMapAttr, &hwid_list)) {
for (size_t i = 0; i < hwid_list->GetSize(); ++i) {
DictionaryValue* hwid_dictionary = NULL;
std::string hwid_mask;
if (hwid_list->GetDictionary(i, &hwid_dictionary) &&
hwid_dictionary->GetString(kHwidMaskAttr, &hwid_mask)) {
if (MatchPattern(hwid, hwid_mask)) {
// If HWID for this machine matches some mask, use HWID specific
// settings.
std::string result;
if (hwid_dictionary->GetString(kInitialLocaleAttr, &result))
initial_locale_ = result;
if (hwid_dictionary->GetString(kInitialTimezoneAttr, &result))
initial_timezone_ = result;
if (hwid_dictionary->GetString(kKeyboardLayoutAttr, &result))
keyboard_layout_ = result;
}
// Don't break here to allow other entires to be applied if match.
} else {
LOG(ERROR) << "Syntax error in customization manifest";
}
}
}
} else {
LOG(ERROR) << "Can't read HWID from " << kHWIDPath;
}
// TODO(dpolukhin): read initial locale and timezone from VPD.
// http://crosbug.com/12355
return true;
}
std::string StartupCustomizationDocument::GetHWID() const {
std::string hwid;
FilePath hwid_file_path(kHWIDPath);
if (!file_util::ReadFileToString(hwid_file_path, &hwid))
LOG(ERROR) << "Can't read HWID from " << kHWIDPath;
return hwid;
}
std::string StartupCustomizationDocument::GetHelpPage(
const std::string& locale) const {
return GetLocaleSpecificString(locale, kSetupContentAttr, kHelpPageAttr);
}
std::string StartupCustomizationDocument::GetEULAPage(
const std::string& locale) const {
return GetLocaleSpecificString(locale, kSetupContentAttr, kEulaPageAttr);
}
// ServicesCustomizationDocument implementation.
std::string ServicesCustomizationDocument::GetInitialStartPage(
const std::string& locale) const {
return GetLocaleSpecificString(
locale, kAppContentAttr, kInitialStartPageAttr);
}
std::string ServicesCustomizationDocument::GetSupportPage(
const std::string& locale) const {
return GetLocaleSpecificString(
locale, kAppContentAttr, kSupportPageAttr);
}
} // namespace chromeos
|