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

Side by Side Diff: url/mojo/url_gurl_struct_traits.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: review comments Created 4 years, 9 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 2016 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 "base/strings/string_piece.h"
6 #include "url/gurl.h"
7 #include "url/mojo/url.mojom.h"
8
9 namespace mojo {
10
11 // copied from content/public/common/content_constants.cc: make that file use
12 // this definition.
13 const size_t kMaxUrlChars = 2 * 1024 * 1024;
14
15 template <>
16 struct StructTraits<url::mojom::Url, GURL> {
17 static base::StringPiece url(const GURL& r) {
18 if (r.possibly_invalid_spec().length() > kMaxUrlChars || !r.is_valid()) {
19 return base::StringPiece();
20 }
21
22 return base::StringPiece(r.possibly_invalid_spec().c_str(),
23 r.possibly_invalid_spec().length());
24 }
25 static bool Read(url::mojom::Url::Reader r, GURL* out) {
26 if (r.url().length() > kMaxUrlChars) {
27 *out = GURL();
28 return false;
29 }
30 *out = GURL(r.url());
31 if (!r.url().empty() && !out->is_valid()) {
32 *out = GURL();
33 return false;
34 }
35 return true;
36 }
37 };
38
39 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698