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

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

Issue 12631008: alternate ntp: implement Show/HideBars API to reduce jank when showing/hiding bars (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased, resolved conflicts Created 7 years, 9 months 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 | Annotate | Revision Log
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/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 "if (window.chrome &&" 231 "if (window.chrome &&"
232 " window.chrome.embeddedSearch &&" 232 " window.chrome.embeddedSearch &&"
233 " window.chrome.embeddedSearch.newTabPage &&" 233 " window.chrome.embeddedSearch.newTabPage &&"
234 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange &&" 234 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange &&"
235 " typeof window.chrome.embeddedSearch.newTabPage.onmostvisitedchange ==" 235 " typeof window.chrome.embeddedSearch.newTabPage.onmostvisitedchange =="
236 " 'function') {" 236 " 'function') {"
237 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange();" 237 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange();"
238 " true;" 238 " true;"
239 "}"; 239 "}";
240 240
241 static const char kDispatchBarsHiddenEventScript[] =
242 "if (window.chrome &&"
243 " window.chrome.searchBox &&"
244 " window.chrome.searchBox.onbarshidden &&"
245 " typeof window.chrome.searchBox.onbarshidden == 'function') {"
246 " window.chrome.searchBox.onbarshidden();"
247 " true;"
248 "}";
249
241 // ---------------------------------------------------------------------------- 250 // ----------------------------------------------------------------------------
242 251
243 class SearchBoxExtensionWrapper : public v8::Extension { 252 class SearchBoxExtensionWrapper : public v8::Extension {
244 public: 253 public:
245 explicit SearchBoxExtensionWrapper(const base::StringPiece& code); 254 explicit SearchBoxExtensionWrapper(const base::StringPiece& code);
246 255
247 // Allows v8's javascript code to call the native functions defined 256 // Allows v8's javascript code to call the native functions defined
248 // in this class for window.chrome. 257 // in this class for window.chrome.
249 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 258 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
250 v8::Handle<v8::String> name) OVERRIDE; 259 v8::Handle<v8::String> name) OVERRIDE;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 const v8::Arguments& args); 366 const v8::Arguments& args);
358 367
359 // Undoes the deletion of all Most Visited itens. 368 // Undoes the deletion of all Most Visited itens.
360 static v8::Handle<v8::Value> UndoAllMostVisitedDeletions( 369 static v8::Handle<v8::Value> UndoAllMostVisitedDeletions(
361 const v8::Arguments& args); 370 const v8::Arguments& args);
362 371
363 // Undoes the deletion of a Most Visited item. 372 // Undoes the deletion of a Most Visited item.
364 static v8::Handle<v8::Value> UndoMostVisitedDeletion( 373 static v8::Handle<v8::Value> UndoMostVisitedDeletion(
365 const v8::Arguments& args); 374 const v8::Arguments& args);
366 375
376 // Shows any attached bars.
377 static v8::Handle<v8::Value> ShowBars(const v8::Arguments& args);
378
379 // Hides any attached bars. When the bars are hidden, the "onbarshidden"
380 // event is fired to notify the page.
381 static v8::Handle<v8::Value> HideBars(const v8::Arguments& args);
382
367 private: 383 private:
368 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); 384 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper);
369 }; 385 };
370 386
371 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper( 387 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper(
372 const base::StringPiece& code) 388 const base::StringPiece& code)
373 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { 389 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) {
374 } 390 }
375 391
376 v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction( 392 v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction(
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 if (name->Equals(v8::String::New("FocusOmnibox"))) 448 if (name->Equals(v8::String::New("FocusOmnibox")))
433 return v8::FunctionTemplate::New(FocusOmnibox); 449 return v8::FunctionTemplate::New(FocusOmnibox);
434 if (name->Equals(v8::String::New("StartCapturingKeyStrokes"))) 450 if (name->Equals(v8::String::New("StartCapturingKeyStrokes")))
435 return v8::FunctionTemplate::New(StartCapturingKeyStrokes); 451 return v8::FunctionTemplate::New(StartCapturingKeyStrokes);
436 if (name->Equals(v8::String::New("StopCapturingKeyStrokes"))) 452 if (name->Equals(v8::String::New("StopCapturingKeyStrokes")))
437 return v8::FunctionTemplate::New(StopCapturingKeyStrokes); 453 return v8::FunctionTemplate::New(StopCapturingKeyStrokes);
438 if (name->Equals(v8::String::New("UndoAllMostVisitedDeletions"))) 454 if (name->Equals(v8::String::New("UndoAllMostVisitedDeletions")))
439 return v8::FunctionTemplate::New(UndoAllMostVisitedDeletions); 455 return v8::FunctionTemplate::New(UndoAllMostVisitedDeletions);
440 if (name->Equals(v8::String::New("UndoMostVisitedDeletion"))) 456 if (name->Equals(v8::String::New("UndoMostVisitedDeletion")))
441 return v8::FunctionTemplate::New(UndoMostVisitedDeletion); 457 return v8::FunctionTemplate::New(UndoMostVisitedDeletion);
458 if (name->Equals(v8::String::New("ShowBars")))
459 return v8::FunctionTemplate::New(ShowBars);
460 if (name->Equals(v8::String::New("HideBars")))
461 return v8::FunctionTemplate::New(HideBars);
442 return v8::Handle<v8::FunctionTemplate>(); 462 return v8::Handle<v8::FunctionTemplate>();
443 } 463 }
444 464
445 // static 465 // static
446 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() { 466 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() {
447 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); 467 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext();
448 if (!webframe) return NULL; 468 if (!webframe) return NULL;
449 469
450 WebKit::WebView* webview = webframe->view(); 470 WebKit::WebView* webview = webframe->view();
451 if (!webview) return NULL; // can happen during closing 471 if (!webview) return NULL; // can happen during closing
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 1098
1079 // static 1099 // static
1080 bool SearchBoxExtension::PageSupportsInstant(WebKit::WebFrame* frame) { 1100 bool SearchBoxExtension::PageSupportsInstant(WebKit::WebFrame* frame) {
1081 if (!frame) return false; 1101 if (!frame) return false;
1082 v8::HandleScope handle_scope; 1102 v8::HandleScope handle_scope;
1083 v8::Handle<v8::Value> v = frame->executeScriptAndReturnValue( 1103 v8::Handle<v8::Value> v = frame->executeScriptAndReturnValue(
1084 WebKit::WebScriptSource(kSupportsInstantScript)); 1104 WebKit::WebScriptSource(kSupportsInstantScript));
1085 return !v.IsEmpty() && v->BooleanValue(); 1105 return !v.IsEmpty() && v->BooleanValue();
1086 } 1106 }
1087 1107
1108 v8::Handle<v8::Value> SearchBoxExtensionWrapper::ShowBars(
1109 const v8::Arguments& args) {
1110 content::RenderView* render_view = GetRenderView();
1111 if (!render_view) return v8::Undefined();
1112
1113 DVLOG(1) << render_view << " ShowBars";
1114 SearchBox::Get(render_view)->ShowBars();
1115 return v8::Undefined();
1116 }
1117
1118 // static
1119 v8::Handle<v8::Value> SearchBoxExtensionWrapper::HideBars(
1120 const v8::Arguments& args) {
1121 content::RenderView* render_view = GetRenderView();
1122 if (!render_view) return v8::Undefined();
1123
1124 DVLOG(1) << render_view << " HideBars";
1125 SearchBox::Get(render_view)->HideBars();
1126 return v8::Undefined();
1127 }
1128
1088 // static 1129 // static
1089 void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) { 1130 void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) {
1090 Dispatch(frame, kDispatchChangeEventScript); 1131 Dispatch(frame, kDispatchChangeEventScript);
1091 } 1132 }
1092 1133
1093 // static 1134 // static
1094 void SearchBoxExtension::DispatchSubmit(WebKit::WebFrame* frame) { 1135 void SearchBoxExtension::DispatchSubmit(WebKit::WebFrame* frame) {
1095 Dispatch(frame, kDispatchSubmitEventScript); 1136 Dispatch(frame, kDispatchSubmitEventScript);
1096 } 1137 }
1097 1138
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 // static 1183 // static
1143 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) { 1184 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) {
1144 Dispatch(frame, kDispatchThemeChangeEventScript); 1185 Dispatch(frame, kDispatchThemeChangeEventScript);
1145 } 1186 }
1146 1187
1147 // static 1188 // static
1148 void SearchBoxExtension::DispatchMostVisitedChanged( 1189 void SearchBoxExtension::DispatchMostVisitedChanged(
1149 WebKit::WebFrame* frame) { 1190 WebKit::WebFrame* frame) {
1150 Dispatch(frame, kDispatchMostVisitedChangedScript); 1191 Dispatch(frame, kDispatchMostVisitedChangedScript);
1151 } 1192 }
1193
1194 void SearchBoxExtension::DispatchBarsHidden(WebKit::WebFrame* frame) {
1195 Dispatch(frame, kDispatchBarsHiddenEventScript);
1196 }
1197
1152 } // namespace extensions_v8 1198 } // namespace extensions_v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698