OLD | NEW |
(Empty) | |
| 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 Update(const string16& text, |
| 19 size_t selection_start, |
| 20 size_t selection_end, |
| 21 bool verbatim) OVERRIDE { |
| 22 Send(new ChromeViewMsg_SearchBoxChange(routing_id(), text, verbatim, |
| 23 selection_start, selection_end)); |
| 24 } |
| 25 |
| 26 virtual void Submit(const string16& text) OVERRIDE { |
| 27 Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text)); |
| 28 } |
| 29 |
| 30 virtual void Cancel(const string16& text) OVERRIDE { |
| 31 Send(new ChromeViewMsg_SearchBoxCancel(routing_id(), text)); |
| 32 } |
| 33 |
| 34 virtual void SetPopupBounds(const gfx::Rect& bounds) OVERRIDE { |
| 35 Send(new ChromeViewMsg_SearchBoxPopupResize(routing_id(), bounds)); |
| 36 } |
| 37 |
| 38 virtual void SetOmniboxBounds(const gfx::Rect& bounds) OVERRIDE { |
| 39 Send(new ChromeViewMsg_SearchBoxMarginChange( |
| 40 routing_id(), bounds.x(), bounds.width())); |
| 41 } |
| 42 |
| 43 virtual void SetFontInformation(const string16& omnibox_font_name, |
| 44 size_t omnibox_font_size) OVERRIDE { |
| 45 Send(new ChromeViewMsg_SearchBoxFontInformation( |
| 46 routing_id(), omnibox_font_name, omnibox_font_size)); |
| 47 } |
| 48 |
| 49 virtual void SendAutocompleteResults( |
| 50 const std::vector<InstantAutocompleteResult>& results) OVERRIDE { |
| 51 Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results)); |
| 52 } |
| 53 |
| 54 virtual void UpOrDownKeyPressed(int count) OVERRIDE { |
| 55 Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count)); |
| 56 } |
| 57 |
| 58 virtual void EscKeyPressed() OVERRIDE { |
| 59 Send(new ChromeViewMsg_SearchBoxEscKeyPressed(routing_id())); |
| 60 } |
| 61 |
| 62 virtual void CancelSelection(const string16& user_text, |
| 63 size_t selection_start, |
| 64 size_t selection_end, |
| 65 bool verbatim) OVERRIDE { |
| 66 Send(new ChromeViewMsg_SearchBoxCancelSelection( |
| 67 routing_id(), user_text, verbatim, selection_start, selection_end)); |
| 68 } |
| 69 |
| 70 virtual void SendThemeBackgroundInfo( |
| 71 const ThemeBackgroundInfo& theme_info) OVERRIDE { |
| 72 Send(new ChromeViewMsg_SearchBoxThemeChanged(routing_id(), theme_info)); |
| 73 } |
| 74 |
| 75 virtual void SetDisplayInstantResults(bool display_instant_results) OVERRIDE { |
| 76 Send(new ChromeViewMsg_SearchBoxSetDisplayInstantResults( |
| 77 routing_id(), display_instant_results)); |
| 78 } |
| 79 |
| 80 virtual void FocusChanged(OmniboxFocusState state, |
| 81 OmniboxFocusChangeReason reason) OVERRIDE { |
| 82 Send(new ChromeViewMsg_SearchBoxFocusChanged(routing_id(), state, reason)); |
| 83 } |
| 84 |
| 85 virtual void SetInputInProgress(bool input_in_progress) OVERRIDE { |
| 86 Send(new ChromeViewMsg_SearchBoxSetInputInProgress( |
| 87 routing_id(), input_in_progress)); |
| 88 } |
| 89 |
| 90 virtual void SendMostVisitedItems( |
| 91 const std::vector<InstantMostVisitedItem>& items) OVERRIDE { |
| 92 Send(new ChromeViewMsg_SearchBoxMostVisitedItemsChanged( |
| 93 routing_id(), items)); |
| 94 } |
| 95 |
| 96 virtual void ToggleVoiceSearch() OVERRIDE { |
| 97 Send(new ChromeViewMsg_SearchBoxToggleVoiceSearch(routing_id())); |
| 98 } |
| 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(InstantIPCSenderImpl); |
| 101 }; |
| 102 |
| 103 // Implementation for incognito profiles. |
| 104 class IncognitoInstantIPCSenderImpl : public InstantIPCSender { |
| 105 public: |
| 106 IncognitoInstantIPCSenderImpl() {} |
| 107 virtual ~IncognitoInstantIPCSenderImpl() {} |
| 108 |
| 109 private: |
| 110 virtual void Submit(const string16& text) OVERRIDE { |
| 111 Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text)); |
| 112 } |
| 113 |
| 114 virtual void SetOmniboxBounds(const gfx::Rect& bounds) OVERRIDE { |
| 115 Send(new ChromeViewMsg_SearchBoxMarginChange( |
| 116 routing_id(), bounds.x(), bounds.width())); |
| 117 } |
| 118 |
| 119 DISALLOW_COPY_AND_ASSIGN(IncognitoInstantIPCSenderImpl); |
| 120 }; |
| 121 |
| 122 } // anonymous namespace |
| 123 |
| 124 // static |
| 125 scoped_ptr<InstantIPCSender> InstantIPCSender::Create(bool is_incognito) { |
| 126 scoped_ptr<InstantIPCSender> sender( |
| 127 is_incognito ? |
| 128 static_cast<InstantIPCSender*>(new IncognitoInstantIPCSenderImpl()) : |
| 129 static_cast<InstantIPCSender*>(new InstantIPCSenderImpl())); |
| 130 return sender.Pass(); |
| 131 } |
| 132 |
| 133 void InstantIPCSender::SetContents(content::WebContents* web_contents) { |
| 134 Observe(web_contents); |
| 135 } |
OLD | NEW |