From 67b71ea2e11563a4c0363e1dce4e266cebcd063a Mon Sep 17 00:00:00 2001 From: markdittmer Date: Thu, 3 Mar 2016 14:40:03 -0800 Subject: [PATCH] Move GURL ParamTraits to url/ipc As a part of the GPU refactor for Mus, we are trying to eliminate spots where content/common/gpu depends on content/. One such dependency is GURL. As per discussion here: https://codereview.chromium.org/1703163002/, the plan of record is to move GURL ParamTraits out of content/ and into url/. BUG=586368 CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_site_isolation Committed: https://crrev.com/45eb2e749a8b08988ab45bfd6806c004e9f511fa Cr-Commit-Position: refs/heads/master@{#378859} Review URL: https://codereview.chromium.org/1722773002 Cr-Commit-Position: refs/heads/master@{#379122} --- BUILD.gn | 1 + android_webview/android_webview.gyp | 1 + build/all.gyp | 1 + .../browser/chrome_content_browser_client.cc | 1 + chrome/chrome_common.gypi | 6 +- chrome/common/common_message_generator.cc | 1 - chrome/common/common_message_generator.h | 4 +- .../profile_import_process_messages.h | 2 +- chrome/common/prerender_messages.h | 2 +- chrome/common/render_messages.h | 8 ++- .../renderer/chrome_render_frame_observer.cc | 2 + components/autofill.gypi | 1 + components/content_settings.gypi | 2 +- .../common/content_settings_messages.h | 3 +- components/nacl.gyp | 1 + components/nacl/common/nacl_host_messages.h | 2 +- components/nacl/loader/BUILD.gn | 1 + components/network_hints.gypi | 1 + .../common/network_hints_messages.h | 2 +- .../renderer/renderer_dns_prefetch.cc | 1 + components/password_manager.gypi | 2 + .../common/credential_manager_messages.h | 2 +- components/pdf.gypi | 1 + components/pdf/common/pdf_messages.h | 2 +- .../safe_json/safe_json_parser_messages.h | 2 - components/translate.gypi | 2 +- .../content/common/translate_messages.h | 2 +- content/browser/frame_host/navigator_impl.cc | 5 +- .../web_contents_impl_unittest.cc | 3 +- content/child/plugin_messages.h | 3 +- .../service_worker_dispatcher.cc | 7 +- content/common/BUILD.gn | 1 + content/common/accessibility_messages.h | 1 - content/common/appcache_messages.h | 1 + .../browser_plugin/browser_plugin_messages.h | 2 - content/common/clipboard_messages.h | 5 +- .../common/common_param_traits_unittest.cc | 62 ---------------- content/common/devtools_messages.h | 1 - .../common/dom_storage/dom_storage_messages.h | 2 +- content/common/drag_messages.h | 1 - content/common/fileapi/webblob_messages.h | 2 +- content/common/gpu/gpu_host_messages.h | 1 + content/common/input_messages.h | 1 - content/content_browser.gypi | 1 + content/content_child.gypi | 1 + content/content_common.gypi | 1 + content/content_renderer.gypi | 1 + content/content_shell.gypi | 1 + content/public/common/BUILD.gn | 1 + content/public/common/common_param_traits.cc | 41 ----------- content/public/common/common_param_traits.h | 12 +--- content/public/common/content_constants.cc | 1 - content/renderer/render_frame_impl.cc | 3 +- content/renderer/render_view_impl.cc | 3 +- .../common/layout_test/layout_test_messages.h | 2 +- .../common/extension_utility_messages.h | 1 + extensions/extensions.gyp | 2 + extensions/utility/unpacker.cc | 1 - url/ipc/BUILD.gn | 38 ++++++++++ url/ipc/url_ipc.gyp | 42 +++++++++++ url/ipc/url_ipc_export.h | 29 ++++++++ url/ipc/url_param_traits.cc | 52 ++++++++++++++ url/ipc/url_param_traits.h | 26 +++++++ url/ipc/url_param_traits_unittest.cc | 72 +++++++++++++++++++ url/url_constants.cc | 2 + url/url_constants.h | 4 ++ 66 files changed, 338 insertions(+), 153 deletions(-) create mode 100644 url/ipc/BUILD.gn create mode 100644 url/ipc/url_ipc.gyp create mode 100644 url/ipc/url_ipc_export.h create mode 100644 url/ipc/url_param_traits.cc create mode 100644 url/ipc/url_param_traits.h create mode 100644 url/ipc/url_param_traits_unittest.cc diff --git a/BUILD.gn b/BUILD.gn index fd6758554a4734..0fa20137de8512 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -195,6 +195,7 @@ group("both_gn_and_gyp") { "//ui/events:events_unittests", "//ui/gl:gl_unittests", "//ui/touch_selection:ui_touch_selection_unittests", + "//url/ipc:url_ipc_unittests", ] } else { deps += [ diff --git a/android_webview/android_webview.gyp b/android_webview/android_webview.gyp index 8378d0e5a949e2..f0cd0e032d7895 100644 --- a/android_webview/android_webview.gyp +++ b/android_webview/android_webview.gyp @@ -262,6 +262,7 @@ '../ui/events/events.gyp:gesture_detection', '../ui/gl/gl.gyp:gl', '../ui/shell_dialogs/shell_dialogs.gyp:shell_dialogs', + '../url/ipc/url_ipc.gyp:url_ipc', '../v8/tools/gyp/v8.gyp:v8', 'android_webview_pak', 'android_webview_version', diff --git a/build/all.gyp b/build/all.gyp index 881ab59e3e1432..169bd5a47e75cc 100644 --- a/build/all.gyp +++ b/build/all.gyp @@ -334,6 +334,7 @@ ['OS!="ios"', { 'dependencies': [ '../ui/gl/gl_tests.gyp:gl_unittests', + '../url/ipc/url_ipc.gyp:url_ipc_unittests', ], }], ['OS!="ios" and OS!="mac"', { diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 3e884bb11b7b4f..c90d3e6f6375ab 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -18,6 +18,7 @@ #include "base/macros.h" #include "base/path_service.h" #include "base/strings/string_number_conversions.h" +#include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index dc732b1308ec32..9328cf7aea6eba 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -358,6 +358,7 @@ '<(DEPTH)/ui/gfx/ipc/gfx_ipc.gyp:gfx_ipc', '<(DEPTH)/ui/resources/ui_resources.gyp:ui_resources', '<(DEPTH)/url/url.gyp:url_lib', + '<(DEPTH)/url/ipc/url_ipc.gyp:url_ipc', ], 'sources': [ '<@(chrome_common_sources)' @@ -496,7 +497,10 @@ ], }, { # Non-Android. - 'sources': [ '<@(chrome_common_importer_sources)' ] + 'sources': [ '<@(chrome_common_importer_sources)' ], + 'dependencies': [ + '<(DEPTH)/url/ipc/url_ipc.gyp:url_ipc', + ], }], ['OS=="win"', { 'include_dirs': [ diff --git a/chrome/common/common_message_generator.cc b/chrome/common/common_message_generator.cc index 959f148325e8d8..eb1dda28ece5c4 100644 --- a/chrome/common/common_message_generator.cc +++ b/chrome/common/common_message_generator.cc @@ -36,4 +36,3 @@ namespace IPC { namespace IPC { #include "chrome/common/common_message_generator.h" } // namespace IPC - diff --git a/chrome/common/common_message_generator.h b/chrome/common/common_message_generator.h index e7a3f68530ddf4..13238daef03eb5 100644 --- a/chrome/common/common_message_generator.h +++ b/chrome/common/common_message_generator.h @@ -6,11 +6,14 @@ #include "chrome/common/benchmarking_messages.h" #include "chrome/common/chrome_utility_messages.h" +#include "chrome/common/common_param_traits_macros.h" #include "chrome/common/mac/app_shim_messages.h" #include "chrome/common/prerender_messages.h" #include "chrome/common/render_messages.h" #include "chrome/common/safe_browsing/safebrowsing_messages.h" #include "chrome/common/tts_messages.h" +#include "content/public/common/common_param_traits.h" +#include "content/public/common/common_param_traits_macros.h" #if defined(ENABLE_EXTENSIONS) #include "chrome/common/cast_messages.h" @@ -33,4 +36,3 @@ #if defined(ENABLE_WEBRTC) #include "chrome/common/media/webrtc_logging_messages.h" #endif - diff --git a/chrome/common/importer/profile_import_process_messages.h b/chrome/common/importer/profile_import_process_messages.h index 63e3708027e145..e53c17127a95b2 100644 --- a/chrome/common/importer/profile_import_process_messages.h +++ b/chrome/common/importer/profile_import_process_messages.h @@ -18,9 +18,9 @@ #include "components/autofill/content/common/autofill_param_traits_macros.h" #include "components/autofill/core/common/password_form.h" #include "components/favicon_base/favicon_usage_data.h" -#include "content/public/common/common_param_traits.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_utils.h" +#include "url/ipc/url_param_traits.h" // Force multiple inclusion of the param traits file to generate all methods. #undef CHROME_COMMON_IMPORTER_PROFILE_IMPORT_PROCESS_PARAM_TRAITS_MACROS_H_ diff --git a/chrome/common/prerender_messages.h b/chrome/common/prerender_messages.h index fc373fe6054fc5..a9ca9f6d9609f7 100644 --- a/chrome/common/prerender_messages.h +++ b/chrome/common/prerender_messages.h @@ -6,13 +6,13 @@ #include -#include "content/public/common/common_param_traits.h" #include "content/public/common/referrer.h" #include "ipc/ipc_message.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_param_traits.h" #include "ui/gfx/geometry/size.h" #include "url/gurl.h" +#include "url/ipc/url_param_traits.h" #define IPC_MESSAGE_START PrerenderMsgStart diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index a34683af9b57ce..74efb68ee84a85 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -11,19 +11,23 @@ #include "base/strings/string16.h" #include "base/time/time.h" #include "build/build_config.h" -#include "chrome/common/common_param_traits.h" #include "chrome/common/instant_types.h" #include "chrome/common/ntp_logging_events.h" #include "chrome/common/search_provider.h" #include "chrome/common/web_application_info.h" +#include "components/content_settings/core/common/content_settings.h" +#include "components/content_settings/core/common/content_settings_pattern.h" #include "components/omnibox/common/omnibox_focus_state.h" -#include "content/public/common/common_param_traits.h" #include "content/public/common/top_controls_state.h" +#include "content/public/common/webplugininfo.h" #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_platform_file.h" #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerPromptReply.h" #include "third_party/WebKit/public/web/WebConsoleMessage.h" +#include "third_party/WebKit/public/web/WebWindowFeatures.h" +#include "ui/base/window_open_disposition.h" +#include "url/ipc/url_param_traits.h" // Singly-included section for enums and custom IPC traits. #ifndef CHROME_COMMON_RENDER_MESSAGES_H_ diff --git a/chrome/renderer/chrome_render_frame_observer.cc b/chrome/renderer/chrome_render_frame_observer.cc index af941392a079a4..b49f1beea21811 100644 --- a/chrome/renderer/chrome_render_frame_observer.cc +++ b/chrome/renderer/chrome_render_frame_observer.cc @@ -12,6 +12,7 @@ #include "base/command_line.h" #include "base/metrics/histogram.h" +#include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" #include "build/build_config.h" #include "chrome/common/chrome_isolated_world_ids.h" @@ -22,6 +23,7 @@ #include "chrome/renderer/prerender/prerender_helper.h" #include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h" #include "components/translate/content/renderer/translate_helper.h" +#include "content/public/common/ssl_status.h" #include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_view.h" #include "extensions/common/constants.h" diff --git a/components/autofill.gypi b/components/autofill.gypi index 60a1d56ec99f82..ac1660d12ea9ab 100644 --- a/components/autofill.gypi +++ b/components/autofill.gypi @@ -325,6 +325,7 @@ '../ui/gfx/gfx.gyp:gfx', '../ui/gfx/ipc/gfx_ipc.gyp:gfx_ipc', '../url/url.gyp:url_lib', + '../url/ipc/url_ipc.gyp:url_ipc', ], 'include_dirs': [ '..', diff --git a/components/content_settings.gypi b/components/content_settings.gypi index 1d9b317628f5cb..243fcce8226b53 100644 --- a/components/content_settings.gypi +++ b/components/content_settings.gypi @@ -128,9 +128,9 @@ 'dependencies': [ 'content_settings_core_common', '../base/base.gyp:base', - '../content/content.gyp:content_common', '../ipc/ipc.gyp:ipc', '../url/url.gyp:url_lib', + '../url/ipc/url_ipc.gyp:url_ipc', ], 'include_dirs': [ '..', diff --git a/components/content_settings/content/common/content_settings_messages.h b/components/content_settings/content/common/content_settings_messages.h index 3b7225c0389a22..63a64c07cb2385 100644 --- a/components/content_settings/content/common/content_settings_messages.h +++ b/components/content_settings/content/common/content_settings_messages.h @@ -5,10 +5,9 @@ // Multiply-included file, no traditional include guard. #include "base/strings/string16.h" #include "components/content_settings/core/common/content_settings_types.h" -#include "content/public/common/common_param_traits.h" -#include "content/public/common/common_param_traits_macros.h" #include "ipc/ipc_message_macros.h" #include "url/gurl.h" +#include "url/ipc/url_param_traits.h" #define IPC_MESSAGE_START ContentSettingsMsgStart diff --git a/components/nacl.gyp b/components/nacl.gyp index fc65e4358d16f3..9ac06d242d7c8f 100644 --- a/components/nacl.gyp +++ b/components/nacl.gyp @@ -464,6 +464,7 @@ ], 'dependencies': [ '../content/content.gyp:content_common', + '../url/ipc/url_ipc.gyp:url_ipc', ], }, ] diff --git a/components/nacl/common/nacl_host_messages.h b/components/nacl/common/nacl_host_messages.h index 2e4d829daf304a..f7c55882641d5a 100644 --- a/components/nacl/common/nacl_host_messages.h +++ b/components/nacl/common/nacl_host_messages.h @@ -13,11 +13,11 @@ #include "components/nacl/common/nacl_types.h" #include "components/nacl/common/nacl_types_param_traits.h" #include "components/nacl/common/pnacl_types.h" -#include "content/public/common/common_param_traits.h" #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_platform_file.h" #include "url/gurl.h" +#include "url/ipc/url_param_traits.h" #define IPC_MESSAGE_START NaClHostMsgStart diff --git a/components/nacl/loader/BUILD.gn b/components/nacl/loader/BUILD.gn index 7b28bf030e84b1..f1cb228241230c 100644 --- a/components/nacl/loader/BUILD.gn +++ b/components/nacl/loader/BUILD.gn @@ -117,6 +117,7 @@ if (is_linux) { "//crypto", "//ipc", "//sandbox/linux:sandbox_services", + "//url/ipc:url_ipc", ] cflags = [ "-fPIE" ] diff --git a/components/network_hints.gypi b/components/network_hints.gypi index 418d79e2c293d9..f78f480e482bb9 100644 --- a/components/network_hints.gypi +++ b/components/network_hints.gypi @@ -14,6 +14,7 @@ 'dependencies': [ '../base/base.gyp:base', '../ui/accessibility/accessibility.gyp:accessibility', + '../url/ipc/url_ipc.gyp:url_ipc', ], 'sources': [ 'network_hints/common/network_hints_common.cc', diff --git a/components/network_hints/common/network_hints_messages.h b/components/network_hints/common/network_hints_messages.h index fb037dbf345066..82fce8f0f93c62 100644 --- a/components/network_hints/common/network_hints_messages.h +++ b/components/network_hints/common/network_hints_messages.h @@ -7,9 +7,9 @@ #include #include "components/network_hints/common/network_hints_common.h" -#include "content/public/common/common_param_traits.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_utils.h" +#include "url/ipc/url_param_traits.h" // Singly-included section for custom IPC traits. #ifndef COMPONENTS_NETWORK_HINTS_COMMON_NETWORK_HINTS_MESSAGES_H_ diff --git a/components/network_hints/renderer/renderer_dns_prefetch.cc b/components/network_hints/renderer/renderer_dns_prefetch.cc index a28d020e6f2e3a..1eed2999216dac 100644 --- a/components/network_hints/renderer/renderer_dns_prefetch.cc +++ b/components/network_hints/renderer/renderer_dns_prefetch.cc @@ -12,6 +12,7 @@ #include "base/location.h" #include "base/logging.h" #include "base/message_loop/message_loop.h" +#include "base/thread_task_runner_handle.h" #include "components/network_hints/common/network_hints_common.h" #include "components/network_hints/common/network_hints_messages.h" #include "components/network_hints/renderer/dns_prefetch_queue.h" diff --git a/components/password_manager.gypi b/components/password_manager.gypi index 0b005bf0be6bf1..17ab476c7187c7 100644 --- a/components/password_manager.gypi +++ b/components/password_manager.gypi @@ -259,6 +259,7 @@ '../content/content.gyp:content_common', '../ipc/ipc.gyp:ipc', '../third_party/WebKit/public/blink.gyp:blink_minimal', + '../url/ipc/url_ipc.gyp:url_ipc', 'password_manager_core_common', ], 'include_dirs': [ @@ -281,6 +282,7 @@ '../content/content.gyp:content_common', '../ipc/ipc.gyp:ipc', '../third_party/WebKit/public/blink.gyp:blink', + '../url/ipc/url_ipc.gyp:url_ipc', 'password_manager_core_common', 'password_manager_content_common', ], diff --git a/components/password_manager/content/common/credential_manager_messages.h b/components/password_manager/content/common/credential_manager_messages.h index 694e1e588b8b1b..6ac642fb418288 100644 --- a/components/password_manager/content/common/credential_manager_messages.h +++ b/components/password_manager/content/common/credential_manager_messages.h @@ -10,11 +10,11 @@ #include "base/strings/string16.h" #include "components/password_manager/core/common/credential_manager_types.h" #include "content/public/common/common_param_traits.h" -#include "content/public/common/common_param_traits_macros.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_utils.h" #include "third_party/WebKit/public/platform/WebCredentialManagerError.h" #include "url/gurl.h" +#include "url/ipc/url_param_traits.h" #define IPC_MESSAGE_START CredentialManagerMsgStart diff --git a/components/pdf.gypi b/components/pdf.gypi index ead16466ae0c78..2d3eb2e9ae7b2f 100644 --- a/components/pdf.gypi +++ b/components/pdf.gypi @@ -14,6 +14,7 @@ '<(DEPTH)/content/content.gyp:content_common', '<(DEPTH)/ipc/ipc.gyp:ipc', '<(DEPTH)/url/url.gyp:url_lib', + '<(DEPTH)/url/ipc/url_ipc.gyp:url_ipc', ], 'sources': [ 'pdf/common/pdf_message_generator.cc', diff --git a/components/pdf/common/pdf_messages.h b/components/pdf/common/pdf_messages.h index 72e974ffa2f41a..20420cd2e4c82d 100644 --- a/components/pdf/common/pdf_messages.h +++ b/components/pdf/common/pdf_messages.h @@ -5,11 +5,11 @@ // Multiply-included file, no traditional include guard. #include -#include "content/public/common/common_param_traits.h" #include "content/public/common/common_param_traits_macros.h" #include "content/public/common/referrer.h" #include "ipc/ipc_message_macros.h" #include "url/gurl.h" +#include "url/ipc/url_param_traits.h" #define IPC_MESSAGE_START PDFMsgStart diff --git a/components/safe_json/safe_json_parser_messages.h b/components/safe_json/safe_json_parser_messages.h index ad9279567b1112..6b405c7a51262d 100644 --- a/components/safe_json/safe_json_parser_messages.h +++ b/components/safe_json/safe_json_parser_messages.h @@ -8,8 +8,6 @@ #include #include "base/strings/string16.h" -#include "content/public/common/common_param_traits.h" -#include "content/public/common/common_param_traits_macros.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_utils.h" diff --git a/components/translate.gypi b/components/translate.gypi index a9a3cc8162e1af..dfe328ff5857f7 100644 --- a/components/translate.gypi +++ b/components/translate.gypi @@ -172,8 +172,8 @@ 'translate_core_common', 'translate_core_language_detection', '../base/base.gyp:base', - '../content/content.gyp:content_common', '../ipc/ipc.gyp:ipc', + '../url/ipc/url_ipc.gyp:url_ipc', ], 'include_dirs': [ '..', diff --git a/components/translate/content/common/translate_messages.h b/components/translate/content/common/translate_messages.h index 05d2313d1d548f..ef394f5f22cc78 100644 --- a/components/translate/content/common/translate_messages.h +++ b/components/translate/content/common/translate_messages.h @@ -6,9 +6,9 @@ #include "components/translate/core/common/language_detection_details.h" #include "components/translate/core/common/translate_errors.h" -#include "content/public/common/common_param_traits.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_utils.h" +#include "url/ipc/url_param_traits.h" #define IPC_MESSAGE_START TranslateMsgStart diff --git a/content/browser/frame_host/navigator_impl.cc b/content/browser/frame_host/navigator_impl.cc index a23efb95731e17..baf2bcdb4c3830 100644 --- a/content/browser/frame_host/navigator_impl.cc +++ b/content/browser/frame_host/navigator_impl.cc @@ -42,6 +42,7 @@ #include "content/public/common/resource_response.h" #include "content/public/common/url_constants.h" #include "net/base/net_errors.h" +#include "url/url_constants.h" namespace content { @@ -290,8 +291,8 @@ bool NavigatorImpl::NavigateToEntry( // The renderer will reject IPC messages with URLs longer than // this limit, so don't attempt to navigate with a longer URL. - if (dest_url.spec().size() > kMaxURLChars) { - LOG(WARNING) << "Refusing to load URL as it exceeds " << kMaxURLChars + if (dest_url.spec().size() > url::kMaxURLChars) { + LOG(WARNING) << "Refusing to load URL as it exceeds " << url::kMaxURLChars << " characters."; return false; } diff --git a/content/browser/web_contents/web_contents_impl_unittest.cc b/content/browser/web_contents/web_contents_impl_unittest.cc index bc12f20b8fbc5e..e95c85363ff3e0 100644 --- a/content/browser/web_contents/web_contents_impl_unittest.cc +++ b/content/browser/web_contents/web_contents_impl_unittest.cc @@ -51,6 +51,7 @@ #include "net/test/cert_test_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkColor.h" +#include "url/url_constants.h" namespace content { namespace { @@ -488,7 +489,7 @@ TEST_F(WebContentsImplTest, SimpleNavigation) { TEST_F(WebContentsImplTest, NavigateToExcessivelyLongURL) { // Construct a URL that's kMaxURLChars + 1 long of all 'a's. const GURL url(std::string("http://example.org/").append( - kMaxURLChars + 1, 'a')); + url::kMaxURLChars + 1, 'a')); controller().LoadURL( url, Referrer(), ui::PAGE_TRANSITION_GENERATED, std::string()); diff --git a/content/child/plugin_messages.h b/content/child/plugin_messages.h index 74bb5d3235b06a..501dfdb1353ec2 100644 --- a/content/child/plugin_messages.h +++ b/content/child/plugin_messages.h @@ -11,12 +11,13 @@ #include "content/common/content_export.h" #include "content/common/content_param_traits.h" #include "content/common/cursors/webcursor.h" -#include "content/public/common/common_param_traits.h" #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_message_macros.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/ipc/gfx_param_traits.h" #include "ui/gfx/native_widget_types.h" +#include "ui/surface/transport_dib.h" +#include "url/ipc/url_param_traits.h" #if defined(OS_POSIX) #include "base/file_descriptor_posix.h" diff --git a/content/child/service_worker/service_worker_dispatcher.cc b/content/child/service_worker/service_worker_dispatcher.cc index b8fd142164af94..72ba685d368827 100644 --- a/content/child/service_worker/service_worker_dispatcher.cc +++ b/content/child/service_worker/service_worker_dispatcher.cc @@ -25,6 +25,7 @@ #include "content/public/common/content_constants.h" #include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWorkerProviderClient.h" +#include "url/url_constants.h" using blink::WebServiceWorkerError; using blink::WebServiceWorkerProvider; @@ -110,8 +111,8 @@ void ServiceWorkerDispatcher::RegisterServiceWorker( WebServiceWorkerRegistrationCallbacks* callbacks) { DCHECK(callbacks); - if (pattern.possibly_invalid_spec().size() > kMaxURLChars || - script_url.possibly_invalid_spec().size() > kMaxURLChars) { + if (pattern.possibly_invalid_spec().size() > url::kMaxURLChars || + script_url.possibly_invalid_spec().size() > url::kMaxURLChars) { scoped_ptr owned_callbacks(callbacks); std::string error_message(kServiceWorkerRegisterErrorPrefix); @@ -161,7 +162,7 @@ void ServiceWorkerDispatcher::GetRegistration( WebServiceWorkerGetRegistrationCallbacks* callbacks) { DCHECK(callbacks); - if (document_url.possibly_invalid_spec().size() > kMaxURLChars) { + if (document_url.possibly_invalid_spec().size() > url::kMaxURLChars) { scoped_ptr owned_callbacks( callbacks); std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); diff --git a/content/common/BUILD.gn b/content/common/BUILD.gn index 3854840a7602b7..63d416ae81975f 100644 --- a/content/common/BUILD.gn +++ b/content/common/BUILD.gn @@ -170,6 +170,7 @@ source_set("common") { "//ui/gfx/ipc", "//ui/shell_dialogs", "//url", + "//url/ipc:url_ipc", ] if (!is_ios) { diff --git a/content/common/accessibility_messages.h b/content/common/accessibility_messages.h index 5a0a5986e94779..660484c2c69488 100644 --- a/content/common/accessibility_messages.h +++ b/content/common/accessibility_messages.h @@ -8,7 +8,6 @@ #include "content/common/ax_content_node_data.h" #include "content/common/content_export.h" #include "content/common/view_message_enums.h" -#include "content/public/common/common_param_traits.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_utils.h" #include "ipc/ipc_param_traits.h" diff --git a/content/common/appcache_messages.h b/content/common/appcache_messages.h index 7e74848e4dd974..95964f71c9de10 100644 --- a/content/common/appcache_messages.h +++ b/content/common/appcache_messages.h @@ -9,6 +9,7 @@ #include #include "content/common/appcache_interfaces.h" +#include "url/ipc/url_param_traits.h" #define IPC_MESSAGE_START AppCacheMsgStart diff --git a/content/common/browser_plugin/browser_plugin_messages.h b/content/common/browser_plugin/browser_plugin_messages.h index ef1640f6d83462..f85bafe726c0c6 100644 --- a/content/common/browser_plugin/browser_plugin_messages.h +++ b/content/common/browser_plugin/browser_plugin_messages.h @@ -12,7 +12,6 @@ #include "content/common/content_param_traits.h" #include "content/common/cursors/webcursor.h" #include "content/common/edit_command.h" -#include "content/public/common/common_param_traits.h" #include "content/public/common/drop_data.h" #include "ipc/ipc_channel_handle.h" #include "ipc/ipc_message_macros.h" @@ -26,7 +25,6 @@ #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" #include "ui/gfx/ipc/gfx_param_traits.h" -#include "url/gurl.h" #undef IPC_MESSAGE_EXPORT #define IPC_MESSAGE_EXPORT CONTENT_EXPORT diff --git a/content/common/clipboard_messages.h b/content/common/clipboard_messages.h index 00a198c1f6a75a..36877f0a241f1a 100644 --- a/content/common/clipboard_messages.h +++ b/content/common/clipboard_messages.h @@ -10,13 +10,16 @@ #include #include +#include "build/build_config.h" #include "base/memory/shared_memory.h" #include "base/strings/string16.h" #include "build/build_config.h" #include "content/common/clipboard_format.h" -#include "content/public/common/common_param_traits.h" +#include "content/common/content_export.h" #include "ipc/ipc_message_macros.h" +#include "ipc/param_traits_macros.h" #include "ui/base/clipboard/clipboard.h" +#include "url/ipc/url_param_traits.h" // Singly-included section for types and/or struct declarations. #ifndef CONTENT_COMMON_CLIPBOARD_MESSAGES_H_ diff --git a/content/common/common_param_traits_unittest.cc b/content/common/common_param_traits_unittest.cc index 03c19a08731829..648e6a6e718e03 100644 --- a/content/common/common_param_traits_unittest.cc +++ b/content/common/common_param_traits_unittest.cc @@ -20,68 +20,6 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/ipc/gfx_param_traits.h" -#include "url/gurl.h" - -// Tests that serialize/deserialize correctly understand each other -TEST(IPCMessageTest, Serialize) { - const char* serialize_cases[] = { - "http://www.google.com/", - "http://user:pass@host.com:888/foo;bar?baz#nop", - }; - - for (size_t i = 0; i < arraysize(serialize_cases); i++) { - GURL input(serialize_cases[i]); - IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); - IPC::ParamTraits::Write(&msg, input); - - GURL output; - base::PickleIterator iter(msg); - EXPECT_TRUE(IPC::ParamTraits::Read(&msg, &iter, &output)); - - // We want to test each component individually to make sure its range was - // correctly serialized and deserialized, not just the spec. - EXPECT_EQ(input.possibly_invalid_spec(), output.possibly_invalid_spec()); - EXPECT_EQ(input.is_valid(), output.is_valid()); - EXPECT_EQ(input.scheme(), output.scheme()); - EXPECT_EQ(input.username(), output.username()); - EXPECT_EQ(input.password(), output.password()); - EXPECT_EQ(input.host(), output.host()); - EXPECT_EQ(input.port(), output.port()); - EXPECT_EQ(input.path(), output.path()); - EXPECT_EQ(input.query(), output.query()); - EXPECT_EQ(input.ref(), output.ref()); - } - - // Test an excessively long GURL. - { - const std::string url = std::string("http://example.org/").append( - content::kMaxURLChars + 1, 'a'); - GURL input(url.c_str()); - IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); - IPC::ParamTraits::Write(&msg, input); - - GURL output; - base::PickleIterator iter(msg); - EXPECT_TRUE(IPC::ParamTraits::Read(&msg, &iter, &output)); - EXPECT_TRUE(output.is_empty()); - } - - // Test an invalid GURL. - { - IPC::Message msg; - msg.WriteString("#inva://idurl/"); - GURL output; - base::PickleIterator iter(msg); - EXPECT_FALSE(IPC::ParamTraits::Read(&msg, &iter, &output)); - } - - // Also test the corrupt case. - IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); - msg.WriteInt(99); - GURL output; - base::PickleIterator iter(msg); - EXPECT_FALSE(IPC::ParamTraits::Read(&msg, &iter, &output)); -} // Tests std::pair serialization TEST(IPCMessageTest, Pair) { diff --git a/content/common/devtools_messages.h b/content/common/devtools_messages.h index f61525c140ef7a..4c7c24a089d7a4 100644 --- a/content/common/devtools_messages.h +++ b/content/common/devtools_messages.h @@ -43,7 +43,6 @@ #include #include "content/common/content_export.h" -#include "content/public/common/common_param_traits.h" #include "content/public/common/console_message_level.h" #include "ipc/ipc_message_macros.h" diff --git a/content/common/dom_storage/dom_storage_messages.h b/content/common/dom_storage/dom_storage_messages.h index 7fd4426a766ded..59d22c9641b23e 100644 --- a/content/common/dom_storage/dom_storage_messages.h +++ b/content/common/dom_storage/dom_storage_messages.h @@ -7,11 +7,11 @@ #include #include "content/common/dom_storage/dom_storage_types.h" -#include "content/public/common/common_param_traits.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_param_traits.h" #include "third_party/WebKit/public/platform/WebStorageArea.h" #include "url/gurl.h" +#include "url/ipc/url_param_traits.h" #define IPC_MESSAGE_START DOMStorageMsgStart diff --git a/content/common/drag_messages.h b/content/common/drag_messages.h index 455bbffa067a79..8d2fd772370113 100644 --- a/content/common/drag_messages.h +++ b/content/common/drag_messages.h @@ -6,7 +6,6 @@ // Multiply-included message file, hence no include guard. #include "content/common/drag_event_source_info.h" -#include "content/public/common/common_param_traits.h" #include "content/public/common/drop_data.h" #include "ipc/ipc_message_macros.h" #include "third_party/WebKit/public/web/WebDragOperation.h" diff --git a/content/common/fileapi/webblob_messages.h b/content/common/fileapi/webblob_messages.h index 0dd31411d197a0..603e501442772e 100644 --- a/content/common/fileapi/webblob_messages.h +++ b/content/common/fileapi/webblob_messages.h @@ -8,9 +8,9 @@ #include #include "content/common/content_export.h" -#include "content/public/common/common_param_traits.h" #include "ipc/ipc_message_macros.h" #include "storage/common/data_element.h" +#include "url/ipc/url_param_traits.h" #undef IPC_MESSAGE_EXPORT #define IPC_MESSAGE_EXPORT CONTENT_EXPORT diff --git a/content/common/gpu/gpu_host_messages.h b/content/common/gpu/gpu_host_messages.h index b0414ab52071c6..1428c8a5bd0d82 100644 --- a/content/common/gpu/gpu_host_messages.h +++ b/content/common/gpu/gpu_host_messages.h @@ -23,6 +23,7 @@ #include "ui/gfx/ipc/gfx_param_traits.h" #include "ui/gfx/native_widget_types.h" #include "url/gurl.h" +#include "url/ipc/url_param_traits.h" #if defined(OS_MACOSX) #include "content/common/gpu/accelerated_surface_buffers_swapped_params_mac.h" diff --git a/content/common/input_messages.h b/content/common/input_messages.h index cef55684107796..cf4dc121e290d0 100644 --- a/content/common/input_messages.h +++ b/content/common/input_messages.h @@ -24,7 +24,6 @@ #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" #include "content/common/input/synthetic_tap_gesture_params.h" #include "content/common/input/touch_action.h" -#include "content/public/common/common_param_traits.h" #include "ipc/ipc_message_macros.h" #include "third_party/WebKit/public/web/WebInputEvent.h" #include "ui/events/ipc/latency_info_param_traits.h" diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 87cda02cb14ab3..f2d4939fa989d7 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -63,6 +63,7 @@ '../ui/snapshot/snapshot.gyp:snapshot', '../ui/surface/surface.gyp:surface', '../ui/touch_selection/ui_touch_selection.gyp:ui_touch_selection', + '../url/ipc/url_ipc.gyp:url_ipc', 'app/resources/content_resources.gyp:content_resources', 'app/strings/content_strings.gyp:content_strings', 'browser/background_sync/background_sync_proto.gyp:background_sync_proto', diff --git a/content/content_child.gypi b/content/content_child.gypi index 5ae11491e7b467..2d296ef11c76c5 100644 --- a/content/content_child.gypi +++ b/content/content_child.gypi @@ -24,6 +24,7 @@ '../ui/gfx/gfx.gyp:gfx', '../ui/gfx/gfx.gyp:gfx_geometry', '../url/url.gyp:url_lib', + '../url/ipc/url_ipc.gyp:url_ipc', 'app/resources/content_resources.gyp:content_resources', 'app/strings/content_strings.gyp:content_strings', 'content_common_mojo_bindings.gyp:content_common_mojo_bindings', diff --git a/content/content_common.gypi b/content/content_common.gypi index 372bab70120c68..e472b9f24dd817 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -46,6 +46,7 @@ '../ui/gl/gl.gyp:gl', '../ui/shell_dialogs/shell_dialogs.gyp:shell_dialogs', '../url/url.gyp:url_lib', + '../url/ipc/url_ipc.gyp:url_ipc', 'content.gyp:common_features', 'content_common_mojo_bindings.gyp:content_common_mojo_bindings', ], diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index e6c4065130a2eb..6a8486fd653e22 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -47,6 +47,7 @@ '../ui/gfx/gfx.gyp:gfx_geometry', '../ui/native_theme/native_theme.gyp:native_theme', '../ui/surface/surface.gyp:surface', + '../url/ipc/url_ipc.gyp:url_ipc', '../v8/tools/gyp/v8.gyp:v8', 'content_common_mojo_bindings.gyp:content_common_mojo_bindings', ], diff --git a/content/content_shell.gypi b/content/content_shell.gypi index ee17cb3e5093b6..dd6fe7d01b11a8 100644 --- a/content/content_shell.gypi +++ b/content/content_shell.gypi @@ -71,6 +71,7 @@ '../ui/gfx/ipc/gfx_ipc.gyp:gfx_ipc', '../ui/gl/gl.gyp:gl', '../url/url.gyp:url_lib', + '../url/ipc/url_ipc.gyp:url_ipc', '../v8/tools/gyp/v8.gyp:v8', ], 'include_dirs': [ diff --git a/content/public/common/BUILD.gn b/content/public/common/BUILD.gn index 83d47d6e07a9e5..9075452a68dd0d 100644 --- a/content/public/common/BUILD.gn +++ b/content/public/common/BUILD.gn @@ -88,6 +88,7 @@ source_set("common_sources") { public_deps = [ "//content/common", "//mojo/public/cpp/bindings", + "//url/ipc:url_ipc", ] deps = [ "//net", diff --git a/content/public/common/common_param_traits.cc b/content/public/common/common_param_traits.cc index 6a937c62c53218..f402cca31b34f0 100644 --- a/content/public/common/common_param_traits.cc +++ b/content/public/common/common_param_traits.cc @@ -15,47 +15,6 @@ namespace IPC { -void ParamTraits::Write(base::Pickle* m, const GURL& p) { - if (p.possibly_invalid_spec().length() > content::kMaxURLChars) { - m->WriteString(std::string()); - return; - } - - // Beware of print-parse inconsistency which would change an invalid - // URL into a valid one. Ideally, the message would contain this flag - // so that the read side could make the check, but performing it here - // avoids changing the on-the-wire representation of such a fundamental - // type as GURL. See https://crbug.com/166486 for additional work in - // this area. - if (!p.is_valid()) { - m->WriteString(std::string()); - return; - } - - m->WriteString(p.possibly_invalid_spec()); - // TODO(brettw) bug 684583: Add encoding for query params. -} - -bool ParamTraits::Read(const base::Pickle* m, - base::PickleIterator* iter, - GURL* p) { - std::string s; - if (!iter->ReadString(&s) || s.length() > content::kMaxURLChars) { - *p = GURL(); - return false; - } - *p = GURL(s); - if (!s.empty() && !p->is_valid()) { - *p = GURL(); - return false; - } - return true; -} - -void ParamTraits::Log(const GURL& p, std::string* l) { - l->append(p.spec()); -} - void ParamTraits::Write(base::Pickle* m, const url::Origin& p) { WriteParam(m, p.unique()); WriteParam(m, p.scheme()); diff --git a/content/public/common/common_param_traits.h b/content/public/common/common_param_traits.h index 5f55f13f72748a..4e7610cdc04b79 100644 --- a/content/public/common/common_param_traits.h +++ b/content/public/common/common_param_traits.h @@ -25,7 +25,7 @@ #include "ipc/ipc_message_utils.h" #include "ui/gfx/native_widget_types.h" #include "ui/surface/transport_dib.h" -#include "url/gurl.h" +#include "url/ipc/url_param_traits.h" #include "url/origin.h" #if defined(OS_WIN) @@ -44,16 +44,6 @@ class IPEndPoint; namespace IPC { -template <> -struct CONTENT_EXPORT ParamTraits { - typedef GURL param_type; - static void Write(base::Pickle* m, const param_type& p); - static bool Read(const base::Pickle* m, - base::PickleIterator* iter, - param_type* p); - static void Log(const param_type& p, std::string* l); -}; - template <> struct CONTENT_EXPORT ParamTraits { typedef url::Origin param_type; diff --git a/content/public/common/content_constants.cc b/content/public/common/content_constants.cc index 3a97a0903ac076..e33743361cbed8 100644 --- a/content/public/common/content_constants.cc +++ b/content/public/common/content_constants.cc @@ -26,7 +26,6 @@ const char kSilverlightPluginMimeTypePrefix[] = "application/x-silverlight"; const size_t kMaxRendererProcessCount = 82; const int kMaxSessionHistoryEntries = 50; const size_t kMaxTitleChars = 4 * 1024; -const size_t kMaxURLChars = 2 * 1024 * 1024; const size_t kMaxURLDisplayChars = 32 * 1024; #if defined(GOOGLE_CHROME_BUILD) diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc index 114c953d73823d..6b7e1ea545723a 100644 --- a/content/renderer/render_frame_impl.cc +++ b/content/renderer/render_frame_impl.cc @@ -180,6 +180,7 @@ #include "third_party/WebKit/public/web/WebSurroundingText.h" #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" #include "third_party/WebKit/public/web/WebView.h" +#include "url/url_constants.h" #include "url/url_util.h" #if defined(ENABLE_PLUGINS) @@ -3666,7 +3667,7 @@ void RenderFrameImpl::showContextMenu(const blink::WebContextMenuData& data) { // in the context menu. // TODO(jcivelli): http://crbug.com/45160 This prevents us from saving large // data encoded images. We should have a way to save them. - if (params.src_url.spec().size() > kMaxURLChars) + if (params.src_url.spec().size() > url::kMaxURLChars) params.src_url = GURL(); context_menu_node_ = data.node; diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc index 9e3b5446b2cadd..a264c8386af2c4 100644 --- a/content/renderer/render_view_impl.cc +++ b/content/renderer/render_view_impl.cc @@ -175,6 +175,7 @@ #include "ui/gfx/geometry/rect_conversions.h" #include "ui/gfx/geometry/size_conversions.h" #include "ui/gfx/native_widget_types.h" +#include "url/url_constants.h" #include "v8/include/v8.h" #if defined(OS_ANDROID) @@ -1897,7 +1898,7 @@ void RenderViewImpl::UpdateTargetURL(const GURL& url, } else { // URLs larger than |kMaxURLChars| cannot be sent through IPC - // see |ParamTraits|. - if (latest_url.possibly_invalid_spec().size() > kMaxURLChars) + if (latest_url.possibly_invalid_spec().size() > url::kMaxURLChars) latest_url = GURL(); Send(new ViewHostMsg_UpdateTargetURL(routing_id(), latest_url)); target_url_ = latest_url; diff --git a/content/shell/common/layout_test/layout_test_messages.h b/content/shell/common/layout_test/layout_test_messages.h index b81b0bc9f5795b..0ca330998a2104 100644 --- a/content/shell/common/layout_test/layout_test_messages.h +++ b/content/shell/common/layout_test/layout_test_messages.h @@ -6,11 +6,11 @@ #include #include -#include "content/public/common/common_param_traits.h" #include "content/public/common/permission_status.mojom.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_platform_file.h" #include "url/gurl.h" +#include "url/ipc/url_param_traits.h" #define IPC_MESSAGE_START LayoutTestMsgStart diff --git a/extensions/common/extension_utility_messages.h b/extensions/common/extension_utility_messages.h index cfaf2734d28410..24df23fb9d1a62 100644 --- a/extensions/common/extension_utility_messages.h +++ b/extensions/common/extension_utility_messages.h @@ -10,6 +10,7 @@ #include "ipc/ipc_message_macros.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/ipc/gfx_param_traits.h" +#include "url/ipc/url_param_traits.h" #define IPC_MESSAGE_START ExtensionUtilityMsgStart diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp index 82e7d6a65c3764..25d85793598bf8 100644 --- a/extensions/extensions.gyp +++ b/extensions/extensions.gyp @@ -68,6 +68,7 @@ '../url/url.gyp:url_lib', '../third_party/boringssl/boringssl.gyp:boringssl', '../third_party/libxml/libxml.gyp:libxml', + '../url/ipc/url_ipc.gyp:url_ipc', 'common/api/api.gyp:extensions_api', 'extensions_resources.gyp:extensions_resources', 'extensions_strings.gyp:extensions_strings', @@ -202,6 +203,7 @@ 'dependencies': [ 'extensions_resources.gyp:extensions_resources', '../components/components.gyp:guest_view_renderer', + '../content/content.gyp:content_common', '../content/content.gyp:content_resources', '../gin/gin.gyp:gin', '../mojo/mojo_public.gyp:mojo_js_bindings', diff --git a/extensions/utility/unpacker.cc b/extensions/utility/unpacker.cc index be0a4b53eb2742..083cb7203ad090 100644 --- a/extensions/utility/unpacker.cc +++ b/extensions/utility/unpacker.cc @@ -20,7 +20,6 @@ #include "base/threading/thread.h" #include "base/values.h" #include "content/public/child/image_decoder_utils.h" -#include "content/public/common/common_param_traits.h" #include "extensions/common/constants.h" #include "extensions/common/extension.h" #include "extensions/common/extension_l10n_util.h" diff --git a/url/ipc/BUILD.gn b/url/ipc/BUILD.gn new file mode 100644 index 00000000000000..1edbe2086bf54b --- /dev/null +++ b/url/ipc/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (c) 2016 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. + +import("//testing/test.gni") + +component("url_ipc") { + sources = [ + "url_ipc_export.h", + "url_param_traits.cc", + "url_param_traits.h", + ] + + defines = [ "URL_IPC_IMPLEMENTATION" ] + + public_deps = [ + "//ipc", + "//url", + ] + deps = [ + "//base", + ] +} + +test("url_ipc_unittests") { + sources = [ + "url_param_traits_unittest.cc", + ] + + deps = [ + ":url_ipc", + "//base", + "//base/test:run_all_unittests", + "//ipc:test_support", + "//testing/gtest", + "//url:url", + ] +} diff --git a/url/ipc/url_ipc.gyp b/url/ipc/url_ipc.gyp new file mode 100644 index 00000000000000..f56b5e80f07af2 --- /dev/null +++ b/url/ipc/url_ipc.gyp @@ -0,0 +1,42 @@ +# Copyright 2016 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. + +{ + 'variables': { + 'chromium_code': 1, + }, + 'targets': [ + { + # GN version: //url/ipc + 'target_name': 'url_ipc', + 'type': '<(component)', + 'dependencies': [ + '../../base/base.gyp:base', + '../../ipc/ipc.gyp:ipc', + '../../url/url.gyp:url_lib', + ], + 'defines': [ 'URL_IPC_IMPLEMENTATION' ], + 'include_dirs': [ + '../..', + ], + 'sources': [ + 'url_ipc_export.h', + 'url_param_traits.cc', + 'url_param_traits.h', + ], + }, + { + 'target_name': 'url_ipc_unittests', + 'type': 'executable', + 'dependencies': [ + '../../base/base.gyp:run_all_unittests', + '../../ipc/ipc.gyp:test_support_ipc', + '../../testing/gtest.gyp:gtest', + '../url.gyp:url_lib', + 'url_ipc', + ], + 'sources': [ 'url_param_traits_unittest.cc' ], + }, + ], +} diff --git a/url/ipc/url_ipc_export.h b/url/ipc/url_ipc_export.h new file mode 100644 index 00000000000000..1da0fa6854b953 --- /dev/null +++ b/url/ipc/url_ipc_export.h @@ -0,0 +1,29 @@ +// Copyright 2016 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. + +#ifndef URL_IPC_EXPORT_H_ +#define URL_IPC_EXPORT_H_ + +#if defined(COMPONENT_BUILD) +#if defined(WIN32) + +#if defined(URL_IPC_IMPLEMENTATION) +#define URL_IPC_EXPORT __declspec(dllexport) +#else +#define URL_IPC_EXPORT __declspec(dllimport) +#endif // defined(URL_IPC_IMPLEMENTATION) + +#else // defined(WIN32) +#if defined(URL_IPC_IMPLEMENTATION) +#define URL_IPC_EXPORT __attribute__((visibility("default"))) +#else +#define URL_IPC_EXPORT +#endif +#endif + +#else // defined(COMPONENT_BUILD) +#define URL_IPC_EXPORT +#endif + +#endif // URL_IPC_EXPORT_H_ diff --git a/url/ipc/url_param_traits.cc b/url/ipc/url_param_traits.cc new file mode 100644 index 00000000000000..e40ae8f9a3c9cc --- /dev/null +++ b/url/ipc/url_param_traits.cc @@ -0,0 +1,52 @@ +// Copyright (c) 2016 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. + +#include "url/ipc/url_param_traits.h" + +#include "url/gurl.h" + +namespace IPC { + +void ParamTraits::Write(base::Pickle* m, const GURL& p) { + if (p.possibly_invalid_spec().length() > url::kMaxURLChars) { + m->WriteString(std::string()); + return; + } + + // Beware of print-parse inconsistency which would change an invalid + // URL into a valid one. Ideally, the message would contain this flag + // so that the read side could make the check, but performing it here + // avoids changing the on-the-wire representation of such a fundamental + // type as GURL. See https://crbug.com/166486 for additional work in + // this area. + if (!p.is_valid()) { + m->WriteString(std::string()); + return; + } + + m->WriteString(p.possibly_invalid_spec()); + // TODO(brettw) bug 684583: Add encoding for query params. +} + +bool ParamTraits::Read(const base::Pickle* m, + base::PickleIterator* iter, + GURL* p) { + std::string s; + if (!iter->ReadString(&s) || s.length() > url::kMaxURLChars) { + *p = GURL(); + return false; + } + *p = GURL(s); + if (!s.empty() && !p->is_valid()) { + *p = GURL(); + return false; + } + return true; +} + +void ParamTraits::Log(const GURL& p, std::string* l) { + l->append(p.spec()); +} + +} // namespace IPC diff --git a/url/ipc/url_param_traits.h b/url/ipc/url_param_traits.h new file mode 100644 index 00000000000000..f40150f110d65f --- /dev/null +++ b/url/ipc/url_param_traits.h @@ -0,0 +1,26 @@ +// Copyright (c) 2016 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. + +#ifndef URL_IPC_URL_PARAM_TRAITS_H_ +#define URL_IPC_URL_PARAM_TRAITS_H_ + +#include "ipc/ipc_message_utils.h" +#include "url/gurl.h" +#include "url/ipc/url_ipc_export.h" + +namespace IPC { + +template <> +struct URL_IPC_EXPORT ParamTraits { + typedef GURL param_type; + static void Write(base::Pickle* m, const param_type& p); + static bool Read(const base::Pickle* m, + base::PickleIterator* iter, + param_type* p); + static void Log(const param_type& p, std::string* l); +}; + +} // namespace IPC + +#endif // URL_IPC_URL_PARAM_TRAITS_H_ diff --git a/url/ipc/url_param_traits_unittest.cc b/url/ipc/url_param_traits_unittest.cc new file mode 100644 index 00000000000000..16eeab0372f37e --- /dev/null +++ b/url/ipc/url_param_traits_unittest.cc @@ -0,0 +1,72 @@ +// Copyright (c) 2016 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. + +#include + +#include "ipc/ipc_message.h" +#include "ipc/ipc_message_utils.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "url/gurl.h" +#include "url/ipc/url_param_traits.h" + +// Tests that serialize/deserialize correctly understand each other. +TEST(IPCMessageTest, Serialize) { + const char* serialize_cases[] = { + "http://www.google.com/", + "http://user:pass@host.com:888/foo;bar?baz#nop", + }; + + for (size_t i = 0; i < arraysize(serialize_cases); i++) { + GURL input(serialize_cases[i]); + IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); + IPC::ParamTraits::Write(&msg, input); + + GURL output; + base::PickleIterator iter(msg); + EXPECT_TRUE(IPC::ParamTraits::Read(&msg, &iter, &output)); + + // We want to test each component individually to make sure its range was + // correctly serialized and deserialized, not just the spec. + EXPECT_EQ(input.possibly_invalid_spec(), output.possibly_invalid_spec()); + EXPECT_EQ(input.is_valid(), output.is_valid()); + EXPECT_EQ(input.scheme(), output.scheme()); + EXPECT_EQ(input.username(), output.username()); + EXPECT_EQ(input.password(), output.password()); + EXPECT_EQ(input.host(), output.host()); + EXPECT_EQ(input.port(), output.port()); + EXPECT_EQ(input.path(), output.path()); + EXPECT_EQ(input.query(), output.query()); + EXPECT_EQ(input.ref(), output.ref()); + } + + // Test an excessively long GURL. + { + const std::string url = std::string("http://example.org/").append( + url::kMaxURLChars + 1, 'a'); + GURL input(url.c_str()); + IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); + IPC::ParamTraits::Write(&msg, input); + + GURL output; + base::PickleIterator iter(msg); + EXPECT_TRUE(IPC::ParamTraits::Read(&msg, &iter, &output)); + EXPECT_TRUE(output.is_empty()); + } + + // Test an invalid GURL. + { + IPC::Message msg; + msg.WriteString("#inva://idurl/"); + GURL output; + base::PickleIterator iter(msg); + EXPECT_FALSE(IPC::ParamTraits::Read(&msg, &iter, &output)); + } + + // Also test the corrupt case. + IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); + msg.WriteInt(99); + GURL output; + base::PickleIterator iter(msg); + EXPECT_FALSE(IPC::ParamTraits::Read(&msg, &iter, &output)); +} diff --git a/url/url_constants.cc b/url/url_constants.cc index 2dc1478a8e0e12..0388fbc221b679 100644 --- a/url/url_constants.cc +++ b/url/url_constants.cc @@ -25,4 +25,6 @@ const char kWssScheme[] = "wss"; const char kStandardSchemeSeparator[] = "://"; +const size_t kMaxURLChars = 2 * 1024 * 1024; + } // namespace url diff --git a/url/url_constants.h b/url/url_constants.h index c48dafcd27dd5d..fa71164cca3b7c 100644 --- a/url/url_constants.h +++ b/url/url_constants.h @@ -5,6 +5,8 @@ #ifndef URL_URL_CONSTANTS_H_ #define URL_URL_CONSTANTS_H_ +#include + #include "url/url_export.h" namespace url { @@ -30,6 +32,8 @@ URL_EXPORT extern const char kWssScheme[]; // Used to separate a standard scheme and the hostname: "://". URL_EXPORT extern const char kStandardSchemeSeparator[]; +URL_EXPORT extern const size_t kMaxURLChars; + } // namespace url #endif // URL_URL_CONSTANTS_H_