17271b53cd4591211e86988882d093448e13ec88
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / search / instant_ipc_sender.cc
1 // Copyright 2013 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 #include "chrome/browser/ui/search/instant_ipc_sender.h"
6
7 #include "chrome/common/render_messages.h"
8
9 namespace {
10
11 // Implementation for regular profiles.
12 class InstantIPCSenderImpl : public InstantIPCSender {
13  public:
14   InstantIPCSenderImpl() {}
15   virtual ~InstantIPCSenderImpl() {}
16
17  private:
18   virtual void SetOmniboxBounds(const gfx::Rect& bounds) OVERRIDE {
19     Send(new ChromeViewMsg_SearchBoxMarginChange(
20         routing_id(), bounds.x(), bounds.width()));
21   }
22
23   virtual void FocusChanged(OmniboxFocusState state,
24                     OmniboxFocusChangeReason reason) OVERRIDE {
25     Send(new ChromeViewMsg_SearchBoxFocusChanged(routing_id(), state, reason));
26   }
27
28   virtual void SetInputInProgress(bool input_in_progress) OVERRIDE {
29     Send(new ChromeViewMsg_SearchBoxSetInputInProgress(
30         routing_id(), input_in_progress));
31   }
32
33   DISALLOW_COPY_AND_ASSIGN(InstantIPCSenderImpl);
34 };
35
36 // Implementation for incognito profiles.
37 class IncognitoInstantIPCSenderImpl : public InstantIPCSender {
38  public:
39   IncognitoInstantIPCSenderImpl() {}
40   virtual ~IncognitoInstantIPCSenderImpl() {}
41
42  private:
43   virtual void SetOmniboxBounds(const gfx::Rect& bounds) OVERRIDE {
44     Send(new ChromeViewMsg_SearchBoxMarginChange(
45         routing_id(), bounds.x(), bounds.width()));
46   }
47
48   DISALLOW_COPY_AND_ASSIGN(IncognitoInstantIPCSenderImpl);
49 };
50
51 }  // anonymous namespace
52
53 // static
54 scoped_ptr<InstantIPCSender> InstantIPCSender::Create(bool is_incognito) {
55   scoped_ptr<InstantIPCSender> sender(
56       is_incognito ?
57       static_cast<InstantIPCSender*>(new IncognitoInstantIPCSenderImpl()) :
58       static_cast<InstantIPCSender*>(new InstantIPCSenderImpl()));
59   return sender.Pass();
60 }
61
62 void InstantIPCSender::SetContents(content::WebContents* web_contents) {
63   Observe(web_contents);
64 }