OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 27 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
28 #include "chrome/common/extensions/manifest_handlers/theme_handler.h" | 28 #include "chrome/common/extensions/manifest_handlers/theme_handler.h" |
29 #include "chrome/common/extensions/message_bundle.h" | 29 #include "chrome/common/extensions/message_bundle.h" |
30 #include "extensions/common/constants.h" | 30 #include "extensions/common/constants.h" |
31 #include "extensions/common/extension_resource.h" | 31 #include "extensions/common/extension_resource.h" |
32 #include "extensions/common/install_warning.h" | 32 #include "extensions/common/install_warning.h" |
33 #include "extensions/common/manifest.h" | 33 #include "extensions/common/manifest.h" |
34 #include "extensions/common/manifest_constants.h" | 34 #include "extensions/common/manifest_constants.h" |
35 #include "extensions/common/manifest_handler.h" | 35 #include "extensions/common/manifest_handler.h" |
36 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
37 #include "net/base/escape.h" | |
38 #include "net/base/file_stream.h" | 37 #include "net/base/file_stream.h" |
39 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
40 | 39 |
41 using extensions::Extension; | 40 using extensions::Extension; |
42 using extensions::ExtensionResource; | 41 using extensions::ExtensionResource; |
43 using extensions::Manifest; | 42 using extensions::Manifest; |
44 | 43 |
45 namespace errors = extensions::manifest_errors; | 44 namespace errors = extensions::manifest_errors; |
46 | 45 |
47 namespace { | 46 namespace { |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 "Cannot load extension with file or directory name %s. " | 485 "Cannot load extension with file or directory name %s. " |
487 "Filenames starting with \"_\" are reserved for use by the system.", | 486 "Filenames starting with \"_\" are reserved for use by the system.", |
488 filename.c_str()); | 487 filename.c_str()); |
489 return false; | 488 return false; |
490 } | 489 } |
491 } | 490 } |
492 | 491 |
493 return true; | 492 return true; |
494 } | 493 } |
495 | 494 |
496 base::FilePath ExtensionURLToRelativeFilePath(const GURL& url) { | |
497 std::string url_path = url.path(); | |
498 if (url_path.empty() || url_path[0] != '/') | |
499 return base::FilePath(); | |
500 | |
501 // Drop the leading slashes and convert %-encoded UTF8 to regular UTF8. | |
502 std::string file_path = net::UnescapeURLComponent(url_path, | |
503 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS); | |
504 size_t skip = file_path.find_first_not_of("/\\"); | |
505 if (skip != file_path.npos) | |
506 file_path = file_path.substr(skip); | |
507 | |
508 base::FilePath path = base::FilePath::FromUTF8Unsafe(file_path); | |
509 | |
510 // It's still possible for someone to construct an annoying URL whose path | |
511 // would still wind up not being considered relative at this point. | |
512 // For example: chrome-extension://id/c:////foo.html | |
513 if (path.IsAbsolute()) | |
514 return base::FilePath(); | |
515 | |
516 return path; | |
517 } | |
518 | |
519 base::FilePath ExtensionResourceURLToFilePath(const GURL& url, | |
520 const base::FilePath& root) { | |
521 std::string host = net::UnescapeURLComponent(url.host(), | |
522 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS); | |
523 if (host.empty()) | |
524 return base::FilePath(); | |
525 | |
526 base::FilePath relative_path = ExtensionURLToRelativeFilePath(url); | |
527 if (relative_path.empty()) | |
528 return base::FilePath(); | |
529 | |
530 base::FilePath path = root.AppendASCII(host).Append(relative_path); | |
531 if (!base::PathExists(path)) | |
532 return base::FilePath(); | |
533 path = base::MakeAbsoluteFilePath(path); | |
534 if (path.empty() || !root.IsParent(path)) | |
535 return base::FilePath(); | |
536 return path; | |
537 } | |
538 | |
539 base::FilePath GetInstallTempDir(const base::FilePath& extensions_dir) { | 495 base::FilePath GetInstallTempDir(const base::FilePath& extensions_dir) { |
540 // We do file IO in this function, but only when the current profile's | 496 // We do file IO in this function, but only when the current profile's |
541 // Temp directory has never been used before, or in a rare error case. | 497 // Temp directory has never been used before, or in a rare error case. |
542 // Developers are not likely to see these situations often, so do an | 498 // Developers are not likely to see these situations often, so do an |
543 // explicit thread check. | 499 // explicit thread check. |
544 base::ThreadRestrictions::AssertIOAllowed(); | 500 base::ThreadRestrictions::AssertIOAllowed(); |
545 | 501 |
546 // Create the temp directory as a sub-directory of the Extensions directory. | 502 // Create the temp directory as a sub-directory of the Extensions directory. |
547 // This guarantees it is on the same file system as the extension's eventual | 503 // This guarantees it is on the same file system as the extension's eventual |
548 // install target. | 504 // install target. |
(...skipping 17 matching lines...) Expand all Loading... |
566 return base::FilePath(); | 522 return base::FilePath(); |
567 } | 523 } |
568 return temp_path; | 524 return temp_path; |
569 } | 525 } |
570 | 526 |
571 void DeleteFile(const base::FilePath& path, bool recursive) { | 527 void DeleteFile(const base::FilePath& path, bool recursive) { |
572 base::DeleteFile(path, recursive); | 528 base::DeleteFile(path, recursive); |
573 } | 529 } |
574 | 530 |
575 } // namespace extension_file_util | 531 } // namespace extension_file_util |
OLD | NEW |