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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_PAGE_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_PAGE_HANDLER_H_
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"
24 namespace user_prefs {
25 class PrefRegistrySyncable;
28 // The handler for Javascript messages related to the "suggestions" view.
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
34 class SuggestionsHandler : public content::WebUIMessageHandler,
35 public content::NotificationObserver,
36 public SuggestionsCombiner::Delegate {
39 virtual ~SuggestionsHandler();
41 // WebUIMessageHandler override and implementation.
42 virtual void RegisterMessages() OVERRIDE;
44 // Callback for the "getSuggestions" message.
45 void HandleGetSuggestions(const base::ListValue* args);
47 // Callback for the "blacklistURLFromSuggestions" message.
48 void HandleBlacklistURL(const base::ListValue* args);
50 // Callback for the "removeURLsFromSuggestionsBlacklist" message.
51 void HandleRemoveURLsFromBlacklist(const base::ListValue* args);
53 // Callback for the "clearSuggestionsURLsBlacklist" message.
54 void HandleClearBlacklist(const base::ListValue* args);
56 // Callback for the "suggestedSitesAction" message.
57 void HandleSuggestedSitesAction(const base::ListValue* args);
59 // Callback for the "suggestedSitesSelected" message.
60 void HandleSuggestedSitesSelected(const base::ListValue* args);
62 // content::NotificationObserver implementation.
63 virtual void Observe(int type,
64 const content::NotificationSource& source,
65 const content::NotificationDetails& details) OVERRIDE;
67 // SuggestionsCombiner::Delegate implementation.
68 virtual void OnSuggestionsReady() OVERRIDE;
70 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
73 // Puts the passed URL in the blacklist (so it does not show as a thumbnail).
74 void BlacklistURL(const GURL& url);
76 // Returns the key used in url_blacklist_ for the passed |url|.
77 std::string GetDictionaryKeyForURL(const std::string& url);
79 // Sends pages_value_ to the javascript side to and resets page_value_.
80 void SendPagesValue();
82 content::NotificationRegistrar registrar_;
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_;
88 // Used to combine suggestions from various sources.
89 scoped_ptr<SuggestionsCombiner> suggestions_combiner_;
91 // Whether the user has viewed the 'suggested' pane.
92 bool suggestions_viewed_;
94 // Whether the user has performed a "tracked" action to leave the page or not.
95 bool user_action_logged_;
97 DISALLOW_COPY_AND_ASSIGN(SuggestionsHandler);
100 #endif // CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_PAGE_HANDLER_H_