Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / chrome / renderer / searchbox / searchbox.h
blob5cf040bdee25ca4cf1df1188f01e5a3648a869f5
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
3 // found in the LICENSE file.
5 #ifndef CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_
6 #define CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/strings/string16.h"
13 #include "chrome/common/instant_types.h"
14 #include "chrome/common/ntp_logging_events.h"
15 #include "chrome/common/omnibox_focus_state.h"
16 #include "chrome/renderer/instant_restricted_id_cache.h"
17 #include "content/public/renderer/render_view_observer.h"
18 #include "content/public/renderer/render_view_observer_tracker.h"
19 #include "ui/base/window_open_disposition.h"
20 #include "url/gurl.h"
22 namespace content {
23 class RenderView;
26 class SearchBox : public content::RenderViewObserver,
27 public content::RenderViewObserverTracker<SearchBox> {
28 public:
29 enum ImageSourceType {
30 NONE = -1,
31 FAVICON,
32 LARGE_ICON,
33 FALLBACK_ICON,
34 THUMB
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;
50 explicit SearchBox(content::RenderView* render_view);
51 ~SearchBox() override;
53 // Sends ChromeViewHostMsg_LogEvent to the browser.
54 void LogEvent(NTPLoggingEventType event);
56 // Sends ChromeViewHostMsg_LogMostVisitedImpression to the browser.
57 void LogMostVisitedImpression(int position, const base::string16& provider);
59 // Sends ChromeViewHostMsg_LogMostVisitedNavigation to the browser.
60 void LogMostVisitedNavigation(int position, const base::string16& provider);
62 // Sends ChromeViewHostMsg_ChromeIdentityCheck to the browser.
63 void CheckIsUserSignedInToChromeAs(const base::string16& identity);
65 // Sends ChromeViewHostMsg_HistorySyncCheck to the browser.
66 void CheckIsUserSyncingHistory();
68 // Sends ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem to the browser.
69 void DeleteMostVisitedItem(InstantRestrictedID most_visited_item_id);
71 // Generates the image URL of |type| for the most visited item specified in
72 // |transient_url|. If |transient_url| is valid, |url| with a translated URL
73 // and returns true. Otherwise it depends on |type|:
74 // - FAVICON: Returns true and renders an URL to display the default favicon.
75 // - LARGE_ICON and FALLBACK_ICON: Returns false.
77 // For |type| == FAVICON, valid forms of |transient_url|:
78 // chrome-search://favicon/<view_id>/<restricted_id>
79 // chrome-search://favicon/<favicon_parameters>/<view_id>/<restricted_id>
81 // For |type| == LARGE_ICON, valid form of |transient_url|:
82 // chrome-search://large-icon/<size>/<view_id>/<restricted_id>
84 // For |type| == FALLBACK_ICON, valid form of |transient_url|:
85 // chrome-search://fallback-icon/<icon specs>/<view_id>/<restricted_id>
87 // For |type| == THUMB, valid form of |transient_url|:
88 // chrome-search://thumb/<render_view_id>/<most_visited_item_id>
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;
101 // Returns the latest most visited items sent by the browser.
102 void GetMostVisitedItems(
103 std::vector<InstantMostVisitedItemIDPair>* items) const;
105 // If the |most_visited_item_id| is found in the cache, sets |item| to it
106 // and returns true.
107 bool GetMostVisitedItemWithID(InstantRestrictedID most_visited_item_id,
108 InstantMostVisitedItem* item) const;
110 // Sends ChromeViewHostMsg_FocusOmnibox to the browser.
111 void Focus();
113 // Sends ChromeViewHostMsg_SearchBoxNavigate to the browser.
114 void NavigateToURL(const GURL& url,
115 WindowOpenDisposition disposition,
116 bool is_most_visited_item_url);
118 // Sends ChromeViewHostMsg_SearchBoxPaste to the browser.
119 void Paste(const base::string16& text);
121 const ThemeBackgroundInfo& GetThemeBackgroundInfo();
122 const EmbeddedSearchRequestParams& GetEmbeddedSearchRequestParams();
124 // Sends ChromeViewHostMsg_SetVoiceSearchSupported to the browser.
125 void SetVoiceSearchSupported(bool supported);
127 // Sends ChromeViewHostMsg_StartCapturingKeyStrokes to the browser.
128 void StartCapturingKeyStrokes();
130 // Sends ChromeViewHostMsg_StopCapturingKeyStrokes to the browser.
131 void StopCapturingKeyStrokes();
133 // Sends ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions to the
134 // browser.
135 void UndoAllMostVisitedDeletions();
137 // Sends ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion to the browser.
138 void UndoMostVisitedDeletion(InstantRestrictedID most_visited_item_id);
140 bool app_launcher_enabled() const { return app_launcher_enabled_; }
141 bool is_focused() const { return is_focused_; }
142 bool is_input_in_progress() const { return is_input_in_progress_; }
143 bool is_key_capture_enabled() const { return is_key_capture_enabled_; }
144 bool display_instant_results() const { return display_instant_results_; }
145 const base::string16& query() const { return query_; }
146 int start_margin() const { return start_margin_; }
147 const InstantSuggestion& suggestion() const { return suggestion_; }
149 private:
150 // Overridden from content::RenderViewObserver:
151 bool OnMessageReceived(const IPC::Message& message) override;
153 void OnSetPageSequenceNumber(int page_seq_no);
154 void OnChromeIdentityCheckResult(const base::string16& identity,
155 bool identity_match);
156 void OnDetermineIfPageSupportsInstant();
157 void OnFocusChanged(OmniboxFocusState new_focus_state,
158 OmniboxFocusChangeReason reason);
159 void OnHistorySyncCheckResult(bool sync_history);
160 void OnMarginChange(int margin);
161 void OnMostVisitedChanged(
162 const std::vector<InstantMostVisitedItem>& items);
163 void OnPromoInformationReceived(bool is_app_launcher_enabled);
164 void OnSetDisplayInstantResults(bool display_instant_results);
165 void OnSetInputInProgress(bool input_in_progress);
166 void OnSetSuggestionToPrefetch(const InstantSuggestion& suggestion);
167 void OnSubmit(const base::string16& query,
168 const EmbeddedSearchRequestParams& params);
169 void OnThemeChanged(const ThemeBackgroundInfo& theme_info);
170 void OnToggleVoiceSearch();
172 // Returns the current zoom factor of the render view or 1 on failure.
173 double GetZoom() const;
175 // Sets the searchbox values to their initial value.
176 void Reset();
178 // Returns the URL of the Most Visited item specified by the |item_id|.
179 GURL GetURLForMostVisitedItem(InstantRestrictedID item_id) const;
181 int page_seq_no_;
182 bool app_launcher_enabled_;
183 bool is_focused_;
184 bool is_input_in_progress_;
185 bool is_key_capture_enabled_;
186 bool display_instant_results_;
187 InstantRestrictedIDCache<InstantMostVisitedItem> most_visited_items_cache_;
188 ThemeBackgroundInfo theme_info_;
189 base::string16 query_;
190 EmbeddedSearchRequestParams embedded_search_request_params_;
191 int start_margin_;
192 InstantSuggestion suggestion_;
194 DISALLOW_COPY_AND_ASSIGN(SearchBox);
197 #endif // CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_