Chromium Code Reviews| 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) | |
|
sreeram
2012/12/04 21:54:58
Perhaps follow the existing style (here and in the
samarth
2012/12/04 22:13:43
Done.
| |
| 757 SearchBox::Get(render_view)->StartCapturingKeyStrokes(); | |
| 758 return v8::Undefined(); | |
| 759 } | |
| 760 | |
| 761 // static | |
| 762 v8::Handle<v8::Value> SearchBoxExtensionWrapper::StopCapturingKeyStrokes( | |
| 763 const v8::Arguments& args) { | |
| 764 content::RenderView* render_view = GetRenderView(); | |
| 765 if (render_view) | |
| 766 SearchBox::Get(render_view)->StopCapturingKeyStrokes(); | |
| 767 return v8::Undefined(); | |
| 768 } | |
| 769 | |
| 770 // static | |
| 741 void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) { | 771 void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) { |
| 742 Dispatch(frame, kDispatchChangeEventScript); | 772 Dispatch(frame, kDispatchChangeEventScript); |
| 743 } | 773 } |
| 744 | 774 |
| 745 // static | 775 // static |
| 746 void SearchBoxExtension::DispatchSubmit(WebKit::WebFrame* frame) { | 776 void SearchBoxExtension::DispatchSubmit(WebKit::WebFrame* frame) { |
| 747 Dispatch(frame, kDispatchSubmitEventScript); | 777 Dispatch(frame, kDispatchSubmitEventScript); |
| 748 } | 778 } |
| 749 | 779 |
| 750 // static | 780 // static |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 795 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); | 825 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); |
| 796 } | 826 } |
| 797 | 827 |
| 798 // static | 828 // static |
| 799 v8::Extension* SearchBoxExtension::Get() { | 829 v8::Extension* SearchBoxExtension::Get() { |
| 800 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). | 830 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). |
| 801 GetRawDataResource(IDR_SEARCHBOX_API)); | 831 GetRawDataResource(IDR_SEARCHBOX_API)); |
| 802 } | 832 } |
| 803 | 833 |
| 804 } // namespace extensions_v8 | 834 } // namespace extensions_v8 |
| OLD | NEW |