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

Side by Side Diff: chrome/browser/ui/prefs/prefs_tab_helper.cc

Issue 393133002: Migrate HostZoomMap to live in StoragePartition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to 291677. 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 | Annotate | Revision Log
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 "components/pref_registry/pref_registry_syncable.h" 21 #include "components/pref_registry/pref_registry_syncable.h"
22 #include "content/public/browser/notification_details.h" 22 #include "content/public/browser/notification_details.h"
23 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/render_process_host.h"
24 #include "content/public/browser/render_view_host.h" 25 #include "content/public/browser/render_view_host.h"
26 #include "content/public/browser/storage_partition.h"
25 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
26 #include "content/public/common/web_preferences.h" 28 #include "content/public/common/web_preferences.h"
27 #include "grit/locale_settings.h" 29 #include "grit/locale_settings.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"
(...skipping 273 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) Would it be better to plumb a helper function on
321 // RenderProcessHost to simplify this type of call?
322 PrefService* zoom_level_prefs = contents->GetRenderProcessHost()
323 ->GetStoragePartition()
324 ->GetZoomLevelPrefs();
325 if (zoom_level_prefs) {
326 zoom_level_pref_change_registrar_.Init(zoom_level_prefs);
327 base::Closure renderer_callback = base::Bind(
328 &PrefsTabHelper::UpdateRendererPreferences, base::Unretained(this));
329 zoom_level_pref_change_registrar_.Add(prefs::kDefaultZoomLevel,
330 renderer_callback);
331 if (zoom_level_prefs->GetInitializationStatus() ==
332 PrefService::INITIALIZATION_STATUS_WAITING) {
333 // Unlike per-profile prefs, which are guaranteed to have initialized by
334 // the time we get here, zoom-level prefs (per-partition) may not have
335 // completed their initialization. In this case, we need to re-sync the
336 // renderer prefs once their initialization completes so that the default
337 // zoom level information is updated.
338 // TODO(wjmaclean) We need to determine if there are possible lifetime
339 // issues here, namely, can 'this' disappear before the zoom_level_prefs
340 // have finished initializing, causing a stale pointer via the callback?
341 zoom_level_prefs->AddPrefInitObserver(
342 base::Bind(&PrefsTabHelper::UpdateAfterZoomLevelPrefsInitialized,
343 base::Unretained(this)));
344 }
345 }
346
318 PrefService* prefs = GetProfile()->GetPrefs(); 347 PrefService* prefs = GetProfile()->GetPrefs();
319 pref_change_registrar_.Init(prefs); 348 pref_change_registrar_.Init(prefs);
320 if (prefs) { 349 if (prefs) {
321 base::Closure renderer_callback = base::Bind( 350 base::Closure renderer_callback = base::Bind(
322 &PrefsTabHelper::UpdateRendererPreferences, base::Unretained(this)); 351 &PrefsTabHelper::UpdateRendererPreferences, base::Unretained(this));
323 pref_change_registrar_.Add(prefs::kAcceptLanguages, renderer_callback); 352 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); 353 pref_change_registrar_.Add(prefs::kEnableDoNotTrack, renderer_callback);
326 pref_change_registrar_.Add(prefs::kEnableReferrers, renderer_callback); 354 pref_change_registrar_.Add(prefs::kEnableReferrers, renderer_callback);
327 355
328 #if !defined(OS_MACOSX) 356 #if !defined(OS_MACOSX)
329 pref_change_registrar_.Add(prefs::kFullscreenAllowed, renderer_callback); 357 pref_change_registrar_.Add(prefs::kFullscreenAllowed, renderer_callback);
330 #endif 358 #endif
331 359
332 PrefChangeRegistrar::NamedChangeCallback webkit_callback = base::Bind( 360 PrefChangeRegistrar::NamedChangeCallback webkit_callback = base::Bind(
333 &PrefsTabHelper::OnWebPrefChanged, base::Unretained(this)); 361 &PrefsTabHelper::OnWebPrefChanged, base::Unretained(this));
334 for (int i = 0; i < kPrefsToObserveLength; ++i) { 362 for (int i = 0; i < kPrefsToObserveLength; ++i) {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 #endif // defined(USE_AURA) 587 #endif // defined(USE_AURA)
560 588
561 NOTREACHED(); 589 NOTREACHED();
562 } 590 }
563 591
564 void PrefsTabHelper::UpdateWebPreferences() { 592 void PrefsTabHelper::UpdateWebPreferences() {
565 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences( 593 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(
566 web_contents_->GetRenderViewHost()->GetWebkitPreferences()); 594 web_contents_->GetRenderViewHost()->GetWebkitPreferences());
567 } 595 }
568 596
597 void PrefsTabHelper::UpdateAfterZoomLevelPrefsInitialized(bool success) {
598 if (success)
599 UpdateRendererPreferences();
600 }
601
569 void PrefsTabHelper::UpdateRendererPreferences() { 602 void PrefsTabHelper::UpdateRendererPreferences() {
570 renderer_preferences_util::UpdateFromSystemSettings( 603 renderer_preferences_util::UpdateFromSystemSettings(
571 web_contents_->GetMutableRendererPrefs(), GetProfile()); 604 web_contents_->GetMutableRendererPrefs(), GetProfile());
572 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); 605 web_contents_->GetRenderViewHost()->SyncRendererPrefs();
573 } 606 }
574 607
575 Profile* PrefsTabHelper::GetProfile() { 608 Profile* PrefsTabHelper::GetProfile() {
576 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); 609 return Profile::FromBrowserContext(web_contents_->GetBrowserContext());
577 } 610 }
578 611
(...skipping 27 matching lines...) Expand all
606 } 639 }
607 } 640 }
608 641
609 void PrefsTabHelper::OnWebPrefChanged(const std::string& pref_name) { 642 void PrefsTabHelper::OnWebPrefChanged(const std::string& pref_name) {
610 #if !defined(OS_ANDROID) 643 #if !defined(OS_ANDROID)
611 OnFontFamilyPrefChanged(pref_name); 644 OnFontFamilyPrefChanged(pref_name);
612 #endif 645 #endif
613 646
614 web_contents_->GetRenderViewHost()->OnWebkitPreferencesChanged(); 647 web_contents_->GetRenderViewHost()->OnWebkitPreferencesChanged();
615 } 648 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698