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