From 7756bb67624158c568a80d332c12fef863e35b7f Mon Sep 17 00:00:00 2001 From: Robo Date: Tue, 6 Oct 2015 21:03:14 +0530 Subject: [PATCH] webcontents: notify guests of embedders' zoom level change --- atom/browser/api/atom_api_web_contents.cc | 20 ++++++++++++++++++++ atom/browser/api/atom_api_web_contents.h | 4 ++++ atom/common/api/api_messages.h | 6 ++++++ atom/renderer/api/atom_api_web_frame.cc | 6 ++++++ atom/renderer/atom_renderer_client.cc | 19 +++++++++++++++++++ 5 files changed, 55 insertions(+) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index f6433ca635c..1a6600a926e 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -31,6 +31,7 @@ #include "chrome/browser/printing/print_view_manager_basic.h" #include "chrome/browser/printing/print_preview_message_handler.h" #include "content/common/view_messages.h" +#include "content/public/browser/browser_plugin_guest_manager.h" #include "content/public/browser/favicon_status.h" #include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/navigation_details.h" @@ -67,6 +68,15 @@ void SetUserAgentInIO(scoped_refptr getter, new net::StaticHttpUserAgentSettings("en-us,en", user_agent)); } +bool NotifyZoomLevelChanged( + double level, content::WebContents* guest_web_contents) { + guest_web_contents->SendToAllFrames( + new AtomViewMsg_SetZoomLevel(MSG_ROUTING_NONE, level)); + + // Return false to iterate over all guests. + return false; +} + } // namespace namespace mate { @@ -528,6 +538,7 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(AtomViewHostMsg_Message, OnRendererMessage) IPC_MESSAGE_HANDLER_DELAY_REPLY(AtomViewHostMsg_Message_Sync, OnRendererMessageSync) + IPC_MESSAGE_HANDLER(AtomViewHostMsg_ZoomLevelChanged, OnZoomLevelChanged) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -1033,6 +1044,15 @@ void WebContents::OnRendererMessageSync(const base::string16& channel, EmitWithSender(base::UTF16ToUTF8(channel), web_contents(), message, args); } +void WebContents::OnZoomLevelChanged(double level) { + auto manager = web_contents()->GetBrowserContext()->GetGuestManager(); + if (!manager) + return; + manager->ForEachGuest(web_contents(), + base::Bind(&NotifyZoomLevelChanged, + level)); +} + // static mate::Handle WebContents::CreateFrom( v8::Isolate* isolate, content::WebContents* web_contents) { diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index bbf331848c5..01075c450a5 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -247,6 +247,10 @@ class WebContents : public mate::TrackableObject, const base::ListValue& args, IPC::Message* message); + // Called when guests need to be notified of + // embedders' zoom level change. + void OnZoomLevelChanged(double level); + v8::Global session_; v8::Global devtools_web_contents_; diff --git a/atom/common/api/api_messages.h b/atom/common/api/api_messages.h index b32df3cef39..274e1f533eb 100644 --- a/atom/common/api/api_messages.h +++ b/atom/common/api/api_messages.h @@ -30,6 +30,12 @@ IPC_SYNC_MESSAGE_ROUTED2_1(AtomViewHostMsg_Message_Sync, base::ListValue /* arguments */, base::string16 /* result (in JSON) */) +IPC_MESSAGE_ROUTED1(AtomViewHostMsg_ZoomLevelChanged, + double /* level */) + +IPC_MESSAGE_ROUTED1(AtomViewMsg_SetZoomLevel, + double /* level */) + IPC_MESSAGE_ROUTED2(AtomViewMsg_Message, base::string16 /* channel */, base::ListValue /* arguments */) diff --git a/atom/renderer/api/atom_api_web_frame.cc b/atom/renderer/api/atom_api_web_frame.cc index 4506658588c..69613043043 100644 --- a/atom/renderer/api/atom_api_web_frame.cc +++ b/atom/renderer/api/atom_api_web_frame.cc @@ -4,11 +4,13 @@ #include "atom/renderer/api/atom_api_web_frame.h" +#include "atom/common/api/api_messages.h" #include "atom/common/native_mate_converters/callback.h" #include "atom/common/native_mate_converters/gfx_converter.h" #include "atom/common/native_mate_converters/string16_converter.h" #include "atom/renderer/api/atom_api_spell_check_client.h" #include "content/public/renderer/render_frame.h" +#include "content/public/renderer/render_view.h" #include "native_mate/dictionary.h" #include "native_mate/object_template_builder.h" #include "third_party/WebKit/public/web/WebDocument.h" @@ -34,6 +36,10 @@ void WebFrame::SetName(const std::string& name) { } double WebFrame::SetZoomLevel(double level) { + auto render_view = content::RenderView::FromWebView(web_frame_->view()); + // Notify guests if any for zoom level change. + render_view->Send( + new AtomViewHostMsg_ZoomLevelChanged(MSG_ROUTING_NONE, level)); return web_frame_->view()->setZoomLevel(level); } diff --git a/atom/renderer/atom_renderer_client.cc b/atom/renderer/atom_renderer_client.cc index b99372bf816..eeadabcba73 100644 --- a/atom/renderer/atom_renderer_client.cc +++ b/atom/renderer/atom_renderer_client.cc @@ -6,6 +6,7 @@ #include +#include "atom/common/api/api_messages.h" #include "atom/common/api/atom_bindings.h" #include "atom/common/node_bindings.h" #include "atom/common/node_includes.h" @@ -21,11 +22,13 @@ #include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_thread.h" +#include "ipc/ipc_message_macros.h" #include "third_party/WebKit/public/web/WebCustomElement.h" #include "third_party/WebKit/public/web/WebLocalFrame.h" #include "third_party/WebKit/public/web/WebPluginParams.h" #include "third_party/WebKit/public/web/WebKit.h" #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" +#include "third_party/WebKit/public/web/WebView.h" #if defined(OS_WIN) #include @@ -64,6 +67,22 @@ class AtomRenderFrameObserver : public content::RenderFrameObserver { render_frame()->GetWebFrame(), context); } + bool OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(AtomRenderFrameObserver, message) + IPC_MESSAGE_HANDLER(AtomViewMsg_SetZoomLevel, OnSetZoomLevel) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + + return handled; + } + + void OnSetZoomLevel(double level) { + auto view = render_frame()->GetWebFrame()->view(); + if (view) + view->setZoomLevel(level); + } + private: AtomRendererClient* renderer_client_;