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

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

Issue 640403002: Drop refs to net::EmbeddedTestServer / net::File{Path,URL} utils in mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use DecodeURLEscapeSequences Created 6 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/shell/filename_util.h"
6
7 #include "base/files/file_path.h"
8 #include "base/path_service.h"
9 #include "base/strings/string_util.h"
10 #include "url/gurl.h"
11 #include "url/url_canon_internal.h"
12 #include "url/url_util.h"
13
14 namespace mojo {
15
16 // Prefix to prepend to get a file URL.
17 static const base::FilePath::CharType kFileURLPrefix[] =
18 FILE_PATH_LITERAL("file:///");
brettw 2014/10/20 17:26:36 You wan only two slashes here since you're appendi
19
20 GURL FilePathToFileURL(const base::FilePath& path) {
21 // Produce a URL like "file:///C:/foo" for a regular file, or
22 // "file://///server/path" for UNC. The URL canonicalizer will fix up the
23 // latter case to be the canonical UNC form: "file://server/path"
24 base::FilePath::StringType url_string(kFileURLPrefix);
25 if (!path.IsAbsolute()) {
26 base::FilePath current_dir;
27 PathService::Get(base::DIR_CURRENT, &current_dir);
28 url_string.append(current_dir.value());
29 url_string.push_back(base::FilePath::kSeparators[0]);
30 }
31 url_string.append(path.value());
32
33 // Now do replacement of some characters. Since we assume the input is a
34 // literal filename, anything the URL parser might consider special should
35 // be escaped here.
36
37 // must be the first substitution since others will introduce percents as the
brettw 2014/10/20 17:26:37 Should be a complete sentence.
38 // escape character
39 ReplaceSubstringsAfterOffset(
40 &url_string, 0, FILE_PATH_LITERAL("%"), FILE_PATH_LITERAL("%25"));
41
42 // semicolon is supposed to be some kind of separator according to RFC 2396
43 ReplaceSubstringsAfterOffset(
44 &url_string, 0, FILE_PATH_LITERAL(";"), FILE_PATH_LITERAL("%3B"));
45
46 ReplaceSubstringsAfterOffset(
47 &url_string, 0, FILE_PATH_LITERAL("#"), FILE_PATH_LITERAL("%23"));
48
49 ReplaceSubstringsAfterOffset(
50 &url_string, 0, FILE_PATH_LITERAL("?"), FILE_PATH_LITERAL("%3F"));
51
52 #if defined(OS_POSIX)
53 ReplaceSubstringsAfterOffset(
54 &url_string, 0, FILE_PATH_LITERAL("\\"), FILE_PATH_LITERAL("%5C"));
55 #endif
56
57 return GURL(url_string);
58 }
59
60 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698