| 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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 height = args[1]->Int32Value(); | 722 height = args[1]->Int32Value(); |
| 711 units = INSTANT_SIZE_PIXELS; | 723 units = INSTANT_SIZE_PIXELS; |
| 712 } | 724 } |
| 713 | 725 |
| 714 SearchBox::Get(render_view)->ShowInstantPreview(reason, height, units); | 726 SearchBox::Get(render_view)->ShowInstantPreview(reason, height, units); |
| 715 | 727 |
| 716 return v8::Undefined(); | 728 return v8::Undefined(); |
| 717 } | 729 } |
| 718 | 730 |
| 719 // static | 731 // static |
| 732 v8::Handle<v8::Value> SearchBoxExtensionWrapper::StartCapturingKeyStrokes( |
| 733 const v8::Arguments& args) { |
| 734 content::RenderView* render_view = GetRenderView(); |
| 735 if (render_view) |
| 736 SearchBox::Get(render_view)->StartCapturingKeyStrokes(); |
| 737 return v8::Undefined(); |
| 738 } |
| 739 |
| 740 // static |
| 741 v8::Handle<v8::Value> SearchBoxExtensionWrapper::StopCapturingKeyStrokes( |
| 742 const v8::Arguments& args) { |
| 743 content::RenderView* render_view = GetRenderView(); |
| 744 if (render_view) |
| 745 SearchBox::Get(render_view)->StopCapturingKeyStrokes(); |
| 746 return v8::Undefined(); |
| 747 } |
| 748 |
| 749 // static |
| 720 void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) { | 750 void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) { |
| 721 DVLOG(1) << "DispatchChange"; | 751 DVLOG(1) << "DispatchChange"; |
| 722 Dispatch(frame, kDispatchChangeEventScript); | 752 Dispatch(frame, kDispatchChangeEventScript); |
| 723 } | 753 } |
| 724 | 754 |
| 725 // static | 755 // static |
| 726 void SearchBoxExtension::DispatchSubmit(WebKit::WebFrame* frame) { | 756 void SearchBoxExtension::DispatchSubmit(WebKit::WebFrame* frame) { |
| 727 Dispatch(frame, kDispatchSubmitEventScript); | 757 Dispatch(frame, kDispatchSubmitEventScript); |
| 728 } | 758 } |
| 729 | 759 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); | 816 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); |
| 787 } | 817 } |
| 788 | 818 |
| 789 // static | 819 // static |
| 790 v8::Extension* SearchBoxExtension::Get() { | 820 v8::Extension* SearchBoxExtension::Get() { |
| 791 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). | 821 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). |
| 792 GetRawDataResource(IDR_SEARCHBOX_API)); | 822 GetRawDataResource(IDR_SEARCHBOX_API)); |
| 793 } | 823 } |
| 794 | 824 |
| 795 } // namespace extensions_v8 | 825 } // namespace extensions_v8 |
| OLD | NEW |