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 "content/public/common/content_constants.h" | 7 #include "content/public/common/content_constants.h" |
8 #include "content/public/common/referrer.h" | 8 #include "content/public/common/referrer.h" |
9 #include "net/base/host_port_pair.h" | 9 #include "net/base/host_port_pair.h" |
10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 void ParamTraits<GURL>::Write(Message* m, const GURL& p) { | 51 void ParamTraits<GURL>::Write(Message* m, const GURL& p) { |
52 DCHECK(p.possibly_invalid_spec().length() <= content::kMaxURLChars); | 52 DCHECK(p.possibly_invalid_spec().length() <= content::kMaxURLChars); |
53 | 53 |
54 // Beware of print-parse inconsistency which would change an invalid | 54 // Beware of print-parse inconsistency which would change an invalid |
55 // URL into a valid one. Ideally, the message would contain this flag | 55 // URL into a valid one. Ideally, the message would contain this flag |
56 // so that the read side could make the check, but performing it here | 56 // so that the read side could make the check, but performing it here |
57 // avoids changing the on-the-wire representation of such a fundamental | 57 // avoids changing the on-the-wire representation of such a fundamental |
58 // type as GURL. See https://crbug.com/166486 for additional work in | 58 // type as GURL. See https://crbug.com/166486 for additional work in |
59 // this area. | 59 // this area. |
60 if (!p.is_valid()) { | 60 if (!p.is_valid()) { |
61 GURL reconstructed_url(p.possibly_invalid_spec()); | 61 m->WriteString(std::string()); |
62 if (reconstructed_url.is_valid()) { | 62 return; |
63 DLOG(WARNING) << "GURL string " << p.possibly_invalid_spec() | |
64 << " (marked invalid) but parsed as valid."; | |
65 m->WriteString(std::string()); | |
66 return; | |
67 } | |
68 } | 63 } |
69 | 64 |
70 m->WriteString(p.possibly_invalid_spec()); | 65 m->WriteString(p.possibly_invalid_spec()); |
71 // TODO(brettw) bug 684583: Add encoding for query params. | 66 // TODO(brettw) bug 684583: Add encoding for query params. |
72 } | 67 } |
73 | 68 |
74 bool ParamTraits<GURL>::Read(const Message* m, PickleIterator* iter, GURL* p) { | 69 bool ParamTraits<GURL>::Read(const Message* m, PickleIterator* iter, GURL* p) { |
75 std::string s; | 70 std::string s; |
76 if (!m->ReadString(iter, &s) || s.length() > content::kMaxURLChars) { | 71 if (!m->ReadString(iter, &s) || s.length() > content::kMaxURLChars) { |
77 *p = GURL(); | 72 *p = GURL(); |
78 return false; | 73 return false; |
79 } | 74 } |
80 *p = GURL(s); | 75 *p = GURL(s); |
| 76 if (!s.empty() && !p->is_valid()) { |
| 77 *p = GURL(); |
| 78 return false; |
| 79 } |
81 return true; | 80 return true; |
82 } | 81 } |
83 | 82 |
84 void ParamTraits<GURL>::Log(const GURL& p, std::string* l) { | 83 void ParamTraits<GURL>::Log(const GURL& p, std::string* l) { |
85 l->append(p.spec()); | 84 l->append(p.spec()); |
86 } | 85 } |
87 | 86 |
88 void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) { | 87 void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) { |
89 WriteParam(m, p.host()); | 88 WriteParam(m, p.host()); |
90 WriteParam(m, p.port()); | 89 WriteParam(m, p.port()); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 360 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
362 #include "content/public/common/common_param_traits_macros.h" | 361 #include "content/public/common/common_param_traits_macros.h" |
363 } // namespace IPC | 362 } // namespace IPC |
364 | 363 |
365 // Generate param traits log methods. | 364 // Generate param traits log methods. |
366 #include "ipc/param_traits_log_macros.h" | 365 #include "ipc/param_traits_log_macros.h" |
367 namespace IPC { | 366 namespace IPC { |
368 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 367 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
369 #include "content/public/common/common_param_traits_macros.h" | 368 #include "content/public/common/common_param_traits_macros.h" |
370 } // namespace IPC | 369 } // namespace IPC |
OLD | NEW |