Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: content/public/common/common_param_traits.cc

Issue 11576038: Beware of print-read inconsistency when serializing GURLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 }; 45 };
46 46
47 } // namespace 47 } // namespace
48 48
49 namespace IPC { 49 namespace IPC {
50 50
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 m->WriteString(p.possibly_invalid_spec()); 53 m->WriteString(p.possibly_invalid_spec());
54 m->WriteBool(p.is_valid());
54 // TODO(brettw) bug 684583: Add encoding for query params. 55 // TODO(brettw) bug 684583: Add encoding for query params.
55 } 56 }
56 57
57 bool ParamTraits<GURL>::Read(const Message* m, PickleIterator* iter, GURL* p) { 58 bool ParamTraits<GURL>::Read(const Message* m, PickleIterator* iter, GURL* p) {
58 std::string s; 59 std::string s;
59 if (!m->ReadString(iter, &s) || s.length() > content::kMaxURLChars) { 60 if (!m->ReadString(iter, &s) || s.length() > content::kMaxURLChars) {
60 *p = GURL(); 61 *p = GURL();
61 return false; 62 return false;
62 } 63 }
64
63 *p = GURL(s); 65 *p = GURL(s);
66
67 // Backwards compatibility with automation bots: permit older messages
68 // that don't contain the is_valid flag without returing an error.
69 bool is_valid;
70 if (m->ReadBool(iter, &is_valid)) {
71 // GURL doesn't always have print-parse consistency; beware of an invalid
72 // URL magically become valid.
73 if (p->is_valid() && !is_valid) {
74 DLOG(WARNING) << "GURL string " << s << " (marked invalid) parsed valid.";
75 *p = GURL();
brettw 2012/12/17 18:53:23 If we're going to do this, why not just have Write
76 }
77 }
64 return true; 78 return true;
65 } 79 }
66 80
67 void ParamTraits<GURL>::Log(const GURL& p, std::string* l) { 81 void ParamTraits<GURL>::Log(const GURL& p, std::string* l) {
68 l->append(p.spec()); 82 l->append(p.spec());
69 } 83 }
70 84
71 void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) { 85 void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) {
72 WriteParam(m, p.host()); 86 WriteParam(m, p.host());
73 WriteParam(m, p.port()); 87 WriteParam(m, p.port());
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ 319 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_
306 #include "content/public/common/common_param_traits_macros.h" 320 #include "content/public/common/common_param_traits_macros.h"
307 } // namespace IPC 321 } // namespace IPC
308 322
309 // Generate param traits log methods. 323 // Generate param traits log methods.
310 #include "ipc/param_traits_log_macros.h" 324 #include "ipc/param_traits_log_macros.h"
311 namespace IPC { 325 namespace IPC {
312 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ 326 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_
313 #include "content/public/common/common_param_traits_macros.h" 327 #include "content/public/common/common_param_traits_macros.h"
314 } // namespace IPC 328 } // namespace IPC
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698