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

Unified Diff: url/mojo/url_gurl.h

Issue 1760643004: Add mojo struct traits for GURL so that it can be sent over mojoms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move to mojom namespace and add security owners Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « url/mojo/url.mojom ('k') | url/mojo/url_test.mojom » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: url/mojo/url_gurl.h
diff --git a/url/mojo/url_gurl.h b/url/mojo/url_gurl.h
new file mode 100644
index 0000000000000000000000000000000000000000..a2760ee71c89942f7e70f0b619424da7bd93b2ae
--- /dev/null
+++ b/url/mojo/url_gurl.h
@@ -0,0 +1,39 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
dcheng 2016/03/03 16:23:53 Can we have some sort of naming convention for fil
jam 2016/03/03 21:25:12 sure that seems reasonable, renamed
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/strings/string_piece.h"
+#include "url/gurl.h"
+#include "url/mojo/url.mojom.h"
+
+namespace mojo {
+
+// copied from content/public/common/content_constants.cc: make that file use
+// this definition.
+const size_t kMaxURLChars = 2 * 1024 * 1024;
dcheng 2016/03/03 16:23:53 Nit: Strictly speaking, this should be kMaxUrlChar
jam 2016/03/03 21:25:12 Done.
+
+template <>
+struct StructTraits<url::mojom::Url, GURL> {
+ static base::StringPiece url(const GURL& r) {
dcheng 2016/03/03 16:23:53 Is there documentation on how StructTraits work? H
jam 2016/03/03 21:25:12 Looks like Ken already replied.
+ if (r.possibly_invalid_spec().length() > kMaxURLChars || !r.is_valid()) {
+ return base::StringPiece();
+ }
+
+ return base::StringPiece(r.possibly_invalid_spec().c_str(),
+ r.possibly_invalid_spec().length());
+ }
+ static bool Read(url::mojom::Url::Reader r, GURL* out) {
+ if (r.url().length() > kMaxURLChars) {
+ *out = GURL();
+ return false;
+ }
+ *out = GURL(r.url());
+ if (!r.url().empty() && !out->is_valid()) {
+ *out = GURL();
+ return false;
+ }
+ return true;
+ }
+};
+
+}
« no previous file with comments | « url/mojo/url.mojom ('k') | url/mojo/url_test.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698