Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 125004: Revert "BUG=12114" (Closed)
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/basictypes.h"
9 #include "base/file_path.h" 8 #include "base/file_path.h"
10 #include "base/file_util.h" 9 #include "base/file_util.h"
11 #include "base/logging.h" 10 #include "base/logging.h"
12 #include "base/string_util.h" 11 #include "base/string_util.h"
13 #include "base/third_party/nss/blapi.h"
14 #include "base/third_party/nss/sha256.h"
15 #include "net/base/base64.h"
16 #include "net/base/net_util.h" 12 #include "net/base/net_util.h"
17 #include "chrome/common/extensions/extension_error_reporter.h" 13 #include "chrome/common/extensions/extension_error_reporter.h"
18 #include "chrome/common/extensions/extension_error_utils.h" 14 #include "chrome/common/extensions/extension_error_utils.h"
19 #include "chrome/common/extensions/user_script.h" 15 #include "chrome/common/extensions/user_script.h"
20 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
21 #include "net/base/base64.h" 17 #include "net/base/base64.h"
22 18
23 #if defined(OS_WIN) 19 #if defined(OS_WIN)
24 #include "base/registry.h" 20 #include "base/registry.h"
25 #endif 21 #endif
26 22
27 namespace { 23 namespace {
28 const int kPEMOutputColumns = 65; 24 const int kPEMOutputColumns = 65;
29 25
30 // KEY MARKERS 26 // KEY MARKERS
31 const char kKeyBeginHeaderMarker[] = "-----BEGIN"; 27 const char kKeyBeginHeaderMarker[] = "-----BEGIN";
32 const char kKeyBeginFooterMarker[] = "-----END"; 28 const char kKeyBeginFooterMarker[] = "-----END";
33 const char kKeyInfoEndMarker[] = "KEY-----"; 29 const char kKeyInfoEndMarker[] = "KEY-----";
34 const char kPublic[] = "PUBLIC"; 30 const char kPublic[] = "PUBLIC";
35 const char kPrivate[] = "PRIVATE"; 31 const char kPrivate[] = "PRIVATE";
36 32
37 const int kRSAKeySize = 1024; 33 const int kRSAKeySize = 1024;
38 }; 34 };
39 35
40 int Extension::id_counter_ = 0;
41
42 const char Extension::kManifestFilename[] = "manifest.json"; 36 const char Extension::kManifestFilename[] = "manifest.json";
43 37
44 const wchar_t* Extension::kBackgroundKey = L"background_page"; 38 const wchar_t* Extension::kBackgroundKey = L"background_page";
45 const wchar_t* Extension::kContentScriptsKey = L"content_scripts"; 39 const wchar_t* Extension::kContentScriptsKey = L"content_scripts";
46 const wchar_t* Extension::kCssKey = L"css"; 40 const wchar_t* Extension::kCssKey = L"css";
47 const wchar_t* Extension::kDescriptionKey = L"description"; 41 const wchar_t* Extension::kDescriptionKey = L"description";
48 const wchar_t* Extension::kIconPathKey = L"icon"; 42 const wchar_t* Extension::kIconPathKey = L"icon";
43 const wchar_t* Extension::kIdKey = L"id";
49 const wchar_t* Extension::kJsKey = L"js"; 44 const wchar_t* Extension::kJsKey = L"js";
50 const wchar_t* Extension::kMatchesKey = L"matches"; 45 const wchar_t* Extension::kMatchesKey = L"matches";
51 const wchar_t* Extension::kNameKey = L"name"; 46 const wchar_t* Extension::kNameKey = L"name";
52 const wchar_t* Extension::kPageActionIdKey = L"id";
53 const wchar_t* Extension::kPageActionsKey = L"page_actions"; 47 const wchar_t* Extension::kPageActionsKey = L"page_actions";
54 const wchar_t* Extension::kPermissionsKey = L"permissions"; 48 const wchar_t* Extension::kPermissionsKey = L"permissions";
55 const wchar_t* Extension::kPluginsKey = L"plugins"; 49 const wchar_t* Extension::kPluginsKey = L"plugins";
56 const wchar_t* Extension::kPluginsPathKey = L"path"; 50 const wchar_t* Extension::kPluginsPathKey = L"path";
57 const wchar_t* Extension::kPluginsPublicKey = L"public"; 51 const wchar_t* Extension::kPluginsPublicKey = L"public";
58 const wchar_t* Extension::kPublicKeyKey = L"key"; 52 const wchar_t* Extension::kPublicKeyKey = L"key";
59 const wchar_t* Extension::kRunAtKey = L"run_at"; 53 const wchar_t* Extension::kRunAtKey = L"run_at";
60 const wchar_t* Extension::kSignatureKey = L"signature"; 54 const wchar_t* Extension::kSignatureKey = L"signature";
61 const wchar_t* Extension::kThemeKey = L"theme"; 55 const wchar_t* Extension::kThemeKey = L"theme";
62 const wchar_t* Extension::kThemeImagesKey = L"images"; 56 const wchar_t* Extension::kThemeImagesKey = L"images";
63 const wchar_t* Extension::kThemeColorsKey = L"colors"; 57 const wchar_t* Extension::kThemeColorsKey = L"colors";
64 const wchar_t* Extension::kThemeTintsKey = L"tints"; 58 const wchar_t* Extension::kThemeTintsKey = L"tints";
65 const wchar_t* Extension::kThemeDisplayPropertiesKey = L"properties"; 59 const wchar_t* Extension::kThemeDisplayPropertiesKey = L"properties";
66 const wchar_t* Extension::kToolstripsKey = L"toolstrips"; 60 const wchar_t* Extension::kToolstripsKey = L"toolstrips";
67 const wchar_t* Extension::kTooltipKey = L"tooltip"; 61 const wchar_t* Extension::kTooltipKey = L"tooltip";
68 const wchar_t* Extension::kTypeKey = L"type"; 62 const wchar_t* Extension::kTypeKey = L"type";
69 const wchar_t* Extension::kVersionKey = L"version"; 63 const wchar_t* Extension::kVersionKey = L"version";
70 64
71 const char* Extension::kRunAtDocumentStartValue = "document_start"; 65 const char* Extension::kRunAtDocumentStartValue = "document_start";
72 const char* Extension::kRunAtDocumentEndValue = "document_end"; 66 const char* Extension::kRunAtDocumentEndValue = "document_end";
73 const char* Extension::kPageActionTypeTab = "tab"; 67 const char* Extension::kPageActionTypeTab = "tab";
74 const char* Extension::kPageActionTypePermanent = "permanent"; 68 const char* Extension::kPageActionTypePermanent = "permanent";
75 69
76 // A list of all the keys allowed by themes. 70 // A list of all the keys allowed by themes.
77 static const wchar_t* kValidThemeKeys[] = { 71 static const wchar_t* kValidThemeKeys[] = {
78 Extension::kDescriptionKey, 72 Extension::kDescriptionKey,
79 Extension::kIconPathKey, 73 Extension::kIconPathKey,
74 Extension::kIdKey,
80 Extension::kNameKey, 75 Extension::kNameKey,
81 Extension::kPublicKeyKey, 76 Extension::kPublicKeyKey,
82 Extension::kSignatureKey, 77 Extension::kSignatureKey,
83 Extension::kThemeKey, 78 Extension::kThemeKey,
84 Extension::kVersionKey 79 Extension::kVersionKey
85 }; 80 };
86 81
87 // Extension-related error messages. Some of these are simple patterns, where a 82 // Extension-related error messages. Some of these are simple patterns, where a
88 // '*' is replaced at runtime with a specific value. This is used instead of 83 // '*' is replaced at runtime with a specific value. This is used instead of
89 // printf because we want to unit test them and scanf is hard to make 84 // printf because we want to unit test them and scanf is hard to make
90 // cross-platform. 85 // cross-platform.
91 const char* Extension::kInvalidContentScriptError = 86 const char* Extension::kInvalidContentScriptError =
92 "Invalid value for 'content_scripts[*]'."; 87 "Invalid value for 'content_scripts[*]'.";
93 const char* Extension::kInvalidContentScriptsListError = 88 const char* Extension::kInvalidContentScriptsListError =
94 "Invalid value for 'content_scripts'."; 89 "Invalid value for 'content_scripts'.";
95 const char* Extension::kInvalidCssError = 90 const char* Extension::kInvalidCssError =
96 "Invalid value for 'content_scripts[*].css[*]'."; 91 "Invalid value for 'content_scripts[*].css[*]'.";
97 const char* Extension::kInvalidCssListError = 92 const char* Extension::kInvalidCssListError =
98 "Required value 'content_scripts[*].css is invalid."; 93 "Required value 'content_scripts[*].css is invalid.";
99 const char* Extension::kInvalidDescriptionError = 94 const char* Extension::kInvalidDescriptionError =
100 "Invalid value for 'description'."; 95 "Invalid value for 'description'.";
96 const char* Extension::kInvalidIdError =
97 "Required value 'id' is missing or invalid.";
101 const char* Extension::kInvalidJsError = 98 const char* Extension::kInvalidJsError =
102 "Invalid value for 'content_scripts[*].js[*]'."; 99 "Invalid value for 'content_scripts[*].js[*]'.";
103 const char* Extension::kInvalidJsListError = 100 const char* Extension::kInvalidJsListError =
104 "Required value 'content_scripts[*].js is invalid."; 101 "Required value 'content_scripts[*].js is invalid.";
105 const char* Extension::kInvalidKeyError =
106 "Value 'key' is missing or invalid.";
107 const char* Extension::kInvalidManifestError = 102 const char* Extension::kInvalidManifestError =
108 "Manifest is missing or invalid."; 103 "Manifest is missing or invalid.";
109 const char* Extension::kInvalidMatchCountError = 104 const char* Extension::kInvalidMatchCountError =
110 "Invalid value for 'content_scripts[*].matches. There must be at least one " 105 "Invalid value for 'content_scripts[*].matches. There must be at least one "
111 "match specified."; 106 "match specified.";
112 const char* Extension::kInvalidMatchError = 107 const char* Extension::kInvalidMatchError =
113 "Invalid value for 'content_scripts[*].matches[*]'."; 108 "Invalid value for 'content_scripts[*].matches[*]'.";
114 const char* Extension::kInvalidMatchesError = 109 const char* Extension::kInvalidMatchesError =
115 "Required value 'content_scripts[*].matches' is missing or invalid."; 110 "Required value 'content_scripts[*].matches' is missing or invalid.";
116 const char* Extension::kInvalidNameError = 111 const char* Extension::kInvalidNameError =
117 "Required value 'name' is missing or invalid."; 112 "Required value 'name' is missing or invalid.";
118 const char* Extension::kInvalidPageActionError = 113 const char* Extension::kInvalidPageActionError =
119 "Invalid value for 'page_actions[*]'."; 114 "Invalid value for 'page_actions[*]'.";
120 const char* Extension::kInvalidPageActionsListError = 115 const char* Extension::kInvalidPageActionsListError =
121 "Invalid value for 'page_actions'."; 116 "Invalid value for 'page_actions'.";
122 const char* Extension::kInvalidPageActionIconPathError = 117 const char* Extension::kInvalidPageActionIconPathError =
123 "Invalid value for 'page_actions[*].icon'."; 118 "Invalid value for 'page_actions[*].icon'.";
124 const char* Extension::kInvalidPageActionIdError =
125 "Required value 'id' is missing or invalid.";
126 const char* Extension::kInvalidPageActionTooltipError = 119 const char* Extension::kInvalidPageActionTooltipError =
127 "Invalid value for 'page_actions[*].tooltip'."; 120 "Invalid value for 'page_actions[*].tooltip'.";
128 const char* Extension::kInvalidPageActionTypeValueError = 121 const char* Extension::kInvalidPageActionTypeValueError =
129 "Invalid value for 'page_actions[*].type', expected 'tab' or 'permanent'."; 122 "Invalid value for 'page_actions[*].type', expected 'tab' or 'permanent'.";
130 const char* Extension::kInvalidPermissionsError = 123 const char* Extension::kInvalidPermissionsError =
131 "Required value 'permissions' is missing or invalid."; 124 "Required value 'permissions' is missing or invalid.";
132 const char* Extension::kInvalidPermissionCountWarning = 125 const char* Extension::kInvalidPermissionCountWarning =
133 "Warning, 'permissions' key found, but array is empty."; 126 "Warning, 'permissions' key found, but array is empty.";
134 const char* Extension::kInvalidPermissionError = 127 const char* Extension::kInvalidPermissionError =
135 "Invalid value for 'permissions[*]'."; 128 "Invalid value for 'permissions[*]'.";
136 const char* Extension::kInvalidPermissionSchemeError = 129 const char* Extension::kInvalidPermissionSchemeError =
137 "Invalid scheme for 'permissions[*]'. Only 'http' and 'https' are " 130 "Invalid scheme for 'permissions[*]'. Only 'http' and 'https' are "
138 "allowed."; 131 "allowed.";
139 const char* Extension::kInvalidPluginsError = 132 const char* Extension::kInvalidPluginsError =
140 "Invalid value for 'plugins'."; 133 "Invalid value for 'plugins'.";
141 const char* Extension::kInvalidPluginsPathError = 134 const char* Extension::kInvalidPluginsPathError =
142 "Invalid value for 'plugins[*].path'."; 135 "Invalid value for 'plugins[*].path'.";
143 const char* Extension::kInvalidPluginsPublicError = 136 const char* Extension::kInvalidPluginsPublicError =
144 "Invalid value for 'plugins[*].public'."; 137 "Invalid value for 'plugins[*].public'.";
145 const char* Extension::kInvalidBackgroundError = 138 const char* Extension::kInvalidBackgroundError =
146 "Invalid value for 'background'."; 139 "Invalid value for 'background'.";
147 const char* Extension::kInvalidRunAtError = 140 const char* Extension::kInvalidRunAtError =
148 "Invalid value for 'content_scripts[*].run_at'."; 141 "Invalid value for 'content_scripts[*].run_at'.";
149 const char* Extension::kInvalidSignatureError =
150 "Value 'signature' is missing or invalid.";
151 const char* Extension::kInvalidToolstripError = 142 const char* Extension::kInvalidToolstripError =
152 "Invalid value for 'toolstrips[*]'"; 143 "Invalid value for 'toolstrips[*]'";
153 const char* Extension::kInvalidToolstripsError = 144 const char* Extension::kInvalidToolstripsError =
154 "Invalid value for 'toolstrips'."; 145 "Invalid value for 'toolstrips'.";
155 const char* Extension::kInvalidVersionError = 146 const char* Extension::kInvalidVersionError =
156 "Required value 'version' is missing or invalid."; 147 "Required value 'version' is missing or invalid.";
157 const char* Extension::kInvalidZipHashError = 148 const char* Extension::kInvalidZipHashError =
158 "Required key 'zip_hash' is missing or invalid."; 149 "Required key 'zip_hash' is missing or invalid.";
159 const char* Extension::kMissingFileError = 150 const char* Extension::kMissingFileError =
160 "At least one js or css file is required for 'content_scripts[*]'."; 151 "At least one js or css file is required for 'content_scripts[*]'.";
161 const char* Extension::kInvalidThemeError = 152 const char* Extension::kInvalidThemeError =
162 "Invalid value for 'theme'."; 153 "Invalid value for 'theme'.";
163 const char* Extension::kInvalidThemeImagesError = 154 const char* Extension::kInvalidThemeImagesError =
164 "Invalid value for theme images - images must be strings."; 155 "Invalid value for theme images - images must be strings.";
165 const char* Extension::kInvalidThemeImagesMissingError = 156 const char* Extension::kInvalidThemeImagesMissingError =
166 "Am image specified in the theme is missing."; 157 "Am image specified in the theme is missing.";
167 const char* Extension::kInvalidThemeColorsError = 158 const char* Extension::kInvalidThemeColorsError =
168 "Invalid value for theme colors - colors must be integers"; 159 "Invalid value for theme colors - colors must be integers";
169 const char* Extension::kInvalidThemeTintsError = 160 const char* Extension::kInvalidThemeTintsError =
170 "Invalid value for theme images - tints must be decimal numbers."; 161 "Invalid value for theme images - tints must be decimal numbers.";
171 const char* Extension::kThemesCannotContainExtensionsError = 162 const char* Extension::kThemesCannotContainExtensionsError =
172 "A theme cannot contain extensions code."; 163 "A theme cannot contain extensions code.";
173 164
174 #if defined(OS_WIN) 165 #if defined(OS_WIN)
175 const char* Extension::kExtensionRegistryPath = 166 const char* Extension::kExtensionRegistryPath =
176 "Software\\Google\\Chrome\\Extensions"; 167 "Software\\Google\\Chrome\\Extensions";
177 #endif 168 #endif
178 169
179 // first 20 bytes of SHA256 hashed public key. 170 const size_t Extension::kIdSize = 20; // SHA1 (160 bits) == 20 bytes
180 const size_t Extension::kIdSize = 20;
181 171
182 Extension::~Extension() { 172 Extension::~Extension() {
183 for (PageActionMap::iterator i = page_actions_.begin(); 173 for (PageActionMap::iterator i = page_actions_.begin();
184 i != page_actions_.end(); ++i) 174 i != page_actions_.end(); ++i)
185 delete i->second; 175 delete i->second;
186 } 176 }
187 177
188 const std::string Extension::VersionString() const { 178 const std::string Extension::VersionString() const {
189 return version_->GetString(); 179 return version_->GetString();
190 } 180 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 HKEY reg_root = HKEY_LOCAL_MACHINE; 223 HKEY reg_root = HKEY_LOCAL_MACHINE;
234 RegKey key; 224 RegKey key;
235 registry_path.append("\\"); 225 registry_path.append("\\");
236 registry_path.append(id_); 226 registry_path.append(id_);
237 if (key.Open(reg_root, ASCIIToWide(registry_path).c_str())) 227 if (key.Open(reg_root, ASCIIToWide(registry_path).c_str()))
238 return Extension::EXTERNAL_REGISTRY; 228 return Extension::EXTERNAL_REGISTRY;
239 #endif 229 #endif
240 return Extension::EXTERNAL_PREF; 230 return Extension::EXTERNAL_PREF;
241 } 231 }
242 232
243 bool Extension::GenerateIdFromPublicKey(const std::string& input,
244 std::string* output) {
245 CHECK(output);
246 if (input.length() == 0)
247 return false;
248
249 const uint8* ubuf = reinterpret_cast<const unsigned char*>(input.data());
250 SHA256Context ctx;
251 SHA256_Begin(&ctx);
252 SHA256_Update(&ctx, ubuf, input.length());
253 uint8 hash[Extension::kIdSize];
254 SHA256_End(&ctx, hash, NULL, sizeof(hash));
255 *output = StringToLowerASCII(HexEncode(hash, sizeof(hash)));
256
257 return true;
258 }
259
260 // Helper method that loads a UserScript object from a dictionary in the 233 // Helper method that loads a UserScript object from a dictionary in the
261 // content_script list of the manifest. 234 // content_script list of the manifest.
262 bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, 235 bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script,
263 int definition_index, std::string* error, 236 int definition_index, std::string* error,
264 UserScript* result) { 237 UserScript* result) {
265 // run_at 238 // run_at
266 if (content_script->HasKey(kRunAtKey)) { 239 if (content_script->HasKey(kRunAtKey)) {
267 std::string run_location; 240 std::string run_location;
268 if (!content_script->GetString(kRunAtKey, &run_location)) { 241 if (!content_script->GetString(kRunAtKey, &run_location)) {
269 *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidRunAtError, 242 *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidRunAtError,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 if (!page_action->GetString(kIconPathKey, &icon)) { 360 if (!page_action->GetString(kIconPathKey, &icon)) {
388 *error = ExtensionErrorUtils::FormatErrorMessage( 361 *error = ExtensionErrorUtils::FormatErrorMessage(
389 kInvalidPageActionIconPathError, IntToString(definition_index)); 362 kInvalidPageActionIconPathError, IntToString(definition_index));
390 return NULL; 363 return NULL;
391 } 364 }
392 FilePath icon_path = path_.AppendASCII(icon); 365 FilePath icon_path = path_.AppendASCII(icon);
393 result->set_icon_path(icon_path); 366 result->set_icon_path(icon_path);
394 367
395 // Read the page action |id|. 368 // Read the page action |id|.
396 std::string id; 369 std::string id;
397 if (!page_action->GetString(kPageActionIdKey, &id)) { 370 if (!page_action->GetString(kIdKey, &id)) {
398 *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidPageActionIdError, 371 *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidIdError,
399 IntToString(definition_index)); 372 IntToString(definition_index));
400 return NULL; 373 return NULL;
401 } 374 }
402 result->set_id(id); 375 result->set_id(id);
403 376
404 // Read the page action |name|. 377 // Read the page action |name|.
405 std::string name; 378 std::string name;
406 if (!page_action->GetString(kNameKey, &name)) { 379 if (!page_action->GetString(kNameKey, &name)) {
407 *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidNameError, 380 *error = ExtensionErrorUtils::FormatErrorMessage(kInvalidNameError,
408 IntToString(definition_index)); 381 IntToString(definition_index));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 if (path_str.size() >= 2 && path_str[0] >= L'a' && path_str[0] <= L'z' && 485 if (path_str.size() >= 2 && path_str[0] >= L'a' && path_str[0] <= L'z' &&
513 path_str[1] == ':') 486 path_str[1] == ':')
514 path_str[0] += ('A' - 'a'); 487 path_str[0] += ('A' - 'a');
515 488
516 path_ = FilePath(path_str); 489 path_ = FilePath(path_str);
517 #else 490 #else
518 path_ = path; 491 path_ = path;
519 #endif 492 #endif
520 } 493 }
521 494
495
522 // TODO(rafaelw): Move ParsePEMKeyBytes, ProducePEM & FormatPEMForOutput to a 496 // TODO(rafaelw): Move ParsePEMKeyBytes, ProducePEM & FormatPEMForOutput to a
523 // util class in base: 497 // util class in base:
524 // http://code.google.com/p/chromium/issues/detail?id=13572 498 // http://code.google.com/p/chromium/issues/detail?id=13572
525 bool Extension::ParsePEMKeyBytes(const std::string& input, 499 bool Extension::ParsePEMKeyBytes(const std::string& input,
526 std::string* output) { 500 std::string* output) {
527 DCHECK(output); 501 CHECK(output);
528 if (!output)
529 return false;
530 if (input.length() == 0) 502 if (input.length() == 0)
531 return false; 503 return false;
532 504
533 std::string working = input; 505 std::string working = input;
534 if (StartsWithASCII(working, kKeyBeginHeaderMarker, true)) { 506 if (StartsWithASCII(working, kKeyBeginHeaderMarker, true)) {
535 working = CollapseWhitespaceASCII(working, true); 507 working = CollapseWhitespaceASCII(working, true);
536 size_t header_pos = working.find(kKeyInfoEndMarker, 508 size_t header_pos = working.find(kKeyInfoEndMarker,
537 sizeof(kKeyBeginHeaderMarker) - 1); 509 sizeof(kKeyBeginHeaderMarker) - 1);
538 if (header_pos == std::string::npos) 510 if (header_pos == std::string::npos)
539 return false; 511 return false;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 output->append(is_public ? kPublic : kPrivate); 557 output->append(is_public ? kPublic : kPrivate);
586 output->append(" "); 558 output->append(" ");
587 output->append(kKeyInfoEndMarker); 559 output->append(kKeyInfoEndMarker);
588 output->append("\n"); 560 output->append("\n");
589 561
590 return true; 562 return true;
591 } 563 }
592 564
593 bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, 565 bool Extension::InitFromValue(const DictionaryValue& source, bool require_id,
594 std::string* error) { 566 std::string* error) {
595 if (source.HasKey(kPublicKeyKey)) { 567 // Initialize id.
596 std::string public_key_bytes; 568 if (source.HasKey(kIdKey)) {
597 if (!source.GetString(kPublicKeyKey, &public_key_) || 569 if (!source.GetString(kIdKey, &id_)) {
598 !ParsePEMKeyBytes(public_key_, &public_key_bytes) || 570 *error = kInvalidIdError;
599 !GenerateIdFromPublicKey(public_key_bytes, &id_)) { 571 return false;
600 *error = kInvalidKeyError; 572 }
601 return false; 573
574 // Normalize the string to lowercase, so it can be used as an URL component
575 // (where GURL will lowercase it).
576 StringToLowerASCII(&id_);
577
578 // Verify that the id is legal.
579 if (!IdIsValid(id_)) {
580 *error = kInvalidIdError;
581 return false;
602 } 582 }
603 } else if (require_id) { 583 } else if (require_id) {
604 *error = kInvalidKeyError; 584 *error = kInvalidIdError;
605 return false; 585 return false;
606 } else { 586 } else {
607 // Generate a random ID 587 // Generate a random ID
608 id_ = StringPrintf("%x", NextGeneratedId()); 588 static int counter = 0;
589 id_ = StringPrintf("%x", counter);
590 ++counter;
609 591
610 // pad the string out to kIdSize*2 chars with zeroes. 592 // pad the string out to 40 chars with zeroes.
611 id_.insert(0, Extension::kIdSize*2 - id_.length(), '0'); 593 id_.insert(0, 40 - id_.length(), '0');
612 } 594 }
613 595
614 // Initialize the URL. 596 // Initialize the URL.
615 extension_url_ = GURL(std::string(chrome::kExtensionScheme) + 597 extension_url_ = GURL(std::string(chrome::kExtensionScheme) +
616 chrome::kStandardSchemeSeparator + id_ + "/"); 598 chrome::kStandardSchemeSeparator + id_ + "/");
617 599
618 // Initialize version. 600 // Initialize version.
619 std::string version_str; 601 std::string version_str;
620 if (!source.GetString(kVersionKey, &version_str)) { 602 if (!source.GetString(kVersionKey, &version_str)) {
621 *error = kInvalidVersionError; 603 *error = kInvalidVersionError;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 } 896 }
915 } 897 }
916 898
917 for (PageActionMap::const_iterator it = page_actions().begin(); 899 for (PageActionMap::const_iterator it = page_actions().begin();
918 it != page_actions().end(); ++it) { 900 it != page_actions().end(); ++it) {
919 image_paths.insert(it->second->icon_path()); 901 image_paths.insert(it->second->icon_path());
920 } 902 }
921 903
922 return image_paths; 904 return image_paths;
923 } 905 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698