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

Unified Diff: net/base/mac/url_conversions.mm

Issue 773373002: Update from https://crrev.com/306706 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/mac/url_conversions.h ('k') | net/base/mac/url_conversions_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/mac/url_conversions.mm
diff --git a/net/base/mac/url_conversions.mm b/net/base/mac/url_conversions.mm
new file mode 100644
index 0000000000000000000000000000000000000000..3171c6fde6538a6051f218c3e585478dcd82f7db
--- /dev/null
+++ b/net/base/mac/url_conversions.mm
@@ -0,0 +1,56 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "net/base/mac/url_conversions.h"
+
+#import <Foundation/Foundation.h>
+
+#include "base/mac/scoped_nsobject.h"
+#include "net/base/escape.h"
+#include "url/gurl.h"
+#include "url/url_canon.h"
+
+namespace net {
+
+NSURL* NSURLWithGURL(const GURL& url) {
+ if (!url.is_valid())
+ return nil;
+
+ // NSURL strictly enforces RFC 1738 which requires that certain characters
+ // are always encoded. These characters are: "<", ">", """, "#", "%", "{",
+ // "}", "|", "\", "^", "~", "[", "]", and "`".
+ //
+ // GURL leaves some of these characters unencoded in the path, query, and
+ // ref. This function manually encodes those components, and then passes the
+ // result to NSURL.
+ GURL::Replacements replacements;
+ std::string escaped_path = EscapeNSURLPrecursor(url.path());
+ std::string escaped_query = EscapeNSURLPrecursor(url.query());
+ std::string escaped_ref = EscapeNSURLPrecursor(url.ref());
+ if (!escaped_path.empty()) {
+ replacements.SetPath(escaped_path.c_str(),
+ url::Component(0, escaped_path.size()));
+ }
+ if (!escaped_query.empty()) {
+ replacements.SetQuery(escaped_query.c_str(),
+ url::Component(0, escaped_query.size()));
+ }
+ if (!escaped_ref.empty()) {
+ replacements.SetRef(escaped_ref.c_str(),
+ url::Component(0, escaped_ref.size()));
+ }
+ GURL escaped_url = url.ReplaceComponents(replacements);
+
+ base::scoped_nsobject<NSString> escaped_url_string(
+ [[NSString alloc] initWithUTF8String:escaped_url.spec().c_str()]);
+ return [NSURL URLWithString:escaped_url_string];
+}
+
+GURL GURLWithNSURL(NSURL* url) {
+ if (url)
+ return GURL([[url absoluteString] UTF8String]);
+ return GURL();
+}
+
+} // namespace net
« no previous file with comments | « net/base/mac/url_conversions.h ('k') | net/base/mac/url_conversions_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698