OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/search/instant_page.h" | 5 #include "chrome/browser/ui/search/instant_page.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/search/search.h" | 8 #include "chrome/browser/search/search.h" |
| 9 #include "chrome/browser/ui/search/instant_ipc_sender.h" |
9 #include "chrome/browser/ui/search/search_model.h" | 10 #include "chrome/browser/ui/search/search_model.h" |
10 #include "chrome/browser/ui/search/search_tab_helper.h" | 11 #include "chrome/browser/ui/search/search_tab_helper.h" |
11 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
12 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
13 #include "content/public/browser/navigation_controller.h" | 14 #include "content/public/browser/navigation_controller.h" |
14 #include "content/public/browser/navigation_details.h" | 15 #include "content/public/browser/navigation_details.h" |
15 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
17 #include "content/public/common/frame_navigate_params.h" | 18 #include "content/public/common/frame_navigate_params.h" |
18 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
(...skipping 15 matching lines...) Expand all Loading... |
34 const std::string& InstantPage::instant_url() const { | 35 const std::string& InstantPage::instant_url() const { |
35 return instant_url_; | 36 return instant_url_; |
36 } | 37 } |
37 | 38 |
38 bool InstantPage::IsLocal() const { | 39 bool InstantPage::IsLocal() const { |
39 return contents() && | 40 return contents() && |
40 (contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl) || | 41 (contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl) || |
41 contents()->GetURL() == GURL(chrome::kChromeSearchLocalGoogleNtpUrl)); | 42 contents()->GetURL() == GURL(chrome::kChromeSearchLocalGoogleNtpUrl)); |
42 } | 43 } |
43 | 44 |
44 void InstantPage::Update(const string16& text, | |
45 size_t selection_start, | |
46 size_t selection_end, | |
47 bool verbatim) { | |
48 Send(new ChromeViewMsg_SearchBoxChange(routing_id(), text, verbatim, | |
49 selection_start, selection_end)); | |
50 } | |
51 | |
52 void InstantPage::Submit(const string16& text) { | |
53 Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text)); | |
54 } | |
55 | |
56 void InstantPage::Cancel(const string16& text) { | |
57 Send(new ChromeViewMsg_SearchBoxCancel(routing_id(), text)); | |
58 } | |
59 | |
60 void InstantPage::SetPopupBounds(const gfx::Rect& bounds) { | |
61 Send(new ChromeViewMsg_SearchBoxPopupResize(routing_id(), bounds)); | |
62 } | |
63 | |
64 void InstantPage::SetOmniboxBounds(const gfx::Rect& bounds) { | |
65 Send(new ChromeViewMsg_SearchBoxMarginChange( | |
66 routing_id(), bounds.x(), bounds.width())); | |
67 } | |
68 | |
69 void InstantPage::InitializeFonts() { | 45 void InstantPage::InitializeFonts() { |
70 #if defined(OS_MACOSX) | 46 #if defined(OS_MACOSX) |
71 // This value should be kept in sync with OmniboxViewMac::GetFieldFont. | 47 // This value should be kept in sync with OmniboxViewMac::GetFieldFont. |
72 const gfx::Font& omnibox_font = | 48 const gfx::Font& omnibox_font = |
73 ui::ResourceBundle::GetSharedInstance().GetFont( | 49 ui::ResourceBundle::GetSharedInstance().GetFont( |
74 ui::ResourceBundle::MediumFont).DeriveFont(1); | 50 ui::ResourceBundle::MediumFont).DeriveFont(1); |
75 #else | 51 #else |
76 const gfx::Font& omnibox_font = | 52 const gfx::Font& omnibox_font = |
77 ui::ResourceBundle::GetSharedInstance().GetFont( | 53 ui::ResourceBundle::GetSharedInstance().GetFont( |
78 ui::ResourceBundle::MediumFont); | 54 ui::ResourceBundle::MediumFont); |
79 #endif | 55 #endif |
80 string16 omnibox_font_name = UTF8ToUTF16(omnibox_font.GetFontName()); | 56 sender()->SetFontInformation(UTF8ToUTF16(omnibox_font.GetFontName()), |
81 size_t omnibox_font_size = omnibox_font.GetFontSize(); | 57 omnibox_font.GetFontSize()); |
82 Send(new ChromeViewMsg_SearchBoxFontInformation( | |
83 routing_id(), omnibox_font_name, omnibox_font_size)); | |
84 } | 58 } |
85 | 59 |
86 void InstantPage::SendAutocompleteResults( | 60 InstantPage::InstantPage(Delegate* delegate, const std::string& instant_url, |
87 const std::vector<InstantAutocompleteResult>& results) { | 61 bool is_incognito) |
88 Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results)); | |
89 } | |
90 | |
91 void InstantPage::UpOrDownKeyPressed(int count) { | |
92 Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count)); | |
93 } | |
94 | |
95 void InstantPage::EscKeyPressed() { | |
96 Send(new ChromeViewMsg_SearchBoxEscKeyPressed(routing_id())); | |
97 } | |
98 | |
99 void InstantPage::CancelSelection(const string16& user_text, | |
100 size_t selection_start, | |
101 size_t selection_end, | |
102 bool verbatim) { | |
103 Send(new ChromeViewMsg_SearchBoxCancelSelection( | |
104 routing_id(), user_text, verbatim, selection_start, selection_end)); | |
105 } | |
106 | |
107 void InstantPage::SendThemeBackgroundInfo( | |
108 const ThemeBackgroundInfo& theme_info) { | |
109 Send(new ChromeViewMsg_SearchBoxThemeChanged(routing_id(), theme_info)); | |
110 } | |
111 | |
112 void InstantPage::SetDisplayInstantResults(bool display_instant_results) { | |
113 Send(new ChromeViewMsg_SearchBoxSetDisplayInstantResults( | |
114 routing_id(), display_instant_results)); | |
115 } | |
116 | |
117 void InstantPage::FocusChanged(OmniboxFocusState state, | |
118 OmniboxFocusChangeReason reason) { | |
119 Send(new ChromeViewMsg_SearchBoxFocusChanged(routing_id(), state, reason)); | |
120 } | |
121 | |
122 void InstantPage::SetInputInProgress(bool input_in_progress) { | |
123 Send(new ChromeViewMsg_SearchBoxSetInputInProgress( | |
124 routing_id(), input_in_progress)); | |
125 } | |
126 | |
127 void InstantPage::SendMostVisitedItems( | |
128 const std::vector<InstantMostVisitedItem>& items) { | |
129 Send(new ChromeViewMsg_SearchBoxMostVisitedItemsChanged(routing_id(), items)); | |
130 } | |
131 | |
132 void InstantPage::ToggleVoiceSearch() { | |
133 Send(new ChromeViewMsg_SearchBoxToggleVoiceSearch(routing_id())); | |
134 } | |
135 | |
136 InstantPage::InstantPage(Delegate* delegate, const std::string& instant_url) | |
137 : delegate_(delegate), | 62 : delegate_(delegate), |
138 instant_url_(instant_url) { | 63 ipc_sender_(InstantIPCSender::Create(is_incognito)), |
| 64 instant_url_(instant_url), |
| 65 is_incognito_(is_incognito) { |
139 } | 66 } |
140 | 67 |
141 void InstantPage::SetContents(content::WebContents* web_contents) { | 68 void InstantPage::SetContents(content::WebContents* web_contents) { |
142 ClearContents(); | 69 ClearContents(); |
143 | 70 |
144 if (!web_contents) | 71 if (!web_contents) |
145 return; | 72 return; |
146 | 73 |
| 74 sender()->SetContents(web_contents); |
147 Observe(web_contents); | 75 Observe(web_contents); |
148 SearchModel* model = SearchTabHelper::FromWebContents(contents())->model(); | 76 SearchModel* model = SearchTabHelper::FromWebContents(contents())->model(); |
149 model->AddObserver(this); | 77 model->AddObserver(this); |
150 | 78 |
151 // Already know whether the page supports instant. | 79 // Already know whether the page supports instant. |
152 if (model->instant_support() != INSTANT_SUPPORT_UNKNOWN) | 80 if (model->instant_support() != INSTANT_SUPPORT_UNKNOWN) |
153 InstantSupportDetermined(model->instant_support() == INSTANT_SUPPORT_YES); | 81 InstantSupportDetermined(model->instant_support() == INSTANT_SUPPORT_YES); |
154 } | 82 } |
155 | 83 |
156 bool InstantPage::ShouldProcessRenderViewCreated() { | 84 bool InstantPage::ShouldProcessRenderViewCreated() { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 bool InstantPage::ShouldProcessUndoAllMostVisitedDeletions() { | 120 bool InstantPage::ShouldProcessUndoAllMostVisitedDeletions() { |
193 return false; | 121 return false; |
194 } | 122 } |
195 | 123 |
196 void InstantPage::RenderViewCreated(content::RenderViewHost* render_view_host) { | 124 void InstantPage::RenderViewCreated(content::RenderViewHost* render_view_host) { |
197 if (ShouldProcessRenderViewCreated()) | 125 if (ShouldProcessRenderViewCreated()) |
198 delegate_->InstantPageRenderViewCreated(contents()); | 126 delegate_->InstantPageRenderViewCreated(contents()); |
199 } | 127 } |
200 | 128 |
201 bool InstantPage::OnMessageReceived(const IPC::Message& message) { | 129 bool InstantPage::OnMessageReceived(const IPC::Message& message) { |
| 130 if (is_incognito_) |
| 131 return false; |
| 132 |
202 bool handled = true; | 133 bool handled = true; |
203 IPC_BEGIN_MESSAGE_MAP(InstantPage, message) | 134 IPC_BEGIN_MESSAGE_MAP(InstantPage, message) |
204 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) | 135 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, OnSetSuggestions) |
205 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowInstantOverlay, | 136 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowInstantOverlay, |
206 OnShowInstantOverlay) | 137 OnShowInstantOverlay) |
207 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FocusOmnibox, OnFocusOmnibox) | 138 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FocusOmnibox, OnFocusOmnibox) |
208 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate, | 139 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate, |
209 OnSearchBoxNavigate); | 140 OnSearchBoxNavigate); |
210 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem, | 141 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem, |
211 OnDeleteMostVisitedItem); | 142 OnDeleteMostVisitedItem); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 if (!ShouldProcessUndoAllMostVisitedDeletions()) | 283 if (!ShouldProcessUndoAllMostVisitedDeletions()) |
353 return; | 284 return; |
354 | 285 |
355 delegate_->UndoAllMostVisitedDeletions(); | 286 delegate_->UndoAllMostVisitedDeletions(); |
356 } | 287 } |
357 | 288 |
358 void InstantPage::ClearContents() { | 289 void InstantPage::ClearContents() { |
359 if (contents()) | 290 if (contents()) |
360 SearchTabHelper::FromWebContents(contents())->model()->RemoveObserver(this); | 291 SearchTabHelper::FromWebContents(contents())->model()->RemoveObserver(this); |
361 | 292 |
| 293 sender()->SetContents(NULL); |
362 Observe(NULL); | 294 Observe(NULL); |
363 } | 295 } |
OLD | NEW |