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

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: Fixed comments, mouse handling logic. 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 static v8::Handle<v8::Value> GetThemeBackgroundInfo( 226 static v8::Handle<v8::Value> GetThemeBackgroundInfo(
218 const v8::Arguments& args); 227 const v8::Arguments& args);
219 228
220 // Gets the theme area height that the entire theme background image should 229 // Gets the theme area height that the entire theme background image should
221 // fill up. 230 // fill up.
222 // Call only when overlay is showing NTP page and GetThemeBackgroundInfo 231 // Call only when overlay is showing NTP page and GetThemeBackgroundInfo
223 // returns a non-empty image_url and an image_vertical_alignment that is not 232 // returns a non-empty image_url and an image_vertical_alignment that is not
224 // "top". 233 // "top".
225 static v8::Handle<v8::Value> GetThemeAreaHeight(const v8::Arguments& args); 234 static v8::Handle<v8::Value> GetThemeAreaHeight(const v8::Arguments& args);
226 235
236 // Gets whether the browser is capturing key strokes.
237 static v8::Handle<v8::Value> IsKeyCaptureEnabled(const v8::Arguments& args);
238
227 // Navigates the window to a URL represented by either a URL string or a 239 // Navigates the window to a URL represented by either a URL string or a
228 // restricted ID. 240 // restricted ID.
229 static v8::Handle<v8::Value> NavigateContentWindow(const v8::Arguments& args); 241 static v8::Handle<v8::Value> NavigateContentWindow(const v8::Arguments& args);
230 242
231 // Sets ordered suggestions. Valid for current |value|. 243 // Sets ordered suggestions. Valid for current |value|.
232 static v8::Handle<v8::Value> SetSuggestions(const v8::Arguments& args); 244 static v8::Handle<v8::Value> SetSuggestions(const v8::Arguments& args);
233 245
234 // Sets the text to be autocompleted into the search box. 246 // Sets the text to be autocompleted into the search box.
235 static v8::Handle<v8::Value> SetQuerySuggestion(const v8::Arguments& args); 247 static v8::Handle<v8::Value> SetQuerySuggestion(const v8::Arguments& args);
236 248
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 if (name->Equals(v8::String::New("GetAutocompleteResults"))) 298 if (name->Equals(v8::String::New("GetAutocompleteResults")))
287 return v8::FunctionTemplate::New(GetAutocompleteResults); 299 return v8::FunctionTemplate::New(GetAutocompleteResults);
288 if (name->Equals(v8::String::New("GetContext"))) 300 if (name->Equals(v8::String::New("GetContext")))
289 return v8::FunctionTemplate::New(GetContext); 301 return v8::FunctionTemplate::New(GetContext);
290 if (name->Equals(v8::String::New("GetDisplayInstantResults"))) 302 if (name->Equals(v8::String::New("GetDisplayInstantResults")))
291 return v8::FunctionTemplate::New(GetDisplayInstantResults); 303 return v8::FunctionTemplate::New(GetDisplayInstantResults);
292 if (name->Equals(v8::String::New("GetThemeBackgroundInfo"))) 304 if (name->Equals(v8::String::New("GetThemeBackgroundInfo")))
293 return v8::FunctionTemplate::New(GetThemeBackgroundInfo); 305 return v8::FunctionTemplate::New(GetThemeBackgroundInfo);
294 if (name->Equals(v8::String::New("GetThemeAreaHeight"))) 306 if (name->Equals(v8::String::New("GetThemeAreaHeight")))
295 return v8::FunctionTemplate::New(GetThemeAreaHeight); 307 return v8::FunctionTemplate::New(GetThemeAreaHeight);
308 if (name->Equals(v8::String::New("IsKeyCaptureEnabled")))
309 return v8::FunctionTemplate::New(IsKeyCaptureEnabled);
296 if (name->Equals(v8::String::New("NavigateContentWindow"))) 310 if (name->Equals(v8::String::New("NavigateContentWindow")))
297 return v8::FunctionTemplate::New(NavigateContentWindow); 311 return v8::FunctionTemplate::New(NavigateContentWindow);
298 if (name->Equals(v8::String::New("SetSuggestions"))) 312 if (name->Equals(v8::String::New("SetSuggestions")))
299 return v8::FunctionTemplate::New(SetSuggestions); 313 return v8::FunctionTemplate::New(SetSuggestions);
300 if (name->Equals(v8::String::New("SetQuerySuggestion"))) 314 if (name->Equals(v8::String::New("SetQuerySuggestion")))
301 return v8::FunctionTemplate::New(SetQuerySuggestion); 315 return v8::FunctionTemplate::New(SetQuerySuggestion);
302 if (name->Equals(v8::String::New("SetQuerySuggestionFromAutocompleteResult"))) 316 if (name->Equals(v8::String::New("SetQuerySuggestionFromAutocompleteResult")))
303 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult); 317 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult);
304 if (name->Equals(v8::String::New("SetQuery"))) 318 if (name->Equals(v8::String::New("SetQuery")))
305 return v8::FunctionTemplate::New(SetQuery); 319 return v8::FunctionTemplate::New(SetQuery);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 ranking_data->Set(v8::String::New("relevance"), 442 ranking_data->Set(v8::String::New("relevance"),
429 v8::Int32::New(results[i].relevance)); 443 v8::Int32::New(results[i].relevance));
430 result->Set(v8::String::New("rankingData"), ranking_data); 444 result->Set(v8::String::New("rankingData"), ranking_data);
431 445
432 results_array->Set(i, result); 446 results_array->Set(i, result);
433 } 447 }
434 return results_array; 448 return results_array;
435 } 449 }
436 450
437 // static 451 // static
452 v8::Handle<v8::Value> SearchBoxExtensionWrapper::IsKeyCaptureEnabled(
453 const v8::Arguments& args) {
454 content::RenderView* render_view = GetRenderView();
455 if (!render_view) return v8::Undefined();
456
457 return v8::Boolean::New(SearchBox::Get(render_view)->
458 is_key_capture_enabled());
459 }
460
461 // static
438 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetContext( 462 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetContext(
439 const v8::Arguments& args) { 463 const v8::Arguments& args) {
440 content::RenderView* render_view = GetRenderView(); 464 content::RenderView* render_view = GetRenderView();
441 if (!render_view) return v8::Undefined(); 465 if (!render_view) return v8::Undefined();
442 466
443 const chrome::search::Mode& mode = SearchBox::Get(render_view)->mode(); 467 const chrome::search::Mode& mode = SearchBox::Get(render_view)->mode();
444 DVLOG(1) << render_view << " GetContext: " << mode.origin << ":" << mode.mode; 468 DVLOG(1) << render_view << " GetContext: " << mode.origin << ":" << mode.mode;
445 v8::Handle<v8::Object> context = v8::Object::New(); 469 v8::Handle<v8::Object> context = v8::Object::New();
446 context->Set(v8::String::New("isNewTabPage"), 470 context->Set(v8::String::New("isNewTabPage"),
447 v8::Boolean::New(mode.is_ntp())); 471 v8::Boolean::New(mode.is_ntp()));
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 831
808 // static 832 // static
809 void SearchBoxExtension::DispatchUpOrDownKeyPress(WebKit::WebFrame* frame, 833 void SearchBoxExtension::DispatchUpOrDownKeyPress(WebKit::WebFrame* frame,
810 int count) { 834 int count) {
811 Dispatch(frame, WebKit::WebString::fromUTF8( 835 Dispatch(frame, WebKit::WebString::fromUTF8(
812 base::StringPrintf(kDispatchUpOrDownKeyPressEventScript, abs(count), 836 base::StringPrintf(kDispatchUpOrDownKeyPressEventScript, abs(count),
813 count < 0 ? ui::VKEY_UP : ui::VKEY_DOWN))); 837 count < 0 ? ui::VKEY_UP : ui::VKEY_DOWN)));
814 } 838 }
815 839
816 // static 840 // static
841 void SearchBoxExtension::DispatchKeyCaptureChange(WebKit::WebFrame* frame) {
842 Dispatch(frame, kDispatchKeyCaptureChangeScript);
843 }
844
845 // static
817 void SearchBoxExtension::DispatchContextChange(WebKit::WebFrame* frame) { 846 void SearchBoxExtension::DispatchContextChange(WebKit::WebFrame* frame) {
818 Dispatch(frame, kDispatchContextChangeEventScript); 847 Dispatch(frame, kDispatchContextChangeEventScript);
819 } 848 }
820 849
821 // static 850 // static
822 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) { 851 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) {
823 Dispatch(frame, kDispatchThemeChangeEventScript); 852 Dispatch(frame, kDispatchThemeChangeEventScript);
824 } 853 }
825 854
826 // static 855 // static
827 void SearchBoxExtension::DispatchThemeAreaHeightChange( 856 void SearchBoxExtension::DispatchThemeAreaHeightChange(
828 WebKit::WebFrame* frame) { 857 WebKit::WebFrame* frame) {
829 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); 858 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript);
830 } 859 }
831 860
832 // static 861 // static
833 v8::Extension* SearchBoxExtension::Get() { 862 v8::Extension* SearchBoxExtension::Get() {
834 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). 863 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance().
835 GetRawDataResource(IDR_SEARCHBOX_API)); 864 GetRawDataResource(IDR_SEARCHBOX_API));
836 } 865 }
837 866
838 } // namespace extensions_v8 867 } // namespace extensions_v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698