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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" 5 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/prefs/overlay_user_pref_store.h" 9 #include "base/prefs/overlay_user_pref_store.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/renderer_preferences_util.h" 17 #include "chrome/browser/renderer_preferences_util.h"
18 #include "chrome/common/pref_font_webkit_names.h" 18 #include "chrome/common/pref_font_webkit_names.h"
19 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
20 #include "chrome/common/pref_names_util.h" 20 #include "chrome/common/pref_names_util.h"
21 #include "chrome/grit/locale_settings.h" 21 #include "chrome/grit/locale_settings.h"
22 #include "components/pref_registry/pref_registry_syncable.h" 22 #include "components/pref_registry/pref_registry_syncable.h"
23 #include "content/public/browser/host_zoom_map.h"
23 #include "content/public/browser/notification_details.h" 24 #include "content/public/browser/notification_details.h"
24 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/render_view_host.h" 26 #include "content/public/browser/render_view_host.h"
26 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "content/public/common/renderer_preferences.h"
27 #include "content/public/common/web_preferences.h" 29 #include "content/public/common/web_preferences.h"
28 #include "grit/platform_locale_settings.h" 30 #include "grit/platform_locale_settings.h"
29 #include "third_party/icu/source/common/unicode/uchar.h" 31 #include "third_party/icu/source/common/unicode/uchar.h"
30 #include "third_party/icu/source/common/unicode/uscript.h" 32 #include "third_party/icu/source/common/unicode/uscript.h"
31 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
32 34
33 #if defined(OS_POSIX) && !defined(OS_MACOSX) && defined(ENABLE_THEMES) 35 #if defined(OS_POSIX) && !defined(OS_MACOSX) && defined(ENABLE_THEMES)
34 #include "chrome/browser/themes/theme_service.h" 36 #include "chrome/browser/themes/theme_service.h"
35 #include "chrome/browser/themes/theme_service_factory.h" 37 #include "chrome/browser/themes/theme_service_factory.h"
36 #endif 38 #endif
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 else 310 else
309 NOTREACHED() << "Unknown generic font family: " << generic_family; 311 NOTREACHED() << "Unknown generic font family: " << generic_family;
310 (*map)[script] = base::UTF8ToUTF16(pref_value); 312 (*map)[script] = base::UTF8ToUTF16(pref_value);
311 } 313 }
312 314
313 } // namespace 315 } // namespace
314 316
315 PrefsTabHelper::PrefsTabHelper(WebContents* contents) 317 PrefsTabHelper::PrefsTabHelper(WebContents* contents)
316 : web_contents_(contents), 318 : web_contents_(contents),
317 weak_ptr_factory_(this) { 319 weak_ptr_factory_(this) {
320 // TODO(wjmaclean): Convert this to use the content-specific zoom-level
321 // prefs when HostZoomMap moves to StoragePartition.
322 PrefService* zoom_level_prefs = GetProfile()->GetZoomLevelPrefs();
323 if (zoom_level_prefs) {
324 zoom_level_pref_change_registrar_.Init(zoom_level_prefs);
325 base::Closure renderer_callback = base::Bind(
326 &PrefsTabHelper::UpdateRendererPreferences, base::Unretained(this));
327 zoom_level_pref_change_registrar_.Add(prefs::kDefaultZoomLevel,
328 renderer_callback);
329 if (zoom_level_prefs->GetInitializationStatus() ==
330 PrefService::INITIALIZATION_STATUS_WAITING) {
331 // Unlike per-profile prefs, which are guaranteed to have initialized by
332 // the time we get here, zoom-level prefs may not have
333 // completed their initialization. In this case, we need to re-sync the
334 // renderer prefs once their initialization completes so that the default
335 // zoom level information is updated.
336 // TODO(wjmaclean) We need to determine if there are possible lifetime
337 // issues here, namely, can 'this' disappear before the zoom_level_prefs
338 // have finished initializing, causing a stale pointer via the callback?
339 zoom_level_prefs->AddPrefInitObserver(
340 base::Bind(&PrefsTabHelper::UpdateAfterZoomLevelPrefsInitialized,
341 base::Unretained(this)));
342 }
343 }
344
318 PrefService* prefs = GetProfile()->GetPrefs(); 345 PrefService* prefs = GetProfile()->GetPrefs();
319 pref_change_registrar_.Init(prefs); 346 pref_change_registrar_.Init(prefs);
320 if (prefs) { 347 if (prefs) {
321 base::Closure renderer_callback = base::Bind( 348 base::Closure renderer_callback = base::Bind(
322 &PrefsTabHelper::UpdateRendererPreferences, base::Unretained(this)); 349 &PrefsTabHelper::UpdateRendererPreferences, base::Unretained(this));
323 pref_change_registrar_.Add(prefs::kAcceptLanguages, renderer_callback); 350 pref_change_registrar_.Add(prefs::kAcceptLanguages, renderer_callback);
324 pref_change_registrar_.Add(prefs::kDefaultZoomLevel, renderer_callback);
325 pref_change_registrar_.Add(prefs::kEnableDoNotTrack, renderer_callback); 351 pref_change_registrar_.Add(prefs::kEnableDoNotTrack, renderer_callback);
326 pref_change_registrar_.Add(prefs::kEnableReferrers, renderer_callback); 352 pref_change_registrar_.Add(prefs::kEnableReferrers, renderer_callback);
327 353
328 #if !defined(OS_MACOSX) 354 #if !defined(OS_MACOSX)
329 pref_change_registrar_.Add(prefs::kFullscreenAllowed, renderer_callback); 355 pref_change_registrar_.Add(prefs::kFullscreenAllowed, renderer_callback);
330 #endif 356 #endif
331 357
332 PrefChangeRegistrar::NamedChangeCallback webkit_callback = base::Bind( 358 PrefChangeRegistrar::NamedChangeCallback webkit_callback = base::Bind(
333 &PrefsTabHelper::OnWebPrefChanged, base::Unretained(this)); 359 &PrefsTabHelper::OnWebPrefChanged, base::Unretained(this));
334 for (int i = 0; i < kPrefsToObserveLength; ++i) { 360 for (int i = 0; i < kPrefsToObserveLength; ++i) {
(...skipping 17 matching lines...) Expand all
352 prefs::kWebKitCursiveFontFamilyMap, 378 prefs::kWebKitCursiveFontFamilyMap,
353 webkit_callback); 379 webkit_callback);
354 RegisterFontFamilyMapObserver(&pref_change_registrar_, 380 RegisterFontFamilyMapObserver(&pref_change_registrar_,
355 prefs::kWebKitFantasyFontFamilyMap, 381 prefs::kWebKitFantasyFontFamilyMap,
356 webkit_callback); 382 webkit_callback);
357 RegisterFontFamilyMapObserver(&pref_change_registrar_, 383 RegisterFontFamilyMapObserver(&pref_change_registrar_,
358 prefs::kWebKitPictographFontFamilyMap, 384 prefs::kWebKitPictographFontFamilyMap,
359 webkit_callback); 385 webkit_callback);
360 } 386 }
361 387
362 renderer_preferences_util::UpdateFromSystemSettings( 388 content::RendererPreferences* render_prefs =
363 web_contents_->GetMutableRendererPrefs(), GetProfile()); 389 web_contents_->GetMutableRendererPrefs();
390 renderer_preferences_util::UpdateFromSystemSettings(render_prefs,
391 GetProfile());
392 // TODO(wjmaclean): Convert this to use the HostZoomMap for the WebContents
393 // when HostZoomMap moves to StoragePartition.
394 render_prefs->default_zoom_level =
395 content::HostZoomMap::GetDefaultForBrowserContext(GetProfile())
396 ->GetDefaultZoomLevel();
364 397
365 #if defined(OS_POSIX) && !defined(OS_MACOSX) && defined(ENABLE_THEMES) 398 #if defined(OS_POSIX) && !defined(OS_MACOSX) && defined(ENABLE_THEMES)
366 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 399 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
367 content::Source<ThemeService>( 400 content::Source<ThemeService>(
368 ThemeServiceFactory::GetForProfile(GetProfile()))); 401 ThemeServiceFactory::GetForProfile(GetProfile())));
369 #endif 402 #endif
370 #if defined(USE_AURA) 403 #if defined(USE_AURA)
371 registrar_.Add(this, 404 registrar_.Add(this,
372 chrome::NOTIFICATION_BROWSER_FLING_CURVE_PARAMETERS_CHANGED, 405 chrome::NOTIFICATION_BROWSER_FLING_CURVE_PARAMETERS_CHANGED,
373 content::NotificationService::AllSources()); 406 content::NotificationService::AllSources());
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 #endif // defined(USE_AURA) 592 #endif // defined(USE_AURA)
560 593
561 NOTREACHED(); 594 NOTREACHED();
562 } 595 }
563 596
564 void PrefsTabHelper::UpdateWebPreferences() { 597 void PrefsTabHelper::UpdateWebPreferences() {
565 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences( 598 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(
566 web_contents_->GetRenderViewHost()->GetWebkitPreferences()); 599 web_contents_->GetRenderViewHost()->GetWebkitPreferences());
567 } 600 }
568 601
602 void PrefsTabHelper::UpdateAfterZoomLevelPrefsInitialized(bool success) {
603 if (success)
604 UpdateRendererPreferences();
605 }
606
569 void PrefsTabHelper::UpdateRendererPreferences() { 607 void PrefsTabHelper::UpdateRendererPreferences() {
570 renderer_preferences_util::UpdateFromSystemSettings( 608 content::RendererPreferences* prefs =
571 web_contents_->GetMutableRendererPrefs(), GetProfile()); 609 web_contents_->GetMutableRendererPrefs();
610 renderer_preferences_util::UpdateFromSystemSettings(prefs, GetProfile());
611 // TODO(wjmaclean): Convert this to use the HostZoomMap for the WebContents
612 // when HostZoomMap moves to StoragePartition.
613 prefs->default_zoom_level = content::HostZoomMap::GetDefaultForBrowserContext(
614 GetProfile())->GetDefaultZoomLevel();
572 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); 615 web_contents_->GetRenderViewHost()->SyncRendererPrefs();
573 } 616 }
574 617
575 Profile* PrefsTabHelper::GetProfile() { 618 Profile* PrefsTabHelper::GetProfile() {
576 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 619 return Profile::FromBrowserContext(web_contents_->GetBrowserContext());
577 } 620 }
578 621
579 void PrefsTabHelper::OnFontFamilyPrefChanged(const std::string& pref_name) { 622 void PrefsTabHelper::OnFontFamilyPrefChanged(const std::string& pref_name) {
580 // When a font family pref's value goes from non-empty to the empty string, we 623 // When a font family pref's value goes from non-empty to the empty string, we
581 // must add it to the usual WebPreferences struct passed to the renderer. 624 // must add it to the usual WebPreferences struct passed to the renderer.
(...skipping 24 matching lines...) Expand all
606 } 649 }
607 } 650 }
608 651
609 void PrefsTabHelper::OnWebPrefChanged(const std::string& pref_name) { 652 void PrefsTabHelper::OnWebPrefChanged(const std::string& pref_name) {
610 #if !defined(OS_ANDROID) 653 #if !defined(OS_ANDROID)
611 OnFontFamilyPrefChanged(pref_name); 654 OnFontFamilyPrefChanged(pref_name);
612 #endif 655 #endif
613 656
614 web_contents_->GetRenderViewHost()->OnWebkitPreferencesChanged(); 657 web_contents_->GetRenderViewHost()->OnWebkitPreferencesChanged();
615 } 658 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698