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

Side by Side Diff: mojo/util/filename_util.cc

Issue 1109993002: Adds support for mojo apps to live in their own directory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge to trunk and move filename_util to own dir Created 5 years, 7 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
« no previous file with comments | « mojo/util/filename_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/runner/filename_util.h" 5 #include "mojo/util/filename_util.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h"
10 #include "url/gurl.h" 11 #include "url/gurl.h"
11 #include "url/url_canon_internal.h" 12 #include "url/url_canon_internal.h"
12 #include "url/url_util.h" 13 #include "url/url_util.h"
13 14
14 namespace mojo { 15 namespace mojo {
15 namespace shell { 16 namespace util {
16 17
17 // Prefix to prepend to get a file URL. 18 // Prefix to prepend to get a file URL.
18 static const base::FilePath::CharType kFileURLPrefix[] = 19 static const base::FilePath::CharType kFileURLPrefix[] =
19 FILE_PATH_LITERAL("file://"); 20 FILE_PATH_LITERAL("file://");
20 21
21 GURL FilePathToFileURL(const base::FilePath& path) { 22 GURL FilePathToFileURL(const base::FilePath& path) {
22 // Produce a URL like "file:///C:/foo" for a regular file, or 23 // Produce a URL like "file:///C:/foo" for a regular file, or
23 // "file://///server/path" for UNC. The URL canonicalizer will fix up the 24 // "file://///server/path" for UNC. The URL canonicalizer will fix up the
24 // latter case to be the canonical UNC form: "file://server/path" 25 // latter case to be the canonical UNC form: "file://server/path"
25 base::FilePath::StringType url_string(kFileURLPrefix); 26 base::FilePath::StringType url_string(kFileURLPrefix);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 GURL AddTrailingSlashIfNeeded(const GURL& url) { 62 GURL AddTrailingSlashIfNeeded(const GURL& url) {
62 if (!url.has_path() || *url.path().rbegin() == '/') 63 if (!url.has_path() || *url.path().rbegin() == '/')
63 return url; 64 return url;
64 65
65 std::string path(url.path() + '/'); 66 std::string path(url.path() + '/');
66 GURL::Replacements replacements; 67 GURL::Replacements replacements;
67 replacements.SetPathStr(path); 68 replacements.SetPathStr(path);
68 return url.ReplaceComponents(replacements); 69 return url.ReplaceComponents(replacements);
69 } 70 }
70 71
71 } // namespace shell 72 base::FilePath UrlToFilePath(const GURL& url) {
73 DCHECK(url.SchemeIsFile());
74 url::RawCanonOutputW<1024> output;
75 url::DecodeURLEscapeSequences(url.path().data(),
76 static_cast<int>(url.path().length()), &output);
77 base::string16 decoded_path = base::string16(output.data(), output.length());
78 #if defined(OS_WIN)
79 base::TrimString(decoded_path, L"/", &decoded_path);
80 base::FilePath path(decoded_path);
81 #else
82 base::FilePath path(base::UTF16ToUTF8(decoded_path));
83 #endif
84 return path;
85 }
86
87 } // namespace util
72 } // namespace mojo 88 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/util/filename_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698