diff options
author | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-15 21:07:03 +0000 |
---|---|---|
committer | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-15 21:07:03 +0000 |
commit | 79d68c6ea3f0ee22789e04bcdcdf64841618f2c1 (patch) | |
tree | 99e371bf8e2be6bdbf3ea7a0b24bd50e5eb1cc20 /content/common | |
parent | ea2a7b919337fb796c8602f1701b60d8fa2d7f42 (diff) | |
download | chromium_src-79d68c6ea3f0ee22789e04bcdcdf64841618f2c1.zip chromium_src-79d68c6ea3f0ee22789e04bcdcdf64841618f2c1.tar.gz chromium_src-79d68c6ea3f0ee22789e04bcdcdf64841618f2c1.tar.bz2 |
Moved ParamTraits specializations that depend on WebKit out of content/common/common_param_traits and into webkit_param_traits. Also pulled some specializations out of chrome/common/render_messages and into chrome/common/common_param_traits. This is done so that the MS toolchain can succeed in discarding more code at link time. This halves the size of npchrome_frame.dll in ordinary "Release" builds. I hope for a similar reduction in official builds.
BUG=77445
TEST=Everything should just work(TM).
Review URL: http://codereview.chromium.org/6840044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81803 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/common')
-rw-r--r-- | content/common/common_param_traits.cc | 360 | ||||
-rw-r--r-- | content/common/common_param_traits.h | 214 | ||||
-rw-r--r-- | content/common/content_message_generator.cc | 3 | ||||
-rw-r--r-- | content/common/drag_messages.h | 1 | ||||
-rw-r--r-- | content/common/plugin_messages.h | 3 | ||||
-rw-r--r-- | content/common/view_messages.h | 1 | ||||
-rw-r--r-- | content/common/webblob_messages.h | 1 | ||||
-rw-r--r-- | content/common/webkit_param_traits.cc | 375 | ||||
-rw-r--r-- | content/common/webkit_param_traits.h | 239 |
9 files changed, 620 insertions, 577 deletions
diff --git a/content/common/common_param_traits.cc b/content/common/common_param_traits.cc index 99ef232..1e0ffd0 100644 --- a/content/common/common_param_traits.cc +++ b/content/common/common_param_traits.cc @@ -8,11 +8,8 @@ #include "net/base/host_port_pair.h" #include "net/base/upload_data.h" #include "net/http/http_response_headers.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/rect.h" -#include "webkit/glue/password_form.h" -#include "webkit/glue/resource_loader_bridge.h" namespace { @@ -49,24 +46,6 @@ struct SkBitmap_Data { } // namespace -NPIdentifier_Param::NPIdentifier_Param() - : identifier() { -} - -NPIdentifier_Param::~NPIdentifier_Param() { -} - -NPVariant_Param::NPVariant_Param() - : type(NPVARIANT_PARAM_VOID), - bool_value(false), - int_value(0), - double_value(0), - npobject_routing_id(-1) { -} - -NPVariant_Param::~NPVariant_Param() { -} - namespace IPC { void ParamTraits<GURL>::Write(Message* m, const GURL& p) { @@ -88,7 +67,6 @@ void ParamTraits<GURL>::Log(const GURL& p, std::string* l) { l->append(p.spec()); } - void ParamTraits<ResourceType::Type>::Write(Message* m, const param_type& p) { m->WriteInt(p); } @@ -415,118 +393,6 @@ void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) { LogParam("IPEndPoint:" + p.ToString(), l); } -void ParamTraits<webkit_glue::ResourceLoadTimingInfo>::Write( - Message* m, const param_type& p) { - WriteParam(m, p.base_time.is_null()); - if (p.base_time.is_null()) - return; - WriteParam(m, p.base_time); - WriteParam(m, p.proxy_start); - WriteParam(m, p.proxy_end); - WriteParam(m, p.dns_start); - WriteParam(m, p.dns_end); - WriteParam(m, p.connect_start); - WriteParam(m, p.connect_end); - WriteParam(m, p.ssl_start); - WriteParam(m, p.ssl_end); - WriteParam(m, p.send_start); - WriteParam(m, p.send_end); - WriteParam(m, p.receive_headers_start); - WriteParam(m, p.receive_headers_end); -} - -bool ParamTraits<webkit_glue::ResourceLoadTimingInfo>::Read( - const Message* m, void** iter, param_type* r) { - bool is_null; - if (!ReadParam(m, iter, &is_null)) - return false; - if (is_null) - return true; - - return - ReadParam(m, iter, &r->base_time) && - ReadParam(m, iter, &r->proxy_start) && - ReadParam(m, iter, &r->proxy_end) && - ReadParam(m, iter, &r->dns_start) && - ReadParam(m, iter, &r->dns_end) && - ReadParam(m, iter, &r->connect_start) && - ReadParam(m, iter, &r->connect_end) && - ReadParam(m, iter, &r->ssl_start) && - ReadParam(m, iter, &r->ssl_end) && - ReadParam(m, iter, &r->send_start) && - ReadParam(m, iter, &r->send_end) && - ReadParam(m, iter, &r->receive_headers_start) && - ReadParam(m, iter, &r->receive_headers_end); -} - -void ParamTraits<webkit_glue::ResourceLoadTimingInfo>::Log(const param_type& p, - std::string* l) { - l->append("("); - LogParam(p.base_time, l); - l->append(", "); - LogParam(p.proxy_start, l); - l->append(", "); - LogParam(p.proxy_end, l); - l->append(", "); - LogParam(p.dns_start, l); - l->append(", "); - LogParam(p.dns_end, l); - l->append(", "); - LogParam(p.connect_start, l); - l->append(", "); - LogParam(p.connect_end, l); - l->append(", "); - LogParam(p.ssl_start, l); - l->append(", "); - LogParam(p.ssl_end, l); - l->append(", "); - LogParam(p.send_start, l); - l->append(", "); - LogParam(p.send_end, l); - l->append(", "); - LogParam(p.receive_headers_start, l); - l->append(", "); - LogParam(p.receive_headers_end, l); - l->append(")"); -} - -void ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Write( - Message* m, const param_type& p) { - WriteParam(m, p.get() != NULL); - if (p.get()) { - WriteParam(m, p->http_status_code); - WriteParam(m, p->http_status_text); - WriteParam(m, p->request_headers); - WriteParam(m, p->response_headers); - } -} - -bool ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Read( - const Message* m, void** iter, param_type* r) { - bool has_object; - if (!ReadParam(m, iter, &has_object)) - return false; - if (!has_object) - return true; - *r = new webkit_glue::ResourceDevToolsInfo(); - return - ReadParam(m, iter, &(*r)->http_status_code) && - ReadParam(m, iter, &(*r)->http_status_text) && - ReadParam(m, iter, &(*r)->request_headers) && - ReadParam(m, iter, &(*r)->response_headers); -} - -void ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Log( - const param_type& p, std::string* l) { - l->append("("); - if (p) { - LogParam(p->request_headers, l); - l->append(", "); - LogParam(p->response_headers, l); - } - l->append(")"); -} - void ParamTraits<base::PlatformFileInfo>::Write( Message* m, const param_type& p) { WriteParam(m, p.size); @@ -635,193 +501,6 @@ void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) { p.width(), p.height())); } -// Only the webkit_blob::BlobData ParamTraits<> definition needs this -// definition, so keep this in the implementation file so we can forward declare -// BlobData in the header. -template <> -struct ParamTraits<webkit_blob::BlobData::Item> { - typedef webkit_blob::BlobData::Item param_type; - static void Write(Message* m, const param_type& p) { - WriteParam(m, static_cast<int>(p.type())); - if (p.type() == webkit_blob::BlobData::TYPE_DATA) { - WriteParam(m, p.data()); - } else if (p.type() == webkit_blob::BlobData::TYPE_FILE) { - WriteParam(m, p.file_path()); - WriteParam(m, p.offset()); - WriteParam(m, p.length()); - WriteParam(m, p.expected_modification_time()); - } else { - WriteParam(m, p.blob_url()); - WriteParam(m, p.offset()); - WriteParam(m, p.length()); - } - } - static bool Read(const Message* m, void** iter, param_type* r) { - int type; - if (!ReadParam(m, iter, &type)) - return false; - if (type == webkit_blob::BlobData::TYPE_DATA) { - std::string data; - if (!ReadParam(m, iter, &data)) - return false; - r->SetToData(data); - } else if (type == webkit_blob::BlobData::TYPE_FILE) { - FilePath file_path; - uint64 offset, length; - base::Time expected_modification_time; - if (!ReadParam(m, iter, &file_path)) - return false; - if (!ReadParam(m, iter, &offset)) - return false; - if (!ReadParam(m, iter, &length)) - return false; - if (!ReadParam(m, iter, &expected_modification_time)) - return false; - r->SetToFile(file_path, offset, length, expected_modification_time); - } else { - DCHECK(type == webkit_blob::BlobData::TYPE_BLOB); - GURL blob_url; - uint64 offset, length; - if (!ReadParam(m, iter, &blob_url)) - return false; - if (!ReadParam(m, iter, &offset)) - return false; - if (!ReadParam(m, iter, &length)) - return false; - r->SetToBlob(blob_url, offset, length); - } - return true; - } - static void Log(const param_type& p, std::string* l) { - l->append("<BlobData::Item>"); - } -}; - -void ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Write( - Message* m, const param_type& p) { - WriteParam(m, p.get() != NULL); - if (p) { - WriteParam(m, p->items()); - WriteParam(m, p->content_type()); - WriteParam(m, p->content_disposition()); - } -} - -bool ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Read( - const Message* m, void** iter, param_type* r) { - bool has_object; - if (!ReadParam(m, iter, &has_object)) - return false; - if (!has_object) - return true; - std::vector<webkit_blob::BlobData::Item> items; - if (!ReadParam(m, iter, &items)) - return false; - std::string content_type; - if (!ReadParam(m, iter, &content_type)) - return false; - std::string content_disposition; - if (!ReadParam(m, iter, &content_disposition)) - return false; - *r = new webkit_blob::BlobData; - (*r)->swap_items(&items); - (*r)->set_content_type(content_type); - (*r)->set_content_disposition(content_disposition); - return true; -} - -void ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Log( - const param_type& p, std::string* l) { - l->append("<webkit_blob::BlobData>"); -} - -void ParamTraits<NPVariant_Param>::Write(Message* m, const param_type& p) { - WriteParam(m, static_cast<int>(p.type)); - if (p.type == NPVARIANT_PARAM_BOOL) { - WriteParam(m, p.bool_value); - } else if (p.type == NPVARIANT_PARAM_INT) { - WriteParam(m, p.int_value); - } else if (p.type == NPVARIANT_PARAM_DOUBLE) { - WriteParam(m, p.double_value); - } else if (p.type == NPVARIANT_PARAM_STRING) { - WriteParam(m, p.string_value); - } else if (p.type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID || - p.type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) { - // This is the routing id used to connect NPObjectProxy in the other - // process with NPObjectStub in this process or to identify the raw - // npobject pointer to be used in the callee process. - WriteParam(m, p.npobject_routing_id); - } else { - DCHECK(p.type == NPVARIANT_PARAM_VOID || p.type == NPVARIANT_PARAM_NULL); - } -} - -bool ParamTraits<NPVariant_Param>::Read(const Message* m, - void** iter, - param_type* r) { - int type; - if (!ReadParam(m, iter, &type)) - return false; - - bool result = false; - r->type = static_cast<NPVariant_ParamEnum>(type); - if (r->type == NPVARIANT_PARAM_BOOL) { - result = ReadParam(m, iter, &r->bool_value); - } else if (r->type == NPVARIANT_PARAM_INT) { - result = ReadParam(m, iter, &r->int_value); - } else if (r->type == NPVARIANT_PARAM_DOUBLE) { - result = ReadParam(m, iter, &r->double_value); - } else if (r->type == NPVARIANT_PARAM_STRING) { - result = ReadParam(m, iter, &r->string_value); - } else if (r->type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID || - r->type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) { - result = ReadParam(m, iter, &r->npobject_routing_id); - } else if ((r->type == NPVARIANT_PARAM_VOID) || - (r->type == NPVARIANT_PARAM_NULL)) { - result = true; - } else { - NOTREACHED(); - } - - return result; -} - -void ParamTraits<NPVariant_Param>::Log(const param_type& p, std::string* l) { - if (p.type == NPVARIANT_PARAM_BOOL) { - LogParam(p.bool_value, l); - } else if (p.type == NPVARIANT_PARAM_INT) { - LogParam(p.int_value, l); - } else if (p.type == NPVARIANT_PARAM_DOUBLE) { - LogParam(p.double_value, l); - } else if (p.type == NPVARIANT_PARAM_STRING) { - LogParam(p.string_value, l); - } else if (p.type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID || - p.type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) { - LogParam(p.npobject_routing_id, l); - } -} - -void ParamTraits<NPIdentifier_Param>::Write(Message* m, const param_type& p) { - webkit_glue::SerializeNPIdentifier(p.identifier, m); -} - -bool ParamTraits<NPIdentifier_Param>::Read(const Message* m, - void** iter, - param_type* r) { - return webkit_glue::DeserializeNPIdentifier(*m, iter, &r->identifier); -} - -void ParamTraits<NPIdentifier_Param>::Log(const param_type& p, std::string* l) { - if (WebKit::WebBindings::identifierIsString(p.identifier)) { - NPUTF8* str = WebKit::WebBindings::utf8FromIdentifier(p.identifier); - l->append(str); - NPN_MemFree(str); - } else { - l->append(base::IntToString( - WebKit::WebBindings::intFromIdentifier(p.identifier))); - } -} - void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { size_t fixed_size = sizeof(SkBitmap_Data); SkBitmap_Data bmp_data; @@ -861,43 +540,4 @@ void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) { l->append("<SkBitmap>"); } -void ParamTraits<webkit_glue::PasswordForm>::Write(Message* m, - const param_type& p) { - WriteParam(m, p.signon_realm); - WriteParam(m, p.origin); - WriteParam(m, p.action); - WriteParam(m, p.submit_element); - WriteParam(m, p.username_element); - WriteParam(m, p.username_value); - WriteParam(m, p.password_element); - WriteParam(m, p.password_value); - WriteParam(m, p.old_password_element); - WriteParam(m, p.old_password_value); - WriteParam(m, p.ssl_valid); - WriteParam(m, p.preferred); - WriteParam(m, p.blacklisted_by_user); -} - -bool ParamTraits<webkit_glue::PasswordForm>::Read(const Message* m, void** iter, - param_type* p) { - return - ReadParam(m, iter, &p->signon_realm) && - ReadParam(m, iter, &p->origin) && - ReadParam(m, iter, &p->action) && - ReadParam(m, iter, &p->submit_element) && - ReadParam(m, iter, &p->username_element) && - ReadParam(m, iter, &p->username_value) && - ReadParam(m, iter, &p->password_element) && - ReadParam(m, iter, &p->password_value) && - ReadParam(m, iter, &p->old_password_element) && - ReadParam(m, iter, &p->old_password_value) && - ReadParam(m, iter, &p->ssl_valid) && - ReadParam(m, iter, &p->preferred) && - ReadParam(m, iter, &p->blacklisted_by_user); -} -void ParamTraits<webkit_glue::PasswordForm>::Log(const param_type& p, - std::string* l) { - l->append("<PasswordForm>"); -} - } // namespace IPC diff --git a/content/common/common_param_traits.h b/content/common/common_param_traits.h index cc60d5d..ae102cb 100644 --- a/content/common/common_param_traits.h +++ b/content/common/common_param_traits.h @@ -16,20 +16,13 @@ #include "base/memory/ref_counted.h" #include "base/platform_file.h" -#include "base/string_number_conversions.h" #include "googleurl/src/gurl.h" #include "ipc/ipc_message_utils.h" #include "net/base/ip_endpoint.h" #include "net/url_request/url_request_status.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/surface/transport_dib.h" -#include "webkit/blob/blob_data.h" -#include "webkit/glue/npruntime_util.h" #include "webkit/glue/resource_type.h" -#include "webkit/glue/webcursor.h" -#include "webkit/glue/window_open_disposition.h" class SkBitmap; @@ -45,49 +38,6 @@ class HostPortPair; class UploadData; } -namespace webkit_glue { -struct PasswordForm; -struct ResourceDevToolsInfo; -struct ResourceLoadTimingInfo; -} - -// Define the NPVariant_Param struct and its enum here since it needs manual -// serialization code. -enum NPVariant_ParamEnum { - NPVARIANT_PARAM_VOID, - NPVARIANT_PARAM_NULL, - NPVARIANT_PARAM_BOOL, - NPVARIANT_PARAM_INT, - NPVARIANT_PARAM_DOUBLE, - NPVARIANT_PARAM_STRING, - // Used when when the NPObject is running in the caller's process, so we - // create an NPObjectProxy in the other process. - NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID, - // Used when the NPObject we're sending is running in the callee's process - // (i.e. we have an NPObjectProxy for it). In that case we want the callee - // to just use the raw pointer. - NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID, -}; - -struct NPVariant_Param { - NPVariant_Param(); - ~NPVariant_Param(); - - NPVariant_ParamEnum type; - bool bool_value; - int int_value; - double double_value; - std::string string_value; - int npobject_routing_id; -}; - -struct NPIdentifier_Param { - NPIdentifier_Param(); - ~NPIdentifier_Param(); - - NPIdentifier identifier; -}; - namespace IPC { template <> @@ -147,22 +97,6 @@ struct ParamTraits<net::IPEndPoint> { }; template <> -struct ParamTraits<webkit_glue::ResourceLoadTimingInfo> { - typedef webkit_glue::ResourceLoadTimingInfo param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, void** iter, param_type* r); - static void Log(const param_type& p, std::string* l); -}; - -template <> -struct ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> > { - typedef scoped_refptr<webkit_glue::ResourceDevToolsInfo> param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, void** iter, param_type* r); - static void Log(const param_type& p, std::string* l); -}; - -template <> struct ParamTraits<base::PlatformFileInfo> { typedef base::PlatformFileInfo param_type; static void Write(Message* m, const param_type& p); @@ -231,136 +165,6 @@ struct ParamTraits<gfx::NativeWindow> { } }; -template <> -struct ParamTraits<scoped_refptr<webkit_blob::BlobData > > { - typedef scoped_refptr<webkit_blob::BlobData> param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, void** iter, param_type* r); - static void Log(const param_type& p, std::string* l); -}; - -template <> -struct ParamTraits<NPVariant_Param> { - typedef NPVariant_Param param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, void** iter, param_type* r); - static void Log(const param_type& p, std::string* l); -}; - -template <> -struct ParamTraits<NPIdentifier_Param> { - typedef NPIdentifier_Param param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, void** iter, param_type* r); - static void Log(const param_type& p, std::string* l); -}; - -template <> -struct ParamTraits<WebCursor> { - typedef WebCursor param_type; - static void Write(Message* m, const param_type& p) { - p.Serialize(m); - } - static bool Read(const Message* m, void** iter, param_type* r) { - return r->Deserialize(m, iter); - } - static void Log(const param_type& p, std::string* l) { - l->append("<WebCursor>"); - } -}; - - -template <> -struct ParamTraits<WebKit::WebInputEvent::Type> { - typedef WebKit::WebInputEvent::Type param_type; - static void Write(Message* m, const param_type& p) { - m->WriteInt(p); - } - static bool Read(const Message* m, void** iter, param_type* p) { - int type; - if (!m->ReadInt(iter, &type)) - return false; - *p = static_cast<WebKit::WebInputEvent::Type>(type); - return true; - } - static void Log(const param_type& p, std::string* l) { - const char* type; - switch (p) { - case WebKit::WebInputEvent::MouseDown: - type = "MouseDown"; - break; - case WebKit::WebInputEvent::MouseUp: - type = "MouseUp"; - break; - case WebKit::WebInputEvent::MouseMove: - type = "MouseMove"; - break; - case WebKit::WebInputEvent::MouseLeave: - type = "MouseLeave"; - break; - case WebKit::WebInputEvent::MouseEnter: - type = "MouseEnter"; - break; - case WebKit::WebInputEvent::MouseWheel: - type = "MouseWheel"; - break; - case WebKit::WebInputEvent::RawKeyDown: - type = "RawKeyDown"; - break; - case WebKit::WebInputEvent::KeyDown: - type = "KeyDown"; - break; - case WebKit::WebInputEvent::KeyUp: - type = "KeyUp"; - break; - default: - type = "None"; - break; - } - LogParam(std::string(type), l); - } -}; - -typedef const WebKit::WebInputEvent* WebInputEventPointer; -template <> -struct ParamTraits<WebInputEventPointer> { - typedef WebInputEventPointer param_type; - static void Write(Message* m, const param_type& p) { - m->WriteData(reinterpret_cast<const char*>(p), p->size); - } - // Note: upon read, the event has the lifetime of the message. - static bool Read(const Message* m, void** iter, param_type* r) { - const char* data; - int data_length; - if (!m->ReadData(iter, &data, &data_length)) { - NOTREACHED(); - return false; - } - if (data_length < static_cast<int>(sizeof(WebKit::WebInputEvent))) { - NOTREACHED(); - return false; - } - param_type event = reinterpret_cast<param_type>(data); - // Check that the data size matches that of the event (we check the latter - // in the delegate). - if (data_length != static_cast<int>(event->size)) { - NOTREACHED(); - return false; - } - *r = event; - return true; - } - static void Log(const param_type& p, std::string* l) { - l->append("("); - LogParam(p->size, l); - l->append(", "); - LogParam(p->type, l); - l->append(", "); - LogParam(p->timeStampSeconds, l); - l->append(")"); - } -}; - #if defined(OS_WIN) template<> struct ParamTraits<TransportDIB::Id> { @@ -402,11 +206,6 @@ struct ParamTraits<TransportDIB::Id> { #endif template <> -struct SimilarTypeTraits<WebKit::WebTextDirection> { - typedef int Type; -}; - -template <> struct ParamTraits<SkBitmap> { typedef SkBitmap param_type; static void Write(Message* m, const param_type& p); @@ -418,19 +217,6 @@ struct ParamTraits<SkBitmap> { static void Log(const param_type& p, std::string* l); }; -template <> -struct SimilarTypeTraits<WindowOpenDisposition> { - typedef int Type; -}; - -template <> -struct ParamTraits<webkit_glue::PasswordForm> { - typedef webkit_glue::PasswordForm param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, void** iter, param_type* p); - static void Log(const param_type& p, std::string* l); -}; - } // namespace IPC #endif // CONTENT_COMMON_COMMON_PARAM_TRAITS_H_ diff --git a/content/common/content_message_generator.cc b/content/common/content_message_generator.cc index 00f2237..c09d6f0 100644 --- a/content/common/content_message_generator.cc +++ b/content/common/content_message_generator.cc @@ -1,10 +1,9 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Get basic type definitions. #define IPC_MESSAGE_IMPL -#include "content/common/common_param_traits.h" #include "content/common/content_message_generator.h" // Generate constructors. diff --git a/content/common/drag_messages.h b/content/common/drag_messages.h index d73470f..6e0507b 100644 --- a/content/common/drag_messages.h +++ b/content/common/drag_messages.h @@ -9,6 +9,7 @@ #include "ipc/ipc_message_macros.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" +#include "ui/gfx/point.h" #include "webkit/glue/webdropdata.h" #define IPC_MESSAGE_START DragMsgStart diff --git a/content/common/plugin_messages.h b/content/common/plugin_messages.h index 23f271e..f817664 100644 --- a/content/common/plugin_messages.h +++ b/content/common/plugin_messages.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -7,6 +7,7 @@ #include "base/shared_memory.h" #include "build/build_config.h" #include "content/common/common_param_traits.h" +#include "content/common/webkit_param_traits.h" #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_message_macros.h" #include "ui/gfx/native_widget_types.h" diff --git a/content/common/view_messages.h b/content/common/view_messages.h index aacceb00..4dc7069 100644 --- a/content/common/view_messages.h +++ b/content/common/view_messages.h @@ -14,6 +14,7 @@ #include "content/common/page_transition_types.h" #include "content/common/page_zoom.h" #include "content/common/renderer_preferences.h" +#include "content/common/webkit_param_traits.h" #include "content/common/window_container_type.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_platform_file.h" diff --git a/content/common/webblob_messages.h b/content/common/webblob_messages.h index b96f5cf..2cbb2b7 100644 --- a/content/common/webblob_messages.h +++ b/content/common/webblob_messages.h @@ -6,6 +6,7 @@ // Multiply-included message file, hence no include guard. #include "content/common/common_param_traits.h" +#include "content/common/webkit_param_traits.h" #include "ipc/ipc_message_macros.h" #define IPC_MESSAGE_START BlobMsgStart diff --git a/content/common/webkit_param_traits.cc b/content/common/webkit_param_traits.cc new file mode 100644 index 0000000..e6dce1d --- /dev/null +++ b/content/common/webkit_param_traits.cc @@ -0,0 +1,375 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// NOTE: New trait definitions that will be used by Chrome Frame must be placed +// in common_param_traits2.cc. + +#include "content/common/webkit_param_traits.h" + +#include "base/string_number_conversions.h" +#include "content/common/common_param_traits.h" +#include "content/common/content_constants.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" +#include "webkit/glue/password_form.h" +#include "webkit/glue/resource_loader_bridge.h" + +NPIdentifier_Param::NPIdentifier_Param() + : identifier() { +} + +NPIdentifier_Param::~NPIdentifier_Param() { +} + +NPVariant_Param::NPVariant_Param() + : type(NPVARIANT_PARAM_VOID), + bool_value(false), + int_value(0), + double_value(0), + npobject_routing_id(-1) { +} + +NPVariant_Param::~NPVariant_Param() { +} + +namespace IPC { + +void ParamTraits<webkit_glue::ResourceLoadTimingInfo>::Write( + Message* m, const param_type& p) { + WriteParam(m, p.base_time.is_null()); + if (p.base_time.is_null()) + return; + WriteParam(m, p.base_time); + WriteParam(m, p.proxy_start); + WriteParam(m, p.proxy_end); + WriteParam(m, p.dns_start); + WriteParam(m, p.dns_end); + WriteParam(m, p.connect_start); + WriteParam(m, p.connect_end); + WriteParam(m, p.ssl_start); + WriteParam(m, p.ssl_end); + WriteParam(m, p.send_start); + WriteParam(m, p.send_end); + WriteParam(m, p.receive_headers_start); + WriteParam(m, p.receive_headers_end); +} + +bool ParamTraits<webkit_glue::ResourceLoadTimingInfo>::Read( + const Message* m, void** iter, param_type* r) { + bool is_null; + if (!ReadParam(m, iter, &is_null)) + return false; + if (is_null) + return true; + + return + ReadParam(m, iter, &r->base_time) && + ReadParam(m, iter, &r->proxy_start) && + ReadParam(m, iter, &r->proxy_end) && + ReadParam(m, iter, &r->dns_start) && + ReadParam(m, iter, &r->dns_end) && + ReadParam(m, iter, &r->connect_start) && + ReadParam(m, iter, &r->connect_end) && + ReadParam(m, iter, &r->ssl_start) && + ReadParam(m, iter, &r->ssl_end) && + ReadParam(m, iter, &r->send_start) && + ReadParam(m, iter, &r->send_end) && + ReadParam(m, iter, &r->receive_headers_start) && + ReadParam(m, iter, &r->receive_headers_end); +} + +void ParamTraits<webkit_glue::ResourceLoadTimingInfo>::Log(const param_type& p, + std::string* l) { + l->append("("); + LogParam(p.base_time, l); + l->append(", "); + LogParam(p.proxy_start, l); + l->append(", "); + LogParam(p.proxy_end, l); + l->append(", "); + LogParam(p.dns_start, l); + l->append(", "); + LogParam(p.dns_end, l); + l->append(", "); + LogParam(p.connect_start, l); + l->append(", "); + LogParam(p.connect_end, l); + l->append(", "); + LogParam(p.ssl_start, l); + l->append(", "); + LogParam(p.ssl_end, l); + l->append(", "); + LogParam(p.send_start, l); + l->append(", "); + LogParam(p.send_end, l); + l->append(", "); + LogParam(p.receive_headers_start, l); + l->append(", "); + LogParam(p.receive_headers_end, l); + l->append(")"); +} + +void ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Write( + Message* m, const param_type& p) { + WriteParam(m, p.get() != NULL); + if (p.get()) { + WriteParam(m, p->http_status_code); + WriteParam(m, p->http_status_text); + WriteParam(m, p->request_headers); + WriteParam(m, p->response_headers); + } +} + +bool ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Read( + const Message* m, void** iter, param_type* r) { + bool has_object; + if (!ReadParam(m, iter, &has_object)) + return false; + if (!has_object) + return true; + *r = new webkit_glue::ResourceDevToolsInfo(); + return + ReadParam(m, iter, &(*r)->http_status_code) && + ReadParam(m, iter, &(*r)->http_status_text) && + ReadParam(m, iter, &(*r)->request_headers) && + ReadParam(m, iter, &(*r)->response_headers); +} + +void ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Log( + const param_type& p, std::string* l) { + l->append("("); + if (p) { + LogParam(p->request_headers, l); + l->append(", "); + LogParam(p->response_headers, l); + } + l->append(")"); +} + +// Only the webkit_blob::BlobData ParamTraits<> definition needs this +// definition, so keep this in the implementation file so we can forward declare +// BlobData in the header. +template <> +struct ParamTraits<webkit_blob::BlobData::Item> { + typedef webkit_blob::BlobData::Item param_type; + static void Write(Message* m, const param_type& p) { + WriteParam(m, static_cast<int>(p.type())); + if (p.type() == webkit_blob::BlobData::TYPE_DATA) { + WriteParam(m, p.data()); + } else if (p.type() == webkit_blob::BlobData::TYPE_FILE) { + WriteParam(m, p.file_path()); + WriteParam(m, p.offset()); + WriteParam(m, p.length()); + WriteParam(m, p.expected_modification_time()); + } else { + WriteParam(m, p.blob_url()); + WriteParam(m, p.offset()); + WriteParam(m, p.length()); + } + } + static bool Read(const Message* m, void** iter, param_type* r) { + int type; + if (!ReadParam(m, iter, &type)) + return false; + if (type == webkit_blob::BlobData::TYPE_DATA) { + std::string data; + if (!ReadParam(m, iter, &data)) + return false; + r->SetToData(data); + } else if (type == webkit_blob::BlobData::TYPE_FILE) { + FilePath file_path; + uint64 offset, length; + base::Time expected_modification_time; + if (!ReadParam(m, iter, &file_path)) + return false; + if (!ReadParam(m, iter, &offset)) + return false; + if (!ReadParam(m, iter, &length)) + return false; + if (!ReadParam(m, iter, &expected_modification_time)) + return false; + r->SetToFile(file_path, offset, length, expected_modification_time); + } else { + DCHECK(type == webkit_blob::BlobData::TYPE_BLOB); + GURL blob_url; + uint64 offset, length; + if (!ReadParam(m, iter, &blob_url)) + return false; + if (!ReadParam(m, iter, &offset)) + return false; + if (!ReadParam(m, iter, &length)) + return false; + r->SetToBlob(blob_url, offset, length); + } + return true; + } + static void Log(const param_type& p, std::string* l) { + l->append("<BlobData::Item>"); + } +}; + +void ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Write( + Message* m, const param_type& p) { + WriteParam(m, p.get() != NULL); + if (p) { + WriteParam(m, p->items()); + WriteParam(m, p->content_type()); + WriteParam(m, p->content_disposition()); + } +} + +bool ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Read( + const Message* m, void** iter, param_type* r) { + bool has_object; + if (!ReadParam(m, iter, &has_object)) + return false; + if (!has_object) + return true; + std::vector<webkit_blob::BlobData::Item> items; + if (!ReadParam(m, iter, &items)) + return false; + std::string content_type; + if (!ReadParam(m, iter, &content_type)) + return false; + std::string content_disposition; + if (!ReadParam(m, iter, &content_disposition)) + return false; + *r = new webkit_blob::BlobData; + (*r)->swap_items(&items); + (*r)->set_content_type(content_type); + (*r)->set_content_disposition(content_disposition); + return true; +} + +void ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Log( + const param_type& p, std::string* l) { + l->append("<webkit_blob::BlobData>"); +} + +void ParamTraits<NPVariant_Param>::Write(Message* m, const param_type& p) { + WriteParam(m, static_cast<int>(p.type)); + if (p.type == NPVARIANT_PARAM_BOOL) { + WriteParam(m, p.bool_value); + } else if (p.type == NPVARIANT_PARAM_INT) { + WriteParam(m, p.int_value); + } else if (p.type == NPVARIANT_PARAM_DOUBLE) { + WriteParam(m, p.double_value); + } else if (p.type == NPVARIANT_PARAM_STRING) { + WriteParam(m, p.string_value); + } else if (p.type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID || + p.type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) { + // This is the routing id used to connect NPObjectProxy in the other + // process with NPObjectStub in this process or to identify the raw + // npobject pointer to be used in the callee process. + WriteParam(m, p.npobject_routing_id); + } else { + DCHECK(p.type == NPVARIANT_PARAM_VOID || p.type == NPVARIANT_PARAM_NULL); + } +} + +bool ParamTraits<NPVariant_Param>::Read(const Message* m, + void** iter, + param_type* r) { + int type; + if (!ReadParam(m, iter, &type)) + return false; + + bool result = false; + r->type = static_cast<NPVariant_ParamEnum>(type); + if (r->type == NPVARIANT_PARAM_BOOL) { + result = ReadParam(m, iter, &r->bool_value); + } else if (r->type == NPVARIANT_PARAM_INT) { + result = ReadParam(m, iter, &r->int_value); + } else if (r->type == NPVARIANT_PARAM_DOUBLE) { + result = ReadParam(m, iter, &r->double_value); + } else if (r->type == NPVARIANT_PARAM_STRING) { + result = ReadParam(m, iter, &r->string_value); + } else if (r->type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID || + r->type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) { + result = ReadParam(m, iter, &r->npobject_routing_id); + } else if ((r->type == NPVARIANT_PARAM_VOID) || + (r->type == NPVARIANT_PARAM_NULL)) { + result = true; + } else { + NOTREACHED(); + } + + return result; +} + +void ParamTraits<NPVariant_Param>::Log(const param_type& p, std::string* l) { + if (p.type == NPVARIANT_PARAM_BOOL) { + LogParam(p.bool_value, l); + } else if (p.type == NPVARIANT_PARAM_INT) { + LogParam(p.int_value, l); + } else if (p.type == NPVARIANT_PARAM_DOUBLE) { + LogParam(p.double_value, l); + } else if (p.type == NPVARIANT_PARAM_STRING) { + LogParam(p.string_value, l); + } else if (p.type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID || + p.type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) { + LogParam(p.npobject_routing_id, l); + } +} + +void ParamTraits<NPIdentifier_Param>::Write(Message* m, const param_type& p) { + webkit_glue::SerializeNPIdentifier(p.identifier, m); +} + +bool ParamTraits<NPIdentifier_Param>::Read(const Message* m, + void** iter, + param_type* r) { + return webkit_glue::DeserializeNPIdentifier(*m, iter, &r->identifier); +} + +void ParamTraits<NPIdentifier_Param>::Log(const param_type& p, std::string* l) { + if (WebKit::WebBindings::identifierIsString(p.identifier)) { + NPUTF8* str = WebKit::WebBindings::utf8FromIdentifier(p.identifier); + l->append(str); + NPN_MemFree(str); + } else { + l->append(base::IntToString( + WebKit::WebBindings::intFromIdentifier(p.identifier))); + } +} + +void ParamTraits<webkit_glue::PasswordForm>::Write(Message* m, + const param_type& p) { + WriteParam(m, p.signon_realm); + WriteParam(m, p.origin); + WriteParam(m, p.action); + WriteParam(m, p.submit_element); + WriteParam(m, p.username_element); + WriteParam(m, p.username_value); + WriteParam(m, p.password_element); + WriteParam(m, p.password_value); + WriteParam(m, p.old_password_element); + WriteParam(m, p.old_password_value); + WriteParam(m, p.ssl_valid); + WriteParam(m, p.preferred); + WriteParam(m, p.blacklisted_by_user); +} + +bool ParamTraits<webkit_glue::PasswordForm>::Read(const Message* m, void** iter, + param_type* p) { + return + ReadParam(m, iter, &p->signon_realm) && + ReadParam(m, iter, &p->origin) && + ReadParam(m, iter, &p->action) && + ReadParam(m, iter, &p->submit_element) && + ReadParam(m, iter, &p->username_element) && + ReadParam(m, iter, &p->username_value) && + ReadParam(m, iter, &p->password_element) && + ReadParam(m, iter, &p->password_value) && + ReadParam(m, iter, &p->old_password_element) && + ReadParam(m, iter, &p->old_password_value) && + ReadParam(m, iter, &p->ssl_valid) && + ReadParam(m, iter, &p->preferred) && + ReadParam(m, iter, &p->blacklisted_by_user); +} +void ParamTraits<webkit_glue::PasswordForm>::Log(const param_type& p, + std::string* l) { + l->append("<PasswordForm>"); +} + +} // namespace IPC diff --git a/content/common/webkit_param_traits.h b/content/common/webkit_param_traits.h new file mode 100644 index 0000000..a937581 --- /dev/null +++ b/content/common/webkit_param_traits.h @@ -0,0 +1,239 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file is used to define IPC::ParamTraits<> specializations for a number +// of WebKit types so that they can be serialized over IPC. IPC::ParamTraits<> +// specializations for basic types (like int and std::string) and types in the +// 'base' project can be found in ipc/ipc_message_utils.h. This file contains +// specializations for types that are used by the content code, and which need +// manual serialization code. This is usually because they're not structs with +// public members. + +#ifndef CONTENT_COMMON_WEBKIT_PARAM_TRAITS_H_ +#define CONTENT_COMMON_WEBKIT_PARAM_TRAITS_H_ +#pragma once + +#include <string> + +#include "base/memory/ref_counted.h" +#include "ipc/ipc_message_utils.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h" +#include "webkit/blob/blob_data.h" +#include "webkit/glue/npruntime_util.h" +#include "webkit/glue/resource_type.h" +#include "webkit/glue/webcursor.h" +#include "webkit/glue/window_open_disposition.h" + +namespace webkit_glue { +struct PasswordForm; +struct ResourceDevToolsInfo; +struct ResourceLoadTimingInfo; +} + +// Define the NPVariant_Param struct and its enum here since it needs manual +// serialization code. +enum NPVariant_ParamEnum { + NPVARIANT_PARAM_VOID, + NPVARIANT_PARAM_NULL, + NPVARIANT_PARAM_BOOL, + NPVARIANT_PARAM_INT, + NPVARIANT_PARAM_DOUBLE, + NPVARIANT_PARAM_STRING, + // Used when when the NPObject is running in the caller's process, so we + // create an NPObjectProxy in the other process. + NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID, + // Used when the NPObject we're sending is running in the callee's process + // (i.e. we have an NPObjectProxy for it). In that case we want the callee + // to just use the raw pointer. + NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID, +}; + +struct NPVariant_Param { + NPVariant_Param(); + ~NPVariant_Param(); + + NPVariant_ParamEnum type; + bool bool_value; + int int_value; + double double_value; + std::string string_value; + int npobject_routing_id; +}; + +struct NPIdentifier_Param { + NPIdentifier_Param(); + ~NPIdentifier_Param(); + + NPIdentifier identifier; +}; + +namespace IPC { + +template <> +struct ParamTraits<webkit_glue::ResourceLoadTimingInfo> { + typedef webkit_glue::ResourceLoadTimingInfo param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, void** iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> > { + typedef scoped_refptr<webkit_glue::ResourceDevToolsInfo> param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, void** iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct ParamTraits<scoped_refptr<webkit_blob::BlobData > > { + typedef scoped_refptr<webkit_blob::BlobData> param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, void** iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct ParamTraits<NPVariant_Param> { + typedef NPVariant_Param param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, void** iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct ParamTraits<NPIdentifier_Param> { + typedef NPIdentifier_Param param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, void** iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template <> +struct ParamTraits<WebCursor> { + typedef WebCursor param_type; + static void Write(Message* m, const param_type& p) { + p.Serialize(m); + } + static bool Read(const Message* m, void** iter, param_type* r) { + return r->Deserialize(m, iter); + } + static void Log(const param_type& p, std::string* l) { + l->append("<WebCursor>"); + } +}; + +template <> +struct ParamTraits<WebKit::WebInputEvent::Type> { + typedef WebKit::WebInputEvent::Type param_type; + static void Write(Message* m, const param_type& p) { + m->WriteInt(p); + } + static bool Read(const Message* m, void** iter, param_type* p) { + int type; + if (!m->ReadInt(iter, &type)) + return false; + *p = static_cast<WebKit::WebInputEvent::Type>(type); + return true; + } + static void Log(const param_type& p, std::string* l) { + const char* type; + switch (p) { + case WebKit::WebInputEvent::MouseDown: + type = "MouseDown"; + break; + case WebKit::WebInputEvent::MouseUp: + type = "MouseUp"; + break; + case WebKit::WebInputEvent::MouseMove: + type = "MouseMove"; + break; + case WebKit::WebInputEvent::MouseLeave: + type = "MouseLeave"; + break; + case WebKit::WebInputEvent::MouseEnter: + type = "MouseEnter"; + break; + case WebKit::WebInputEvent::MouseWheel: + type = "MouseWheel"; + break; + case WebKit::WebInputEvent::RawKeyDown: + type = "RawKeyDown"; + break; + case WebKit::WebInputEvent::KeyDown: + type = "KeyDown"; + break; + case WebKit::WebInputEvent::KeyUp: + type = "KeyUp"; + break; + default: + type = "None"; + break; + } + LogParam(std::string(type), l); + } +}; + +typedef const WebKit::WebInputEvent* WebInputEventPointer; +template <> +struct ParamTraits<WebInputEventPointer> { + typedef WebInputEventPointer param_type; + static void Write(Message* m, const param_type& p) { + m->WriteData(reinterpret_cast<const char*>(p), p->size); + } + // Note: upon read, the event has the lifetime of the message. + static bool Read(const Message* m, void** iter, param_type* r) { + const char* data; + int data_length; + if (!m->ReadData(iter, &data, &data_length)) { + NOTREACHED(); + return false; + } + if (data_length < static_cast<int>(sizeof(WebKit::WebInputEvent))) { + NOTREACHED(); + return false; + } + param_type event = reinterpret_cast<param_type>(data); + // Check that the data size matches that of the event (we check the latter + // in the delegate). + if (data_length != static_cast<int>(event->size)) { + NOTREACHED(); + return false; + } + *r = event; + return true; + } + static void Log(const param_type& p, std::string* l) { + l->append("("); + LogParam(p->size, l); + l->append(", "); + LogParam(p->type, l); + l->append(", "); + LogParam(p->timeStampSeconds, l); + l->append(")"); + } +}; + +template <> +struct SimilarTypeTraits<WebKit::WebTextDirection> { + typedef int Type; +}; + +template <> +struct SimilarTypeTraits<WindowOpenDisposition> { + typedef int Type; +}; + +template <> +struct ParamTraits<webkit_glue::PasswordForm> { + typedef webkit_glue::PasswordForm param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, void** iter, param_type* p); + static void Log(const param_type& p, std::string* l); +}; + +} // namespace IPC + +#endif // CONTENT_COMMON_WEBKIT_PARAM_TRAITS_H_ |