Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: chrome/browser/instant/instant_client.cc

Issue 11824050: InstantExtended: Committed NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2012 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/instant/instant_client.h"
6
7 #include "base/utf_string_conversions.h"
8 #include "chrome/common/render_messages.h"
9 #include "content/public/browser/web_contents.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/font.h"
12
13 InstantClient::Delegate::~Delegate() {
14 }
15
16 InstantClient::InstantClient(Delegate* delegate) : delegate_(delegate) {
17 }
18
19 InstantClient::~InstantClient() {
20 }
21
22 void InstantClient::SetContents(content::WebContents* contents) {
23 Observe(contents);
24 }
25
26 void InstantClient::Update(const string16& text,
27 size_t selection_start,
28 size_t selection_end,
29 bool verbatim) {
30 Send(new ChromeViewMsg_SearchBoxChange(routing_id(), text, verbatim,
31 selection_start, selection_end));
32 }
33
34 void InstantClient::Submit(const string16& text) {
35 Send(new ChromeViewMsg_SearchBoxSubmit(routing_id(), text));
36 }
37
38 void InstantClient::Cancel(const string16& text) {
39 Send(new ChromeViewMsg_SearchBoxCancel(routing_id(), text));
40 }
41
42 void InstantClient::SetPopupBounds(const gfx::Rect& bounds) {
43 Send(new ChromeViewMsg_SearchBoxPopupResize(routing_id(), bounds));
44 }
45
46 void InstantClient::SetMarginSize(const int start, const int end) {
47 Send(new ChromeViewMsg_SearchBoxMarginChange(routing_id(), start, end));
48 }
49
50 void InstantClient::DetermineIfPageSupportsInstant() {
51 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id()));
52 }
53
54 void InstantClient::SendAutocompleteResults(
55 const std::vector<InstantAutocompleteResult>& results) {
56 Send(new ChromeViewMsg_SearchBoxAutocompleteResults(routing_id(), results));
57 }
58
59 void InstantClient::UpOrDownKeyPressed(int count) {
60 Send(new ChromeViewMsg_SearchBoxUpOrDownKeyPressed(routing_id(), count));
61 }
62
63 void InstantClient::SearchModeChanged(const chrome::search::Mode& mode) {
64 Send(new ChromeViewMsg_SearchBoxModeChanged(routing_id(), mode));
65 }
66
67 void InstantClient::SendThemeBackgroundInfo(
68 const ThemeBackgroundInfo& theme_info) {
69 Send(new ChromeViewMsg_SearchBoxThemeChanged(routing_id(), theme_info));
70 }
71
72 void InstantClient::SendThemeAreaHeight(int height) {
73 Send(new ChromeViewMsg_SearchBoxThemeAreaHeightChanged(routing_id(), height));
74 }
75
76 void InstantClient::SetDisplayInstantResults(bool display_instant_results) {
77 Send(new ChromeViewMsg_SearchBoxSetDisplayInstantResults(routing_id(),
78 display_instant_results));
79 }
80
81 void InstantClient::KeyCaptureChanged(bool is_key_capture_enabled) {
82 Send(new ChromeViewMsg_SearchBoxKeyCaptureChanged(routing_id(),
83 is_key_capture_enabled));
84 }
85
86 void InstantClient::DidFinishLoad(
87 int64 /* frame_id */,
88 const GURL& /* validated_url */,
89 bool is_main_frame,
90 content::RenderViewHost* /* render_view_host */) {
91 if (is_main_frame)
92 DetermineIfPageSupportsInstant();
93 }
94
95 bool InstantClient::OnMessageReceived(const IPC::Message& message) {
96 bool handled = true;
97 IPC_BEGIN_MESSAGE_MAP(InstantClient, message)
98 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetSuggestions, SetSuggestions)
99 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined,
100 InstantSupportDetermined)
101 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowInstantPreview,
102 ShowInstantPreview)
103 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_StartCapturingKeyStrokes,
104 StartCapturingKeyStrokes);
105 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_StopCapturingKeyStrokes,
106 StopCapturingKeyStrokes);
107 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate,
108 SearchBoxNavigate);
109 IPC_MESSAGE_UNHANDLED(handled = false)
110 IPC_END_MESSAGE_MAP()
111 return handled;
112 }
113
114 void InstantClient::RenderViewGone(base::TerminationStatus status) {
115 delegate_->RenderViewGone();
116 }
117
118 void InstantClient::DidCommitProvisionalLoadForFrame(
119 int64 frame_id,
120 bool is_main_frame,
121 const GURL& url,
122 content::PageTransition transition_type,
123 content::RenderViewHost* render_view_host) {
124 if (!is_main_frame)
125 return;
126 delegate_->AboutToNavigateMainFrame(url);
127 }
128
129 void InstantClient::SetSuggestions(
130 int page_id,
131 const std::vector<InstantSuggestion>& suggestions) {
132 if (web_contents()->IsActiveEntry(page_id))
133 delegate_->SetSuggestions(suggestions);
134 }
135
136 void InstantClient::InstantSupportDetermined(int page_id, bool result) {
137 if (result) {
138 // Inform the renderer process of the Omnibox's font information.
139 const gfx::Font& omnibox_font =
140 ui::ResourceBundle::GetSharedInstance().GetFont(
141 ui::ResourceBundle::MediumFont);
142 string16 omnibox_font_name = UTF8ToUTF16(omnibox_font.GetFontName());
143 size_t omnibox_font_size = omnibox_font.GetFontSize();
144
145 Send(new ChromeViewMsg_SearchBoxFontInformation(
146 routing_id(), omnibox_font_name, omnibox_font_size));
147 }
148 if (web_contents()->IsActiveEntry(page_id))
149 delegate_->InstantSupportDetermined(result);
150 }
151
152 void InstantClient::ShowInstantPreview(int page_id,
153 InstantShownReason reason,
154 int height,
155 InstantSizeUnits units) {
156 if (web_contents()->IsActiveEntry(page_id))
157 delegate_->ShowInstantPreview(reason, height, units);
158 }
159
160 void InstantClient::StartCapturingKeyStrokes(int page_id) {
161 if (web_contents()->IsActiveEntry(page_id))
162 delegate_->StartCapturingKeyStrokes();
163 }
164
165 void InstantClient::StopCapturingKeyStrokes(int page_id) {
166 if (web_contents()->IsActiveEntry(page_id))
167 delegate_->StopCapturingKeyStrokes();
168 }
169
170 void InstantClient::SearchBoxNavigate(int page_id,
171 const GURL& url,
172 content::PageTransition transition) {
173 if (web_contents()->IsActiveEntry(page_id))
174 delegate_->NavigateToURL(url, transition);
175 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698