• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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_WEBUI_SHOWN_SECTIONS_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_SHOWN_SECTIONS_HANDLER_H_
7 #pragma once
8 
9 #include "chrome/browser/prefs/pref_change_registrar.h"
10 #include "content/browser/webui/web_ui.h"
11 #include "content/common/notification_observer.h"
12 
13 class Extension;
14 class Value;
15 class PrefService;
16 
17 // Use for the shown sections bitmask.
18 // Currently, only the THUMB and APPS sections can be toggled by the user. Other
19 // sections are shown automatically if they have data, and hidden otherwise.
20 enum Section {
21   // If one of these is set, the corresponding section shows large thumbnails,
22   // else it shows only a small overview list.
23   THUMB = 1 << 0,
24   APPS = 1 << 6,
25 
26   // We use the low 16 bits for sections, the high 16 bits for menu mode.
27   ALL_SECTIONS_MASK = 0x0000FFFF,
28 
29   // If one of these is set, then the corresponding section is shown in a menu
30   // at the bottom of the NTP and no data is directly visible on the NTP.
31   MENU_THUMB = 1 << (0 + 16),
32   MENU_RECENT = 1 << (2 + 16),
33   MENU_APPS = 1 << (6 + 16),
34 };
35 
36 class ShownSectionsHandler : public WebUIMessageHandler,
37                              public NotificationObserver {
38  public:
39   explicit ShownSectionsHandler(PrefService* pref_service);
~ShownSectionsHandler()40   virtual ~ShownSectionsHandler() {}
41 
42   // Helper to get the current shown sections.
43   static int GetShownSections(PrefService* pref_service);
44 
45   // Expands |section|, collapsing any previously expanded section. This is the
46   // same thing that happens if a user clicks on |section|.
47   static void SetShownSection(PrefService* prefs, Section section);
48 
49   // WebUIMessageHandler implementation.
50   virtual void RegisterMessages();
51 
52   // NotificationObserver implementation.
53   virtual void Observe(NotificationType type,
54                        const NotificationSource& source,
55                        const NotificationDetails& details);
56 
57   // Callback for "getShownSections" message.
58   void HandleGetShownSections(const ListValue* args);
59 
60   // Callback for "setShownSections" message.
61   void HandleSetShownSections(const ListValue* args);
62 
63   static void RegisterUserPrefs(PrefService* pref_service);
64 
65   static void MigrateUserPrefs(PrefService* pref_service,
66                                int old_pref_version,
67                                int new_pref_version);
68 
69   static void OnExtensionInstalled(PrefService* prefs,
70                                    const Extension* extension);
71 
72  private:
73   PrefService* pref_service_;
74   PrefChangeRegistrar pref_registrar_;
75 
76   DISALLOW_COPY_AND_ASSIGN(ShownSectionsHandler);
77 };
78 
79 #endif  // CHROME_BROWSER_UI_WEBUI_SHOWN_SECTIONS_HANDLER_H_
80