diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index be40ada46e7c..92b071193a12 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -252,21 +252,6 @@ void OnCapturePageDone(util::Promise promise, const SkBitmap& bitmap) { } // namespace -struct WebContents::FrameDispatchHelper { - WebContents* api_web_contents; - content::RenderFrameHost* rfh; - - bool Send(IPC::Message* msg) { return rfh->Send(msg); } - - void OnSetTemporaryZoomLevel(double level, IPC::Message* reply_msg) { - api_web_contents->OnSetTemporaryZoomLevel(rfh, level, reply_msg); - } - - void OnGetZoomLevel(IPC::Message* reply_msg) { - api_web_contents->OnGetZoomLevel(rfh, reply_msg); - } -}; - WebContents::WebContents(v8::Isolate* isolate, content::WebContents* web_contents) : content::WebContentsObserver(web_contents), type_(Type::REMOTE) { @@ -1146,13 +1131,7 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) { bool WebContents::OnMessageReceived(const IPC::Message& message, content::RenderFrameHost* frame_host) { bool handled = true; - FrameDispatchHelper helper = {this, frame_host}; IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContents, message, frame_host) - IPC_MESSAGE_FORWARD_DELAY_REPLY( - AtomFrameHostMsg_SetTemporaryZoomLevel, &helper, - FrameDispatchHelper::OnSetTemporaryZoomLevel) - IPC_MESSAGE_FORWARD_DELAY_REPLY(AtomFrameHostMsg_GetZoomLevel, &helper, - FrameDispatchHelper::OnGetZoomLevel) #if defined(TOOLKIT_VIEWS) IPC_MESSAGE_HANDLER(AtomAutofillFrameHostMsg_ShowPopup, ShowAutofillPopup) IPC_MESSAGE_HANDLER(AtomAutofillFrameHostMsg_HidePopup, HideAutofillPopup) @@ -2044,20 +2023,12 @@ double WebContents::GetZoomFactor() const { return content::ZoomLevelToZoomFactor(level); } -void WebContents::OnSetTemporaryZoomLevel(content::RenderFrameHost* rfh, - double level, - IPC::Message* reply_msg) { +void WebContents::SetTemporaryZoomLevel(double level) { zoom_controller_->SetTemporaryZoomLevel(level); - double new_level = zoom_controller_->GetZoomLevel(); - AtomFrameHostMsg_SetTemporaryZoomLevel::WriteReplyParams(reply_msg, - new_level); - rfh->Send(reply_msg); } -void WebContents::OnGetZoomLevel(content::RenderFrameHost* rfh, - IPC::Message* reply_msg) { - AtomFrameHostMsg_GetZoomLevel::WriteReplyParams(reply_msg, GetZoomLevel()); - rfh->Send(reply_msg); +void WebContents::DoGetZoomLevel(DoGetZoomLevelCallback callback) { + std::move(callback).Run(GetZoomLevel()); } v8::Local WebContents::GetPreloadPath(v8::Isolate* isolate) const { diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index d9d2ed1678db..c38ca4c2500c 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -474,7 +474,6 @@ class WebContents : public mate::TrackableObject, #endif private: - struct FrameDispatchHelper; AtomBrowserContext* GetBrowserContext() const; // Binds the given request for the ElectronBrowser API. When the @@ -509,16 +508,12 @@ class WebContents : public mate::TrackableObject, void MessageHost(const std::string& channel, base::Value arguments) override; void UpdateDraggableRegions( std::vector regions) override; + void SetTemporaryZoomLevel(double level) override; + void DoGetZoomLevel(DoGetZoomLevelCallback callback) override; // Called when we receive a CursorChange message from chromium. void OnCursorChange(const content::WebCursor& cursor); - // Called when received a synchronous message from renderer to - // set temporary zoom level. - void OnSetTemporaryZoomLevel(content::RenderFrameHost* frame_host, - double level, - IPC::Message* reply_msg); - // Called when received a synchronous message from renderer to // get the zoom level. void OnGetZoomLevel(content::RenderFrameHost* frame_host, diff --git a/atom/common/api/api.mojom b/atom/common/api/api.mojom index 989becb9d952..64de740b43c9 100644 --- a/atom/common/api/api.mojom +++ b/atom/common/api/api.mojom @@ -59,4 +59,9 @@ interface ElectronBrowser { UpdateDraggableRegions( array regions); + + SetTemporaryZoomLevel(double zoom_level); + + [Sync] + DoGetZoomLevel() => (double result); }; diff --git a/atom/common/api/api_messages.h b/atom/common/api/api_messages.h index 2083c98b3517..42396a00d0cc 100644 --- a/atom/common/api/api_messages.h +++ b/atom/common/api/api_messages.h @@ -7,15 +7,9 @@ #include "base/strings/string16.h" #include "base/values.h" #include "content/public/common/common_param_traits.h" -#include "content/public/common/referrer.h" #include "ipc/ipc_message_macros.h" -#include "ipc/ipc_platform_file.h" #include "ui/gfx/geometry/rect_f.h" #include "ui/gfx/ipc/gfx_param_traits.h" -#include "url/gurl.h" - -// The message starter should be declared in ipc/ipc_message_start.h. Since -// we don't want to patch Chromium, we just pretend to be Content Shell. #define IPC_MESSAGE_START ElectronMsgStart @@ -31,11 +25,3 @@ IPC_MESSAGE_ROUTED1(AtomAutofillFrameMsg_AcceptSuggestion, // Update renderer process preferences. IPC_MESSAGE_CONTROL1(AtomMsg_UpdatePreferences, base::ListValue) - -// Sent by renderer to set the temporary zoom level. -IPC_SYNC_MESSAGE_ROUTED1_1(AtomFrameHostMsg_SetTemporaryZoomLevel, - double /* zoom level */, - double /* result */) - -// Sent by renderer to get the zoom level. -IPC_SYNC_MESSAGE_ROUTED0_1(AtomFrameHostMsg_GetZoomLevel, double /* result */) diff --git a/atom/renderer/api/atom_api_web_frame.cc b/atom/renderer/api/atom_api_web_frame.cc index 677d40a45d80..73b55288c5ec 100644 --- a/atom/renderer/api/atom_api_web_frame.cc +++ b/atom/renderer/api/atom_api_web_frame.cc @@ -7,6 +7,7 @@ #include #include +#include "atom/common/api/api.mojom.h" #include "atom/common/api/api_messages.h" #include "atom/common/api/event_emitter_caller.h" #include "atom/common/native_mate_converters/blink_converter.h" @@ -23,6 +24,7 @@ #include "content/public/renderer/render_view.h" #include "native_mate/dictionary.h" #include "native_mate/object_template_builder.h" +#include "services/service_manager/public/cpp/interface_provider.h" #include "third_party/blink/public/platform/web_cache.h" #include "third_party/blink/public/platform/web_isolated_world_info.h" #include "third_party/blink/public/web/web_custom_element.h" @@ -201,25 +203,26 @@ void SetName(v8::Local window, const std::string& name) { blink::WebString::FromUTF8(name)); } -double SetZoomLevel(v8::Local window, double level) { - double result = 0.0; +void SetZoomLevel(v8::Local window, double level) { content::RenderFrame* render_frame = GetRenderFrame(window); - render_frame->Send(new AtomFrameHostMsg_SetTemporaryZoomLevel( - render_frame->GetRoutingID(), level, &result)); - return result; + mojom::ElectronBrowserPtr browser_ptr; + render_frame->GetRemoteInterfaces()->GetInterface( + mojo::MakeRequest(&browser_ptr)); + browser_ptr->SetTemporaryZoomLevel(level); } double GetZoomLevel(v8::Local window) { double result = 0.0; content::RenderFrame* render_frame = GetRenderFrame(window); - render_frame->Send( - new AtomFrameHostMsg_GetZoomLevel(render_frame->GetRoutingID(), &result)); + mojom::ElectronBrowserPtr browser_ptr; + render_frame->GetRemoteInterfaces()->GetInterface( + mojo::MakeRequest(&browser_ptr)); + browser_ptr->DoGetZoomLevel(&result); return result; } -double SetZoomFactor(v8::Local window, double factor) { - return blink::WebView::ZoomLevelToZoomFactor( - SetZoomLevel(window, blink::WebView::ZoomFactorToZoomLevel(factor))); +void SetZoomFactor(v8::Local window, double factor) { + SetZoomLevel(window, blink::WebView::ZoomFactorToZoomLevel(factor)); } double GetZoomFactor(v8::Local window) {