| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 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 "url/ipc/url_param_traits.h" | |
| 6 | |
| 7 #include "url/gurl.h" | |
| 8 | |
| 9 namespace IPC { | |
| 10 | |
| 11 void ParamTraits<GURL>::Write(base::Pickle* m, const GURL& p) { | |
| 12 if (p.possibly_invalid_spec().length() > url::kMaxURLChars) { | |
| 13 m->WriteString(std::string()); | |
| 14 return; | |
| 15 } | |
| 16 | |
| 17 // Beware of print-parse inconsistency which would change an invalid | |
| 18 // URL into a valid one. Ideally, the message would contain this flag | |
| 19 // so that the read side could make the check, but performing it here | |
| 20 // avoids changing the on-the-wire representation of such a fundamental | |
| 21 // type as GURL. See https://crbug.com/166486 for additional work in | |
| 22 // this area. | |
| 23 if (!p.is_valid()) { | |
| 24 m->WriteString(std::string()); | |
| 25 return; | |
| 26 } | |
| 27 | |
| 28 m->WriteString(p.possibly_invalid_spec()); | |
| 29 // TODO(brettw) bug 684583: Add encoding for query params. | |
| 30 } | |
| 31 | |
| 32 bool ParamTraits<GURL>::Read(const base::Pickle* m, | |
| 33 base::PickleIterator* iter, | |
| 34 GURL* p) { | |
| 35 std::string s; | |
| 36 if (!iter->ReadString(&s) || s.length() > url::kMaxURLChars) { | |
| 37 *p = GURL(); | |
| 38 return false; | |
| 39 } | |
| 40 *p = GURL(s); | |
| 41 if (!s.empty() && !p->is_valid()) { | |
| 42 *p = GURL(); | |
| 43 return false; | |
| 44 } | |
| 45 return true; | |
| 46 } | |
| 47 | |
| 48 void ParamTraits<GURL>::Log(const GURL& p, std::string* l) { | |
| 49 l->append(p.spec()); | |
| 50 } | |
| 51 | |
| 52 } // namespace IPC | |
| OLD | NEW |