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

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: Answered mathp 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 identity_match ? "true" : "false"))); 494 identity_match ? "true" : "false")));
481 Dispatch(frame, script); 495 Dispatch(frame, script);
482 } 496 }
483 497
484 // static 498 // static
485 void SearchBoxExtension::DispatchFocusChange(blink::WebFrame* frame) { 499 void SearchBoxExtension::DispatchFocusChange(blink::WebFrame* frame) {
486 Dispatch(frame, kDispatchFocusChangedScript); 500 Dispatch(frame, kDispatchFocusChangedScript);
487 } 501 }
488 502
489 // static 503 // static
504 void SearchBoxExtension::DispatchHistorySyncCheckResult(
505 blink::WebFrame* frame,
506 bool sync_history) {
507 blink::WebString script(base::UTF8ToUTF16(base::StringPrintf(
508 kDispatchHistorySyncCheckResult,
509 sync_history ? "true" : "false")));
510 Dispatch(frame, script);
511 }
512
513 // static
490 void SearchBoxExtension::DispatchInputCancel(blink::WebFrame* frame) { 514 void SearchBoxExtension::DispatchInputCancel(blink::WebFrame* frame) {
491 Dispatch(frame, kDispatchInputCancelScript); 515 Dispatch(frame, kDispatchInputCancelScript);
492 } 516 }
493 517
494 // static 518 // static
495 void SearchBoxExtension::DispatchInputStart(blink::WebFrame* frame) { 519 void SearchBoxExtension::DispatchInputStart(blink::WebFrame* frame) {
496 Dispatch(frame, kDispatchInputStartScript); 520 Dispatch(frame, kDispatchInputStartScript);
497 } 521 }
498 522
499 // static 523 // static
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { 562 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) {
539 } 563 }
540 564
541 v8::Handle<v8::FunctionTemplate> 565 v8::Handle<v8::FunctionTemplate>
542 SearchBoxExtensionWrapper::GetNativeFunctionTemplate( 566 SearchBoxExtensionWrapper::GetNativeFunctionTemplate(
543 v8::Isolate* isolate, 567 v8::Isolate* isolate,
544 v8::Handle<v8::String> name) { 568 v8::Handle<v8::String> name) {
545 if (name->Equals( 569 if (name->Equals(
546 v8::String::NewFromUtf8(isolate, "CheckIsUserSignedInToChromeAs"))) 570 v8::String::NewFromUtf8(isolate, "CheckIsUserSignedInToChromeAs")))
547 return v8::FunctionTemplate::New(isolate, CheckIsUserSignedInToChromeAs); 571 return v8::FunctionTemplate::New(isolate, CheckIsUserSignedInToChromeAs);
572 if (name->Equals(
573 v8::String::NewFromUtf8(isolate, "CheckIsUserSyncingHistory")))
574 return v8::FunctionTemplate::New(isolate, CheckIsUserSyncingHistory);
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::CheckIsUserSyncingHistory(
661 const v8::FunctionCallbackInfo<v8::Value>& args) {
662 content::RenderView* render_view = GetRenderView();
663 if (!render_view) return;
664
665 DVLOG(1) << render_view << " CheckIsUserSyncingHistory";
666 SearchBox::Get(render_view)->CheckIsUserSyncingHistory();
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
« chrome/common/render_messages.h ('K') | « chrome/renderer/searchbox/searchbox_extension.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698