Home | History | Annotate | Download | only in searchbox
      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/omnibox_focus_state.h"
     15 #include "content/public/common/page_transition_types.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_CountMouseover to the browser.
     32   void CountMouseover();
     33 
     34   // Sends ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem to the browser.
     35   void DeleteMostVisitedItem(InstantRestrictedID most_visited_item_id);
     36 
     37   // Generates the favicon URL of the most visited item specified by the
     38   // |transient_url|. If the |transient_url| is valid, returns true and fills in
     39   // |url|. If the |transient_url| is invalid, returns true and |url| is set to
     40   // "chrome-search://favicon/" in order to prevent the invalid URL to be
     41   // requested.
     42   //
     43   // Valid forms of |transient_url|:
     44   //    chrome-search://favicon/<view_id>/<restricted_id>
     45   //    chrome-search://favicon/<favicon_parameters>/<view_id>/<restricted_id>
     46   bool GenerateFaviconURLFromTransientURL(const GURL& transient_url,
     47                                           GURL* url) const;
     48 
     49   // Generates the thumbnail URL of the most visited item specified by the
     50   // |transient_url|. If the |transient_url| is valid, returns true and fills in
     51   // |url|. If the |transient_url| is invalid, returns false  and |url| is not
     52   // set.
     53   //
     54   // Valid form of |transient_url|:
     55   //    chrome-search://thumb/<render_view_id>/<most_visited_item_id>
     56   bool GenerateThumbnailURLFromTransientURL(const GURL& transient_url,
     57                                             GURL* url) const;
     58 
     59   // Returns the latest most visited items sent by the browser.
     60   void GetMostVisitedItems(
     61       std::vector<InstantMostVisitedItemIDPair>* items) const;
     62 
     63   // If the |most_visited_item_id| is found in the cache, sets |item| to it
     64   // and returns true.
     65   bool GetMostVisitedItemWithID(InstantRestrictedID most_visited_item_id,
     66                                 InstantMostVisitedItem* item) const;
     67 
     68   // Sends ChromeViewHostMsg_SearchBoxNavigate to the browser.
     69   void NavigateToURL(const GURL& url,
     70                      content::PageTransition transition,
     71                      WindowOpenDisposition disposition,
     72                      bool is_search_type);
     73 
     74   // Sends ChromeViewHostMsg_SearchBoxPaste to the browser.
     75   void Paste(const string16& text);
     76 
     77   const ThemeBackgroundInfo& GetThemeBackgroundInfo();
     78 
     79   // Sends ChromeViewHostMsg_SetVoiceSearchSupported to the browser.
     80   void SetVoiceSearchSupported(bool supported);
     81 
     82   // Sends ChromeViewHostMsg_StartCapturingKeyStrokes to the browser.
     83   void StartCapturingKeyStrokes();
     84 
     85   // Sends ChromeViewHostMsg_StopCapturingKeyStrokes to the browser.
     86   void StopCapturingKeyStrokes();
     87 
     88   // Sends ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions to the
     89   // browser.
     90   void UndoAllMostVisitedDeletions();
     91 
     92   // Sends ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion to the browser.
     93   void UndoMostVisitedDeletion(InstantRestrictedID most_visited_item_id);
     94 
     95   bool app_launcher_enabled() const { return app_launcher_enabled_; }
     96   bool is_focused() const { return is_focused_; }
     97   bool is_input_in_progress() const { return is_input_in_progress_; }
     98   bool is_key_capture_enabled() const { return is_key_capture_enabled_; }
     99   const string16& omnibox_font() const { return omnibox_font_; }
    100   const string16& query() const { return query_; }
    101   int start_margin() const { return start_margin_; }
    102   size_t omnibox_font_size() const { return omnibox_font_size_; }
    103 
    104  private:
    105   // Overridden from content::RenderViewObserver:
    106   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
    107 
    108   void OnDetermineIfPageSupportsInstant();
    109   void OnFocusChanged(OmniboxFocusState new_focus_state,
    110                       OmniboxFocusChangeReason reason);
    111   void OnFontInformationReceived(const string16& omnibox_font,
    112                                  size_t omnibox_font_size);
    113   void OnMarginChange(int margin, int width);
    114   void OnMostVisitedChanged(
    115       const std::vector<InstantMostVisitedItem>& items);
    116   void OnPromoInformationReceived(bool is_app_launcher_enabled);
    117   void OnSetInputInProgress(bool input_in_progress);
    118   void OnSubmit(const string16& query);
    119   void OnThemeChanged(const ThemeBackgroundInfo& theme_info);
    120   void OnToggleVoiceSearch();
    121 
    122   // Returns the current zoom factor of the render view or 1 on failure.
    123   double GetZoom() const;
    124 
    125   // Sets the searchbox values to their initial value.
    126   void Reset();
    127 
    128   // Returns the URL of the Most Visited item specified by the |item_id|.
    129   GURL GetURLForMostVisitedItem(InstantRestrictedID item_id) const;
    130 
    131   bool app_launcher_enabled_;
    132   bool is_focused_;
    133   bool is_input_in_progress_;
    134   bool is_key_capture_enabled_;
    135   InstantRestrictedIDCache<InstantMostVisitedItem> most_visited_items_cache_;
    136   ThemeBackgroundInfo theme_info_;
    137   string16 omnibox_font_;
    138   size_t omnibox_font_size_;
    139   string16 query_;
    140   int start_margin_;
    141   int width_;
    142 
    143   DISALLOW_COPY_AND_ASSIGN(SearchBox);
    144 };
    145 
    146 #endif  // CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_
    147