Skip to content

Commit

Permalink
[Page Zoom] Add page zoom behind experimental UI on Android
Browse files Browse the repository at this point in the history
This CL continues the accessibility Page Zoom work behind a feature
flag.

Here we add the main functionality for page zoom and connect it with
the mock UI on Android. When the feature flags are enabled, the old
treatment of accessibility font scale factor will be disabled, and the
page zoom functionality will be leveraged instead. This uses the
existing zoom component and host zoom maps used on non-mobile
platforms. We add a simple singleton controller on the Java-side code
and connect it through JNI to the zoom component. The final resting
place for this UI is not yet decided, so the specifics of the
implementation can still change.

AX-Relnotes: N/A (Behind a flag)
Bug: 1232536, 645717
Change-Id: I1acc6dadcf1c70da44e1701f5e428e0fba92ce1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3166992
Reviewed-by: Bettina Dea <bdea@chromium.org>
Reviewed-by: Ehimare Okoyomon <eokoyomon@chromium.org>
Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
Reviewed-by: Theresa  <twellington@chromium.org>
Reviewed-by: Philip Rogers <pdr@chromium.org>
Reviewed-by: Sean Topping <seantopping@chromium.org>
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: David Roger <droger@chromium.org>
Reviewed-by: W. James MacLean <wjmaclean@chromium.org>
Commit-Queue: Mark Schillaci <mschillaci@google.com>
Cr-Commit-Position: refs/heads/main@{#927772}
  • Loading branch information
mschillaci authored and Chromium LUCI CQ committed Oct 4, 2021
1 parent 7cf5d48 commit 1363e4a
Show file tree
Hide file tree
Showing 47 changed files with 296 additions and 186 deletions.
7 changes: 7 additions & 0 deletions android_webview/browser/aw_browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "content/public/browser/ssl_host_state_delegate.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/zoom_level_delegate.h"
#include "media/mojo/buildflags.h"
#include "net/proxy_resolution/proxy_config_service_android.h"
#include "net/proxy_resolution/proxy_resolution_service.h"
Expand Down Expand Up @@ -454,6 +455,12 @@ AwBrowserContext::RetriveInProgressDownloadManager() {
/*wake_lock_provider_binder*/ base::NullCallback());
}

std::unique_ptr<content::ZoomLevelDelegate>
AwBrowserContext::CreateZoomLevelDelegate(
const base::FilePath& partition_path) {
return nullptr;
}

void AwBrowserContext::RebuildTable(
const scoped_refptr<URLEnumerator>& enumerator) {
// Android WebView rebuilds from WebChromeClient.getVisitedHistory. The client
Expand Down
3 changes: 3 additions & 0 deletions android_webview/browser/aw_browser_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "components/prefs/pref_registry_simple.h"
#include "components/visitedlink/browser/visitedlink_delegate.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/zoom_level_delegate.h"
#include "services/cert_verifier/public/mojom/cert_verifier_service_factory.mojom-forward.h"

class GURL;
Expand Down Expand Up @@ -111,6 +112,8 @@ class AwBrowserContext : public content::BrowserContext,
override;
download::InProgressDownloadManager* RetriveInProgressDownloadManager()
override;
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
const base::FilePath& partition_path) override;

// visitedlink::VisitedLinkDelegate implementation.
void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2292,6 +2292,7 @@ static_library("browser") {
"//components/webrtc",
"//components/webrtc_logging/browser",
"//components/webrtc_logging/common",
"//components/zoom",
"//content/app/resources",
"//content/public/browser",
"//content/public/common",
Expand Down Expand Up @@ -4414,7 +4415,6 @@ static_library("browser") {
"//components/soda:constants",
"//components/ukm/content",
"//components/web_modal",
"//components/zoom",
"//courgette:courgette_lib",
"//services/device/public/cpp/hid",
"//third_party/sqlite",
Expand Down
17 changes: 3 additions & 14 deletions chrome/browser/profiles/off_the_record_profile_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/transition_manager/full_browser_transition_manager.h"
#include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
#include "chrome/browser/ui/zoom/chrome_zoom_level_otr_delegate.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
Expand All @@ -65,8 +66,10 @@
#include "components/security_interstitials/content/stateful_ssl_host_state_delegate.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "components/user_prefs/user_prefs.h"
#include "components/zoom/zoom_event_manager.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/host_zoom_map.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/url_data_source.h"
Expand All @@ -80,10 +83,6 @@

#if defined(OS_ANDROID)
#include "components/prefs/scoped_user_pref_update.h"
#else // !defined(OS_ANDROID)
#include "chrome/browser/ui/zoom/chrome_zoom_level_otr_delegate.h"
#include "components/zoom/zoom_event_manager.h"
#include "content/public/browser/host_zoom_map.h"
#endif // defined(OS_ANDROID)

#if BUILDFLAG(IS_CHROMEOS_ASH)
Expand Down Expand Up @@ -114,9 +113,7 @@

using content::BrowserThread;
using content::DownloadManagerDelegate;
#if !defined(OS_ANDROID)
using content::HostZoomMap;
#endif

namespace {

Expand Down Expand Up @@ -182,9 +179,7 @@ void OffTheRecordProfileImpl::Init() {
IncognitoModePrefs::GetAvailability(profile_->GetPrefs()) !=
IncognitoModePrefs::Availability::kDisabled);

#if !defined(OS_ANDROID)
TrackZoomLevelsFromParent();
#endif

#if BUILDFLAG(ENABLE_PLUGINS)
ChromePluginServiceFilter::GetInstance()->RegisterProfile(this);
Expand Down Expand Up @@ -264,7 +259,6 @@ OffTheRecordProfileImpl::~OffTheRecordProfileImpl() {
}
}

#if !defined(OS_ANDROID)
void OffTheRecordProfileImpl::TrackZoomLevelsFromParent() {
// Here we only want to use zoom levels stored in the main-context's default
// storage partition. We're not interested in zoom levels in special
Expand All @@ -287,7 +281,6 @@ void OffTheRecordProfileImpl::TrackZoomLevelsFromParent() {
base::BindRepeating(&OffTheRecordProfileImpl::UpdateDefaultZoomLevel,
base::Unretained(this)));
}
#endif // !defined(OS_ANDROID)

std::string OffTheRecordProfileImpl::GetProfileUserName() const {
// Incognito profile should not return the username.
Expand All @@ -306,14 +299,12 @@ base::Time OffTheRecordProfileImpl::GetCreationTime() const {
return start_time_;
}

#if !defined(OS_ANDROID)
std::unique_ptr<content::ZoomLevelDelegate>
OffTheRecordProfileImpl::CreateZoomLevelDelegate(
const base::FilePath& partition_path) {
return std::make_unique<ChromeZoomLevelOTRDelegate>(
zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr());
}
#endif // !defined(OS_ANDROID)

scoped_refptr<base::SequencedTaskRunner>
OffTheRecordProfileImpl::GetIOTaskRunner() {
Expand Down Expand Up @@ -644,7 +635,6 @@ bool OffTheRecordProfileImpl::IsSignedIn() {
return false;
}

#if !defined(OS_ANDROID)
void OffTheRecordProfileImpl::OnParentZoomLevelChanged(
const HostZoomMap::ZoomLevelChange& change) {
HostZoomMap* host_zoom_map = HostZoomMap::GetDefaultForBrowserContext(this);
Expand Down Expand Up @@ -674,7 +664,6 @@ void OffTheRecordProfileImpl::UpdateDefaultZoomLevel() {
zoom::ZoomEventManager::GetForBrowserContext(this)
->OnDefaultZoomLevelChanged();
}
#endif // !defined(OS_ANDROID)

void OffTheRecordProfileImpl::RecordPrimaryMainFrameNavigation() {
main_frame_navigations_++;
Expand Down
13 changes: 1 addition & 12 deletions chrome/browser/profiles/off_the_record_profile_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
#include "build/chromeos_buildflags.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/scoped_profile_keep_alive.h"
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
#include "components/domain_reliability/clear_mode.h"
#include "content/public/browser/content_browser_client.h"

#if !defined(OS_ANDROID)
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
#include "content/public/browser/host_zoom_map.h"
#endif

namespace sync_preferences {
class PrefServiceSyncable;
Expand Down Expand Up @@ -97,10 +94,8 @@ class OffTheRecordProfileImpl : public Profile {
base::FilePath GetPath() override;
base::FilePath GetPath() const override;
base::Time GetCreationTime() const override;
#if !defined(OS_ANDROID)
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
const base::FilePath& partition_path) override;
#endif // !defined(OS_ANDROID)
scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() override;
bool IsOffTheRecord() override;
bool IsOffTheRecord() const override;
Expand Down Expand Up @@ -135,17 +130,13 @@ class OffTheRecordProfileImpl : public Profile {
bool IsSignedIn() override;

private:
#if !defined(OS_ANDROID)
// Allows a profile to track changes in zoom levels in its parent profile.
void TrackZoomLevelsFromParent();
#endif // !defined(OS_ANDROID)

#if !defined(OS_ANDROID)
// Callback function for tracking parent's zoom level changes.
void OnParentZoomLevelChanged(
const content::HostZoomMap::ZoomLevelChange& change);
void UpdateDefaultZoomLevel();
#endif // !defined(OS_ANDROID)

// The real underlying profile.
Profile* profile_;
Expand All @@ -156,10 +147,8 @@ class OffTheRecordProfileImpl : public Profile {

std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs_;

#if !defined(OS_ANDROID)
base::CallbackListSubscription track_zoom_subscription_;
base::CallbackListSubscription parent_default_zoom_level_subscription_;
#endif // !defined(OS_ANDROID)

// Time we were started.
base::Time start_time_;
Expand Down
11 changes: 1 addition & 10 deletions chrome/browser/profiles/profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "components/variations/variations_ids_provider.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/host_zoom_map.h"
#include "content/public/browser/resource_context.h"
#include "content/public/browser/shared_cors_origin_access_list.h"
#include "content/public/browser/storage_partition.h"
Expand All @@ -51,10 +52,6 @@
#include "chrome/browser/profiles/android/jni_headers/OTRProfileID_jni.h"
#endif

#if !defined(OS_ANDROID)
#include "content/public/browser/host_zoom_map.h"
#endif

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/browser/extension_pref_store.h"
#include "extensions/browser/extension_pref_value_map_factory.h"
Expand Down Expand Up @@ -265,11 +262,9 @@ TestingProfile* Profile::AsTestingProfile() {
return nullptr;
}

#if !defined(OS_ANDROID)
ChromeZoomLevelPrefs* Profile::GetZoomLevelPrefs() {
return nullptr;
}
#endif // !defined(OS_ANDROID)

Profile::Delegate::~Delegate() {
}
Expand Down Expand Up @@ -316,10 +311,8 @@ void Profile::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
std::string());
registry->RegisterStringPref(prefs::kAccessibilityCaptionsTextShadow,
std::string());
#if !defined(OS_ANDROID)
registry->RegisterDictionaryPref(prefs::kPartitionDefaultZoomLevel);
registry->RegisterDictionaryPref(prefs::kPartitionPerHostZoomLevels);
#endif // !defined(OS_ANDROID)
registry->RegisterStringPref(prefs::kPreinstalledApps, "install");
registry->RegisterBooleanPref(prefs::kSpeechRecognitionFilterProfanities,
true);
Expand Down Expand Up @@ -483,11 +476,9 @@ bool ProfileCompare::operator()(Profile* a, Profile* b) const {
return a->GetOriginalProfile() < b->GetOriginalProfile();
}

#if !defined(OS_ANDROID)
double Profile::GetDefaultZoomLevelForProfile() {
return GetDefaultStoragePartition()->GetHostZoomMap()->GetDefaultZoomLevel();
}
#endif // !defined(OS_ANDROID)

void Profile::Wipe() {
GetBrowsingDataRemover()->Remove(
Expand Down
7 changes: 0 additions & 7 deletions chrome/browser/profiles/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
#include "base/android/scoped_java_ref.h"
#endif

#if !defined(OS_ANDROID)
class ChromeZoomLevelPrefs;
#endif

class ExtensionSpecialStoragePolicy;
class GURL;
class PrefService;
Expand Down Expand Up @@ -320,12 +317,10 @@ class Profile : public content::BrowserContext {
virtual PrefService* GetPrefs() = 0;
virtual const PrefService* GetPrefs() const = 0;

#if !defined(OS_ANDROID)
// Retrieves a pointer to the PrefService that manages the default zoom
// level and the per-host zoom levels for this user profile.
// TODO(wjmaclean): Remove this when HostZoomMap migrates to StoragePartition.
virtual ChromeZoomLevelPrefs* GetZoomLevelPrefs();
#endif

// Gives a read-only view of prefs that can be used even if there's no OTR
// profile at the moment (i.e. HasOffTheRecordProfile is false).
Expand Down Expand Up @@ -501,11 +496,9 @@ class Profile : public content::BrowserContext {
// destroyed by ProfileDestroyer, but in tests, some are not.
void MaybeSendDestroyedNotification();

#if !defined(OS_ANDROID)
// Convenience method to retrieve the default zoom level for the default
// storage partition.
double GetDefaultZoomLevelForProfile();
#endif

// Wipes all data for this profile.
void Wipe();
Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/profiles/profile_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
#include "components/url_formatter/url_fixer.h"
#include "components/user_prefs/user_prefs.h"
#include "components/version_info/channel.h"
#include "components/zoom/zoom_event_manager.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/dom_storage_context.h"
Expand Down Expand Up @@ -208,7 +209,6 @@
#include "chrome/browser/android/profile_key_startup_accessor.h"
#else
#include "chrome/browser/first_run/first_run.h"
#include "components/zoom/zoom_event_manager.h"
#include "content/public/common/page_zoom.h"
#endif

Expand Down Expand Up @@ -961,14 +961,12 @@ std::string ProfileImpl::GetProfileUserName() const {
return std::string();
}

#if !defined(OS_ANDROID)
std::unique_ptr<content::ZoomLevelDelegate>
ProfileImpl::CreateZoomLevelDelegate(const base::FilePath& partition_path) {
return std::make_unique<ChromeZoomLevelPrefs>(
GetPrefs(), GetPath(), partition_path,
zoom::ZoomEventManager::GetForBrowserContext(this)->GetWeakPtr());
}
#endif // !defined(OS_ANDROID)

base::FilePath ProfileImpl::GetPath() {
return path_;
Expand Down Expand Up @@ -1241,12 +1239,10 @@ const PrefService* ProfileImpl::GetPrefs() const {
return prefs_.get();
}

#if !defined(OS_ANDROID)
ChromeZoomLevelPrefs* ProfileImpl::GetZoomLevelPrefs() {
return static_cast<ChromeZoomLevelPrefs*>(
GetDefaultStoragePartition()->GetZoomLevelDelegate());
}
#endif // !defined(OS_ANDROID)

// TODO(crbug.com/734484): Remove this function.
PrefService* ProfileImpl::GetReadOnlyOffTheRecordPrefs() {
Expand Down
11 changes: 2 additions & 9 deletions chrome/browser/profiles/profile_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
#include "chrome/common/buildflags.h"
#include "components/keyed_service/core/simple_factory_key.h"
#include "components/prefs/pref_change_registrar.h"
#include "content/public/browser/content_browser_client.h"
#include "extensions/buildflags/buildflags.h"

#if !defined(OS_ANDROID)
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
#include "content/public/browser/host_zoom_map.h"
#endif
#include "extensions/buildflags/buildflags.h"

class MediaDeviceIDSalt;
class PrefService;
Expand Down Expand Up @@ -77,10 +74,8 @@ class ProfileImpl : public Profile {
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);

// content::BrowserContext implementation:
#if !defined(OS_ANDROID)
std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate(
const base::FilePath& partition_path) override;
#endif
content::DownloadManagerDelegate* GetDownloadManagerDelegate() override;
content::BrowserPluginGuestManager* GetGuestManager() override;
storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
Expand Down Expand Up @@ -138,9 +133,7 @@ class ProfileImpl : public Profile {
ExtensionSpecialStoragePolicy* GetExtensionSpecialStoragePolicy() override;
PrefService* GetPrefs() override;
const PrefService* GetPrefs() const override;
#if !defined(OS_ANDROID)
ChromeZoomLevelPrefs* GetZoomLevelPrefs() override;
#endif
PrefService* GetReadOnlyOffTheRecordPrefs() override;
policy::SchemaRegistryService* GetPolicySchemaRegistryService() override;
#if BUILDFLAG(IS_CHROMEOS_ASH)
Expand Down
Loading

0 comments on commit 1363e4a

Please sign in to comment.