Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Side by Side Diff: chrome/renderer/searchbox/searchbox_extension.cc

Issue 701973002: Separate checking the user identity and checking if the user is syncing his history in two differen… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 "if (window.chrome &&" 326 "if (window.chrome &&"
327 " window.chrome.embeddedSearch &&" 327 " window.chrome.embeddedSearch &&"
328 " window.chrome.embeddedSearch.searchBox &&" 328 " window.chrome.embeddedSearch.searchBox &&"
329 " window.chrome.embeddedSearch.searchBox.ontogglevoicesearch &&" 329 " window.chrome.embeddedSearch.searchBox.ontogglevoicesearch &&"
330 " typeof window.chrome.embeddedSearch.searchBox.ontogglevoicesearch ==" 330 " typeof window.chrome.embeddedSearch.searchBox.ontogglevoicesearch =="
331 " 'function') {" 331 " 'function') {"
332 " window.chrome.embeddedSearch.searchBox.ontogglevoicesearch();" 332 " window.chrome.embeddedSearch.searchBox.ontogglevoicesearch();"
333 " true;" 333 " true;"
334 "}"; 334 "}";
335 335
336 static const char kDispatchCheckUserSyncHistoryResult[] =
337 "if (window.chrome &&"
338 " window.chrome.embeddedSearch &&"
339 " window.chrome.embeddedSearch.newTabPage &&"
340 " window.chrome.embeddedSearch.newTabPage.onusersynchistorydone &&"
341 " typeof window.chrome.embeddedSearch.newTabPage"
342 " .onusersynchistorydone === 'function') {"
343 " window.chrome.embeddedSearch.newTabPage.onusersynchistorydone(%s);"
344 " true;"
345 "}";
346
336 // ---------------------------------------------------------------------------- 347 // ----------------------------------------------------------------------------
337 348
338 class SearchBoxExtensionWrapper : public v8::Extension { 349 class SearchBoxExtensionWrapper : public v8::Extension {
339 public: 350 public:
340 explicit SearchBoxExtensionWrapper(const base::StringPiece& code); 351 explicit SearchBoxExtensionWrapper(const base::StringPiece& code);
341 352
342 // Allows v8's javascript code to call the native functions defined 353 // Allows v8's javascript code to call the native functions defined
343 // in this class for window.chrome. 354 // in this class for window.chrome.
344 v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate( 355 v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate(
345 v8::Isolate*, 356 v8::Isolate*,
346 v8::Handle<v8::String> name) override; 357 v8::Handle<v8::String> name) override;
347 358
348 // Helper function to find the RenderView. May return NULL. 359 // Helper function to find the RenderView. May return NULL.
349 static content::RenderView* GetRenderView(); 360 static content::RenderView* GetRenderView();
350 361
351 // Sends a Chrome identity check to the browser. 362 // Sends a Chrome identity check to the browser.
352 static void CheckIsUserSignedInToChromeAs( 363 static void CheckIsUserSignedInToChromeAs(
353 const v8::FunctionCallbackInfo<v8::Value>& args); 364 const v8::FunctionCallbackInfo<v8::Value>& args);
354 365
366 // Checks whether the user sync his history.
367 static void CheckUserSyncHistory(
368 const v8::FunctionCallbackInfo<v8::Value>& args);
369
355 // Deletes a Most Visited item. 370 // Deletes a Most Visited item.
356 static void DeleteMostVisitedItem( 371 static void DeleteMostVisitedItem(
357 const v8::FunctionCallbackInfo<v8::Value>& args); 372 const v8::FunctionCallbackInfo<v8::Value>& args);
358 373
359 // Focuses the omnibox. 374 // Focuses the omnibox.
360 static void Focus(const v8::FunctionCallbackInfo<v8::Value>& args); 375 static void Focus(const v8::FunctionCallbackInfo<v8::Value>& args);
361 376
362 // Gets whether or not the app launcher is enabled. 377 // Gets whether or not the app launcher is enabled.
363 static void GetAppLauncherEnabled( 378 static void GetAppLauncherEnabled(
364 const v8::FunctionCallbackInfo<v8::Value>& args); 379 const v8::FunctionCallbackInfo<v8::Value>& args);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 void SearchBoxExtension::DispatchThemeChange(blink::WebFrame* frame) { 541 void SearchBoxExtension::DispatchThemeChange(blink::WebFrame* frame) {
527 Dispatch(frame, kDispatchThemeChangeEventScript); 542 Dispatch(frame, kDispatchThemeChangeEventScript);
528 } 543 }
529 544
530 // static 545 // static
531 void SearchBoxExtension::DispatchToggleVoiceSearch( 546 void SearchBoxExtension::DispatchToggleVoiceSearch(
532 blink::WebFrame* frame) { 547 blink::WebFrame* frame) {
533 Dispatch(frame, kDispatchToggleVoiceSearchScript); 548 Dispatch(frame, kDispatchToggleVoiceSearchScript);
534 } 549 }
535 550
551 // static
552 void SearchBoxExtension::DispatchCheckUserSyncHistoryResult(
553 blink::WebFrame* frame,
554 bool sync_history) {
555 blink::WebString script(base::UTF8ToUTF16(base::StringPrintf(
556 kDispatchCheckUserSyncHistoryResult,
557 sync_history ? "true" : "false")));
558 Dispatch(frame, script);
559 }
560
536 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper( 561 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper(
537 const base::StringPiece& code) 562 const base::StringPiece& code)
538 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { 563 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) {
539 } 564 }
540 565
541 v8::Handle<v8::FunctionTemplate> 566 v8::Handle<v8::FunctionTemplate>
542 SearchBoxExtensionWrapper::GetNativeFunctionTemplate( 567 SearchBoxExtensionWrapper::GetNativeFunctionTemplate(
543 v8::Isolate* isolate, 568 v8::Isolate* isolate,
544 v8::Handle<v8::String> name) { 569 v8::Handle<v8::String> name) {
545 if (name->Equals( 570 if (name->Equals(
546 v8::String::NewFromUtf8(isolate, "CheckIsUserSignedInToChromeAs"))) 571 v8::String::NewFromUtf8(isolate, "CheckIsUserSignedInToChromeAs")))
547 return v8::FunctionTemplate::New(isolate, CheckIsUserSignedInToChromeAs); 572 return v8::FunctionTemplate::New(isolate, CheckIsUserSignedInToChromeAs);
573 if (name->Equals(v8::String::NewFromUtf8(isolate, "CheckUserSyncHistory")))
574 return v8::FunctionTemplate::New(isolate, CheckUserSyncHistory);
548 if (name->Equals(v8::String::NewFromUtf8(isolate, "DeleteMostVisitedItem"))) 575 if (name->Equals(v8::String::NewFromUtf8(isolate, "DeleteMostVisitedItem")))
549 return v8::FunctionTemplate::New(isolate, DeleteMostVisitedItem); 576 return v8::FunctionTemplate::New(isolate, DeleteMostVisitedItem);
550 if (name->Equals(v8::String::NewFromUtf8(isolate, "Focus"))) 577 if (name->Equals(v8::String::NewFromUtf8(isolate, "Focus")))
551 return v8::FunctionTemplate::New(isolate, Focus); 578 return v8::FunctionTemplate::New(isolate, Focus);
552 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetAppLauncherEnabled"))) 579 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetAppLauncherEnabled")))
553 return v8::FunctionTemplate::New(isolate, GetAppLauncherEnabled); 580 return v8::FunctionTemplate::New(isolate, GetAppLauncherEnabled);
554 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetDispositionFromClick"))) 581 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetDispositionFromClick")))
555 return v8::FunctionTemplate::New(isolate, GetDispositionFromClick); 582 return v8::FunctionTemplate::New(isolate, GetDispositionFromClick);
556 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItems"))) 583 if (name->Equals(v8::String::NewFromUtf8(isolate, "GetMostVisitedItems")))
557 return v8::FunctionTemplate::New(isolate, GetMostVisitedItems); 584 return v8::FunctionTemplate::New(isolate, GetMostVisitedItems);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 content::RenderView* render_view = GetRenderView(); 650 content::RenderView* render_view = GetRenderView();
624 if (!render_view || args.Length() == 0 || args[0]->IsUndefined()) return; 651 if (!render_view || args.Length() == 0 || args[0]->IsUndefined()) return;
625 652
626 DVLOG(1) << render_view << " CheckIsUserSignedInToChromeAs"; 653 DVLOG(1) << render_view << " CheckIsUserSignedInToChromeAs";
627 654
628 SearchBox::Get(render_view)->CheckIsUserSignedInToChromeAs( 655 SearchBox::Get(render_view)->CheckIsUserSignedInToChromeAs(
629 V8ValueToUTF16(args[0])); 656 V8ValueToUTF16(args[0]));
630 } 657 }
631 658
632 // static 659 // static
660 void SearchBoxExtensionWrapper::CheckUserSyncHistory(
661 const v8::FunctionCallbackInfo<v8::Value>& args) {
662 content::RenderView* render_view = GetRenderView();
663 if (!render_view) return;
664
665 DVLOG(1) << render_view << " CheckUserSyncHistory";
666 SearchBox::Get(render_view)->CheckUserSyncHistory();
667 }
668
669 // static
633 void SearchBoxExtensionWrapper::DeleteMostVisitedItem( 670 void SearchBoxExtensionWrapper::DeleteMostVisitedItem(
634 const v8::FunctionCallbackInfo<v8::Value>& args) { 671 const v8::FunctionCallbackInfo<v8::Value>& args) {
635 content::RenderView* render_view = GetRenderView(); 672 content::RenderView* render_view = GetRenderView();
636 if (!render_view || !args.Length()) return; 673 if (!render_view || !args.Length()) return;
637 674
638 DVLOG(1) << render_view << " DeleteMostVisitedItem"; 675 DVLOG(1) << render_view << " DeleteMostVisitedItem";
639 SearchBox::Get(render_view)->DeleteMostVisitedItem(args[0]->IntegerValue()); 676 SearchBox::Get(render_view)->DeleteMostVisitedItem(args[0]->IntegerValue());
640 } 677 }
641 678
642 // static 679 // static
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 if (!render_view) return; 1155 if (!render_view) return;
1119 1156
1120 bool display_instant_results = 1157 bool display_instant_results =
1121 SearchBox::Get(render_view)->display_instant_results(); 1158 SearchBox::Get(render_view)->display_instant_results();
1122 DVLOG(1) << render_view << " GetDisplayInstantResults" << 1159 DVLOG(1) << render_view << " GetDisplayInstantResults" <<
1123 display_instant_results; 1160 display_instant_results;
1124 args.GetReturnValue().Set(display_instant_results); 1161 args.GetReturnValue().Set(display_instant_results);
1125 } 1162 }
1126 1163
1127 } // namespace extensions_v8 1164 } // namespace extensions_v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698