Commit 9faf17b1 authored by Robbie Gibson's avatar Robbie Gibson Committed by Commit Bot

[iOS] Only enable text zoom on pages with HTML content

The text zoom option should only be enabled on pages with HTML content,
as the zoom mechanism uses Javascript.

Bug: 1062101
Change-Id: Ia2285d73adf5b82fb28c348e49c16b4453a707c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2106191
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751303}
parent 2577c2b9
......@@ -652,7 +652,7 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
// Whether or not text zoom is enabled
- (BOOL)isTextZoomEnabled {
if (self.webContentAreaShowingOverlay || ![self isCurrentURLWebURL]) {
if (self.webContentAreaShowingOverlay) {
return NO;
}
......@@ -660,7 +660,8 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
return NO;
}
FontSizeTabHelper* helper = FontSizeTabHelper::FromWebState(self.webState);
return helper && !helper->IsTextZoomUIActive();
return helper && helper->CurrentPageSupportsTextZoom() &&
!helper->IsTextZoomUIActive();
}
// Whether the page is currently loading.
......
......@@ -55,6 +55,9 @@ class FontSizeTabHelper : public web::WebStateObserver,
// not the UI should be displayed when possible.
void SetTextZoomUIActive(bool active);
// Text zoom is currently only supported on HTML pages.
bool CurrentPageSupportsTextZoom() const;
// Remove any stored zoom levels from the provided |PrefService|.
static void ClearUserZoomPrefs(PrefService* pref_service);
......
......@@ -126,6 +126,9 @@ void FontSizeTabHelper::ClearUserZoomPrefs(PrefService* pref_service) {
}
void FontSizeTabHelper::SetPageFontSize(int size) {
if (!CurrentPageSupportsTextZoom()) {
return;
}
tab_helper_has_zoomed_ = true;
if (web_state_->ContentIsHTML()) {
NSString* js = [NSString
......@@ -135,6 +138,7 @@ void FontSizeTabHelper::SetPageFontSize(int size) {
}
void FontSizeTabHelper::UserZoom(Zoom zoom) {
DCHECK(CurrentPageSupportsTextZoom());
double new_zoom_multiplier = NewMultiplierAfterZoom(zoom).value_or(1);
StoreCurrentUserZoomMultiplier(new_zoom_multiplier);
......@@ -206,6 +210,10 @@ void FontSizeTabHelper::SetTextZoomUIActive(bool active) {
text_zoom_ui_active_ = active;
}
bool FontSizeTabHelper::CurrentPageSupportsTextZoom() const {
return web_state_->ContentIsHTML();
}
int FontSizeTabHelper::GetFontSize() const {
// Multiply by 100 as the web property needs a percentage.
return SystemSuggestedFontSizeMultiplier() * GetCurrentUserZoomMultiplier() *
......
......@@ -277,3 +277,15 @@ TEST_F(FontSizeTabHelperTest, ClearUserZoomPrefs) {
->Get(prefs::kIosUserZoomMultipliers)
->DictEmpty());
}
// Tests that zoom is only enabled if the page content is html.
TEST_F(FontSizeTabHelperTest, CanZoomContent) {
FontSizeTabHelper* font_size_tab_helper =
FontSizeTabHelper::FromWebState(&web_state_);
web_state_.SetContentIsHTML(false);
EXPECT_FALSE(font_size_tab_helper->CurrentPageSupportsTextZoom());
web_state_.SetContentIsHTML(true);
EXPECT_TRUE(font_size_tab_helper->CurrentPageSupportsTextZoom());
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment