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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 kDispatchKeyStrokeCapturingModeChangeScript[] = | |
| 135 "if (window.chrome &&" | |
| 136 " window.chrome.searchBox &&" | |
| 137 " window.chrome.searchBox.onkeystrokecapturingmodechange &&" | |
| 138 " typeof window.chrome.searchBox.onkeystrokecapturingmodechange == " | |
| 139 " 'function') {" | |
| 140 " for (var i = 0; i < %d; ++i)" | |
| 141 " window.chrome.searchBox.onkeystrokecapturingmodechange();" | |
| 142 " true;" | |
| 143 "}"; | |
| 144 | |
| 134 static const char kDispatchContextChangeEventScript[] = | 145 static const char kDispatchContextChangeEventScript[] = |
| 135 "if (window.chrome &&" | 146 "if (window.chrome &&" |
| 136 " window.chrome.searchBox &&" | 147 " window.chrome.searchBox &&" |
| 137 " window.chrome.searchBox.oncontextchange &&" | 148 " window.chrome.searchBox.oncontextchange &&" |
| 138 " typeof window.chrome.searchBox.oncontextchange == 'function') {" | 149 " typeof window.chrome.searchBox.oncontextchange == 'function') {" |
| 139 " window.chrome.searchBox.oncontextchange();" | 150 " window.chrome.searchBox.oncontextchange();" |
| 140 " true;" | 151 " true;" |
| 141 "}"; | 152 "}"; |
| 142 | 153 |
| 143 static const char kDispatchThemeChangeEventScript[] = | 154 static const char kDispatchThemeChangeEventScript[] = |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 // Gets the width of the region of the search box that overlaps the window. | 209 // Gets the width of the region of the search box that overlaps the window. |
| 199 static v8::Handle<v8::Value> GetWidth(const v8::Arguments& args); | 210 static v8::Handle<v8::Value> GetWidth(const v8::Arguments& args); |
| 200 | 211 |
| 201 // Gets the height of the region of the search box that overlaps the window. | 212 // Gets the height of the region of the search box that overlaps the window. |
| 202 static v8::Handle<v8::Value> GetHeight(const v8::Arguments& args); | 213 static v8::Handle<v8::Value> GetHeight(const v8::Arguments& args); |
| 203 | 214 |
| 204 // Gets the autocomplete results from search box. | 215 // Gets the autocomplete results from search box. |
| 205 static v8::Handle<v8::Value> GetAutocompleteResults( | 216 static v8::Handle<v8::Value> GetAutocompleteResults( |
| 206 const v8::Arguments& args); | 217 const v8::Arguments& args); |
| 207 | 218 |
| 219 // Gets whether the browser is capturing key strokes. | |
| 220 static v8::Handle<v8::Value> GetIsCapturingKeyStrokes( | |
|
Jered
2012/11/28 17:50:16
GetIsCapturingKeyStrokes -> IsKeyCaptureEnabled.
samarth
2012/11/28 19:33:09
Done.
| |
| 221 const v8::Arguments& args); | |
| 222 | |
| 208 // Gets the current session context. | 223 // Gets the current session context. |
| 209 static v8::Handle<v8::Value> GetContext(const v8::Arguments& args); | 224 static v8::Handle<v8::Value> GetContext(const v8::Arguments& args); |
| 210 | 225 |
| 211 // Gets the background info of the theme currently adopted by browser. | 226 // Gets the background info of the theme currently adopted by browser. |
| 212 // Call only when overlay is showing NTP page. | 227 // Call only when overlay is showing NTP page. |
| 213 static v8::Handle<v8::Value> GetThemeBackgroundInfo( | 228 static v8::Handle<v8::Value> GetThemeBackgroundInfo( |
| 214 const v8::Arguments& args); | 229 const v8::Arguments& args); |
| 215 | 230 |
| 216 // Gets the theme area height that the entire theme background image should | 231 // Gets the theme area height that the entire theme background image should |
| 217 // fill up. | 232 // fill up. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 if (name->Equals(v8::String::New("GetX"))) | 289 if (name->Equals(v8::String::New("GetX"))) |
| 275 return v8::FunctionTemplate::New(GetX); | 290 return v8::FunctionTemplate::New(GetX); |
| 276 if (name->Equals(v8::String::New("GetY"))) | 291 if (name->Equals(v8::String::New("GetY"))) |
| 277 return v8::FunctionTemplate::New(GetY); | 292 return v8::FunctionTemplate::New(GetY); |
| 278 if (name->Equals(v8::String::New("GetWidth"))) | 293 if (name->Equals(v8::String::New("GetWidth"))) |
| 279 return v8::FunctionTemplate::New(GetWidth); | 294 return v8::FunctionTemplate::New(GetWidth); |
| 280 if (name->Equals(v8::String::New("GetHeight"))) | 295 if (name->Equals(v8::String::New("GetHeight"))) |
| 281 return v8::FunctionTemplate::New(GetHeight); | 296 return v8::FunctionTemplate::New(GetHeight); |
| 282 if (name->Equals(v8::String::New("GetAutocompleteResults"))) | 297 if (name->Equals(v8::String::New("GetAutocompleteResults"))) |
| 283 return v8::FunctionTemplate::New(GetAutocompleteResults); | 298 return v8::FunctionTemplate::New(GetAutocompleteResults); |
| 299 if (name->Equals(v8::String::New("GetIsCapturingKeyStrokes"))) | |
| 300 return v8::FunctionTemplate::New(GetIsCapturingKeyStrokes); | |
| 284 if (name->Equals(v8::String::New("GetContext"))) | 301 if (name->Equals(v8::String::New("GetContext"))) |
| 285 return v8::FunctionTemplate::New(GetContext); | 302 return v8::FunctionTemplate::New(GetContext); |
| 286 if (name->Equals(v8::String::New("GetThemeBackgroundInfo"))) | 303 if (name->Equals(v8::String::New("GetThemeBackgroundInfo"))) |
| 287 return v8::FunctionTemplate::New(GetThemeBackgroundInfo); | 304 return v8::FunctionTemplate::New(GetThemeBackgroundInfo); |
| 288 if (name->Equals(v8::String::New("GetThemeAreaHeight"))) | 305 if (name->Equals(v8::String::New("GetThemeAreaHeight"))) |
| 289 return v8::FunctionTemplate::New(GetThemeAreaHeight); | 306 return v8::FunctionTemplate::New(GetThemeAreaHeight); |
| 290 if (name->Equals(v8::String::New("NavigateContentWindow"))) | 307 if (name->Equals(v8::String::New("NavigateContentWindow"))) |
| 291 return v8::FunctionTemplate::New(NavigateContentWindow); | 308 return v8::FunctionTemplate::New(NavigateContentWindow); |
| 292 if (name->Equals(v8::String::New("SetSuggestions"))) | 309 if (name->Equals(v8::String::New("SetSuggestions"))) |
| 293 return v8::FunctionTemplate::New(SetSuggestions); | 310 return v8::FunctionTemplate::New(SetSuggestions); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 ranking_data->Set(v8::String::New("relevance"), | 437 ranking_data->Set(v8::String::New("relevance"), |
| 421 v8::Int32::New(results[i].relevance)); | 438 v8::Int32::New(results[i].relevance)); |
| 422 result->Set(v8::String::New("rankingData"), ranking_data); | 439 result->Set(v8::String::New("rankingData"), ranking_data); |
| 423 | 440 |
| 424 results_array->Set(i, result); | 441 results_array->Set(i, result); |
| 425 } | 442 } |
| 426 return results_array; | 443 return results_array; |
| 427 } | 444 } |
| 428 | 445 |
| 429 // static | 446 // static |
| 447 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetIsCapturingKeyStrokes( | |
| 448 const v8::Arguments& args) { | |
| 449 content::RenderView* render_view = GetRenderView(); | |
| 450 if (!render_view) return v8::Undefined(); | |
| 451 | |
| 452 return v8::Boolean::New(SearchBox::Get(render_view)->capturing_key_strokes()); | |
| 453 } | |
| 454 | |
| 455 // static | |
| 430 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetContext( | 456 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetContext( |
| 431 const v8::Arguments& args) { | 457 const v8::Arguments& args) { |
| 432 content::RenderView* render_view = GetRenderView(); | 458 content::RenderView* render_view = GetRenderView(); |
| 433 if (!render_view) return v8::Undefined(); | 459 if (!render_view) return v8::Undefined(); |
| 434 | 460 |
| 435 const chrome::search::Mode& mode = SearchBox::Get(render_view)->mode(); | 461 const chrome::search::Mode& mode = SearchBox::Get(render_view)->mode(); |
| 436 DVLOG(1) << "GetContext: " << mode.origin << ":" << mode.mode; | 462 DVLOG(1) << "GetContext: " << mode.origin << ":" << mode.mode; |
| 437 v8::Handle<v8::Object> context = v8::Object::New(); | 463 v8::Handle<v8::Object> context = v8::Object::New(); |
| 438 // TODO(jered): Remove isNewTabPage, it's deprecated. | 464 // TODO(jered): Remove isNewTabPage, it's deprecated. |
| 439 context->Set(v8::String::New("isNewTabPage"), | 465 context->Set(v8::String::New("isNewTabPage"), |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 | 824 |
| 799 // static | 825 // static |
| 800 void SearchBoxExtension::DispatchUpOrDownKeyPress(WebKit::WebFrame* frame, | 826 void SearchBoxExtension::DispatchUpOrDownKeyPress(WebKit::WebFrame* frame, |
| 801 int count) { | 827 int count) { |
| 802 Dispatch(frame, WebKit::WebString::fromUTF8( | 828 Dispatch(frame, WebKit::WebString::fromUTF8( |
| 803 base::StringPrintf(kDispatchUpOrDownKeyPressEventScript, abs(count), | 829 base::StringPrintf(kDispatchUpOrDownKeyPressEventScript, abs(count), |
| 804 count < 0 ? ui::VKEY_UP : ui::VKEY_DOWN))); | 830 count < 0 ? ui::VKEY_UP : ui::VKEY_DOWN))); |
| 805 } | 831 } |
| 806 | 832 |
| 807 // static | 833 // static |
| 834 void SearchBoxExtension::DispatchKeyStrokeCapturingModeChange( | |
| 835 WebKit::WebFrame* frame) { | |
| 836 DVLOG(1) << "DispatchKeyStrokeCapturingModeChange"; | |
| 837 Dispatch(frame, kDispatchKeyStrokeCapturingModeChangeScript); | |
| 838 } | |
| 839 | |
| 840 // static | |
| 808 void SearchBoxExtension::DispatchContextChange(WebKit::WebFrame* frame) { | 841 void SearchBoxExtension::DispatchContextChange(WebKit::WebFrame* frame) { |
| 809 DVLOG(1) << "DispatchContextChange"; | 842 DVLOG(1) << "DispatchContextChange"; |
| 810 Dispatch(frame, kDispatchContextChangeEventScript); | 843 Dispatch(frame, kDispatchContextChangeEventScript); |
| 811 } | 844 } |
| 812 | 845 |
| 813 // static | 846 // static |
| 814 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) { | 847 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) { |
| 815 Dispatch(frame, kDispatchThemeChangeEventScript); | 848 Dispatch(frame, kDispatchThemeChangeEventScript); |
| 816 } | 849 } |
| 817 | 850 |
| 818 // static | 851 // static |
| 819 void SearchBoxExtension::DispatchThemeAreaHeightChange( | 852 void SearchBoxExtension::DispatchThemeAreaHeightChange( |
| 820 WebKit::WebFrame* frame) { | 853 WebKit::WebFrame* frame) { |
| 821 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); | 854 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); |
| 822 } | 855 } |
| 823 | 856 |
| 824 // static | 857 // static |
| 825 v8::Extension* SearchBoxExtension::Get() { | 858 v8::Extension* SearchBoxExtension::Get() { |
| 826 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). | 859 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). |
| 827 GetRawDataResource(IDR_SEARCHBOX_API)); | 860 GetRawDataResource(IDR_SEARCHBOX_API)); |
| 828 } | 861 } |
| 829 | 862 |
| 830 } // namespace extensions_v8 | 863 } // namespace extensions_v8 |
| OLD | NEW |