Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Move CrxFile, FileReader, ExtensionResource to src/extensions.

Also move ExtensionResource to extensions namespace.
Also clean up the GenerateId and ShouldLocalizeManfest interfaces.

BUG=159265


Review URL: https://chromiumcodereview.appspot.com/12578008

git-svn-id: http://src.chromium.org/svn/trunk/src/chrome/browser@190078 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
  • Loading branch information...
commit e48505730b60363d77689c743391a7295165f464 1 parent 33cb102
authored March 23, 2013

Showing 76 changed files with 172 additions and 492 deletions. Show diff stats Hide diff stats

  1. 1  DEPS
  2. 7  background/background_application_list_model.cc
  3. 1  browser_process_impl.cc
  4. 12  chromeos/accessibility/accessibility_util.cc
  5. 2  component_updater/component_unpacker.cc
  6. 5  extensions/all_urls_apitest.cc
  7. 2  extensions/api/developer_private/developer_private_api.cc
  8. 2  extensions/api/tabs/tabs_api.cc
  9. 4  extensions/api/tabs/tabs_api.h
  10. 4  extensions/component_loader.cc
  11. 5  extensions/component_loader_unittest.cc
  12. 4  extensions/convert_user_script.cc
  13. 5  extensions/convert_user_script_unittest.cc
  14. 4  extensions/convert_web_app.cc
  15. 2  extensions/convert_web_app_unittest.cc
  16. 68  extensions/crx_file.cc
  17. 76  extensions/crx_file.h
  18. 1  extensions/crx_installer.cc
  19. 2  extensions/crx_installer.h
  20. 3  extensions/extension_browsertest.cc
  21. 2  extensions/extension_browsertest.h
  22. 7  extensions/extension_creator.cc
  23. 3  extensions/extension_function_test_utils.cc
  24. 6  extensions/extension_icon_image.cc
  25. 11  extensions/extension_icon_manager.cc
  26. 5  extensions/extension_icon_manager_unittest.cc
  27. 4  extensions/extension_install_prompt.cc
  28. 6  extensions/extension_protocols.cc
  29. 1  extensions/extension_service.cc
  30. 17  extensions/extension_service_unittest.cc
  31. 3  extensions/extension_ui_unittest.cc
  32. 4  extensions/extension_uninstall_dialog.cc
  33. 4  extensions/extension_web_ui.cc
  34. 34  extensions/file_reader.cc
  35. 43  extensions/file_reader.h
  36. 106  extensions/file_reader_unittest.cc
  37. 2  extensions/image_loader.h
  38. 3  extensions/image_loader_unittest.cc
  39. 3  extensions/installed_loader.cc
  40. 11  extensions/sandboxed_unpacker.cc
  41. 7  extensions/sandboxed_unpacker_unittest.cc
  42. 2  extensions/tab_helper.cc
  43. 3  extensions/unpacked_installer.cc
  44. 19  extensions/updater/extension_updater_unittest.cc
  45. 2  extensions/user_script_master.cc
  46. 5  managed_mode/managed_mode_site_list.cc
  47. 6  managed_mode/managed_mode_site_list.h
  48. 3  managed_mode/managed_user_service.cc
  49. 10  sync/test/integration/sync_app_helper.cc
  50. 32  sync/test/integration/sync_extension_helper.cc
  51. 3  sync/test/integration/sync_extension_helper.h
  52. 5  sync/test/integration/themes_helper.cc
  53. 7  sync_file_system/drive_file_sync_service_mock_unittest.cc
  54. 8  themes/browser_theme_pack.cc
  55. 2  ui/ash/launcher/chrome_launcher_controller_per_app.cc
  56. 1  ui/ash/launcher/chrome_launcher_controller_per_browser.cc
  57. 1  ui/cocoa/extensions/browser_action_button.mm
  58. 4  ui/cocoa/infobars/extension_infobar_controller.mm
  59. 1  ui/cocoa/location_bar/location_bar_view_mac.mm
  60. 1  ui/cocoa/location_bar/page_action_decoration.mm
  61. 1  ui/gtk/browser_actions_toolbar_gtk.cc
  62. 1  ui/gtk/create_application_shortcuts_dialog_gtk.cc
  63. 11  ui/gtk/infobars/extension_infobar_gtk.cc
  64. 1  ui/gtk/infobars/extension_infobar_gtk.h
  65. 1  ui/gtk/location_bar_view_gtk.cc
  66. 1  ui/views/create_application_shortcut_view.cc
  67. 1  ui/views/frame/browser_view.cc
  68. 7  ui/views/infobars/extension_infobar.cc
  69. 1  ui/views/location_bar/page_action_image_view.cc
  70. 3  ui/views/script_bubble_view.cc
  71. 10  ui/web_applications/web_app_ui.cc
  72. 11  ui/webui/extensions/extension_icon_source.cc
  73. 5  ui/webui/extensions/extension_icon_source.h
  74. 1  ui/webui/extensions/extension_settings_handler.h
  75. 1  ui/webui/ntp/app_launcher_handler.cc
  76. 1  ui/webui/ntp/favicon_webui_handler.cc
1  DEPS
@@ -16,6 +16,7 @@ include_rules = [
16 16
   "+content/public/browser",
17 17
   "+device/bluetooth",
18 18
   "+device/media_transfer_protocol",
  19
+  "+extensions/browser",
19 20
   "+extensions/common",
20 21
   "+google/cacheinvalidation",  # Sync invalidation API protobuf files.
21 22
   "+google_apis",
7  background/background_application_list_model.cc
@@ -25,10 +25,10 @@
25 25
 #include "chrome/common/extensions/extension.h"
26 26
 #include "chrome/common/extensions/extension_constants.h"
27 27
 #include "chrome/common/extensions/extension_icon_set.h"
28  
-#include "chrome/common/extensions/extension_resource.h"
29 28
 #include "chrome/common/extensions/permissions/permission_set.h"
30 29
 #include "content/public/browser/notification_details.h"
31 30
 #include "content/public/browser/notification_source.h"
  31
+#include "extensions/common/extension_resource.h"
32 32
 #include "ui/base/l10n/l10n_util_collator.h"
33 33
 #include "ui/gfx/image/image.h"
34 34
 #include "ui/gfx/image/image_skia.h"
@@ -154,8 +154,9 @@ void BackgroundApplicationListModel::Application::OnImageLoaded(
154 154
 
155 155
 void BackgroundApplicationListModel::Application::RequestIcon(
156 156
     extension_misc::ExtensionIcons size) {
157  
-  ExtensionResource resource = extensions::IconsInfo::GetIconResource(
158  
-      extension_, size, ExtensionIconSet::MATCH_BIGGER);
  157
+  extensions::ExtensionResource resource =
  158
+      extensions::IconsInfo::GetIconResource(
  159
+          extension_, size, ExtensionIconSet::MATCH_BIGGER);
159 160
   extensions::ImageLoader::Get(model_->profile_)->LoadImageAsync(
160 161
       extension_, resource, gfx::Size(size, size),
161 162
       base::Bind(&Application::OnImageLoaded, AsWeakPtr()));
1  browser_process_impl.cc
@@ -72,7 +72,6 @@
72 72
 #include "chrome/common/chrome_paths.h"
73 73
 #include "chrome/common/chrome_switches.h"
74 74
 #include "chrome/common/extensions/extension_l10n_util.h"
75  
-#include "chrome/common/extensions/extension_resource.h"
76 75
 #include "chrome/common/pref_names.h"
77 76
 #include "chrome/common/switch_utils.h"
78 77
 #include "chrome/common/url_constants.h"
12  chromeos/accessibility/accessibility_util.cc
@@ -22,14 +22,12 @@
22 22
 #include "chrome/browser/extensions/component_loader.h"
23 23
 #include "chrome/browser/extensions/extension_service.h"
24 24
 #include "chrome/browser/extensions/extension_system.h"
25  
-#include "chrome/browser/extensions/file_reader.h"
26 25
 #include "chrome/browser/profiles/profile.h"
27 26
 #include "chrome/browser/profiles/profile_manager.h"
28 27
 #include "chrome/browser/speech/tts_controller.h"
29 28
 #include "chrome/browser/ui/singleton_tabs.h"
30 29
 #include "chrome/common/extensions/extension.h"
31 30
 #include "chrome/common/extensions/extension_messages.h"
32  
-#include "chrome/common/extensions/extension_resource.h"
33 31
 #include "chrome/common/extensions/user_script.h"
34 32
 #include "chrome/common/pref_names.h"
35 33
 #include "chrome/common/url_constants.h"
@@ -39,6 +37,8 @@
39 37
 #include "content/public/browser/render_view_host.h"
40 38
 #include "content/public/browser/web_contents.h"
41 39
 #include "content/public/browser/web_ui.h"
  40
+#include "extensions/browser/file_reader.h"
  41
+#include "extensions/common/extension_resource.h"
42 42
 #include "googleurl/src/gurl.h"
43 43
 #include "grit/browser_resources.h"
44 44
 #include "grit/generated_resources.h"
@@ -65,7 +65,7 @@ class ContentScriptLoader {
65 65
 
66 66
   // Call this once with the ExtensionResource corresponding to each
67 67
   // content script to be loaded.
68  
-  void AppendScript(ExtensionResource resource) {
  68
+  void AppendScript(extensions::ExtensionResource resource) {
69 69
     resources_.push(resource);
70 70
   }
71 71
 
@@ -77,7 +77,7 @@ class ContentScriptLoader {
77 77
       return;
78 78
     }
79 79
 
80  
-    ExtensionResource resource = resources_.front();
  80
+    extensions::ExtensionResource resource = resources_.front();
81 81
     resources_.pop();
82 82
     scoped_refptr<FileReader> reader(new FileReader(resource, base::Bind(
83 83
         &ContentScriptLoader::OnFileLoaded, base::Unretained(this))));
@@ -109,7 +109,7 @@ class ContentScriptLoader {
109 109
   std::string extension_id_;
110 110
   int render_process_id_;
111 111
   int render_view_id_;
112  
-  std::queue<ExtensionResource> resources_;
  112
+  std::queue<extensions::ExtensionResource> resources_;
113 113
 };
114 114
 
115 115
 void UpdateChromeOSAccessibilityHistograms() {
@@ -201,7 +201,7 @@ void EnableSpokenFeedback(bool enabled,
201 201
         const extensions::UserScript& script = extension->content_scripts()[i];
202 202
         for (size_t j = 0; j < script.js_scripts().size(); ++j) {
203 203
           const extensions::UserScript::File &file = script.js_scripts()[j];
204  
-          ExtensionResource resource = extension->GetResource(
  204
+          extensions::ExtensionResource resource = extension->GetResource(
205 205
               file.relative_path());
206 206
           loader->AppendScript(resource);
207 207
         }
2  component_updater/component_unpacker.cc
@@ -13,11 +13,11 @@
13 13
 #include "base/stringprintf.h"
14 14
 #include "base/strings/string_number_conversions.h"
15 15
 #include "chrome/browser/component_updater/component_updater_service.h"
16  
-#include "chrome/browser/extensions/crx_file.h"
17 16
 #include "chrome/common/extensions/extension_constants.h"
18 17
 #include "chrome/common/zip.h"
19 18
 #include "crypto/secure_hash.h"
20 19
 #include "crypto/signature_verifier.h"
  20
+#include "extensions/common/crx_file.h"
21 21
 
22 22
 using crypto::SecureHash;
23 23
 
5  extensions/all_urls_apitest.cc
@@ -10,6 +10,7 @@
10 10
 #include "chrome/browser/ui/browser.h"
11 11
 #include "chrome/common/extensions/extension.h"
12 12
 #include "chrome/test/base/ui_test_utils.h"
  13
+#include "extensions/common/id_util.h"
13 14
 
14 15
 const std::string kAllUrlsTarget =
15 16
     "files/extensions/api_test/all_urls/index.html";
@@ -31,8 +32,8 @@ IN_PROC_BROWSER_TEST_F(AllUrlsApiTest, MAYBE_WhitelistedExtension) {
31 32
 
32 33
   // Then add the two extensions to the whitelist.
33 34
   extensions::Extension::ScriptingWhitelist whitelist;
34  
-  whitelist.push_back(extensions::Extension::GenerateIdForPath(extension_dir1));
35  
-  whitelist.push_back(extensions::Extension::GenerateIdForPath(extension_dir2));
  35
+  whitelist.push_back(extensions::id_util::GenerateIdForPath(extension_dir1));
  36
+  whitelist.push_back(extensions::id_util::GenerateIdForPath(extension_dir2));
36 37
   extensions::Extension::SetScriptingWhitelist(whitelist);
37 38
 
38 39
   // Then load extensions.
2  extensions/api/developer_private/developer_private_api.cc
@@ -30,13 +30,13 @@
30 30
 #include "chrome/common/extensions/api/icons/icons_handler.h"
31 31
 #include "chrome/common/extensions/background_info.h"
32 32
 #include "chrome/common/extensions/extension_icon_set.h"
33  
-#include "chrome/common/extensions/extension_resource.h"
34 33
 #include "chrome/common/extensions/manifest_url_handler.h"
35 34
 #include "content/public/browser/browser_thread.h"
36 35
 #include "content/public/browser/render_process_host.h"
37 36
 #include "content/public/browser/render_view_host.h"
38 37
 #include "content/public/browser/web_contents.h"
39 38
 #include "extensions/common/constants.h"
  39
+#include "extensions/common/extension_resource.h"
40 40
 #include "grit/chromium_strings.h"
41 41
 #include "grit/generated_resources.h"
42 42
 #include "net/base/net_util.h"
2  extensions/api/tabs/tabs_api.cc
@@ -27,7 +27,6 @@
27 27
 #include "chrome/browser/extensions/extension_host.h"
28 28
 #include "chrome/browser/extensions/extension_service.h"
29 29
 #include "chrome/browser/extensions/extension_tab_util.h"
30  
-#include "chrome/browser/extensions/file_reader.h"
31 30
 #include "chrome/browser/extensions/script_executor.h"
32 31
 #include "chrome/browser/extensions/tab_helper.h"
33 32
 #include "chrome/browser/extensions/window_controller.h"
@@ -73,6 +72,7 @@
73 72
 #include "content/public/browser/web_contents.h"
74 73
 #include "content/public/browser/web_contents_view.h"
75 74
 #include "content/public/common/url_constants.h"
  75
+#include "extensions/browser/file_reader.h"
76 76
 #include "extensions/common/constants.h"
77 77
 #include "extensions/common/error_utils.h"
78 78
 #include "skia/ext/image_operations.h"
4  extensions/api/tabs/tabs_api.h
@@ -10,10 +10,10 @@
10 10
 
11 11
 #include "base/compiler_specific.h"
12 12
 #include "chrome/browser/extensions/extension_function.h"
13  
-#include "chrome/common/extensions/extension_resource.h"
14 13
 #include "chrome/common/extensions/user_script.h"
15 14
 #include "content/public/browser/notification_observer.h"
16 15
 #include "content/public/browser/notification_registrar.h"
  16
+#include "extensions/common/extension_resource.h"
17 17
 #include "googleurl/src/gurl.h"
18 18
 
19 19
 class BackingStore;
@@ -262,7 +262,7 @@ class ExecuteCodeInTabFunction : public AsyncExtensionFunction {
262 262
 
263 263
   // Contains extension resource built from path of file which is
264 264
   // specified in JSON arguments.
265  
-  ExtensionResource resource_;
  265
+  extensions::ExtensionResource resource_;
266 266
 };
267 267
 
268 268
 class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction {
4  extensions/component_loader.cc
@@ -24,6 +24,7 @@
24 24
 #include "components/user_prefs/pref_registry_syncable.h"
25 25
 #include "content/public/browser/notification_details.h"
26 26
 #include "content/public/browser/notification_source.h"
  27
+#include "extensions/common/id_util.h"
27 28
 #include "grit/browser_resources.h"
28 29
 #include "ui/base/resource/resource_bundle.h"
29 30
 
@@ -50,10 +51,9 @@ std::string GenerateId(const DictionaryValue* manifest,
50 51
                        const base::FilePath& path) {
51 52
   std::string raw_key;
52 53
   std::string id_input;
53  
-  std::string id;
54 54
   CHECK(manifest->GetString(extension_manifest_keys::kPublicKey, &raw_key));
55 55
   CHECK(Extension::ParsePEMKeyBytes(raw_key, &id_input));
56  
-  CHECK(Extension::GenerateId(id_input, &id));
  56
+  std::string id = id_util::GenerateId(id_input);
57 57
   return id;
58 58
 }
59 59
 
5  extensions/component_loader_unittest.cc
@@ -17,6 +17,7 @@
17 17
 #include "chrome/common/pref_names.h"
18 18
 #include "chrome/test/base/testing_pref_service_syncable.h"
19 19
 #include "components/user_prefs/pref_registry_syncable.h"
  20
+#include "extensions/common/constants.h"
20 21
 #include "testing/gtest/include/gtest/gtest.h"
21 22
 
22 23
 using extensions::Extension;
@@ -92,8 +93,8 @@ class ComponentLoaderTest : public testing::Test {
92 93
 
93 94
     // Read in the extension manifest.
94 95
     ASSERT_TRUE(file_util::ReadFileToString(
95  
-        extension_path_.Append(Extension::kManifestFilename),
96  
-                               &manifest_contents_));
  96
+        extension_path_.Append(kManifestFilename),
  97
+        &manifest_contents_));
97 98
 
98 99
     // Register the user prefs that ComponentLoader will read.
99 100
     prefs_.registry()->RegisterStringPref(
4  extensions/convert_user_script.cc
@@ -22,6 +22,7 @@
22 22
 #include "chrome/common/extensions/extension_manifest_constants.h"
23 23
 #include "chrome/common/extensions/user_script.h"
24 24
 #include "crypto/sha2.h"
  25
+#include "extensions/common/constants.h"
25 26
 #include "googleurl/src/gurl.h"
26 27
 
27 28
 namespace keys = extension_manifest_keys;
@@ -155,8 +156,7 @@ scoped_refptr<Extension> ConvertUserScriptToExtension(
155 156
 
156 157
   root->Set(keys::kContentScripts, content_scripts);
157 158
 
158  
-  base::FilePath manifest_path = temp_dir.path().Append(
159  
-      Extension::kManifestFilename);
  159
+  base::FilePath manifest_path = temp_dir.path().Append(kManifestFilename);
160 160
   JSONFileValueSerializer serializer(manifest_path);
161 161
   if (!serializer.Serialize(*root)) {
162 162
     *error = ASCIIToUTF16("Could not write JSON.");
5  extensions/convert_user_script_unittest.cc
@@ -14,6 +14,7 @@
14 14
 #include "chrome/browser/extensions/convert_user_script.h"
15 15
 #include "chrome/common/chrome_paths.h"
16 16
 #include "chrome/common/extensions/extension.h"
  17
+#include "extensions/common/constants.h"
17 18
 #include "testing/gtest/include/gtest/gtest.h"
18 19
 
19 20
 namespace extensions {
@@ -74,7 +75,7 @@ TEST(ExtensionFromUserScript, Basic) {
74 75
   EXPECT_TRUE(file_util::PathExists(
75 76
       extension->path().Append(script.js_scripts()[0].relative_path())));
76 77
   EXPECT_TRUE(file_util::PathExists(
77  
-      extension->path().Append(Extension::kManifestFilename)));
  78
+      extension->path().Append(kManifestFilename)));
78 79
 }
79 80
 
80 81
 TEST(ExtensionFromUserScript, NoMetdata) {
@@ -120,7 +121,7 @@ TEST(ExtensionFromUserScript, NoMetdata) {
120 121
   EXPECT_TRUE(file_util::PathExists(
121 122
       extension->path().Append(script.js_scripts()[0].relative_path())));
122 123
   EXPECT_TRUE(file_util::PathExists(
123  
-      extension->path().Append(Extension::kManifestFilename)));
  124
+      extension->path().Append(kManifestFilename)));
124 125
 }
125 126
 
126 127
 TEST(ExtensionFromUserScript, NotUTF8) {
4  extensions/convert_web_app.cc
@@ -25,6 +25,7 @@
25 25
 #include "chrome/common/extensions/extension_manifest_constants.h"
26 26
 #include "chrome/common/web_apps.h"
27 27
 #include "crypto/sha2.h"
  28
+#include "extensions/common/constants.h"
28 29
 #include "googleurl/src/gurl.h"
29 30
 #include "third_party/skia/include/core/SkBitmap.h"
30 31
 #include "ui/gfx/codec/png_codec.h"
@@ -143,8 +144,7 @@ scoped_refptr<Extension> ConvertWebAppToExtension(
143 144
   }
144 145
 
145 146
   // Write the manifest.
146  
-  base::FilePath manifest_path = temp_dir.path().Append(
147  
-      Extension::kManifestFilename);
  147
+  base::FilePath manifest_path = temp_dir.path().Append(kManifestFilename);
148 148
   JSONFileValueSerializer serializer(manifest_path);
149 149
   if (!serializer.Serialize(*root)) {
150 150
     LOG(ERROR) << "Could not serialize manifest.";
2  extensions/convert_web_app_unittest.cc
@@ -19,9 +19,9 @@
19 19
 #include "chrome/common/extensions/api/icons/icons_handler.h"
20 20
 #include "chrome/common/extensions/extension.h"
21 21
 #include "chrome/common/extensions/extension_icon_set.h"
22  
-#include "chrome/common/extensions/extension_resource.h"
23 22
 #include "chrome/common/extensions/permissions/permission_set.h"
24 23
 #include "chrome/common/web_apps.h"
  24
+#include "extensions/common/extension_resource.h"
25 25
 #include "extensions/common/url_pattern.h"
26 26
 #include "googleurl/src/gurl.h"
27 27
 #include "testing/gtest/include/gtest/gtest.h"
68  extensions/crx_file.cc
... ...
@@ -1,68 +0,0 @@
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
3  
-// found in the LICENSE file.
4  
-
5  
-#include "chrome/browser/extensions/crx_file.h"
6  
-
7  
-namespace extensions {
8  
-
9  
-namespace {
10  
-
11  
-// The current version of the crx format.
12  
-static const uint32 kCurrentVersion = 2;
13  
-
14  
-// The maximum size the crx parser will tolerate for a public key.
15  
-static const uint32 kMaxPublicKeySize = 1 << 16;
16  
-
17  
-// The maximum size the crx parser will tolerate for a signature.
18  
-static const uint32 kMaxSignatureSize = 1 << 16;
19  
-
20  
-}  // namespace
21  
-
22  
-// The magic string embedded in the header.
23  
-const char kCrxFileHeaderMagic[] = "Cr24";
24  
-
25  
-scoped_ptr<CrxFile> CrxFile::Parse(const CrxFile::Header& header,
26  
-                                   CrxFile::Error* error) {
27  
-  if (HeaderIsValid(header, error))
28  
-    return scoped_ptr<CrxFile>(new CrxFile(header));
29  
-  return scoped_ptr<CrxFile>();
30  
-}
31  
-
32  
-scoped_ptr<CrxFile> CrxFile::Create(const uint32 key_size,
33  
-                                    const uint32 signature_size,
34  
-                                    CrxFile::Error* error) {
35  
-  CrxFile::Header header;
36  
-  memcpy(&header.magic, kCrxFileHeaderMagic, kCrxFileHeaderMagicSize);
37  
-  header.version = kCurrentVersion;
38  
-  header.key_size = key_size;
39  
-  header.signature_size = signature_size;
40  
-  if (HeaderIsValid(header, error))
41  
-    return scoped_ptr<CrxFile>(new CrxFile(header));
42  
-  return scoped_ptr<CrxFile>();
43  
-}
44  
-
45  
-CrxFile::CrxFile(const Header& header) : header_(header) {
46  
-}
47  
-
48  
-bool CrxFile::HeaderIsValid(const CrxFile::Header& header,
49  
-                            CrxFile::Error* error) {
50  
-  bool valid = false;
51  
-  if (strncmp(kCrxFileHeaderMagic, header.magic, sizeof(header.magic)))
52  
-    *error = kWrongMagic;
53  
-  else if (header.version != kCurrentVersion)
54  
-    *error = kInvalidVersion;
55  
-  else if (header.key_size > kMaxPublicKeySize)
56  
-    *error = kInvalidKeyTooLarge;
57  
-  else if (header.key_size == 0)
58  
-    *error = kInvalidKeyTooSmall;
59  
-  else if (header.signature_size > kMaxSignatureSize)
60  
-    *error = kInvalidSignatureTooLarge;
61  
-  else if (header.signature_size == 0)
62  
-    *error = kInvalidSignatureTooSmall;
63  
-  else
64  
-    valid = true;
65  
-  return valid;
66  
-}
67  
-
68  
-}  // namespace extensions
76  extensions/crx_file.h
... ...
@@ -1,76 +0,0 @@
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
3  
-// found in the LICENSE file.
4  
-
5  
-#ifndef CHROME_BROWSER_EXTENSIONS_CRX_FILE_H_
6  
-#define CHROME_BROWSER_EXTENSIONS_CRX_FILE_H_
7  
-
8  
-#include <sys/types.h>
9  
-#include "base/basictypes.h"
10  
-#include "base/memory/scoped_ptr.h"
11  
-
12  
-namespace extensions {
13  
-
14  
-// CRX files have a header that includes a magic key, version number, and
15  
-// some signature sizing information. Use CrxFile object to validate whether
16  
-// the header is valid or not.
17  
-class CrxFile {
18  
- public:
19  
-
20  
-  // The size of the magic character sequence at the beginning of each crx
21  
-  // file, in bytes. This should be a multiple of 4.
22  
-  static const size_t kCrxFileHeaderMagicSize = 4;
23  
-
24  
-  // This header is the first data at the beginning of an extension. Its
25  
-  // contents are purposely 32-bit aligned so that it can just be slurped into
26  
-  // a struct without manual parsing.
27  
-  struct Header {
28  
-    char magic[kCrxFileHeaderMagicSize];
29  
-    uint32 version;
30  
-    uint32 key_size;  // The size of the public key, in bytes.
31  
-    uint32 signature_size;  // The size of the signature, in bytes.
32  
-    // An ASN.1-encoded PublicKeyInfo structure follows.
33  
-    // The signature follows.
34  
-  };
35  
-
36  
-  enum Error {
37  
-    kWrongMagic,
38  
-    kInvalidVersion,
39  
-    kInvalidKeyTooLarge,
40  
-    kInvalidKeyTooSmall,
41  
-    kInvalidSignatureTooLarge,
42  
-    kInvalidSignatureTooSmall,
43  
-  };
44  
-
45  
-  // Construct a new CRX file header object with bytes of a header
46  
-  // read from a CRX file. If a null scoped_ptr is returned, |error|
47  
-  // contains an error code with additional information.
48  
-  static scoped_ptr<CrxFile> Parse(const Header& header, Error* error);
49  
-
50  
-  // Construct a new header for the given key and signature sizes.
51  
-  // Returns a null scoped_ptr if erroneous values of |key_size| and/or
52  
-  // |signature_size| are provided. |error| contains an error code with
53  
-  // additional information.
54  
-  // Use this constructor and then .header() to obtain the Header
55  
-  // for writing out to a CRX file.
56  
-  static scoped_ptr<CrxFile> Create(const uint32 key_size,
57  
-                                    const uint32 signature_size,
58  
-                                    Error* error);
59  
-
60  
-  // Returns the header structure for writing out to a CRX file.
61  
-  const Header& header() const { return header_; }
62  
-
63  
- private:
64  
-  Header header_;
65  
-
66  
-  // Constructor is private. Clients should use static factory methods above.
67  
-  explicit CrxFile(const Header& header);
68  
-
69  
-  // Checks the |header| for validity and returns true if the values are valid.
70  
-  // If false is returned, more detailed error code is returned in |error|.
71  
-  static bool HeaderIsValid(const Header& header, Error* error);
72  
-};
73  
-
74  
-}  // namespace extensions
75  
-
76  
-#endif  // CHROME_BROWSER_EXTENSIONS_CRX_FILE_H_
1  extensions/crx_installer.cc
@@ -23,6 +23,7 @@
23 23
 #include "base/version.h"
24 24
 #include "chrome/browser/extensions/convert_user_script.h"
25 25
 #include "chrome/browser/extensions/convert_web_app.h"
  26
+#include "chrome/browser/extensions/crx_installer_error.h"
26 27
 #include "chrome/browser/extensions/extension_error_reporter.h"
27 28
 #include "chrome/browser/extensions/extension_install_ui.h"
28 29
 #include "chrome/browser/extensions/extension_service.h"
2  extensions/crx_installer.h
@@ -12,7 +12,6 @@
12 12
 #include "base/memory/ref_counted.h"
13 13
 #include "base/memory/weak_ptr.h"
14 14
 #include "base/version.h"
15  
-#include "chrome/browser/extensions/crx_installer_error.h"
16 15
 #include "chrome/browser/extensions/extension_install_prompt.h"
17 16
 #include "chrome/browser/extensions/sandboxed_unpacker.h"
18 17
 #include "chrome/browser/extensions/webstore_installer.h"
@@ -30,6 +29,7 @@ class SequencedTaskRunner;
30 29
 }
31 30
 
32 31
 namespace extensions {
  32
+class CrxInstallerError;
33 33
 class ExtensionUpdaterTest;
34 34
 class RequirementsChecker;
35 35
 
3  extensions/extension_browsertest.cc
@@ -43,6 +43,7 @@
43 43
 #include "content/public/browser/notification_service.h"
44 44
 #include "content/public/browser/render_view_host.h"
45 45
 #include "content/public/test/browser_test_utils.h"
  46
+#include "extensions/common/constants.h"
46 47
 #include "sync/api/string_ordinal.h"
47 48
 
48 49
 using extensions::Extension;
@@ -231,7 +232,7 @@ const Extension* ExtensionBrowserTest::LoadExtensionAsComponentWithManifest(
231 232
 const Extension* ExtensionBrowserTest::LoadExtensionAsComponent(
232 233
     const base::FilePath& path) {
233 234
   return LoadExtensionAsComponentWithManifest(path,
234  
-                                              Extension::kManifestFilename);
  235
+                                              extensions::kManifestFilename);
235 236
 }
236 237
 
237 238
 base::FilePath ExtensionBrowserTest::PackExtension(
2  extensions/extension_browsertest.h
@@ -89,7 +89,7 @@ class ExtensionBrowserTest : virtual public InProcessBrowserTest,
89 89
 
90 90
   // Loads unpacked extension from |path| and imitates that it is a component
91 91
   // extension. Equivalent to
92  
-  // LoadExtensionAsComponentWithManifest(path, Extensions::kManifestFilename).
  92
+  // LoadExtensionAsComponentWithManifest(path, extensions::kManifestFilename).
93 93
   const extensions::Extension* LoadExtensionAsComponent(
94 94
       const base::FilePath& path);
95 95
 
7  extensions/extension_creator.cc
@@ -13,13 +13,14 @@
13 13
 #include "base/files/scoped_temp_dir.h"
14 14
 #include "base/memory/scoped_handle.h"
15 15
 #include "base/string_util.h"
16  
-#include "chrome/browser/extensions/crx_file.h"
17 16
 #include "chrome/browser/extensions/extension_creator_filter.h"
18 17
 #include "chrome/common/extensions/extension.h"
19 18
 #include "chrome/common/extensions/extension_file_util.h"
20 19
 #include "chrome/common/zip.h"
21 20
 #include "crypto/rsa_private_key.h"
22 21
 #include "crypto/signature_creator.h"
  22
+#include "extensions/common/crx_file.h"
  23
+#include "extensions/common/id_util.h"
23 24
 #include "grit/generated_resources.h"
24 25
 #include "ui/base/l10n/l10n_util.h"
25 26
 
@@ -97,9 +98,7 @@ bool ExtensionCreator::ValidateManifest(const base::FilePath& extension_dir,
97 98
   public_key.insert(public_key.begin(),
98 99
                     public_key_bytes.begin(), public_key_bytes.end());
99 100
 
100  
-  std::string extension_id;
101  
-  if (!Extension::GenerateId(public_key, &extension_id))
102  
-    return false;
  101
+  std::string extension_id = id_util::GenerateId(public_key);
103 102
 
104 103
   // Load the extension once. We don't really need it, but this does a lot of
105 104
   // useful validation of the structure.
3  extensions/extension_function_test_utils.cc
@@ -15,6 +15,7 @@
15 15
 #include "chrome/browser/ui/browser.h"
16 16
 #include "chrome/common/extensions/extension.h"
17 17
 #include "chrome/test/base/ui_test_utils.h"
  18
+#include "extensions/common/id_util.h"
18 19
 #include "testing/gtest/include/gtest/gtest.h"
19 20
 
20 21
 using content::WebContents;
@@ -135,7 +136,7 @@ scoped_refptr<Extension> CreateExtension(
135 136
   const base::FilePath test_extension_path;
136 137
   std::string id;
137 138
   if (!id_input.empty())
138  
-    CHECK(Extension::GenerateId(id_input, &id));
  139
+    id = extensions::id_util::GenerateId(id_input);
139 140
   scoped_refptr<Extension> extension(Extension::Create(
140 141
       test_extension_path,
141 142
       location,
6  extensions/extension_icon_image.cc
@@ -42,14 +42,14 @@ namespace {
42 42
 
43 43
 const int kMatchBiggerTreshold = 32;
44 44
 
45  
-ExtensionResource GetExtensionIconResource(
  45
+extensions::ExtensionResource GetExtensionIconResource(
46 46
     const extensions::Extension* extension,
47 47
     const ExtensionIconSet& icons,
48 48
     int size,
49 49
     ExtensionIconSet::MatchType match_type) {
50 50
   std::string path = icons.Get(size, match_type);
51 51
   if (path.empty())
52  
-    return ExtensionResource();
  52
+    return extensions::ExtensionResource();
53 53
 
54 54
   return extension->GetResource(path);
55 55
 }
@@ -167,7 +167,7 @@ gfx::ImageSkiaRep IconImage::LoadImageForScaleFactor(
167 167
   const int resource_size_in_pixel =
168 168
       static_cast<int>(resource_size_in_dip_ * scale);
169 169
 
170  
-  ExtensionResource resource;
  170
+  extensions::ExtensionResource resource;
171 171
 
172 172
   // Find extension resource for non bundled component extensions.
173 173
   // We try loading bigger image only if resource size is >= 32.
11  extensions/extension_icon_manager.cc
@@ -12,7 +12,7 @@
12 12
 #include "chrome/common/extensions/extension.h"
13 13
 #include "chrome/common/extensions/extension_constants.h"
14 14
 #include "chrome/common/extensions/extension_icon_set.h"
15  
-#include "chrome/common/extensions/extension_resource.h"
  15
+#include "extensions/common/extension_resource.h"
16 16
 #include "grit/theme_resources.h"
17 17
 #include "skia/ext/image_operations.h"
18 18
 #include "ui/base/resource/resource_bundle.h"
@@ -54,10 +54,11 @@ ExtensionIconManager::~ExtensionIconManager() {
54 54
 
55 55
 void ExtensionIconManager::LoadIcon(Profile* profile,
56 56
                                     const extensions::Extension* extension) {
57  
-  ExtensionResource icon_resource = extensions::IconsInfo::GetIconResource(
58  
-      extension,
59  
-      extension_misc::EXTENSION_ICON_BITTY,
60  
-      ExtensionIconSet::MATCH_BIGGER);
  57
+  extensions::ExtensionResource icon_resource =
  58
+      extensions::IconsInfo::GetIconResource(
  59
+          extension,
  60
+          extension_misc::EXTENSION_ICON_BITTY,
  61
+          ExtensionIconSet::MATCH_BIGGER);
61 62
   if (!icon_resource.extension_root().empty()) {
62 63
     // Insert into pending_icons_ first because LoadImage can call us back
63 64
     // synchronously if the image is already cached.
5  extensions/extension_icon_manager_unittest.cc
@@ -9,9 +9,9 @@
9 9
 #include "chrome/browser/extensions/extension_icon_manager.h"
10 10
 #include "chrome/common/chrome_paths.h"
11 11
 #include "chrome/common/extensions/extension.h"
12  
-#include "chrome/common/extensions/extension_resource.h"
13 12
 #include "chrome/test/base/testing_profile.h"
14 13
 #include "content/public/test/test_browser_thread.h"
  14
+#include "extensions/common/id_util.h"
15 15
 #include "testing/gtest/include/gtest/gtest.h"
16 16
 #include "ui/gfx/skia_util.h"
17 17
 
@@ -93,8 +93,7 @@ class TestIconManager : public ExtensionIconManager {
93 93
 // Returns the default icon that ExtensionIconManager gives when an extension
94 94
 // doesn't have an icon.
95 95
 SkBitmap GetDefaultIcon() {
96  
-  std::string dummy_id;
97  
-  EXPECT_TRUE(Extension::GenerateId(std::string("whatever"), &dummy_id));
  96
+  std::string dummy_id = extensions::id_util::GenerateId("whatever");
98 97
   ExtensionIconManager manager;
99 98
   return manager.GetIcon(dummy_id);
100 99
 }
4  extensions/extension_install_prompt.cc
@@ -29,13 +29,13 @@
29 29
 #include "chrome/common/extensions/extension_constants.h"
30 30
 #include "chrome/common/extensions/extension_icon_set.h"
31 31
 #include "chrome/common/extensions/extension_manifest_constants.h"
32  
-#include "chrome/common/extensions/extension_resource.h"
33 32
 #include "chrome/common/extensions/feature_switch.h"
34 33
 #include "chrome/common/extensions/manifest.h"
35 34
 #include "chrome/common/extensions/permissions/permission_set.h"
36 35
 #include "chrome/common/pref_names.h"
37 36
 #include "content/public/browser/web_contents.h"
38 37
 #include "content/public/browser/web_contents_view.h"
  38
+#include "extensions/common/extension_resource.h"
39 39
 #include "extensions/common/url_pattern.h"
40 40
 #include "grit/chromium_strings.h"
41 41
 #include "grit/generated_resources.h"
@@ -609,7 +609,7 @@ void ExtensionInstallPrompt::LoadImageIfNeeded() {
609 609
   }
610 610
 
611 611
   // Load the image asynchronously. For the response, check OnImageLoaded.
612  
-  ExtensionResource image = extensions::IconsInfo::GetIconResource(
  612
+  extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource(
613 613
       extension_,
614 614
       extension_misc::EXTENSION_ICON_LARGE,
615 615
       ExtensionIconSet::MATCH_BIGGER);
6  extensions/extension_protocols.cc
@@ -24,11 +24,11 @@
24 24
 #include "chrome/common/extensions/background_info.h"
25 25
 #include "chrome/common/extensions/extension.h"
26 26
 #include "chrome/common/extensions/extension_file_util.h"
27  
-#include "chrome/common/extensions/extension_resource.h"
28 27
 #include "chrome/common/extensions/web_accessible_resources_handler.h"
29 28
 #include "chrome/common/url_constants.h"
30 29
 #include "content/public/browser/resource_request_info.h"
31 30
 #include "extensions/common/constants.h"
  31
+#include "extensions/common/extension_resource.h"
32 32
 #include "googleurl/src/url_util.h"
33 33
 #include "grit/component_extension_resources_map.h"
34 34
 #include "net/base/mime_util.h"
@@ -191,7 +191,7 @@ class GeneratedBackgroundPageJob : public net::URLRequestSimpleJob {
191 191
   net::HttpResponseInfo response_info_;
192 192
 };
193 193
 
194  
-void ReadResourceFilePath(const ExtensionResource& resource,
  194
+void ReadResourceFilePath(const extensions::ExtensionResource& resource,
195 195
                           base::FilePath* file_path) {
196 196
   *file_path = resource.GetFilePath();
197 197
 }
@@ -241,7 +241,7 @@ class URLRequestExtensionJob : public net::URLRequestFileJob {
241 241
   }
242 242
 
243 243
   net::HttpResponseInfo response_info_;
244  
-  ExtensionResource resource_;
  244
+  extensions::ExtensionResource resource_;
245 245
   base::WeakPtrFactory<URLRequestExtensionJob> weak_factory_;
246 246
 };
247 247
 
1  extensions/extension_service.cc
@@ -83,7 +83,6 @@
83 83
 #include "chrome/common/extensions/extension_file_util.h"
84 84
 #include "chrome/common/extensions/extension_manifest_constants.h"
85 85
 #include "chrome/common/extensions/extension_messages.h"
86  
-#include "chrome/common/extensions/extension_resource.h"
87 86
 #include "chrome/common/extensions/feature_switch.h"
88 87
 #include "chrome/common/extensions/features/feature.h"
89 88
 #include "chrome/common/extensions/manifest.h"
17  extensions/extension_service_unittest.cc
@@ -68,7 +68,6 @@
68 68
 #include "chrome/common/extensions/extension.h"
69 69
 #include "chrome/common/extensions/extension_l10n_util.h"
70 70
 #include "chrome/common/extensions/extension_manifest_constants.h"
71  
-#include "chrome/common/extensions/extension_resource.h"
72 71
 #include "chrome/common/extensions/manifest_handler.h"
73 72
 #include "chrome/common/extensions/manifest_url_handler.h"
74 73
 #include "chrome/common/extensions/permissions/permission_set.h"
@@ -86,6 +85,8 @@
86 85
 #include "content/public/common/content_constants.h"
87 86
 #include "content/public/common/gpu_info.h"
88 87
 #include "content/public/test/test_browser_thread.h"
  88
+#include "extensions/common/constants.h"
  89
+#include "extensions/common/extension_resource.h"
89 90
 #include "extensions/common/url_pattern.h"
90 91
 #include "googleurl/src/gurl.h"
91 92
 #include "grit/browser_resources.h"
@@ -122,6 +123,7 @@ using extensions::CrxInstaller;
122 123
 using extensions::Extension;
123 124
 using extensions::ExtensionCreator;
124 125
 using extensions::ExtensionPrefs;
  126
+using extensions::ExtensionResource;
125 127
 using extensions::ExtensionSystem;
126 128
 using extensions::FeatureSwitch;
127 129
 using extensions::Manifest;
@@ -1929,7 +1931,7 @@ TEST_F(ExtensionServiceTest, PackExtension) {
1929 1931
   // Try packing with an invalid manifest.
1930 1932
   std::string invalid_manifest_content = "I am not a manifest.";
1931 1933
   ASSERT_TRUE(file_util::WriteFile(
1932  
-      temp_dir2.path().Append(Extension::kManifestFilename),
  1934
+      temp_dir2.path().Append(extensions::kManifestFilename),
1933 1935
       invalid_manifest_content.c_str(), invalid_manifest_content.size()));
1934 1936
   creator.reset(new ExtensionCreator());
1935 1937
   ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path,
@@ -2147,7 +2149,7 @@ TEST_F(ExtensionServiceTest, UnpackedExtensionCanChangeID) {
2147 2149
 
2148 2150
   base::FilePath extension_path = temp.path();
2149 2151
   base::FilePath manifest_path =
2150  
-      extension_path.Append(Extension::kManifestFilename);
  2152
+      extension_path.Append(extensions::kManifestFilename);
2151 2153
   base::FilePath manifest_no_key = data_dir_.
2152 2154
       AppendASCII("unpacked").
2153 2155
       AppendASCII("manifest_no_key.json");
@@ -2198,7 +2200,8 @@ TEST_F(ExtensionServiceTest, UnpackedExtensionMayContainSymlinkedFiles) {
2198 2200
   base::ScopedTempDir temp;
2199 2201
   ASSERT_TRUE(temp.CreateUniqueTempDir());
2200 2202
   base::FilePath extension_path = temp.path();
2201  
-  base::FilePath manifest = extension_path.Append(Extension::kManifestFilename);
  2203
+  base::FilePath manifest = extension_path.Append(
  2204
+      extensions::kManifestFilename);
2202 2205
   base::FilePath icon_symlink = extension_path.AppendASCII("icon.png");
2203 2206
   file_util::CopyFile(source_manifest, manifest);
2204 2207
   file_util::CreateSymbolicLink(source_icon, icon_symlink);
@@ -2637,7 +2640,7 @@ TEST_F(ExtensionServiceTest, LoadExtensionsCanDowngrade) {
2637 2640
   // to make it easier to change the version number.
2638 2641
   base::FilePath extension_path = temp.path();
2639 2642
   base::FilePath manifest_path =
2640  
-      extension_path.Append(Extension::kManifestFilename);
  2643
+      extension_path.Append(extensions::kManifestFilename);
2641 2644
   ASSERT_FALSE(file_util::PathExists(manifest_path));
2642 2645
 
2643 2646
   // Start with version 2.0.
@@ -3205,7 +3208,7 @@ TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) {
3205 3208
       .AppendASCII("1.0.0.0");
3206 3209
   std::string manifest;
3207 3210
   ASSERT_TRUE(file_util::ReadFileToString(
3208  
-      path.Append(Extension::kManifestFilename), &manifest));
  3211
+      path.Append(extensions::kManifestFilename), &manifest));
3209 3212
   service_->component_loader()->Add(manifest, path);
3210 3213
   service_->Init();
3211 3214
 
@@ -4741,7 +4744,7 @@ TEST_F(ExtensionServiceTest, ComponentExtensions) {
4741 4744
 
4742 4745
   std::string manifest;
4743 4746
   ASSERT_TRUE(file_util::ReadFileToString(
4744  
-      path.Append(Extension::kManifestFilename), &manifest));
  4747
+      path.Append(extensions::kManifestFilename), &manifest));
4745 4748
 
4746 4749
   service_->component_loader()->Add(manifest, path);
4747 4750
   service_->Init();
3  extensions/extension_ui_unittest.cc
@@ -15,6 +15,7 @@
15 15
 #include "chrome/common/extensions/extension.h"
16 16
 #include "chrome/test/base/testing_profile.h"
17 17
 #include "content/public/test/test_browser_thread.h"
  18
+#include "extensions/common/constants.h"
18 19
 #include "testing/gtest/include/gtest/gtest.h"
19 20
 
20 21
 using extensions::Extension;
@@ -66,7 +67,7 @@ class ExtensionUITest : public testing::Test {
66 67
     std::string error;
67 68
 
68 69
     base::FilePath manifest_path = extension_path.Append(
69  
-        Extension::kManifestFilename);
  70
+        extensions::kManifestFilename);
70 71
     scoped_ptr<DictionaryValue> extension_data(DeserializeJSONTestData(
71 72
         manifest_path, &error));
72 73
     EXPECT_EQ("", error);
4  extensions/extension_uninstall_dialog.cc
@@ -14,9 +14,9 @@
14 14
 #include "chrome/common/extensions/extension.h"
15 15
 #include "chrome/common/extensions/extension_constants.h"
16 16
 #include "chrome/common/extensions/extension_icon_set.h"
17  
-#include "chrome/common/extensions/extension_resource.h"
18 17
 #include "content/public/browser/notification_service.h"
19 18
 #include "content/public/browser/notification_source.h"
  19
+#include "extensions/common/extension_resource.h"
20 20
 #include "grit/generated_resources.h"
21 21
 #include "grit/theme_resources.h"
22 22
 #include "ui/base/resource/resource_bundle.h"
@@ -86,7 +86,7 @@ void ExtensionUninstallDialog::ConfirmUninstall(
86 86
     return;
87 87
 #endif
88 88
 
89  
-  ExtensionResource image = extensions::IconsInfo::GetIconResource(
  89
+  extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource(
90 90
       extension_,
91 91
       extension_misc::EXTENSION_ICON_LARGE,
92 92
       ExtensionIconSet::MATCH_BIGGER);
4  extensions/extension_web_ui.cc
@@ -23,7 +23,6 @@
23 23
 #include "chrome/common/extensions/extension.h"
24 24
 #include "chrome/common/extensions/extension_constants.h"
25 25
 #include "chrome/common/extensions/extension_icon_set.h"
26  
-#include "chrome/common/extensions/extension_resource.h"
27 26
 #include "chrome/common/url_constants.h"
28 27
 #include "components/user_prefs/pref_registry_syncable.h"
29 28
 #include "content/public/browser/navigation_controller.h"
@@ -31,6 +30,7 @@
31 30
 #include "content/public/browser/web_ui.h"
32 31
 #include "content/public/common/bindings_policy.h"
33 32
 #include "content/public/common/page_transition_types.h"
  33
+#include "extensions/common/extension_resource.h"
34 34
 #include "net/base/file_stream.h"
35 35
 #include "third_party/skia/include/core/SkBitmap.h"
36 36
 #include "ui/gfx/codec/png_codec.h"
@@ -419,7 +419,7 @@ void ExtensionWebUI::GetFaviconForURL(
419 419
   for (size_t i = 0; i < scale_factors.size(); ++i) {
420 420
     float scale = ui::GetScaleFactorScale(scale_factors[i]);
421 421
     int pixel_size = static_cast<int>(gfx::kFaviconSize * scale);
422  
-    ExtensionResource icon_resource =
  422
+    extensions::ExtensionResource icon_resource =
423 423
         extensions::IconsInfo::GetIconResource(extension,
424 424
                                                pixel_size,
425 425
                                                ExtensionIconSet::MATCH_BIGGER);
34  extensions/file_reader.cc
... ...
@@ -1,34 +0,0 @@
1  
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2  
-// Use of this source code is governed by a BSD-style license that can be
3  
-// found in the LICENSE file.
4  
-
5  
-#include "chrome/browser/extensions/file_reader.h"
6  
-
7  
-#include "base/bind.h"
8  
-#include "base/file_util.h"
9  
-#include "base/message_loop.h"
10  
-#include "chrome/common/extensions/extension_resource.h"
11  
-#include "content/public/browser/browser_thread.h"
12  
-
13  
-using content::BrowserThread;
14  
-
15  
-FileReader::FileReader(const ExtensionResource& resource,
16  
-                       const Callback& callback)
17  
-    : resource_(resource),
18  
-      callback_(callback),
19  
-      origin_loop_(MessageLoop::current()) {
20  
-}
21  
-
22  
-void FileReader::Start() {
23  
-  BrowserThread::PostTask(
24  
-      BrowserThread::FILE, FROM_HERE,
25  
-      base::Bind(&FileReader::ReadFileOnBackgroundThread, this));
26  
-}
27  
-
28  
-FileReader::~FileReader() {}
29  
-
30  
-void FileReader::ReadFileOnBackgroundThread() {
31  
-  std::string data;
32  
-  bool success = file_util::ReadFileToString(resource_.GetFilePath(), &data);
33  
-  origin_loop_->PostTask(FROM_HERE, base::Bind(callback_, success, data));
34  
-}
43  extensions/file_reader.h
... ...
@@ -1,43 +0,0 @@
1  
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2  
-// Use of this source code is governed by a BSD-style license that can be
3  
-// found in the LICENSE file.
4  
-
5  
-#ifndef CHROME_BROWSER_EXTENSIONS_FILE_READER_H_
6  
-#define CHROME_BROWSER_EXTENSIONS_FILE_READER_H_
7  
-
8  
-#include <string>
9  
-
10  
-#include "base/callback.h"
11  
-#include "base/memory/ref_counted.h"
12  
-#include "chrome/common/extensions/extension_resource.h"
13  
-
14  
-class MessageLoop;
15  
-
16  
-// This file defines an interface for reading a file asynchronously on a
17  
-// background thread.
18  
-// Consider abstracting out a FilePathProvider (ExtensionResource) and moving
19  
-// back to chrome/browser/net if other subsystems want to use it.
20  
-class FileReader : public base::RefCountedThreadSafe<FileReader> {
21  
- public:
22  
-  // Reports success or failure and the data of the file upon success.
23  
-  typedef base::Callback<void(bool, const std::string&)> Callback;
24  
-
25  
-  FileReader(const ExtensionResource& resource, const Callback& callback);
26  
-
27  
-  // Called to start reading the file on a background thread.  Upon completion,
28  
-  // the callback will be notified of the results.
29  
-  void Start();
30  
-
31  
- private:
32  
-  friend class base::RefCountedThreadSafe<FileReader>;
33  
-
34  
-  virtual ~FileReader();
35  
-
36  
-  void ReadFileOnBackgroundThread();
37  
-
38  
-  ExtensionResource resource_;
39  
-  Callback callback_;
40  
-  MessageLoop* origin_loop_;
41  
-};
42  
-
43  
-#endif  // CHROME_BROWSER_EXTENSIONS_FILE_READER_H_
106  extensions/file_reader_unittest.cc
... ...
@@ -1,106 +0,0 @@
1  
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2  
-// Use of this source code is governed by a BSD-style license that can be
3  
-// found in the LICENSE file.
4  
-
5  
-#include "base/bind.h"
6  
-#include "base/bind_helpers.h"
7  
-#include "base/file_util.h"
8  
-#include "base/files/file_path.h"
9  
-#include "base/message_loop.h"
10  
-#include "base/path_service.h"
11  
-#include "chrome/browser/extensions/file_reader.h"
12  
-#include "chrome/common/chrome_paths.h"
13  
-#include "chrome/common/extensions/extension.h"
14  
-#include "chrome/common/extensions/extension_resource.h"
15  
-#include "chrome/common/extensions/extension_test_util.h"
16  
-#include "content/public/test/test_browser_thread.h"
17  
-#include "testing/gtest/include/gtest/gtest.h"
18  
-
19  
-using content::BrowserThread;
20  
-
21  
-namespace {
22  
-
23  
-class FileReaderTest : public testing::Test {
24  
- public:
25  
-  FileReaderTest() : file_thread_(BrowserThread::FILE) {
26  
-    file_thread_.Start();
27  
-  }
28  
- private:
29  
-  MessageLoop message_loop_;
30  
-  content::TestBrowserThread file_thread_;
31  
-};
32  
-
33  
-class Receiver {
34  
- public:
35  
-  Receiver() : succeeded_(false) {
36  
-  }
37  
-
38  
-  FileReader::Callback NewCallback() {
39  
-    return base::Bind(&Receiver::DidReadFile, base::Unretained(this));
40  
-  }
41  
-
42  
-  bool succeeded() const { return succeeded_; }
43  
-  const std::string& data() const { return data_; }
44  
-
45  
- private:
46  
-  void DidReadFile(bool success, const std::string& data) {
47  
-    succeeded_ = success;
48  
-    data_ = data;
49  
-    MessageLoop::current()->Quit();
50  
-  }
51  
-
52  
-  bool succeeded_;
53  
-  std::string data_;
54  
-};
55  
-
56  
-void RunBasicTest(const char* filename) {
57  
-  base::FilePath path;
58  
-  PathService::Get(chrome::DIR_TEST_DATA, &path);
59  
-  std::string extension_id = extension_test_util::MakeId("test");
60  
-  ExtensionResource resource(extension_id, path,
61  
-                             base::FilePath().AppendASCII(filename));
62  
-  path = path.AppendASCII(filename);
63  
-
64  
-  std::string file_contents;
65  
-  bool file_exists = file_util::ReadFileToString(path, &file_contents);
66  
-
67  
-  Receiver receiver;
68  
-
69  
-  scoped_refptr<FileReader> file_reader(
70  
-      new FileReader(resource, receiver.NewCallback()));
71  
-  file_reader->Start();
72  
-
73  
-  MessageLoop::current()->Run();
74  
-
75  
-  EXPECT_EQ(file_exists, receiver.succeeded());
76  
-  EXPECT_EQ(file_contents, receiver.data());
77  
-}
78  
-
79  
-TEST_F(FileReaderTest, SmallFile) {
80  
-  RunBasicTest("title1.html");
81  
-}
82  
-
83  
-TEST_F(FileReaderTest, BiggerFile) {
84  
-  RunBasicTest("download-test1.lib");
85  
-}
86  
-
87  
-TEST_F(FileReaderTest, NonExistantFile) {
88  
-  base::FilePath path;
89  
-  PathService::Get(chrome::DIR_TEST_DATA, &path);
90  
-  std::string extension_id = extension_test_util::MakeId("test");
91  
-  ExtensionResource resource(extension_id, path, base::FilePath(
92  
-      FILE_PATH_LITERAL("file_that_does_not_exist")));
93  
-  path = path.AppendASCII("file_that_does_not_exist");
94  
-
95  
-  Receiver receiver;
96  
-
97  
-  scoped_refptr<FileReader> file_reader(
98  
-      new FileReader(resource, receiver.NewCallback()));
99  
-  file_reader->Start();
100  
-