use zoom factor webpreference option when required.

* When setzoomlevel is not called for the host.
* When there is no zoom preference for the host.
This commit is contained in:
deepak1556 2017-01-30 00:38:28 +05:30
parent b27c94368d
commit 07794a58aa
4 changed files with 41 additions and 21 deletions

View file

@ -68,6 +68,7 @@
#include "content/public/common/context_menu_params.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "net/base/url_util.h"
#include "net/url_request/url_request_context.h"
#include "third_party/WebKit/public/platform/WebInputEvent.h"
#include "third_party/WebKit/public/web/WebFindOptions.h"
@ -252,7 +253,8 @@ WebContents::WebContents(v8::Isolate* isolate,
type_(type),
request_id_(0),
background_throttling_(true),
enable_devtools_(true) {
enable_devtools_(true),
zoom_factor_(content::kMinimumZoomFactor) {
if (type == REMOTE) {
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent());
@ -272,9 +274,11 @@ WebContents::WebContents(v8::Isolate* isolate,
type_(BROWSER_WINDOW),
request_id_(0),
background_throttling_(true),
enable_devtools_(true) {
enable_devtools_(true),
zoom_factor_(content::kMinimumZoomFactor) {
// Read options.
options.Get("backgroundThrottling", &background_throttling_);
options.Get("zoomFactor", &zoom_factor_);
// FIXME(zcbenz): We should read "type" parameter for better design, but
// on Windows we have encountered a compiler bug that if we read "type"
@ -734,6 +738,8 @@ void WebContents::DidFinishNavigation(
auto url = navigation_handle->GetURL();
bool is_in_page = navigation_handle->IsSamePage();
if (is_main_frame && !is_in_page) {
// Set initial zoom factor if needed.
SetZoomFactorIfNeeded(url);
Emit("did-navigate", url);
} else if (is_in_page) {
Emit("did-navigate-in-page", url, is_main_frame);
@ -1500,6 +1506,15 @@ void WebContents::Invalidate() {
}
void WebContents::SetZoomLevel(double level) {
auto factor = content::ZoomLevelToZoomFactor(level);
if (!content::ZoomValuesEqual(zoom_factor_, factor)) {
content::NavigationEntry* entry =
web_contents()->GetController().GetLastCommittedEntry();
if (entry) {
std::string host = net::GetHostOrSpecFromURL(entry->GetURL());
host_zoom_factor_[host] = factor;
}
}
content::HostZoomMap::SetZoomLevel(web_contents(), level);
}
@ -1517,6 +1532,22 @@ double WebContents::GetZoomFactor() {
return content::ZoomLevelToZoomFactor(level);
}
void WebContents::SetZoomFactorIfNeeded(const GURL& url) {
if (zoom_factor_ == content::kMinimumZoomFactor)
return;
std::string host = net::GetHostOrSpecFromURL(url);
double zoom_factor = zoom_factor_;
auto it = host_zoom_factor_.find(host);
if (it != host_zoom_factor_.end())
zoom_factor = it->second;
auto level = content::ZoomFactorToZoomLevel(zoom_factor);
if (content::ZoomValuesEqual(level, GetZoomLevel()))
return;
SetZoomLevel(level);
}
v8::Local<v8::Value> WebContents::GetWebPreferences(v8::Isolate* isolate) {
WebContentsPreferences* web_preferences =
WebContentsPreferences::FromWebContents(web_contents());