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

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: 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 "if (window.chrome &&" 209 "if (window.chrome &&"
210 " window.chrome.embeddedSearch &&" 210 " window.chrome.embeddedSearch &&"
211 " window.chrome.embeddedSearch.newTabPage &&" 211 " window.chrome.embeddedSearch.newTabPage &&"
212 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange &&" 212 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange &&"
213 " typeof window.chrome.embeddedSearch.newTabPage.onmostvisitedchange ==" 213 " typeof window.chrome.embeddedSearch.newTabPage.onmostvisitedchange =="
214 " 'function') {" 214 " 'function') {"
215 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange();" 215 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange();"
216 " true;" 216 " true;"
217 "}"; 217 "}";
218 218
219 static const char kDispatchBarsHiddenEventScript[] =
220 "if (window.chrome &&"
221 " window.chrome.searchBox &&"
222 " window.chrome.searchBox.onbarshidden &&"
223 " typeof window.chrome.searchBox.onbarshidden == 'function') {"
224 " window.chrome.searchBox.onbarshidden();"
225 " true;"
226 "}";
227
219 // ---------------------------------------------------------------------------- 228 // ----------------------------------------------------------------------------
220 229
221 class SearchBoxExtensionWrapper : public v8::Extension { 230 class SearchBoxExtensionWrapper : public v8::Extension {
222 public: 231 public:
223 explicit SearchBoxExtensionWrapper(const base::StringPiece& code); 232 explicit SearchBoxExtensionWrapper(const base::StringPiece& code);
224 233
225 // Allows v8's javascript code to call the native functions defined 234 // Allows v8's javascript code to call the native functions defined
226 // in this class for window.chrome. 235 // in this class for window.chrome.
227 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 236 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
228 v8::Handle<v8::String> name) OVERRIDE; 237 v8::Handle<v8::String> name) OVERRIDE;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 const v8::Arguments& args); 338 const v8::Arguments& args);
330 339
331 // Undoes the deletion of all Most Visited itens. 340 // Undoes the deletion of all Most Visited itens.
332 static v8::Handle<v8::Value> UndoAllMostVisitedDeletions( 341 static v8::Handle<v8::Value> UndoAllMostVisitedDeletions(
333 const v8::Arguments& args); 342 const v8::Arguments& args);
334 343
335 // Undoes the deletion of a Most Visited item. 344 // Undoes the deletion of a Most Visited item.
336 static v8::Handle<v8::Value> UndoMostVisitedDeletion( 345 static v8::Handle<v8::Value> UndoMostVisitedDeletion(
337 const v8::Arguments& args); 346 const v8::Arguments& args);
338 347
348 // Shows any attached bars.
349 static v8::Handle<v8::Value> ShowBars(const v8::Arguments& args);
350
351 // Hides any attached bars. When the bars are hidden, the "onbarshidden"
352 // event is fired to notify the page.
353 static v8::Handle<v8::Value> HideBars(const v8::Arguments& args);
354
339 private: 355 private:
340 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); 356 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper);
341 }; 357 };
342 358
343 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper( 359 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper(
344 const base::StringPiece& code) 360 const base::StringPiece& code)
345 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { 361 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) {
346 } 362 }
347 363
348 v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction( 364 v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 if (name->Equals(v8::String::New("FocusOmnibox"))) 416 if (name->Equals(v8::String::New("FocusOmnibox")))
401 return v8::FunctionTemplate::New(FocusOmnibox); 417 return v8::FunctionTemplate::New(FocusOmnibox);
402 if (name->Equals(v8::String::New("StartCapturingKeyStrokes"))) 418 if (name->Equals(v8::String::New("StartCapturingKeyStrokes")))
403 return v8::FunctionTemplate::New(StartCapturingKeyStrokes); 419 return v8::FunctionTemplate::New(StartCapturingKeyStrokes);
404 if (name->Equals(v8::String::New("StopCapturingKeyStrokes"))) 420 if (name->Equals(v8::String::New("StopCapturingKeyStrokes")))
405 return v8::FunctionTemplate::New(StopCapturingKeyStrokes); 421 return v8::FunctionTemplate::New(StopCapturingKeyStrokes);
406 if (name->Equals(v8::String::New("UndoAllMostVisitedDeletions"))) 422 if (name->Equals(v8::String::New("UndoAllMostVisitedDeletions")))
407 return v8::FunctionTemplate::New(UndoAllMostVisitedDeletions); 423 return v8::FunctionTemplate::New(UndoAllMostVisitedDeletions);
408 if (name->Equals(v8::String::New("UndoMostVisitedDeletion"))) 424 if (name->Equals(v8::String::New("UndoMostVisitedDeletion")))
409 return v8::FunctionTemplate::New(UndoMostVisitedDeletion); 425 return v8::FunctionTemplate::New(UndoMostVisitedDeletion);
426 if (name->Equals(v8::String::New("ShowBars")))
427 return v8::FunctionTemplate::New(ShowBars);
428 if (name->Equals(v8::String::New("HideBars")))
429 return v8::FunctionTemplate::New(HideBars);
410 return v8::Handle<v8::FunctionTemplate>(); 430 return v8::Handle<v8::FunctionTemplate>();
411 } 431 }
412 432
413 // static 433 // static
414 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() { 434 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() {
415 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); 435 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext();
416 if (!webframe) return NULL; 436 if (!webframe) return NULL;
417 437
418 WebKit::WebView* webview = webframe->view(); 438 WebKit::WebView* webview = webframe->view();
419 if (!webview) return NULL; // can happen during closing 439 if (!webview) return NULL; // can happen during closing
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 1022
1003 // static 1023 // static
1004 bool SearchBoxExtension::PageSupportsInstant(WebKit::WebFrame* frame) { 1024 bool SearchBoxExtension::PageSupportsInstant(WebKit::WebFrame* frame) {
1005 if (!frame) return false; 1025 if (!frame) return false;
1006 v8::HandleScope handle_scope; 1026 v8::HandleScope handle_scope;
1007 v8::Handle<v8::Value> v = frame->executeScriptAndReturnValue( 1027 v8::Handle<v8::Value> v = frame->executeScriptAndReturnValue(
1008 WebKit::WebScriptSource(kSupportsInstantScript)); 1028 WebKit::WebScriptSource(kSupportsInstantScript));
1009 return !v.IsEmpty() && v->BooleanValue(); 1029 return !v.IsEmpty() && v->BooleanValue();
1010 } 1030 }
1011 1031
1032 v8::Handle<v8::Value> SearchBoxExtensionWrapper::ShowBars(
1033 const v8::Arguments& args) {
1034 content::RenderView* render_view = GetRenderView();
1035 if (!render_view) return v8::Undefined();
1036
1037 DVLOG(1) << render_view << " ShowBars";
1038 SearchBox::Get(render_view)->ShowBars();
1039 return v8::Undefined();
1040 }
1041
1042 // static
1043 v8::Handle<v8::Value> SearchBoxExtensionWrapper::HideBars(
1044 const v8::Arguments& args) {
1045 content::RenderView* render_view = GetRenderView();
1046 if (!render_view) return v8::Undefined();
1047
1048 DVLOG(1) << render_view << " HideBars";
1049 SearchBox::Get(render_view)->HideBars();
1050 return v8::Undefined();
1051 }
1052
1012 // static 1053 // static
1013 void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) { 1054 void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) {
1014 Dispatch(frame, kDispatchChangeEventScript); 1055 Dispatch(frame, kDispatchChangeEventScript);
1015 } 1056 }
1016 1057
1017 // static 1058 // static
1018 void SearchBoxExtension::DispatchSubmit(WebKit::WebFrame* frame) { 1059 void SearchBoxExtension::DispatchSubmit(WebKit::WebFrame* frame) {
1019 Dispatch(frame, kDispatchSubmitEventScript); 1060 Dispatch(frame, kDispatchSubmitEventScript);
1020 } 1061 }
1021 1062
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 // static 1107 // static
1067 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) { 1108 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) {
1068 Dispatch(frame, kDispatchThemeChangeEventScript); 1109 Dispatch(frame, kDispatchThemeChangeEventScript);
1069 } 1110 }
1070 1111
1071 // static 1112 // static
1072 void SearchBoxExtension::DispatchMostVisitedChanged( 1113 void SearchBoxExtension::DispatchMostVisitedChanged(
1073 WebKit::WebFrame* frame) { 1114 WebKit::WebFrame* frame) {
1074 Dispatch(frame, kDispatchMostVisitedChangedScript); 1115 Dispatch(frame, kDispatchMostVisitedChangedScript);
1075 } 1116 }
1117
1118 void SearchBoxExtension::DispatchBarsHidden(WebKit::WebFrame* frame) {
1119 Dispatch(frame, kDispatchBarsHiddenEventScript);
1120 }
1121
1076 } // namespace extensions_v8 1122 } // namespace extensions_v8
OLDNEW
« chrome/renderer/searchbox/searchbox.cc ('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