Commit 54a0c925 authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[string16] Use WString in Chrome Cleaner Mojo Interfaces

This change adds a wstring.mojom to chrome_cleaner, renames
string16_embedded_nulls.mojom to wstring_embedded_nulls.mojom
and makes WStringEmbeddedNulls an alias for String16EmbeddedNulls.

Bug: 911896
Change-Id: I9fbf8cb4e0252eb21f66fc89610438da44bd9df8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2316357
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarJoe Mason <joenotcharles@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792162}
parent 01bade90
......@@ -32,6 +32,10 @@ chrome_cleaner_mojom("footprints_interface") {
sources = [ "footprints.mojom" ]
}
chrome_cleaner_mojom("wstring") {
sources = [ "wstring.mojom" ]
}
chrome_cleaner_mojom("engine_sandbox_interface") {
sources = [
"cleaner_engine_requests.mojom",
......@@ -39,18 +43,22 @@ chrome_cleaner_mojom("engine_sandbox_interface") {
"engine_requests.mojom",
"engine_sandbox.mojom",
"pup.mojom",
"string16_embedded_nulls.mojom",
"windows_handle.mojom",
"wstring_embedded_nulls.mojom",
]
deps = [
":footprints_interface",
":wstring",
"//mojo/public/mojom/base",
]
}
chrome_cleaner_mojom("parser_interface") {
sources = [ "parser_interface.mojom" ]
deps = [ "//mojo/public/mojom/base" ]
deps = [
":wstring",
"//mojo/public/mojom/base",
]
}
chrome_cleaner_mojom("zip_archiver_interface") {
......@@ -62,7 +70,7 @@ chrome_cleaner_mojom("engine_sandbox_test_interface") {
sources = [
"test_pup_typemap.mojom",
"test_string16_embedded_nulls.mojom",
"test_wstring_embedded_nulls.mojom",
]
deps = [ ":engine_sandbox_interface" ]
......
......@@ -5,8 +5,8 @@
module chrome_cleaner.mojom;
import "chrome/chrome_cleaner/mojom/footprints.mojom";
import "chrome/chrome_cleaner/mojom/string16_embedded_nulls.mojom";
import "mojo/public/mojom/base/string16.mojom";
import "chrome/chrome_cleaner/mojom/wstring.mojom";
import "chrome/chrome_cleaner/mojom/wstring_embedded_nulls.mojom";
// Passes requests that can mutate the system from the low-privilege sandbox
// target process to the high-privilege broker process. It is implemented in
......@@ -25,27 +25,27 @@ interface CleanerEngineRequests {
SandboxDeleteFilePostReboot(FilePath file_name) => (bool result);
// Deletes the given registry key. |key| may contain null characters.
SandboxNtDeleteRegistryKey(String16EmbeddedNulls key) => (bool result);
SandboxNtDeleteRegistryKey(WStringEmbeddedNulls key) => (bool result);
// Deletes the given value for the given registry key. |key| and |key_name|
// may contain null characters.
SandboxNtDeleteRegistryValue(String16EmbeddedNulls key,
String16EmbeddedNulls value_name)
SandboxNtDeleteRegistryValue(WStringEmbeddedNulls key,
WStringEmbeddedNulls value_name)
=> (bool result);
// Updates the value of the given key's value to |new_value|.
// |new_value| must be a subset of the existing value. This is intended to be
// used to delete parts of a value, not to set a new value.
SandboxNtChangeRegistryValue(String16EmbeddedNulls key,
String16EmbeddedNulls value_name,
String16EmbeddedNulls new_value)
SandboxNtChangeRegistryValue(WStringEmbeddedNulls key,
WStringEmbeddedNulls value_name,
WStringEmbeddedNulls new_value)
=> (bool result);
// Deletes the given service.
SandboxDeleteService(mojo_base.mojom.String16 name) => (bool result);
SandboxDeleteService(WString name) => (bool result);
// Deletes the given task.
SandboxDeleteTask(mojo_base.mojom.String16 name) => (bool result);
SandboxDeleteTask(WString name) => (bool result);
// Terminates the given process.
// The broker process can't be terminated.
......
......@@ -5,10 +5,10 @@
module chrome_cleaner.mojom;
import "chrome/chrome_cleaner/mojom/footprints.mojom";
import "chrome/chrome_cleaner/mojom/string16_embedded_nulls.mojom";
import "chrome/chrome_cleaner/mojom/windows_handle.mojom";
import "chrome/chrome_cleaner/mojom/wstring.mojom";
import "chrome/chrome_cleaner/mojom/wstring_embedded_nulls.mojom";
import "mojo/public/mojom/base/process_id.mojom";
import "mojo/public/mojom/base/string16.mojom";
enum KnownFolder {
kWindows = 0,
......@@ -18,24 +18,24 @@ enum KnownFolder {
};
struct StringSid {
mojo_base.mojom.String16 value;
WString value;
};
struct ScheduledTaskAction {
FilePath path;
FilePath working_dir;
mojo_base.mojom.String16 arguments;
WString arguments;
};
struct ScheduledTask {
mojo_base.mojom.String16 name;
mojo_base.mojom.String16 description;
WString name;
WString description;
array<ScheduledTaskAction> actions;
};
struct UserInformation {
mojo_base.mojom.String16 name;
mojo_base.mojom.String16 domain;
WString name;
WString domain;
// User account type (SID_NAME_USE). See
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa379601(v=vs.85).aspx
uint32 account_type;
......@@ -70,11 +70,11 @@ interface EngineRequests {
// Gets all of the modules loaded into memory for the given process.
SandboxGetLoadedModules(mojo_base.mojom.ProcessId pid) =>
(bool result, array<mojo_base.mojom.String16> modules);
(bool result, array<WString> modules);
// Gets the command line for the given process.
SandboxGetProcessCommandLine(mojo_base.mojom.ProcessId pid) =>
(bool result, mojo_base.mojom.String16 command_line);
(bool result, WString command_line);
// Gets the given UserInformation values for |sid|.
SandboxGetUserInfoFromSID(StringSid sid) => (bool result,
......@@ -84,14 +84,14 @@ interface EngineRequests {
// |dw_access| may specify KEY_WOW64_32KEY or KEY_WOW64_64KEY. |root_key| must
// be non-null, and |sub_key| can't have any null characters.
SandboxOpenReadOnlyRegistry(WindowsHandle root_key,
mojo_base.mojom.String16 sub_key, uint32 dw_access) =>
WString sub_key, uint32 dw_access) =>
(uint32 result, WindowsHandle reg_handle);
// Gets a read-only registry key handle to the given key.
// |dw_access| may not specify KEY_WOW64_32KEY or KEY_WOW64_64KEY.
// ||root_key| may be null, and |sub_key| may have null characters.
SandboxNtOpenReadOnlyRegistry(WindowsHandle root_key,
String16EmbeddedNulls sub_key,
WStringEmbeddedNulls sub_key,
uint32 dw_access) =>
(uint32 result, WindowsHandle reg_handle);
};
......@@ -4,7 +4,7 @@
module chrome_cleaner.mojom;
import "mojo/public/mojom/base/string16.mojom";
import "chrome/chrome_cleaner/mojom/wstring.mojom";
import "mojo/public/mojom/base/values.mojom";
enum LnkParsingResult {
......@@ -25,9 +25,9 @@ interface Parser {
// attempted to be parsed, extracting the executable target path and the
// command line arguments.
ParseShortcut(handle<platform> lkn_file_handle)
=> (LnkParsingResult parsing_result, mojo_base.mojom.String16? target_path,
mojo_base.mojom.String16? command_line_arguments,
mojo_base.mojom.String16? icon_location);
=> (LnkParsingResult parsing_result, WString? target_path,
WString? command_line_arguments,
WString? icon_location);
// JSON parser:
// Interface copied from services/data_decoder/public/mojom/json_parser.mojom,
......
......@@ -4,9 +4,9 @@
module chrome_cleaner.mojom;
import "chrome/chrome_cleaner/mojom/string16_embedded_nulls.mojom";
import "chrome/chrome_cleaner/mojom/wstring_embedded_nulls.mojom";
// Simple interface that echoes an object for typemap testing.
interface TestString16EmbeddedNulls {
Echo(String16EmbeddedNulls input) => (String16EmbeddedNulls output);
interface TestWStringEmbeddedNulls {
Echo(WStringEmbeddedNulls input) => (WStringEmbeddedNulls output);
};
......@@ -10,7 +10,7 @@ source_set("unittest_sources") {
sources = [
"pup_typemap_unittest.cc",
"string16_embedded_nulls_typemap_unittest.cc",
"wstring_embedded_nulls_typemap_unittest.cc",
]
deps = [
......
......@@ -9,12 +9,11 @@ public_headers = [
]
traits_headers =
[ "//chrome/chrome_cleaner/mojom/typemaps/footprints_mojom_traits.h" ]
sources = [
"//chrome/chrome_cleaner/mojom/typemaps/footprints_mojom_traits.cc",
]
sources =
[ "//chrome/chrome_cleaner/mojom/typemaps/footprints_mojom_traits.cc" ]
type_mappings = [
"chrome_cleaner.mojom.FilePath=::base::FilePath",
"chrome_cleaner.mojom.RegistryKey=::base::string16",
"chrome_cleaner.mojom.ExtensionId=::base::string16",
"chrome_cleaner.mojom.RegistryKey=::std::wstring",
"chrome_cleaner.mojom.ExtensionId=::std::wstring",
]
......@@ -29,8 +29,8 @@ bool StructTraits<chrome_cleaner::mojom::FilePathDataView,
#if defined(OS_WIN)
ArrayDataView<uint16_t> view;
path_view.GetValueDataView(&view);
base::FilePath path = base::FilePath(base::string16(
reinterpret_cast<const base::char16*>(view.data()), view.size()));
base::FilePath path = base::FilePath(
std::wstring(reinterpret_cast<const wchar_t*>(view.data()), view.size()));
*out = std::move(path);
return true;
#else
......@@ -41,8 +41,8 @@ bool StructTraits<chrome_cleaner::mojom::FilePathDataView,
// static
base::span<const uint16_t>
StructTraits<chrome_cleaner::mojom::RegistryKeyDataView, base::string16>::value(
const base::string16& registry_key) {
StructTraits<chrome_cleaner::mojom::RegistryKeyDataView, std::wstring>::value(
const std::wstring& registry_key) {
#if defined(OS_WIN)
return base::make_span(reinterpret_cast<const uint16_t*>(registry_key.data()),
registry_key.size());
......@@ -53,14 +53,15 @@ StructTraits<chrome_cleaner::mojom::RegistryKeyDataView, base::string16>::value(
}
// static
bool StructTraits<chrome_cleaner::mojom::RegistryKeyDataView, base::string16>::
Read(chrome_cleaner::mojom::RegistryKeyDataView registry_key_view,
base::string16* out) {
bool StructTraits<chrome_cleaner::mojom::RegistryKeyDataView,
std::wstring>::Read(chrome_cleaner::mojom::RegistryKeyDataView
registry_key_view,
std::wstring* out) {
#if defined(OS_WIN)
ArrayDataView<uint16_t> view;
registry_key_view.GetValueDataView(&view);
base::string16 registry_key = base::string16(
reinterpret_cast<const base::char16*>(view.data()), view.size());
std::wstring registry_key =
std::wstring(reinterpret_cast<const wchar_t*>(view.data()), view.size());
*out = std::move(registry_key);
return true;
#else
......@@ -71,8 +72,8 @@ bool StructTraits<chrome_cleaner::mojom::RegistryKeyDataView, base::string16>::
// static
base::span<const uint16_t>
StructTraits<chrome_cleaner::mojom::ExtensionIdDataView, base::string16>::value(
const base::string16& extension_id) {
StructTraits<chrome_cleaner::mojom::ExtensionIdDataView, std::wstring>::value(
const std::wstring& extension_id) {
#if defined(OS_WIN)
return base::make_span(reinterpret_cast<const uint16_t*>(extension_id.data()),
extension_id.size());
......@@ -83,14 +84,15 @@ StructTraits<chrome_cleaner::mojom::ExtensionIdDataView, base::string16>::value(
}
// static
bool StructTraits<chrome_cleaner::mojom::ExtensionIdDataView, base::string16>::
Read(chrome_cleaner::mojom::ExtensionIdDataView extension_id_view,
base::string16* out) {
bool StructTraits<chrome_cleaner::mojom::ExtensionIdDataView,
std::wstring>::Read(chrome_cleaner::mojom::ExtensionIdDataView
extension_id_view,
std::wstring* out) {
#if defined(OS_WIN)
ArrayDataView<uint16_t> view;
extension_id_view.GetValueDataView(&view);
base::string16 extension_id = base::string16(
reinterpret_cast<const base::char16*>(view.data()), view.size());
std::wstring extension_id =
std::wstring(reinterpret_cast<const wchar_t*>(view.data()), view.size());
*out = std::move(extension_id);
return true;
#else
......
......@@ -5,9 +5,10 @@
#ifndef CHROME_CHROME_CLEANER_MOJOM_TYPEMAPS_FOOTPRINTS_MOJOM_TRAITS_H_
#define CHROME_CHROME_CLEANER_MOJOM_TYPEMAPS_FOOTPRINTS_MOJOM_TRAITS_H_
#include <string>
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/strings/string16.h"
#include "chrome/chrome_cleaner/mojom/footprints.mojom.h"
namespace mojo {
......@@ -20,19 +21,17 @@ struct StructTraits<chrome_cleaner::mojom::FilePathDataView, base::FilePath> {
};
template <>
struct StructTraits<chrome_cleaner::mojom::RegistryKeyDataView,
base::string16> {
static base::span<const uint16_t> value(const base::string16& registry_key);
struct StructTraits<chrome_cleaner::mojom::RegistryKeyDataView, std::wstring> {
static base::span<const uint16_t> value(const std::wstring& registry_key);
static bool Read(chrome_cleaner::mojom::RegistryKeyDataView registry_key_view,
base::string16* out);
std::wstring* out);
};
template <>
struct StructTraits<chrome_cleaner::mojom::ExtensionIdDataView,
base::string16> {
static base::span<const uint16_t> value(const base::string16& extension_id);
struct StructTraits<chrome_cleaner::mojom::ExtensionIdDataView, std::wstring> {
static base::span<const uint16_t> value(const std::wstring& extension_id);
static bool Read(chrome_cleaner::mojom::ExtensionIdDataView extension_id_view,
base::string16* out);
std::wstring* out);
};
} // namespace mojo
......
......@@ -211,7 +211,7 @@ MULTIPROCESS_TEST_MAIN(EchoPUP_ExtraData) {
pup.expanded_scheduled_tasks.push_back(L"Scheduled task 3");
pup.matched_extensions.push_back(ForceInstalledExtension(
*ExtensionID::Create(base::UTF16ToUTF8(kTestExtensionId1)),
*ExtensionID::Create(base::WideToUTF8(kTestExtensionId1)),
POLICY_EXTENSION_FORCELIST, "https://test.com",
"all_your_permission_are_belong_to_us"));
......
# 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.
mojom = "//chrome/chrome_cleaner/mojom/string16_embedded_nulls.mojom"
public_headers = [ "//chrome/chrome_cleaner/strings/string16_embedded_nulls.h" ]
traits_headers = [ "//chrome/chrome_cleaner/mojom/typemaps/string16_embedded_nulls_mojom_traits.h" ]
sources = [
"//chrome/chrome_cleaner/mojom/typemaps/string16_embedded_nulls_mojom_traits.cc",
]
type_mappings = [ "chrome_cleaner.mojom.String16EmbeddedNulls=::chrome_cleaner::String16EmbeddedNulls" ]
......@@ -5,6 +5,7 @@
typemaps = [
"//chrome/chrome_cleaner/mojom/typemaps/footprints.typemap",
"//chrome/chrome_cleaner/mojom/typemaps/pup.typemap",
"//chrome/chrome_cleaner/mojom/typemaps/string16_embedded_nulls.typemap",
"//chrome/chrome_cleaner/mojom/typemaps/wstring.typemap",
"//chrome/chrome_cleaner/mojom/typemaps/wstring_embedded_nulls.typemap",
"//chrome/chrome_cleaner/mojom/typemaps/windows_handle.typemap",
]
# Copyright 2020 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.
mojom = "//chrome/chrome_cleaner/mojom/wstring.mojom"
traits_headers =
[ "//chrome/chrome_cleaner/mojom/typemaps/wstring_mojom_traits.h" ]
sources = [ "//chrome/chrome_cleaner/mojom/typemaps/wstring_mojom_traits.cc" ]
type_mappings = [ "chrome_cleaner.mojom.WString=::std::wstring" ]
# 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.
mojom = "//chrome/chrome_cleaner/mojom/wstring_embedded_nulls.mojom"
public_headers = [ "//chrome/chrome_cleaner/strings/wstring_embedded_nulls.h" ]
traits_headers = [ "//chrome/chrome_cleaner/mojom/typemaps/wstring_embedded_nulls_mojom_traits.h" ]
sources = [ "//chrome/chrome_cleaner/mojom/typemaps/wstring_embedded_nulls_mojom_traits.cc" ]
type_mappings = [ "chrome_cleaner.mojom.WStringEmbeddedNulls=::chrome_cleaner::WStringEmbeddedNulls" ]
......@@ -2,13 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/chrome_cleaner/mojom/typemaps/string16_embedded_nulls_mojom_traits.h"
#include "chrome/chrome_cleaner/mojom/typemaps/wstring_embedded_nulls_mojom_traits.h"
#include "mojo/public/cpp/bindings/array_data_view.h"
namespace mojo {
using chrome_cleaner::WStringEmbeddedNulls;
using chrome_cleaner::mojom::NullValueDataView;
using chrome_cleaner::mojom::String16EmbeddedNullsDataView;
using chrome_cleaner::String16EmbeddedNulls;
using chrome_cleaner::mojom::WStringEmbeddedNullsDataView;
// static
bool StructTraits<NullValueDataView, nullptr_t>::Read(NullValueDataView data,
......@@ -19,9 +21,9 @@ bool StructTraits<NullValueDataView, nullptr_t>::Read(NullValueDataView data,
// static
base::span<const uint16_t>
UnionTraits<String16EmbeddedNullsDataView, String16EmbeddedNulls>::value(
const String16EmbeddedNulls& str) {
DCHECK_EQ(String16EmbeddedNullsDataView::Tag::VALUE, GetTag(str));
UnionTraits<WStringEmbeddedNullsDataView, WStringEmbeddedNulls>::value(
const WStringEmbeddedNulls& str) {
DCHECK_EQ(WStringEmbeddedNullsDataView::Tag::VALUE, GetTag(str));
// This should only be called by Mojo to get the data to be send through the
// pipe. When called by Mojo in this case, str will outlive the returned span.
......@@ -30,37 +32,37 @@ UnionTraits<String16EmbeddedNullsDataView, String16EmbeddedNulls>::value(
// static
nullptr_t
UnionTraits<String16EmbeddedNullsDataView, String16EmbeddedNulls>::null_value(
const chrome_cleaner::String16EmbeddedNulls& str) {
DCHECK_EQ(String16EmbeddedNullsDataView::Tag::NULL_VALUE, GetTag(str));
UnionTraits<WStringEmbeddedNullsDataView, WStringEmbeddedNulls>::null_value(
const chrome_cleaner::WStringEmbeddedNulls& str) {
DCHECK_EQ(WStringEmbeddedNullsDataView::Tag::NULL_VALUE, GetTag(str));
return nullptr;
}
// static
chrome_cleaner::mojom::String16EmbeddedNullsDataView::Tag
UnionTraits<String16EmbeddedNullsDataView, String16EmbeddedNulls>::GetTag(
const chrome_cleaner::String16EmbeddedNulls& str) {
return str.size() == 0 ? String16EmbeddedNullsDataView::Tag::NULL_VALUE
: String16EmbeddedNullsDataView::Tag::VALUE;
chrome_cleaner::mojom::WStringEmbeddedNullsDataView::Tag
UnionTraits<WStringEmbeddedNullsDataView, WStringEmbeddedNulls>::GetTag(
const chrome_cleaner::WStringEmbeddedNulls& str) {
return str.size() == 0 ? WStringEmbeddedNullsDataView::Tag::NULL_VALUE
: WStringEmbeddedNullsDataView::Tag::VALUE;
}
// static
bool UnionTraits<String16EmbeddedNullsDataView, String16EmbeddedNulls>::Read(
String16EmbeddedNullsDataView str_view,
String16EmbeddedNulls* out) {
bool UnionTraits<WStringEmbeddedNullsDataView, WStringEmbeddedNulls>::Read(
WStringEmbeddedNullsDataView str_view,
WStringEmbeddedNulls* out) {
if (str_view.is_null_value()) {
*out = String16EmbeddedNulls();
*out = WStringEmbeddedNulls();
return true;
}
ArrayDataView<uint16_t> view;
str_view.GetValueDataView(&view);
// Note: Casting is intentional, since the data view represents the string as
// a uint16_t array, whereas String16EmbeddedNulls's constructor expects
// a uint16_t array, whereas WStringEmbeddedNulls's constructor expects
// a wchar_t array.
*out = String16EmbeddedNulls(reinterpret_cast<const wchar_t*>(view.data()),
view.size());
*out = WStringEmbeddedNulls(reinterpret_cast<const wchar_t*>(view.data()),
view.size());
return true;
}
......
......@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_CHROME_CLEANER_MOJOM_TYPEMAPS_STRING16_EMBEDDED_NULLS_MOJOM_TRAITS_H_
#define CHROME_CHROME_CLEANER_MOJOM_TYPEMAPS_STRING16_EMBEDDED_NULLS_MOJOM_TRAITS_H_
#ifndef CHROME_CHROME_CLEANER_MOJOM_TYPEMAPS_WSTRING_EMBEDDED_NULLS_MOJOM_TRAITS_H_
#define CHROME_CHROME_CLEANER_MOJOM_TYPEMAPS_WSTRING_EMBEDDED_NULLS_MOJOM_TRAITS_H_
#include <stdint.h>
#include "base/containers/span.h"
#include "chrome/chrome_cleaner/mojom/string16_embedded_nulls.mojom.h"
#include "chrome/chrome_cleaner/strings/string16_embedded_nulls.h"
#include "chrome/chrome_cleaner/mojom/wstring_embedded_nulls.mojom.h"
#include "chrome/chrome_cleaner/strings/wstring_embedded_nulls.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
#include "mojo/public/cpp/bindings/union_traits.h"
......@@ -23,22 +23,21 @@ struct StructTraits<chrome_cleaner::mojom::NullValueDataView, nullptr_t> {
};
template <>
struct UnionTraits<chrome_cleaner::mojom::String16EmbeddedNullsDataView,
chrome_cleaner::String16EmbeddedNulls> {
struct UnionTraits<chrome_cleaner::mojom::WStringEmbeddedNullsDataView,
chrome_cleaner::WStringEmbeddedNulls> {
// This should only be called by Mojo to marshal the object before sending it
// through the pipe.
static base::span<const uint16_t> value(
const chrome_cleaner::String16EmbeddedNulls& str);
static nullptr_t null_value(const chrome_cleaner::String16EmbeddedNulls& str);
const chrome_cleaner::WStringEmbeddedNulls& str);
static nullptr_t null_value(const chrome_cleaner::WStringEmbeddedNulls& str);
static chrome_cleaner::mojom::String16EmbeddedNullsDataView::Tag GetTag(
const chrome_cleaner::String16EmbeddedNulls& str);
static chrome_cleaner::mojom::WStringEmbeddedNullsDataView::Tag GetTag(
const chrome_cleaner::WStringEmbeddedNulls& str);
static bool Read(
chrome_cleaner::mojom::String16EmbeddedNullsDataView str_view,
chrome_cleaner::String16EmbeddedNulls* out);
static bool Read(chrome_cleaner::mojom::WStringEmbeddedNullsDataView str_view,
chrome_cleaner::WStringEmbeddedNulls* out);
};
} // namespace mojo
#endif // CHROME_CHROME_CLEANER_MOJOM_TYPEMAPS_STRING16_EMBEDDED_NULLS_MOJOM_TRAITS_H_
#endif // CHROME_CHROME_CLEANER_MOJOM_TYPEMAPS_WSTRING_EMBEDDED_NULLS_MOJOM_TRAITS_H_
......@@ -9,10 +9,10 @@
#include "base/synchronization/waitable_event.h"
#include "chrome/chrome_cleaner/ipc/ipc_test_util.h"
#include "chrome/chrome_cleaner/ipc/mojo_task_runner.h"
#include "chrome/chrome_cleaner/mojom/string16_embedded_nulls.mojom.h"
#include "chrome/chrome_cleaner/mojom/test_string16_embedded_nulls.mojom.h"
#include "chrome/chrome_cleaner/strings/string16_embedded_nulls.h"
#include "chrome/chrome_cleaner/mojom/test_wstring_embedded_nulls.mojom.h"
#include "chrome/chrome_cleaner/mojom/wstring_embedded_nulls.mojom.h"
#include "chrome/chrome_cleaner/strings/string_test_helpers.h"
#include "chrome/chrome_cleaner/strings/wstring_embedded_nulls.h"
#include "chrome/chrome_cleaner/test/test_util.h"
#include "mojo/core/embedder/embedder.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
......@@ -30,18 +30,18 @@ namespace {
using base::WaitableEvent;
class TestString16EmbeddedNullsImpl : public mojom::TestString16EmbeddedNulls {
class TestWStringEmbeddedNullsImpl : public mojom::TestWStringEmbeddedNulls {
public:
explicit TestString16EmbeddedNullsImpl(
mojo::PendingReceiver<mojom::TestString16EmbeddedNulls> receiver)
explicit TestWStringEmbeddedNullsImpl(
mojo::PendingReceiver<mojom::TestWStringEmbeddedNulls> receiver)
: receiver_(this, std::move(receiver)) {}
void Echo(const String16EmbeddedNulls& path, EchoCallback callback) override {
void Echo(const WStringEmbeddedNulls& path, EchoCallback callback) override {
std::move(callback).Run(path);
}
private:
mojo::Receiver<mojom::TestString16EmbeddedNulls> receiver_;
mojo::Receiver<mojom::TestWStringEmbeddedNulls> receiver_;
};
class SandboxParentProcess : public chrome_cleaner::ParentProcess {
......@@ -51,10 +51,9 @@ class SandboxParentProcess : public chrome_cleaner::ParentProcess {
protected:
void CreateImpl(mojo::ScopedMessagePipeHandle mojo_pipe) override {
mojo::PendingReceiver<mojom::TestString16EmbeddedNulls> receiver(
mojo::PendingReceiver<mojom::TestWStringEmbeddedNulls> receiver(
std::move(mojo_pipe));
impl_ =
std::make_unique<TestString16EmbeddedNullsImpl>(std::move(receiver));
impl_ = std::make_unique<TestWStringEmbeddedNullsImpl>(std::move(receiver));
}
void DestroyImpl() override { impl_.reset(); }
......@@ -62,26 +61,27 @@ class SandboxParentProcess : public chrome_cleaner::ParentProcess {
private:
~SandboxParentProcess() override = default;
std::unique_ptr<TestString16EmbeddedNullsImpl> impl_;
std::unique_ptr<TestWStringEmbeddedNullsImpl> impl_;
};
class SandboxChildProcess : public chrome_cleaner::ChildProcess {
public:
explicit SandboxChildProcess(scoped_refptr<MojoTaskRunner> mojo_task_runner)
: ChildProcess(mojo_task_runner),
remote_(std::make_unique<
mojo::Remote<mojom::TestString16EmbeddedNulls>>()) {}
remote_(
std::make_unique<mojo::Remote<mojom::TestWStringEmbeddedNulls>>()) {
}
void BindToPipe(mojo::ScopedMessagePipeHandle mojo_pipe,
WaitableEvent* event) {
remote_->Bind(
mojo::PendingRemote<chrome_cleaner::mojom::TestString16EmbeddedNulls>(
mojo::PendingRemote<chrome_cleaner::mojom::TestWStringEmbeddedNulls>(
std::move(mojo_pipe), 0));
event->Signal();
}
bool SuccessfulEcho(const String16EmbeddedNulls& input) {
String16EmbeddedNulls output;
bool SuccessfulEcho(const WStringEmbeddedNulls& input) {
WStringEmbeddedNulls output;
WaitableEvent event(WaitableEvent::ResetPolicy::MANUAL,
WaitableEvent::InitialState::NOT_SIGNALED);
mojo_task_runner_->PostTask(
......@@ -98,7 +98,7 @@ class SandboxChildProcess : public chrome_cleaner::ChildProcess {
mojo_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
[](std::unique_ptr<mojo::Remote<mojom::TestString16EmbeddedNulls>>
[](std::unique_ptr<mojo::Remote<mojom::TestWStringEmbeddedNulls>>
remote) { remote.reset(); },
std::move(remote_)));
}
......@@ -116,12 +116,12 @@ class SandboxChildProcess : public chrome_cleaner::ChildProcess {
output, event);
}
void RunEcho(const String16EmbeddedNulls& input,
mojom::TestString16EmbeddedNulls::EchoCallback callback) {
void RunEcho(const WStringEmbeddedNulls& input,
mojom::TestWStringEmbeddedNulls::EchoCallback callback) {
(*remote_)->Echo(input, std::move(callback));
}
std::unique_ptr<mojo::Remote<mojom::TestString16EmbeddedNulls>> remote_;
std::unique_ptr<mojo::Remote<mojom::TestWStringEmbeddedNulls>> remote_;
};
scoped_refptr<SandboxChildProcess> InitChildProcess() {
......@@ -144,47 +144,47 @@ MULTIPROCESS_TEST_MAIN(EchoMain) {
scoped_refptr<SandboxChildProcess> child_process = InitChildProcess();
// Empty string.
EXPECT_TRUE(child_process->SuccessfulEcho(String16EmbeddedNulls()));
EXPECT_TRUE(child_process->SuccessfulEcho(String16EmbeddedNulls(nullptr)));
EXPECT_TRUE(child_process->SuccessfulEcho(String16EmbeddedNulls(nullptr, 0)));
EXPECT_TRUE(child_process->SuccessfulEcho(String16EmbeddedNulls(nullptr, 1)));
EXPECT_TRUE(child_process->SuccessfulEcho(String16EmbeddedNulls(L"", 0)));
EXPECT_TRUE(child_process->SuccessfulEcho(WStringEmbeddedNulls()));
EXPECT_TRUE(child_process->SuccessfulEcho(WStringEmbeddedNulls(nullptr)));
EXPECT_TRUE(child_process->SuccessfulEcho(WStringEmbeddedNulls(nullptr, 0)));
EXPECT_TRUE(child_process->SuccessfulEcho(WStringEmbeddedNulls(nullptr, 1)));
EXPECT_TRUE(child_process->SuccessfulEcho(WStringEmbeddedNulls(L"", 0)));
EXPECT_TRUE(child_process->SuccessfulEcho(
String16EmbeddedNulls(std::vector<wchar_t>{})));
WStringEmbeddedNulls(std::vector<wchar_t>{})));
EXPECT_TRUE(
child_process->SuccessfulEcho(String16EmbeddedNulls(base::string16())));
EXPECT_TRUE(child_process->SuccessfulEcho(
String16EmbeddedNulls(base::string16(L""))));
child_process->SuccessfulEcho(WStringEmbeddedNulls(std::wstring())));
EXPECT_TRUE(
child_process->SuccessfulEcho(WStringEmbeddedNulls(std::wstring(L""))));
EXPECT_TRUE(child_process->SuccessfulEcho(
String16EmbeddedNulls(base::StringPiece16())));
WStringEmbeddedNulls(base::WStringPiece())));
EXPECT_TRUE(child_process->SuccessfulEcho(
String16EmbeddedNulls(base::StringPiece16(L""))));
WStringEmbeddedNulls(base::WStringPiece(L""))));
// Null-terminated strings. Zeroes will be replaced with null characters.
constexpr wchar_t kStringWithNulls[] = L"string0with0nulls";
const std::vector<wchar_t> vec1 = CreateVectorWithNulls(kStringWithNulls);
EXPECT_TRUE(child_process->SuccessfulEcho(
String16EmbeddedNulls(vec1.data(), vec1.size())));
EXPECT_TRUE(child_process->SuccessfulEcho(String16EmbeddedNulls(vec1)));
WStringEmbeddedNulls(vec1.data(), vec1.size())));
EXPECT_TRUE(child_process->SuccessfulEcho(WStringEmbeddedNulls(vec1)));
EXPECT_TRUE(child_process->SuccessfulEcho(
String16EmbeddedNulls(base::string16(vec1.data(), vec1.size()))));
WStringEmbeddedNulls(std::wstring(vec1.data(), vec1.size()))));
EXPECT_TRUE(child_process->SuccessfulEcho(
String16EmbeddedNulls(base::StringPiece16(vec1.data(), vec1.size()))));
WStringEmbeddedNulls(base::WStringPiece(vec1.data(), vec1.size()))));
// Non null-terminated strings.
const std::vector<wchar_t> vec2(vec1.begin(), vec1.end() - 1);
EXPECT_TRUE(child_process->SuccessfulEcho(
String16EmbeddedNulls(vec2.data(), vec2.size())));
EXPECT_TRUE(child_process->SuccessfulEcho(String16EmbeddedNulls(vec2)));
WStringEmbeddedNulls(vec2.data(), vec2.size())));
EXPECT_TRUE(child_process->SuccessfulEcho(WStringEmbeddedNulls(vec2)));
EXPECT_TRUE(child_process->SuccessfulEcho(
String16EmbeddedNulls(base::string16(vec2.data(), vec2.size()))));
WStringEmbeddedNulls(std::wstring(vec2.data(), vec2.size()))));
EXPECT_TRUE(child_process->SuccessfulEcho(
String16EmbeddedNulls(base::StringPiece16(vec2.data(), vec2.size()))));
WStringEmbeddedNulls(base::WStringPiece(vec2.data(), vec2.size()))));
return ::testing::Test::HasNonfatalFailure();
}
class String16EmbeddedNullsTypemapTest : public ::testing::Test {
class WStringEmbeddedNullsTypemapTest : public ::testing::Test {
public:
void SetUp() override {
mojo_task_runner_ = MojoTaskRunner::Create();
......@@ -197,7 +197,7 @@ class String16EmbeddedNullsTypemapTest : public ::testing::Test {
scoped_refptr<SandboxParentProcess> parent_process_;
};
TEST_F(String16EmbeddedNullsTypemapTest, Echo) {
TEST_F(WStringEmbeddedNullsTypemapTest, Echo) {
int32_t exit_code = -1;
EXPECT_TRUE(
parent_process_->LaunchConnectedChildProcess("EchoMain", &exit_code));
......
// Copyright 2020 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 "chrome/chrome_cleaner/mojom/typemaps/wstring_mojom_traits.h"
#include "mojo/public/cpp/bindings/array_data_view.h"
namespace mojo {
// static
bool StructTraits<chrome_cleaner::mojom::WStringDataView, std::wstring>::Read(
chrome_cleaner::mojom::WStringDataView data,
std::wstring* out) {
ArrayDataView<uint16_t> view;
data.GetDataDataView(&view);
out->assign(reinterpret_cast<const wchar_t*>(view.data()), view.size());
return true;
}
} // namespace mojo
// Copyright 2020 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 CHROME_CHROME_CLEANER_MOJOM_TYPEMAPS_WSTRING_MOJOM_TRAITS_H_
#define CHROME_CHROME_CLEANER_MOJOM_TYPEMAPS_WSTRING_MOJOM_TRAITS_H_
#include <string>
#include "base/containers/span.h"
#include "chrome/chrome_cleaner/mojom/wstring.mojom.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
namespace mojo {
template <>
struct StructTraits<chrome_cleaner::mojom::WStringDataView, std::wstring> {
static base::span<const uint16_t> data(const std::wstring& str) {
return base::make_span(reinterpret_cast<const uint16_t*>(str.data()),
str.size());
}
static bool Read(chrome_cleaner::mojom::WStringDataView data,
std::wstring* out);
};
} // namespace mojo
#endif // CHROME_CHROME_CLEANER_MOJOM_TYPEMAPS_WSTRING_MOJOM_TRAITS_H_
// Copyright 2020 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 chrome_cleaner.mojom;
// Corresponds to std::wstring.
struct WString {
array<uint16> data;
};
......@@ -4,13 +4,13 @@
module chrome_cleaner.mojom;
// Typemapped to chrome_cleaner::String16EmbeddedNulls.
// Typemapped to chrome_cleaner::WStringEmbeddedNulls.
//
// Note: Mojo doesn't allow sending null arrays over the wire, and the strings
// represented by this type can be empty (without a null at the end).
// Because of that, represented as a union of either something that is
// always empty (NullValue) or a non-empty array of uint16.
union String16EmbeddedNulls {
union WStringEmbeddedNulls {
// The underlying string is a null array (not the same as an empty string,
// which has at least one character '\0').
NullValue? null_value;
......
......@@ -11,6 +11,7 @@ source_set("strings") {
"string16_embedded_nulls.h",
"string_util.cc",
"string_util.h",
"wstring_embedded_nulls.h",
]
deps = [
"//base",
......
// Copyright 2020 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 CHROME_CHROME_CLEANER_STRINGS_WSTRING_EMBEDDED_NULLS_H_
#define CHROME_CHROME_CLEANER_STRINGS_WSTRING_EMBEDDED_NULLS_H_
#include "chrome/chrome_cleaner/strings/string16_embedded_nulls.h"
namespace chrome_cleaner {
// TODO(crbug.com/911896): Rename String16EmbeddedNulls to WStringEmbeddedNulls
// and get rid of this alias.
using WStringEmbeddedNulls = String16EmbeddedNulls;
} // namespace chrome_cleaner
#endif // CHROME_CHROME_CLEANER_STRINGS_WSTRING_EMBEDDED_NULLS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment