OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/browser/extensions/extension.h" | 5 #include "chrome/browser/extensions/extension.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
11 #include "chrome/common/extensions/user_script.h" | 11 #include "chrome/common/extensions/user_script.h" |
12 #include "chrome/common/resource_bundle.h" | 12 #include "chrome/common/resource_bundle.h" |
13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
14 | 14 |
15 const char Extension::kManifestFilename[] = "manifest.json"; | 15 const char Extension::kManifestFilename[] = "manifest.json"; |
16 | 16 |
17 const wchar_t* Extension::kContentScriptsKey = L"content_scripts"; | 17 const wchar_t* Extension::kContentScriptsKey = L"content_scripts"; |
18 const wchar_t* Extension::kDescriptionKey = L"description"; | 18 const wchar_t* Extension::kDescriptionKey = L"description"; |
19 const wchar_t* Extension::kFormatVersionKey = L"format_version"; | 19 const wchar_t* Extension::kFormatVersionKey = L"format_version"; |
20 const wchar_t* Extension::kIdKey = L"id"; | 20 const wchar_t* Extension::kIdKey = L"id"; |
21 const wchar_t* Extension::kJsKey = L"js"; | 21 const wchar_t* Extension::kJsKey = L"js"; |
22 const wchar_t* Extension::kMatchesKey = L"matches"; | 22 const wchar_t* Extension::kMatchesKey = L"matches"; |
23 const wchar_t* Extension::kNameKey = L"name"; | 23 const wchar_t* Extension::kNameKey = L"name"; |
24 const wchar_t* Extension::kRunAtKey = L"run_at"; | 24 const wchar_t* Extension::kRunAtKey = L"run_at"; |
25 const wchar_t* Extension::kVersionKey = L"version"; | 25 const wchar_t* Extension::kVersionKey = L"version"; |
26 const wchar_t* Extension::kZipHashKey = L"zip_hash"; | 26 const wchar_t* Extension::kZipHashKey = L"zip_hash"; |
27 const wchar_t* Extension::kPluginsDirKey = L"plugins_dir"; | 27 const wchar_t* Extension::kPluginsDirKey = L"plugins_dir"; |
28 const wchar_t* Extension::kThemeKey = L"theme"; | 28 const wchar_t* Extension::kThemeKey = L"theme"; |
| 29 const wchar_t* Extension::kToolstripKey = L"toolstrip"; |
29 | 30 |
30 const char* Extension::kRunAtDocumentStartValue = "document_start"; | 31 const char* Extension::kRunAtDocumentStartValue = "document_start"; |
31 const char* Extension::kRunAtDocumentEndValue = "document_end"; | 32 const char* Extension::kRunAtDocumentEndValue = "document_end"; |
32 | 33 |
33 // Extension-related error messages. Some of these are simple patterns, where a | 34 // Extension-related error messages. Some of these are simple patterns, where a |
34 // '*' is replaced at runtime with a specific value. This is used instead of | 35 // '*' is replaced at runtime with a specific value. This is used instead of |
35 // printf because we want to unit test them and scanf is hard to make | 36 // printf because we want to unit test them and scanf is hard to make |
36 // cross-platform. | 37 // cross-platform. |
37 const char* Extension::kInvalidContentScriptError = | 38 const char* Extension::kInvalidContentScriptError = |
38 "Invalid value for 'content_scripts[*]'."; | 39 "Invalid value for 'content_scripts[*]'."; |
(...skipping 24 matching lines...) Expand all Loading... |
63 const char* Extension::kInvalidNameError = | 64 const char* Extension::kInvalidNameError = |
64 "Required value 'name' is missing or invalid."; | 65 "Required value 'name' is missing or invalid."; |
65 const char* Extension::kInvalidRunAtError = | 66 const char* Extension::kInvalidRunAtError = |
66 "Invalid value for 'content_scripts[*].run_at'."; | 67 "Invalid value for 'content_scripts[*].run_at'."; |
67 const char* Extension::kInvalidVersionError = | 68 const char* Extension::kInvalidVersionError = |
68 "Required value 'version' is missing or invalid."; | 69 "Required value 'version' is missing or invalid."; |
69 const char* Extension::kInvalidZipHashError = | 70 const char* Extension::kInvalidZipHashError = |
70 "Required key 'zip_hash' is missing or invalid."; | 71 "Required key 'zip_hash' is missing or invalid."; |
71 const char* Extension::kInvalidPluginsDirError = | 72 const char* Extension::kInvalidPluginsDirError = |
72 "Invalid value for 'plugins_dir'."; | 73 "Invalid value for 'plugins_dir'."; |
| 74 const char* Extension::kInvalidToolstripError = |
| 75 "Invalid value for 'toolstrip'."; |
73 | 76 |
74 const size_t Extension::kIdSize = 20; // SHA1 (160 bits) == 20 bytes | 77 const size_t Extension::kIdSize = 20; // SHA1 (160 bits) == 20 bytes |
75 | 78 |
76 Extension::Extension(const Extension& rhs) | 79 Extension::Extension(const Extension& rhs) |
77 : path_(rhs.path_), | 80 : path_(rhs.path_), |
78 extension_url_(rhs.extension_url_), | 81 extension_url_(rhs.extension_url_), |
79 id_(rhs.id_), | 82 id_(rhs.id_), |
80 version_(new Version(*rhs.version_)), | 83 version_(new Version(*rhs.version_)), |
81 name_(rhs.name_), | 84 name_(rhs.name_), |
82 description_(rhs.description_), | 85 description_(rhs.description_), |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 // Initialize plugins dir (optional). | 256 // Initialize plugins dir (optional). |
254 if (source.HasKey(kPluginsDirKey)) { | 257 if (source.HasKey(kPluginsDirKey)) { |
255 std::string plugins_dir; | 258 std::string plugins_dir; |
256 if (!source.GetString(kPluginsDirKey, &plugins_dir)) { | 259 if (!source.GetString(kPluginsDirKey, &plugins_dir)) { |
257 *error = kInvalidPluginsDirError; | 260 *error = kInvalidPluginsDirError; |
258 return false; | 261 return false; |
259 } | 262 } |
260 plugins_dir_ = path_.AppendASCII(plugins_dir); | 263 plugins_dir_ = path_.AppendASCII(plugins_dir); |
261 } | 264 } |
262 | 265 |
| 266 // Initialize toolstrip (optional). |
| 267 if (source.HasKey(kToolstripKey)) { |
| 268 std::string toolstrip_path; |
| 269 if (!source.GetString(kToolstripKey, &toolstrip_path)) { |
| 270 *error = kInvalidToolstripError; |
| 271 return false; |
| 272 } |
| 273 toolstrip_url_ = GetResourceURL(extension_url_, toolstrip_path); |
| 274 } |
| 275 |
263 if (source.HasKey(kThemeKey)) { | 276 if (source.HasKey(kThemeKey)) { |
264 DictionaryValue* dict_value; | 277 DictionaryValue* dict_value; |
265 if (source.GetDictionary(kThemeKey, &dict_value)) { | 278 if (source.GetDictionary(kThemeKey, &dict_value)) { |
266 DictionaryValue::key_iterator iter = dict_value->begin_keys(); | 279 DictionaryValue::key_iterator iter = dict_value->begin_keys(); |
267 while (iter != dict_value->end_keys()) { | 280 while (iter != dict_value->end_keys()) { |
268 std::string val; | 281 std::string val; |
269 if (dict_value->GetString(*iter, &val)) { | 282 if (dict_value->GetString(*iter, &val)) { |
270 std::wstring id = *iter; | 283 std::wstring id = *iter; |
271 theme_paths_[id] = val; | 284 theme_paths_[id] = val; |
272 } | 285 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 script.set_path(Extension::GetResourcePath(path(), file)); | 374 script.set_path(Extension::GetResourcePath(path(), file)); |
362 script.set_url(Extension::GetResourceURL(url(), file)); | 375 script.set_url(Extension::GetResourceURL(url(), file)); |
363 | 376 |
364 content_scripts_.push_back(script); | 377 content_scripts_.push_back(script); |
365 } | 378 } |
366 } | 379 } |
367 | 380 |
368 return true; | 381 return true; |
369 } | 382 } |
370 | 383 |
OLD | NEW |