electron/shell/browser/osr/osr_render_widget_host_view.h
Electron Bot 72a089262e
chore: bump chromium to a84d34e372b8fb5e9a94b1b4b447e (master) (#23908)
* chore: bump chromium in DEPS to a7249f73ae05d456c04487ef1693325f719556dd

* chore: bump chromium in DEPS to 202466fa40b58f0bb9c9a76a037d1c50154c099e

* chore: bump chromium in DEPS to 2dd1b25c8d794b50fb0dd911e0c4e909ff39f145

* Update patches

* update patches

* Revert "[printing] Mojofy PrintHostMsg_CheckForCancel"

https://chromium-review.googlesource.com/c/chromium/src/+/2226002

* chore: bump chromium in DEPS to 8c1542e7dd36854fdf4abd1a8021eeb65a6a2e2b

* chore: bump chromium in DEPS to 078bc6d796334fb403acd8975b99d1c8ecd028e8

* chore: bump chromium in DEPS to d96e9f16ae852ec9dbd15bf17df3d440402413bb

* update patches

* chore: update patches

* Use ExtensionSystem::is_ready() instead of ExtensionService::is_ready()

https://chromium-review.googlesource.com/c/chromium/src/+/2207499

* Remove WebImeTextSpan

https://chromium-review.googlesource.com/c/chromium/src/+/2225240

* Remove PDFAnnotations flag altogether.

https://chromium-review.googlesource.com/c/chromium/src/+/2229317

* Rework find-from-selection so it's synchronous -- fixes flaky tests

https://chromium-review.googlesource.com/c/chromium/src/+/2181570

* fixup! Revert "[printing] Mojofy PrintHostMsg_CheckForCancel"

* chore: bump chromium in DEPS to a8a280835830c65145ed8573a9a09f36d3920418

* update sysroots

* update patches

* update patches

* Take RFH as a parameter for DidUpdateFavicon/ManifestURL

https://chromium-review.googlesource.com/c/chromium/src/+/2224745

* chore: bump chromium in DEPS to b6149cb5a5e32caf8eab67b97ef3072b72521ca8

* Update patches

* Rename net::cookie_util::StripStatuses to StripAccessResults

https://chromium-review.googlesource.com/c/chromium/src/+/2212697

* use net::CookieAccessResultList instead of net::CookieAccessResultList

* fix mas_no_private_api patch

https://chromium-review.googlesource.com/c/chromium/src/+/2230281

* chore: bump chromium in DEPS to a27feee1643d952e48f77c92d8c03aedea14b720

* update patches

* fix: add new navigation state REUSE_SITE_INSTANCE

To fix the new set of state checks added in
https://chromium-review.googlesource.com/c/chromium/src/+/2215141

* chore: bump chromium in DEPS to ff4559a4c13d20888202474e4ab9917dbdad8a9a

* update patches

* Cleanup usages of old mojo types and remove unused code

https://chromium-review.googlesource.com/c/chromium/src/+/2235699

* chore: bump chromium in DEPS to 05279845f76eb22900a8b0d1a11d4fd339a8e53b

* chore: bump chromium in DEPS to 821558279767cffec90e3b5b947865f90089fed3

* chore: bump chromium in DEPS to 1aef04e6486be337d3dd820b2d64d6320a1b9c13

* chore: bump chromium in DEPS to dc86386e8fdd796a0f7577e91e42a7f8b7e9bc78

* chore: bump chromium in DEPS to 64f2360794f14643764092ba3e58e2ed8f9fee12

* chore: update patches

* refactor: MessageLoop, you are terminated \o/

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2246173

* refactor: plumb DownloadSchedule to DownloadItem

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2242202

* chore: fix variable typo in IPC

* chore: s/BindPipeAndPassReceiver/BindNewPipeAndPassReceiver

* chore: update patches

* chore: XEvent becomes x11::Event

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2240355

* fixup! refactor: MessageLoop, you are terminated \o/

* fixup! chore: XEvent becomes x11::Event

* build: update v8 headers

* chore: fix windows build

* chore: disable SameSite-by-default changes

https://chromium-review.googlesource.com/c/chromium/src/+/2231445

* update printing.patch

* chore: bump chromium DEPS to 9ae03ef8f7d4f6ac663f725bcfe70311987652f3

* Convert WidgetHostMsg_SelectionBoundsChanged/TextInputStateChanged

https://chromium-review.googlesource.com/c/chromium/src/+/2243531

* chore: update v8 patches

* [XProto] Replace usages of XID and ::Window with x11::Window

https://chromium-review.googlesource.com/c/chromium/src/+/2249389

* Update VideoFrameMetadata to use base::Optionals

https://chromium-review.googlesource.com/c/chromium/src/+/2231706
https://chromium-review.googlesource.com/c/chromium/src/+/2238361

* --disable-dev-shm-usage for gpu process crash

* [v8] Allow for 4GB TypedArrays

https://chromium-review.googlesource.com/c/v8/v8/+/2249668

* update lib_src_switch_buffer_kmaxlength_to_size_t.patch

* disable app.getGPUInfo spec on linux

* update patches

Co-authored-by: John Kleinschmidt <jkleinsc@github.com>
Co-authored-by: Electron Bot <anonymous@electronjs.org>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
2020-06-22 10:35:10 -07:00

292 lines
10 KiB
C++

// Copyright (c) 2016 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef SHELL_BROWSER_OSR_OSR_RENDER_WIDGET_HOST_VIEW_H_
#define SHELL_BROWSER_OSR_OSR_RENDER_WIDGET_HOST_VIEW_H_
#include <memory>
#include <set>
#include <string>
#include <vector>
#if defined(OS_WIN)
#include <windows.h>
#endif
#include "base/process/kill.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "components/viz/common/quads/compositor_frame.h"
#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
#include "content/browser/renderer_host/delegated_frame_host.h" // nogncheck
#include "content/browser/renderer_host/input/mouse_wheel_phase_handler.h" // nogncheck
#include "content/browser/renderer_host/render_widget_host_impl.h" // nogncheck
#include "content/browser/renderer_host/render_widget_host_view_base.h" // nogncheck
#include "content/browser/web_contents/web_contents_view.h" // nogncheck
#include "shell/browser/osr/osr_host_display_client.h"
#include "shell/browser/osr/osr_video_consumer.h"
#include "shell/browser/osr/osr_view_proxy.h"
#include "third_party/blink/public/platform/web_vector.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/ime/text_input_client.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer_delegate.h"
#include "ui/compositor/layer_owner.h"
#include "ui/gfx/geometry/point.h"
#include "components/viz/host/host_display_client.h"
#if defined(OS_WIN)
#include "ui/gfx/win/window_impl.h"
#endif
namespace content {
class CursorManager;
} // namespace content
namespace electron {
class ElectronCopyFrameGenerator;
class ElectronBeginFrameTimer;
class ElectronDelegatedFrameHostClient;
typedef base::Callback<void(const gfx::Rect&, const SkBitmap&)> OnPaintCallback;
typedef base::Callback<void(const gfx::Rect&)> OnPopupPaintCallback;
class OffScreenRenderWidgetHostView : public content::RenderWidgetHostViewBase,
public ui::CompositorDelegate,
public OffscreenViewProxyObserver {
public:
OffScreenRenderWidgetHostView(bool transparent,
bool painting,
int frame_rate,
const OnPaintCallback& callback,
content::RenderWidgetHost* render_widget_host,
OffScreenRenderWidgetHostView* parent_host_view,
gfx::Size initial_size);
~OffScreenRenderWidgetHostView() override;
content::BrowserAccessibilityManager* CreateBrowserAccessibilityManager(
content::BrowserAccessibilityDelegate*,
bool) override;
// content::RenderWidgetHostView:
void InitAsChild(gfx::NativeView) override;
void SetSize(const gfx::Size&) override;
void SetBounds(const gfx::Rect&) override;
gfx::NativeView GetNativeView(void) override;
gfx::NativeViewAccessible GetNativeViewAccessible(void) override;
ui::TextInputClient* GetTextInputClient() override;
void Focus(void) override;
bool HasFocus(void) override;
uint32_t GetCaptureSequenceNumber() const override;
bool IsSurfaceAvailableForCopy(void) override;
void Show(void) override;
void Hide(void) override;
bool IsShowing(void) override;
void EnsureSurfaceSynchronizedForWebTest() override;
gfx::Rect GetViewBounds(void) override;
gfx::Size GetVisibleViewportSize() override;
void SetInsets(const gfx::Insets&) override;
void SetBackgroundColor(SkColor color) override;
base::Optional<SkColor> GetBackgroundColor() override;
void UpdateBackgroundColor() override;
blink::mojom::PointerLockResult LockMouse(
bool request_unadjusted_movement) override;
blink::mojom::PointerLockResult ChangeMouseLock(
bool request_unadjusted_movement) override;
void UnlockMouse(void) override;
void TakeFallbackContentFrom(content::RenderWidgetHostView* view) override;
#if defined(OS_MACOSX)
void SetActive(bool active) override;
void ShowDefinitionForSelection() override;
void SpeakSelection() override;
bool UpdateNSViewAndDisplay();
#endif // defined(OS_MACOSX)
// content::RenderWidgetHostViewBase:
void ResetFallbackToFirstNavigationSurface() override;
void InitAsPopup(content::RenderWidgetHostView* rwhv,
const gfx::Rect& rect) override;
void InitAsFullscreen(content::RenderWidgetHostView*) override;
void UpdateCursor(const content::WebCursor&) override;
void SetIsLoading(bool is_loading) override;
void TextInputStateChanged(const ui::mojom::TextInputState& params) override;
void ImeCancelComposition(void) override;
void RenderProcessGone() override;
void Destroy(void) override;
void SetTooltipText(const base::string16&) override;
content::CursorManager* GetCursorManager() override;
void CopyFromSurface(
const gfx::Rect& src_rect,
const gfx::Size& output_size,
base::OnceCallback<void(const SkBitmap&)> callback) override;
void GetScreenInfo(content::ScreenInfo* results) override;
void TransformPointToRootSurface(gfx::PointF* point) override;
gfx::Rect GetBoundsInRootWindow(void) override;
viz::SurfaceId GetCurrentSurfaceId() const override;
std::unique_ptr<content::SyntheticGestureTarget>
CreateSyntheticGestureTarget() override;
void ImeCompositionRangeChanged(const gfx::Range&,
const std::vector<gfx::Rect>&) override;
gfx::Size GetCompositorViewportPixelSize() override;
content::RenderWidgetHostViewBase* CreateViewForWidget(
content::RenderWidgetHost*,
content::RenderWidgetHost*,
content::WebContentsView*) override;
const viz::LocalSurfaceIdAllocation& GetLocalSurfaceIdAllocation()
const override;
const viz::FrameSinkId& GetFrameSinkId() const override;
void DidNavigate() override;
bool TransformPointToCoordSpaceForView(
const gfx::PointF& point,
RenderWidgetHostViewBase* target_view,
gfx::PointF* transformed_point) override;
// ui::CompositorDelegate:
std::unique_ptr<viz::HostDisplayClient> CreateHostDisplayClient(
ui::Compositor* compositor) override;
bool InstallTransparency();
void CancelWidget();
void AddGuestHostView(OffScreenRenderWidgetHostView* guest_host);
void RemoveGuestHostView(OffScreenRenderWidgetHostView* guest_host);
void AddViewProxy(OffscreenViewProxy* proxy);
void RemoveViewProxy(OffscreenViewProxy* proxy);
void ProxyViewDestroyed(OffscreenViewProxy* proxy) override;
void OnPaint(const gfx::Rect& damage_rect, const SkBitmap& bitmap);
void OnPopupPaint(const gfx::Rect& damage_rect);
void OnProxyViewPaint(const gfx::Rect& damage_rect) override;
gfx::Size SizeInPixels();
void CompositeFrame(const gfx::Rect& damage_rect);
bool IsPopupWidget() const {
return widget_type_ == content::WidgetType::kPopup;
}
const SkBitmap& GetBacking() { return *backing_.get(); }
void HoldResize();
void ReleaseResize();
void SynchronizeVisualProperties();
void SendMouseEvent(const blink::WebMouseEvent& event);
void SendMouseWheelEvent(const blink::WebMouseWheelEvent& event);
void SetPainting(bool painting);
bool IsPainting() const;
void SetFrameRate(int frame_rate);
int GetFrameRate() const;
ui::Compositor* GetCompositor() const;
ui::Layer* GetRootLayer() const;
content::DelegatedFrameHost* GetDelegatedFrameHost() const;
void Invalidate();
void InvalidateBounds(const gfx::Rect&);
content::RenderWidgetHostImpl* render_widget_host() const {
return render_widget_host_;
}
gfx::Size size() const { return size_; }
void set_popup_host_view(OffScreenRenderWidgetHostView* popup_view) {
popup_host_view_ = popup_view;
}
void set_child_host_view(OffScreenRenderWidgetHostView* child_view) {
child_host_view_ = child_view;
}
private:
void SetupFrameRate(bool force);
void ResizeRootLayer(bool force);
viz::FrameSinkId AllocateFrameSinkId();
// Applies background color without notifying the RenderWidget about
// opaqueness changes.
void UpdateBackgroundColorFromRenderer(SkColor color);
// Weak ptrs.
content::RenderWidgetHostImpl* render_widget_host_;
OffScreenRenderWidgetHostView* parent_host_view_ = nullptr;
OffScreenRenderWidgetHostView* popup_host_view_ = nullptr;
OffScreenRenderWidgetHostView* child_host_view_ = nullptr;
std::set<OffScreenRenderWidgetHostView*> guest_host_views_;
std::set<OffscreenViewProxy*> proxy_views_;
const bool transparent_;
OnPaintCallback callback_;
OnPopupPaintCallback parent_callback_;
int frame_rate_ = 0;
int frame_rate_threshold_us_ = 0;
base::Time last_time_ = base::Time::Now();
gfx::Vector2dF last_scroll_offset_;
gfx::Size size_;
bool painting_;
bool is_showing_ = false;
bool is_destroyed_ = false;
gfx::Rect popup_position_;
bool hold_resize_ = false;
bool pending_resize_ = false;
bool paint_callback_running_ = false;
viz::LocalSurfaceIdAllocation delegated_frame_host_allocation_;
viz::ParentLocalSurfaceIdAllocator delegated_frame_host_allocator_;
viz::LocalSurfaceIdAllocation compositor_allocation_;
viz::ParentLocalSurfaceIdAllocator compositor_allocator_;
std::unique_ptr<ui::Layer> root_layer_;
std::unique_ptr<ui::Compositor> compositor_;
std::unique_ptr<content::DelegatedFrameHost> delegated_frame_host_;
std::unique_ptr<content::CursorManager> cursor_manager_;
OffScreenHostDisplayClient* host_display_client_;
std::unique_ptr<OffScreenVideoConsumer> video_consumer_;
std::unique_ptr<ElectronDelegatedFrameHostClient>
delegated_frame_host_client_;
content::MouseWheelPhaseHandler mouse_wheel_phase_handler_;
// Latest capture sequence number which is incremented when the caller
// requests surfaces be synchronized via
// EnsureSurfaceSynchronizedForWebTest().
uint32_t latest_capture_sequence_number_ = 0u;
SkColor background_color_ = SkColor();
std::unique_ptr<SkBitmap> backing_;
base::WeakPtrFactory<OffScreenRenderWidgetHostView> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(OffScreenRenderWidgetHostView);
};
} // namespace electron
#endif // SHELL_BROWSER_OSR_OSR_RENDER_WIDGET_HOST_VIEW_H_