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

Side by Side Diff: extensions/common/file_util.cc

Issue 229813002: Move extensions manifest IconsHandler to //extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments (icons-handler) Created 6 years, 8 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
« no previous file with comments | « extensions/common/file_util.h ('k') | extensions/common/manifest_handlers/icons_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "extensions/common/file_util.h" 5 #include "extensions/common/file_util.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/utf_string_conversions.h"
14 #include "extensions/common/constants.h" 15 #include "extensions/common/constants.h"
16 #include "extensions/common/extension.h"
17 #include "extensions/common/extension_icon_set.h"
15 #include "extensions/common/extension_l10n_util.h" 18 #include "extensions/common/extension_l10n_util.h"
19 #include "extensions/common/message_bundle.h"
16 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
17 #include "net/base/escape.h" 21 #include "net/base/escape.h"
18 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
19 #include "url/gurl.h" 23 #include "url/gurl.h"
20 24
21 namespace extensions { 25 namespace extensions {
22 namespace file_util { 26 namespace file_util {
27 namespace {
28
29 // Returns true if the given file path exists and is not zero-length.
30 bool ValidateFilePath(const base::FilePath& path) {
31 int64 size = 0;
32 if (!base::PathExists(path) ||
33 !base::GetFileSize(path, &size) ||
34 size == 0) {
35 return false;
36 }
37
38 return true;
39 }
40
41 } // namespace
23 42
24 base::FilePath ExtensionURLToRelativeFilePath(const GURL& url) { 43 base::FilePath ExtensionURLToRelativeFilePath(const GURL& url) {
25 std::string url_path = url.path(); 44 std::string url_path = url.path();
26 if (url_path.empty() || url_path[0] != '/') 45 if (url_path.empty() || url_path[0] != '/')
27 return base::FilePath(); 46 return base::FilePath();
28 47
29 // Drop the leading slashes and convert %-encoded UTF8 to regular UTF8. 48 // Drop the leading slashes and convert %-encoded UTF8 to regular UTF8.
30 std::string file_path = net::UnescapeURLComponent(url_path, 49 std::string file_path = net::UnescapeURLComponent(url_path,
31 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS); 50 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS);
32 size_t skip = file_path.find_first_not_of("/\\"); 51 size_t skip = file_path.find_first_not_of("/\\");
(...skipping 24 matching lines...) Expand all
57 76
58 base::FilePath path = root.AppendASCII(host).Append(relative_path); 77 base::FilePath path = root.AppendASCII(host).Append(relative_path);
59 if (!base::PathExists(path)) 78 if (!base::PathExists(path))
60 return base::FilePath(); 79 return base::FilePath();
61 path = base::MakeAbsoluteFilePath(path); 80 path = base::MakeAbsoluteFilePath(path);
62 if (path.empty() || !root.IsParent(path)) 81 if (path.empty() || !root.IsParent(path))
63 return base::FilePath(); 82 return base::FilePath();
64 return path; 83 return path;
65 } 84 }
66 85
86 bool ValidateExtensionIconSet(const ExtensionIconSet& icon_set,
87 const Extension* extension,
88 int error_message_id,
89 std::string* error) {
90 for (ExtensionIconSet::IconMap::const_iterator iter = icon_set.map().begin();
91 iter != icon_set.map().end();
92 ++iter) {
93 const base::FilePath path =
94 extension->GetResource(iter->second).GetFilePath();
95 if (!ValidateFilePath(path)) {
96 *error = l10n_util::GetStringFUTF8(error_message_id,
97 base::UTF8ToUTF16(iter->second));
98 return false;
99 }
100 }
101 return true;
102 }
103
67 MessageBundle* LoadMessageBundle( 104 MessageBundle* LoadMessageBundle(
68 const base::FilePath& extension_path, 105 const base::FilePath& extension_path,
69 const std::string& default_locale, 106 const std::string& default_locale,
70 std::string* error) { 107 std::string* error) {
71 error->clear(); 108 error->clear();
72 // Load locale information if available. 109 // Load locale information if available.
73 base::FilePath locale_path = extension_path.Append(kLocaleFolder); 110 base::FilePath locale_path = extension_path.Append(kLocaleFolder);
74 if (!base::PathExists(locale_path)) 111 if (!base::PathExists(locale_path))
75 return NULL; 112 return NULL;
76 113
(...skipping 11 matching lines...) Expand all
88 extension_l10n_util::LoadMessageCatalogs( 125 extension_l10n_util::LoadMessageCatalogs(
89 locale_path, 126 locale_path,
90 default_locale, 127 default_locale,
91 extension_l10n_util::CurrentLocaleOrDefault(), 128 extension_l10n_util::CurrentLocaleOrDefault(),
92 locales, 129 locales,
93 error); 130 error);
94 131
95 return message_bundle; 132 return message_bundle;
96 } 133 }
97 134
98 MessageBundle::SubstitutionMap* LoadMessageBundleSubstitutionMap( 135 std::map<std::string, std::string>* LoadMessageBundleSubstitutionMap(
99 const base::FilePath& extension_path, 136 const base::FilePath& extension_path,
100 const std::string& extension_id, 137 const std::string& extension_id,
101 const std::string& default_locale) { 138 const std::string& default_locale) {
102 MessageBundle::SubstitutionMap* returnValue = 139 std::map<std::string, std::string>* return_value =
103 new MessageBundle::SubstitutionMap(); 140 new std::map<std::string, std::string>();
104 if (!default_locale.empty()) { 141 if (!default_locale.empty()) {
105 // Touch disk only if extension is localized. 142 // Touch disk only if extension is localized.
106 std::string error; 143 std::string error;
107 scoped_ptr<MessageBundle> bundle( 144 scoped_ptr<MessageBundle> bundle(
108 LoadMessageBundle(extension_path, default_locale, &error)); 145 LoadMessageBundle(extension_path, default_locale, &error));
109 146
110 if (bundle.get()) 147 if (bundle.get())
111 *returnValue = *bundle->dictionary(); 148 *return_value = *bundle->dictionary();
112 } 149 }
113 150
114 // Add @@extension_id reserved message here, so it's available to 151 // Add @@extension_id reserved message here, so it's available to
115 // non-localized extensions too. 152 // non-localized extensions too.
116 returnValue->insert( 153 return_value->insert(
117 std::make_pair(MessageBundle::kExtensionIdKey, extension_id)); 154 std::make_pair(MessageBundle::kExtensionIdKey, extension_id));
118 155
119 return returnValue; 156 return return_value;
120 } 157 }
121 158
122 } // namespace file_util 159 } // namespace file_util
123 } // namespace extensions 160 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/file_util.h ('k') | extensions/common/manifest_handlers/icons_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698