Consolidate page zoom limits and conversions in blink/public/

We have the min/max page zoom factors limits and methods to convert
between "page zoom factor" and "page zoom level" in
- content/common/page_zoom.h
- blink/renderer/core/exported/web_view_impl.cc
- blink/public/web/web_view.h

Instead of duplicating the limits and the logic, consolidate it all
into a single blink public header. content/browser/ and components
are able to include blink public headers, they just can't link against
blink.

The new site is in blink/public/common/page/page_zoom.h

This updates all callers to point to this common site, and removes
the redundant ones in content/common/ and WebView{Impl}.

[email protected]
TBR=darin

Bug: 419087
Change-Id: Ib89f022d96c9ac7ebfd4b84c08f666a25458725a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1814857
Commit-Queue: danakj <[email protected]>
Reviewed-by: Darin Fisher <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Avi Drissman <[email protected]>
Auto-Submit: danakj <[email protected]>
Cr-Commit-Position: refs/heads/master@{#699424}
diff --git a/content/browser/client_hints/client_hints.cc b/content/browser/client_hints/client_hints.cc
index 5b326627..ed270d8c 100644
--- a/content/browser/client_hints/client_hints.cc
+++ b/content/browser/client_hints/client_hints.cc
@@ -20,13 +20,13 @@
 #include "content/public/browser/host_zoom_map.h"
 #include "content/public/common/content_features.h"
 #include "content/public/common/content_switches.h"
-#include "content/public/common/page_zoom.h"
 #include "net/base/url_util.h"
 #include "net/nqe/effective_connection_type.h"
 #include "net/nqe/network_quality_estimator_params.h"
 #include "services/network/public/cpp/network_quality_tracker.h"
 #include "third_party/blink/public/common/client_hints/client_hints.h"
 #include "third_party/blink/public/common/device_memory/approximated_device_memory.h"
+#include "third_party/blink/public/common/page/page_zoom.h"
 #include "third_party/blink/public/common/user_agent/user_agent_metadata.h"
 #include "third_party/blink/public/platform/web_client_hints_type.h"
 #include "ui/display/display.h"
@@ -137,7 +137,7 @@
                      ->GetDefaultZoomLevel();
   }
 
-  return content::ZoomLevelToZoomFactor(zoom_level);
+  return blink::PageZoomLevelToZoomFactor(zoom_level);
 #endif
 }
 
diff --git a/content/browser/host_zoom_map_impl.cc b/content/browser/host_zoom_map_impl.cc
index d1acf73..45fbb2e 100644
--- a/content/browser/host_zoom_map_impl.cc
+++ b/content/browser/host_zoom_map_impl.cc
@@ -24,9 +24,9 @@
 #include "content/public/browser/resource_context.h"
 #include "content/public/browser/site_instance.h"
 #include "content/public/browser/storage_partition.h"
-#include "content/public/common/page_zoom.h"
 #include "content/public/common/url_constants.h"
 #include "net/base/url_util.h"
+#include "third_party/blink/public/common/page/page_zoom.h"
 
 namespace content {
 
@@ -225,7 +225,7 @@
                                                   base::Time last_modified) {
   DCHECK_CURRENTLY_ON(BrowserThread::UI);
 
-  if (ZoomValuesEqual(level, default_zoom_level_)) {
+  if (blink::PageZoomValuesEqual(level, default_zoom_level_)) {
     host_zoom_levels_.erase(host);
   } else {
     ZoomLevel& zoomLevel = host_zoom_levels_[host];
@@ -273,14 +273,14 @@
 void HostZoomMapImpl::SetDefaultZoomLevel(double level) {
   DCHECK_CURRENTLY_ON(BrowserThread::UI);
 
-  if (ZoomValuesEqual(level, default_zoom_level_))
-      return;
+  if (blink::PageZoomValuesEqual(level, default_zoom_level_))
+    return;
 
   default_zoom_level_ = level;
 
   // First, remove all entries that match the new default zoom level.
   for (auto it = host_zoom_levels_.begin(); it != host_zoom_levels_.end();) {
-    if (ZoomValuesEqual(it->second.level, default_zoom_level_))
+    if (blink::PageZoomValuesEqual(it->second.level, default_zoom_level_))
       it = host_zoom_levels_.erase(it);
     else
       it++;
diff --git a/content/browser/renderer_host/render_widget_host_unittest.cc b/content/browser/renderer_host/render_widget_host_unittest.cc
index 2bc014f..542aa4fa 100644
--- a/content/browser/renderer_host/render_widget_host_unittest.cc
+++ b/content/browser/renderer_host/render_widget_host_unittest.cc
@@ -58,6 +58,7 @@
 #include "mojo/public/cpp/bindings/pending_remote.h"
 #include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/blink/public/common/page/page_zoom.h"
 #include "ui/display/screen.h"
 #include "ui/events/base_event_utils.h"
 #include "ui/events/blink/blink_features.h"
@@ -762,7 +763,7 @@
   // The zoom has changed so host should send out a sync message
   EXPECT_CALL(mock_visual_properties_manager_, SendVisualProperties(_, _))
       .Times(1);
-  double new_zoom_level = content::ZoomFactorToZoomLevel(0.25);
+  double new_zoom_level = blink::PageZoomFactorToZoomLevel(0.25);
   delegate_->SetZoomLevel(new_zoom_level);
   EXPECT_TRUE(host_->SynchronizeVisualProperties());
   EXPECT_FALSE(host_->visual_properties_ack_pending_);
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index cfaab6e90..f408405 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -132,7 +132,6 @@
 #include "content/public/common/content_features.h"
 #include "content/public/common/content_switches.h"
 #include "content/public/common/page_state.h"
-#include "content/public/common/page_zoom.h"
 #include "content/public/common/referrer_type_converters.h"
 #include "content/public/common/result_codes.h"
 #include "content/public/common/url_utils.h"
@@ -153,6 +152,7 @@
 #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
 #include "third_party/blink/public/common/frame/sandbox_flags.h"
 #include "third_party/blink/public/common/mime_util/mime_util.h"
+#include "third_party/blink/public/common/page/page_zoom.h"
 #include "third_party/blink/public/mojom/loader/pause_subresource_loading_handle.mojom.h"
 #include "third_party/blink/public/mojom/mediastream/media_stream.mojom-shared.h"
 #include "third_party/blink/public/platform/web_security_style.h"
@@ -572,8 +572,10 @@
       is_showing_before_unload_dialog_(false),
       last_active_time_(base::TimeTicks::Now()),
       closed_by_user_gesture_(false),
-      minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
-      maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
+      minimum_zoom_percent_(
+          static_cast<int>(blink::kMinimumPageZoomFactor * 100)),
+      maximum_zoom_percent_(
+          static_cast<int>(blink::kMaximumPageZoomFactor * 100)),
       zoom_scroll_remainder_(0),
       fullscreen_widget_process_id_(ChildProcessHost::kInvalidUniqueID),
       fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
diff --git a/content/browser/zoom_browsertest.cc b/content/browser/zoom_browsertest.cc
index f575a34c..7983ca39 100644
--- a/content/browser/zoom_browsertest.cc
+++ b/content/browser/zoom_browsertest.cc
@@ -12,7 +12,6 @@
 #include "content/public/browser/navigation_entry.h"
 #include "content/public/browser/notification_service.h"
 #include "content/public/browser/notification_types.h"
-#include "content/public/common/page_zoom.h"
 #include "content/public/test/browser_test_utils.h"
 #include "content/public/test/content_browser_test.h"
 #include "content/public/test/content_browser_test_utils.h"
@@ -21,6 +20,7 @@
 #include "content/test/content_browser_test_utils_internal.h"
 #include "net/dns/mock_host_resolver.h"
 #include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/blink/public/common/page/page_zoom.h"
 #include "url/gurl.h"
 
 namespace content {
@@ -244,7 +244,7 @@
     ResizeObserver observer(root->current_frame_host());
 
     const double new_zoom_level =
-        default_zoom_level + ZoomFactorToZoomLevel(new_zoom_factor);
+        default_zoom_level + blink::PageZoomFactorToZoomLevel(new_zoom_factor);
     host_zoom_map->SetZoomLevelForHost(top_level_host, new_zoom_level);
 
     WaitForResize(msg_queue, observer);
@@ -311,7 +311,7 @@
                                  scale_one_grandchild_width, kTolerance);
 
     const double new_zoom_level =
-        default_zoom_level + ZoomFactorToZoomLevel(new_zoom_factor);
+        default_zoom_level + blink::PageZoomFactorToZoomLevel(new_zoom_factor);
     host_zoom_map->SetZoomLevelForHost(top_level_host, new_zoom_level);
 
     WaitAndCheckFrameZoom(msg_queue, frame_observers);
@@ -356,7 +356,7 @@
 
   const double new_zoom_factor = 2.0;
   const double new_zoom_level =
-      default_zoom_level + ZoomFactorToZoomLevel(new_zoom_factor);
+      default_zoom_level + blink::PageZoomFactorToZoomLevel(new_zoom_factor);
 
   // This should not cause the nested iframe to change its zoom.
   host_zoom_map->SetZoomLevelForHost("b.com", new_zoom_level);
@@ -415,7 +415,8 @@
                                  scale_one_grandchild_width, kTolerance);
 
     const double new_default_zoom_level =
-        default_zoom_level + ZoomFactorToZoomLevel(new_default_zoom_factor);
+        default_zoom_level +
+        blink::PageZoomFactorToZoomLevel(new_default_zoom_factor);
 
     host_zoom_map->SetZoomLevelForHost("b.com", new_default_zoom_level + 1.0);
     host_zoom_map->SetDefaultZoomLevel(new_default_zoom_level);
@@ -470,7 +471,7 @@
                                  scale_one_child2_width, kTolerance);
 
     const double new_zoom_level =
-        default_zoom_level + ZoomFactorToZoomLevel(new_zoom_factor);
+        default_zoom_level + blink::PageZoomFactorToZoomLevel(new_zoom_factor);
     host_zoom_map->SetZoomLevelForHost(top_level_host, new_zoom_level);
 
     WaitAndCheckFrameZoom(msg_queue, frame_observers);
@@ -519,7 +520,7 @@
                                  scale_one_child_width, kTolerance);
 
     const double new_zoom_level =
-        default_zoom_level + ZoomFactorToZoomLevel(new_zoom_factor);
+        default_zoom_level + blink::PageZoomFactorToZoomLevel(new_zoom_factor);
     host_zoom_map->SetZoomLevelForHost(top_level_host, new_zoom_level);
 
     WaitAndCheckFrameZoom(msg_queue, frame_observers);
@@ -562,7 +563,8 @@
   const double kZoomFactorForRedirectedHost = 1.5;
   HostZoomMap* host_zoom_map = HostZoomMap::GetForWebContents(web_contents());
   host_zoom_map->SetZoomLevelForHost(
-      redirected_host, ZoomFactorToZoomLevel(kZoomFactorForRedirectedHost));
+      redirected_host,
+      blink::PageZoomFactorToZoomLevel(kZoomFactorForRedirectedHost));
 
   // Navigation to a.com doesn't change the zoom level, but when it redirects
   // to b.com, and then a subframe loads, the zoom should change.
@@ -607,7 +609,7 @@
   // Set a zoom for a host that will be navigated to below.
   const double new_zoom_factor = 2.0;
   const double new_zoom_level =
-      default_zoom_level + ZoomFactorToZoomLevel(new_zoom_factor);
+      default_zoom_level + blink::PageZoomFactorToZoomLevel(new_zoom_factor);
   host_zoom_map->SetZoomLevelForHost("foo.com", new_zoom_level);
 
   // Navigate forward in the same RFH to a site with that host via a
diff --git a/content/common/BUILD.gn b/content/common/BUILD.gn
index a3beecf..2d73082 100644
--- a/content/common/BUILD.gn
+++ b/content/common/BUILD.gn
@@ -195,7 +195,6 @@
     "page_messages.h",
     "page_state_serialization.cc",
     "page_state_serialization.h",
-    "page_zoom.cc",
     "pepper_file_util.cc",
     "pepper_file_util.h",
     "pepper_plugin_list.cc",
diff --git a/content/common/page_zoom.cc b/content/common/page_zoom.cc
deleted file mode 100644
index 2b7c7a06..0000000
--- a/content/common/page_zoom.cc
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <cmath>
-
-#include "content/public/common/page_zoom.h"
-
-namespace content {
-
-// Mirrored in third_party/blink/renderer/core/exported/web_view_impl.cc.
-const double kMinimumZoomFactor = 0.25;
-const double kMaximumZoomFactor = 5.0;
-
-const double kEpsilon = 0.001;
-const double kTextSizeMultiplierRatio = 1.2;
-
-bool ZoomValuesEqual(double value_a, double value_b) {
-  return (std::fabs(value_a - value_b) <= kEpsilon);
-}
-
-double ZoomLevelToZoomFactor(double zoom_level) {
-  return std::pow(kTextSizeMultiplierRatio, zoom_level);
-}
-
-double ZoomFactorToZoomLevel(double factor) {
-  return std::log(factor) / std::log(kTextSizeMultiplierRatio);
-}
-
-}  // namespace content
diff --git a/content/common/page_zoom_unittest.cc b/content/common/page_zoom_unittest.cc
deleted file mode 100644
index 67dd5d56..0000000
--- a/content/common/page_zoom_unittest.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "content/public/common/page_zoom.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-TEST(PageZoomTest, ZoomValuesEqual) {
-  // Test two identical values.
-  EXPECT_TRUE(content::ZoomValuesEqual(1.5, 1.5));
-
-  // Test two values that are close enough to be considered equal.
-  EXPECT_TRUE(content::ZoomValuesEqual(1.5, 1.49999999));
-
-  // Test two values that are close, but should not be considered equal.
-  EXPECT_FALSE(content::ZoomValuesEqual(1.5, 1.4));
-}
-
diff --git a/content/public/common/page_zoom.h b/content/public/common/page_zoom.h
index aa5e56a..49e0810 100644
--- a/content/public/common/page_zoom.h
+++ b/content/public/common/page_zoom.h
@@ -5,8 +5,6 @@
 #ifndef CONTENT_PUBLIC_COMMON_PAGE_ZOOM_H_
 #define CONTENT_PUBLIC_COMMON_PAGE_ZOOM_H_
 
-#include "content/common/content_export.h"
-
 namespace content {
 
 // This enum is the parameter to various text/page zoom commands so we know
@@ -17,28 +15,6 @@
   PAGE_ZOOM_IN    = 1,
 };
 
-// The minimum zoom factor permitted for a page. This is an alternative to
-// WebView::minTextSizeMultiplier.
-CONTENT_EXPORT extern const double kMinimumZoomFactor;
-
-// The maximum zoom factor permitted for a page. This is an alternative to
-// WebView::maxTextSizeMultiplier.
-CONTENT_EXPORT extern const double kMaximumZoomFactor;
-
-// Epsilon value for comparing two floating-point zoom values. We don't use
-// std::numeric_limits<> because it is too precise for zoom values. Zoom
-// values lose precision due to factor/level conversions. A value of 0.001
-// is precise enough for zoom value comparisons.
-CONTENT_EXPORT extern const double kEpsilon;
-
-// Test if two zoom values (either zoom factors or zoom levels) should be
-// considered equal.
-CONTENT_EXPORT bool ZoomValuesEqual(double value_a, double value_b);
-
-// Converts between zoom factors and levels.
-CONTENT_EXPORT double ZoomLevelToZoomFactor(double zoom_level);
-CONTENT_EXPORT double ZoomFactorToZoomLevel(double factor);
-
 }  // namespace content
 
 #endif  // CONTENT_PUBLIC_COMMON_PAGE_ZOOM_H_
diff --git a/content/renderer/render_view_browsertest.cc b/content/renderer/render_view_browsertest.cc
index 59f1152..5437184 100644
--- a/content/renderer/render_view_browsertest.cc
+++ b/content/renderer/render_view_browsertest.cc
@@ -37,7 +37,6 @@
 #include "content/public/browser/web_ui_controller_factory.h"
 #include "content/public/common/bindings_policy.h"
 #include "content/public/common/content_switches.h"
-#include "content/public/common/page_zoom.h"
 #include "content/public/common/url_constants.h"
 #include "content/public/common/url_utils.h"
 #include "content/public/common/use_zoom_for_dsf_policy.h"
@@ -70,6 +69,7 @@
 #include "third_party/blink/public/common/dom_storage/session_storage_namespace_id.h"
 #include "third_party/blink/public/common/origin_trials/origin_trial_policy.h"
 #include "third_party/blink/public/common/origin_trials/trial_token_validator.h"
+#include "third_party/blink/public/common/page/page_zoom.h"
 #include "third_party/blink/public/mojom/loader/request_context_frame_type.mojom.h"
 #include "third_party/blink/public/platform/modules/service_worker/web_service_worker_network_provider.h"
 #include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
@@ -2398,7 +2398,7 @@
   gfx::Size size = GetPreferredSize();
   EXPECT_EQ(gfx::Size(400 + scrollbar_width, 400), size);
 
-  EXPECT_TRUE(view()->SetZoomLevel(ZoomFactorToZoomLevel(2.0)));
+  EXPECT_TRUE(view()->SetZoomLevel(blink::PageZoomFactorToZoomLevel(2.0)));
   size = GetPreferredSize();
   EXPECT_EQ(gfx::Size(800 + scrollbar_width, 800), size);
 }
@@ -2784,7 +2784,7 @@
   EXPECT_FALSE(view()->SetZoomLevel(0));
 
   // Change the zoom level to 25% and check if the view gets the change.
-  EXPECT_TRUE(view()->SetZoomLevel(content::ZoomFactorToZoomLevel(0.25)));
+  EXPECT_TRUE(view()->SetZoomLevel(blink::PageZoomFactorToZoomLevel(0.25)));
 }
 
 #endif
diff --git a/content/test/BUILD.gn b/content/test/BUILD.gn
index 58862874..4f1be9a 100644
--- a/content/test/BUILD.gn
+++ b/content/test/BUILD.gn
@@ -1896,7 +1896,6 @@
     "../common/mime_sniffing_throttle_unittest.cc",
     "../common/origin_util_unittest.cc",
     "../common/page_state_serialization_unittest.cc",
-    "../common/page_zoom_unittest.cc",
     "../common/service_manager/service_manager_connection_impl_unittest.cc",
     "../common/service_worker/service_worker_utils_unittest.cc",
     "../common/tab_switch_time_recorder_unittest.cc",