OLD | NEW |
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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 // Sets the search box text, completely replacing what the user typed. | 237 // Sets the search box text, completely replacing what the user typed. |
238 static v8::Handle<v8::Value> SetQuery(const v8::Arguments& args); | 238 static v8::Handle<v8::Value> SetQuery(const v8::Arguments& args); |
239 | 239 |
240 // Like |SetQuery| but uses a restricted ID to identify the text. | 240 // Like |SetQuery| but uses a restricted ID to identify the text. |
241 static v8::Handle<v8::Value> SetQueryFromAutocompleteResult( | 241 static v8::Handle<v8::Value> SetQueryFromAutocompleteResult( |
242 const v8::Arguments& args); | 242 const v8::Arguments& args); |
243 | 243 |
244 // Requests the preview be shown with the specified contents and height. | 244 // Requests the preview be shown with the specified contents and height. |
245 static v8::Handle<v8::Value> Show(const v8::Arguments& args); | 245 static v8::Handle<v8::Value> Show(const v8::Arguments& args); |
246 | 246 |
| 247 // Start capturing user key strokes. |
| 248 static v8::Handle<v8::Value> StartCapturingKeyStrokes( |
| 249 const v8::Arguments& args); |
| 250 |
| 251 // Stop capturing user key strokes. |
| 252 static v8::Handle<v8::Value> StopCapturingKeyStrokes( |
| 253 const v8::Arguments& args); |
| 254 |
247 private: | 255 private: |
248 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); | 256 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); |
249 }; | 257 }; |
250 | 258 |
251 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper( | 259 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper( |
252 const base::StringPiece& code) | 260 const base::StringPiece& code) |
253 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { | 261 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { |
254 } | 262 } |
255 | 263 |
256 v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction( | 264 v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction( |
(...skipping 29 matching lines...) Expand all Loading... |
286 if (name->Equals(v8::String::New("SetQuerySuggestion"))) | 294 if (name->Equals(v8::String::New("SetQuerySuggestion"))) |
287 return v8::FunctionTemplate::New(SetQuerySuggestion); | 295 return v8::FunctionTemplate::New(SetQuerySuggestion); |
288 if (name->Equals(v8::String::New("SetQuerySuggestionFromAutocompleteResult"))) | 296 if (name->Equals(v8::String::New("SetQuerySuggestionFromAutocompleteResult"))) |
289 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult); | 297 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult); |
290 if (name->Equals(v8::String::New("SetQuery"))) | 298 if (name->Equals(v8::String::New("SetQuery"))) |
291 return v8::FunctionTemplate::New(SetQuery); | 299 return v8::FunctionTemplate::New(SetQuery); |
292 if (name->Equals(v8::String::New("SetQueryFromAutocompleteResult"))) | 300 if (name->Equals(v8::String::New("SetQueryFromAutocompleteResult"))) |
293 return v8::FunctionTemplate::New(SetQueryFromAutocompleteResult); | 301 return v8::FunctionTemplate::New(SetQueryFromAutocompleteResult); |
294 if (name->Equals(v8::String::New("Show"))) | 302 if (name->Equals(v8::String::New("Show"))) |
295 return v8::FunctionTemplate::New(Show); | 303 return v8::FunctionTemplate::New(Show); |
| 304 if (name->Equals(v8::String::New("StartCapturingKeyStrokes"))) |
| 305 return v8::FunctionTemplate::New(StartCapturingKeyStrokes); |
| 306 if (name->Equals(v8::String::New("StopCapturingKeyStrokes"))) |
| 307 return v8::FunctionTemplate::New(StopCapturingKeyStrokes); |
296 return v8::Handle<v8::FunctionTemplate>(); | 308 return v8::Handle<v8::FunctionTemplate>(); |
297 } | 309 } |
298 | 310 |
299 // static | 311 // static |
300 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() { | 312 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() { |
301 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); | 313 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); |
302 if (!webframe) return NULL; | 314 if (!webframe) return NULL; |
303 | 315 |
304 WebKit::WebView* webview = webframe->view(); | 316 WebKit::WebView* webview = webframe->view(); |
305 if (!webview) return NULL; // can happen during closing | 317 if (!webview) return NULL; // can happen during closing |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 height = args[1]->Int32Value(); | 727 height = args[1]->Int32Value(); |
716 units = INSTANT_SIZE_PIXELS; | 728 units = INSTANT_SIZE_PIXELS; |
717 } | 729 } |
718 | 730 |
719 SearchBox::Get(render_view)->ShowInstantPreview(reason, height, units); | 731 SearchBox::Get(render_view)->ShowInstantPreview(reason, height, units); |
720 | 732 |
721 return v8::Undefined(); | 733 return v8::Undefined(); |
722 } | 734 } |
723 | 735 |
724 // static | 736 // static |
| 737 v8::Handle<v8::Value> SearchBoxExtensionWrapper::StartCapturingKeyStrokes( |
| 738 const v8::Arguments& args) { |
| 739 content::RenderView* render_view = GetRenderView(); |
| 740 if (render_view) |
| 741 SearchBox::Get(render_view)->StartCapturingKeyStrokes(); |
| 742 return v8::Undefined(); |
| 743 } |
| 744 |
| 745 // static |
| 746 v8::Handle<v8::Value> SearchBoxExtensionWrapper::StopCapturingKeyStrokes( |
| 747 const v8::Arguments& args) { |
| 748 content::RenderView* render_view = GetRenderView(); |
| 749 if (render_view) |
| 750 SearchBox::Get(render_view)->StopCapturingKeyStrokes(); |
| 751 return v8::Undefined(); |
| 752 } |
| 753 |
| 754 // static |
725 void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) { | 755 void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) { |
726 DVLOG(1) << "DispatchChange"; | 756 DVLOG(1) << "DispatchChange"; |
727 Dispatch(frame, kDispatchChangeEventScript); | 757 Dispatch(frame, kDispatchChangeEventScript); |
728 } | 758 } |
729 | 759 |
730 // static | 760 // static |
731 void SearchBoxExtension::DispatchSubmit(WebKit::WebFrame* frame) { | 761 void SearchBoxExtension::DispatchSubmit(WebKit::WebFrame* frame) { |
732 Dispatch(frame, kDispatchSubmitEventScript); | 762 Dispatch(frame, kDispatchSubmitEventScript); |
733 } | 763 } |
734 | 764 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); | 821 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); |
792 } | 822 } |
793 | 823 |
794 // static | 824 // static |
795 v8::Extension* SearchBoxExtension::Get() { | 825 v8::Extension* SearchBoxExtension::Get() { |
796 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). | 826 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). |
797 GetRawDataResource(IDR_SEARCHBOX_API)); | 827 GetRawDataResource(IDR_SEARCHBOX_API)); |
798 } | 828 } |
799 | 829 |
800 } // namespace extensions_v8 | 830 } // namespace extensions_v8 |
OLD | NEW |