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/browser/extensions/extension_error_reporter.h" | 11 #include "chrome/browser/extensions/extension_error_reporter.h" |
12 #include "chrome/common/extensions/user_script.h" | 12 #include "chrome/common/extensions/user_script.h" |
13 #include "chrome/common/resource_bundle.h" | 13 #include "chrome/common/resource_bundle.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 | 15 |
16 const char Extension::kManifestFilename[] = "manifest.json"; | 16 const char Extension::kManifestFilename[] = "manifest.json"; |
17 | 17 |
18 const wchar_t* Extension::kContentScriptsKey = L"content_scripts"; | 18 const wchar_t* Extension::kContentScriptsKey = L"content_scripts"; |
19 const wchar_t* Extension::kCssKey = L"css"; | 19 const wchar_t* Extension::kCssKey = L"css"; |
20 const wchar_t* Extension::kDescriptionKey = L"description"; | 20 const wchar_t* Extension::kDescriptionKey = L"description"; |
21 const wchar_t* Extension::kIdKey = L"id"; | 21 const wchar_t* Extension::kIdKey = L"id"; |
22 const wchar_t* Extension::kJsKey = L"js"; | 22 const wchar_t* Extension::kJsKey = L"js"; |
23 const wchar_t* Extension::kMatchesKey = L"matches"; | 23 const wchar_t* Extension::kMatchesKey = L"matches"; |
24 const wchar_t* Extension::kNameKey = L"name"; | 24 const wchar_t* Extension::kNameKey = L"name"; |
25 const wchar_t* Extension::kPermissionsKey = L"permissions"; | 25 const wchar_t* Extension::kPermissionsKey = L"permissions"; |
26 const wchar_t* Extension::kPluginsDirKey = L"plugins_dir"; | 26 const wchar_t* Extension::kPluginsDirKey = L"plugins_dir"; |
| 27 const wchar_t* Extension::kBackgroundKey = L"background"; |
27 const wchar_t* Extension::kRunAtKey = L"run_at"; | 28 const wchar_t* Extension::kRunAtKey = L"run_at"; |
28 const wchar_t* Extension::kThemeKey = L"theme"; | 29 const wchar_t* Extension::kThemeKey = L"theme"; |
29 const wchar_t* Extension::kToolstripsKey = L"toolstrips"; | 30 const wchar_t* Extension::kToolstripsKey = L"toolstrips"; |
30 const wchar_t* Extension::kVersionKey = L"version"; | 31 const wchar_t* Extension::kVersionKey = L"version"; |
31 const wchar_t* Extension::kZipHashKey = L"zip_hash"; | 32 const wchar_t* Extension::kZipHashKey = L"zip_hash"; |
32 | 33 |
33 const char* Extension::kRunAtDocumentStartValue = "document_start"; | 34 const char* Extension::kRunAtDocumentStartValue = "document_start"; |
34 const char* Extension::kRunAtDocumentEndValue = "document_end"; | 35 const char* Extension::kRunAtDocumentEndValue = "document_end"; |
35 | 36 |
36 // Extension-related error messages. Some of these are simple patterns, where a | 37 // Extension-related error messages. Some of these are simple patterns, where a |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 "Required value 'permissions' is missing or invalid."; | 69 "Required value 'permissions' is missing or invalid."; |
69 const char* Extension::kInvalidPermissionCountWarning = | 70 const char* Extension::kInvalidPermissionCountWarning = |
70 "Warning, 'permissions' key found, but array is empty."; | 71 "Warning, 'permissions' key found, but array is empty."; |
71 const char* Extension::kInvalidPermissionError = | 72 const char* Extension::kInvalidPermissionError = |
72 "Invalid value for 'permissions[*]'."; | 73 "Invalid value for 'permissions[*]'."; |
73 const char* Extension::kInvalidPermissionSchemeError = | 74 const char* Extension::kInvalidPermissionSchemeError = |
74 "Invalid scheme for 'permissions[*]'. Only 'http' and 'https' are " | 75 "Invalid scheme for 'permissions[*]'. Only 'http' and 'https' are " |
75 "allowed."; | 76 "allowed."; |
76 const char* Extension::kInvalidPluginsDirError = | 77 const char* Extension::kInvalidPluginsDirError = |
77 "Invalid value for 'plugins_dir'."; | 78 "Invalid value for 'plugins_dir'."; |
| 79 const char* Extension::kInvalidBackgroundError = |
| 80 "Invalid value for 'background'."; |
78 const char* Extension::kInvalidRunAtError = | 81 const char* Extension::kInvalidRunAtError = |
79 "Invalid value for 'content_scripts[*].run_at'."; | 82 "Invalid value for 'content_scripts[*].run_at'."; |
80 const char* Extension::kInvalidToolstripError = | 83 const char* Extension::kInvalidToolstripError = |
81 "Invalid value for 'toolstrips[*]'"; | 84 "Invalid value for 'toolstrips[*]'"; |
82 const char* Extension::kInvalidToolstripsError = | 85 const char* Extension::kInvalidToolstripsError = |
83 "Invalid value for 'toolstrips'."; | 86 "Invalid value for 'toolstrips'."; |
84 const char* Extension::kInvalidVersionError = | 87 const char* Extension::kInvalidVersionError = |
85 "Required value 'version' is missing or invalid."; | 88 "Required value 'version' is missing or invalid."; |
86 const char* Extension::kInvalidZipHashError = | 89 const char* Extension::kInvalidZipHashError = |
87 "Required key 'zip_hash' is missing or invalid."; | 90 "Required key 'zip_hash' is missing or invalid."; |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 // Initialize plugins dir (optional). | 399 // Initialize plugins dir (optional). |
397 if (source.HasKey(kPluginsDirKey)) { | 400 if (source.HasKey(kPluginsDirKey)) { |
398 std::string plugins_dir; | 401 std::string plugins_dir; |
399 if (!source.GetString(kPluginsDirKey, &plugins_dir)) { | 402 if (!source.GetString(kPluginsDirKey, &plugins_dir)) { |
400 *error = kInvalidPluginsDirError; | 403 *error = kInvalidPluginsDirError; |
401 return false; | 404 return false; |
402 } | 405 } |
403 plugins_dir_ = path_.AppendASCII(plugins_dir); | 406 plugins_dir_ = path_.AppendASCII(plugins_dir); |
404 } | 407 } |
405 | 408 |
| 409 // Initialize background url (optional). |
| 410 if (source.HasKey(kBackgroundKey)) { |
| 411 std::string background_str; |
| 412 if (!source.GetString(kBackgroundKey, &background_str)) { |
| 413 *error = kInvalidBackgroundError; |
| 414 return false; |
| 415 } |
| 416 background_url_ = GetResourceURL(background_str); |
| 417 } |
| 418 |
406 // Initialize toolstrips (optional). | 419 // Initialize toolstrips (optional). |
407 if (source.HasKey(kToolstripsKey)) { | 420 if (source.HasKey(kToolstripsKey)) { |
408 ListValue* list_value; | 421 ListValue* list_value; |
409 if (!source.GetList(kToolstripsKey, &list_value)) { | 422 if (!source.GetList(kToolstripsKey, &list_value)) { |
410 *error = kInvalidToolstripsError; | 423 *error = kInvalidToolstripsError; |
411 return false; | 424 return false; |
412 } | 425 } |
413 | 426 |
414 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 427 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
415 std::string toolstrip; | 428 std::string toolstrip; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 IntToString(i)); | 509 IntToString(i)); |
497 return false; | 510 return false; |
498 } | 511 } |
499 | 512 |
500 permissions_.push_back(pattern); | 513 permissions_.push_back(pattern); |
501 } | 514 } |
502 } | 515 } |
503 | 516 |
504 return true; | 517 return true; |
505 } | 518 } |
OLD | NEW |