summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/search/instant_ipc_sender.cc
blob: 4150259e3787df4fc60d21af710d6badd7c399ca (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
// Copyright 2013 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.

#include "chrome/browser/ui/search/instant_ipc_sender.h"

#include "chrome/common/render_messages.h"

namespace {

// Implementation for regular profiles.
class InstantIPCSenderImpl : public InstantIPCSender {
 public:
  InstantIPCSenderImpl() {}
  virtual ~InstantIPCSenderImpl() {}

 private:
  virtual void Update(const string16& text,
                      size_t selection_start,
                      size_t selection_end,
                      bool verbatim) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxChange(routing_id(), text, verbatim,
                                           selection_start, selection_end));
  }

  virtual void Submit(const string16& text) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text));
  }

  virtual void Cancel(const string16& text) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxCancel(routing_id(), text));
  }

  virtual void SetPopupBounds(const gfx::Rect& bounds) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxPopupResize(routing_id(), bounds));
  }

  virtual void SetOmniboxBounds(const gfx::Rect& bounds) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxMarginChange(
        routing_id(), bounds.x(), bounds.width()));
  }

  virtual void SetFontInformation(const string16& omnibox_font_name,
                          size_t omnibox_font_size) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxFontInformation(
        routing_id(), omnibox_font_name, omnibox_font_size));
  }

  virtual void SetPromoInformation(bool is_app_launcher_enabled) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxPromoInformation(
        routing_id(), is_app_launcher_enabled));
  }

  virtual void SendAutocompleteResults(
      const std::vector<InstantAutocompleteResult>& results) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results));
  }

  virtual void UpOrDownKeyPressed(int count) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count));
  }

  virtual void EscKeyPressed() OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxEscKeyPressed(routing_id()));
  }

  virtual void CancelSelection(const string16& user_text,
                               size_t selection_start,
                               size_t selection_end,
                               bool verbatim) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxCancelSelection(
        routing_id(), user_text, verbatim, selection_start, selection_end));
  }

  virtual void SendThemeBackgroundInfo(
      const ThemeBackgroundInfo& theme_info) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxThemeChanged(routing_id(), theme_info));
  }

  virtual void SetDisplayInstantResults(bool display_instant_results) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxSetDisplayInstantResults(
        routing_id(), display_instant_results));
  }

  virtual void FocusChanged(OmniboxFocusState state,
                    OmniboxFocusChangeReason reason) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxFocusChanged(routing_id(), state, reason));
  }

  virtual void SetInputInProgress(bool input_in_progress) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxSetInputInProgress(
        routing_id(), input_in_progress));
  }

  virtual void SendMostVisitedItems(
      const std::vector<InstantMostVisitedItem>& items) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxMostVisitedItemsChanged(
        routing_id(), items));
  }

  virtual void ToggleVoiceSearch() OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxToggleVoiceSearch(routing_id()));
  }

  DISALLOW_COPY_AND_ASSIGN(InstantIPCSenderImpl);
};

// Implementation for incognito profiles.
class IncognitoInstantIPCSenderImpl : public InstantIPCSender {
 public:
  IncognitoInstantIPCSenderImpl() {}
  virtual ~IncognitoInstantIPCSenderImpl() {}

 private:
  virtual void Submit(const string16& text) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text));
  }

  virtual void SetOmniboxBounds(const gfx::Rect& bounds) OVERRIDE {
    Send(new ChromeViewMsg_SearchBoxMarginChange(
        routing_id(), bounds.x(), bounds.width()));
  }

  DISALLOW_COPY_AND_ASSIGN(IncognitoInstantIPCSenderImpl);
};

}  // anonymous namespace

// static
scoped_ptr<InstantIPCSender> InstantIPCSender::Create(bool is_incognito) {
  scoped_ptr<InstantIPCSender> sender(
      is_incognito ?
      static_cast<InstantIPCSender*>(new IncognitoInstantIPCSenderImpl()) :
      static_cast<InstantIPCSender*>(new InstantIPCSenderImpl()));
  return sender.Pass();
}

void InstantIPCSender::SetContents(content::WebContents* web_contents) {
  Observe(web_contents);
}