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
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_UI_PREFS_PREFS_TAB_HELPER_H_
6#define CHROME_BROWSER_UI_PREFS_PREFS_TAB_HELPER_H_
7
8#include "base/callback_list.h"
9#include "base/compiler_specific.h"
10#include "base/memory/weak_ptr.h"
11#include "base/prefs/pref_change_registrar.h"
12#include "content/public/browser/notification_observer.h"
13#include "content/public/browser/notification_registrar.h"
14#include "content/public/browser/web_contents_user_data.h"
15
16class OverlayUserPrefStore;
17class PrefService;
18class Profile;
19
20namespace content {
21class WebContents;
22}
23
24namespace user_prefs {
25class PrefRegistrySyncable;
26}
27
28// Per-tab class to handle user preferences.
29class PrefsTabHelper : public content::NotificationObserver,
30                       public content::WebContentsUserData<PrefsTabHelper> {
31 public:
32  virtual ~PrefsTabHelper();
33
34  static void InitIncognitoUserPrefStore(OverlayUserPrefStore* pref_store);
35  static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
36
37 protected:
38  // Update the RenderView's WebPreferences. Exposed as protected for testing.
39  virtual void UpdateWebPreferences();
40
41 private:
42  explicit PrefsTabHelper(content::WebContents* contents);
43  friend class content::WebContentsUserData<PrefsTabHelper>;
44
45  // content::NotificationObserver overrides:
46  virtual void Observe(int type,
47                       const content::NotificationSource& source,
48                       const content::NotificationDetails& details) OVERRIDE;
49
50  // Update the WebContents's RendererPreferences.
51  void UpdateRendererPreferences();
52
53  Profile* GetProfile();
54
55  void OnFontFamilyPrefChanged(const std::string& pref_name);
56  void OnWebPrefChanged(const std::string& pref_name);
57
58  content::WebContents* web_contents_;
59  content::NotificationRegistrar registrar_;
60  PrefChangeRegistrar pref_change_registrar_;
61  scoped_ptr<base::CallbackList<void(void)>::Subscription>
62      style_sheet_subscription_;
63  base::WeakPtrFactory<PrefsTabHelper> weak_ptr_factory_;
64
65  DISALLOW_COPY_AND_ASSIGN(PrefsTabHelper);
66};
67
68#endif  // CHROME_BROWSER_UI_PREFS_PREFS_TAB_HELPER_H_
69