OLD | NEW |
(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 } |
OLD | NEW |