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

Side by Side Diff: chrome/renderer/searchbox/searchbox_extension.cc

Issue 11413217: Instant API: tell page whether the browser is capturing key strokes. (Closed) Base URL: http://git.chromium.org/chromium/src.git@focus
Patch Set: Fix tests. Created 8 years 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
« no previous file with comments | « chrome/renderer/searchbox/searchbox_extension.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 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/renderer/searchbox/searchbox_extension.h" 5 #include "chrome/renderer/searchbox/searchbox_extension.h"
6 6
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "chrome/common/extensions/extension.h" 9 #include "chrome/common/extensions/extension.h"
10 #include "chrome/renderer/searchbox/searchbox.h" 10 #include "chrome/renderer/searchbox/searchbox.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 static const char kDispatchUpOrDownKeyPressEventScript[] = 134 static const char kDispatchUpOrDownKeyPressEventScript[] =
135 "if (window.chrome &&" 135 "if (window.chrome &&"
136 " window.chrome.searchBox &&" 136 " window.chrome.searchBox &&"
137 " window.chrome.searchBox.onkeypress &&" 137 " window.chrome.searchBox.onkeypress &&"
138 " typeof window.chrome.searchBox.onkeypress == 'function') {" 138 " typeof window.chrome.searchBox.onkeypress == 'function') {"
139 " for (var i = 0; i < %d; ++i)" 139 " for (var i = 0; i < %d; ++i)"
140 " window.chrome.searchBox.onkeypress({keyCode: %d});" 140 " window.chrome.searchBox.onkeypress({keyCode: %d});"
141 " true;" 141 " true;"
142 "}"; 142 "}";
143 143
144 static const char kDispatchKeyCaptureChangeScript[] =
145 "if (window.chrome &&"
146 " window.chrome.searchBox &&"
147 " window.chrome.searchBox.onkeycapturechange &&"
148 " typeof window.chrome.searchBox.onkeycapturechange == 'function') {"
149 " window.chrome.searchBox.onkeycapturechange();"
150 " true;"
151 "}";
152
144 static const char kDispatchContextChangeEventScript[] = 153 static const char kDispatchContextChangeEventScript[] =
145 "if (window.chrome &&" 154 "if (window.chrome &&"
146 " window.chrome.searchBox &&" 155 " window.chrome.searchBox &&"
147 " window.chrome.searchBox.oncontextchange &&" 156 " window.chrome.searchBox.oncontextchange &&"
148 " typeof window.chrome.searchBox.oncontextchange == 'function') {" 157 " typeof window.chrome.searchBox.oncontextchange == 'function') {"
149 " window.chrome.searchBox.oncontextchange();" 158 " window.chrome.searchBox.oncontextchange();"
150 " true;" 159 " true;"
151 "}"; 160 "}";
152 161
153 static const char kDispatchThemeChangeEventScript[] = 162 static const char kDispatchThemeChangeEventScript[] =
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 static v8::Handle<v8::Value> GetThemeBackgroundInfo( 236 static v8::Handle<v8::Value> GetThemeBackgroundInfo(
228 const v8::Arguments& args); 237 const v8::Arguments& args);
229 238
230 // Gets the theme area height that the entire theme background image should 239 // Gets the theme area height that the entire theme background image should
231 // fill up. 240 // fill up.
232 // Call only when overlay is showing NTP page and GetThemeBackgroundInfo 241 // Call only when overlay is showing NTP page and GetThemeBackgroundInfo
233 // returns a non-empty image_url and an image_vertical_alignment that is not 242 // returns a non-empty image_url and an image_vertical_alignment that is not
234 // "top". 243 // "top".
235 static v8::Handle<v8::Value> GetThemeAreaHeight(const v8::Arguments& args); 244 static v8::Handle<v8::Value> GetThemeAreaHeight(const v8::Arguments& args);
236 245
246 // Gets whether the browser is capturing key strokes.
247 static v8::Handle<v8::Value> IsKeyCaptureEnabled(const v8::Arguments& args);
248
237 // Navigates the window to a URL represented by either a URL string or a 249 // Navigates the window to a URL represented by either a URL string or a
238 // restricted ID. 250 // restricted ID.
239 static v8::Handle<v8::Value> NavigateContentWindow(const v8::Arguments& args); 251 static v8::Handle<v8::Value> NavigateContentWindow(const v8::Arguments& args);
240 252
241 // Sets ordered suggestions. Valid for current |value|. 253 // Sets ordered suggestions. Valid for current |value|.
242 static v8::Handle<v8::Value> SetSuggestions(const v8::Arguments& args); 254 static v8::Handle<v8::Value> SetSuggestions(const v8::Arguments& args);
243 255
244 // Sets the text to be autocompleted into the search box. 256 // Sets the text to be autocompleted into the search box.
245 static v8::Handle<v8::Value> SetQuerySuggestion(const v8::Arguments& args); 257 static v8::Handle<v8::Value> SetQuerySuggestion(const v8::Arguments& args);
246 258
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 if (name->Equals(v8::String::New("GetAutocompleteResults"))) 308 if (name->Equals(v8::String::New("GetAutocompleteResults")))
297 return v8::FunctionTemplate::New(GetAutocompleteResults); 309 return v8::FunctionTemplate::New(GetAutocompleteResults);
298 if (name->Equals(v8::String::New("GetContext"))) 310 if (name->Equals(v8::String::New("GetContext")))
299 return v8::FunctionTemplate::New(GetContext); 311 return v8::FunctionTemplate::New(GetContext);
300 if (name->Equals(v8::String::New("GetDisplayInstantResults"))) 312 if (name->Equals(v8::String::New("GetDisplayInstantResults")))
301 return v8::FunctionTemplate::New(GetDisplayInstantResults); 313 return v8::FunctionTemplate::New(GetDisplayInstantResults);
302 if (name->Equals(v8::String::New("GetThemeBackgroundInfo"))) 314 if (name->Equals(v8::String::New("GetThemeBackgroundInfo")))
303 return v8::FunctionTemplate::New(GetThemeBackgroundInfo); 315 return v8::FunctionTemplate::New(GetThemeBackgroundInfo);
304 if (name->Equals(v8::String::New("GetThemeAreaHeight"))) 316 if (name->Equals(v8::String::New("GetThemeAreaHeight")))
305 return v8::FunctionTemplate::New(GetThemeAreaHeight); 317 return v8::FunctionTemplate::New(GetThemeAreaHeight);
318 if (name->Equals(v8::String::New("IsKeyCaptureEnabled")))
319 return v8::FunctionTemplate::New(IsKeyCaptureEnabled);
306 if (name->Equals(v8::String::New("NavigateContentWindow"))) 320 if (name->Equals(v8::String::New("NavigateContentWindow")))
307 return v8::FunctionTemplate::New(NavigateContentWindow); 321 return v8::FunctionTemplate::New(NavigateContentWindow);
308 if (name->Equals(v8::String::New("SetSuggestions"))) 322 if (name->Equals(v8::String::New("SetSuggestions")))
309 return v8::FunctionTemplate::New(SetSuggestions); 323 return v8::FunctionTemplate::New(SetSuggestions);
310 if (name->Equals(v8::String::New("SetQuerySuggestion"))) 324 if (name->Equals(v8::String::New("SetQuerySuggestion")))
311 return v8::FunctionTemplate::New(SetQuerySuggestion); 325 return v8::FunctionTemplate::New(SetQuerySuggestion);
312 if (name->Equals(v8::String::New("SetQuerySuggestionFromAutocompleteResult"))) 326 if (name->Equals(v8::String::New("SetQuerySuggestionFromAutocompleteResult")))
313 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult); 327 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult);
314 if (name->Equals(v8::String::New("SetQuery"))) 328 if (name->Equals(v8::String::New("SetQuery")))
315 return v8::FunctionTemplate::New(SetQuery); 329 return v8::FunctionTemplate::New(SetQuery);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 ranking_data->Set(v8::String::New("relevance"), 452 ranking_data->Set(v8::String::New("relevance"),
439 v8::Int32::New(results[i].relevance)); 453 v8::Int32::New(results[i].relevance));
440 result->Set(v8::String::New("rankingData"), ranking_data); 454 result->Set(v8::String::New("rankingData"), ranking_data);
441 455
442 results_array->Set(i, result); 456 results_array->Set(i, result);
443 } 457 }
444 return results_array; 458 return results_array;
445 } 459 }
446 460
447 // static 461 // static
462 v8::Handle<v8::Value> SearchBoxExtensionWrapper::IsKeyCaptureEnabled(
463 const v8::Arguments& args) {
464 content::RenderView* render_view = GetRenderView();
465 if (!render_view) return v8::Undefined();
466
467 return v8::Boolean::New(SearchBox::Get(render_view)->
468 is_key_capture_enabled());
469 }
470
471 // static
448 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetContext( 472 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetContext(
449 const v8::Arguments& args) { 473 const v8::Arguments& args) {
450 content::RenderView* render_view = GetRenderView(); 474 content::RenderView* render_view = GetRenderView();
451 if (!render_view) return v8::Undefined(); 475 if (!render_view) return v8::Undefined();
452 476
453 const chrome::search::Mode& mode = SearchBox::Get(render_view)->mode(); 477 const chrome::search::Mode& mode = SearchBox::Get(render_view)->mode();
454 DVLOG(1) << render_view << " GetContext: " << mode.origin << ":" << mode.mode; 478 DVLOG(1) << render_view << " GetContext: " << mode.origin << ":" << mode.mode;
455 v8::Handle<v8::Object> context = v8::Object::New(); 479 v8::Handle<v8::Object> context = v8::Object::New();
456 context->Set(v8::String::New("isNewTabPage"), 480 context->Set(v8::String::New("isNewTabPage"),
457 v8::Boolean::New(mode.is_ntp())); 481 v8::Boolean::New(mode.is_ntp()));
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 847
824 // static 848 // static
825 void SearchBoxExtension::DispatchUpOrDownKeyPress(WebKit::WebFrame* frame, 849 void SearchBoxExtension::DispatchUpOrDownKeyPress(WebKit::WebFrame* frame,
826 int count) { 850 int count) {
827 Dispatch(frame, WebKit::WebString::fromUTF8( 851 Dispatch(frame, WebKit::WebString::fromUTF8(
828 base::StringPrintf(kDispatchUpOrDownKeyPressEventScript, abs(count), 852 base::StringPrintf(kDispatchUpOrDownKeyPressEventScript, abs(count),
829 count < 0 ? ui::VKEY_UP : ui::VKEY_DOWN))); 853 count < 0 ? ui::VKEY_UP : ui::VKEY_DOWN)));
830 } 854 }
831 855
832 // static 856 // static
857 void SearchBoxExtension::DispatchKeyCaptureChange(WebKit::WebFrame* frame) {
858 Dispatch(frame, kDispatchKeyCaptureChangeScript);
859 }
860
861 // static
833 void SearchBoxExtension::DispatchContextChange(WebKit::WebFrame* frame) { 862 void SearchBoxExtension::DispatchContextChange(WebKit::WebFrame* frame) {
834 Dispatch(frame, kDispatchContextChangeEventScript); 863 Dispatch(frame, kDispatchContextChangeEventScript);
835 } 864 }
836 865
837 // static 866 // static
838 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) { 867 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) {
839 Dispatch(frame, kDispatchThemeChangeEventScript); 868 Dispatch(frame, kDispatchThemeChangeEventScript);
840 } 869 }
841 870
842 // static 871 // static
843 void SearchBoxExtension::DispatchThemeAreaHeightChange( 872 void SearchBoxExtension::DispatchThemeAreaHeightChange(
844 WebKit::WebFrame* frame) { 873 WebKit::WebFrame* frame) {
845 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); 874 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript);
846 } 875 }
847 876
848 // static 877 // static
849 v8::Extension* SearchBoxExtension::Get() { 878 v8::Extension* SearchBoxExtension::Get() {
850 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). 879 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance().
851 GetRawDataResource(IDR_SEARCHBOX_API)); 880 GetRawDataResource(IDR_SEARCHBOX_API));
852 } 881 }
853 882
854 } // namespace extensions_v8 883 } // namespace extensions_v8
OLDNEW
« no previous file with comments | « chrome/renderer/searchbox/searchbox_extension.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698