mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: crash on invalid zoomFactor (#22710)
This commit is contained in:
@@ -1066,11 +1066,13 @@ Returns `Boolean` - Whether audio is currently playing.
|
||||
|
||||
#### `contents.setZoomFactor(factor)`
|
||||
|
||||
* `factor` Number - Zoom factor.
|
||||
* `factor` Double - Zoom factor; default is 1.0.
|
||||
|
||||
Changes the zoom factor to the specified factor. Zoom factor is
|
||||
zoom percent divided by 100, so 300% = 3.0.
|
||||
|
||||
The factor must be greater than 0.0.
|
||||
|
||||
**[Deprecated](modernization/property-updates.md)**
|
||||
|
||||
#### `contents.getZoomFactor()`
|
||||
|
||||
@@ -22,11 +22,13 @@ The `WebFrame` class has the following instance methods:
|
||||
|
||||
### `webFrame.setZoomFactor(factor)`
|
||||
|
||||
* `factor` Number - Zoom factor.
|
||||
* `factor` Double - Zoom factor; default is 1.0.
|
||||
|
||||
Changes the zoom factor to the specified factor. Zoom factor is
|
||||
zoom percent divided by 100, so 300% = 3.0.
|
||||
|
||||
The factor must be greater than 0.0.
|
||||
|
||||
### `webFrame.getZoomFactor()`
|
||||
|
||||
Returns `Number` - The current zoom factor.
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "shell/browser/api/atom_api_web_contents.h"
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
@@ -2321,7 +2322,12 @@ double WebContents::GetZoomLevel() const {
|
||||
return zoom_controller_->GetZoomLevel();
|
||||
}
|
||||
|
||||
void WebContents::SetZoomFactor(double factor) {
|
||||
void WebContents::SetZoomFactor(mate::Arguments* args, double factor) {
|
||||
if (factor < std::numeric_limits<double>::epsilon()) {
|
||||
args->ThrowError("'zoomFactor' must be a double greater than 0.0");
|
||||
return;
|
||||
}
|
||||
|
||||
auto level = content::ZoomFactorToZoomLevel(factor);
|
||||
SetZoomLevel(level);
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||
// Methods for zoom handling.
|
||||
void SetZoomLevel(double level);
|
||||
double GetZoomLevel() const;
|
||||
void SetZoomFactor(double factor);
|
||||
void SetZoomFactor(mate::Arguments* args, double factor);
|
||||
double GetZoomFactor() const;
|
||||
|
||||
// Callback triggered on permission response.
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@@ -250,7 +251,14 @@ double GetZoomLevel(v8::Local<v8::Value> window) {
|
||||
return result;
|
||||
}
|
||||
|
||||
void SetZoomFactor(v8::Local<v8::Value> window, double factor) {
|
||||
void SetZoomFactor(mate::Arguments* args,
|
||||
v8::Local<v8::Value> window,
|
||||
double factor) {
|
||||
if (factor < std::numeric_limits<double>::epsilon()) {
|
||||
args->ThrowError("'zoomFactor' must be a double greater than 0.0");
|
||||
return;
|
||||
}
|
||||
|
||||
SetZoomLevel(window, blink::WebView::ZoomFactorToZoomLevel(factor));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user