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

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

Issue 12253022: Manifest handler for all keys background-related. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_file_util.h" 5 #include "chrome/common/extensions/extension_file_util.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/json/json_file_value_serializer.h" 13 #include "base/json/json_file_value_serializer.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/stringprintf.h" 17 #include "base/stringprintf.h"
18 #include "base/threading/thread_restrictions.h" 18 #include "base/threading/thread_restrictions.h"
19 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
20 #include "chrome/common/chrome_constants.h" 20 #include "chrome/common/chrome_constants.h"
21 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
22 #include "chrome/common/extensions/api/extension_action/action_info.h" 22 #include "chrome/common/extensions/api/extension_action/action_info.h"
23 #include "chrome/common/extensions/api/extension_action/browser_action_handler.h " 23 #include "chrome/common/extensions/api/extension_action/browser_action_handler.h "
24 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" 24 #include "chrome/common/extensions/api/i18n/default_locale_handler.h"
25 #include "chrome/common/extensions/api/icons/icons_handler.h" 25 #include "chrome/common/extensions/api/icons/icons_handler.h"
26 #include "chrome/common/extensions/api/themes/theme_handler.h" 26 #include "chrome/common/extensions/api/themes/theme_handler.h"
27 #include "chrome/common/extensions/background_info.h"
27 #include "chrome/common/extensions/extension.h" 28 #include "chrome/common/extensions/extension.h"
28 #include "chrome/common/extensions/extension_l10n_util.h" 29 #include "chrome/common/extensions/extension_l10n_util.h"
29 #include "chrome/common/extensions/extension_manifest_constants.h" 30 #include "chrome/common/extensions/extension_manifest_constants.h"
30 #include "chrome/common/extensions/extension_messages.h" 31 #include "chrome/common/extensions/extension_messages.h"
31 #include "chrome/common/extensions/extension_resource.h" 32 #include "chrome/common/extensions/extension_resource.h"
32 #include "chrome/common/extensions/manifest.h" 33 #include "chrome/common/extensions/manifest.h"
33 #include "chrome/common/extensions/manifest_url_handler.h" 34 #include "chrome/common/extensions/manifest_url_handler.h"
34 #include "chrome/common/extensions/message_bundle.h" 35 #include "chrome/common/extensions/message_bundle.h"
35 #include "extensions/common/install_warning.h" 36 #include "extensions/common/install_warning.h"
36 #include "grit/generated_resources.h" 37 #include "grit/generated_resources.h"
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } 351 }
351 352
352 action = extensions::ActionInfo::GetBrowserActionInfo(extension); 353 action = extensions::ActionInfo::GetBrowserActionInfo(extension);
353 if (action && !action->default_icon.empty() && 354 if (action && !action->default_icon.empty() &&
354 !ValidateExtensionIconSet(action->default_icon, extension, 355 !ValidateExtensionIconSet(action->default_icon, extension,
355 IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED, error)) { 356 IDS_EXTENSION_LOAD_ICON_FOR_BROWSER_ACTION_FAILED, error)) {
356 return false; 357 return false;
357 } 358 }
358 359
359 // Validate that background scripts exist. 360 // Validate that background scripts exist.
360 for (size_t i = 0; i < extension->background_scripts().size(); ++i) { 361 const std::vector<std::string>& background_scripts =
362 extensions::BackgroundInfo::GetBackgroundScripts(extension);
363 for (size_t i = 0; i < background_scripts.size(); ++i) {
361 if (!file_util::PathExists( 364 if (!file_util::PathExists(
362 extension->GetResource( 365 extension->GetResource(background_scripts[i]).GetFilePath())) {
363 extension->background_scripts()[i]).GetFilePath())) {
364 *error = l10n_util::GetStringFUTF8( 366 *error = l10n_util::GetStringFUTF8(
365 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, 367 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED,
366 UTF8ToUTF16(extension->background_scripts()[i])); 368 UTF8ToUTF16(background_scripts[i]));
367 return false; 369 return false;
368 } 370 }
369 } 371 }
370 372
371 // Validate background page location, except for hosted apps, which should use 373 // Validate background page location, except for hosted apps, which should use
372 // an external URL. Background page for hosted apps are verified when the 374 // an external URL. Background page for hosted apps are verified when the
373 // extension is created (in Extension::InitFromValue) 375 // extension is created (in Extension::InitFromValue)
374 if (extension->has_background_page() && 376 if (extensions::BackgroundInfo::HasBackgroundPage(extension) &&
375 !extension->is_hosted_app() && 377 !extension->is_hosted_app() && background_scripts.empty()) {
376 extension->background_scripts().empty()) {
377 base::FilePath page_path = ExtensionURLToRelativeFilePath( 378 base::FilePath page_path = ExtensionURLToRelativeFilePath(
378 extension->GetBackgroundURL()); 379 extensions::BackgroundInfo::GetBackgroundURL(extension));
379 const base::FilePath path = extension->GetResource(page_path).GetFilePath(); 380 const base::FilePath path = extension->GetResource(page_path).GetFilePath();
380 if (path.empty() || !file_util::PathExists(path)) { 381 if (path.empty() || !file_util::PathExists(path)) {
381 *error = 382 *error =
382 l10n_util::GetStringFUTF8( 383 l10n_util::GetStringFUTF8(
383 IDS_EXTENSION_LOAD_BACKGROUND_PAGE_FAILED, 384 IDS_EXTENSION_LOAD_BACKGROUND_PAGE_FAILED,
384 page_path.LossyDisplayName()); 385 page_path.LossyDisplayName());
385 return false; 386 return false;
386 } 387 }
387 } 388 }
388 389
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 return base::FilePath(); 774 return base::FilePath();
774 } 775 }
775 return temp_path; 776 return temp_path;
776 } 777 }
777 778
778 void DeleteFile(const base::FilePath& path, bool recursive) { 779 void DeleteFile(const base::FilePath& path, bool recursive) {
779 file_util::Delete(path, recursive); 780 file_util::Delete(path, recursive);
780 } 781 }
781 782
782 } // namespace extension_file_util 783 } // namespace extension_file_util
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | chrome/common/extensions/extension_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698