Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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_RENDERER_SEARCHBOX_SEARCHBOX_H_ | 5 #ifndef CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_ |
| 6 #define CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_ | 6 #define CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_ |
| 7 | 7 |
| 8 #include <string> | |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 11 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 12 #include "chrome/common/instant_types.h" | 13 #include "chrome/common/instant_types.h" |
| 13 #include "chrome/common/ntp_logging_events.h" | 14 #include "chrome/common/ntp_logging_events.h" |
| 14 #include "chrome/common/omnibox_focus_state.h" | 15 #include "chrome/common/omnibox_focus_state.h" |
| 15 #include "chrome/renderer/instant_restricted_id_cache.h" | 16 #include "chrome/renderer/instant_restricted_id_cache.h" |
| 16 #include "content/public/renderer/render_view_observer.h" | 17 #include "content/public/renderer/render_view_observer.h" |
| 17 #include "content/public/renderer/render_view_observer_tracker.h" | 18 #include "content/public/renderer/render_view_observer_tracker.h" |
| 18 #include "ui/base/window_open_disposition.h" | 19 #include "ui/base/window_open_disposition.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 class RenderView; | 23 class RenderView; |
| 23 } | 24 } |
| 24 | 25 |
| 25 class SearchBox : public content::RenderViewObserver, | 26 class SearchBox : public content::RenderViewObserver, |
| 26 public content::RenderViewObserverTracker<SearchBox> { | 27 public content::RenderViewObserverTracker<SearchBox> { |
| 27 public: | 28 public: |
| 29 enum ImageSourceType { | |
| 30 NONE = -1, | |
| 31 FAVICON, | |
| 32 LARGE_ICON, | |
| 33 FALLBACK_ICON, | |
| 34 THUMB | |
| 35 }; | |
| 36 | |
| 37 // Helper class for GenerateImageURLFromTransientURL() to adapt SearchBox's | |
| 38 // instance, thereby allow mocking for unit tests. | |
| 39 class IconURLHelper { | |
| 40 public: | |
| 41 IconURLHelper(); | |
| 42 virtual ~IconURLHelper(); | |
| 43 virtual int GetViewID() const = 0; | |
| 44 virtual std::string GetURLStringFromRestrictedID(InstantRestrictedID rid) | |
| 45 const = 0; | |
| 46 }; | |
| 47 | |
| 28 explicit SearchBox(content::RenderView* render_view); | 48 explicit SearchBox(content::RenderView* render_view); |
| 29 ~SearchBox() override; | 49 ~SearchBox() override; |
| 30 | 50 |
| 31 // Sends ChromeViewHostMsg_LogEvent to the browser. | 51 // Sends ChromeViewHostMsg_LogEvent to the browser. |
| 32 void LogEvent(NTPLoggingEventType event); | 52 void LogEvent(NTPLoggingEventType event); |
| 33 | 53 |
| 34 // Sends ChromeViewHostMsg_LogMostVisitedImpression to the browser. | 54 // Sends ChromeViewHostMsg_LogMostVisitedImpression to the browser. |
| 35 void LogMostVisitedImpression(int position, const base::string16& provider); | 55 void LogMostVisitedImpression(int position, const base::string16& provider); |
| 36 | 56 |
| 37 // Sends ChromeViewHostMsg_LogMostVisitedNavigation to the browser. | 57 // Sends ChromeViewHostMsg_LogMostVisitedNavigation to the browser. |
| 38 void LogMostVisitedNavigation(int position, const base::string16& provider); | 58 void LogMostVisitedNavigation(int position, const base::string16& provider); |
| 39 | 59 |
| 40 // Sends ChromeViewHostMsg_ChromeIdentityCheck to the browser. | 60 // Sends ChromeViewHostMsg_ChromeIdentityCheck to the browser. |
| 41 void CheckIsUserSignedInToChromeAs(const base::string16& identity); | 61 void CheckIsUserSignedInToChromeAs(const base::string16& identity); |
| 42 | 62 |
| 43 // Sends ChromeViewHostMsg_HistorySyncCheck to the browser. | 63 // Sends ChromeViewHostMsg_HistorySyncCheck to the browser. |
| 44 void CheckIsUserSyncingHistory(); | 64 void CheckIsUserSyncingHistory(); |
| 45 | 65 |
| 46 // Sends ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem to the browser. | 66 // Sends ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem to the browser. |
| 47 void DeleteMostVisitedItem(InstantRestrictedID most_visited_item_id); | 67 void DeleteMostVisitedItem(InstantRestrictedID most_visited_item_id); |
| 48 | 68 |
| 49 // Generates the favicon URL of the most visited item specified by the | 69 // Generates the image URL of |type| for the most visited item specified in |
| 50 // |transient_url|. If the |transient_url| is valid, returns true and fills in | 70 // |transient_url|. If |transient_url| is valid, |url| with a translated URL |
| 51 // |url|. If the |transient_url| is invalid, returns true and |url| is set to | 71 // and returns true. Otherwise it depends on |type|: |
| 52 // "chrome-search://favicon/" in order to prevent the invalid URL to be | 72 // - FAVICON: Returns true and renders an URL to display the default favicon. |
| 53 // requested. | 73 // - LARGE_ICON and FALLBACK_ICON: Returns false. |
| 54 // | 74 // |
| 55 // Valid forms of |transient_url|: | 75 // For |type| == FAVICON, valid forms of |transient_url|: |
| 56 // chrome-search://favicon/<view_id>/<restricted_id> | 76 // chrome-search://favicon/<view_id>/<restricted_id> |
| 57 // chrome-search://favicon/<favicon_parameters>/<view_id>/<restricted_id> | 77 // chrome-search://favicon/<favicon_parameters>/<view_id>/<restricted_id> |
| 58 bool GenerateFaviconURLFromTransientURL(const GURL& transient_url, | |
| 59 GURL* url) const; | |
| 60 | |
| 61 // Generates the thumbnail URL of the most visited item specified by the | |
| 62 // |transient_url|. If the |transient_url| is valid, returns true and fills in | |
| 63 // |url|. If the |transient_url| is invalid, returns false and |url| is not | |
| 64 // set. | |
| 65 // | 78 // |
| 66 // Valid form of |transient_url|: | 79 // For |type| == LARGE_ICON, valid form of |transient_url|: |
| 80 // chrome-search://large-icon/<size>/<view_id>/<restricted_id> | |
| 81 // | |
| 82 // For |type| == FALLBACK_ICON, valid form of |transient_url|: | |
| 83 // chrome-search://fallback-icon/<icon styles>/<view_id>/<restricted_id> | |
| 84 // | |
| 85 // For |type| == THUMB, valid form of |transient_url|: | |
| 67 // chrome-search://thumb/<render_view_id>/<most_visited_item_id> | 86 // chrome-search://thumb/<render_view_id>/<most_visited_item_id> |
| 68 bool GenerateThumbnailURLFromTransientURL(const GURL& transient_url, | 87 // |
| 69 GURL* url) const; | 88 // We do to prevent search providers from abusing image URLs and deduce |
|
James Hawkins
2015/03/20 16:26:43
nit: Please clean up the grammar at the beginning
huangs
2015/03/20 17:32:37
Done.
| |
| 89 // whether the user has visited a particular page. For example, if | |
| 90 // "chrome-search://favicon/http://www.secretsite.com" is accessible, then | |
| 91 // the search provider can use its return code to determine whether the user | |
| 92 // has visited "http://www.secretsite.com". Therefore we require search | |
| 93 // providers to specify URL by "<view_id>/<restricted_id>". We then translate | |
| 94 // this to the original |url|, and pass the request to the proper endpoint. | |
| 95 bool GenerateImageURLFromTransientURL(const GURL& transient_url, | |
| 96 ImageSourceType type, | |
| 97 GURL* url) const; | |
| 70 | 98 |
| 71 // Returns the latest most visited items sent by the browser. | 99 // Returns the latest most visited items sent by the browser. |
| 72 void GetMostVisitedItems( | 100 void GetMostVisitedItems( |
| 73 std::vector<InstantMostVisitedItemIDPair>* items) const; | 101 std::vector<InstantMostVisitedItemIDPair>* items) const; |
| 74 | 102 |
| 75 // If the |most_visited_item_id| is found in the cache, sets |item| to it | 103 // If the |most_visited_item_id| is found in the cache, sets |item| to it |
| 76 // and returns true. | 104 // and returns true. |
| 77 bool GetMostVisitedItemWithID(InstantRestrictedID most_visited_item_id, | 105 bool GetMostVisitedItemWithID(InstantRestrictedID most_visited_item_id, |
| 78 InstantMostVisitedItem* item) const; | 106 InstantMostVisitedItem* item) const; |
| 79 | 107 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 ThemeBackgroundInfo theme_info_; | 186 ThemeBackgroundInfo theme_info_; |
| 159 base::string16 query_; | 187 base::string16 query_; |
| 160 EmbeddedSearchRequestParams embedded_search_request_params_; | 188 EmbeddedSearchRequestParams embedded_search_request_params_; |
| 161 int start_margin_; | 189 int start_margin_; |
| 162 InstantSuggestion suggestion_; | 190 InstantSuggestion suggestion_; |
| 163 | 191 |
| 164 DISALLOW_COPY_AND_ASSIGN(SearchBox); | 192 DISALLOW_COPY_AND_ASSIGN(SearchBox); |
| 165 }; | 193 }; |
| 166 | 194 |
| 167 #endif // CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_ | 195 #endif // CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_ |
| OLD | NEW |