| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 isolate, s.data(), v8::String::kNormalString, s.size()); | 86 isolate, s.data(), v8::String::kNormalString, s.size()); |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Throws a TypeError on the current V8 context if the args are invalid. | 89 // Throws a TypeError on the current V8 context if the args are invalid. |
| 90 void ThrowInvalidParameters(const v8::FunctionCallbackInfo<v8::Value>& args) { | 90 void ThrowInvalidParameters(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 91 v8::Isolate* isolate = args.GetIsolate(); | 91 v8::Isolate* isolate = args.GetIsolate(); |
| 92 isolate->ThrowException(v8::Exception::TypeError( | 92 isolate->ThrowException(v8::Exception::TypeError( |
| 93 v8::String::NewFromUtf8(isolate, "Invalid parameters"))); | 93 v8::String::NewFromUtf8(isolate, "Invalid parameters"))); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void Dispatch(blink::WebFrame* frame, const blink::WebString& script) { | 96 void Dispatch(blink::WebLocalFrame* frame, const blink::WebString& script) { |
| 97 if (!frame) return; | 97 if (!frame) return; |
| 98 frame->ExecuteScript(blink::WebScriptSource(script)); | 98 frame->ExecuteScript(blink::WebScriptSource(script)); |
| 99 } | 99 } |
| 100 | 100 |
| 101 v8::Local<v8::String> GenerateThumbnailURL( | 101 v8::Local<v8::String> GenerateThumbnailURL( |
| 102 v8::Isolate* isolate, | 102 v8::Isolate* isolate, |
| 103 int render_view_id, | 103 int render_view_id, |
| 104 InstantRestrictedID most_visited_item_id) { | 104 InstantRestrictedID most_visited_item_id) { |
| 105 return UTF8ToV8String( | 105 return UTF8ToV8String( |
| 106 isolate, | 106 isolate, |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 }; | 435 }; |
| 436 | 436 |
| 437 // static | 437 // static |
| 438 v8::Extension* SearchBoxExtension::Get() { | 438 v8::Extension* SearchBoxExtension::Get() { |
| 439 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). | 439 return new SearchBoxExtensionWrapper(ResourceBundle::GetSharedInstance(). |
| 440 GetRawDataResource(IDR_SEARCHBOX_API)); | 440 GetRawDataResource(IDR_SEARCHBOX_API)); |
| 441 } | 441 } |
| 442 | 442 |
| 443 // static | 443 // static |
| 444 void SearchBoxExtension::DispatchChromeIdentityCheckResult( | 444 void SearchBoxExtension::DispatchChromeIdentityCheckResult( |
| 445 blink::WebFrame* frame, | 445 blink::WebLocalFrame* frame, |
| 446 const base::string16& identity, | 446 const base::string16& identity, |
| 447 bool identity_match) { | 447 bool identity_match) { |
| 448 std::string escaped_identity = base::GetQuotedJSONString(identity); | 448 std::string escaped_identity = base::GetQuotedJSONString(identity); |
| 449 blink::WebString script(blink::WebString::FromUTF8(base::StringPrintf( | 449 blink::WebString script(blink::WebString::FromUTF8(base::StringPrintf( |
| 450 kDispatchChromeIdentityCheckResult, escaped_identity.c_str(), | 450 kDispatchChromeIdentityCheckResult, escaped_identity.c_str(), |
| 451 identity_match ? "true" : "false"))); | 451 identity_match ? "true" : "false"))); |
| 452 Dispatch(frame, script); | 452 Dispatch(frame, script); |
| 453 } | 453 } |
| 454 | 454 |
| 455 // static | 455 // static |
| 456 void SearchBoxExtension::DispatchFocusChange(blink::WebFrame* frame) { | 456 void SearchBoxExtension::DispatchFocusChange(blink::WebLocalFrame* frame) { |
| 457 Dispatch(frame, kDispatchFocusChangedScript); | 457 Dispatch(frame, kDispatchFocusChangedScript); |
| 458 } | 458 } |
| 459 | 459 |
| 460 // static | 460 // static |
| 461 void SearchBoxExtension::DispatchHistorySyncCheckResult( | 461 void SearchBoxExtension::DispatchHistorySyncCheckResult( |
| 462 blink::WebFrame* frame, | 462 blink::WebLocalFrame* frame, |
| 463 bool sync_history) { | 463 bool sync_history) { |
| 464 blink::WebString script(blink::WebString::FromUTF8(base::StringPrintf( | 464 blink::WebString script(blink::WebString::FromUTF8(base::StringPrintf( |
| 465 kDispatchHistorySyncCheckResult, sync_history ? "true" : "false"))); | 465 kDispatchHistorySyncCheckResult, sync_history ? "true" : "false"))); |
| 466 Dispatch(frame, script); | 466 Dispatch(frame, script); |
| 467 } | 467 } |
| 468 | 468 |
| 469 // static | 469 // static |
| 470 void SearchBoxExtension::DispatchInputCancel(blink::WebFrame* frame) { | 470 void SearchBoxExtension::DispatchInputCancel(blink::WebLocalFrame* frame) { |
| 471 Dispatch(frame, kDispatchInputCancelScript); | 471 Dispatch(frame, kDispatchInputCancelScript); |
| 472 } | 472 } |
| 473 | 473 |
| 474 // static | 474 // static |
| 475 void SearchBoxExtension::DispatchInputStart(blink::WebFrame* frame) { | 475 void SearchBoxExtension::DispatchInputStart(blink::WebLocalFrame* frame) { |
| 476 Dispatch(frame, kDispatchInputStartScript); | 476 Dispatch(frame, kDispatchInputStartScript); |
| 477 } | 477 } |
| 478 | 478 |
| 479 // static | 479 // static |
| 480 void SearchBoxExtension::DispatchKeyCaptureChange(blink::WebFrame* frame) { | 480 void SearchBoxExtension::DispatchKeyCaptureChange(blink::WebLocalFrame* frame) { |
| 481 Dispatch(frame, kDispatchKeyCaptureChangeScript); | 481 Dispatch(frame, kDispatchKeyCaptureChangeScript); |
| 482 } | 482 } |
| 483 | 483 |
| 484 // static | 484 // static |
| 485 void SearchBoxExtension::DispatchMostVisitedChanged( | 485 void SearchBoxExtension::DispatchMostVisitedChanged( |
| 486 blink::WebFrame* frame) { | 486 blink::WebLocalFrame* frame) { |
| 487 Dispatch(frame, kDispatchMostVisitedChangedScript); | 487 Dispatch(frame, kDispatchMostVisitedChangedScript); |
| 488 } | 488 } |
| 489 | 489 |
| 490 // static | 490 // static |
| 491 void SearchBoxExtension::DispatchSubmit(blink::WebFrame* frame) { | 491 void SearchBoxExtension::DispatchSubmit(blink::WebLocalFrame* frame) { |
| 492 Dispatch(frame, kDispatchSubmitEventScript); | 492 Dispatch(frame, kDispatchSubmitEventScript); |
| 493 } | 493 } |
| 494 | 494 |
| 495 // static | 495 // static |
| 496 void SearchBoxExtension::DispatchSuggestionChange(blink::WebFrame* frame) { | 496 void SearchBoxExtension::DispatchSuggestionChange(blink::WebLocalFrame* frame) { |
| 497 Dispatch(frame, kDispatchSuggestionChangeEventScript); | 497 Dispatch(frame, kDispatchSuggestionChangeEventScript); |
| 498 } | 498 } |
| 499 | 499 |
| 500 // static | 500 // static |
| 501 void SearchBoxExtension::DispatchThemeChange(blink::WebFrame* frame) { | 501 void SearchBoxExtension::DispatchThemeChange(blink::WebLocalFrame* frame) { |
| 502 Dispatch(frame, kDispatchThemeChangeEventScript); | 502 Dispatch(frame, kDispatchThemeChangeEventScript); |
| 503 } | 503 } |
| 504 | 504 |
| 505 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper( | 505 SearchBoxExtensionWrapper::SearchBoxExtensionWrapper( |
| 506 const base::StringPiece& code) | 506 const base::StringPiece& code) |
| 507 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { | 507 : v8::Extension(kSearchBoxExtensionName, code.data(), 0, 0, code.size()) { |
| 508 } | 508 } |
| 509 | 509 |
| 510 v8::Local<v8::FunctionTemplate> | 510 v8::Local<v8::FunctionTemplate> |
| 511 SearchBoxExtensionWrapper::GetNativeFunctionTemplate( | 511 SearchBoxExtensionWrapper::GetNativeFunctionTemplate( |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 ThrowInvalidParameters(args); | 1049 ThrowInvalidParameters(args); |
| 1050 return; | 1050 return; |
| 1051 } | 1051 } |
| 1052 | 1052 |
| 1053 DVLOG(1) << render_frame << " UndoMostVisitedDeletion"; | 1053 DVLOG(1) << render_frame << " UndoMostVisitedDeletion"; |
| 1054 SearchBox::Get(render_frame) | 1054 SearchBox::Get(render_frame) |
| 1055 ->UndoMostVisitedDeletion(args[0]->ToInteger()->Value()); | 1055 ->UndoMostVisitedDeletion(args[0]->ToInteger()->Value()); |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 } // namespace extensions_v8 | 1058 } // namespace extensions_v8 |
| OLD | NEW |