| OLD | NEW |
| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 if (!ValidateExtension(extension.get(), error)) | 142 if (!ValidateExtension(extension.get(), error)) |
| 143 return NULL; | 143 return NULL; |
| 144 | 144 |
| 145 return extension.release(); | 145 return extension.release(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 bool ValidateExtension(Extension* extension, std::string* error) { | 148 bool ValidateExtension(Extension* extension, std::string* error) { |
| 149 // Validate icons exist. | 149 // Validate icons exist. |
| 150 for (std::map<int, std::string>::const_iterator iter = | 150 for (std::map<int, std::string>::const_iterator iter = |
| 151 extension->icons().begin(); iter != extension->icons().end(); ++iter) { | 151 extension->icons().begin(); iter != extension->icons().end(); ++iter) { |
| 152 if (extension->GetResource(iter->second).GetFilePath().empty()) { | 152 const FilePath path = extension->GetResource(iter->second).GetFilePath(); |
| 153 if (!file_util::PathExists(path)) { |
| 153 *error = StringPrintf("Could not load extension icon '%s'.", | 154 *error = StringPrintf("Could not load extension icon '%s'.", |
| 154 iter->second.c_str()); | 155 iter->second.c_str()); |
| 155 return false; | 156 return false; |
| 156 } | 157 } |
| 157 } | 158 } |
| 158 | 159 |
| 159 // Theme resource validation. | 160 // Theme resource validation. |
| 160 if (extension->IsTheme()) { | 161 if (extension->IsTheme()) { |
| 161 DictionaryValue* images_value = extension->GetThemeImages(); | 162 DictionaryValue* images_value = extension->GetThemeImages(); |
| 162 if (images_value) { | 163 if (images_value) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 180 } | 181 } |
| 181 | 182 |
| 182 // Validate that claimed script resources actually exist. | 183 // Validate that claimed script resources actually exist. |
| 183 for (size_t i = 0; i < extension->content_scripts().size(); ++i) { | 184 for (size_t i = 0; i < extension->content_scripts().size(); ++i) { |
| 184 const UserScript& script = extension->content_scripts()[i]; | 185 const UserScript& script = extension->content_scripts()[i]; |
| 185 | 186 |
| 186 for (size_t j = 0; j < script.js_scripts().size(); j++) { | 187 for (size_t j = 0; j < script.js_scripts().size(); j++) { |
| 187 const UserScript::File& js_script = script.js_scripts()[j]; | 188 const UserScript::File& js_script = script.js_scripts()[j]; |
| 188 const FilePath& path = ExtensionResource::GetFilePath( | 189 const FilePath& path = ExtensionResource::GetFilePath( |
| 189 js_script.extension_root(), js_script.relative_path()); | 190 js_script.extension_root(), js_script.relative_path()); |
| 190 if (path.empty()) { | 191 if (!file_util::PathExists(path)) { |
| 191 *error = StringPrintf("Could not load '%s' for content script.", | 192 *error = StringPrintf("Could not load '%s' for content script.", |
| 192 WideToUTF8(path.ToWStringHack()).c_str()); | 193 WideToUTF8(path.ToWStringHack()).c_str()); |
| 193 return false; | 194 return false; |
| 194 } | 195 } |
| 195 } | 196 } |
| 196 | 197 |
| 197 for (size_t j = 0; j < script.css_scripts().size(); j++) { | 198 for (size_t j = 0; j < script.css_scripts().size(); j++) { |
| 198 const UserScript::File& css_script = script.css_scripts()[j]; | 199 const UserScript::File& css_script = script.css_scripts()[j]; |
| 199 const FilePath& path = ExtensionResource::GetFilePath( | 200 const FilePath& path = ExtensionResource::GetFilePath( |
| 200 css_script.extension_root(), css_script.relative_path()); | 201 css_script.extension_root(), css_script.relative_path()); |
| 201 if (path.empty()) { | 202 if (!file_util::PathExists(path)) { |
| 202 *error = StringPrintf("Could not load '%s' for content script.", | 203 *error = StringPrintf("Could not load '%s' for content script.", |
| 203 WideToUTF8(path.ToWStringHack()).c_str()); | 204 WideToUTF8(path.ToWStringHack()).c_str()); |
| 204 return false; | 205 return false; |
| 205 } | 206 } |
| 206 } | 207 } |
| 207 } | 208 } |
| 208 | 209 |
| 209 // Validate claimed plugin paths. | 210 // Validate claimed plugin paths. |
| 210 for (size_t i = 0; i < extension->plugins().size(); ++i) { | 211 for (size_t i = 0; i < extension->plugins().size(); ++i) { |
| 211 const Extension::PluginInfo& plugin = extension->plugins()[i]; | 212 const Extension::PluginInfo& plugin = extension->plugins()[i]; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 228 } | 229 } |
| 229 | 230 |
| 230 // Validate icon location for page actions. | 231 // Validate icon location for page actions. |
| 231 ExtensionAction* page_action = extension->page_action(); | 232 ExtensionAction* page_action = extension->page_action(); |
| 232 if (page_action) { | 233 if (page_action) { |
| 233 std::vector<std::string> icon_paths(*page_action->icon_paths()); | 234 std::vector<std::string> icon_paths(*page_action->icon_paths()); |
| 234 if (!page_action->default_icon_path().empty()) | 235 if (!page_action->default_icon_path().empty()) |
| 235 icon_paths.push_back(page_action->default_icon_path()); | 236 icon_paths.push_back(page_action->default_icon_path()); |
| 236 for (std::vector<std::string>::iterator iter = icon_paths.begin(); | 237 for (std::vector<std::string>::iterator iter = icon_paths.begin(); |
| 237 iter != icon_paths.end(); ++iter) { | 238 iter != icon_paths.end(); ++iter) { |
| 238 if (extension->GetResource(*iter).GetFilePath().empty()) { | 239 if (!file_util::PathExists(extension->GetResource(*iter).GetFilePath())) { |
| 239 *error = StringPrintf("Could not load icon '%s' for page action.", | 240 *error = StringPrintf("Could not load icon '%s' for page action.", |
| 240 iter->c_str()); | 241 iter->c_str()); |
| 241 return false; | 242 return false; |
| 242 } | 243 } |
| 243 } | 244 } |
| 244 } | 245 } |
| 245 | 246 |
| 246 // Validate icon location for browser actions. | 247 // Validate icon location for browser actions. |
| 247 // Note: browser actions don't use the icon_paths(). | 248 // Note: browser actions don't use the icon_paths(). |
| 248 ExtensionAction* browser_action = extension->browser_action(); | 249 ExtensionAction* browser_action = extension->browser_action(); |
| 249 if (browser_action) { | 250 if (browser_action) { |
| 250 std::string default_icon_path = browser_action->default_icon_path(); | 251 std::string path = browser_action->default_icon_path(); |
| 251 if (!default_icon_path.empty()) { | 252 if (!path.empty() && |
| 252 if (extension->GetResource(default_icon_path).GetFilePath().empty()) { | 253 !file_util::PathExists(extension->GetResource(path).GetFilePath())) { |
| 253 *error = StringPrintf("Could not load icon '%s' for browser action.", | 254 *error = StringPrintf("Could not load icon '%s' for browser action.", |
| 254 default_icon_path.c_str()); | 255 path.c_str()); |
| 255 return false; | 256 return false; |
| 256 } | 257 } |
| 258 } |
| 259 |
| 260 // Validate background page location. |
| 261 if (!extension->background_url().is_empty()) { |
| 262 const std::string page_path = extension->background_url().path(); |
| 263 const FilePath path = extension->GetResource(page_path).GetFilePath(); |
| 264 if (!file_util::PathExists(path)) { |
| 265 *error = StringPrintf("Could not load background page '%s'.", |
| 266 WideToUTF8(path.ToWStringHack()).c_str()); |
| 267 return false; |
| 257 } | 268 } |
| 258 } | 269 } |
| 259 | 270 |
| 260 // Check children of extension root to see if any of them start with _ and is | 271 // Check children of extension root to see if any of them start with _ and is |
| 261 // not on the reserved list. | 272 // not on the reserved list. |
| 262 if (!CheckForIllegalFilenames(extension->path(), error)) { | 273 if (!CheckForIllegalFilenames(extension->path(), error)) { |
| 263 return false; | 274 return false; |
| 264 } | 275 } |
| 265 | 276 |
| 266 return true; | 277 return true; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 "Filenames starting with \"_\" are reserved for use by the system.", | 412 "Filenames starting with \"_\" are reserved for use by the system.", |
| 402 filename.c_str()); | 413 filename.c_str()); |
| 403 return false; | 414 return false; |
| 404 } | 415 } |
| 405 } | 416 } |
| 406 | 417 |
| 407 return true; | 418 return true; |
| 408 } | 419 } |
| 409 | 420 |
| 410 } // namespace extension_file_util | 421 } // namespace extension_file_util |
| OLD | NEW |