Home | History | Annotate | Download | only in prefs
      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 
     16 class OverlayUserPrefStore;
     17 class PrefService;
     18 class Profile;
     19 
     20 namespace content {
     21 class WebContents;
     22 }
     23 
     24 namespace user_prefs {
     25 class PrefRegistrySyncable;
     26 }
     27 
     28 // Per-tab class to handle user preferences.
     29 class 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   void OnWebPrefChanged(const std::string& pref_name);
     55 
     56   content::WebContents* web_contents_;
     57   content::NotificationRegistrar registrar_;
     58   PrefChangeRegistrar pref_change_registrar_;
     59   scoped_ptr<base::CallbackList<void(void)>::Subscription>
     60       style_sheet_subscription_;
     61   base::WeakPtrFactory<PrefsTabHelper> weak_ptr_factory_;
     62 
     63   DISALLOW_COPY_AND_ASSIGN(PrefsTabHelper);
     64 };
     65 
     66 #endif  // CHROME_BROWSER_UI_PREFS_PREFS_TAB_HELPER_H_
     67