Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1166)

Unified Diff: chrome/browser/ui/prefs/prefs_tab_helper.cc

Issue 541103002: Introduce ChromeZoomLevelPref, make zoom level prefs independent of profile prefs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments (use WeakPtr in callback). Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/prefs/prefs_tab_helper.cc
diff --git a/chrome/browser/ui/prefs/prefs_tab_helper.cc b/chrome/browser/ui/prefs/prefs_tab_helper.cc
index 816e08b60f60092d0f97371f9dc9d6261dbc86bb..df0c6ad94b8064406368af25ad2c53171d6dab69 100644
--- a/chrome/browser/ui/prefs/prefs_tab_helper.cc
+++ b/chrome/browser/ui/prefs/prefs_tab_helper.cc
@@ -15,15 +15,18 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_preferences_util.h"
+#include "chrome/browser/ui/zoom/zoom_controller.h"
#include "chrome/common/pref_font_webkit_names.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_names_util.h"
#include "chrome/grit/locale_settings.h"
#include "components/pref_registry/pref_registry_syncable.h"
+#include "content/public/browser/host_zoom_map.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/common/renderer_preferences.h"
#include "content/public/common/web_preferences.h"
#include "grit/platform_locale_settings.h"
#include "third_party/icu/source/common/unicode/uchar.h"
@@ -310,18 +313,50 @@ void OverrideFontFamily(WebPreferences* prefs,
(*map)[script] = base::UTF8ToUTF16(pref_value);
}
+double GetDefaultZoomLevel(const content::WebContents* web_contents) {
+ const ZoomController* zoom_controller =
+ ZoomController::FromWebContents(web_contents);
+ if (zoom_controller)
+ return zoom_controller->GetDefaultZoomLevel();
+ return content::HostZoomMap::GetDefaultForBrowserContext(
+ web_contents->GetBrowserContext())->GetDefaultZoomLevel();
+}
+
} // namespace
PrefsTabHelper::PrefsTabHelper(WebContents* contents)
: web_contents_(contents),
weak_ptr_factory_(this) {
+ // TODO(wjmaclean): Convert this to use the content-specific zoom-level
+ // prefs when HostZoomMap moves to StoragePartition.
+ PrefService* zoom_level_prefs = GetProfile()->GetZoomLevelPrefs();
+ if (zoom_level_prefs) {
+ zoom_level_pref_change_registrar_.Init(zoom_level_prefs);
+ base::Closure renderer_callback = base::Bind(
+ &PrefsTabHelper::UpdateRendererPreferences, base::Unretained(this));
+ zoom_level_pref_change_registrar_.Add(prefs::kDefaultZoomLevel,
+ renderer_callback);
+ if (zoom_level_prefs->GetInitializationStatus() ==
+ PrefService::INITIALIZATION_STATUS_WAITING) {
+ // Unlike per-profile prefs, which are guaranteed to have initialized by
+ // the time we get here, zoom-level prefs may not have
+ // completed their initialization. In this case, we need to re-sync the
+ // renderer prefs once their initialization completes so that the default
+ // zoom level information is updated.
+ // We bind to a WeakPtr in case 'this' disappears before the pref store
+ // calls the observer, e.g. shutting down Chrome during startup?
+ zoom_level_prefs->AddPrefInitObserver(
+ base::Bind(&PrefsTabHelper::UpdateAfterZoomLevelPrefsInitialized,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
+ }
+
PrefService* prefs = GetProfile()->GetPrefs();
pref_change_registrar_.Init(prefs);
if (prefs) {
base::Closure renderer_callback = base::Bind(
&PrefsTabHelper::UpdateRendererPreferences, base::Unretained(this));
pref_change_registrar_.Add(prefs::kAcceptLanguages, renderer_callback);
- pref_change_registrar_.Add(prefs::kDefaultZoomLevel, renderer_callback);
pref_change_registrar_.Add(prefs::kEnableDoNotTrack, renderer_callback);
pref_change_registrar_.Add(prefs::kEnableReferrers, renderer_callback);
@@ -359,13 +394,18 @@ PrefsTabHelper::PrefsTabHelper(WebContents* contents)
webkit_callback);
}
- renderer_preferences_util::UpdateFromSystemSettings(
- web_contents_->GetMutableRendererPrefs(), GetProfile());
+ content::RendererPreferences* render_prefs =
+ web_contents_->GetMutableRendererPrefs();
+ renderer_preferences_util::UpdateFromSystemSettings(render_prefs,
+ GetProfile());
+ render_prefs->default_zoom_level = GetDefaultZoomLevel(web_contents_);
#if defined(OS_POSIX) && !defined(OS_MACOSX) && defined(ENABLE_THEMES)
- registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
- content::Source<ThemeService>(
- ThemeServiceFactory::GetForProfile(GetProfile())));
+ registrar_.Add(
+ this,
+ chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
+ content::Source<ThemeService>(
+ ThemeServiceFactory::GetForProfile(GetProfile())));
#endif
#if defined(USE_AURA)
registrar_.Add(this,
@@ -566,9 +606,16 @@ void PrefsTabHelper::UpdateWebPreferences() {
web_contents_->GetRenderViewHost()->GetWebkitPreferences());
}
+void PrefsTabHelper::UpdateAfterZoomLevelPrefsInitialized(bool success) {
+ if (success)
+ UpdateRendererPreferences();
+}
+
void PrefsTabHelper::UpdateRendererPreferences() {
- renderer_preferences_util::UpdateFromSystemSettings(
- web_contents_->GetMutableRendererPrefs(), GetProfile());
+ content::RendererPreferences* prefs =
+ web_contents_->GetMutableRendererPrefs();
+ renderer_preferences_util::UpdateFromSystemSettings(prefs, GetProfile());
+ prefs->default_zoom_level = GetDefaultZoomLevel(web_contents_);
web_contents_->GetRenderViewHost()->SyncRendererPrefs();
}

Powered by Google App Engine
This is Rietveld 408576698