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

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: Rebase. Addressed comments. 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
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 static const char kDispatchUpOrDownKeyPressEventScript[] = 124 static const char kDispatchUpOrDownKeyPressEventScript[] =
125 "if (window.chrome &&" 125 "if (window.chrome &&"
126 " window.chrome.searchBox &&" 126 " window.chrome.searchBox &&"
127 " window.chrome.searchBox.onkeypress &&" 127 " window.chrome.searchBox.onkeypress &&"
128 " typeof window.chrome.searchBox.onkeypress == 'function') {" 128 " typeof window.chrome.searchBox.onkeypress == 'function') {"
129 " for (var i = 0; i < %d; ++i)" 129 " for (var i = 0; i < %d; ++i)"
130 " window.chrome.searchBox.onkeypress({keyCode: %d});" 130 " window.chrome.searchBox.onkeypress({keyCode: %d});"
131 " true;" 131 " true;"
132 "}"; 132 "}";
133 133
134 static const char kDispatchKeyCaptureChangeScript[] =
135 "if (window.chrome &&"
136 " window.chrome.searchBox &&"
137 " window.chrome.searchBox.onkeycapturechange &&"
138 " typeof window.chrome.searchBox.onkeycapturechange == 'function') {"
139 " window.chrome.searchBox.onkeycapturechange();"
140 " true;"
141 "}";
142
134 static const char kDispatchContextChangeEventScript[] = 143 static const char kDispatchContextChangeEventScript[] =
135 "if (window.chrome &&" 144 "if (window.chrome &&"
136 " window.chrome.searchBox &&" 145 " window.chrome.searchBox &&"
137 " window.chrome.searchBox.oncontextchange &&" 146 " window.chrome.searchBox.oncontextchange &&"
138 " typeof window.chrome.searchBox.oncontextchange == 'function') {" 147 " typeof window.chrome.searchBox.oncontextchange == 'function') {"
139 " window.chrome.searchBox.oncontextchange();" 148 " window.chrome.searchBox.oncontextchange();"
140 " true;" 149 " true;"
141 "}"; 150 "}";
142 151
143 static const char kDispatchThemeChangeEventScript[] = 152 static const char kDispatchThemeChangeEventScript[] =
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 static v8::Handle<v8::Value> GetThemeBackgroundInfo( 222 static v8::Handle<v8::Value> GetThemeBackgroundInfo(
214 const v8::Arguments& args); 223 const v8::Arguments& args);
215 224
216 // Gets the theme area height that the entire theme background image should 225 // Gets the theme area height that the entire theme background image should
217 // fill up. 226 // fill up.
218 // Call only when overlay is showing NTP page and GetThemeBackgroundInfo 227 // Call only when overlay is showing NTP page and GetThemeBackgroundInfo
219 // returns a non-empty image_url and an image_vertical_alignment that is not 228 // returns a non-empty image_url and an image_vertical_alignment that is not
220 // "top". 229 // "top".
221 static v8::Handle<v8::Value> GetThemeAreaHeight(const v8::Arguments& args); 230 static v8::Handle<v8::Value> GetThemeAreaHeight(const v8::Arguments& args);
222 231
232 // Gets whether the browser is capturing key strokes.
233 static v8::Handle<v8::Value> IsKeyCaptureEnabled(const v8::Arguments& args);
234
223 // Navigates the window to a URL represented by either a URL string or a 235 // Navigates the window to a URL represented by either a URL string or a
224 // restricted ID. 236 // restricted ID.
225 static v8::Handle<v8::Value> NavigateContentWindow(const v8::Arguments& args); 237 static v8::Handle<v8::Value> NavigateContentWindow(const v8::Arguments& args);
226 238
227 // Sets ordered suggestions. Valid for current |value|. 239 // Sets ordered suggestions. Valid for current |value|.
228 static v8::Handle<v8::Value> SetSuggestions(const v8::Arguments& args); 240 static v8::Handle<v8::Value> SetSuggestions(const v8::Arguments& args);
229 241
230 // Sets the text to be autocompleted into the search box. 242 // Sets the text to be autocompleted into the search box.
231 static v8::Handle<v8::Value> SetQuerySuggestion(const v8::Arguments& args); 243 static v8::Handle<v8::Value> SetQuerySuggestion(const v8::Arguments& args);
232 244
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 if (name->Equals(v8::String::New("GetHeight"))) 292 if (name->Equals(v8::String::New("GetHeight")))
281 return v8::FunctionTemplate::New(GetHeight); 293 return v8::FunctionTemplate::New(GetHeight);
282 if (name->Equals(v8::String::New("GetAutocompleteResults"))) 294 if (name->Equals(v8::String::New("GetAutocompleteResults")))
283 return v8::FunctionTemplate::New(GetAutocompleteResults); 295 return v8::FunctionTemplate::New(GetAutocompleteResults);
284 if (name->Equals(v8::String::New("GetContext"))) 296 if (name->Equals(v8::String::New("GetContext")))
285 return v8::FunctionTemplate::New(GetContext); 297 return v8::FunctionTemplate::New(GetContext);
286 if (name->Equals(v8::String::New("GetThemeBackgroundInfo"))) 298 if (name->Equals(v8::String::New("GetThemeBackgroundInfo")))
287 return v8::FunctionTemplate::New(GetThemeBackgroundInfo); 299 return v8::FunctionTemplate::New(GetThemeBackgroundInfo);
288 if (name->Equals(v8::String::New("GetThemeAreaHeight"))) 300 if (name->Equals(v8::String::New("GetThemeAreaHeight")))
289 return v8::FunctionTemplate::New(GetThemeAreaHeight); 301 return v8::FunctionTemplate::New(GetThemeAreaHeight);
302 if (name->Equals(v8::String::New("IsKeyCaptureEnabled")))
303 return v8::FunctionTemplate::New(IsKeyCaptureEnabled);
290 if (name->Equals(v8::String::New("NavigateContentWindow"))) 304 if (name->Equals(v8::String::New("NavigateContentWindow")))
291 return v8::FunctionTemplate::New(NavigateContentWindow); 305 return v8::FunctionTemplate::New(NavigateContentWindow);
292 if (name->Equals(v8::String::New("SetSuggestions"))) 306 if (name->Equals(v8::String::New("SetSuggestions")))
293 return v8::FunctionTemplate::New(SetSuggestions); 307 return v8::FunctionTemplate::New(SetSuggestions);
294 if (name->Equals(v8::String::New("SetQuerySuggestion"))) 308 if (name->Equals(v8::String::New("SetQuerySuggestion")))
295 return v8::FunctionTemplate::New(SetQuerySuggestion); 309 return v8::FunctionTemplate::New(SetQuerySuggestion);
296 if (name->Equals(v8::String::New("SetQuerySuggestionFromAutocompleteResult"))) 310 if (name->Equals(v8::String::New("SetQuerySuggestionFromAutocompleteResult")))
297 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult); 311 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult);
298 if (name->Equals(v8::String::New("SetQuery"))) 312 if (name->Equals(v8::String::New("SetQuery")))
299 return v8::FunctionTemplate::New(SetQuery); 313 return v8::FunctionTemplate::New(SetQuery);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 ranking_data->Set(v8::String::New("relevance"), 434 ranking_data->Set(v8::String::New("relevance"),
421 v8::Int32::New(results[i].relevance)); 435 v8::Int32::New(results[i].relevance));
422 result->Set(v8::String::New("rankingData"), ranking_data); 436 result->Set(v8::String::New("rankingData"), ranking_data);
423 437
424 results_array->Set(i, result); 438 results_array->Set(i, result);
425 } 439 }
426 return results_array; 440 return results_array;
427 } 441 }
428 442
429 // static 443 // static
444 v8::Handle<v8::Value> SearchBoxExtensionWrapper::IsKeyCaptureEnabled(
445 const v8::Arguments& args) {
446 content::RenderView* render_view = GetRenderView();
447 if (!render_view) return v8::Undefined();
448
449 return v8::Boolean::New(SearchBox::Get(render_view)->
450 is_key_capture_enabled());
451 }
452
453 // static
430 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetContext( 454 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetContext(
431 const v8::Arguments& args) { 455 const v8::Arguments& args) {
432 content::RenderView* render_view = GetRenderView(); 456 content::RenderView* render_view = GetRenderView();
433 if (!render_view) return v8::Undefined(); 457 if (!render_view) return v8::Undefined();
434 458
435 const chrome::search::Mode& mode = SearchBox::Get(render_view)->mode(); 459 const chrome::search::Mode& mode = SearchBox::Get(render_view)->mode();
436 DVLOG(1) << "GetContext: " << mode.origin << ":" << mode.mode; 460 DVLOG(1) << "GetContext: " << mode.origin << ":" << mode.mode;
437 v8::Handle<v8::Object> context = v8::Object::New(); 461 v8::Handle<v8::Object> context = v8::Object::New();
438 context->Set(v8::String::New("isNewTabPage"), 462 context->Set(v8::String::New("isNewTabPage"),
439 v8::Boolean::New(mode.is_ntp())); 463 v8::Boolean::New(mode.is_ntp()));
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 817
794 // static 818 // static
795 void SearchBoxExtension::DispatchUpOrDownKeyPress(WebKit::WebFrame* frame, 819 void SearchBoxExtension::DispatchUpOrDownKeyPress(WebKit::WebFrame* frame,
796 int count) { 820 int count) {
797 Dispatch(frame, WebKit::WebString::fromUTF8( 821 Dispatch(frame, WebKit::WebString::fromUTF8(
798 base::StringPrintf(kDispatchUpOrDownKeyPressEventScript, abs(count), 822 base::StringPrintf(kDispatchUpOrDownKeyPressEventScript, abs(count),
799 count < 0 ? ui::VKEY_UP : ui::VKEY_DOWN))); 823 count < 0 ? ui::VKEY_UP : ui::VKEY_DOWN)));
800 } 824 }
801 825
802 // static 826 // static
827 void SearchBoxExtension::DispatchKeyCaptureChange(WebKit::WebFrame* frame) {
828 DVLOG(1) << "DispatchKeyCaptureChange";
829 Dispatch(frame, kDispatchKeyCaptureChangeScript);
830 }
831
832 // static
803 void SearchBoxExtension::DispatchContextChange(WebKit::WebFrame* frame) { 833 void SearchBoxExtension::DispatchContextChange(WebKit::WebFrame* frame) {
804 DVLOG(1) << "DispatchContextChange"; 834 DVLOG(1) << "DispatchContextChange";
805 Dispatch(frame, kDispatchContextChangeEventScript); 835 Dispatch(frame, kDispatchContextChangeEventScript);
806 } 836 }
807 837
808 // static 838 // static
809 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) { 839 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) {
810 Dispatch(frame, kDispatchThemeChangeEventScript); 840 Dispatch(frame, kDispatchThemeChangeEventScript);
811 } 841 }
812 842
813 // static 843 // static
814 void SearchBoxExtension::DispatchThemeAreaHeightChange( 844 void SearchBoxExtension::DispatchThemeAreaHeightChange(
815 WebKit::WebFrame* frame) { 845 WebKit::WebFrame* frame) {
816 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); 846 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript);
817 } 847 }
818 848
819 // static 849 // static
820 v8::Extension* SearchBoxExtension::Get() { 850 v8::Extension* SearchBoxExtension::Get() {
821 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). 851 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance().
822 GetRawDataResource(IDR_SEARCHBOX_API)); 852 GetRawDataResource(IDR_SEARCHBOX_API));
823 } 853 }
824 854
825 } // namespace extensions_v8 855 } // namespace extensions_v8
OLDNEW
« chrome/renderer/searchbox/searchbox.cc ('K') | « chrome/renderer/searchbox/searchbox_extension.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698