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

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

Issue 256022: Loads local resources from current locale subtree if available, if not it fal... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_file_util.h" 5 #include "chrome/browser/extensions/extension_file_util.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 if (!ValidateExtension(extension.get(), error)) 130 if (!ValidateExtension(extension.get(), error))
131 return NULL; 131 return NULL;
132 132
133 return extension.release(); 133 return extension.release();
134 } 134 }
135 135
136 bool ValidateExtension(Extension* extension, std::string* error) { 136 bool ValidateExtension(Extension* extension, std::string* error) {
137 // Validate icons exist. 137 // Validate icons exist.
138 for (std::map<int, std::string>::const_iterator iter = 138 for (std::map<int, std::string>::const_iterator iter =
139 extension->icons().begin(); iter != extension->icons().end(); ++iter) { 139 extension->icons().begin(); iter != extension->icons().end(); ++iter) {
140 if (!file_util::PathExists(extension->GetResourcePath(iter->second))) { 140 if (extension->GetResource(iter->second).GetFilePath().empty()) {
141 *error = StringPrintf("Could not load extension icon '%s'.", 141 *error = StringPrintf("Could not load extension icon '%s'.",
142 iter->second.c_str()); 142 iter->second.c_str());
143 return false; 143 return false;
144 } 144 }
145 } 145 }
146 146
147 // Theme resource validation. 147 // Theme resource validation.
148 if (extension->IsTheme()) { 148 if (extension->IsTheme()) {
149 DictionaryValue* images_value = extension->GetThemeImages(); 149 DictionaryValue* images_value = extension->GetThemeImages();
150 if (images_value) { 150 if (images_value) {
(...skipping 14 matching lines...) Expand all
165 165
166 // Themes cannot contain other extension types. 166 // Themes cannot contain other extension types.
167 return true; 167 return true;
168 } 168 }
169 169
170 // Validate that claimed script resources actually exist. 170 // Validate that claimed script resources actually exist.
171 for (size_t i = 0; i < extension->content_scripts().size(); ++i) { 171 for (size_t i = 0; i < extension->content_scripts().size(); ++i) {
172 const UserScript& script = extension->content_scripts()[i]; 172 const UserScript& script = extension->content_scripts()[i];
173 173
174 for (size_t j = 0; j < script.js_scripts().size(); j++) { 174 for (size_t j = 0; j < script.js_scripts().size(); j++) {
175 const FilePath& path = script.js_scripts()[j].path(); 175 const FilePath& path =
176 if (!file_util::PathExists(path)) { 176 script.js_scripts()[j].resource().GetFilePath();
177 if (path.empty()) {
177 *error = StringPrintf("Could not load '%s' for content script.", 178 *error = StringPrintf("Could not load '%s' for content script.",
178 WideToUTF8(path.ToWStringHack()).c_str()); 179 WideToUTF8(path.ToWStringHack()).c_str());
179 return false; 180 return false;
180 } 181 }
181 } 182 }
182 183
183 for (size_t j = 0; j < script.css_scripts().size(); j++) { 184 for (size_t j = 0; j < script.css_scripts().size(); j++) {
184 const FilePath& path = script.css_scripts()[j].path(); 185 const FilePath& path =
185 if (!file_util::PathExists(path)) { 186 script.css_scripts()[j].resource().GetFilePath();
187 if (path.empty()) {
186 *error = StringPrintf("Could not load '%s' for content script.", 188 *error = StringPrintf("Could not load '%s' for content script.",
187 WideToUTF8(path.ToWStringHack()).c_str()); 189 WideToUTF8(path.ToWStringHack()).c_str());
188 return false; 190 return false;
189 } 191 }
190 } 192 }
191 } 193 }
192 194
193 // Validate claimed plugin paths. 195 // Validate claimed plugin paths.
194 for (size_t i = 0; i < extension->plugins().size(); ++i) { 196 for (size_t i = 0; i < extension->plugins().size(); ++i) {
195 const Extension::PluginInfo& plugin = extension->plugins()[i]; 197 const Extension::PluginInfo& plugin = extension->plugins()[i];
(...skipping 16 matching lines...) Expand all
212 } 214 }
213 215
214 // Validate icon location for page actions. 216 // Validate icon location for page actions.
215 const ExtensionActionMap& page_actions = extension->page_actions(); 217 const ExtensionActionMap& page_actions = extension->page_actions();
216 for (ExtensionActionMap::const_iterator i(page_actions.begin()); 218 for (ExtensionActionMap::const_iterator i(page_actions.begin());
217 i != page_actions.end(); ++i) { 219 i != page_actions.end(); ++i) {
218 ExtensionAction* page_action = i->second; 220 ExtensionAction* page_action = i->second;
219 const std::vector<std::string>& icon_paths = page_action->icon_paths(); 221 const std::vector<std::string>& icon_paths = page_action->icon_paths();
220 for (std::vector<std::string>::const_iterator iter = icon_paths.begin(); 222 for (std::vector<std::string>::const_iterator iter = icon_paths.begin();
221 iter != icon_paths.end(); ++iter) { 223 iter != icon_paths.end(); ++iter) {
222 if (!file_util::PathExists(extension->GetResourcePath(*iter))) { 224 if (extension->GetResource(*iter).GetFilePath().empty()) {
223 *error = StringPrintf("Could not load icon '%s' for page action.", 225 *error = StringPrintf("Could not load icon '%s' for page action.",
224 iter->c_str()); 226 iter->c_str());
225 return false; 227 return false;
226 } 228 }
227 } 229 }
228 } 230 }
229 231
230 // Validate icon location for browser actions. 232 // Validate icon location for browser actions.
231 const ExtensionAction* browser_action = extension->browser_action(); 233 const ExtensionAction* browser_action = extension->browser_action();
232 if (browser_action) { 234 if (browser_action) {
233 const std::vector<std::string>& icon_paths = browser_action->icon_paths(); 235 const std::vector<std::string>& icon_paths = browser_action->icon_paths();
234 for (std::vector<std::string>::const_iterator iter = icon_paths.begin(); 236 for (std::vector<std::string>::const_iterator iter = icon_paths.begin();
235 iter != icon_paths.end(); ++iter) { 237 iter != icon_paths.end(); ++iter) {
236 if (!file_util::PathExists(extension->GetResourcePath(*iter))) { 238 if (extension->GetResource(*iter).GetFilePath().empty()) {
237 *error = StringPrintf("Could not load icon '%s' for browser action.", 239 *error = StringPrintf("Could not load icon '%s' for browser action.",
238 iter->c_str()); 240 iter->c_str());
239 return false; 241 return false;
240 } 242 }
241 } 243 }
242 } 244 }
243 245
244 // Check children of extension root to see if any of them start with _ and is 246 // Check children of extension root to see if any of them start with _ and is
245 // not on the reserved list. 247 // not on the reserved list.
246 if (!CheckForIllegalFilenames(extension->path(), error)) { 248 if (!CheckForIllegalFilenames(extension->path(), error)) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 "Filenames starting with \"_\" are reserved for use by the system.", 386 "Filenames starting with \"_\" are reserved for use by the system.",
385 filename.c_str()); 387 filename.c_str());
386 return false; 388 return false;
387 } 389 }
388 } 390 }
389 391
390 return true; 392 return true;
391 } 393 }
392 394
393 } // extension_file_util 395 } // extension_file_util
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_disabled_infobar_delegate.cc ('k') | chrome/browser/extensions/extension_l10n_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698