Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // 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
| |
| 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; | |
|
dcheng
2016/03/03 16:23:53
Nit: Strictly speaking, this should be kMaxUrlChar
jam
2016/03/03 21:25:12
Done.
| |
| 14 | |
| 15 template <> | |
| 16 struct StructTraits<url::mojom::Url, GURL> { | |
| 17 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.
| |
| 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 } | |
| OLD | NEW |