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

Side by Side Diff: chrome/common/common_param_traits.cc

Issue 6705012: Move the rest of the content browser->renderer messages to content. Also move drag related messa... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months 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 | « chrome/common/common_param_traits.h ('k') | chrome/common/extensions/extension_unpacker.cc » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/common/common_param_traits.h" 5 #include "chrome/common/common_param_traits.h"
6 6
7 #include "base/time.h" 7 #include "base/time.h"
8 #include "chrome/common/chrome_constants.h" 8 #include "chrome/common/chrome_constants.h"
9 #include "chrome/common/content_settings.h" 9 #include "chrome/common/content_settings.h"
10 #include "chrome/common/thumbnail_score.h" 10 #include "chrome/common/thumbnail_score.h"
11 #include "chrome/common/web_apps.h" 11 #include "chrome/common/web_apps.h"
12 #include "content/common/common_param_traits.h" 12 #include "content/common/common_param_traits.h"
13 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
14 #include "printing/backend/print_backend.h" 14 #include "printing/backend/print_backend.h"
15 #include "printing/native_metafile.h" 15 #include "printing/native_metafile.h"
16 #include "printing/page_range.h" 16 #include "printing/page_range.h"
17
18 #ifndef EXCLUDE_SKIA_DEPENDENCIES
19 #include "third_party/skia/include/core/SkBitmap.h"
20 #endif
21 #include "webkit/glue/password_form.h" 17 #include "webkit/glue/password_form.h"
22 18
23 namespace IPC { 19 namespace IPC {
24 20
25 #ifndef EXCLUDE_SKIA_DEPENDENCIES
26
27 namespace {
28
29 struct SkBitmap_Data {
30 // The configuration for the bitmap (bits per pixel, etc).
31 SkBitmap::Config fConfig;
32
33 // The width of the bitmap in pixels.
34 uint32 fWidth;
35
36 // The height of the bitmap in pixels.
37 uint32 fHeight;
38
39 void InitSkBitmapDataForTransfer(const SkBitmap& bitmap) {
40 fConfig = bitmap.config();
41 fWidth = bitmap.width();
42 fHeight = bitmap.height();
43 }
44
45 // Returns whether |bitmap| successfully initialized.
46 bool InitSkBitmapFromData(SkBitmap* bitmap, const char* pixels,
47 size_t total_pixels) const {
48 if (total_pixels) {
49 bitmap->setConfig(fConfig, fWidth, fHeight, 0);
50 if (!bitmap->allocPixels())
51 return false;
52 if (total_pixels != bitmap->getSize())
53 return false;
54 memcpy(bitmap->getPixels(), pixels, total_pixels);
55 }
56 return true;
57 }
58 };
59
60 } // namespace
61
62
63 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) {
64 size_t fixed_size = sizeof(SkBitmap_Data);
65 SkBitmap_Data bmp_data;
66 bmp_data.InitSkBitmapDataForTransfer(p);
67 m->WriteData(reinterpret_cast<const char*>(&bmp_data),
68 static_cast<int>(fixed_size));
69 size_t pixel_size = p.getSize();
70 SkAutoLockPixels p_lock(p);
71 m->WriteData(reinterpret_cast<const char*>(p.getPixels()),
72 static_cast<int>(pixel_size));
73 }
74
75 bool ParamTraits<SkBitmap>::Read(const Message* m, void** iter, SkBitmap* r) {
76 const char* fixed_data;
77 int fixed_data_size = 0;
78 if (!m->ReadData(iter, &fixed_data, &fixed_data_size) ||
79 (fixed_data_size <= 0)) {
80 NOTREACHED();
81 return false;
82 }
83 if (fixed_data_size != sizeof(SkBitmap_Data))
84 return false; // Message is malformed.
85
86 const char* variable_data;
87 int variable_data_size = 0;
88 if (!m->ReadData(iter, &variable_data, &variable_data_size) ||
89 (variable_data_size < 0)) {
90 NOTREACHED();
91 return false;
92 }
93 const SkBitmap_Data* bmp_data =
94 reinterpret_cast<const SkBitmap_Data*>(fixed_data);
95 return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size);
96 }
97
98 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) {
99 l->append("<SkBitmap>");
100 }
101
102 #endif // EXCLUDE_SKIA_DEPENDENCIES
103
104 void ParamTraits<ContentSetting>::Write(Message* m, const param_type& p) { 21 void ParamTraits<ContentSetting>::Write(Message* m, const param_type& p) {
105 WriteParam(m, static_cast<int>(p)); 22 WriteParam(m, static_cast<int>(p));
106 } 23 }
107 24
108 bool ParamTraits<ContentSetting>::Read(const Message* m, void** iter, 25 bool ParamTraits<ContentSetting>::Read(const Message* m, void** iter,
109 param_type* r) { 26 param_type* r) {
110 int value; 27 int value;
111 if (!ReadParam(m, iter, &value)) 28 if (!ReadParam(m, iter, &value))
112 return false; 29 return false;
113 if (value < 0 || value >= static_cast<int>(CONTENT_SETTING_NUM_SETTINGS)) 30 if (value < 0 || value >= static_cast<int>(CONTENT_SETTING_NUM_SETTINGS))
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 l->append(","); 255 l->append(",");
339 LogParam(p.caps_mime_type, l); 256 LogParam(p.caps_mime_type, l);
340 l->append(","); 257 l->append(",");
341 LogParam(p.printer_defaults, l); 258 LogParam(p.printer_defaults, l);
342 l->append(","); 259 l->append(",");
343 LogParam(p.defaults_mime_type, l); 260 LogParam(p.defaults_mime_type, l);
344 l->append(")"); 261 l->append(")");
345 } 262 }
346 263
347 } // namespace IPC 264 } // namespace IPC
OLDNEW
« no previous file with comments | « chrome/common/common_param_traits.h ('k') | chrome/common/extensions/extension_unpacker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698