• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_
6 #define CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_
7 
8 #include <vector>
9 
10 #include "base/basictypes.h"
11 #include "base/strings/string16.h"
12 #include "chrome/common/instant_restricted_id_cache.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 "content/public/renderer/render_view_observer.h"
17 #include "content/public/renderer/render_view_observer_tracker.h"
18 #include "ui/base/window_open_disposition.h"
19 #include "url/gurl.h"
20 
21 namespace content {
22 class RenderView;
23 }
24 
25 class SearchBox : public content::RenderViewObserver,
26                   public content::RenderViewObserverTracker<SearchBox> {
27  public:
28   explicit SearchBox(content::RenderView* render_view);
29   virtual ~SearchBox();
30 
31   // Sends ChromeViewHostMsg_LogEvent to the browser.
32   void LogEvent(NTPLoggingEventType event);
33 
34   // Sends ChromeViewHostMsg_LogImpression to the browser.
35   void LogImpression(int position, const base::string16& provider);
36 
37   // Sends ChromeViewHostMsg_ChromeIdentityCheck to the browser.
38   void CheckIsUserSignedInToChromeAs(const base::string16& identity);
39 
40   // Sends ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem to the browser.
41   void DeleteMostVisitedItem(InstantRestrictedID most_visited_item_id);
42 
43   // Generates the favicon URL of the most visited item specified by the
44   // |transient_url|. If the |transient_url| is valid, returns true and fills in
45   // |url|. If the |transient_url| is invalid, returns true and |url| is set to
46   // "chrome-search://favicon/" in order to prevent the invalid URL to be
47   // requested.
48   //
49   // Valid forms of |transient_url|:
50   //    chrome-search://favicon/<view_id>/<restricted_id>
51   //    chrome-search://favicon/<favicon_parameters>/<view_id>/<restricted_id>
52   bool GenerateFaviconURLFromTransientURL(const GURL& transient_url,
53                                           GURL* url) const;
54 
55   // Generates the thumbnail URL of the most visited item specified by the
56   // |transient_url|. If the |transient_url| is valid, returns true and fills in
57   // |url|. If the |transient_url| is invalid, returns false  and |url| is not
58   // set.
59   //
60   // Valid form of |transient_url|:
61   //    chrome-search://thumb/<render_view_id>/<most_visited_item_id>
62   bool GenerateThumbnailURLFromTransientURL(const GURL& transient_url,
63                                             GURL* url) const;
64 
65   // Returns the latest most visited items sent by the browser.
66   void GetMostVisitedItems(
67       std::vector<InstantMostVisitedItemIDPair>* items) const;
68 
69   // If the |most_visited_item_id| is found in the cache, sets |item| to it
70   // and returns true.
71   bool GetMostVisitedItemWithID(InstantRestrictedID most_visited_item_id,
72                                 InstantMostVisitedItem* item) const;
73 
74   // Sends ChromeViewHostMsg_FocusOmnibox to the browser.
75   void Focus();
76 
77   // Sends ChromeViewHostMsg_SearchBoxNavigate to the browser.
78   void NavigateToURL(const GURL& url,
79                      WindowOpenDisposition disposition,
80                      bool is_most_visited_item_url);
81 
82   // Sends ChromeViewHostMsg_SearchBoxPaste to the browser.
83   void Paste(const base::string16& text);
84 
85   const ThemeBackgroundInfo& GetThemeBackgroundInfo();
86 
87   // Sends ChromeViewHostMsg_SetVoiceSearchSupported to the browser.
88   void SetVoiceSearchSupported(bool supported);
89 
90   // Sends ChromeViewHostMsg_StartCapturingKeyStrokes to the browser.
91   void StartCapturingKeyStrokes();
92 
93   // Sends ChromeViewHostMsg_StopCapturingKeyStrokes to the browser.
94   void StopCapturingKeyStrokes();
95 
96   // Sends ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions to the
97   // browser.
98   void UndoAllMostVisitedDeletions();
99 
100   // Sends ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion to the browser.
101   void UndoMostVisitedDeletion(InstantRestrictedID most_visited_item_id);
102 
app_launcher_enabled()103   bool app_launcher_enabled() const { return app_launcher_enabled_; }
is_focused()104   bool is_focused() const { return is_focused_; }
is_input_in_progress()105   bool is_input_in_progress() const { return is_input_in_progress_; }
is_key_capture_enabled()106   bool is_key_capture_enabled() const { return is_key_capture_enabled_; }
display_instant_results()107   bool display_instant_results() const { return display_instant_results_; }
query()108   const base::string16& query() const { return query_; }
start_margin()109   int start_margin() const { return start_margin_; }
suggestion()110   const InstantSuggestion& suggestion() const { return suggestion_; }
111 
112  private:
113   // Overridden from content::RenderViewObserver:
114   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
115 
116   void OnChromeIdentityCheckResult(const base::string16& identity,
117                                    bool identity_match);
118   void OnDetermineIfPageSupportsInstant();
119   void OnFocusChanged(OmniboxFocusState new_focus_state,
120                       OmniboxFocusChangeReason reason);
121   void OnMarginChange(int margin, int width);
122   void OnMostVisitedChanged(
123       const std::vector<InstantMostVisitedItem>& items);
124   void OnPromoInformationReceived(bool is_app_launcher_enabled);
125   void OnSetDisplayInstantResults(bool display_instant_results);
126   void OnSetInputInProgress(bool input_in_progress);
127   void OnSetSuggestionToPrefetch(const InstantSuggestion& suggestion);
128   void OnSubmit(const base::string16& query);
129   void OnThemeChanged(const ThemeBackgroundInfo& theme_info);
130   void OnToggleVoiceSearch();
131 
132   // Returns the current zoom factor of the render view or 1 on failure.
133   double GetZoom() const;
134 
135   // Sets the searchbox values to their initial value.
136   void Reset();
137 
138   // Returns the URL of the Most Visited item specified by the |item_id|.
139   GURL GetURLForMostVisitedItem(InstantRestrictedID item_id) const;
140 
141   bool app_launcher_enabled_;
142   bool is_focused_;
143   bool is_input_in_progress_;
144   bool is_key_capture_enabled_;
145   bool display_instant_results_;
146   InstantRestrictedIDCache<InstantMostVisitedItem> most_visited_items_cache_;
147   ThemeBackgroundInfo theme_info_;
148   base::string16 query_;
149   int start_margin_;
150   InstantSuggestion suggestion_;
151   int width_;
152 
153   DISALLOW_COPY_AND_ASSIGN(SearchBox);
154 };
155 
156 #endif  // CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_
157