Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Support zoom limiting on webFrame
Browse files Browse the repository at this point in the history
Auditors: @bsclifton

Electron side of the fix for brave/browser-laptop#6315
  • Loading branch information
bbondy committed Dec 23, 2016
1 parent bcdb019 commit 5a9e43c
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 12 deletions.
12 changes: 12 additions & 0 deletions atom/common/api/resources/web_frame_bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) {
apiFunctions.setHandleRequest('setSpellCheckProvider', function(lang, autoCorrectEnabled, spellCheckProvider) {
return webFrameNatives.setSpellCheckProvider(lang, autoCorrectEnabled, spellCheckProvider)
})

apiFunctions.setHandleRequest('setZoomLevel', function(level) {
return webFrameNatives.setZoomLevel(level)
})

apiFunctions.setHandleRequest('setZoomLevelLimits', function(minimumLevel, maximumLevel) {
return webFrameNatives.setZoomLevelLimits(minimumLevel, maximumLevel)
})

apiFunctions.setHandleRequest('setPageScaleLimits', function(minScale, maxScale) {
return webFrameNatives.setPageScaleLimits(minScale, maxScale)
})
})

exports.$set('binding', binding.generate())
41 changes: 41 additions & 0 deletions brave/common/extensions/api/web_frame.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,47 @@
}
]
},
{
"name": "setZoomLevel",
"nocompile": true,
"type": "function",
"parameters": [
{
"type": "number",
"name": "level"
}
]
},
{
"name": "setZoomLevelLimits",
"nocompile": true,
"type": "function",
"parameters": [
{
"type": "number",
"name": "minimumLevel"
},
{
"type": "number",
"name": "maximumLevel"
}
]
},
{
"name": "setPageScaleLimits",
"nocompile": true,
"type": "function",
"parameters": [
{
"type": "number",
"name": "minScale"
},
{
"type": "number",
"name": "maxScale"
}
]
},
{
"name": "executeJavaScript",
"nocompile": true,
Expand Down
51 changes: 39 additions & 12 deletions brave/renderer/extensions/web_frame_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ WebFrameBindings::WebFrameBindings(extensions::ScriptContext* context)
"setSpellCheckProvider",
base::Bind(&WebFrameBindings::SetSpellCheckProvider,
base::Unretained(this)));
RouteFunction(
"setZoomLevel",
base::Bind(&WebFrameBindings::SetZoomLevel,
base::Unretained(this)));
RouteFunction(
"setZoomLevelLimits",
base::Bind(&WebFrameBindings::SetZoomLevelLimits,
base::Unretained(this)));
RouteFunction(
"setPageScaleLimits",
base::Bind(&WebFrameBindings::SetPageScaleLimits,
base::Unretained(this)));
RouteFunction(
"setGlobal",
base::Bind(&WebFrameBindings::SetGlobal, base::Unretained(this)));
Expand Down Expand Up @@ -148,7 +160,6 @@ void WebFrameBindings::ExecuteJavaScript(
callback.release());
}


void WebFrameBindings::SetGlobal(
const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = GetIsolate();
Expand Down Expand Up @@ -183,10 +194,13 @@ void WebFrameBindings::SetGlobal(
}
}

// double WebFrame::SetZoomLevel(double level) {
// double ret = web_frame_->view()->setZoomLevel(level);
// return ret;
// }
void WebFrameBindings::SetZoomLevel(
const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK_EQ(args.Length(), 1);
CHECK(args[0]->IsInt32());
double level = args[0].As<v8::Number>()->Value();
context()->web_frame()->view()->setZoomLevel(level);
}

// double WebFrame::GetZoomLevel() const {
// return web_frame_->view()->zoomLevel();
Expand All @@ -201,9 +215,15 @@ void WebFrameBindings::SetGlobal(
// return blink::WebView::zoomLevelToZoomFactor(GetZoomLevel());
// }

// void WebFrame::SetZoomLevelLimits(double min_level, double max_level) {
// web_frame_->view()->zoomLimitsChanged(min_level, max_level);
// }
void WebFrameBindings::SetZoomLevelLimits(
const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK_EQ(args.Length(), 2);
CHECK(args[0]->IsInt32());
CHECK(args[1]->IsInt32());
float min_level = args[0].As<v8::Number>()->Value();
float max_level = args[1].As<v8::Number>()->Value();
context()->web_frame()->view()->zoomLimitsChanged(min_level, max_level);
}

// float WebFrame::GetPageScaleFactor() {
// return web_frame_->view()->pageScaleFactor();
Expand All @@ -213,10 +233,17 @@ void WebFrameBindings::SetGlobal(
// web_frame_->view()->setPageScaleFactor(factor);
// }

// void WebFrame::SetPageScaleLimits(float min_scale, float max_scale) {
// web_frame_->view()->setDefaultPageScaleLimits(min_scale, max_scale);
// web_frame_->view()->setIgnoreViewportTagScaleLimits(true);
// }
void WebFrameBindings::SetPageScaleLimits(
const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK_EQ(args.Length(), 2);
CHECK(args[0]->IsInt32());
CHECK(args[1]->IsInt32());
auto web_frame = context()->web_frame();
float min_scale = args[0].As<v8::Number>()->Value();
float max_scale = args[1].As<v8::Number>()->Value();
web_frame->view()->setDefaultPageScaleLimits(min_scale, max_scale);
web_frame->view()->setIgnoreViewportTagScaleLimits(true);
}

// float WebFrame::GetTextZoomFactor() {
// return web_frame_->view()->textZoomFactor();
Expand Down
5 changes: 5 additions & 0 deletions brave/renderer/extensions/web_frame_bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class WebFrameBindings : public extensions::ObjectBackedNativeHandler {
void RegisterEmbedderCustomElement(
const v8::FunctionCallbackInfo<v8::Value>& args);
void SetSpellCheckProvider(const v8::FunctionCallbackInfo<v8::Value>& args);

void SetZoomLevel(const v8::FunctionCallbackInfo<v8::Value>& args);
void SetZoomLevelLimits(const v8::FunctionCallbackInfo<v8::Value>& args);
void SetPageScaleLimits(const v8::FunctionCallbackInfo<v8::Value>& args);

void SetGlobal(const v8::FunctionCallbackInfo<v8::Value>& args);
void ExecuteJavaScript(const v8::FunctionCallbackInfo<v8::Value>& args);
void Invalidate() override;
Expand Down

2 comments on commit 5a9e43c

@bsclifton
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

@darkdh
Copy link
Member

@darkdh darkdh commented on 5a9e43c Jan 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Please sign in to comment.