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 <ctype.h> | |
samarth
2012/11/28 03:51:19
Why do you need this?
melevin
2012/11/28 20:28:19
Oops, I think this was a bad merge.
| |
8 | |
9 #include "base/i18n/rtl.h" | |
7 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
8 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
9 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
10 #include "chrome/renderer/searchbox/searchbox.h" | 13 #include "chrome/renderer/searchbox/searchbox.h" |
11 #include "content/public/renderer/render_view.h" | 14 #include "content/public/renderer/render_view.h" |
12 #include "grit/renderer_resources.h" | 15 #include "grit/renderer_resources.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques t.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 static const char kDispatchThemeAreaHeightChangeEventScript[] = | 155 static const char kDispatchThemeAreaHeightChangeEventScript[] = |
153 "if (window.chrome &&" | 156 "if (window.chrome &&" |
154 " window.chrome.searchBox &&" | 157 " window.chrome.searchBox &&" |
155 " window.chrome.searchBox.onthemeareaheightchange &&" | 158 " window.chrome.searchBox.onthemeareaheightchange &&" |
156 " typeof window.chrome.searchBox.onthemeareaheightchange ==" | 159 " typeof window.chrome.searchBox.onthemeareaheightchange ==" |
157 " 'function') {" | 160 " 'function') {" |
158 " window.chrome.searchBox.onthemeareaheightchange();" | 161 " window.chrome.searchBox.onthemeareaheightchange();" |
159 " true;" | 162 " true;" |
160 "}"; | 163 "}"; |
161 | 164 |
165 static const char kDispatchMarginChangeEventScript[] = | |
166 "if (window.chrome &&" | |
167 " window.chrome.searchBox &&" | |
168 " window.chrome.searchBox.onmarginchange &&" | |
169 " typeof window.chrome.searchBox.onmarginchange == 'function') {" | |
170 " window.chrome.searchBox.onmarginchange();" | |
171 " true;" | |
172 "}"; | |
173 | |
162 // ---------------------------------------------------------------------------- | 174 // ---------------------------------------------------------------------------- |
163 | 175 |
164 class SearchBoxExtensionWrapper : public v8::Extension { | 176 class SearchBoxExtensionWrapper : public v8::Extension { |
165 public: | 177 public: |
166 explicit SearchBoxExtensionWrapper(const base::StringPiece& code); | 178 explicit SearchBoxExtensionWrapper(const base::StringPiece& code); |
167 | 179 |
168 // Allows v8's javascript code to call the native functions defined | 180 // Allows v8's javascript code to call the native functions defined |
169 // in this class for window.chrome. | 181 // in this class for window.chrome. |
170 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( | 182 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( |
171 v8::Handle<v8::String> name); | 183 v8::Handle<v8::String> name); |
(...skipping 22 matching lines...) Expand all Loading... | |
194 // Gets the y coordinate (relative to |window|) of the right edge of the | 206 // Gets the y coordinate (relative to |window|) of the right edge of the |
195 // region of the search box that overlaps the window. | 207 // region of the search box that overlaps the window. |
196 static v8::Handle<v8::Value> GetY(const v8::Arguments& args); | 208 static v8::Handle<v8::Value> GetY(const v8::Arguments& args); |
197 | 209 |
198 // Gets the width of the region of the search box that overlaps the window. | 210 // 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); | 211 static v8::Handle<v8::Value> GetWidth(const v8::Arguments& args); |
200 | 212 |
201 // Gets the height of the region of the search box that overlaps the window. | 213 // 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); | 214 static v8::Handle<v8::Value> GetHeight(const v8::Arguments& args); |
203 | 215 |
216 // Gets the width of the margin from the start-edge of the page to the start | |
217 // of the suggestions dropdown. | |
218 static v8::Handle<v8::Value> GetStartMargin(const v8::Arguments& args); | |
219 | |
220 // Gets the width of the margin from the end-edge of the page to the end of | |
221 // the suggestions dropdown. | |
222 static v8::Handle<v8::Value> GetEndMargin(const v8::Arguments& args); | |
223 | |
224 // Returns true if the Searchbox itself is oriented right-to-left. | |
225 static v8::Handle<v8::Value> GetRightToLeft(const v8::Arguments& args); | |
226 | |
204 // Gets the autocomplete results from search box. | 227 // Gets the autocomplete results from search box. |
205 static v8::Handle<v8::Value> GetAutocompleteResults( | 228 static v8::Handle<v8::Value> GetAutocompleteResults( |
206 const v8::Arguments& args); | 229 const v8::Arguments& args); |
207 | 230 |
208 // Gets the current session context. | 231 // Gets the current session context. |
209 static v8::Handle<v8::Value> GetContext(const v8::Arguments& args); | 232 static v8::Handle<v8::Value> GetContext(const v8::Arguments& args); |
210 | 233 |
211 // Gets the background info of the theme currently adopted by browser. | 234 // Gets the background info of the theme currently adopted by browser. |
212 // Call only when overlay is showing NTP page. | 235 // Call only when overlay is showing NTP page. |
213 static v8::Handle<v8::Value> GetThemeBackgroundInfo( | 236 static v8::Handle<v8::Value> GetThemeBackgroundInfo( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 if (name->Equals(v8::String::New("GetSelectionEnd"))) | 287 if (name->Equals(v8::String::New("GetSelectionEnd"))) |
265 return v8::FunctionTemplate::New(GetSelectionEnd); | 288 return v8::FunctionTemplate::New(GetSelectionEnd); |
266 if (name->Equals(v8::String::New("GetX"))) | 289 if (name->Equals(v8::String::New("GetX"))) |
267 return v8::FunctionTemplate::New(GetX); | 290 return v8::FunctionTemplate::New(GetX); |
268 if (name->Equals(v8::String::New("GetY"))) | 291 if (name->Equals(v8::String::New("GetY"))) |
269 return v8::FunctionTemplate::New(GetY); | 292 return v8::FunctionTemplate::New(GetY); |
270 if (name->Equals(v8::String::New("GetWidth"))) | 293 if (name->Equals(v8::String::New("GetWidth"))) |
271 return v8::FunctionTemplate::New(GetWidth); | 294 return v8::FunctionTemplate::New(GetWidth); |
272 if (name->Equals(v8::String::New("GetHeight"))) | 295 if (name->Equals(v8::String::New("GetHeight"))) |
273 return v8::FunctionTemplate::New(GetHeight); | 296 return v8::FunctionTemplate::New(GetHeight); |
297 if (name->Equals(v8::String::New("GetStartMargin"))) | |
298 return v8::FunctionTemplate::New(GetStartMargin); | |
299 if (name->Equals(v8::String::New("GetEndMargin"))) | |
300 return v8::FunctionTemplate::New(GetEndMargin); | |
301 if (name->Equals(v8::String::New("GetRightToLeft"))) | |
302 return v8::FunctionTemplate::New(GetRightToLeft); | |
274 if (name->Equals(v8::String::New("GetAutocompleteResults"))) | 303 if (name->Equals(v8::String::New("GetAutocompleteResults"))) |
275 return v8::FunctionTemplate::New(GetAutocompleteResults); | 304 return v8::FunctionTemplate::New(GetAutocompleteResults); |
276 if (name->Equals(v8::String::New("GetContext"))) | 305 if (name->Equals(v8::String::New("GetContext"))) |
277 return v8::FunctionTemplate::New(GetContext); | 306 return v8::FunctionTemplate::New(GetContext); |
278 if (name->Equals(v8::String::New("GetThemeBackgroundInfo"))) | 307 if (name->Equals(v8::String::New("GetThemeBackgroundInfo"))) |
279 return v8::FunctionTemplate::New(GetThemeBackgroundInfo); | 308 return v8::FunctionTemplate::New(GetThemeBackgroundInfo); |
280 if (name->Equals(v8::String::New("GetThemeAreaHeight"))) | 309 if (name->Equals(v8::String::New("GetThemeAreaHeight"))) |
281 return v8::FunctionTemplate::New(GetThemeAreaHeight); | 310 return v8::FunctionTemplate::New(GetThemeAreaHeight); |
282 if (name->Equals(v8::String::New("NavigateContentWindow"))) | 311 if (name->Equals(v8::String::New("NavigateContentWindow"))) |
283 return v8::FunctionTemplate::New(NavigateContentWindow); | 312 return v8::FunctionTemplate::New(NavigateContentWindow); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 | 373 |
345 return v8::Uint32::New(SearchBox::Get(render_view)->selection_end()); | 374 return v8::Uint32::New(SearchBox::Get(render_view)->selection_end()); |
346 } | 375 } |
347 | 376 |
348 // static | 377 // static |
349 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetX( | 378 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetX( |
350 const v8::Arguments& args) { | 379 const v8::Arguments& args) { |
351 content::RenderView* render_view = GetRenderView(); | 380 content::RenderView* render_view = GetRenderView(); |
352 if (!render_view) return v8::Undefined(); | 381 if (!render_view) return v8::Undefined(); |
353 | 382 |
354 return v8::Int32::New(SearchBox::Get(render_view)->GetRect().x()); | 383 return v8::Int32::New(SearchBox::Get(render_view)->GetPopupBounds().x()); |
355 } | 384 } |
356 | 385 |
357 // static | 386 // static |
358 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetY( | 387 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetY( |
359 const v8::Arguments& args) { | 388 const v8::Arguments& args) { |
360 content::RenderView* render_view = GetRenderView(); | 389 content::RenderView* render_view = GetRenderView(); |
361 if (!render_view) return v8::Undefined(); | 390 if (!render_view) return v8::Undefined(); |
362 | 391 |
363 return v8::Int32::New(SearchBox::Get(render_view)->GetRect().y()); | 392 return v8::Int32::New(SearchBox::Get(render_view)->GetPopupBounds().y()); |
364 } | 393 } |
365 | 394 |
366 // static | 395 // static |
367 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetWidth( | 396 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetWidth( |
368 const v8::Arguments& args) { | 397 const v8::Arguments& args) { |
369 content::RenderView* render_view = GetRenderView(); | 398 content::RenderView* render_view = GetRenderView(); |
370 if (!render_view) return v8::Undefined(); | 399 if (!render_view) return v8::Undefined(); |
371 | 400 |
372 return v8::Int32::New(SearchBox::Get(render_view)->GetRect().width()); | 401 return v8::Int32::New(SearchBox::Get(render_view)->GetPopupBounds().width()); |
373 } | 402 } |
374 | 403 |
375 // static | 404 // static |
376 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetHeight( | 405 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetHeight( |
377 const v8::Arguments& args) { | 406 const v8::Arguments& args) { |
378 content::RenderView* render_view = GetRenderView(); | 407 content::RenderView* render_view = GetRenderView(); |
379 if (!render_view) return v8::Undefined(); | 408 if (!render_view) return v8::Undefined(); |
380 | 409 |
381 return v8::Int32::New(SearchBox::Get(render_view)->GetRect().height()); | 410 return v8::Int32::New(SearchBox::Get(render_view)->GetPopupBounds().height()); |
382 } | 411 } |
383 | 412 |
384 // static | 413 // static |
414 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetStartMargin( | |
415 const v8::Arguments& args) { | |
416 content::RenderView* render_view = GetRenderView(); | |
417 if (!render_view) return v8::Undefined(); | |
418 return v8::Int32::New(SearchBox::Get(render_view)->GetStartMargin()); | |
419 } | |
420 | |
421 // static | |
422 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetEndMargin( | |
423 const v8::Arguments& args) { | |
424 content::RenderView* render_view = GetRenderView(); | |
425 if (!render_view) return v8::Undefined(); | |
426 return v8::Int32::New(SearchBox::Get(render_view)->GetEndMargin()); | |
427 } | |
428 | |
429 // static | |
430 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetRightToLeft( | |
431 const v8::Arguments& args) { | |
432 return v8::Boolean::New(base::i18n::IsRTL()); | |
433 } | |
434 | |
435 // static | |
385 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetAutocompleteResults( | 436 v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetAutocompleteResults( |
386 const v8::Arguments& args) { | 437 const v8::Arguments& args) { |
387 DVLOG(1) << "GetAutocompleteResults"; | 438 DVLOG(1) << "GetAutocompleteResults"; |
388 content::RenderView* render_view = GetRenderView(); | 439 content::RenderView* render_view = GetRenderView(); |
389 if (!render_view) return v8::Undefined(); | 440 if (!render_view) return v8::Undefined(); |
390 | 441 |
391 const std::vector<InstantAutocompleteResult>& results = | 442 const std::vector<InstantAutocompleteResult>& results = |
392 SearchBox::Get(render_view)->GetAutocompleteResults(); | 443 SearchBox::Get(render_view)->GetAutocompleteResults(); |
393 const size_t results_base = SearchBox::Get(render_view)->results_base(); | 444 const size_t results_base = SearchBox::Get(render_view)->results_base(); |
394 | 445 |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
779 DVLOG(1) << "DispatchContextChange"; | 830 DVLOG(1) << "DispatchContextChange"; |
780 Dispatch(frame, kDispatchContextChangeEventScript); | 831 Dispatch(frame, kDispatchContextChangeEventScript); |
781 } | 832 } |
782 | 833 |
783 // static | 834 // static |
784 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) { | 835 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) { |
785 Dispatch(frame, kDispatchThemeChangeEventScript); | 836 Dispatch(frame, kDispatchThemeChangeEventScript); |
786 } | 837 } |
787 | 838 |
788 // static | 839 // static |
840 void SearchBoxExtension::DispatchMarginChange(WebKit::WebFrame* frame) { | |
841 Dispatch(frame, kDispatchMarginChangeEventScript); | |
842 } | |
843 | |
844 // static | |
789 void SearchBoxExtension::DispatchThemeAreaHeightChange( | 845 void SearchBoxExtension::DispatchThemeAreaHeightChange( |
790 WebKit::WebFrame* frame) { | 846 WebKit::WebFrame* frame) { |
791 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); | 847 Dispatch(frame, kDispatchThemeAreaHeightChangeEventScript); |
792 } | 848 } |
793 | 849 |
794 // static | 850 // static |
795 v8::Extension* SearchBoxExtension::Get() { | 851 v8::Extension* SearchBoxExtension::Get() { |
796 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). | 852 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). |
797 GetRawDataResource(IDR_SEARCHBOX_API)); | 853 GetRawDataResource(IDR_SEARCHBOX_API)); |
798 } | 854 } |
799 | 855 |
800 } // namespace extensions_v8 | 856 } // namespace extensions_v8 |
OLD | NEW |