| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/guest_view/web_view/web_view_internal_api.h" | 5 #include "extensions/browser/api/guest_view/web_view/web_view_internal_api.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 script.set_consumer_instance_type(UserScript::WEBVIEW); | 241 script.set_consumer_instance_type(UserScript::WEBVIEW); |
| 242 result->insert(script); | 242 result->insert(script); |
| 243 } | 243 } |
| 244 return true; | 244 return true; |
| 245 } | 245 } |
| 246 | 246 |
| 247 } // namespace | 247 } // namespace |
| 248 | 248 |
| 249 namespace extensions { | 249 namespace extensions { |
| 250 | 250 |
| 251 bool WebViewInternalExtensionFunction::RunAsync() { | 251 bool LegacyWebViewInternalExtensionFunction::RunAsync() { |
| 252 int instance_id = 0; | 252 int instance_id = 0; |
| 253 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &instance_id)); | 253 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &instance_id)); |
| 254 WebViewGuest* guest = WebViewGuest::From( | 254 WebViewGuest* guest = WebViewGuest::From( |
| 255 render_frame_host()->GetProcess()->GetID(), instance_id); | 255 render_frame_host()->GetProcess()->GetID(), instance_id); |
| 256 if (!guest) | 256 if (!guest) |
| 257 return false; | 257 return false; |
| 258 | 258 |
| 259 return RunAsyncSafe(guest); | 259 return RunAsyncSafe(guest); |
| 260 } | 260 } |
| 261 | 261 |
| 262 bool WebViewInternalExtensionFunction::PreRunValidation(std::string* error) { |
| 263 int instance_id = 0; |
| 264 EXTENSION_FUNCTION_PRERUN_VALIDATE(args_->GetInteger(0, &instance_id)); |
| 265 guest_ = WebViewGuest::From(render_frame_host()->GetProcess()->GetID(), |
| 266 instance_id); |
| 267 if (!guest_) { |
| 268 *error = "Could not find guest"; |
| 269 return false; |
| 270 } |
| 271 return true; |
| 272 } |
| 273 |
| 262 WebViewInternalCaptureVisibleRegionFunction:: | 274 WebViewInternalCaptureVisibleRegionFunction:: |
| 263 WebViewInternalCaptureVisibleRegionFunction() | 275 WebViewInternalCaptureVisibleRegionFunction() |
| 264 : is_guest_transparent_(false) {} | 276 : is_guest_transparent_(false) {} |
| 265 | 277 |
| 266 bool WebViewInternalCaptureVisibleRegionFunction::RunAsyncSafe( | 278 bool WebViewInternalCaptureVisibleRegionFunction::RunAsyncSafe( |
| 267 WebViewGuest* guest) { | 279 WebViewGuest* guest) { |
| 268 using api::extension_types::ImageDetails; | 280 using api::extension_types::ImageDetails; |
| 269 | 281 |
| 270 std::unique_ptr<web_view_internal::CaptureVisibleRegion::Params> params( | 282 std::unique_ptr<web_view_internal::CaptureVisibleRegion::Params> params( |
| 271 web_view_internal::CaptureVisibleRegion::Params::Create(*args_)); | 283 web_view_internal::CaptureVisibleRegion::Params::Create(*args_)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 break; | 329 break; |
| 318 case FAILURE_REASON_VIEW_INVISIBLE: | 330 case FAILURE_REASON_VIEW_INVISIBLE: |
| 319 reason_description = "view is invisible"; | 331 reason_description = "view is invisible"; |
| 320 break; | 332 break; |
| 321 } | 333 } |
| 322 error_ = ErrorUtils::FormatErrorMessage("Failed to capture webview: *", | 334 error_ = ErrorUtils::FormatErrorMessage("Failed to capture webview: *", |
| 323 reason_description); | 335 reason_description); |
| 324 SendResponse(false); | 336 SendResponse(false); |
| 325 } | 337 } |
| 326 | 338 |
| 327 bool WebViewInternalNavigateFunction::RunAsyncSafe(WebViewGuest* guest) { | 339 ExtensionFunction::ResponseAction WebViewInternalNavigateFunction::Run() { |
| 328 std::unique_ptr<web_view_internal::Navigate::Params> params( | 340 std::unique_ptr<web_view_internal::Navigate::Params> params( |
| 329 web_view_internal::Navigate::Params::Create(*args_)); | 341 web_view_internal::Navigate::Params::Create(*args_)); |
| 330 EXTENSION_FUNCTION_VALIDATE(params.get()); | 342 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 331 std::string src = params->src; | 343 std::string src = params->src; |
| 332 guest->NavigateGuest(src, true /* force_navigation */); | 344 guest_->NavigateGuest(src, true /* force_navigation */); |
| 333 return true; | 345 return RespondNow(NoArguments()); |
| 334 } | 346 } |
| 335 | 347 |
| 336 WebViewInternalExecuteCodeFunction::WebViewInternalExecuteCodeFunction() | 348 WebViewInternalExecuteCodeFunction::WebViewInternalExecuteCodeFunction() |
| 337 : guest_instance_id_(0), guest_src_(GURL::EmptyGURL()) { | 349 : guest_instance_id_(0) {} |
| 338 } | |
| 339 | 350 |
| 340 WebViewInternalExecuteCodeFunction::~WebViewInternalExecuteCodeFunction() { | 351 WebViewInternalExecuteCodeFunction::~WebViewInternalExecuteCodeFunction() { |
| 341 } | 352 } |
| 342 | 353 |
| 343 bool WebViewInternalExecuteCodeFunction::Init() { | 354 bool WebViewInternalExecuteCodeFunction::Init() { |
| 344 if (details_.get()) | 355 if (details_.get()) |
| 345 return true; | 356 return true; |
| 346 | 357 |
| 347 if (!args_->GetInteger(0, &guest_instance_id_)) | 358 if (!args_->GetInteger(0, &guest_instance_id_)) |
| 348 return false; | 359 return false; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 params->instance_id, host_id, script_name_list); | 550 params->instance_id, host_id, script_name_list); |
| 540 return RespondNow(NoArguments()); | 551 return RespondNow(NoArguments()); |
| 541 } | 552 } |
| 542 | 553 |
| 543 WebViewInternalSetNameFunction::WebViewInternalSetNameFunction() { | 554 WebViewInternalSetNameFunction::WebViewInternalSetNameFunction() { |
| 544 } | 555 } |
| 545 | 556 |
| 546 WebViewInternalSetNameFunction::~WebViewInternalSetNameFunction() { | 557 WebViewInternalSetNameFunction::~WebViewInternalSetNameFunction() { |
| 547 } | 558 } |
| 548 | 559 |
| 549 bool WebViewInternalSetNameFunction::RunAsyncSafe(WebViewGuest* guest) { | 560 ExtensionFunction::ResponseAction WebViewInternalSetNameFunction::Run() { |
| 550 std::unique_ptr<web_view_internal::SetName::Params> params( | 561 std::unique_ptr<web_view_internal::SetName::Params> params( |
| 551 web_view_internal::SetName::Params::Create(*args_)); | 562 web_view_internal::SetName::Params::Create(*args_)); |
| 552 EXTENSION_FUNCTION_VALIDATE(params.get()); | 563 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 553 guest->SetName(params->frame_name); | 564 guest_->SetName(params->frame_name); |
| 554 SendResponse(true); | 565 return RespondNow(NoArguments()); |
| 555 return true; | |
| 556 } | 566 } |
| 557 | 567 |
| 558 WebViewInternalSetAllowTransparencyFunction:: | 568 WebViewInternalSetAllowTransparencyFunction:: |
| 559 WebViewInternalSetAllowTransparencyFunction() { | 569 WebViewInternalSetAllowTransparencyFunction() { |
| 560 } | 570 } |
| 561 | 571 |
| 562 WebViewInternalSetAllowTransparencyFunction:: | 572 WebViewInternalSetAllowTransparencyFunction:: |
| 563 ~WebViewInternalSetAllowTransparencyFunction() { | 573 ~WebViewInternalSetAllowTransparencyFunction() { |
| 564 } | 574 } |
| 565 | 575 |
| 566 bool WebViewInternalSetAllowTransparencyFunction::RunAsyncSafe( | 576 ExtensionFunction::ResponseAction |
| 567 WebViewGuest* guest) { | 577 WebViewInternalSetAllowTransparencyFunction::Run() { |
| 568 std::unique_ptr<web_view_internal::SetAllowTransparency::Params> params( | 578 std::unique_ptr<web_view_internal::SetAllowTransparency::Params> params( |
| 569 web_view_internal::SetAllowTransparency::Params::Create(*args_)); | 579 web_view_internal::SetAllowTransparency::Params::Create(*args_)); |
| 570 EXTENSION_FUNCTION_VALIDATE(params.get()); | 580 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 571 guest->SetAllowTransparency(params->allow); | 581 guest_->SetAllowTransparency(params->allow); |
| 572 SendResponse(true); | 582 return RespondNow(NoArguments()); |
| 573 return true; | |
| 574 } | 583 } |
| 575 | 584 |
| 576 WebViewInternalSetAllowScalingFunction:: | 585 WebViewInternalSetAllowScalingFunction:: |
| 577 WebViewInternalSetAllowScalingFunction() { | 586 WebViewInternalSetAllowScalingFunction() { |
| 578 } | 587 } |
| 579 | 588 |
| 580 WebViewInternalSetAllowScalingFunction:: | 589 WebViewInternalSetAllowScalingFunction:: |
| 581 ~WebViewInternalSetAllowScalingFunction() { | 590 ~WebViewInternalSetAllowScalingFunction() { |
| 582 } | 591 } |
| 583 | 592 |
| 584 bool WebViewInternalSetAllowScalingFunction::RunAsyncSafe(WebViewGuest* guest) { | 593 ExtensionFunction::ResponseAction |
| 594 WebViewInternalSetAllowScalingFunction::Run() { |
| 585 std::unique_ptr<web_view_internal::SetAllowScaling::Params> params( | 595 std::unique_ptr<web_view_internal::SetAllowScaling::Params> params( |
| 586 web_view_internal::SetAllowScaling::Params::Create(*args_)); | 596 web_view_internal::SetAllowScaling::Params::Create(*args_)); |
| 587 EXTENSION_FUNCTION_VALIDATE(params.get()); | 597 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 588 guest->SetAllowScaling(params->allow); | 598 guest_->SetAllowScaling(params->allow); |
| 589 SendResponse(true); | 599 return RespondNow(NoArguments()); |
| 590 return true; | |
| 591 } | 600 } |
| 592 | 601 |
| 593 WebViewInternalSetZoomFunction::WebViewInternalSetZoomFunction() { | 602 WebViewInternalSetZoomFunction::WebViewInternalSetZoomFunction() { |
| 594 } | 603 } |
| 595 | 604 |
| 596 WebViewInternalSetZoomFunction::~WebViewInternalSetZoomFunction() { | 605 WebViewInternalSetZoomFunction::~WebViewInternalSetZoomFunction() { |
| 597 } | 606 } |
| 598 | 607 |
| 599 bool WebViewInternalSetZoomFunction::RunAsyncSafe(WebViewGuest* guest) { | 608 ExtensionFunction::ResponseAction WebViewInternalSetZoomFunction::Run() { |
| 600 std::unique_ptr<web_view_internal::SetZoom::Params> params( | 609 std::unique_ptr<web_view_internal::SetZoom::Params> params( |
| 601 web_view_internal::SetZoom::Params::Create(*args_)); | 610 web_view_internal::SetZoom::Params::Create(*args_)); |
| 602 EXTENSION_FUNCTION_VALIDATE(params.get()); | 611 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 603 guest->SetZoom(params->zoom_factor); | 612 guest_->SetZoom(params->zoom_factor); |
| 604 | 613 return RespondNow(NoArguments()); |
| 605 SendResponse(true); | |
| 606 return true; | |
| 607 } | 614 } |
| 608 | 615 |
| 609 WebViewInternalGetZoomFunction::WebViewInternalGetZoomFunction() { | 616 WebViewInternalGetZoomFunction::WebViewInternalGetZoomFunction() { |
| 610 } | 617 } |
| 611 | 618 |
| 612 WebViewInternalGetZoomFunction::~WebViewInternalGetZoomFunction() { | 619 WebViewInternalGetZoomFunction::~WebViewInternalGetZoomFunction() { |
| 613 } | 620 } |
| 614 | 621 |
| 615 bool WebViewInternalGetZoomFunction::RunAsyncSafe(WebViewGuest* guest) { | 622 ExtensionFunction::ResponseAction WebViewInternalGetZoomFunction::Run() { |
| 616 std::unique_ptr<web_view_internal::GetZoom::Params> params( | 623 std::unique_ptr<web_view_internal::GetZoom::Params> params( |
| 617 web_view_internal::GetZoom::Params::Create(*args_)); | 624 web_view_internal::GetZoom::Params::Create(*args_)); |
| 618 EXTENSION_FUNCTION_VALIDATE(params.get()); | 625 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 619 | 626 |
| 620 double zoom_factor = guest->GetZoom(); | 627 double zoom_factor = guest_->GetZoom(); |
| 621 SetResult(base::MakeUnique<base::FundamentalValue>(zoom_factor)); | 628 return RespondNow( |
| 622 SendResponse(true); | 629 OneArgument(base::MakeUnique<base::FundamentalValue>(zoom_factor))); |
| 623 return true; | |
| 624 } | 630 } |
| 625 | 631 |
| 626 WebViewInternalSetZoomModeFunction::WebViewInternalSetZoomModeFunction() { | 632 WebViewInternalSetZoomModeFunction::WebViewInternalSetZoomModeFunction() { |
| 627 } | 633 } |
| 628 | 634 |
| 629 WebViewInternalSetZoomModeFunction::~WebViewInternalSetZoomModeFunction() { | 635 WebViewInternalSetZoomModeFunction::~WebViewInternalSetZoomModeFunction() { |
| 630 } | 636 } |
| 631 | 637 |
| 632 bool WebViewInternalSetZoomModeFunction::RunAsyncSafe(WebViewGuest* guest) { | 638 ExtensionFunction::ResponseAction WebViewInternalSetZoomModeFunction::Run() { |
| 633 std::unique_ptr<web_view_internal::SetZoomMode::Params> params( | 639 std::unique_ptr<web_view_internal::SetZoomMode::Params> params( |
| 634 web_view_internal::SetZoomMode::Params::Create(*args_)); | 640 web_view_internal::SetZoomMode::Params::Create(*args_)); |
| 635 EXTENSION_FUNCTION_VALIDATE(params.get()); | 641 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 636 | 642 |
| 637 ZoomController::ZoomMode zoom_mode = ZoomController::ZOOM_MODE_DEFAULT; | 643 ZoomController::ZoomMode zoom_mode = ZoomController::ZOOM_MODE_DEFAULT; |
| 638 switch (params->zoom_mode) { | 644 switch (params->zoom_mode) { |
| 639 case web_view_internal::ZOOM_MODE_PER_ORIGIN: | 645 case web_view_internal::ZOOM_MODE_PER_ORIGIN: |
| 640 zoom_mode = ZoomController::ZOOM_MODE_DEFAULT; | 646 zoom_mode = ZoomController::ZOOM_MODE_DEFAULT; |
| 641 break; | 647 break; |
| 642 case web_view_internal::ZOOM_MODE_PER_VIEW: | 648 case web_view_internal::ZOOM_MODE_PER_VIEW: |
| 643 zoom_mode = ZoomController::ZOOM_MODE_ISOLATED; | 649 zoom_mode = ZoomController::ZOOM_MODE_ISOLATED; |
| 644 break; | 650 break; |
| 645 case web_view_internal::ZOOM_MODE_DISABLED: | 651 case web_view_internal::ZOOM_MODE_DISABLED: |
| 646 zoom_mode = ZoomController::ZOOM_MODE_DISABLED; | 652 zoom_mode = ZoomController::ZOOM_MODE_DISABLED; |
| 647 break; | 653 break; |
| 648 default: | 654 default: |
| 649 NOTREACHED(); | 655 NOTREACHED(); |
| 650 } | 656 } |
| 651 | 657 |
| 652 guest->SetZoomMode(zoom_mode); | 658 guest_->SetZoomMode(zoom_mode); |
| 653 | 659 return RespondNow(NoArguments()); |
| 654 SendResponse(true); | |
| 655 return true; | |
| 656 } | 660 } |
| 657 | 661 |
| 658 WebViewInternalGetZoomModeFunction::WebViewInternalGetZoomModeFunction() { | 662 WebViewInternalGetZoomModeFunction::WebViewInternalGetZoomModeFunction() { |
| 659 } | 663 } |
| 660 | 664 |
| 661 WebViewInternalGetZoomModeFunction::~WebViewInternalGetZoomModeFunction() { | 665 WebViewInternalGetZoomModeFunction::~WebViewInternalGetZoomModeFunction() { |
| 662 } | 666 } |
| 663 | 667 |
| 664 bool WebViewInternalGetZoomModeFunction::RunAsyncSafe(WebViewGuest* guest) { | 668 ExtensionFunction::ResponseAction WebViewInternalGetZoomModeFunction::Run() { |
| 665 std::unique_ptr<web_view_internal::GetZoomMode::Params> params( | 669 std::unique_ptr<web_view_internal::GetZoomMode::Params> params( |
| 666 web_view_internal::GetZoomMode::Params::Create(*args_)); | 670 web_view_internal::GetZoomMode::Params::Create(*args_)); |
| 667 EXTENSION_FUNCTION_VALIDATE(params.get()); | 671 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 668 | 672 |
| 669 web_view_internal::ZoomMode zoom_mode = web_view_internal::ZOOM_MODE_NONE; | 673 web_view_internal::ZoomMode zoom_mode = web_view_internal::ZOOM_MODE_NONE; |
| 670 switch (guest->GetZoomMode()) { | 674 switch (guest_->GetZoomMode()) { |
| 671 case ZoomController::ZOOM_MODE_DEFAULT: | 675 case ZoomController::ZOOM_MODE_DEFAULT: |
| 672 zoom_mode = web_view_internal::ZOOM_MODE_PER_ORIGIN; | 676 zoom_mode = web_view_internal::ZOOM_MODE_PER_ORIGIN; |
| 673 break; | 677 break; |
| 674 case ZoomController::ZOOM_MODE_ISOLATED: | 678 case ZoomController::ZOOM_MODE_ISOLATED: |
| 675 zoom_mode = web_view_internal::ZOOM_MODE_PER_VIEW; | 679 zoom_mode = web_view_internal::ZOOM_MODE_PER_VIEW; |
| 676 break; | 680 break; |
| 677 case ZoomController::ZOOM_MODE_DISABLED: | 681 case ZoomController::ZOOM_MODE_DISABLED: |
| 678 zoom_mode = web_view_internal::ZOOM_MODE_DISABLED; | 682 zoom_mode = web_view_internal::ZOOM_MODE_DISABLED; |
| 679 break; | 683 break; |
| 680 default: | 684 default: |
| 681 NOTREACHED(); | 685 NOTREACHED(); |
| 682 } | 686 } |
| 683 | 687 |
| 684 SetResult(base::MakeUnique<base::StringValue>( | 688 return RespondNow(OneArgument(base::MakeUnique<base::StringValue>( |
| 685 web_view_internal::ToString(zoom_mode))); | 689 web_view_internal::ToString(zoom_mode)))); |
| 686 SendResponse(true); | |
| 687 return true; | |
| 688 } | 690 } |
| 689 | 691 |
| 690 WebViewInternalFindFunction::WebViewInternalFindFunction() { | 692 WebViewInternalFindFunction::WebViewInternalFindFunction() { |
| 691 } | 693 } |
| 692 | 694 |
| 693 WebViewInternalFindFunction::~WebViewInternalFindFunction() { | 695 WebViewInternalFindFunction::~WebViewInternalFindFunction() { |
| 694 } | 696 } |
| 695 | 697 |
| 696 bool WebViewInternalFindFunction::RunAsyncSafe(WebViewGuest* guest) { | 698 bool WebViewInternalFindFunction::RunAsyncSafe(WebViewGuest* guest) { |
| 697 std::unique_ptr<web_view_internal::Find::Params> params( | 699 std::unique_ptr<web_view_internal::Find::Params> params( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 715 guest->StartFind(search_text, options, this); | 717 guest->StartFind(search_text, options, this); |
| 716 return true; | 718 return true; |
| 717 } | 719 } |
| 718 | 720 |
| 719 WebViewInternalStopFindingFunction::WebViewInternalStopFindingFunction() { | 721 WebViewInternalStopFindingFunction::WebViewInternalStopFindingFunction() { |
| 720 } | 722 } |
| 721 | 723 |
| 722 WebViewInternalStopFindingFunction::~WebViewInternalStopFindingFunction() { | 724 WebViewInternalStopFindingFunction::~WebViewInternalStopFindingFunction() { |
| 723 } | 725 } |
| 724 | 726 |
| 725 bool WebViewInternalStopFindingFunction::RunAsyncSafe(WebViewGuest* guest) { | 727 ExtensionFunction::ResponseAction WebViewInternalStopFindingFunction::Run() { |
| 726 std::unique_ptr<web_view_internal::StopFinding::Params> params( | 728 std::unique_ptr<web_view_internal::StopFinding::Params> params( |
| 727 web_view_internal::StopFinding::Params::Create(*args_)); | 729 web_view_internal::StopFinding::Params::Create(*args_)); |
| 728 EXTENSION_FUNCTION_VALIDATE(params.get()); | 730 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 729 | 731 |
| 730 // Set the StopFindAction. | 732 // Set the StopFindAction. |
| 731 content::StopFindAction action; | 733 content::StopFindAction action; |
| 732 switch (params->action) { | 734 switch (params->action) { |
| 733 case web_view_internal::STOP_FINDING_ACTION_CLEAR: | 735 case web_view_internal::STOP_FINDING_ACTION_CLEAR: |
| 734 action = content::STOP_FIND_ACTION_CLEAR_SELECTION; | 736 action = content::STOP_FIND_ACTION_CLEAR_SELECTION; |
| 735 break; | 737 break; |
| 736 case web_view_internal::STOP_FINDING_ACTION_KEEP: | 738 case web_view_internal::STOP_FINDING_ACTION_KEEP: |
| 737 action = content::STOP_FIND_ACTION_KEEP_SELECTION; | 739 action = content::STOP_FIND_ACTION_KEEP_SELECTION; |
| 738 break; | 740 break; |
| 739 case web_view_internal::STOP_FINDING_ACTION_ACTIVATE: | 741 case web_view_internal::STOP_FINDING_ACTION_ACTIVATE: |
| 740 action = content::STOP_FIND_ACTION_ACTIVATE_SELECTION; | 742 action = content::STOP_FIND_ACTION_ACTIVATE_SELECTION; |
| 741 break; | 743 break; |
| 742 default: | 744 default: |
| 743 action = content::STOP_FIND_ACTION_KEEP_SELECTION; | 745 action = content::STOP_FIND_ACTION_KEEP_SELECTION; |
| 744 } | 746 } |
| 745 | 747 |
| 746 guest->StopFinding(action); | 748 guest_->StopFinding(action); |
| 747 return true; | 749 return RespondNow(NoArguments()); |
| 748 } | 750 } |
| 749 | 751 |
| 750 WebViewInternalLoadDataWithBaseUrlFunction:: | 752 WebViewInternalLoadDataWithBaseUrlFunction:: |
| 751 WebViewInternalLoadDataWithBaseUrlFunction() { | 753 WebViewInternalLoadDataWithBaseUrlFunction() { |
| 752 } | 754 } |
| 753 | 755 |
| 754 WebViewInternalLoadDataWithBaseUrlFunction:: | 756 WebViewInternalLoadDataWithBaseUrlFunction:: |
| 755 ~WebViewInternalLoadDataWithBaseUrlFunction() { | 757 ~WebViewInternalLoadDataWithBaseUrlFunction() { |
| 756 } | 758 } |
| 757 | 759 |
| 758 bool WebViewInternalLoadDataWithBaseUrlFunction::RunAsyncSafe( | 760 ExtensionFunction::ResponseAction |
| 759 WebViewGuest* guest) { | 761 WebViewInternalLoadDataWithBaseUrlFunction::Run() { |
| 760 std::unique_ptr<web_view_internal::LoadDataWithBaseUrl::Params> params( | 762 std::unique_ptr<web_view_internal::LoadDataWithBaseUrl::Params> params( |
| 761 web_view_internal::LoadDataWithBaseUrl::Params::Create(*args_)); | 763 web_view_internal::LoadDataWithBaseUrl::Params::Create(*args_)); |
| 762 EXTENSION_FUNCTION_VALIDATE(params.get()); | 764 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 763 | 765 |
| 764 // If a virtual URL was provided, use it. Otherwise, the user will be shown | 766 // If a virtual URL was provided, use it. Otherwise, the user will be shown |
| 765 // the data URL. | 767 // the data URL. |
| 766 std::string virtual_url = | 768 std::string virtual_url = |
| 767 params->virtual_url ? *params->virtual_url : params->data_url; | 769 params->virtual_url ? *params->virtual_url : params->data_url; |
| 768 | 770 |
| 769 bool successful = guest->LoadDataWithBaseURL( | 771 bool successful = guest_->LoadDataWithBaseURL( |
| 770 params->data_url, params->base_url, virtual_url, &error_); | 772 params->data_url, params->base_url, virtual_url, &error_); |
| 771 SendResponse(successful); | 773 if (successful) |
| 772 return successful; | 774 return RespondNow(NoArguments()); |
| 775 return RespondNow(Error(error_)); |
| 773 } | 776 } |
| 774 | 777 |
| 775 WebViewInternalGoFunction::WebViewInternalGoFunction() { | 778 WebViewInternalGoFunction::WebViewInternalGoFunction() { |
| 776 } | 779 } |
| 777 | 780 |
| 778 WebViewInternalGoFunction::~WebViewInternalGoFunction() { | 781 WebViewInternalGoFunction::~WebViewInternalGoFunction() { |
| 779 } | 782 } |
| 780 | 783 |
| 781 bool WebViewInternalGoFunction::RunAsyncSafe(WebViewGuest* guest) { | 784 ExtensionFunction::ResponseAction WebViewInternalGoFunction::Run() { |
| 782 std::unique_ptr<web_view_internal::Go::Params> params( | 785 std::unique_ptr<web_view_internal::Go::Params> params( |
| 783 web_view_internal::Go::Params::Create(*args_)); | 786 web_view_internal::Go::Params::Create(*args_)); |
| 784 EXTENSION_FUNCTION_VALIDATE(params.get()); | 787 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 785 | 788 |
| 786 bool successful = guest->Go(params->relative_index); | 789 bool successful = guest_->Go(params->relative_index); |
| 787 SetResult(base::MakeUnique<base::FundamentalValue>(successful)); | 790 return RespondNow( |
| 788 SendResponse(true); | 791 OneArgument(base::MakeUnique<base::FundamentalValue>(successful))); |
| 789 return true; | |
| 790 } | 792 } |
| 791 | 793 |
| 792 WebViewInternalReloadFunction::WebViewInternalReloadFunction() { | 794 WebViewInternalReloadFunction::WebViewInternalReloadFunction() { |
| 793 } | 795 } |
| 794 | 796 |
| 795 WebViewInternalReloadFunction::~WebViewInternalReloadFunction() { | 797 WebViewInternalReloadFunction::~WebViewInternalReloadFunction() { |
| 796 } | 798 } |
| 797 | 799 |
| 798 bool WebViewInternalReloadFunction::RunAsyncSafe(WebViewGuest* guest) { | 800 ExtensionFunction::ResponseAction WebViewInternalReloadFunction::Run() { |
| 799 guest->Reload(); | 801 guest_->Reload(); |
| 800 return true; | 802 return RespondNow(NoArguments()); |
| 801 } | 803 } |
| 802 | 804 |
| 803 WebViewInternalSetPermissionFunction::WebViewInternalSetPermissionFunction() { | 805 WebViewInternalSetPermissionFunction::WebViewInternalSetPermissionFunction() { |
| 804 } | 806 } |
| 805 | 807 |
| 806 WebViewInternalSetPermissionFunction::~WebViewInternalSetPermissionFunction() { | 808 WebViewInternalSetPermissionFunction::~WebViewInternalSetPermissionFunction() { |
| 807 } | 809 } |
| 808 | 810 |
| 809 bool WebViewInternalSetPermissionFunction::RunAsyncSafe(WebViewGuest* guest) { | 811 ExtensionFunction::ResponseAction WebViewInternalSetPermissionFunction::Run() { |
| 810 std::unique_ptr<web_view_internal::SetPermission::Params> params( | 812 std::unique_ptr<web_view_internal::SetPermission::Params> params( |
| 811 web_view_internal::SetPermission::Params::Create(*args_)); | 813 web_view_internal::SetPermission::Params::Create(*args_)); |
| 812 EXTENSION_FUNCTION_VALIDATE(params.get()); | 814 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 813 | 815 |
| 814 WebViewPermissionHelper::PermissionResponseAction action = | 816 WebViewPermissionHelper::PermissionResponseAction action = |
| 815 WebViewPermissionHelper::DEFAULT; | 817 WebViewPermissionHelper::DEFAULT; |
| 816 switch (params->action) { | 818 switch (params->action) { |
| 817 case api::web_view_internal::SET_PERMISSION_ACTION_ALLOW: | 819 case api::web_view_internal::SET_PERMISSION_ACTION_ALLOW: |
| 818 action = WebViewPermissionHelper::ALLOW; | 820 action = WebViewPermissionHelper::ALLOW; |
| 819 break; | 821 break; |
| 820 case api::web_view_internal::SET_PERMISSION_ACTION_DENY: | 822 case api::web_view_internal::SET_PERMISSION_ACTION_DENY: |
| 821 action = WebViewPermissionHelper::DENY; | 823 action = WebViewPermissionHelper::DENY; |
| 822 break; | 824 break; |
| 823 case api::web_view_internal::SET_PERMISSION_ACTION_DEFAULT: | 825 case api::web_view_internal::SET_PERMISSION_ACTION_DEFAULT: |
| 824 break; | 826 break; |
| 825 default: | 827 default: |
| 826 NOTREACHED(); | 828 NOTREACHED(); |
| 827 } | 829 } |
| 828 | 830 |
| 829 std::string user_input; | 831 std::string user_input; |
| 830 if (params->user_input) | 832 if (params->user_input) |
| 831 user_input = *params->user_input; | 833 user_input = *params->user_input; |
| 832 | 834 |
| 833 WebViewPermissionHelper* web_view_permission_helper = | 835 WebViewPermissionHelper* web_view_permission_helper = |
| 834 WebViewPermissionHelper::FromWebContents(guest->web_contents()); | 836 WebViewPermissionHelper::FromWebContents(guest_->web_contents()); |
| 835 | 837 |
| 836 WebViewPermissionHelper::SetPermissionResult result = | 838 WebViewPermissionHelper::SetPermissionResult result = |
| 837 web_view_permission_helper->SetPermission( | 839 web_view_permission_helper->SetPermission( |
| 838 params->request_id, action, user_input); | 840 params->request_id, action, user_input); |
| 839 | 841 |
| 840 EXTENSION_FUNCTION_VALIDATE(result != | 842 EXTENSION_FUNCTION_VALIDATE(result != |
| 841 WebViewPermissionHelper::SET_PERMISSION_INVALID); | 843 WebViewPermissionHelper::SET_PERMISSION_INVALID); |
| 842 | 844 |
| 843 SetResult(base::MakeUnique<base::FundamentalValue>( | 845 return RespondNow(OneArgument(base::MakeUnique<base::FundamentalValue>( |
| 844 result == WebViewPermissionHelper::SET_PERMISSION_ALLOWED)); | 846 result == WebViewPermissionHelper::SET_PERMISSION_ALLOWED))); |
| 845 SendResponse(true); | |
| 846 return true; | |
| 847 } | 847 } |
| 848 | 848 |
| 849 WebViewInternalOverrideUserAgentFunction:: | 849 WebViewInternalOverrideUserAgentFunction:: |
| 850 WebViewInternalOverrideUserAgentFunction() { | 850 WebViewInternalOverrideUserAgentFunction() { |
| 851 } | 851 } |
| 852 | 852 |
| 853 WebViewInternalOverrideUserAgentFunction:: | 853 WebViewInternalOverrideUserAgentFunction:: |
| 854 ~WebViewInternalOverrideUserAgentFunction() { | 854 ~WebViewInternalOverrideUserAgentFunction() { |
| 855 } | 855 } |
| 856 | 856 |
| 857 bool WebViewInternalOverrideUserAgentFunction::RunAsyncSafe( | 857 ExtensionFunction::ResponseAction |
| 858 WebViewGuest* guest) { | 858 WebViewInternalOverrideUserAgentFunction::Run() { |
| 859 std::unique_ptr<web_view_internal::OverrideUserAgent::Params> params( | 859 std::unique_ptr<web_view_internal::OverrideUserAgent::Params> params( |
| 860 web_view_internal::OverrideUserAgent::Params::Create(*args_)); | 860 web_view_internal::OverrideUserAgent::Params::Create(*args_)); |
| 861 EXTENSION_FUNCTION_VALIDATE(params.get()); | 861 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 862 | 862 |
| 863 guest->SetUserAgentOverride(params->user_agent_override); | 863 guest_->SetUserAgentOverride(params->user_agent_override); |
| 864 return true; | 864 return RespondNow(NoArguments()); |
| 865 } | 865 } |
| 866 | 866 |
| 867 WebViewInternalStopFunction::WebViewInternalStopFunction() { | 867 WebViewInternalStopFunction::WebViewInternalStopFunction() { |
| 868 } | 868 } |
| 869 | 869 |
| 870 WebViewInternalStopFunction::~WebViewInternalStopFunction() { | 870 WebViewInternalStopFunction::~WebViewInternalStopFunction() { |
| 871 } | 871 } |
| 872 | 872 |
| 873 bool WebViewInternalStopFunction::RunAsyncSafe(WebViewGuest* guest) { | 873 ExtensionFunction::ResponseAction WebViewInternalStopFunction::Run() { |
| 874 guest->Stop(); | 874 guest_->Stop(); |
| 875 return true; | 875 return RespondNow(NoArguments()); |
| 876 } | 876 } |
| 877 | 877 |
| 878 WebViewInternalTerminateFunction::WebViewInternalTerminateFunction() { | 878 WebViewInternalTerminateFunction::WebViewInternalTerminateFunction() { |
| 879 } | 879 } |
| 880 | 880 |
| 881 WebViewInternalTerminateFunction::~WebViewInternalTerminateFunction() { | 881 WebViewInternalTerminateFunction::~WebViewInternalTerminateFunction() { |
| 882 } | 882 } |
| 883 | 883 |
| 884 bool WebViewInternalTerminateFunction::RunAsyncSafe(WebViewGuest* guest) { | 884 ExtensionFunction::ResponseAction WebViewInternalTerminateFunction::Run() { |
| 885 guest->Terminate(); | 885 guest_->Terminate(); |
| 886 return true; | 886 return RespondNow(NoArguments()); |
| 887 } | 887 } |
| 888 | 888 |
| 889 WebViewInternalClearDataFunction::WebViewInternalClearDataFunction() | 889 WebViewInternalClearDataFunction::WebViewInternalClearDataFunction() |
| 890 : remove_mask_(0), bad_message_(false) { | 890 : remove_mask_(0), bad_message_(false) { |
| 891 } | 891 } |
| 892 | 892 |
| 893 WebViewInternalClearDataFunction::~WebViewInternalClearDataFunction() { | 893 WebViewInternalClearDataFunction::~WebViewInternalClearDataFunction() { |
| 894 } | 894 } |
| 895 | 895 |
| 896 // Parses the |dataToRemove| argument to generate the remove mask. Sets | 896 // Parses the |dataToRemove| argument to generate the remove mask. Sets |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 // Will finish asynchronously. | 962 // Will finish asynchronously. |
| 963 return true; | 963 return true; |
| 964 } | 964 } |
| 965 | 965 |
| 966 void WebViewInternalClearDataFunction::ClearDataDone() { | 966 void WebViewInternalClearDataFunction::ClearDataDone() { |
| 967 Release(); // Balanced in RunAsync(). | 967 Release(); // Balanced in RunAsync(). |
| 968 SendResponse(true); | 968 SendResponse(true); |
| 969 } | 969 } |
| 970 | 970 |
| 971 } // namespace extensions | 971 } // namespace extensions |
| OLD | NEW |