Change FilePath to use EnableIf instead of native typemapping.
Bug: 676224
Change-Id: I101d138ac8ca72815cc6aa0a1b5ad4218b3c3001
Reviewed-on: https://chromium-review.googlesource.com/1065753
Reviewed-by: Ken Rockot <rockot@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560839}
diff --git a/chrome/services/util_win/public/mojom/shell_util_win.typemap b/chrome/services/util_win/public/mojom/shell_util_win.typemap
index 7e05c23..dcbf2a0 100644
--- a/chrome/services/util_win/public/mojom/shell_util_win.typemap
+++ b/chrome/services/util_win/public/mojom/shell_util_win.typemap
@@ -5,6 +5,7 @@
mojom = "//chrome/services/util_win/public/mojom/shell_util_win.mojom"
public_headers = [ "//base/strings/string16.h" ]
+traits_headers = [ "//ipc/ipc_message_utils.h" ]
deps = [
"//base",
diff --git a/mojo/public/cpp/base/BUILD.gn b/mojo/public/cpp/base/BUILD.gn
index 78a615a..e97ccda 100644
--- a/mojo/public/cpp/base/BUILD.gn
+++ b/mojo/public/cpp/base/BUILD.gn
@@ -30,6 +30,8 @@
sources = [
"big_buffer_mojom_traits.cc",
"big_buffer_mojom_traits.h",
+ "file_path_mojom_traits.cc",
+ "file_path_mojom_traits.h",
"shared_memory_mojom_traits.cc",
"shared_memory_mojom_traits.h",
"values_mojom_traits.cc",
diff --git a/mojo/public/cpp/base/file_path.typemap b/mojo/public/cpp/base/file_path.typemap
index 682200f..aa30b2d8 100644
--- a/mojo/public/cpp/base/file_path.typemap
+++ b/mojo/public/cpp/base/file_path.typemap
@@ -4,9 +4,9 @@
mojom = "//mojo/public/mojom/base/file_path.mojom"
public_headers = [ "//base/files/file_path.h" ]
-traits_headers = [ "//ipc/ipc_message_utils.h" ]
+traits_headers = [ "//mojo/public/cpp/base/file_path_mojom_traits.h" ]
public_deps = [
- "//ipc",
+ "//mojo/public/cpp/base:shared_typemap_traits",
]
type_mappings = [ "mojo_base.mojom.FilePath=base::FilePath" ]
diff --git a/mojo/public/cpp/base/file_path_mojom_traits.cc b/mojo/public/cpp/base/file_path_mojom_traits.cc
new file mode 100644
index 0000000..f7af33d
--- /dev/null
+++ b/mojo/public/cpp/base/file_path_mojom_traits.cc
@@ -0,0 +1,28 @@
+// Copyright 2018 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 "mojo/public/cpp/base/file_path_mojom_traits.h"
+
+namespace mojo {
+
+// static
+bool StructTraits<mojo_base::mojom::FilePathDataView, base::FilePath>::Read(
+ mojo_base::mojom::FilePathDataView data,
+ base::FilePath* out) {
+ base::FilePath::StringPieceType path_view;
+#if defined(OS_WIN)
+ ArrayDataView<uint16_t> view;
+ data.GetPathDataView(&view);
+ path_view.set(reinterpret_cast<const base::char16*>(view.data()),
+ view.size());
+#else
+ if (!data.ReadPath(&path_view)) {
+ return false;
+ }
+#endif
+ *out = base::FilePath(path_view);
+ return true;
+}
+
+} // namespace mojo
diff --git a/mojo/public/cpp/base/file_path_mojom_traits.h b/mojo/public/cpp/base/file_path_mojom_traits.h
new file mode 100644
index 0000000..f974f1c2
--- /dev/null
+++ b/mojo/public/cpp/base/file_path_mojom_traits.h
@@ -0,0 +1,38 @@
+// Copyright 2018 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 MOJO_PUBLIC_CPP_BASE_FILE_PATH_MOJOM_TRAITS_H_
+#define MOJO_PUBLIC_CPP_BASE_FILE_PATH_MOJOM_TRAITS_H_
+
+#include "base/component_export.h"
+#include "base/containers/span.h"
+#include "base/files/file_path.h"
+#include "build/build_config.h"
+#include "mojo/public/cpp/bindings/struct_traits.h"
+#include "mojo/public/mojom/base/file_path.mojom-shared.h"
+
+namespace mojo {
+
+template <>
+struct COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS)
+ StructTraits<mojo_base::mojom::FilePathDataView, base::FilePath> {
+#if defined(OS_WIN)
+ static base::span<const uint16_t> path(const base::FilePath& path) {
+ return base::make_span(
+ reinterpret_cast<const uint16_t*>(path.value().data()),
+ path.value().size());
+ }
+#else
+ static const base::FilePath::StringType& path(const base::FilePath& path) {
+ return path.value();
+ }
+#endif
+
+ static bool Read(mojo_base::mojom::FilePathDataView data,
+ base::FilePath* out);
+};
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BASE_FILE_PATH_MOJOM_TRAITS_H_
diff --git a/mojo/public/cpp/base/file_path_unittest.cc b/mojo/public/cpp/base/file_path_unittest.cc
index 9c53bff..a5b027a9 100644
--- a/mojo/public/cpp/base/file_path_unittest.cc
+++ b/mojo/public/cpp/base/file_path_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ipc/ipc_message_utils.h"
+#include "mojo/public/cpp/base/file_path_mojom_traits.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "mojo/public/mojom/base/file_path.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/mojo/public/mojom/base/BUILD.gn b/mojo/public/mojom/base/BUILD.gn
index acbc814..807d4b9 100644
--- a/mojo/public/mojom/base/BUILD.gn
+++ b/mojo/public/mojom/base/BUILD.gn
@@ -27,9 +27,11 @@
if (is_win) {
sources += [ "logfont_win.mojom" ]
}
-
- if (is_posix && !is_android && !is_fuchsia && !is_mac) {
- enabled_features = [ "shared_memory_region_uses_fd_pair" ]
+ enabled_features = []
+ if (is_win) {
+ enabled_features += [ "file_path_is_string16" ]
+ } else {
+ enabled_features += [ "file_path_is_string" ]
}
output_prefix = "mojo_base_mojom"
diff --git a/mojo/public/mojom/base/file_path.mojom b/mojo/public/mojom/base/file_path.mojom
index cbe0bbe..674d8cd 100644
--- a/mojo/public/mojom/base/file_path.mojom
+++ b/mojo/public/mojom/base/file_path.mojom
@@ -4,5 +4,15 @@
module mojo_base.mojom;
-[Native]
-struct FilePath;
+struct FilePath {
+ [EnableIf=file_path_is_string]
+ string path;
+
+ // This duplicates the contents of mojo_base.mojom.String16. String16 isn't
+ // used here due to typemapping dependency problems. base::FilePath is
+ // used for the typemap for both variants, but base::string16 and WTF::String
+ // are used for mojo_base.mojom.String16 typemapping. This mismatch causes
+ // problems with dependencies.
+ [EnableIf=file_path_is_string16]
+ array<uint16> path;
+};
diff --git a/ui/display/mojo/display_snapshot_struct_traits.cc b/ui/display/mojo/display_snapshot_struct_traits.cc
index 165c378e6..2132e86 100644
--- a/ui/display/mojo/display_snapshot_struct_traits.cc
+++ b/ui/display/mojo/display_snapshot_struct_traits.cc
@@ -4,6 +4,7 @@
#include "ui/display/mojo/display_snapshot_struct_traits.h"
+#include "mojo/public/cpp/base/file_path_mojom_traits.h"
#include "ui/display/types/display_constants.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/geometry/size.h"
diff --git a/ui/display/mojo/display_struct_traits_unittest.cc b/ui/display/mojo/display_struct_traits_unittest.cc
index 8d956238..f20bb0545 100644
--- a/ui/display/mojo/display_struct_traits_unittest.cc
+++ b/ui/display/mojo/display_struct_traits_unittest.cc
@@ -8,6 +8,7 @@
#include <vector>
#include "base/macros.h"
+#include "mojo/public/cpp/base/file_path_mojom_traits.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/display/display.h"
#include "ui/display/display_layout.h"