summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/searchbox/searchbox.h
blob: 51247dba550ead32ab90c1a3fece96eb7d626df2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_
#define CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_

#include <vector>

#include "base/basictypes.h"
#include "base/strings/string16.h"
#include "chrome/common/instant_restricted_id_cache.h"
#include "chrome/common/instant_types.h"
#include "chrome/common/ntp_logging_events.h"
#include "chrome/common/omnibox_focus_state.h"
#include "content/public/renderer/render_view_observer.h"
#include "content/public/renderer/render_view_observer_tracker.h"
#include "ui/base/window_open_disposition.h"
#include "url/gurl.h"

namespace content {
class RenderView;
}

class SearchBox : public content::RenderViewObserver,
                  public content::RenderViewObserverTracker<SearchBox> {
 public:
  explicit SearchBox(content::RenderView* render_view);
  virtual ~SearchBox();

  // Sends ChromeViewHostMsg_LogEvent to the browser.
  void LogEvent(NTPLoggingEventType event);

  // Sends ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem to the browser.
  void DeleteMostVisitedItem(InstantRestrictedID most_visited_item_id);

  // Generates the favicon URL of the most visited item specified by the
  // |transient_url|. If the |transient_url| is valid, returns true and fills in
  // |url|. If the |transient_url| is invalid, returns true and |url| is set to
  // "chrome-search://favicon/" in order to prevent the invalid URL to be
  // requested.
  //
  // Valid forms of |transient_url|:
  //    chrome-search://favicon/<view_id>/<restricted_id>
  //    chrome-search://favicon/<favicon_parameters>/<view_id>/<restricted_id>
  bool GenerateFaviconURLFromTransientURL(const GURL& transient_url,
                                          GURL* url) const;

  // Generates the thumbnail URL of the most visited item specified by the
  // |transient_url|. If the |transient_url| is valid, returns true and fills in
  // |url|. If the |transient_url| is invalid, returns false  and |url| is not
  // set.
  //
  // Valid form of |transient_url|:
  //    chrome-search://thumb/<render_view_id>/<most_visited_item_id>
  bool GenerateThumbnailURLFromTransientURL(const GURL& transient_url,
                                            GURL* url) const;

  // Returns the latest most visited items sent by the browser.
  void GetMostVisitedItems(
      std::vector<InstantMostVisitedItemIDPair>* items) const;

  // If the |most_visited_item_id| is found in the cache, sets |item| to it
  // and returns true.
  bool GetMostVisitedItemWithID(InstantRestrictedID most_visited_item_id,
                                InstantMostVisitedItem* item) const;

  // Sends ChromeViewHostMsg_FocusOmnibox to the browser.
  void Focus();

  // Sends ChromeViewHostMsg_SearchBoxNavigate to the browser.
  void NavigateToURL(const GURL& url,
                     WindowOpenDisposition disposition,
                     bool is_most_visited_item_url);

  // Sends ChromeViewHostMsg_SearchBoxPaste to the browser.
  void Paste(const string16& text);

  const ThemeBackgroundInfo& GetThemeBackgroundInfo();

  // Sends ChromeViewHostMsg_SetVoiceSearchSupported to the browser.
  void SetVoiceSearchSupported(bool supported);

  // Sends ChromeViewHostMsg_StartCapturingKeyStrokes to the browser.
  void StartCapturingKeyStrokes();

  // Sends ChromeViewHostMsg_StopCapturingKeyStrokes to the browser.
  void StopCapturingKeyStrokes();

  // Sends ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions to the
  // browser.
  void UndoAllMostVisitedDeletions();

  // Sends ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion to the browser.
  void UndoMostVisitedDeletion(InstantRestrictedID most_visited_item_id);

  bool app_launcher_enabled() const { return app_launcher_enabled_; }
  bool is_focused() const { return is_focused_; }
  bool is_input_in_progress() const { return is_input_in_progress_; }
  bool is_key_capture_enabled() const { return is_key_capture_enabled_; }
  bool display_instant_results() const { return display_instant_results_; }
  const string16& query() const { return query_; }
  int start_margin() const { return start_margin_; }
  const InstantSuggestion& suggestion() const { return suggestion_; }

 private:
  // Overridden from content::RenderViewObserver:
  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;

  void OnDetermineIfPageSupportsInstant();
  void OnFocusChanged(OmniboxFocusState new_focus_state,
                      OmniboxFocusChangeReason reason);
  void OnMarginChange(int margin, int width);
  void OnMostVisitedChanged(
      const std::vector<InstantMostVisitedItem>& items);
  void OnPromoInformationReceived(bool is_app_launcher_enabled);
  void OnSetDisplayInstantResults(bool display_instant_results);
  void OnSetInputInProgress(bool input_in_progress);
  void OnSetSuggestionToPrefetch(const InstantSuggestion& suggestion);
  void OnSubmit(const string16& query);
  void OnThemeChanged(const ThemeBackgroundInfo& theme_info);
  void OnToggleVoiceSearch();

  // Returns the current zoom factor of the render view or 1 on failure.
  double GetZoom() const;

  // Sets the searchbox values to their initial value.
  void Reset();

  // Returns the URL of the Most Visited item specified by the |item_id|.
  GURL GetURLForMostVisitedItem(InstantRestrictedID item_id) const;

  bool app_launcher_enabled_;
  bool is_focused_;
  bool is_input_in_progress_;
  bool is_key_capture_enabled_;
  bool display_instant_results_;
  InstantRestrictedIDCache<InstantMostVisitedItem> most_visited_items_cache_;
  ThemeBackgroundInfo theme_info_;
  string16 query_;
  int start_margin_;
  InstantSuggestion suggestion_;
  int width_;

  DISALLOW_COPY_AND_ASSIGN(SearchBox);
};

#endif  // CHROME_RENDERER_SEARCHBOX_SEARCHBOX_H_