| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/public/common/common_param_traits.h" | 5 #include "content/public/common/common_param_traits.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "content/public/common/content_constants.h" | 9 #include "content/public/common/content_constants.h" |
| 10 #include "content/public/common/page_state.h" | 10 #include "content/public/common/page_state.h" |
| 11 #include "content/public/common/referrer.h" | 11 #include "content/public/common/referrer.h" |
| 12 #include "net/base/host_port_pair.h" | 12 #include "net/base/host_port_pair.h" |
| 13 #include "net/base/ip_address.h" | 13 #include "net/base/ip_address.h" |
| 14 #include "net/base/ip_endpoint.h" | 14 #include "net/base/ip_endpoint.h" |
| 15 | 15 |
| 16 namespace IPC { | 16 namespace IPC { |
| 17 | 17 |
| 18 void ParamTraits<GURL>::Write(base::Pickle* m, const GURL& p) { | |
| 19 if (p.possibly_invalid_spec().length() > content::kMaxURLChars) { | |
| 20 m->WriteString(std::string()); | |
| 21 return; | |
| 22 } | |
| 23 | |
| 24 // Beware of print-parse inconsistency which would change an invalid | |
| 25 // URL into a valid one. Ideally, the message would contain this flag | |
| 26 // so that the read side could make the check, but performing it here | |
| 27 // avoids changing the on-the-wire representation of such a fundamental | |
| 28 // type as GURL. See https://crbug.com/166486 for additional work in | |
| 29 // this area. | |
| 30 if (!p.is_valid()) { | |
| 31 m->WriteString(std::string()); | |
| 32 return; | |
| 33 } | |
| 34 | |
| 35 m->WriteString(p.possibly_invalid_spec()); | |
| 36 // TODO(brettw) bug 684583: Add encoding for query params. | |
| 37 } | |
| 38 | |
| 39 bool ParamTraits<GURL>::Read(const base::Pickle* m, | |
| 40 base::PickleIterator* iter, | |
| 41 GURL* p) { | |
| 42 std::string s; | |
| 43 if (!iter->ReadString(&s) || s.length() > content::kMaxURLChars) { | |
| 44 *p = GURL(); | |
| 45 return false; | |
| 46 } | |
| 47 *p = GURL(s); | |
| 48 if (!s.empty() && !p->is_valid()) { | |
| 49 *p = GURL(); | |
| 50 return false; | |
| 51 } | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 void ParamTraits<GURL>::Log(const GURL& p, std::string* l) { | |
| 56 l->append(p.spec()); | |
| 57 } | |
| 58 | |
| 59 void ParamTraits<url::Origin>::Write(base::Pickle* m, const url::Origin& p) { | 18 void ParamTraits<url::Origin>::Write(base::Pickle* m, const url::Origin& p) { |
| 60 WriteParam(m, p.unique()); | 19 WriteParam(m, p.unique()); |
| 61 WriteParam(m, p.scheme()); | 20 WriteParam(m, p.scheme()); |
| 62 WriteParam(m, p.host()); | 21 WriteParam(m, p.host()); |
| 63 WriteParam(m, p.port()); | 22 WriteParam(m, p.port()); |
| 64 } | 23 } |
| 65 | 24 |
| 66 bool ParamTraits<url::Origin>::Read(const base::Pickle* m, | 25 bool ParamTraits<url::Origin>::Read(const base::Pickle* m, |
| 67 base::PickleIterator* iter, | 26 base::PickleIterator* iter, |
| 68 url::Origin* p) { | 27 url::Origin* p) { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 160 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
| 202 #include "content/public/common/common_param_traits_macros.h" | 161 #include "content/public/common/common_param_traits_macros.h" |
| 203 } // namespace IPC | 162 } // namespace IPC |
| 204 | 163 |
| 205 // Generate param traits log methods. | 164 // Generate param traits log methods. |
| 206 #include "ipc/param_traits_log_macros.h" | 165 #include "ipc/param_traits_log_macros.h" |
| 207 namespace IPC { | 166 namespace IPC { |
| 208 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 167 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
| 209 #include "content/public/common/common_param_traits_macros.h" | 168 #include "content/public/common/common_param_traits_macros.h" |
| 210 } // namespace IPC | 169 } // namespace IPC |
| OLD | NEW |