diff --git a/atom/browser/api/atom_api_browser_window.cc b/atom/browser/api/atom_api_browser_window.cc index 103d294bd8cf..5a429e9a1e31 100644 --- a/atom/browser/api/atom_api_browser_window.cc +++ b/atom/browser/api/atom_api_browser_window.cc @@ -170,17 +170,6 @@ void BrowserWindow::OnRendererUnresponsive(content::RenderProcessHost*) { ScheduleUnresponsiveEvent(50); } -bool BrowserWindow::OnMessageReceived(const IPC::Message& message, - content::RenderFrameHost* rfh) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(BrowserWindow, message, rfh) - IPC_MESSAGE_HANDLER(AtomFrameHostMsg_UpdateDraggableRegions, - UpdateDraggableRegions) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - void BrowserWindow::OnCloseContents() { // On some machines it may happen that the window gets destroyed for twice, // checking web_contents() can effectively guard against that. @@ -216,6 +205,11 @@ void BrowserWindow::OnRendererResponsive() { Emit("responsive"); } +void BrowserWindow::OnDraggableRegionsUpdated( + const std::vector& regions) { + UpdateDraggableRegions(regions); +} + void BrowserWindow::RequestPreferredWidth(int* width) { *width = web_contents()->GetPreferredSize().width(); } @@ -276,7 +270,7 @@ void BrowserWindow::OnWindowFocus() { void BrowserWindow::OnWindowResize() { #if defined(OS_MACOSX) if (!draggable_regions_.empty()) - UpdateDraggableRegions(nullptr, draggable_regions_); + UpdateDraggableRegions(draggable_regions_); #endif TopLevelWindow::OnWindowResize(); } @@ -314,28 +308,28 @@ void BrowserWindow::SetBrowserView(v8::Local value) { TopLevelWindow::ResetBrowserViews(); TopLevelWindow::AddBrowserView(value); #if defined(OS_MACOSX) - UpdateDraggableRegions(nullptr, draggable_regions_); + UpdateDraggableRegions(draggable_regions_); #endif } void BrowserWindow::AddBrowserView(v8::Local value) { TopLevelWindow::AddBrowserView(value); #if defined(OS_MACOSX) - UpdateDraggableRegions(nullptr, draggable_regions_); + UpdateDraggableRegions(draggable_regions_); #endif } void BrowserWindow::RemoveBrowserView(v8::Local value) { TopLevelWindow::RemoveBrowserView(value); #if defined(OS_MACOSX) - UpdateDraggableRegions(nullptr, draggable_regions_); + UpdateDraggableRegions(draggable_regions_); #endif } void BrowserWindow::ResetBrowserViews() { TopLevelWindow::ResetBrowserViews(); #if defined(OS_MACOSX) - UpdateDraggableRegions(nullptr, draggable_regions_); + UpdateDraggableRegions(draggable_regions_); #endif } @@ -377,13 +371,13 @@ v8::Local BrowserWindow::GetWebContents(v8::Isolate* isolate) { // Convert draggable regions in raw format to SkRegion format. std::unique_ptr BrowserWindow::DraggableRegionsToSkRegion( - const std::vector& regions) { + const std::vector& regions) { auto sk_region = std::make_unique(); - for (const DraggableRegion& region : regions) { + for (const auto& region : regions) { sk_region->op( - region.bounds.x(), region.bounds.y(), region.bounds.right(), - region.bounds.bottom(), - region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); + region->bounds.x(), region->bounds.y(), region->bounds.right(), + region->bounds.bottom(), + region->draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); } return sk_region; } diff --git a/atom/browser/api/atom_api_browser_window.h b/atom/browser/api/atom_api_browser_window.h index 6cf33384f60e..1750a0bf33e3 100644 --- a/atom/browser/api/atom_api_browser_window.h +++ b/atom/browser/api/atom_api_browser_window.h @@ -51,12 +51,12 @@ class BrowserWindow : public TopLevelWindow, void DidFirstVisuallyNonEmptyPaint() override; void BeforeUnloadDialogCancelled() override; void OnRendererUnresponsive(content::RenderProcessHost*) override; - bool OnMessageReceived(const IPC::Message& message, - content::RenderFrameHost* rfh) override; // ExtendedWebContentsObserver: void OnCloseContents() override; void OnRendererResponsive() override; + void OnDraggableRegionsUpdated( + const std::vector& regions) override; // NativeWindowObserver: void RequestPreferredWidth(int* width) override; @@ -91,12 +91,12 @@ class BrowserWindow : public TopLevelWindow, // Helpers. // Called when the window needs to update its draggable region. - void UpdateDraggableRegions(content::RenderFrameHost* rfh, - const std::vector& regions); + void UpdateDraggableRegions( + const std::vector& regions); // Convert draggable regions in raw format to SkRegion format. std::unique_ptr DraggableRegionsToSkRegion( - const std::vector& regions); + const std::vector& regions); // Schedule a notification unresponsive event. void ScheduleUnresponsiveEvent(int ms); @@ -112,7 +112,7 @@ class BrowserWindow : public TopLevelWindow, base::CancelableClosure window_unresponsive_closure_; #if defined(OS_MACOSX) - std::vector draggable_regions_; + std::vector draggable_regions_; #endif v8::Global web_contents_; diff --git a/atom/browser/api/atom_api_browser_window_mac.mm b/atom/browser/api/atom_api_browser_window_mac.mm index 55c3bad7dd3c..d5eb23660df1 100644 --- a/atom/browser/api/atom_api_browser_window_mac.mm +++ b/atom/browser/api/atom_api_browser_window_mac.mm @@ -12,7 +12,6 @@ #include "atom/browser/native_browser_view.h" #include "atom/browser/native_window_mac.h" #include "atom/browser/ui/inspectable_web_contents_view.h" -#include "atom/common/draggable_region.h" #include "base/mac/scoped_nsobject.h" @interface NSView (WebContentsView) @@ -76,8 +75,7 @@ void BrowserWindow::OverrideNSWindowContentView(InspectableWebContents* iwc) { } void BrowserWindow::UpdateDraggableRegions( - content::RenderFrameHost* rfh, - const std::vector& regions) { + const std::vector& regions) { if (window_->has_frame()) return; @@ -103,7 +101,9 @@ void BrowserWindow::UpdateDraggableRegions( // Draggable regions is implemented by having the whole web view draggable // (mouseDownCanMoveWindow) and overlaying regions that are not draggable. - draggable_regions_ = regions; + draggable_regions_.clear(); + for (const auto& r : regions) + draggable_regions_.push_back(r.Clone()); std::vector drag_exclude_rects; if (regions.empty()) { drag_exclude_rects.push_back(gfx::Rect(0, 0, webViewWidth, webViewHeight)); @@ -114,7 +114,7 @@ void BrowserWindow::UpdateDraggableRegions( auto browser_views = window_->browser_views(); for (NativeBrowserView* view : browser_views) { - (view)->UpdateDraggableRegions(drag_exclude_rects); + view->UpdateDraggableRegions(drag_exclude_rects); } // Create and add a ControlRegionView for each region that needs to be diff --git a/atom/browser/api/atom_api_browser_window_views.cc b/atom/browser/api/atom_api_browser_window_views.cc index d681f5a9232d..8094df0766c9 100644 --- a/atom/browser/api/atom_api_browser_window_views.cc +++ b/atom/browser/api/atom_api_browser_window_views.cc @@ -11,8 +11,7 @@ namespace atom { namespace api { void BrowserWindow::UpdateDraggableRegions( - content::RenderFrameHost* rfh, - const std::vector& regions) { + const std::vector& regions) { if (window_->has_frame()) return; static_cast(window_.get()) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 763a1e00f5bb..be40ada46e7c 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -964,6 +964,12 @@ void WebContents::MessageHost(const std::string& channel, base::nullopt, channel, std::move(arguments)); } +void WebContents::UpdateDraggableRegions( + std::vector regions) { + for (ExtendedWebContentsObserver& observer : observers_) + observer.OnDraggableRegionsUpdated(regions); +} + void WebContents::RenderFrameDeleted( content::RenderFrameHost* render_frame_host) { // A RenderFrameHost can be destroyed before the related Mojo binding is diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 1aea7f1d035c..d9d2ed1678db 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -69,6 +69,8 @@ class ExtendedWebContentsObserver : public base::CheckedObserver { public: virtual void OnCloseContents() {} virtual void OnRendererResponsive() {} + virtual void OnDraggableRegionsUpdated( + const std::vector& regions) {} protected: ~ExtendedWebContentsObserver() override {} @@ -505,6 +507,8 @@ class WebContents : public mate::TrackableObject, const std::string& channel, base::Value arguments) override; void MessageHost(const std::string& channel, base::Value arguments) override; + void UpdateDraggableRegions( + std::vector regions) override; // Called when we receive a CursorChange message from chromium. void OnCursorChange(const content::WebCursor& cursor); diff --git a/atom/browser/native_browser_view.h b/atom/browser/native_browser_view.h index fb519d41ee69..3e72f263c2cd 100644 --- a/atom/browser/native_browser_view.h +++ b/atom/browser/native_browser_view.h @@ -7,7 +7,6 @@ #include -#include "atom/common/draggable_region.h" #include "base/macros.h" #include "content/public/browser/web_contents.h" #include "third_party/skia/include/core/SkColor.h" diff --git a/atom/browser/native_browser_view_mac.h b/atom/browser/native_browser_view_mac.h index ae0f497f9355..7d16e2c33492 100644 --- a/atom/browser/native_browser_view_mac.h +++ b/atom/browser/native_browser_view_mac.h @@ -9,7 +9,6 @@ #include #include "atom/browser/native_browser_view.h" -#include "atom/common/draggable_region.h" #include "base/mac/scoped_nsobject.h" namespace atom { diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index e9bcbb83e484..e609de853714 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -44,8 +44,6 @@ namespace atom { class AtomMenuModel; class NativeBrowserView; -struct DraggableRegion; - #if defined(OS_MACOSX) typedef NSView* NativeWindowHandle; #else diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index de8e8a20b72e..0ec744fc62c3 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -22,7 +22,6 @@ #include "atom/browser/web_view_manager.h" #include "atom/browser/window_list.h" #include "atom/common/atom_constants.h" -#include "atom/common/draggable_region.h" #include "atom/common/native_mate_converters/image_converter.h" #include "atom/common/options_switches.h" #include "base/strings/utf_string_conversions.h" diff --git a/atom/common/api/BUILD.gn b/atom/common/api/BUILD.gn index ed29819c656e..cd367dc4a69d 100644 --- a/atom/common/api/BUILD.gn +++ b/atom/common/api/BUILD.gn @@ -7,5 +7,6 @@ mojom("mojo") { public_deps = [ "//mojo/public/mojom/base", + "//ui/gfx/geometry/mojo", ] } diff --git a/atom/common/api/api.mojom b/atom/common/api/api.mojom index ae5b665fcf1a..989becb9d952 100644 --- a/atom/common/api/api.mojom +++ b/atom/common/api/api.mojom @@ -1,6 +1,7 @@ module atom.mojom; import "mojo/public/mojom/base/values.mojom"; +import "ui/gfx/geometry/mojo/geometry.mojom"; interface ElectronRenderer { Message( @@ -13,6 +14,11 @@ interface ElectronRenderer { TakeHeapSnapshot(handle file) => (bool success); }; +struct DraggableRegion { + bool draggable; + gfx.mojom.Rect bounds; +}; + interface ElectronBrowser { // Emits an event on |channel| from the ipcMain JavaScript object in the main // process. @@ -50,4 +56,7 @@ interface ElectronBrowser { MessageHost( string channel, mojo_base.mojom.ListValue arguments); + + UpdateDraggableRegions( + array regions); }; diff --git a/atom/common/api/api_messages.h b/atom/common/api/api_messages.h index 26890cc40eb9..2083c98b3517 100644 --- a/atom/common/api/api_messages.h +++ b/atom/common/api/api_messages.h @@ -4,7 +4,6 @@ // Multiply-included file, no traditional include guard. -#include "atom/common/draggable_region.h" #include "base/strings/string16.h" #include "base/values.h" #include "content/public/common/common_param_traits.h" @@ -20,11 +19,6 @@ #define IPC_MESSAGE_START ElectronMsgStart -IPC_STRUCT_TRAITS_BEGIN(atom::DraggableRegion) - IPC_STRUCT_TRAITS_MEMBER(draggable) - IPC_STRUCT_TRAITS_MEMBER(bounds) -IPC_STRUCT_TRAITS_END() - IPC_MESSAGE_ROUTED3(AtomAutofillFrameHostMsg_ShowPopup, gfx::RectF /* bounds */, std::vector /* values */, @@ -35,10 +29,6 @@ IPC_MESSAGE_ROUTED0(AtomAutofillFrameHostMsg_HidePopup) IPC_MESSAGE_ROUTED1(AtomAutofillFrameMsg_AcceptSuggestion, base::string16 /* suggestion */) -// Sent by the renderer when the draggable regions are updated. -IPC_MESSAGE_ROUTED1(AtomFrameHostMsg_UpdateDraggableRegions, - std::vector /* regions */) - // Update renderer process preferences. IPC_MESSAGE_CONTROL1(AtomMsg_UpdatePreferences, base::ListValue) diff --git a/atom/common/draggable_region.cc b/atom/common/draggable_region.cc deleted file mode 100644 index a571b2edf2b2..000000000000 --- a/atom/common/draggable_region.cc +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#include "atom/common/draggable_region.h" - -namespace atom { - -DraggableRegion::DraggableRegion() : draggable(false) {} - -} // namespace atom diff --git a/atom/common/draggable_region.h b/atom/common/draggable_region.h deleted file mode 100644 index a007c8cb9fe5..000000000000 --- a/atom/common/draggable_region.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#ifndef ATOM_COMMON_DRAGGABLE_REGION_H_ -#define ATOM_COMMON_DRAGGABLE_REGION_H_ - -#include "ui/gfx/geometry/rect.h" - -namespace atom { - -struct DraggableRegion { - bool draggable; - gfx::Rect bounds; - - DraggableRegion(); -}; - -} // namespace atom - -#endif // ATOM_COMMON_DRAGGABLE_REGION_H_ diff --git a/atom/renderer/atom_render_frame_observer.cc b/atom/renderer/atom_render_frame_observer.cc index 0cfb93dc6ac5..d10af97e3178 100644 --- a/atom/renderer/atom_render_frame_observer.cc +++ b/atom/renderer/atom_render_frame_observer.cc @@ -5,6 +5,7 @@ #include "atom/renderer/atom_render_frame_observer.h" #include +#include #include #include "atom/common/api/api_messages.h" @@ -19,11 +20,10 @@ #include "content/public/renderer/render_view.h" #include "electron/atom/common/api/api.mojom.h" #include "ipc/ipc_message_macros.h" -#include "mojo/public/cpp/bindings/associated_binding.h" #include "native_mate/dictionary.h" #include "net/base/net_module.h" #include "net/grit/net_resources.h" -#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" +#include "services/service_manager/public/cpp/interface_provider.h" #include "third_party/blink/public/platform/web_isolated_world_info.h" #include "third_party/blink/public/web/blink.h" #include "third_party/blink/public/web/web_document.h" @@ -95,16 +95,20 @@ void AtomRenderFrameObserver::DidCreateScriptContext( void AtomRenderFrameObserver::DraggableRegionsChanged() { blink::WebVector webregions = render_frame_->GetWebFrame()->GetDocument().DraggableRegions(); - std::vector regions; + std::vector regions; for (auto& webregion : webregions) { - DraggableRegion region; + auto region = mojom::DraggableRegion::New(); render_frame_->GetRenderView()->ConvertViewportToWindowViaWidget( &webregion.bounds); - region.bounds = webregion.bounds; - region.draggable = webregion.draggable; - regions.push_back(region); + region->bounds = webregion.bounds; + region->draggable = webregion.draggable; + regions.push_back(std::move(region)); } - Send(new AtomFrameHostMsg_UpdateDraggableRegions(routing_id(), regions)); + + mojom::ElectronBrowserPtr browser_ptr; + render_frame_->GetRemoteInterfaces()->GetInterface( + mojo::MakeRequest(&browser_ptr)); + browser_ptr->UpdateDraggableRegions(std::move(regions)); } void AtomRenderFrameObserver::WillReleaseScriptContext( diff --git a/filenames.gni b/filenames.gni index 6d44565c0920..778ca8172b61 100644 --- a/filenames.gni +++ b/filenames.gni @@ -512,8 +512,6 @@ filenames = { "atom/common/crash_reporter/win/crash_service.h", "atom/common/crash_reporter/win/crash_service_main.cc", "atom/common/crash_reporter/win/crash_service_main.h", - "atom/common/draggable_region.cc", - "atom/common/draggable_region.h", "atom/common/gin_util.h", "atom/common/heap_snapshot.cc", "atom/common/heap_snapshot.h",