feat: replace BrowserView with WebContentsView (#35658)

This commit is contained in:
Jeremy Rose 2023-12-13 13:01:03 -08:00 committed by GitHub
parent a94fb2cb5d
commit 15c6014324
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
76 changed files with 2987 additions and 1531 deletions

View file

@ -21,10 +21,6 @@ bool IsFakeLocationProviderEnabled() {
return BUILDFLAG(OVERRIDE_LOCATION_PROVIDER);
}
bool IsViewApiEnabled() {
return BUILDFLAG(ENABLE_VIEWS_API);
}
bool IsPrintingEnabled() {
return BUILDFLAG(ENABLE_PRINTING);
}
@ -50,7 +46,6 @@ void Initialize(v8::Local<v8::Object> exports,
dict.SetMethod("isPDFViewerEnabled", &IsPDFViewerEnabled);
dict.SetMethod("isFakeLocationProviderEnabled",
&IsFakeLocationProviderEnabled);
dict.SetMethod("isViewApiEnabled", &IsViewApiEnabled);
dict.SetMethod("isPrintingEnabled", &IsPrintingEnabled);
dict.SetMethod("isComponentBuild", &IsComponentBuild);
dict.SetMethod("isExtensionsEnabled", &IsExtensionsEnabled);

View file

@ -9,6 +9,15 @@
#include "third_party/skia/include/core/SkColor.h"
// SkColor is a typedef for uint32_t, this wrapper is to tag an SkColor for
// ease of use in gin converters.
struct WrappedSkColor {
WrappedSkColor() {}
WrappedSkColor(SkColor c) : value(c) {} // NOLINT(runtime/explicit)
SkColor value;
operator SkColor() const { return value; }
};
namespace electron {
// Parses a CSS-style color string from hex, rgb(), rgba(),

View file

@ -4,9 +4,14 @@
#include "shell/common/gin_converters/gfx_converter.h"
#include <string>
#include "gin/data_object_builder.h"
#include "shell/common/color_util.h"
#include "shell/common/gin_helper/dictionary.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h"
@ -103,6 +108,35 @@ bool Converter<gfx::Rect>::FromV8(v8::Isolate* isolate,
return true;
}
v8::Local<v8::Value> Converter<gfx::Insets>::ToV8(v8::Isolate* isolate,
const gfx::Insets& val) {
return gin::DataObjectBuilder(isolate)
.Set("top", val.top())
.Set("left", val.left())
.Set("bottom", val.bottom())
.Set("right", val.right())
.Build();
}
bool Converter<gfx::Insets>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
gfx::Insets* out) {
gin::Dictionary dict(isolate);
if (!gin::ConvertFromV8(isolate, val, &dict))
return false;
double top, left, right, bottom;
if (!dict.Get("top", &top))
return false;
if (!dict.Get("left", &left))
return false;
if (!dict.Get("bottom", &bottom))
return false;
if (!dict.Get("right", &right))
return false;
*out = gfx::Insets::TLBR(top, left, bottom, right);
return true;
}
template <>
struct Converter<display::Display::AccelerometerSupport> {
static v8::Local<v8::Value> ToV8(
@ -185,4 +219,14 @@ v8::Local<v8::Value> Converter<gfx::ResizeEdge>::ToV8(
}
}
bool Converter<WrappedSkColor>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
WrappedSkColor* out) {
std::string str;
if (!gin::ConvertFromV8(isolate, val, &str))
return false;
*out = electron::ParseCSSColor(str);
return true;
}
} // namespace gin

View file

@ -6,6 +6,7 @@
#define ELECTRON_SHELL_COMMON_GIN_CONVERTERS_GFX_CONVERTER_H_
#include "gin/converter.h"
#include "shell/common/color_util.h"
namespace display {
class Display;
@ -16,6 +17,7 @@ class Point;
class PointF;
class Size;
class Rect;
class Insets;
enum class ResizeEdge;
} // namespace gfx
@ -54,6 +56,15 @@ struct Converter<gfx::Rect> {
gfx::Rect* out);
};
template <>
struct Converter<gfx::Insets> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const gfx::Insets& val);
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
gfx::Insets* out);
};
template <>
struct Converter<display::Display> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
@ -69,6 +80,13 @@ struct Converter<gfx::ResizeEdge> {
const gfx::ResizeEdge& val);
};
template <>
struct Converter<WrappedSkColor> {
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
WrappedSkColor* out);
};
} // namespace gin
#endif // ELECTRON_SHELL_COMMON_GIN_CONVERTERS_GFX_CONVERTER_H_

View file

@ -23,7 +23,7 @@ class EventEmitterMixin;
// class Example : public gin::Wrappable<Example>,
// public gin_helper::Constructible<Example> {
// public:
// static gin::Handle<Tray> New(...usual gin method arguments...);
// static gin::Handle<Example> New(...usual gin method arguments...);
// static void FillObjectTemplate(
// v8::Isolate*,
// v8::Local<v8::ObjectTemplate>);

View file

@ -46,13 +46,13 @@
#define ELECTRON_BROWSER_BINDINGS(V) \
V(electron_browser_app) \
V(electron_browser_auto_updater) \
V(electron_browser_browser_view) \
V(electron_browser_content_tracing) \
V(electron_browser_crash_reporter) \
V(electron_browser_desktop_capturer) \
V(electron_browser_dialog) \
V(electron_browser_event_emitter) \
V(electron_browser_global_shortcut) \
V(electron_browser_image_view) \
V(electron_browser_in_app_purchase) \
V(electron_browser_menu) \
V(electron_browser_message_port) \
@ -98,8 +98,6 @@
#define ELECTRON_UTILITY_BINDINGS(V) V(electron_utility_parent_port)
#define ELECTRON_VIEWS_BINDINGS(V) V(electron_browser_image_view)
#define ELECTRON_TESTING_BINDINGS(V) V(electron_common_testing)
// This is used to load built-in bindings. Instead of using
@ -112,9 +110,6 @@ ELECTRON_BROWSER_BINDINGS(V)
ELECTRON_COMMON_BINDINGS(V)
ELECTRON_RENDERER_BINDINGS(V)
ELECTRON_UTILITY_BINDINGS(V)
#if BUILDFLAG(ENABLE_VIEWS_API)
ELECTRON_VIEWS_BINDINGS(V)
#endif
#if DCHECK_IS_ON()
ELECTRON_TESTING_BINDINGS(V)
#endif
@ -441,9 +436,6 @@ void NodeBindings::RegisterBuiltinBindings() {
#define V(modname) _register_##modname();
if (IsBrowserProcess()) {
ELECTRON_BROWSER_BINDINGS(V)
#if BUILDFLAG(ENABLE_VIEWS_API)
ELECTRON_VIEWS_BINDINGS(V)
#endif
}
ELECTRON_COMMON_BINDINGS(V)
if (IsRendererProcess()) {