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 Submit(const string16& text) OVERRIDE { 19 Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text)); 20 } 21 22 virtual void SetOmniboxBounds(const gfx::Rect& bounds) OVERRIDE { 23 Send(new ChromeViewMsg_SearchBoxMarginChange( 24 routing_id(), bounds.x(), bounds.width())); 25 } 26 27 virtual void SetFontInformation(const string16& omnibox_font_name, 28 size_t omnibox_font_size) OVERRIDE { 29 Send(new ChromeViewMsg_SearchBoxFontInformation( 30 routing_id(), omnibox_font_name, omnibox_font_size)); 31 } 32 33 virtual void SetPromoInformation(bool is_app_launcher_enabled) OVERRIDE { 34 Send(new ChromeViewMsg_SearchBoxPromoInformation( 35 routing_id(), is_app_launcher_enabled)); 36 } 37 38 virtual void SendThemeBackgroundInfo( 39 const ThemeBackgroundInfo& theme_info) OVERRIDE { 40 Send(new ChromeViewMsg_SearchBoxThemeChanged(routing_id(), theme_info)); 41 } 42 43 virtual void FocusChanged(OmniboxFocusState state, 44 OmniboxFocusChangeReason reason) OVERRIDE { 45 Send(new ChromeViewMsg_SearchBoxFocusChanged(routing_id(), state, reason)); 46 } 47 48 virtual void SetInputInProgress(bool input_in_progress) OVERRIDE { 49 Send(new ChromeViewMsg_SearchBoxSetInputInProgress( 50 routing_id(), input_in_progress)); 51 } 52 53 virtual void SendMostVisitedItems( 54 const std::vector<InstantMostVisitedItem>& items) OVERRIDE { 55 Send(new ChromeViewMsg_SearchBoxMostVisitedItemsChanged( 56 routing_id(), items)); 57 } 58 59 virtual void ToggleVoiceSearch() OVERRIDE { 60 Send(new ChromeViewMsg_SearchBoxToggleVoiceSearch(routing_id())); 61 } 62 63 DISALLOW_COPY_AND_ASSIGN(InstantIPCSenderImpl); 64 }; 65 66 // Implementation for incognito profiles. 67 class IncognitoInstantIPCSenderImpl : public InstantIPCSender { 68 public: 69 IncognitoInstantIPCSenderImpl() {} 70 virtual ~IncognitoInstantIPCSenderImpl() {} 71 72 private: 73 virtual void Submit(const string16& text) OVERRIDE { 74 Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text)); 75 } 76 77 virtual void SetOmniboxBounds(const gfx::Rect& bounds) OVERRIDE { 78 Send(new ChromeViewMsg_SearchBoxMarginChange( 79 routing_id(), bounds.x(), bounds.width())); 80 } 81 82 virtual void ToggleVoiceSearch() OVERRIDE { 83 Send(new ChromeViewMsg_SearchBoxToggleVoiceSearch(routing_id())); 84 } 85 86 DISALLOW_COPY_AND_ASSIGN(IncognitoInstantIPCSenderImpl); 87 }; 88 89 } // anonymous namespace 90 91 // static 92 scoped_ptr<InstantIPCSender> InstantIPCSender::Create(bool is_incognito) { 93 scoped_ptr<InstantIPCSender> sender( 94 is_incognito ? 95 static_cast<InstantIPCSender*>(new IncognitoInstantIPCSenderImpl()) : 96 static_cast<InstantIPCSender*>(new InstantIPCSenderImpl())); 97 return sender.Pass(); 98 } 99 100 void InstantIPCSender::SetContents(content::WebContents* web_contents) { 101 Observe(web_contents); 102 } 103