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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 // Sets the search box text, completely replacing what the user typed. | 241 // Sets the search box text, completely replacing what the user typed. |
242 static v8::Handle<v8::Value> SetQuery(const v8::Arguments& args); | 242 static v8::Handle<v8::Value> SetQuery(const v8::Arguments& args); |
243 | 243 |
244 // Like |SetQuery| but uses a restricted ID to identify the text. | 244 // Like |SetQuery| but uses a restricted ID to identify the text. |
245 static v8::Handle<v8::Value> SetQueryFromAutocompleteResult( | 245 static v8::Handle<v8::Value> SetQueryFromAutocompleteResult( |
246 const v8::Arguments& args); | 246 const v8::Arguments& args); |
247 | 247 |
248 // Requests the preview be shown with the specified contents and height. | 248 // Requests the preview be shown with the specified contents and height. |
249 static v8::Handle<v8::Value> Show(const v8::Arguments& args); | 249 static v8::Handle<v8::Value> Show(const v8::Arguments& args); |
250 | 250 |
| 251 // Start capturing user key strokes. |
| 252 static v8::Handle<v8::Value> StartCapturingKeyStrokes( |
| 253 const v8::Arguments& args); |
| 254 |
| 255 // Stop capturing user key strokes. |
| 256 static v8::Handle<v8::Value> StopCapturingKeyStrokes( |
| 257 const v8::Arguments& args); |
| 258 |
251 private: | 259 private: |
252 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); | 260 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); |
253 }; | 261 }; |
254 | 262 |
255 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper( | 263 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper( |
256 const base::StringPiece& code) | 264 const base::StringPiece& code) |
257 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { | 265 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { |
258 } | 266 } |
259 | 267 |
260 v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction( | 268 v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 if (name->Equals(v8::String::New("SetQuerySuggestion"))) | 300 if (name->Equals(v8::String::New("SetQuerySuggestion"))) |
293 return v8::FunctionTemplate::New(SetQuerySuggestion); | 301 return v8::FunctionTemplate::New(SetQuerySuggestion); |
294 if (name->Equals(v8::String::New("SetQuerySuggestionFromAutocompleteResult"))) | 302 if (name->Equals(v8::String::New("SetQuerySuggestionFromAutocompleteResult"))) |
295 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult); | 303 return v8::FunctionTemplate::New(SetQuerySuggestionFromAutocompleteResult); |
296 if (name->Equals(v8::String::New("SetQuery"))) | 304 if (name->Equals(v8::String::New("SetQuery"))) |
297 return v8::FunctionTemplate::New(SetQuery); | 305 return v8::FunctionTemplate::New(SetQuery); |
298 if (name->Equals(v8::String::New("SetQueryFromAutocompleteResult"))) | 306 if (name->Equals(v8::String::New("SetQueryFromAutocompleteResult"))) |
299 return v8::FunctionTemplate::New(SetQueryFromAutocompleteResult); | 307 return v8::FunctionTemplate::New(SetQueryFromAutocompleteResult); |
300 if (name->Equals(v8::String::New("Show"))) | 308 if (name->Equals(v8::String::New("Show"))) |
301 return v8::FunctionTemplate::New(Show); | 309 return v8::FunctionTemplate::New(Show); |
| 310 if (name->Equals(v8::String::New("StartCapturingKeyStrokes"))) |
| 311 return v8::FunctionTemplate::New(StartCapturingKeyStrokes); |
| 312 if (name->Equals(v8::String::New("StopCapturingKeyStrokes"))) |
| 313 return v8::FunctionTemplate::New(StopCapturingKeyStrokes); |
302 return v8::Handle<v8::FunctionTemplate>(); | 314 return v8::Handle<v8::FunctionTemplate>(); |
303 } | 315 } |
304 | 316 |
305 // static | 317 // static |
306 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() { | 318 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() { |
307 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); | 319 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); |
308 if (!webframe) return NULL; | 320 if (!webframe) return NULL; |
309 | 321 |
310 WebKit::WebView* webview = webframe->view(); | 322 WebKit::WebView* webview = webframe->view(); |
311 if (!webview) return NULL; // can happen during closing | 323 if (!webview) return NULL; // can happen during closing |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 height = args[1]->Int32Value(); | 743 height = args[1]->Int32Value(); |
732 units = INSTANT_SIZE_PIXELS; | 744 units = INSTANT_SIZE_PIXELS; |
733 } | 745 } |
734 | 746 |
735 SearchBox::Get(render_view)->ShowInstantPreview(reason, height, units); | 747 SearchBox::Get(render_view)->ShowInstantPreview(reason, height, units); |
736 | 748 |
737 return v8::Undefined(); | 749 return v8::Undefined(); |
738 } | 750 } |
739 | 751 |
740 // static | 752 // static |
| 753 v8::Handle<v8::Value> SearchBoxExtensionWrapper::StartCapturingKeyStrokes( |
| 754 const v8::Arguments& args) { |
| 755 content::RenderView* render_view = GetRenderView(); |
| 756 if (!render_view) return v8::Undefined(); |
| 757 |
| 758 DVLOG(1) << render_view << " StartCapturingKeyStrokes"; |
| 759 SearchBox::Get(render_view)->StartCapturingKeyStrokes(); |
| 760 return v8::Undefined(); |
| 761 } |
| 762 |
| 763 // static |
| 764 v8::Handle<v8::Value> SearchBoxExtensionWrapper::StopCapturingKeyStrokes( |
| 765 const v8::Arguments& args) { |
| 766 content::RenderView* render_view = GetRenderView(); |
| 767 if (!render_view) return v8::Undefined(); |
| 768 |
| 769 DVLOG(1) << render_view << " StopCapturingKeyStrokes"; |
| 770 SearchBox::Get(render_view)->StopCapturingKeyStrokes(); |
| 771 return v8::Undefined(); |
| 772 } |
| 773 |
| 774 // static |
741 void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) { | 775 void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) { |
742 Dispatch(frame, kDispatchChangeEventScript); | 776 Dispatch(frame, kDispatchChangeEventScript); |
743 } | 777 } |
744 | 778 |
745 // static | 779 // static |
746 void SearchBoxExtension::DispatchSubmit(WebKit::WebFrame* frame) { | 780 void SearchBoxExtension::DispatchSubmit(WebKit::WebFrame* frame) { |
747 Dispatch(frame, kDispatchSubmitEventScript); | 781 Dispatch(frame, kDispatchSubmitEventScript); |
748 } | 782 } |
749 | 783 |
750 // static | 784 // static |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); | 829 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); |
796 } | 830 } |
797 | 831 |
798 // static | 832 // static |
799 v8::Extension* SearchBoxExtension::Get() { | 833 v8::Extension* SearchBoxExtension::Get() { |
800 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). | 834 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). |
801 GetRawDataResource(IDR_SEARCHBOX_API)); | 835 GetRawDataResource(IDR_SEARCHBOX_API)); |
802 } | 836 } |
803 | 837 |
804 } // namespace extensions_v8 | 838 } // namespace extensions_v8 |
OLD | NEW |