summaryrefslogtreecommitdiffstats
path: root/url
diff options
context:
space:
mode:
authorjam <jam@chromium.org>2016-03-03 15:11:54 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-03 23:13:21 +0000
commitbaaeb815d807659fc7fe9b8cba2cc3b4d20018bf (patch)
tree5763d074a5369c6c4d2d25dc935fb07bacdc5fc3 /url
parentfd4a7725b4762877ef29c50bf2e0095e8d26fe39 (diff)
downloadchromium_src-baaeb815d807659fc7fe9b8cba2cc3b4d20018bf.zip
chromium_src-baaeb815d807659fc7fe9b8cba2cc3b4d20018bf.tar.gz
chromium_src-baaeb815d807659fc7fe9b8cba2cc3b4d20018bf.tar.bz2
Add mojo struct traits for GURL so that it can be sent over mojoms.
The motivation for adding a structtraits for GURL, as opposed to using paramtraits, is that most probably we'll be passing urls to languages other than C++. BUG=586194 Review URL: https://codereview.chromium.org/1760643004 Cr-Commit-Position: refs/heads/master@{#379128}
Diffstat (limited to 'url')
-rw-r--r--url/BUILD.gn7
-rw-r--r--url/DEPS4
-rw-r--r--url/mojo/BUILD.gn36
-rw-r--r--url/mojo/DEPS3
-rw-r--r--url/mojo/OWNERS27
-rw-r--r--url/mojo/gurl.typemap14
-rw-r--r--url/mojo/url.mojom9
-rw-r--r--url/mojo/url_gurl_struct_traits.h39
-rw-r--r--url/mojo/url_gurl_struct_traits_unittest.cc73
-rw-r--r--url/mojo/url_test.mojom12
-rw-r--r--url/run_all_unittests.cc35
-rw-r--r--url/url.gyp73
12 files changed, 330 insertions, 2 deletions
diff --git a/url/BUILD.gn b/url/BUILD.gn
index 6924784..94efa01 100644
--- a/url/BUILD.gn
+++ b/url/BUILD.gn
@@ -118,7 +118,9 @@ if (!is_android) {
test("url_unittests") {
sources = [
"gurl_unittest.cc",
+ "mojo/url_gurl_struct_traits_unittest.cc",
"origin_unittest.cc",
+ "run_all_unittests.cc",
"scheme_host_port_unittest.cc",
"url_canon_icu_unittest.cc",
"url_canon_unittest.cc",
@@ -133,9 +135,12 @@ if (!is_android) {
deps = [
":url",
"//base",
- "//base/test:run_all_unittests",
+ "//base/test:test_support",
+ "//mojo/edk/system",
+ "//mojo/edk/test:test_support",
"//testing/gtest",
"//third_party/icu:icuuc",
+ "//url/mojo:test_url_mojom_gurl",
]
}
}
diff --git a/url/DEPS b/url/DEPS
index 9643291..c89ac32 100644
--- a/url/DEPS
+++ b/url/DEPS
@@ -10,4 +10,8 @@ specific_include_rules = {
"url_canon_icu(\.cc|_unittest\.cc)": [
"+third_party/icu",
],
+ "run_all_unittests\.cc": [
+ "+mojo/edk/embedder/embedder.h",
+ "+mojo/edk/test/scoped_ipc_support.h",
+ ],
}
diff --git a/url/mojo/BUILD.gn b/url/mojo/BUILD.gn
new file mode 100644
index 0000000..6c1b174
--- /dev/null
+++ b/url/mojo/BUILD.gn
@@ -0,0 +1,36 @@
+# 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.
+
+import("//mojo/public/tools/bindings/mojom.gni")
+
+mojom("url_mojom") {
+ sources = [
+ "url.mojom",
+ ]
+}
+
+mojom("url_mojom_gurl") {
+ sources = [
+ "url.mojom",
+ ]
+
+ variant = "chromium"
+ typemaps = [ "gurl.typemap" ]
+
+ public_deps = [
+ ":url_mojom",
+ ]
+}
+
+mojom("test_url_mojom_gurl") {
+ sources = [
+ "url_test.mojom",
+ ]
+
+ typemaps = [ "gurl.typemap" ]
+
+ public_deps = [
+ ":url_mojom_gurl",
+ ]
+}
diff --git a/url/mojo/DEPS b/url/mojo/DEPS
new file mode 100644
index 0000000..093b1d9
--- /dev/null
+++ b/url/mojo/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+ "+mojo/public/cpp",
+]
diff --git a/url/mojo/OWNERS b/url/mojo/OWNERS
new file mode 100644
index 0000000..7a5a05a
--- /dev/null
+++ b/url/mojo/OWNERS
@@ -0,0 +1,27 @@
+# Changes to IPC serialization require a security review to avoid introducing
+# new sandbox escapes.
+per-file url_gurl_struct_traits.h=set noparent
+per-file url_gurl_struct_traits.h=dcheng@chromium.org
+per-file url_gurl_struct_traits.h=inferno@chromium.org
+per-file url_gurl_struct_traits.h=jln@chromium.org
+per-file url_gurl_struct_traits.h=jschuh@chromium.org
+per-file url_gurl_struct_traits.h=kenrb@chromium.org
+per-file url_gurl_struct_traits.h=mkwst@chromium.org
+per-file url_gurl_struct_traits.h=nasko@chromium.org
+per-file url_gurl_struct_traits.h=palmer@chromium.org
+per-file url_gurl_struct_traits.h=tsepez@chromium.org
+per-file url_gurl_struct_traits.h=wfh@chromium.org
+
+# Changes to Mojo interfaces require a security review to avoid
+# introducing new sandbox escapes.
+per-file *.mojom=set noparent
+per-file *.mojom=dcheng@chromium.org
+per-file *.mojom=inferno@chromium.org
+per-file *.mojom=jln@chromium.org
+per-file *.mojom=jschuh@chromium.org
+per-file *.mojom=kenrb@chromium.org
+per-file *.mojom=mkwst@chromium.org
+per-file *.mojom=nasko@chromium.org
+per-file *.mojom=palmer@chromium.org
+per-file *.mojom=tsepez@chromium.org
+per-file *.mojom=wfh@chromium.org
diff --git a/url/mojo/gurl.typemap b/url/mojo/gurl.typemap
new file mode 100644
index 0000000..93840c5
--- /dev/null
+++ b/url/mojo/gurl.typemap
@@ -0,0 +1,14 @@
+// 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.
+
+{
+ "c++": {
+ "url.mojom.Url": {
+ "typename": "GURL",
+ "headers": [
+ "url/mojo/url_gurl_struct_traits.h"
+ ]
+ }
+ }
+}
diff --git a/url/mojo/url.mojom b/url/mojo/url.mojom
new file mode 100644
index 0000000..56ca8ee
--- /dev/null
+++ b/url/mojo/url.mojom
@@ -0,0 +1,9 @@
+// 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.
+
+module url.mojom;
+
+struct Url {
+ string url;
+}; \ No newline at end of file
diff --git a/url/mojo/url_gurl_struct_traits.h b/url/mojo/url_gurl_struct_traits.h
new file mode 100644
index 0000000..1894baf
--- /dev/null
+++ b/url/mojo/url_gurl_struct_traits.h
@@ -0,0 +1,39 @@
+// 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.
+
+#include "base/strings/string_piece.h"
+#include "url/gurl.h"
+#include "url/mojo/url.mojom.h"
+
+namespace mojo {
+
+// copied from content/public/common/content_constants.cc: make that file use
+// this definition.
+const size_t kMaxUrlChars = 2 * 1024 * 1024;
+
+template <>
+struct StructTraits<url::mojom::Url, GURL> {
+ static base::StringPiece url(const GURL& r) {
+ if (r.possibly_invalid_spec().length() > kMaxUrlChars || !r.is_valid()) {
+ return base::StringPiece();
+ }
+
+ return base::StringPiece(r.possibly_invalid_spec().c_str(),
+ r.possibly_invalid_spec().length());
+ }
+ static bool Read(url::mojom::Url::Reader r, GURL* out) {
+ if (r.url().length() > kMaxUrlChars) {
+ *out = GURL();
+ return false;
+ }
+ *out = GURL(r.url());
+ if (!r.url().empty() && !out->is_valid()) {
+ *out = GURL();
+ return false;
+ }
+ return true;
+ }
+};
+
+}
diff --git a/url/mojo/url_gurl_struct_traits_unittest.cc b/url/mojo/url_gurl_struct_traits_unittest.cc
new file mode 100644
index 0000000..061e114
--- /dev/null
+++ b/url/mojo/url_gurl_struct_traits_unittest.cc
@@ -0,0 +1,73 @@
+// 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.
+
+#include <utility>
+
+#include "base/logging.h"
+#include "base/macros.h"
+#include "mojo/public/cpp/bindings/binding.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/mojo/url_test.mojom.h"
+
+namespace url {
+
+class UrlTestImpl : public mojom::UrlTest {
+ public:
+ explicit UrlTestImpl(mojo::InterfaceRequest<url::mojom::UrlTest> request)
+ : binding_(this, std::move(request)) {
+ }
+
+ // UrlTest:
+ void Bounce(const GURL& in, const BounceCallback& callback) override {
+ callback.Run(in);
+ }
+
+ private:
+ mojo::Binding<UrlTest> binding_;
+};
+
+// Mojo version of chrome IPC test in
+// content/common/common_param_traits_unittest.cc
+TEST(MojoUrlGURLStructTraitsTest, Basic) {
+ base::MessageLoop message_loop;
+
+ mojom::UrlTestPtr proxy;
+ UrlTestImpl impl(GetProxy(&proxy));
+
+ 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]);
+ GURL output;
+ EXPECT_TRUE(proxy->Bounce(input, &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(
+ mojo::kMaxUrlChars + 1, 'a');
+ GURL input(url.c_str());
+ GURL output;
+ EXPECT_TRUE(proxy->Bounce(input, &output));
+ EXPECT_TRUE(output.is_empty());
+ }
+}
+
+} // namespace url
diff --git a/url/mojo/url_test.mojom b/url/mojo/url_test.mojom
new file mode 100644
index 0000000..8efa8b2
--- /dev/null
+++ b/url/mojo/url_test.mojom
@@ -0,0 +1,12 @@
+// 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.
+
+module url.mojom;
+
+import "url/mojo/url.mojom";
+
+interface UrlTest {
+ [Sync]
+ Bounce(Url in) => (Url out);
+}; \ No newline at end of file
diff --git a/url/run_all_unittests.cc b/url/run_all_unittests.cc
new file mode 100644
index 0000000..b3bdcc2
--- /dev/null
+++ b/url/run_all_unittests.cc
@@ -0,0 +1,35 @@
+// 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.
+
+#include "base/bind.h"
+#include "base/message_loop/message_loop.h"
+#include "base/test/launcher/unit_test_launcher.h"
+#include "base/test/test_io_thread.h"
+#include "base/test/test_suite.h"
+#include "build/build_config.h"
+#include "mojo/edk/embedder/embedder.h"
+#include "mojo/edk/test/scoped_ipc_support.h"
+
+#if defined(OS_ANDROID)
+#include "base/android/jni_android.h"
+#include "base/test/test_file_util.h"
+#endif
+
+int main(int argc, char** argv) {
+#if defined(OS_ANDROID)
+ JNIEnv* env = base::android::AttachCurrentThread();
+ base::RegisterContentUriTestUtils(env);
+#endif
+ base::TestSuite test_suite(argc, argv);
+
+ mojo::edk::Init();
+ base::TestIOThread test_io_thread(base::TestIOThread::kAutoStart);
+ scoped_ptr<mojo::edk::test::ScopedIPCSupport> ipc_support;
+ ipc_support.reset(
+ new mojo::edk::test::ScopedIPCSupport(test_io_thread.task_runner()));
+
+ return base::LaunchUnitTests(
+ argc, argv,
+ base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
+}
diff --git a/url/url.gyp b/url/url.gyp
index e9e7ff5..e7fb3aa 100644
--- a/url/url.gyp
+++ b/url/url.gyp
@@ -40,14 +40,18 @@
'target_name': 'url_unittests',
'type': 'executable',
'dependencies': [
- '../base/base.gyp:run_all_unittests',
+ '../base/base.gyp:test_support_base',
+ '../mojo/mojo_edk.gyp:mojo_common_test_support',
'../testing/gtest.gyp:gtest',
'../third_party/icu/icu.gyp:icuuc',
+ 'url_test_mojom',
'url_lib',
],
'sources': [
'gurl_unittest.cc',
+ 'mojo/url_gurl_struct_traits_unittest.cc',
'origin_unittest.cc',
+ 'run_all_unittests.cc',
'scheme_host_port_unittest.cc',
'url_canon_icu_unittest.cc',
'url_canon_unittest.cc',
@@ -58,6 +62,73 @@
# TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
'msvs_disabled_warnings': [4267, ],
},
+ {
+ 'target_name': 'url_interfaces_mojom',
+ 'type': 'none',
+ 'variables': {
+ 'mojom_files': [
+ 'mojo/url.mojom',
+ ],
+ },
+ 'includes': [ '../mojo/mojom_bindings_generator_explicit.gypi' ],
+ },
+ {
+ 'target_name': 'url_mojom_chromium',
+ 'type': 'none',
+ 'variables': {
+ 'mojom_variant': 'chromium',
+ 'mojom_extra_generator_args': [
+ '--typemap', '<(DEPTH)/url/mojo/gurl.typemap',
+ ],
+ 'mojom_files': [
+ 'mojo/url.mojom',
+ ],
+ },
+ 'includes': [ '../mojo/mojom_bindings_generator_explicit.gypi' ],
+ 'dependencies': [
+ 'url_interfaces_mojom',
+ ],
+ },
+ {
+ 'target_name': 'url_mojom',
+ 'type': 'static_library',
+ 'export_dependent_settings': [
+ '../mojo/mojo_public.gyp:mojo_cpp_bindings',
+ ],
+ 'dependencies': [
+ '../mojo/mojo_public.gyp:mojo_cpp_bindings',
+ 'url_interfaces_mojom',
+ ],
+ },
+ {
+ 'target_name': 'url_test_interfaces_mojom',
+ 'type': 'none',
+ 'variables': {
+ 'mojom_extra_generator_args': [
+ '--typemap', '<(DEPTH)/url/mojo/gurl.typemap',
+ ],
+ 'mojom_files': [
+ 'mojo/url_test.mojom',
+ ],
+ },
+ 'includes': [ '../mojo/mojom_bindings_generator_explicit.gypi' ],
+ 'dependencies': [
+ '../mojo/mojo_public.gyp:mojo_cpp_bindings',
+ 'url_mojom_chromium',
+ ],
+ },
+ {
+ 'target_name': 'url_test_mojom',
+ 'type': 'static_library',
+ 'export_dependent_settings': [
+ '../mojo/mojo_public.gyp:mojo_cpp_bindings',
+ ],
+ 'dependencies': [
+ '../mojo/mojo_public.gyp:mojo_cpp_bindings',
+ 'url_mojom',
+ 'url_test_interfaces_mojom',
+ ],
+ },
],
'conditions': [
['OS=="android"', {