fix: crash on invalid zoomFactor (#22673)

This commit is contained in:
Shelley Vohr 2020-03-13 23:13:05 +00:00 committed by GitHub
parent 9c5874306d
commit a4c4c86b9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 5 deletions

View file

@ -4,6 +4,7 @@
#include "shell/browser/api/electron_api_web_contents.h"
#include <limits>
#include <memory>
#include <set>
#include <string>
@ -2489,7 +2490,13 @@ double WebContents::GetZoomLevel() const {
return zoom_controller_->GetZoomLevel();
}
void WebContents::SetZoomFactor(double factor) {
void WebContents::SetZoomFactor(gin_helper::ErrorThrower thrower,
double factor) {
if (factor < std::numeric_limits<double>::epsilon()) {
thrower.ThrowError("'zoomFactor' must be a double greater than 0.0");
return;
}
auto level = blink::PageZoomFactorToZoomLevel(factor);
SetZoomLevel(level);
}

View file

@ -297,7 +297,7 @@ class WebContents : public gin_helper::TrackableObject<WebContents>,
// Methods for zoom handling.
void SetZoomLevel(double level);
double GetZoomLevel() const;
void SetZoomFactor(double factor);
void SetZoomFactor(gin_helper::ErrorThrower thrower, double factor);
double GetZoomFactor() const;
// Callback triggered on permission response.