refactor: mojofy zoom api (#18608)
* refactor: mojofy zoom api * remove unneeded #includes * remove outdated comment
This commit is contained in:
parent
24b3d66767
commit
d1371c5dd0
5 changed files with 23 additions and 63 deletions
|
@ -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<v8::Value> WebContents::GetPreloadPath(v8::Isolate* isolate) const {
|
||||
|
|
|
@ -474,7 +474,6 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
#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<WebContents>,
|
|||
void MessageHost(const std::string& channel, base::Value arguments) override;
|
||||
void UpdateDraggableRegions(
|
||||
std::vector<mojom::DraggableRegionPtr> 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,
|
||||
|
|
|
@ -59,4 +59,9 @@ interface ElectronBrowser {
|
|||
|
||||
UpdateDraggableRegions(
|
||||
array<DraggableRegion> regions);
|
||||
|
||||
SetTemporaryZoomLevel(double zoom_level);
|
||||
|
||||
[Sync]
|
||||
DoGetZoomLevel() => (double result);
|
||||
};
|
||||
|
|
|
@ -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 */)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<v8::Value> window, const std::string& name) {
|
|||
blink::WebString::FromUTF8(name));
|
||||
}
|
||||
|
||||
double SetZoomLevel(v8::Local<v8::Value> window, double level) {
|
||||
double result = 0.0;
|
||||
void SetZoomLevel(v8::Local<v8::Value> 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<v8::Value> 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<v8::Value> window, double factor) {
|
||||
return blink::WebView::ZoomLevelToZoomFactor(
|
||||
SetZoomLevel(window, blink::WebView::ZoomFactorToZoomLevel(factor)));
|
||||
void SetZoomFactor(v8::Local<v8::Value> window, double factor) {
|
||||
SetZoomLevel(window, blink::WebView::ZoomFactorToZoomLevel(factor));
|
||||
}
|
||||
|
||||
double GetZoomFactor(v8::Local<v8::Value> window) {
|
||||
|
|
Loading…
Reference in a new issue