зеркало из https://github.com/electron/electron.git
Change webview's zoom level on JavaScript side
This commit is contained in:
Родитель
118924ba7a
Коммит
af02739c4e
|
@ -33,7 +33,6 @@
|
|||
#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"
|
||||
|
@ -75,15 +74,6 @@ void SetUserAgentInIO(scoped_refptr<net::URLRequestContextGetter> getter,
|
|||
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 {
|
||||
|
@ -625,7 +615,6 @@ 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()
|
||||
|
||||
|
@ -1154,15 +1143,6 @@ 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> WebContents::CreateFrom(
|
||||
v8::Isolate* isolate, content::WebContents* web_contents) {
|
||||
|
|
|
@ -263,10 +263,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
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<v8::Value> session_;
|
||||
v8::Global<v8::Value> devtools_web_contents_;
|
||||
|
||||
|
|
|
@ -59,6 +59,9 @@ PDFPageSize = {
|
|||
const webFrameMethods = [
|
||||
'executeJavaScript',
|
||||
'insertText',
|
||||
'setZoomFactor',
|
||||
'setZoomLevel',
|
||||
'setZoomLevelLimits',
|
||||
];
|
||||
|
||||
wrapWebContents = function(webContents) {
|
||||
|
|
|
@ -30,12 +30,6 @@ 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 */)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "atom/renderer/api/atom_api_web_frame.h"
|
||||
|
||||
#include "atom/common/api/api_messages.h"
|
||||
#include "atom/common/api/event_emitter_caller.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"
|
||||
|
@ -38,11 +38,9 @@ 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);
|
||||
double ret = web_frame_->view()->setZoomLevel(level);
|
||||
mate::EmitEvent(isolate(), GetWrapper(isolate()), "zoom-level-changed", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
double WebFrame::GetZoomLevel() const {
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
var deprecate, webFrame;
|
||||
'use strict';
|
||||
|
||||
deprecate = require('electron').deprecate;
|
||||
const deprecate = require('electron').deprecate;
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
|
||||
webFrame = process.atomBinding('web_frame').webFrame;
|
||||
const webFrame = process.atomBinding('web_frame').webFrame;
|
||||
|
||||
// webFrame is an EventEmitter.
|
||||
webFrame.__proto__ = EventEmitter.prototype;
|
||||
|
||||
/* Deprecated. */
|
||||
// Lots of webview would subscribe to webFrame's events.
|
||||
webFrame.setMaxListeners(0);
|
||||
|
||||
// Deprecated.
|
||||
deprecate.rename(webFrame, 'registerUrlSchemeAsSecure', 'registerURLSchemeAsSecure');
|
||||
|
||||
deprecate.rename(webFrame, 'registerUrlSchemeAsBypassingCSP', 'registerURLSchemeAsBypassingCSP');
|
||||
|
||||
deprecate.rename(webFrame, 'registerUrlSchemeAsPrivileged', 'registerURLSchemeAsPrivileged');
|
||||
|
||||
module.exports = webFrame;
|
||||
|
|
|
@ -57,22 +57,6 @@ 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_;
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'user strict';
|
||||
|
||||
var WebViewImpl, deprecate, getNextId, guestViewInternal, ipcRenderer, listener, nextId, ref, registerBrowserPluginElement, registerWebViewElement, remote, useCapture, v8Util, webFrame, webViewConstants,
|
||||
hasProp = {}.hasOwnProperty,
|
||||
slice = [].slice;
|
||||
|
@ -39,6 +41,11 @@ WebViewImpl = (function() {
|
|||
this.setupFocusPropagation();
|
||||
this.viewInstanceId = getNextId();
|
||||
shadowRoot.appendChild(this.browserPluginNode);
|
||||
|
||||
// Subscribe to host's zoom level changes.
|
||||
webFrame.on('zoom-level-changed', (zoomLevel) => {
|
||||
this.webviewNode.setZoomLevel(zoomLevel);
|
||||
});
|
||||
}
|
||||
|
||||
WebViewImpl.prototype.createBrowserPluginNode = function() {
|
||||
|
@ -382,6 +389,9 @@ registerWebViewElement = function() {
|
|||
'insertText',
|
||||
'send',
|
||||
'sendInputEvent',
|
||||
'setZoomFactor',
|
||||
'setZoomLevel',
|
||||
'setZoomLevelLimits',
|
||||
];
|
||||
|
||||
/* Forward proto.foo* method calls to WebViewImpl.foo*. */
|
||||
|
|
Загрузка…
Ссылка в новой задаче