Commit 0b116d01 authored by danakj's avatar danakj Committed by Commit Bot

Rename UnsafeBitmap to BitmapMappingFromTrustedProcess

This explains more what is unsafe about this mojom, and add additional
comments explaining when it is okay to use this and discouraging
general use.

R=darin@chromium.org, dcheng@chromium.org

Bug: 1144462
Change-Id: I735da27d649394f2e196d99f6b63444e370e9586
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2545203Reviewed-by: default avatarDarin Fisher <darin@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828755}
parent f9009e12
...@@ -28,8 +28,9 @@ interface SnapshotCapturer { ...@@ -28,8 +28,9 @@ interface SnapshotCapturer {
// Captures a bitmap snapshot of the specified screen or window. If |success| // Captures a bitmap snapshot of the specified screen or window. If |success|
// is false, that may indicate that the specified source no longer exists. // is false, that may indicate that the specified source no longer exists.
[Sync] [Sync]
TakeSnapshot@1(uint64 id) => (bool success, TakeSnapshot@1(uint64 id) =>
skia.mojom.UnsafeBitmap? snapshot); (bool success,
skia.mojom.BitmapMappedFromTrustedProcess? snapshot);
}; };
// This interface is implemented by ash-chrome. It allows lacros-chrome to query // This interface is implemented by ash-chrome. It allows lacros-chrome to query
......
...@@ -58,7 +58,7 @@ mojom("mojom") { ...@@ -58,7 +58,7 @@ mojom("mojom") {
nullable_is_same_type = true nullable_is_same_type = true
}, },
{ {
mojom = "skia.mojom.UnsafeBitmap" mojom = "skia.mojom.BitmapMappedFromTrustedProcess"
cpp = "::SkBitmap" cpp = "::SkBitmap"
nullable_is_same_type = true nullable_is_same_type = true
}, },
......
...@@ -17,16 +17,17 @@ struct Bitmap { ...@@ -17,16 +17,17 @@ struct Bitmap {
// Similar to above, but the generated bindings avoid copying pixel data on the // Similar to above, but the generated bindings avoid copying pixel data on the
// receiving side of an IPC message. That can be a valuable optimization for // receiving side of an IPC message. That can be a valuable optimization for
// large bitmaps. However, this is unsafe for some applications as it leaves // large bitmaps. However, this is DANGEROUS as it leaves open the possibility
// open the possibility for the sender to continue to modify the pixel data, // for the sender to continue to modify the pixel data, which could lead to
// which could lead to TOCTOU issues. Use this type *only* when the sender is // TOCTOU issues. Use this type *only* when the sender is fully trusted (and
// trusted. // a compromise there would already mean system compromise), such as from the
// browser process.
// //
// NOTE: It is important that the fields of this struct exactly match the // NOTE: It is important that the fields of this struct exactly match the
// fields of the Bitmap struct. This enables stable interfaces to freely // fields of the Bitmap struct. This enables stable interfaces to freely
// migrate between these two types in a compatible fashion. // migrate between these two types in a compatible fashion.
[Stable] [Stable, RenamedFrom="skia.mojom.UnsafeBitmap"]
struct UnsafeBitmap { struct BitmapMappedFromTrustedProcess {
ImageInfo image_info; ImageInfo image_info;
uint64 row_bytes; uint64 row_bytes;
mojo_base.mojom.BigBuffer pixel_data; mojo_base.mojom.BigBuffer pixel_data;
......
...@@ -107,40 +107,43 @@ bool StructTraits<skia::mojom::BitmapDataView, SkBitmap>::Read( ...@@ -107,40 +107,43 @@ bool StructTraits<skia::mojom::BitmapDataView, SkBitmap>::Read(
} }
// static // static
bool StructTraits<skia::mojom::UnsafeBitmapDataView, SkBitmap>::IsNull( bool StructTraits<skia::mojom::BitmapMappedFromTrustedProcessDataView,
const SkBitmap& b) { SkBitmap>::IsNull(const SkBitmap& b) {
return b.isNull(); return b.isNull();
} }
// static // static
void StructTraits<skia::mojom::UnsafeBitmapDataView, SkBitmap>::SetToNull( void StructTraits<skia::mojom::BitmapMappedFromTrustedProcessDataView,
SkBitmap* b) { SkBitmap>::SetToNull(SkBitmap* b) {
b->reset(); b->reset();
} }
// static // static
const SkImageInfo& StructTraits<skia::mojom::UnsafeBitmapDataView, const SkImageInfo&
SkBitmap>::image_info(const SkBitmap& b) { StructTraits<skia::mojom::BitmapMappedFromTrustedProcessDataView,
SkBitmap>::image_info(const SkBitmap& b) {
return b.info(); return b.info();
} }
// static // static
uint64_t StructTraits<skia::mojom::UnsafeBitmapDataView, SkBitmap>::row_bytes( uint64_t StructTraits<skia::mojom::BitmapMappedFromTrustedProcessDataView,
const SkBitmap& b) { SkBitmap>::row_bytes(const SkBitmap& b) {
return b.rowBytes(); return b.rowBytes();
} }
// static // static
mojo_base::BigBufferView StructTraits<skia::mojom::UnsafeBitmapDataView, mojo_base::BigBufferView
SkBitmap>::pixel_data(const SkBitmap& b) { StructTraits<skia::mojom::BitmapMappedFromTrustedProcessDataView,
SkBitmap>::pixel_data(const SkBitmap& b) {
return mojo_base::BigBufferView(base::make_span( return mojo_base::BigBufferView(base::make_span(
static_cast<uint8_t*>(b.getPixels()), b.computeByteSize())); static_cast<uint8_t*>(b.getPixels()), b.computeByteSize()));
} }
// static // static
bool StructTraits<skia::mojom::UnsafeBitmapDataView, SkBitmap>::Read( bool StructTraits<
skia::mojom::UnsafeBitmapDataView data, skia::mojom::BitmapMappedFromTrustedProcessDataView,
SkBitmap* b) { SkBitmap>::Read(skia::mojom::BitmapMappedFromTrustedProcessDataView data,
SkBitmap* b) {
SkImageInfo image_info; SkImageInfo image_info;
if (!data.ReadImageInfo(&image_info)) if (!data.ReadImageInfo(&image_info))
return false; return false;
......
...@@ -30,13 +30,15 @@ struct COMPONENT_EXPORT(SKIA_SHARED_TRAITS) ...@@ -30,13 +30,15 @@ struct COMPONENT_EXPORT(SKIA_SHARED_TRAITS)
template <> template <>
struct COMPONENT_EXPORT(SKIA_SHARED_TRAITS) struct COMPONENT_EXPORT(SKIA_SHARED_TRAITS)
StructTraits<skia::mojom::UnsafeBitmapDataView, SkBitmap> { StructTraits<skia::mojom::BitmapMappedFromTrustedProcessDataView,
SkBitmap> {
static bool IsNull(const SkBitmap& b); static bool IsNull(const SkBitmap& b);
static void SetToNull(SkBitmap* b); static void SetToNull(SkBitmap* b);
static const SkImageInfo& image_info(const SkBitmap& b); static const SkImageInfo& image_info(const SkBitmap& b);
static uint64_t row_bytes(const SkBitmap& b); static uint64_t row_bytes(const SkBitmap& b);
static mojo_base::BigBufferView pixel_data(const SkBitmap& b); static mojo_base::BigBufferView pixel_data(const SkBitmap& b);
static bool Read(skia::mojom::UnsafeBitmapDataView data, SkBitmap* b); static bool Read(skia::mojom::BitmapMappedFromTrustedProcessDataView data,
SkBitmap* b);
}; };
template <> template <>
......
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