Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / ntp / suggestions_page_handler.h
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_WEBUI_NTP_SUGGESTIONS_PAGE_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_PAGE_HANDLER_H_
7
8 #include <string>
9
10 #include "chrome/browser/history/history_types.h"
11 #include "chrome/browser/ui/webui/ntp/suggestions_combiner.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "content/public/browser/web_ui_message_handler.h"
15
16 class GURL;
17 class PageUsageData;
18
19 namespace base {
20 class ListValue;
21 class Value;
22 }
23
24 namespace user_prefs {
25 class PrefRegistrySyncable;
26 }
27
28 // The handler for Javascript messages related to the "suggestions" view.
29 //
30 // This class manages one preference:
31 // - The URL blacklist: URLs we do not want to show in the thumbnails list.  It
32 //   is a dictionary for quick access (it associates a dummy boolean to the URL
33 //   string).
34 class SuggestionsHandler : public content::WebUIMessageHandler,
35                            public content::NotificationObserver,
36                            public SuggestionsCombiner::Delegate {
37  public:
38   SuggestionsHandler();
39   virtual ~SuggestionsHandler();
40
41   // WebUIMessageHandler override and implementation.
42   virtual void RegisterMessages() OVERRIDE;
43
44   // Callback for the "getSuggestions" message.
45   void HandleGetSuggestions(const base::ListValue* args);
46
47   // Callback for the "blacklistURLFromSuggestions" message.
48   void HandleBlacklistURL(const base::ListValue* args);
49
50   // Callback for the "removeURLsFromSuggestionsBlacklist" message.
51   void HandleRemoveURLsFromBlacklist(const base::ListValue* args);
52
53   // Callback for the "clearSuggestionsURLsBlacklist" message.
54   void HandleClearBlacklist(const base::ListValue* args);
55
56   // Callback for the "suggestedSitesAction" message.
57   void HandleSuggestedSitesAction(const base::ListValue* args);
58
59   // Callback for the "suggestedSitesSelected" message.
60   void HandleSuggestedSitesSelected(const base::ListValue* args);
61
62   // content::NotificationObserver implementation.
63   virtual void Observe(int type,
64                        const content::NotificationSource& source,
65                        const content::NotificationDetails& details) OVERRIDE;
66
67   // SuggestionsCombiner::Delegate implementation.
68   virtual void OnSuggestionsReady() OVERRIDE;
69
70   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
71
72  private:
73   // Puts the passed URL in the blacklist (so it does not show as a thumbnail).
74   void BlacklistURL(const GURL& url);
75
76   // Returns the key used in url_blacklist_ for the passed |url|.
77   std::string GetDictionaryKeyForURL(const std::string& url);
78
79   // Sends pages_value_ to the javascript side to and resets page_value_.
80   void SendPagesValue();
81
82   content::NotificationRegistrar registrar_;
83
84   // We pre-fetch the first set of result pages.  This variable is false until
85   // we get the first getSuggestions() call.
86   bool got_first_suggestions_request_;
87
88   // Used to combine suggestions from various sources.
89   scoped_ptr<SuggestionsCombiner> suggestions_combiner_;
90
91   // Whether the user has viewed the 'suggested' pane.
92   bool suggestions_viewed_;
93
94   // Whether the user has performed a "tracked" action to leave the page or not.
95   bool user_action_logged_;
96
97   DISALLOW_COPY_AND_ASSIGN(SuggestionsHandler);
98 };
99
100 #endif  // CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_PAGE_HANDLER_H_