| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "tonic/dart_library_provider_files.h" | 5 #include "tonic/dart_library_provider_files.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 callback.Run(pipe.consumer_handle.Pass()); | 55 callback.Run(pipe.consumer_handle.Pass()); |
| 56 | 56 |
| 57 base::FilePath source(name); | 57 base::FilePath source(name); |
| 58 scoped_refptr<base::SingleThreadTaskRunner> runner = | 58 scoped_refptr<base::SingleThreadTaskRunner> runner = |
| 59 base::MessageLoop::current()->task_runner(); | 59 base::MessageLoop::current()->task_runner(); |
| 60 mojo::common::CopyFromFile(source, pipe.producer_handle.Pass(), 0, | 60 mojo::common::CopyFromFile(source, pipe.producer_handle.Pass(), 0, |
| 61 runner.get(), base::Bind(&CopyComplete, source)); | 61 runner.get(), base::Bind(&CopyComplete, source)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 std::string DartLibraryProviderFiles::CanonicalizePackageURL(std::string url) { | 64 std::string DartLibraryProviderFiles::CanonicalizePackageURL(std::string url) { |
| 65 DCHECK(StartsWithASCII(url, "package:", true)); | 65 DCHECK(base::StartsWithASCII(url, "package:", true)); |
| 66 ReplaceFirstSubstringAfterOffset(&url, 0, "package:", ""); | 66 base::ReplaceFirstSubstringAfterOffset(&url, 0, "package:", ""); |
| 67 return package_root_.Append(url).AsUTF8Unsafe(); | 67 return package_root_.Append(url).AsUTF8Unsafe(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 Dart_Handle DartLibraryProviderFiles::CanonicalizeURL(Dart_Handle library, | 70 Dart_Handle DartLibraryProviderFiles::CanonicalizeURL(Dart_Handle library, |
| 71 Dart_Handle url) { | 71 Dart_Handle url) { |
| 72 std::string string = StdStringFromDart(url); | 72 std::string string = StdStringFromDart(url); |
| 73 if (StartsWithASCII(string, "dart:", true)) | 73 if (base::StartsWithASCII(string, "dart:", true)) |
| 74 return url; | 74 return url; |
| 75 if (StartsWithASCII(string, "package:", true)) | 75 if (base::StartsWithASCII(string, "package:", true)) |
| 76 return StdStringToDart(CanonicalizePackageURL(string)); | 76 return StdStringToDart(CanonicalizePackageURL(string)); |
| 77 base::FilePath base_path(StdStringFromDart(Dart_LibraryUrl(library))); | 77 base::FilePath base_path(StdStringFromDart(Dart_LibraryUrl(library))); |
| 78 base::FilePath resolved_path = base_path.DirName().Append(string); | 78 base::FilePath resolved_path = base_path.DirName().Append(string); |
| 79 base::FilePath normalized_path = SimplifyPath(resolved_path); | 79 base::FilePath normalized_path = SimplifyPath(resolved_path); |
| 80 return StdStringToDart(normalized_path.AsUTF8Unsafe()); | 80 return StdStringToDart(normalized_path.AsUTF8Unsafe()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 } // namespace tonic | 83 } // namespace tonic |
| OLD | NEW |