| 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/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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 "if (window.chrome &&" | 232 "if (window.chrome &&" |
| 233 " window.chrome.embeddedSearch &&" | 233 " window.chrome.embeddedSearch &&" |
| 234 " window.chrome.embeddedSearch.newTabPage &&" | 234 " window.chrome.embeddedSearch.newTabPage &&" |
| 235 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange &&" | 235 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange &&" |
| 236 " typeof window.chrome.embeddedSearch.newTabPage.onmostvisitedchange ==" | 236 " typeof window.chrome.embeddedSearch.newTabPage.onmostvisitedchange ==" |
| 237 " 'function') {" | 237 " 'function') {" |
| 238 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange();" | 238 " window.chrome.embeddedSearch.newTabPage.onmostvisitedchange();" |
| 239 " true;" | 239 " true;" |
| 240 "}"; | 240 "}"; |
| 241 | 241 |
| 242 static const char kDispatchBarsHiddenEventScript[] = |
| 243 "if (window.chrome &&" |
| 244 " window.chrome.searchBox &&" |
| 245 " window.chrome.searchBox.onbarshidden &&" |
| 246 " typeof window.chrome.searchBox.onbarshidden == 'function') {" |
| 247 " window.chrome.searchBox.onbarshidden();" |
| 248 " true;" |
| 249 "}"; |
| 250 |
| 242 // ---------------------------------------------------------------------------- | 251 // ---------------------------------------------------------------------------- |
| 243 | 252 |
| 244 class SearchBoxExtensionWrapper : public v8::Extension { | 253 class SearchBoxExtensionWrapper : public v8::Extension { |
| 245 public: | 254 public: |
| 246 explicit SearchBoxExtensionWrapper(const base::StringPiece& code); | 255 explicit SearchBoxExtensionWrapper(const base::StringPiece& code); |
| 247 | 256 |
| 248 // Allows v8's javascript code to call the native functions defined | 257 // Allows v8's javascript code to call the native functions defined |
| 249 // in this class for window.chrome. | 258 // in this class for window.chrome. |
| 250 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( | 259 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( |
| 251 v8::Handle<v8::String> name) OVERRIDE; | 260 v8::Handle<v8::String> name) OVERRIDE; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 const v8::Arguments& args); | 367 const v8::Arguments& args); |
| 359 | 368 |
| 360 // Undoes the deletion of all Most Visited itens. | 369 // Undoes the deletion of all Most Visited itens. |
| 361 static v8::Handle<v8::Value> UndoAllMostVisitedDeletions( | 370 static v8::Handle<v8::Value> UndoAllMostVisitedDeletions( |
| 362 const v8::Arguments& args); | 371 const v8::Arguments& args); |
| 363 | 372 |
| 364 // Undoes the deletion of a Most Visited item. | 373 // Undoes the deletion of a Most Visited item. |
| 365 static v8::Handle<v8::Value> UndoMostVisitedDeletion( | 374 static v8::Handle<v8::Value> UndoMostVisitedDeletion( |
| 366 const v8::Arguments& args); | 375 const v8::Arguments& args); |
| 367 | 376 |
| 377 // Shows any attached bars. |
| 378 static v8::Handle<v8::Value> ShowBars(const v8::Arguments& args); |
| 379 |
| 380 // Hides any attached bars. When the bars are hidden, the "onbarshidden" |
| 381 // event is fired to notify the page. |
| 382 static v8::Handle<v8::Value> HideBars(const v8::Arguments& args); |
| 383 |
| 368 private: | 384 private: |
| 369 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); | 385 DISALLOW_COPY_AND_ASSIGN(SearchBoxExtensionWrapper); |
| 370 }; | 386 }; |
| 371 | 387 |
| 372 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper( | 388 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper( |
| 373 const base::StringPiece& code) | 389 const base::StringPiece& code) |
| 374 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { | 390 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { |
| 375 } | 391 } |
| 376 | 392 |
| 377 v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction( | 393 v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 if (name->Equals(v8::String::New("FocusOmnibox"))) | 449 if (name->Equals(v8::String::New("FocusOmnibox"))) |
| 434 return v8::FunctionTemplate::New(FocusOmnibox); | 450 return v8::FunctionTemplate::New(FocusOmnibox); |
| 435 if (name->Equals(v8::String::New("StartCapturingKeyStrokes"))) | 451 if (name->Equals(v8::String::New("StartCapturingKeyStrokes"))) |
| 436 return v8::FunctionTemplate::New(StartCapturingKeyStrokes); | 452 return v8::FunctionTemplate::New(StartCapturingKeyStrokes); |
| 437 if (name->Equals(v8::String::New("StopCapturingKeyStrokes"))) | 453 if (name->Equals(v8::String::New("StopCapturingKeyStrokes"))) |
| 438 return v8::FunctionTemplate::New(StopCapturingKeyStrokes); | 454 return v8::FunctionTemplate::New(StopCapturingKeyStrokes); |
| 439 if (name->Equals(v8::String::New("UndoAllMostVisitedDeletions"))) | 455 if (name->Equals(v8::String::New("UndoAllMostVisitedDeletions"))) |
| 440 return v8::FunctionTemplate::New(UndoAllMostVisitedDeletions); | 456 return v8::FunctionTemplate::New(UndoAllMostVisitedDeletions); |
| 441 if (name->Equals(v8::String::New("UndoMostVisitedDeletion"))) | 457 if (name->Equals(v8::String::New("UndoMostVisitedDeletion"))) |
| 442 return v8::FunctionTemplate::New(UndoMostVisitedDeletion); | 458 return v8::FunctionTemplate::New(UndoMostVisitedDeletion); |
| 459 if (name->Equals(v8::String::New("ShowBars"))) |
| 460 return v8::FunctionTemplate::New(ShowBars); |
| 461 if (name->Equals(v8::String::New("HideBars"))) |
| 462 return v8::FunctionTemplate::New(HideBars); |
| 443 return v8::Handle<v8::FunctionTemplate>(); | 463 return v8::Handle<v8::FunctionTemplate>(); |
| 444 } | 464 } |
| 445 | 465 |
| 446 // static | 466 // static |
| 447 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() { | 467 content::RenderView* SearchBoxExtensionWrapper::GetRenderView() { |
| 448 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); | 468 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); |
| 449 if (!webframe) return NULL; | 469 if (!webframe) return NULL; |
| 450 | 470 |
| 451 WebKit::WebView* webview = webframe->view(); | 471 WebKit::WebView* webview = webframe->view(); |
| 452 if (!webview) return NULL; // can happen during closing | 472 if (!webview) return NULL; // can happen during closing |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 | 1112 |
| 1093 // static | 1113 // static |
| 1094 bool SearchBoxExtension::PageSupportsInstant(WebKit::WebFrame* frame) { | 1114 bool SearchBoxExtension::PageSupportsInstant(WebKit::WebFrame* frame) { |
| 1095 if (!frame) return false; | 1115 if (!frame) return false; |
| 1096 v8::HandleScope handle_scope; | 1116 v8::HandleScope handle_scope; |
| 1097 v8::Handle<v8::Value> v = frame->executeScriptAndReturnValue( | 1117 v8::Handle<v8::Value> v = frame->executeScriptAndReturnValue( |
| 1098 WebKit::WebScriptSource(kSupportsInstantScript)); | 1118 WebKit::WebScriptSource(kSupportsInstantScript)); |
| 1099 return !v.IsEmpty() && v->BooleanValue(); | 1119 return !v.IsEmpty() && v->BooleanValue(); |
| 1100 } | 1120 } |
| 1101 | 1121 |
| 1122 v8::Handle<v8::Value> SearchBoxExtensionWrapper::ShowBars( |
| 1123 const v8::Arguments& args) { |
| 1124 content::RenderView* render_view = GetRenderView(); |
| 1125 if (!render_view) return v8::Undefined(); |
| 1126 |
| 1127 DVLOG(1) << render_view << " ShowBars"; |
| 1128 SearchBox::Get(render_view)->ShowBars(); |
| 1129 return v8::Undefined(); |
| 1130 } |
| 1131 |
| 1132 // static |
| 1133 v8::Handle<v8::Value> SearchBoxExtensionWrapper::HideBars( |
| 1134 const v8::Arguments& args) { |
| 1135 content::RenderView* render_view = GetRenderView(); |
| 1136 if (!render_view) return v8::Undefined(); |
| 1137 |
| 1138 DVLOG(1) << render_view << " HideBars"; |
| 1139 SearchBox::Get(render_view)->HideBars(); |
| 1140 return v8::Undefined(); |
| 1141 } |
| 1142 |
| 1102 // static | 1143 // static |
| 1103 void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) { | 1144 void SearchBoxExtension::DispatchChange(WebKit::WebFrame* frame) { |
| 1104 Dispatch(frame, kDispatchChangeEventScript); | 1145 Dispatch(frame, kDispatchChangeEventScript); |
| 1105 } | 1146 } |
| 1106 | 1147 |
| 1107 // static | 1148 // static |
| 1108 void SearchBoxExtension::DispatchSubmit(WebKit::WebFrame* frame) { | 1149 void SearchBoxExtension::DispatchSubmit(WebKit::WebFrame* frame) { |
| 1109 Dispatch(frame, kDispatchSubmitEventScript); | 1150 Dispatch(frame, kDispatchSubmitEventScript); |
| 1110 } | 1151 } |
| 1111 | 1152 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 // static | 1197 // static |
| 1157 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) { | 1198 void SearchBoxExtension::DispatchThemeChange(WebKit::WebFrame* frame) { |
| 1158 Dispatch(frame, kDispatchThemeChangeEventScript); | 1199 Dispatch(frame, kDispatchThemeChangeEventScript); |
| 1159 } | 1200 } |
| 1160 | 1201 |
| 1161 // static | 1202 // static |
| 1162 void SearchBoxExtension::DispatchMostVisitedChanged( | 1203 void SearchBoxExtension::DispatchMostVisitedChanged( |
| 1163 WebKit::WebFrame* frame) { | 1204 WebKit::WebFrame* frame) { |
| 1164 Dispatch(frame, kDispatchMostVisitedChangedScript); | 1205 Dispatch(frame, kDispatchMostVisitedChangedScript); |
| 1165 } | 1206 } |
| 1207 |
| 1208 void SearchBoxExtension::DispatchBarsHidden(WebKit::WebFrame* frame) { |
| 1209 Dispatch(frame, kDispatchBarsHiddenEventScript); |
| 1210 } |
| 1211 |
| 1166 } // namespace extensions_v8 | 1212 } // namespace extensions_v8 |
| OLD | NEW |