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/common/cancelable_request.h"
11 #include "chrome/browser/history/history_types.h"
12 #include "chrome/browser/ui/webui/ntp/suggestions_combiner.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "content/public/browser/web_ui_message_handler.h"
25 namespace user_prefs
{
26 class PrefRegistrySyncable
;
29 // The handler for Javascript messages related to the "suggestions" view.
31 // This class manages one preference:
32 // - The URL blacklist: URLs we do not want to show in the thumbnails list. It
33 // is a dictionary for quick access (it associates a dummy boolean to the URL
35 class SuggestionsHandler
: public content::WebUIMessageHandler
,
36 public content::NotificationObserver
,
37 public SuggestionsCombiner::Delegate
{
40 virtual ~SuggestionsHandler();
42 // WebUIMessageHandler override and implementation.
43 virtual void RegisterMessages() OVERRIDE
;
45 // Callback for the "getSuggestions" message.
46 void HandleGetSuggestions(const base::ListValue
* args
);
48 // Callback for the "blacklistURLFromSuggestions" message.
49 void HandleBlacklistURL(const base::ListValue
* args
);
51 // Callback for the "removeURLsFromSuggestionsBlacklist" message.
52 void HandleRemoveURLsFromBlacklist(const base::ListValue
* args
);
54 // Callback for the "clearSuggestionsURLsBlacklist" message.
55 void HandleClearBlacklist(const base::ListValue
* args
);
57 // Callback for the "suggestedSitesAction" message.
58 void HandleSuggestedSitesAction(const base::ListValue
* args
);
60 // Callback for the "suggestedSitesSelected" message.
61 void HandleSuggestedSitesSelected(const base::ListValue
* args
);
63 // content::NotificationObserver implementation.
64 virtual void Observe(int type
,
65 const content::NotificationSource
& source
,
66 const content::NotificationDetails
& details
) OVERRIDE
;
68 // SuggestionsCombiner::Delegate implementation.
69 virtual void OnSuggestionsReady() OVERRIDE
;
71 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
74 // Puts the passed URL in the blacklist (so it does not show as a thumbnail).
75 void BlacklistURL(const GURL
& url
);
77 // Returns the key used in url_blacklist_ for the passed |url|.
78 std::string
GetDictionaryKeyForURL(const std::string
& url
);
80 // Sends pages_value_ to the javascript side to and resets page_value_.
81 void SendPagesValue();
83 content::NotificationRegistrar registrar_
;
85 // We pre-fetch the first set of result pages. This variable is false until
86 // we get the first getSuggestions() call.
87 bool got_first_suggestions_request_
;
89 // Used to combine suggestions from various sources.
90 scoped_ptr
<SuggestionsCombiner
> suggestions_combiner_
;
92 // Whether the user has viewed the 'suggested' pane.
93 bool suggestions_viewed_
;
95 // Whether the user has performed a "tracked" action to leave the page or not.
96 bool user_action_logged_
;
98 DISALLOW_COPY_AND_ASSIGN(SuggestionsHandler
);
101 #endif // CHROME_BROWSER_UI_WEBUI_NTP_SUGGESTIONS_PAGE_HANDLER_H_