Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: chrome/renderer/searchbox/searchbox.h

Issue 1010783002: [Icons NTP] Working prototype to fetch, store, and display big icons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweaks and unit test fix. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Retruns view id for validating icon URL.
44 virtual int GetViewID() const = 0;
45 // Returns the page URL string for |rid|, or empty string for invalid |rid|.
46 virtual std::string GetURLStringFromRestrictedID(InstantRestrictedID rid)
47 const = 0;
48 };
49
28 explicit SearchBox(content::RenderView* render_view); 50 explicit SearchBox(content::RenderView* render_view);
29 ~SearchBox() override; 51 ~SearchBox() override;
30 52
31 // Sends ChromeViewHostMsg_LogEvent to the browser. 53 // Sends ChromeViewHostMsg_LogEvent to the browser.
32 void LogEvent(NTPLoggingEventType event); 54 void LogEvent(NTPLoggingEventType event);
33 55
34 // Sends ChromeViewHostMsg_LogMostVisitedImpression to the browser. 56 // Sends ChromeViewHostMsg_LogMostVisitedImpression to the browser.
35 void LogMostVisitedImpression(int position, const base::string16& provider); 57 void LogMostVisitedImpression(int position, const base::string16& provider);
36 58
37 // Sends ChromeViewHostMsg_LogMostVisitedNavigation to the browser. 59 // Sends ChromeViewHostMsg_LogMostVisitedNavigation to the browser.
38 void LogMostVisitedNavigation(int position, const base::string16& provider); 60 void LogMostVisitedNavigation(int position, const base::string16& provider);
39 61
40 // Sends ChromeViewHostMsg_ChromeIdentityCheck to the browser. 62 // Sends ChromeViewHostMsg_ChromeIdentityCheck to the browser.
41 void CheckIsUserSignedInToChromeAs(const base::string16& identity); 63 void CheckIsUserSignedInToChromeAs(const base::string16& identity);
42 64
43 // Sends ChromeViewHostMsg_HistorySyncCheck to the browser. 65 // Sends ChromeViewHostMsg_HistorySyncCheck to the browser.
44 void CheckIsUserSyncingHistory(); 66 void CheckIsUserSyncingHistory();
45 67
46 // Sends ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem to the browser. 68 // Sends ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem to the browser.
47 void DeleteMostVisitedItem(InstantRestrictedID most_visited_item_id); 69 void DeleteMostVisitedItem(InstantRestrictedID most_visited_item_id);
48 70
49 // Generates the favicon URL of the most visited item specified by the 71 // 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 72 // |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 73 // and returns true. Otherwise it depends on |type|:
52 // "chrome-search://favicon/" in order to prevent the invalid URL to be 74 // - FAVICON: Returns true and renders an URL to display the default favicon.
53 // requested. 75 // - LARGE_ICON and FALLBACK_ICON: Returns false.
54 // 76 //
55 // Valid forms of |transient_url|: 77 // For |type| == FAVICON, valid forms of |transient_url|:
56 // chrome-search://favicon/<view_id>/<restricted_id> 78 // chrome-search://favicon/<view_id>/<restricted_id>
57 // chrome-search://favicon/<favicon_parameters>/<view_id>/<restricted_id> 79 // 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 // 80 //
66 // Valid form of |transient_url|: 81 // For |type| == LARGE_ICON, valid form of |transient_url|:
82 // chrome-search://large-icon/<size>/<view_id>/<restricted_id>
83 //
84 // For |type| == FALLBACK_ICON, valid form of |transient_url|:
85 // chrome-search://fallback-icon/<icon specs>/<view_id>/<restricted_id>
86 //
87 // For |type| == THUMB, valid form of |transient_url|:
67 // chrome-search://thumb/<render_view_id>/<most_visited_item_id> 88 // chrome-search://thumb/<render_view_id>/<most_visited_item_id>
68 bool GenerateThumbnailURLFromTransientURL(const GURL& transient_url, 89 //
69 GURL* url) const; 90 // We do this to prevent search providers from abusing image URLs and deduce
91 // whether the user has visited a particular page. For example, if
92 // "chrome-search://favicon/http://www.secretsite.com" is accessible, then
93 // the search provider can use its return code to determine whether the user
94 // has visited "http://www.secretsite.com". Therefore we require search
95 // providers to specify URL by "<view_id>/<restricted_id>". We then translate
96 // this to the original |url|, and pass the request to the proper endpoint.
97 bool GenerateImageURLFromTransientURL(const GURL& transient_url,
98 ImageSourceType type,
99 GURL* url) const;
70 100
71 // Returns the latest most visited items sent by the browser. 101 // Returns the latest most visited items sent by the browser.
72 void GetMostVisitedItems( 102 void GetMostVisitedItems(
73 std::vector<InstantMostVisitedItemIDPair>* items) const; 103 std::vector<InstantMostVisitedItemIDPair>* items) const;
74 104
75 // If the |most_visited_item_id| is found in the cache, sets |item| to it 105 // If the |most_visited_item_id| is found in the cache, sets |item| to it
76 // and returns true. 106 // and returns true.
77 bool GetMostVisitedItemWithID(InstantRestrictedID most_visited_item_id, 107 bool GetMostVisitedItemWithID(InstantRestrictedID most_visited_item_id,
78 InstantMostVisitedItem* item) const; 108 InstantMostVisitedItem* item) const;
79 109
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 ThemeBackgroundInfo theme_info_; 188 ThemeBackgroundInfo theme_info_;
159 base::string16 query_; 189 base::string16 query_;
160 EmbeddedSearchRequestParams embedded_search_request_params_; 190 EmbeddedSearchRequestParams embedded_search_request_params_;
161 int start_margin_; 191 int start_margin_;
162 InstantSuggestion suggestion_; 192 InstantSuggestion suggestion_;
163 193
164 DISALLOW_COPY_AND_ASSIGN(SearchBox); 194 DISALLOW_COPY_AND_ASSIGN(SearchBox);
165 }; 195 };
166 196
167 #endif // CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_ 197 #endif // CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_
OLDNEW
« no previous file with comments | « chrome/renderer/chrome_content_renderer_client.cc ('k') | chrome/renderer/searchbox/searchbox.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698