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/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/json/string_escape.h" | 8 #include "base/json/string_escape.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 "if (window.chrome &&" | 215 "if (window.chrome &&" |
216 " window.chrome.embeddedSearch &&" | 216 " window.chrome.embeddedSearch &&" |
217 " window.chrome.embeddedSearch.newTabPage &&" | 217 " window.chrome.embeddedSearch.newTabPage &&" |
218 " window.chrome.embeddedSearch.newTabPage.onsignedincheckdone &&" | 218 " window.chrome.embeddedSearch.newTabPage.onsignedincheckdone &&" |
219 " typeof window.chrome.embeddedSearch.newTabPage" | 219 " typeof window.chrome.embeddedSearch.newTabPage" |
220 " .onsignedincheckdone === 'function') {" | 220 " .onsignedincheckdone === 'function') {" |
221 " window.chrome.embeddedSearch.newTabPage.onsignedincheckdone(%s, %s);" | 221 " window.chrome.embeddedSearch.newTabPage.onsignedincheckdone(%s, %s);" |
222 " true;" | 222 " true;" |
223 "}"; | 223 "}"; |
224 | 224 |
225 | |
226 static const char kDispatchFocusChangedScript[] = | 225 static const char kDispatchFocusChangedScript[] = |
227 "if (window.chrome &&" | 226 "if (window.chrome &&" |
228 " window.chrome.embeddedSearch &&" | 227 " window.chrome.embeddedSearch &&" |
229 " window.chrome.embeddedSearch.searchBox &&" | 228 " window.chrome.embeddedSearch.searchBox &&" |
230 " window.chrome.embeddedSearch.searchBox.onfocuschange &&" | 229 " window.chrome.embeddedSearch.searchBox.onfocuschange &&" |
231 " typeof window.chrome.embeddedSearch.searchBox.onfocuschange ==" | 230 " typeof window.chrome.embeddedSearch.searchBox.onfocuschange ==" |
232 " 'function') {" | 231 " 'function') {" |
233 " window.chrome.embeddedSearch.searchBox.onfocuschange();" | 232 " window.chrome.embeddedSearch.searchBox.onfocuschange();" |
234 " true;" | 233 " true;" |
235 "}"; | 234 "}"; |
236 | 235 |
| 236 static const char kDispatchHistorySyncCheckResult[] = |
| 237 "if (window.chrome &&" |
| 238 " window.chrome.embeddedSearch &&" |
| 239 " window.chrome.embeddedSearch.newTabPage &&" |
| 240 " window.chrome.embeddedSearch.newTabPage.onhistorysynccheckdone &&" |
| 241 " typeof window.chrome.embeddedSearch.newTabPage" |
| 242 " .onhistorysynccheckdone === 'function') {" |
| 243 " window.chrome.embeddedSearch.newTabPage.onhistorysynccheckdone(%s);" |
| 244 " true;" |
| 245 "}"; |
| 246 |
237 static const char kDispatchInputCancelScript[] = | 247 static const char kDispatchInputCancelScript[] = |
238 "if (window.chrome &&" | 248 "if (window.chrome &&" |
239 " window.chrome.embeddedSearch &&" | 249 " window.chrome.embeddedSearch &&" |
240 " window.chrome.embeddedSearch.newTabPage &&" | 250 " window.chrome.embeddedSearch.newTabPage &&" |
241 " window.chrome.embeddedSearch.newTabPage.oninputcancel &&" | 251 " window.chrome.embeddedSearch.newTabPage.oninputcancel &&" |
242 " typeof window.chrome.embeddedSearch.newTabPage.oninputcancel ==" | 252 " typeof window.chrome.embeddedSearch.newTabPage.oninputcancel ==" |
243 " 'function') {" | 253 " 'function') {" |
244 " window.chrome.embeddedSearch.newTabPage.oninputcancel();" | 254 " window.chrome.embeddedSearch.newTabPage.oninputcancel();" |
245 " true;" | 255 " true;" |
246 "}"; | 256 "}"; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 v8::Isolate*, | 355 v8::Isolate*, |
346 v8::Handle<v8::String> name) override; | 356 v8::Handle<v8::String> name) override; |
347 | 357 |
348 // Helper function to find the RenderView. May return NULL. | 358 // Helper function to find the RenderView. May return NULL. |
349 static content::RenderView* GetRenderView(); | 359 static content::RenderView* GetRenderView(); |
350 | 360 |
351 // Sends a Chrome identity check to the browser. | 361 // Sends a Chrome identity check to the browser. |
352 static void CheckIsUserSignedInToChromeAs( | 362 static void CheckIsUserSignedInToChromeAs( |
353 const v8::FunctionCallbackInfo<v8::Value>& args); | 363 const v8::FunctionCallbackInfo<v8::Value>& args); |
354 | 364 |
| 365 // Checks whether the user sync his history. |
| 366 static void CheckIsUserSyncingHistory( |
| 367 const v8::FunctionCallbackInfo<v8::Value>& args); |
| 368 |
355 // Deletes a Most Visited item. | 369 // Deletes a Most Visited item. |
356 static void DeleteMostVisitedItem( | 370 static void DeleteMostVisitedItem( |
357 const v8::FunctionCallbackInfo<v8::Value>& args); | 371 const v8::FunctionCallbackInfo<v8::Value>& args); |
358 | 372 |
359 // Focuses the omnibox. | 373 // Focuses the omnibox. |
360 static void Focus(const v8::FunctionCallbackInfo<v8::Value>& args); | 374 static void Focus(const v8::FunctionCallbackInfo<v8::Value>& args); |
361 | 375 |
362 // Gets whether or not the app launcher is enabled. | 376 // Gets whether or not the app launcher is enabled. |
363 static void GetAppLauncherEnabled( | 377 static void GetAppLauncherEnabled( |
364 const v8::FunctionCallbackInfo<v8::Value>& args); | 378 const v8::FunctionCallbackInfo<v8::Value>& args); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 identity_match ? "true" : "false"))); | 498 identity_match ? "true" : "false"))); |
485 Dispatch(frame, script); | 499 Dispatch(frame, script); |
486 } | 500 } |
487 | 501 |
488 // static | 502 // static |
489 void SearchBoxExtension::DispatchFocusChange(blink::WebFrame* frame) { | 503 void SearchBoxExtension::DispatchFocusChange(blink::WebFrame* frame) { |
490 Dispatch(frame, kDispatchFocusChangedScript); | 504 Dispatch(frame, kDispatchFocusChangedScript); |
491 } | 505 } |
492 | 506 |
493 // static | 507 // static |
| 508 void SearchBoxExtension::DispatchHistorySyncCheckResult( |
| 509 blink::WebFrame* frame, |
| 510 bool sync_history) { |
| 511 blink::WebString script(base::UTF8ToUTF16(base::StringPrintf( |
| 512 kDispatchHistorySyncCheckResult, |
| 513 sync_history ? "true" : "false"))); |
| 514 Dispatch(frame, script); |
| 515 } |
| 516 |
| 517 // static |
494 void SearchBoxExtension::DispatchInputCancel(blink::WebFrame* frame) { | 518 void SearchBoxExtension::DispatchInputCancel(blink::WebFrame* frame) { |
495 Dispatch(frame, kDispatchInputCancelScript); | 519 Dispatch(frame, kDispatchInputCancelScript); |
496 } | 520 } |
497 | 521 |
498 // static | 522 // static |
499 void SearchBoxExtension::DispatchInputStart(blink::WebFrame* frame) { | 523 void SearchBoxExtension::DispatchInputStart(blink::WebFrame* frame) { |
500 Dispatch(frame, kDispatchInputStartScript); | 524 Dispatch(frame, kDispatchInputStartScript); |
501 } | 525 } |
502 | 526 |
503 // static | 527 // static |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { | 566 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { |
543 } | 567 } |
544 | 568 |
545 v8::Handle<v8::FunctionTemplate> | 569 v8::Handle<v8::FunctionTemplate> |
546 SearchBoxExtensionWrapper::GetNativeFunctionTemplate( | 570 SearchBoxExtensionWrapper::GetNativeFunctionTemplate( |
547 v8::Isolate* isolate, | 571 v8::Isolate* isolate, |
548 v8::Handle<v8::String> name) { | 572 v8::Handle<v8::String> name) { |
549 if (name->Equals( | 573 if (name->Equals( |
550 v8::String::NewFromUtf8(isolate, "CheckIsUserSignedInToChromeAs"))) | 574 v8::String::NewFromUtf8(isolate, "CheckIsUserSignedInToChromeAs"))) |
551 return v8::FunctionTemplate::New(isolate, CheckIsUserSignedInToChromeAs); | 575 return v8::FunctionTemplate::New(isolate, CheckIsUserSignedInToChromeAs); |
| 576 if (name->Equals( |
| 577 v8::String::NewFromUtf8(isolate, "CheckIsUserSyncingHistory"))) |
| 578 return v8::FunctionTemplate::New(isolate, CheckIsUserSyncingHistory); |
552 if (name->Equals(v8::String::NewFromUtf8(isolate, "DeleteMostVisitedItem"))) | 579 if (name->Equals(v8::String::NewFromUtf8(isolate, "DeleteMostVisitedItem"))) |
553 return v8::FunctionTemplate::New(isolate, DeleteMostVisitedItem); | 580 return v8::FunctionTemplate::New(isolate, DeleteMostVisitedItem); |
554 if (name->Equals(v8::String::NewFromUtf8(isolate, "Focus"))) | 581 if (name->Equals(v8::String::NewFromUtf8(isolate, "Focus"))) |
555 return v8::FunctionTemplate::New(isolate, Focus); | 582 return v8::FunctionTemplate::New(isolate, Focus); |
556 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetAppLauncherEnabled"))) | 583 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetAppLauncherEnabled"))) |
557 return v8::FunctionTemplate::New(isolate, GetAppLauncherEnabled); | 584 return v8::FunctionTemplate::New(isolate, GetAppLauncherEnabled); |
558 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetDispositionFromClick"))) | 585 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetDispositionFromClick"))) |
559 return v8::FunctionTemplate::New(isolate, GetDispositionFromClick); | 586 return v8::FunctionTemplate::New(isolate, GetDispositionFromClick); |
560 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItems"))) | 587 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItems"))) |
561 return v8::FunctionTemplate::New(isolate, GetMostVisitedItems); | 588 return v8::FunctionTemplate::New(isolate, GetMostVisitedItems); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 content::RenderView* render_view = GetRenderView(); | 656 content::RenderView* render_view = GetRenderView(); |
630 if (!render_view || args.Length() == 0 || args[0]->IsUndefined()) return; | 657 if (!render_view || args.Length() == 0 || args[0]->IsUndefined()) return; |
631 | 658 |
632 DVLOG(1) << render_view << " CheckIsUserSignedInToChromeAs"; | 659 DVLOG(1) << render_view << " CheckIsUserSignedInToChromeAs"; |
633 | 660 |
634 SearchBox::Get(render_view)->CheckIsUserSignedInToChromeAs( | 661 SearchBox::Get(render_view)->CheckIsUserSignedInToChromeAs( |
635 V8ValueToUTF16(args[0])); | 662 V8ValueToUTF16(args[0])); |
636 } | 663 } |
637 | 664 |
638 // static | 665 // static |
| 666 void SearchBoxExtensionWrapper::CheckIsUserSyncingHistory( |
| 667 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 668 content::RenderView* render_view = GetRenderView(); |
| 669 if (!render_view) return; |
| 670 |
| 671 DVLOG(1) << render_view << " CheckIsUserSyncingHistory"; |
| 672 SearchBox::Get(render_view)->CheckIsUserSyncingHistory(); |
| 673 } |
| 674 |
| 675 // static |
639 void SearchBoxExtensionWrapper::DeleteMostVisitedItem( | 676 void SearchBoxExtensionWrapper::DeleteMostVisitedItem( |
640 const v8::FunctionCallbackInfo<v8::Value>& args) { | 677 const v8::FunctionCallbackInfo<v8::Value>& args) { |
641 content::RenderView* render_view = GetRenderView(); | 678 content::RenderView* render_view = GetRenderView(); |
642 if (!render_view || !args.Length()) return; | 679 if (!render_view || !args.Length()) return; |
643 | 680 |
644 DVLOG(1) << render_view << " DeleteMostVisitedItem"; | 681 DVLOG(1) << render_view << " DeleteMostVisitedItem"; |
645 SearchBox::Get(render_view)->DeleteMostVisitedItem(args[0]->IntegerValue()); | 682 SearchBox::Get(render_view)->DeleteMostVisitedItem(args[0]->IntegerValue()); |
646 } | 683 } |
647 | 684 |
648 // static | 685 // static |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 if (!render_view) return; | 1194 if (!render_view) return; |
1158 | 1195 |
1159 bool display_instant_results = | 1196 bool display_instant_results = |
1160 SearchBox::Get(render_view)->display_instant_results(); | 1197 SearchBox::Get(render_view)->display_instant_results(); |
1161 DVLOG(1) << render_view << " GetDisplayInstantResults" << | 1198 DVLOG(1) << render_view << " GetDisplayInstantResults" << |
1162 display_instant_results; | 1199 display_instant_results; |
1163 args.GetReturnValue().Set(display_instant_results); | 1200 args.GetReturnValue().Set(display_instant_results); |
1164 } | 1201 } |
1165 | 1202 |
1166 } // namespace extensions_v8 | 1203 } // namespace extensions_v8 |
OLD | NEW |