OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/background_info.h" | 5 #include "extensions/common/manifest_handlers/background_info.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/common/chrome_switches.h" | |
14 #include "chrome/common/extensions/extension_file_util.h" | |
15 #include "chrome/common/extensions/permissions/permissions_data.h" | 13 #include "chrome/common/extensions/permissions/permissions_data.h" |
16 #include "extensions/common/constants.h" | 14 #include "extensions/common/constants.h" |
17 #include "extensions/common/error_utils.h" | 15 #include "extensions/common/error_utils.h" |
| 16 #include "extensions/common/file_util.h" |
18 #include "extensions/common/manifest_constants.h" | 17 #include "extensions/common/manifest_constants.h" |
19 #include "extensions/common/permissions/api_permission_set.h" | 18 #include "extensions/common/permissions/api_permission_set.h" |
| 19 #include "extensions/common/switches.h" |
20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
22 | 22 |
23 using base::DictionaryValue; | 23 using base::DictionaryValue; |
24 | 24 |
25 namespace extensions { | 25 namespace extensions { |
26 | 26 |
27 namespace keys = manifest_keys; | 27 namespace keys = manifest_keys; |
28 namespace values = manifest_values; | 28 namespace values = manifest_values; |
29 namespace errors = manifest_errors; | 29 namespace errors = manifest_errors; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 extension->SetManifestData(kBackground, info.release()); | 261 extension->SetManifestData(kBackground, info.release()); |
262 return true; | 262 return true; |
263 } | 263 } |
264 | 264 |
265 bool BackgroundManifestHandler::Validate( | 265 bool BackgroundManifestHandler::Validate( |
266 const Extension* extension, | 266 const Extension* extension, |
267 std::string* error, | 267 std::string* error, |
268 std::vector<InstallWarning>* warnings) const { | 268 std::vector<InstallWarning>* warnings) const { |
269 // Validate that background scripts exist. | 269 // Validate that background scripts exist. |
270 const std::vector<std::string>& background_scripts = | 270 const std::vector<std::string>& background_scripts = |
271 extensions::BackgroundInfo::GetBackgroundScripts(extension); | 271 BackgroundInfo::GetBackgroundScripts(extension); |
272 for (size_t i = 0; i < background_scripts.size(); ++i) { | 272 for (size_t i = 0; i < background_scripts.size(); ++i) { |
273 if (!base::PathExists( | 273 if (!base::PathExists( |
274 extension->GetResource(background_scripts[i]).GetFilePath())) { | 274 extension->GetResource(background_scripts[i]).GetFilePath())) { |
275 *error = l10n_util::GetStringFUTF8( | 275 *error = l10n_util::GetStringFUTF8( |
276 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, | 276 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, |
277 UTF8ToUTF16(background_scripts[i])); | 277 UTF8ToUTF16(background_scripts[i])); |
278 return false; | 278 return false; |
279 } | 279 } |
280 } | 280 } |
281 | 281 |
282 // Validate background page location, except for hosted apps, which should use | 282 // Validate background page location, except for hosted apps, which should use |
283 // an external URL. Background page for hosted apps are verified when the | 283 // an external URL. Background page for hosted apps are verified when the |
284 // extension is created (in Extension::InitFromValue) | 284 // extension is created (in Extension::InitFromValue) |
285 if (extensions::BackgroundInfo::HasBackgroundPage(extension) && | 285 if (BackgroundInfo::HasBackgroundPage(extension) && |
286 !extension->is_hosted_app() && background_scripts.empty()) { | 286 !extension->is_hosted_app() && background_scripts.empty()) { |
287 base::FilePath page_path = | 287 base::FilePath page_path = file_util::ExtensionURLToRelativeFilePath( |
288 extension_file_util::ExtensionURLToRelativeFilePath( | 288 BackgroundInfo::GetBackgroundURL(extension)); |
289 extensions::BackgroundInfo::GetBackgroundURL(extension)); | |
290 const base::FilePath path = extension->GetResource(page_path).GetFilePath(); | 289 const base::FilePath path = extension->GetResource(page_path).GetFilePath(); |
291 if (path.empty() || !base::PathExists(path)) { | 290 if (path.empty() || !base::PathExists(path)) { |
292 *error = | 291 *error = |
293 l10n_util::GetStringFUTF8( | 292 l10n_util::GetStringFUTF8( |
294 IDS_EXTENSION_LOAD_BACKGROUND_PAGE_FAILED, | 293 IDS_EXTENSION_LOAD_BACKGROUND_PAGE_FAILED, |
295 page_path.LossyDisplayName()); | 294 page_path.LossyDisplayName()); |
296 return false; | 295 return false; |
297 } | 296 } |
298 } | 297 } |
299 return true; | 298 return true; |
(...skipping 10 matching lines...) Expand all Loading... |
310 keys::kBackgroundPageLegacy, | 309 keys::kBackgroundPageLegacy, |
311 keys::kBackgroundPersistent, | 310 keys::kBackgroundPersistent, |
312 keys::kBackgroundScripts, | 311 keys::kBackgroundScripts, |
313 keys::kPlatformAppBackgroundPage, | 312 keys::kPlatformAppBackgroundPage, |
314 keys::kPlatformAppBackgroundScripts | 313 keys::kPlatformAppBackgroundScripts |
315 }; | 314 }; |
316 return std::vector<std::string>(keys, keys + arraysize(keys)); | 315 return std::vector<std::string>(keys, keys + arraysize(keys)); |
317 } | 316 } |
318 | 317 |
319 } // namespace extensions | 318 } // namespace extensions |
OLD | NEW |