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 "ui/gfx/ipc/gfx_param_traits.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "content/public/common/content_constants.h" | |
10 #include "content/public/common/page_state.h" | |
11 #include "content/public/common/referrer.h" | |
12 #include "content/public/common/url_utils.h" | |
13 #include "net/base/host_port_pair.h" | |
14 #include "net/base/ip_endpoint.h" | |
15 #include "third_party/skia/include/core/SkBitmap.h" | 9 #include "third_party/skia/include/core/SkBitmap.h" |
16 #include "ui/gfx/rect.h" | 10 #include "ui/gfx/rect.h" |
17 #include "ui/gfx/rect_f.h" | 11 #include "ui/gfx/rect_f.h" |
18 | 12 |
19 namespace { | 13 namespace { |
20 | 14 |
21 struct SkBitmap_Data { | 15 struct SkBitmap_Data { |
22 // The configuration for the bitmap (bits per pixel, etc). | 16 // The configuration for the bitmap (bits per pixel, etc). |
23 SkBitmap::Config fConfig; | 17 SkBitmap::Config fConfig; |
reed1
2014/06/20 13:30:55
I think you can replace the first 3 fields with Sk
| |
24 | 18 |
25 // The width of the bitmap in pixels. | 19 // The width of the bitmap in pixels. |
26 uint32 fWidth; | 20 uint32 fWidth; |
27 | 21 |
28 // The height of the bitmap in pixels. | 22 // The height of the bitmap in pixels. |
29 uint32 fHeight; | 23 uint32 fHeight; |
30 | 24 |
31 void InitSkBitmapDataForTransfer(const SkBitmap& bitmap) { | 25 void InitSkBitmapDataForTransfer(const SkBitmap& bitmap) { |
32 fConfig = bitmap.config(); | 26 fConfig = bitmap.config(); |
33 fWidth = bitmap.width(); | 27 fWidth = bitmap.width(); |
34 fHeight = bitmap.height(); | 28 fHeight = bitmap.height(); |
35 } | 29 } |
36 | 30 |
37 // Returns whether |bitmap| successfully initialized. | 31 // Returns whether |bitmap| successfully initialized. |
38 bool InitSkBitmapFromData(SkBitmap* bitmap, const char* pixels, | 32 bool InitSkBitmapFromData(SkBitmap* bitmap, const char* pixels, |
39 size_t total_pixels) const { | 33 size_t total_pixels) const { |
40 if (total_pixels) { | 34 if (total_pixels) { |
reed1
2014/06/20 13:30:55
This method could then become
bitmap->install
| |
41 bitmap->setConfig(fConfig, fWidth, fHeight, 0); | 35 bitmap->setConfig(fConfig, fWidth, fHeight, 0); |
42 if (!bitmap->allocPixels()) | 36 if (!bitmap->allocPixels()) |
43 return false; | 37 return false; |
44 if (total_pixels != bitmap->getSize()) | 38 if (total_pixels != bitmap->getSize()) |
45 return false; | 39 return false; |
46 memcpy(bitmap->getPixels(), pixels, total_pixels); | 40 memcpy(bitmap->getPixels(), pixels, total_pixels); |
47 } | 41 } |
48 return true; | 42 return true; |
49 } | 43 } |
50 }; | 44 }; |
51 | 45 |
52 } // namespace | 46 } // namespace |
53 | 47 |
54 namespace IPC { | 48 namespace IPC { |
55 | 49 |
56 void ParamTraits<GURL>::Write(Message* m, const GURL& p) { | |
57 DCHECK(p.possibly_invalid_spec().length() <= content::GetMaxURLChars()); | |
58 | |
59 // Beware of print-parse inconsistency which would change an invalid | |
60 // URL into a valid one. Ideally, the message would contain this flag | |
61 // so that the read side could make the check, but performing it here | |
62 // avoids changing the on-the-wire representation of such a fundamental | |
63 // type as GURL. See https://crbug.com/166486 for additional work in | |
64 // this area. | |
65 if (!p.is_valid()) { | |
66 m->WriteString(std::string()); | |
67 return; | |
68 } | |
69 | |
70 m->WriteString(p.possibly_invalid_spec()); | |
71 // TODO(brettw) bug 684583: Add encoding for query params. | |
72 } | |
73 | |
74 bool ParamTraits<GURL>::Read(const Message* m, PickleIterator* iter, GURL* p) { | |
75 std::string s; | |
76 if (!m->ReadString(iter, &s) || s.length() > content::GetMaxURLChars()) { | |
77 *p = GURL(); | |
78 return false; | |
79 } | |
80 *p = GURL(s); | |
81 if (!s.empty() && !p->is_valid()) { | |
82 *p = GURL(); | |
83 return false; | |
84 } | |
85 return true; | |
86 } | |
87 | |
88 void ParamTraits<GURL>::Log(const GURL& p, std::string* l) { | |
89 l->append(p.spec()); | |
90 } | |
91 | |
92 void ParamTraits<url::Origin>::Write(Message* m, | |
93 const url::Origin& p) { | |
94 m->WriteString(p.string()); | |
95 } | |
96 | |
97 bool ParamTraits<url::Origin>::Read(const Message* m, | |
98 PickleIterator* iter, | |
99 url::Origin* p) { | |
100 std::string s; | |
101 if (!m->ReadString(iter, &s)) { | |
102 *p = url::Origin(); | |
103 return false; | |
104 } | |
105 *p = url::Origin(s); | |
106 return true; | |
107 } | |
108 | |
109 void ParamTraits<url::Origin>::Log(const url::Origin& p, std::string* l) { | |
110 l->append(p.string()); | |
111 } | |
112 | |
113 void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) { | |
114 WriteParam(m, p.host()); | |
115 WriteParam(m, p.port()); | |
116 } | |
117 | |
118 bool ParamTraits<net::HostPortPair>::Read(const Message* m, | |
119 PickleIterator* iter, | |
120 param_type* r) { | |
121 std::string host; | |
122 uint16 port; | |
123 if (!ReadParam(m, iter, &host) || !ReadParam(m, iter, &port)) | |
124 return false; | |
125 | |
126 r->set_host(host); | |
127 r->set_port(port); | |
128 return true; | |
129 } | |
130 | |
131 void ParamTraits<net::HostPortPair>::Log(const param_type& p, std::string* l) { | |
132 l->append(p.ToString()); | |
133 } | |
134 | |
135 void ParamTraits<net::IPEndPoint>::Write(Message* m, const param_type& p) { | |
136 WriteParam(m, p.address()); | |
137 WriteParam(m, p.port()); | |
138 } | |
139 | |
140 bool ParamTraits<net::IPEndPoint>::Read(const Message* m, PickleIterator* iter, | |
141 param_type* p) { | |
142 net::IPAddressNumber address; | |
143 int port; | |
144 if (!ReadParam(m, iter, &address) || !ReadParam(m, iter, &port)) | |
145 return false; | |
146 if (address.size() && | |
147 address.size() != net::kIPv4AddressSize && | |
148 address.size() != net::kIPv6AddressSize) { | |
149 return false; | |
150 } | |
151 *p = net::IPEndPoint(address, port); | |
152 return true; | |
153 } | |
154 | |
155 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) { | |
156 LogParam("IPEndPoint:" + p.ToString(), l); | |
157 } | |
158 | |
159 void ParamTraits<content::PageState>::Write( | |
160 Message* m, const param_type& p) { | |
161 WriteParam(m, p.ToEncodedData()); | |
162 } | |
163 | |
164 bool ParamTraits<content::PageState>::Read( | |
165 const Message* m, PickleIterator* iter, param_type* r) { | |
166 std::string data; | |
167 if (!ReadParam(m, iter, &data)) | |
168 return false; | |
169 *r = content::PageState::CreateFromEncodedData(data); | |
170 return true; | |
171 } | |
172 | |
173 void ParamTraits<content::PageState>::Log( | |
174 const param_type& p, std::string* l) { | |
175 l->append("("); | |
176 LogParam(p.ToEncodedData(), l); | |
177 l->append(")"); | |
178 } | |
179 | |
180 void ParamTraits<gfx::Point>::Write(Message* m, const gfx::Point& p) { | 50 void ParamTraits<gfx::Point>::Write(Message* m, const gfx::Point& p) { |
181 m->WriteInt(p.x()); | 51 m->WriteInt(p.x()); |
182 m->WriteInt(p.y()); | 52 m->WriteInt(p.y()); |
183 } | 53 } |
184 | 54 |
185 bool ParamTraits<gfx::Point>::Read(const Message* m, PickleIterator* iter, | 55 bool ParamTraits<gfx::Point>::Read(const Message* m, PickleIterator* iter, |
186 gfx::Point* r) { | 56 gfx::Point* r) { |
187 int x, y; | 57 int x, y; |
188 if (!m->ReadInt(iter, &x) || | 58 if (!m->ReadInt(iter, &x) || |
189 !m->ReadInt(iter, &y)) | 59 !m->ReadInt(iter, &y)) |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 const SkBitmap_Data* bmp_data = | 255 const SkBitmap_Data* bmp_data = |
386 reinterpret_cast<const SkBitmap_Data*>(fixed_data); | 256 reinterpret_cast<const SkBitmap_Data*>(fixed_data); |
387 return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); | 257 return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); |
388 } | 258 } |
389 | 259 |
390 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) { | 260 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) { |
391 l->append("<SkBitmap>"); | 261 l->append("<SkBitmap>"); |
392 } | 262 } |
393 | 263 |
394 } // namespace IPC | 264 } // namespace IPC |
395 | |
396 // Generate param traits write methods. | |
397 #include "ipc/param_traits_write_macros.h" | |
398 namespace IPC { | |
399 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | |
400 #include "content/public/common/common_param_traits_macros.h" | |
401 } // namespace IPC | |
402 | |
403 // Generate param traits read methods. | |
404 #include "ipc/param_traits_read_macros.h" | |
405 namespace IPC { | |
406 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | |
407 #include "content/public/common/common_param_traits_macros.h" | |
408 } // namespace IPC | |
409 | |
410 // Generate param traits log methods. | |
411 #include "ipc/param_traits_log_macros.h" | |
412 namespace IPC { | |
413 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | |
414 #include "content/public/common/common_param_traits_macros.h" | |
415 } // namespace IPC | |
OLD | NEW |