| 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/usb/usb_api.h" | 5 #include "extensions/browser/api/usb/usb_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/barrier_closure.h" | 10 #include "base/barrier_closure.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "device/core/device_client.h" | 12 #include "device/core/device_client.h" |
| 13 #include "device/usb/usb_descriptors.h" | 13 #include "device/usb/usb_descriptors.h" |
| 14 #include "device/usb/usb_device_handle.h" | 14 #include "device/usb/usb_device_handle.h" |
| 15 #include "device/usb/usb_service.h" | 15 #include "device/usb/usb_service.h" |
| 16 #include "extensions/browser/api/device_permissions_manager.h" | 16 #include "extensions/browser/api/device_permissions_manager.h" |
| 17 #include "extensions/browser/api/device_permissions_prompt.h" | 17 #include "extensions/browser/api/device_permissions_prompt.h" |
| 18 #include "extensions/browser/api/extensions_api_client.h" | 18 #include "extensions/browser/api/extensions_api_client.h" |
| 19 #include "extensions/browser/api/usb/usb_device_resource.h" | 19 #include "extensions/browser/api/usb/usb_device_resource.h" |
| 20 #include "extensions/browser/api/usb/usb_guid_map.h" | 20 #include "extensions/browser/api/usb/usb_guid_map.h" |
| 21 #include "extensions/browser/extension_system.h" | 21 #include "extensions/browser/extension_system.h" |
| 22 #include "extensions/common/api/usb.h" | 22 #include "extensions/common/api/usb.h" |
| 23 #include "extensions/common/permissions/permissions_data.h" | 23 #include "extensions/common/permissions/permissions_data.h" |
| 24 #include "extensions/common/permissions/usb_device_permission.h" | 24 #include "extensions/common/permissions/usb_device_permission.h" |
| 25 | 25 |
| 26 namespace usb = extensions::core_api::usb; | 26 namespace usb = extensions::api::usb; |
| 27 namespace BulkTransfer = usb::BulkTransfer; | 27 namespace BulkTransfer = usb::BulkTransfer; |
| 28 namespace ClaimInterface = usb::ClaimInterface; | 28 namespace ClaimInterface = usb::ClaimInterface; |
| 29 namespace CloseDevice = usb::CloseDevice; | 29 namespace CloseDevice = usb::CloseDevice; |
| 30 namespace ControlTransfer = usb::ControlTransfer; | 30 namespace ControlTransfer = usb::ControlTransfer; |
| 31 namespace FindDevices = usb::FindDevices; | 31 namespace FindDevices = usb::FindDevices; |
| 32 namespace GetDevices = usb::GetDevices; | 32 namespace GetDevices = usb::GetDevices; |
| 33 namespace GetUserSelectedDevices = usb::GetUserSelectedDevices; | 33 namespace GetUserSelectedDevices = usb::GetUserSelectedDevices; |
| 34 namespace InterruptTransfer = usb::InterruptTransfer; | 34 namespace InterruptTransfer = usb::InterruptTransfer; |
| 35 namespace IsochronousTransfer = usb::IsochronousTransfer; | 35 namespace IsochronousTransfer = usb::IsochronousTransfer; |
| 36 namespace SetConfiguration = usb::SetConfiguration; | 36 namespace SetConfiguration = usb::SetConfiguration; |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 } | 426 } |
| 427 } | 427 } |
| 428 | 428 |
| 429 UsbConnectionFunction::UsbConnectionFunction() { | 429 UsbConnectionFunction::UsbConnectionFunction() { |
| 430 } | 430 } |
| 431 | 431 |
| 432 UsbConnectionFunction::~UsbConnectionFunction() { | 432 UsbConnectionFunction::~UsbConnectionFunction() { |
| 433 } | 433 } |
| 434 | 434 |
| 435 scoped_refptr<device::UsbDeviceHandle> UsbConnectionFunction::GetDeviceHandle( | 435 scoped_refptr<device::UsbDeviceHandle> UsbConnectionFunction::GetDeviceHandle( |
| 436 const extensions::core_api::usb::ConnectionHandle& handle) { | 436 const extensions::api::usb::ConnectionHandle& handle) { |
| 437 ApiResourceManager<UsbDeviceResource>* manager = | 437 ApiResourceManager<UsbDeviceResource>* manager = |
| 438 ApiResourceManager<UsbDeviceResource>::Get(browser_context()); | 438 ApiResourceManager<UsbDeviceResource>::Get(browser_context()); |
| 439 if (!manager) { | 439 if (!manager) { |
| 440 return nullptr; | 440 return nullptr; |
| 441 } | 441 } |
| 442 | 442 |
| 443 UsbDeviceResource* resource = manager->Get(extension_id(), handle.handle); | 443 UsbDeviceResource* resource = manager->Get(extension_id(), handle.handle); |
| 444 if (!resource) { | 444 if (!resource) { |
| 445 return nullptr; | 445 return nullptr; |
| 446 } | 446 } |
| 447 | 447 |
| 448 return resource->device(); | 448 return resource->device(); |
| 449 } | 449 } |
| 450 | 450 |
| 451 void UsbConnectionFunction::ReleaseDeviceHandle( | 451 void UsbConnectionFunction::ReleaseDeviceHandle( |
| 452 const extensions::core_api::usb::ConnectionHandle& handle) { | 452 const extensions::api::usb::ConnectionHandle& handle) { |
| 453 ApiResourceManager<UsbDeviceResource>* manager = | 453 ApiResourceManager<UsbDeviceResource>* manager = |
| 454 ApiResourceManager<UsbDeviceResource>::Get(browser_context()); | 454 ApiResourceManager<UsbDeviceResource>::Get(browser_context()); |
| 455 manager->Remove(extension_id(), handle.handle); | 455 manager->Remove(extension_id(), handle.handle); |
| 456 } | 456 } |
| 457 | 457 |
| 458 UsbTransferFunction::UsbTransferFunction() { | 458 UsbTransferFunction::UsbTransferFunction() { |
| 459 } | 459 } |
| 460 | 460 |
| 461 UsbTransferFunction::~UsbTransferFunction() { | 461 UsbTransferFunction::~UsbTransferFunction() { |
| 462 } | 462 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 480 } | 480 } |
| 481 } | 481 } |
| 482 | 482 |
| 483 UsbFindDevicesFunction::UsbFindDevicesFunction() { | 483 UsbFindDevicesFunction::UsbFindDevicesFunction() { |
| 484 } | 484 } |
| 485 | 485 |
| 486 UsbFindDevicesFunction::~UsbFindDevicesFunction() { | 486 UsbFindDevicesFunction::~UsbFindDevicesFunction() { |
| 487 } | 487 } |
| 488 | 488 |
| 489 ExtensionFunction::ResponseAction UsbFindDevicesFunction::Run() { | 489 ExtensionFunction::ResponseAction UsbFindDevicesFunction::Run() { |
| 490 scoped_ptr<extensions::core_api::usb::FindDevices::Params> parameters = | 490 scoped_ptr<extensions::api::usb::FindDevices::Params> parameters = |
| 491 FindDevices::Params::Create(*args_); | 491 FindDevices::Params::Create(*args_); |
| 492 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 492 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 493 | 493 |
| 494 vendor_id_ = parameters->options.vendor_id; | 494 vendor_id_ = parameters->options.vendor_id; |
| 495 product_id_ = parameters->options.product_id; | 495 product_id_ = parameters->options.product_id; |
| 496 int interface_id = parameters->options.interface_id.get() | 496 int interface_id = parameters->options.interface_id.get() |
| 497 ? *parameters->options.interface_id.get() | 497 ? *parameters->options.interface_id.get() |
| 498 : UsbDevicePermissionData::ANY_INTERFACE; | 498 : UsbDevicePermissionData::ANY_INTERFACE; |
| 499 UsbDevicePermission::CheckParam param(vendor_id_, product_id_, interface_id); | 499 UsbDevicePermission::CheckParam param(vendor_id_, product_id_, interface_id); |
| 500 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( | 500 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 Respond(OneArgument(result_.release())); | 546 Respond(OneArgument(result_.release())); |
| 547 } | 547 } |
| 548 | 548 |
| 549 UsbGetDevicesFunction::UsbGetDevicesFunction() { | 549 UsbGetDevicesFunction::UsbGetDevicesFunction() { |
| 550 } | 550 } |
| 551 | 551 |
| 552 UsbGetDevicesFunction::~UsbGetDevicesFunction() { | 552 UsbGetDevicesFunction::~UsbGetDevicesFunction() { |
| 553 } | 553 } |
| 554 | 554 |
| 555 ExtensionFunction::ResponseAction UsbGetDevicesFunction::Run() { | 555 ExtensionFunction::ResponseAction UsbGetDevicesFunction::Run() { |
| 556 scoped_ptr<extensions::core_api::usb::GetDevices::Params> parameters = | 556 scoped_ptr<extensions::api::usb::GetDevices::Params> parameters = |
| 557 GetDevices::Params::Create(*args_); | 557 GetDevices::Params::Create(*args_); |
| 558 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 558 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 559 | 559 |
| 560 if (parameters->options.filters) { | 560 if (parameters->options.filters) { |
| 561 filters_.resize(parameters->options.filters->size()); | 561 filters_.resize(parameters->options.filters->size()); |
| 562 for (size_t i = 0; i < parameters->options.filters->size(); ++i) { | 562 for (size_t i = 0; i < parameters->options.filters->size(); ++i) { |
| 563 ConvertDeviceFilter(*parameters->options.filters->at(i).get(), | 563 ConvertDeviceFilter(*parameters->options.filters->at(i).get(), |
| 564 &filters_[i]); | 564 &filters_[i]); |
| 565 } | 565 } |
| 566 } | 566 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 597 Respond(OneArgument(result.release())); | 597 Respond(OneArgument(result.release())); |
| 598 } | 598 } |
| 599 | 599 |
| 600 UsbGetUserSelectedDevicesFunction::UsbGetUserSelectedDevicesFunction() { | 600 UsbGetUserSelectedDevicesFunction::UsbGetUserSelectedDevicesFunction() { |
| 601 } | 601 } |
| 602 | 602 |
| 603 UsbGetUserSelectedDevicesFunction::~UsbGetUserSelectedDevicesFunction() { | 603 UsbGetUserSelectedDevicesFunction::~UsbGetUserSelectedDevicesFunction() { |
| 604 } | 604 } |
| 605 | 605 |
| 606 ExtensionFunction::ResponseAction UsbGetUserSelectedDevicesFunction::Run() { | 606 ExtensionFunction::ResponseAction UsbGetUserSelectedDevicesFunction::Run() { |
| 607 scoped_ptr<extensions::core_api::usb::GetUserSelectedDevices::Params> | 607 scoped_ptr<extensions::api::usb::GetUserSelectedDevices::Params> parameters = |
| 608 parameters = GetUserSelectedDevices::Params::Create(*args_); | 608 GetUserSelectedDevices::Params::Create(*args_); |
| 609 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 609 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 610 | 610 |
| 611 if (!user_gesture()) { | 611 if (!user_gesture()) { |
| 612 return RespondNow(OneArgument(new base::ListValue())); | 612 return RespondNow(OneArgument(new base::ListValue())); |
| 613 } | 613 } |
| 614 | 614 |
| 615 bool multiple = false; | 615 bool multiple = false; |
| 616 if (parameters->options.multiple) { | 616 if (parameters->options.multiple) { |
| 617 multiple = *parameters->options.multiple; | 617 multiple = *parameters->options.multiple; |
| 618 } | 618 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 Respond(OneArgument(result.release())); | 650 Respond(OneArgument(result.release())); |
| 651 } | 651 } |
| 652 | 652 |
| 653 UsbRequestAccessFunction::UsbRequestAccessFunction() { | 653 UsbRequestAccessFunction::UsbRequestAccessFunction() { |
| 654 } | 654 } |
| 655 | 655 |
| 656 UsbRequestAccessFunction::~UsbRequestAccessFunction() { | 656 UsbRequestAccessFunction::~UsbRequestAccessFunction() { |
| 657 } | 657 } |
| 658 | 658 |
| 659 ExtensionFunction::ResponseAction UsbRequestAccessFunction::Run() { | 659 ExtensionFunction::ResponseAction UsbRequestAccessFunction::Run() { |
| 660 scoped_ptr<extensions::core_api::usb::RequestAccess::Params> parameters = | 660 scoped_ptr<extensions::api::usb::RequestAccess::Params> parameters = |
| 661 RequestAccess::Params::Create(*args_); | 661 RequestAccess::Params::Create(*args_); |
| 662 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 662 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 663 return RespondNow(OneArgument(new base::FundamentalValue(true))); | 663 return RespondNow(OneArgument(new base::FundamentalValue(true))); |
| 664 } | 664 } |
| 665 | 665 |
| 666 UsbOpenDeviceFunction::UsbOpenDeviceFunction() { | 666 UsbOpenDeviceFunction::UsbOpenDeviceFunction() { |
| 667 } | 667 } |
| 668 | 668 |
| 669 UsbOpenDeviceFunction::~UsbOpenDeviceFunction() { | 669 UsbOpenDeviceFunction::~UsbOpenDeviceFunction() { |
| 670 } | 670 } |
| 671 | 671 |
| 672 ExtensionFunction::ResponseAction UsbOpenDeviceFunction::Run() { | 672 ExtensionFunction::ResponseAction UsbOpenDeviceFunction::Run() { |
| 673 scoped_ptr<extensions::core_api::usb::OpenDevice::Params> parameters = | 673 scoped_ptr<extensions::api::usb::OpenDevice::Params> parameters = |
| 674 OpenDevice::Params::Create(*args_); | 674 OpenDevice::Params::Create(*args_); |
| 675 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 675 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 676 | 676 |
| 677 UsbService* service = device::DeviceClient::Get()->GetUsbService(); | 677 UsbService* service = device::DeviceClient::Get()->GetUsbService(); |
| 678 if (!service) { | 678 if (!service) { |
| 679 return RespondNow(Error(kErrorInitService)); | 679 return RespondNow(Error(kErrorInitService)); |
| 680 } | 680 } |
| 681 | 681 |
| 682 std::string guid; | 682 std::string guid; |
| 683 if (!UsbGuidMap::Get(browser_context()) | 683 if (!UsbGuidMap::Get(browser_context()) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 device->vendor_id(), device->product_id()))); | 717 device->vendor_id(), device->product_id()))); |
| 718 } | 718 } |
| 719 | 719 |
| 720 UsbSetConfigurationFunction::UsbSetConfigurationFunction() { | 720 UsbSetConfigurationFunction::UsbSetConfigurationFunction() { |
| 721 } | 721 } |
| 722 | 722 |
| 723 UsbSetConfigurationFunction::~UsbSetConfigurationFunction() { | 723 UsbSetConfigurationFunction::~UsbSetConfigurationFunction() { |
| 724 } | 724 } |
| 725 | 725 |
| 726 ExtensionFunction::ResponseAction UsbSetConfigurationFunction::Run() { | 726 ExtensionFunction::ResponseAction UsbSetConfigurationFunction::Run() { |
| 727 scoped_ptr<extensions::core_api::usb::SetConfiguration::Params> parameters = | 727 scoped_ptr<extensions::api::usb::SetConfiguration::Params> parameters = |
| 728 SetConfiguration::Params::Create(*args_); | 728 SetConfiguration::Params::Create(*args_); |
| 729 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 729 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 730 | 730 |
| 731 scoped_refptr<UsbDeviceHandle> device_handle = | 731 scoped_refptr<UsbDeviceHandle> device_handle = |
| 732 GetDeviceHandle(parameters->handle); | 732 GetDeviceHandle(parameters->handle); |
| 733 if (!device_handle.get()) { | 733 if (!device_handle.get()) { |
| 734 return RespondNow(Error(kErrorNoConnection)); | 734 return RespondNow(Error(kErrorNoConnection)); |
| 735 } | 735 } |
| 736 | 736 |
| 737 device_handle->SetConfiguration( | 737 device_handle->SetConfiguration( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 748 } | 748 } |
| 749 } | 749 } |
| 750 | 750 |
| 751 UsbGetConfigurationFunction::UsbGetConfigurationFunction() { | 751 UsbGetConfigurationFunction::UsbGetConfigurationFunction() { |
| 752 } | 752 } |
| 753 | 753 |
| 754 UsbGetConfigurationFunction::~UsbGetConfigurationFunction() { | 754 UsbGetConfigurationFunction::~UsbGetConfigurationFunction() { |
| 755 } | 755 } |
| 756 | 756 |
| 757 ExtensionFunction::ResponseAction UsbGetConfigurationFunction::Run() { | 757 ExtensionFunction::ResponseAction UsbGetConfigurationFunction::Run() { |
| 758 scoped_ptr<extensions::core_api::usb::GetConfiguration::Params> parameters = | 758 scoped_ptr<extensions::api::usb::GetConfiguration::Params> parameters = |
| 759 GetConfiguration::Params::Create(*args_); | 759 GetConfiguration::Params::Create(*args_); |
| 760 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 760 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 761 | 761 |
| 762 scoped_refptr<UsbDeviceHandle> device_handle = | 762 scoped_refptr<UsbDeviceHandle> device_handle = |
| 763 GetDeviceHandle(parameters->handle); | 763 GetDeviceHandle(parameters->handle); |
| 764 if (!device_handle.get()) { | 764 if (!device_handle.get()) { |
| 765 return RespondNow(Error(kErrorNoConnection)); | 765 return RespondNow(Error(kErrorNoConnection)); |
| 766 } | 766 } |
| 767 | 767 |
| 768 const UsbConfigDescriptor* config_descriptor = | 768 const UsbConfigDescriptor* config_descriptor = |
| 769 device_handle->GetDevice()->GetConfiguration(); | 769 device_handle->GetDevice()->GetConfiguration(); |
| 770 if (config_descriptor) { | 770 if (config_descriptor) { |
| 771 ConfigDescriptor config; | 771 ConfigDescriptor config; |
| 772 ConvertConfigDescriptor(*config_descriptor, &config); | 772 ConvertConfigDescriptor(*config_descriptor, &config); |
| 773 return RespondNow(OneArgument(config.ToValue().release())); | 773 return RespondNow(OneArgument(config.ToValue().release())); |
| 774 } else { | 774 } else { |
| 775 return RespondNow(Error(kErrorNotConfigured)); | 775 return RespondNow(Error(kErrorNotConfigured)); |
| 776 } | 776 } |
| 777 } | 777 } |
| 778 | 778 |
| 779 UsbListInterfacesFunction::UsbListInterfacesFunction() { | 779 UsbListInterfacesFunction::UsbListInterfacesFunction() { |
| 780 } | 780 } |
| 781 | 781 |
| 782 UsbListInterfacesFunction::~UsbListInterfacesFunction() { | 782 UsbListInterfacesFunction::~UsbListInterfacesFunction() { |
| 783 } | 783 } |
| 784 | 784 |
| 785 ExtensionFunction::ResponseAction UsbListInterfacesFunction::Run() { | 785 ExtensionFunction::ResponseAction UsbListInterfacesFunction::Run() { |
| 786 scoped_ptr<extensions::core_api::usb::ListInterfaces::Params> parameters = | 786 scoped_ptr<extensions::api::usb::ListInterfaces::Params> parameters = |
| 787 ListInterfaces::Params::Create(*args_); | 787 ListInterfaces::Params::Create(*args_); |
| 788 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 788 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 789 | 789 |
| 790 scoped_refptr<UsbDeviceHandle> device_handle = | 790 scoped_refptr<UsbDeviceHandle> device_handle = |
| 791 GetDeviceHandle(parameters->handle); | 791 GetDeviceHandle(parameters->handle); |
| 792 if (!device_handle.get()) { | 792 if (!device_handle.get()) { |
| 793 return RespondNow(Error(kErrorNoConnection)); | 793 return RespondNow(Error(kErrorNoConnection)); |
| 794 } | 794 } |
| 795 | 795 |
| 796 const UsbConfigDescriptor* config_descriptor = | 796 const UsbConfigDescriptor* config_descriptor = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 810 } | 810 } |
| 811 } | 811 } |
| 812 | 812 |
| 813 UsbCloseDeviceFunction::UsbCloseDeviceFunction() { | 813 UsbCloseDeviceFunction::UsbCloseDeviceFunction() { |
| 814 } | 814 } |
| 815 | 815 |
| 816 UsbCloseDeviceFunction::~UsbCloseDeviceFunction() { | 816 UsbCloseDeviceFunction::~UsbCloseDeviceFunction() { |
| 817 } | 817 } |
| 818 | 818 |
| 819 ExtensionFunction::ResponseAction UsbCloseDeviceFunction::Run() { | 819 ExtensionFunction::ResponseAction UsbCloseDeviceFunction::Run() { |
| 820 scoped_ptr<extensions::core_api::usb::CloseDevice::Params> parameters = | 820 scoped_ptr<extensions::api::usb::CloseDevice::Params> parameters = |
| 821 CloseDevice::Params::Create(*args_); | 821 CloseDevice::Params::Create(*args_); |
| 822 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 822 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 823 | 823 |
| 824 scoped_refptr<UsbDeviceHandle> device_handle = | 824 scoped_refptr<UsbDeviceHandle> device_handle = |
| 825 GetDeviceHandle(parameters->handle); | 825 GetDeviceHandle(parameters->handle); |
| 826 if (!device_handle.get()) { | 826 if (!device_handle.get()) { |
| 827 return RespondNow(Error(kErrorNoConnection)); | 827 return RespondNow(Error(kErrorNoConnection)); |
| 828 } | 828 } |
| 829 | 829 |
| 830 // The device handle is closed when the resource is destroyed. | 830 // The device handle is closed when the resource is destroyed. |
| 831 ReleaseDeviceHandle(parameters->handle); | 831 ReleaseDeviceHandle(parameters->handle); |
| 832 return RespondNow(NoArguments()); | 832 return RespondNow(NoArguments()); |
| 833 } | 833 } |
| 834 | 834 |
| 835 UsbClaimInterfaceFunction::UsbClaimInterfaceFunction() { | 835 UsbClaimInterfaceFunction::UsbClaimInterfaceFunction() { |
| 836 } | 836 } |
| 837 | 837 |
| 838 UsbClaimInterfaceFunction::~UsbClaimInterfaceFunction() { | 838 UsbClaimInterfaceFunction::~UsbClaimInterfaceFunction() { |
| 839 } | 839 } |
| 840 | 840 |
| 841 ExtensionFunction::ResponseAction UsbClaimInterfaceFunction::Run() { | 841 ExtensionFunction::ResponseAction UsbClaimInterfaceFunction::Run() { |
| 842 scoped_ptr<extensions::core_api::usb::ClaimInterface::Params> parameters = | 842 scoped_ptr<extensions::api::usb::ClaimInterface::Params> parameters = |
| 843 ClaimInterface::Params::Create(*args_); | 843 ClaimInterface::Params::Create(*args_); |
| 844 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 844 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 845 | 845 |
| 846 scoped_refptr<UsbDeviceHandle> device_handle = | 846 scoped_refptr<UsbDeviceHandle> device_handle = |
| 847 GetDeviceHandle(parameters->handle); | 847 GetDeviceHandle(parameters->handle); |
| 848 if (!device_handle.get()) { | 848 if (!device_handle.get()) { |
| 849 return RespondNow(Error(kErrorNoConnection)); | 849 return RespondNow(Error(kErrorNoConnection)); |
| 850 } | 850 } |
| 851 | 851 |
| 852 device_handle->ClaimInterface( | 852 device_handle->ClaimInterface( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 863 } | 863 } |
| 864 } | 864 } |
| 865 | 865 |
| 866 UsbReleaseInterfaceFunction::UsbReleaseInterfaceFunction() { | 866 UsbReleaseInterfaceFunction::UsbReleaseInterfaceFunction() { |
| 867 } | 867 } |
| 868 | 868 |
| 869 UsbReleaseInterfaceFunction::~UsbReleaseInterfaceFunction() { | 869 UsbReleaseInterfaceFunction::~UsbReleaseInterfaceFunction() { |
| 870 } | 870 } |
| 871 | 871 |
| 872 ExtensionFunction::ResponseAction UsbReleaseInterfaceFunction::Run() { | 872 ExtensionFunction::ResponseAction UsbReleaseInterfaceFunction::Run() { |
| 873 scoped_ptr<extensions::core_api::usb::ReleaseInterface::Params> parameters = | 873 scoped_ptr<extensions::api::usb::ReleaseInterface::Params> parameters = |
| 874 ReleaseInterface::Params::Create(*args_); | 874 ReleaseInterface::Params::Create(*args_); |
| 875 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 875 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 876 | 876 |
| 877 scoped_refptr<UsbDeviceHandle> device_handle = | 877 scoped_refptr<UsbDeviceHandle> device_handle = |
| 878 GetDeviceHandle(parameters->handle); | 878 GetDeviceHandle(parameters->handle); |
| 879 if (!device_handle.get()) { | 879 if (!device_handle.get()) { |
| 880 return RespondNow(Error(kErrorNoConnection)); | 880 return RespondNow(Error(kErrorNoConnection)); |
| 881 } | 881 } |
| 882 | 882 |
| 883 if (device_handle->ReleaseInterface(parameters->interface_number)) { | 883 if (device_handle->ReleaseInterface(parameters->interface_number)) { |
| 884 return RespondNow(NoArguments()); | 884 return RespondNow(NoArguments()); |
| 885 } else { | 885 } else { |
| 886 return RespondNow(Error(kErrorCannotReleaseInterface)); | 886 return RespondNow(Error(kErrorCannotReleaseInterface)); |
| 887 } | 887 } |
| 888 } | 888 } |
| 889 | 889 |
| 890 UsbSetInterfaceAlternateSettingFunction:: | 890 UsbSetInterfaceAlternateSettingFunction:: |
| 891 UsbSetInterfaceAlternateSettingFunction() { | 891 UsbSetInterfaceAlternateSettingFunction() { |
| 892 } | 892 } |
| 893 | 893 |
| 894 UsbSetInterfaceAlternateSettingFunction:: | 894 UsbSetInterfaceAlternateSettingFunction:: |
| 895 ~UsbSetInterfaceAlternateSettingFunction() { | 895 ~UsbSetInterfaceAlternateSettingFunction() { |
| 896 } | 896 } |
| 897 | 897 |
| 898 ExtensionFunction::ResponseAction | 898 ExtensionFunction::ResponseAction |
| 899 UsbSetInterfaceAlternateSettingFunction::Run() { | 899 UsbSetInterfaceAlternateSettingFunction::Run() { |
| 900 scoped_ptr<extensions::core_api::usb::SetInterfaceAlternateSetting::Params> | 900 scoped_ptr<extensions::api::usb::SetInterfaceAlternateSetting::Params> |
| 901 parameters = SetInterfaceAlternateSetting::Params::Create(*args_); | 901 parameters = SetInterfaceAlternateSetting::Params::Create(*args_); |
| 902 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 902 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 903 | 903 |
| 904 scoped_refptr<UsbDeviceHandle> device_handle = | 904 scoped_refptr<UsbDeviceHandle> device_handle = |
| 905 GetDeviceHandle(parameters->handle); | 905 GetDeviceHandle(parameters->handle); |
| 906 if (!device_handle.get()) { | 906 if (!device_handle.get()) { |
| 907 return RespondNow(Error(kErrorNoConnection)); | 907 return RespondNow(Error(kErrorNoConnection)); |
| 908 } | 908 } |
| 909 | 909 |
| 910 device_handle->SetInterfaceAlternateSetting( | 910 device_handle->SetInterfaceAlternateSetting( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 921 } | 921 } |
| 922 } | 922 } |
| 923 | 923 |
| 924 UsbControlTransferFunction::UsbControlTransferFunction() { | 924 UsbControlTransferFunction::UsbControlTransferFunction() { |
| 925 } | 925 } |
| 926 | 926 |
| 927 UsbControlTransferFunction::~UsbControlTransferFunction() { | 927 UsbControlTransferFunction::~UsbControlTransferFunction() { |
| 928 } | 928 } |
| 929 | 929 |
| 930 ExtensionFunction::ResponseAction UsbControlTransferFunction::Run() { | 930 ExtensionFunction::ResponseAction UsbControlTransferFunction::Run() { |
| 931 scoped_ptr<extensions::core_api::usb::ControlTransfer::Params> parameters = | 931 scoped_ptr<extensions::api::usb::ControlTransfer::Params> parameters = |
| 932 ControlTransfer::Params::Create(*args_); | 932 ControlTransfer::Params::Create(*args_); |
| 933 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 933 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 934 | 934 |
| 935 scoped_refptr<UsbDeviceHandle> device_handle = | 935 scoped_refptr<UsbDeviceHandle> device_handle = |
| 936 GetDeviceHandle(parameters->handle); | 936 GetDeviceHandle(parameters->handle); |
| 937 if (!device_handle.get()) { | 937 if (!device_handle.get()) { |
| 938 return RespondNow(Error(kErrorNoConnection)); | 938 return RespondNow(Error(kErrorNoConnection)); |
| 939 } | 939 } |
| 940 | 940 |
| 941 const ControlTransferInfo& transfer = parameters->transfer_info; | 941 const ControlTransferInfo& transfer = parameters->transfer_info; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 return RespondLater(); | 978 return RespondLater(); |
| 979 } | 979 } |
| 980 | 980 |
| 981 UsbBulkTransferFunction::UsbBulkTransferFunction() { | 981 UsbBulkTransferFunction::UsbBulkTransferFunction() { |
| 982 } | 982 } |
| 983 | 983 |
| 984 UsbBulkTransferFunction::~UsbBulkTransferFunction() { | 984 UsbBulkTransferFunction::~UsbBulkTransferFunction() { |
| 985 } | 985 } |
| 986 | 986 |
| 987 ExtensionFunction::ResponseAction UsbBulkTransferFunction::Run() { | 987 ExtensionFunction::ResponseAction UsbBulkTransferFunction::Run() { |
| 988 scoped_ptr<extensions::core_api::usb::BulkTransfer::Params> parameters = | 988 scoped_ptr<extensions::api::usb::BulkTransfer::Params> parameters = |
| 989 BulkTransfer::Params::Create(*args_); | 989 BulkTransfer::Params::Create(*args_); |
| 990 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 990 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 991 | 991 |
| 992 scoped_refptr<UsbDeviceHandle> device_handle = | 992 scoped_refptr<UsbDeviceHandle> device_handle = |
| 993 GetDeviceHandle(parameters->handle); | 993 GetDeviceHandle(parameters->handle); |
| 994 if (!device_handle.get()) { | 994 if (!device_handle.get()) { |
| 995 return RespondNow(Error(kErrorNoConnection)); | 995 return RespondNow(Error(kErrorNoConnection)); |
| 996 } | 996 } |
| 997 | 997 |
| 998 const GenericTransferInfo& transfer = parameters->transfer_info; | 998 const GenericTransferInfo& transfer = parameters->transfer_info; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1024 return RespondLater(); | 1024 return RespondLater(); |
| 1025 } | 1025 } |
| 1026 | 1026 |
| 1027 UsbInterruptTransferFunction::UsbInterruptTransferFunction() { | 1027 UsbInterruptTransferFunction::UsbInterruptTransferFunction() { |
| 1028 } | 1028 } |
| 1029 | 1029 |
| 1030 UsbInterruptTransferFunction::~UsbInterruptTransferFunction() { | 1030 UsbInterruptTransferFunction::~UsbInterruptTransferFunction() { |
| 1031 } | 1031 } |
| 1032 | 1032 |
| 1033 ExtensionFunction::ResponseAction UsbInterruptTransferFunction::Run() { | 1033 ExtensionFunction::ResponseAction UsbInterruptTransferFunction::Run() { |
| 1034 scoped_ptr<extensions::core_api::usb::InterruptTransfer::Params> parameters = | 1034 scoped_ptr<extensions::api::usb::InterruptTransfer::Params> parameters = |
| 1035 InterruptTransfer::Params::Create(*args_); | 1035 InterruptTransfer::Params::Create(*args_); |
| 1036 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 1036 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 1037 | 1037 |
| 1038 scoped_refptr<UsbDeviceHandle> device_handle = | 1038 scoped_refptr<UsbDeviceHandle> device_handle = |
| 1039 GetDeviceHandle(parameters->handle); | 1039 GetDeviceHandle(parameters->handle); |
| 1040 if (!device_handle.get()) { | 1040 if (!device_handle.get()) { |
| 1041 return RespondNow(Error(kErrorNoConnection)); | 1041 return RespondNow(Error(kErrorNoConnection)); |
| 1042 } | 1042 } |
| 1043 | 1043 |
| 1044 const GenericTransferInfo& transfer = parameters->transfer_info; | 1044 const GenericTransferInfo& transfer = parameters->transfer_info; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1070 return RespondLater(); | 1070 return RespondLater(); |
| 1071 } | 1071 } |
| 1072 | 1072 |
| 1073 UsbIsochronousTransferFunction::UsbIsochronousTransferFunction() { | 1073 UsbIsochronousTransferFunction::UsbIsochronousTransferFunction() { |
| 1074 } | 1074 } |
| 1075 | 1075 |
| 1076 UsbIsochronousTransferFunction::~UsbIsochronousTransferFunction() { | 1076 UsbIsochronousTransferFunction::~UsbIsochronousTransferFunction() { |
| 1077 } | 1077 } |
| 1078 | 1078 |
| 1079 ExtensionFunction::ResponseAction UsbIsochronousTransferFunction::Run() { | 1079 ExtensionFunction::ResponseAction UsbIsochronousTransferFunction::Run() { |
| 1080 scoped_ptr<extensions::core_api::usb::IsochronousTransfer::Params> | 1080 scoped_ptr<extensions::api::usb::IsochronousTransfer::Params> parameters = |
| 1081 parameters = IsochronousTransfer::Params::Create(*args_); | 1081 IsochronousTransfer::Params::Create(*args_); |
| 1082 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 1082 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 1083 | 1083 |
| 1084 scoped_refptr<UsbDeviceHandle> device_handle = | 1084 scoped_refptr<UsbDeviceHandle> device_handle = |
| 1085 GetDeviceHandle(parameters->handle); | 1085 GetDeviceHandle(parameters->handle); |
| 1086 if (!device_handle.get()) { | 1086 if (!device_handle.get()) { |
| 1087 return RespondNow(Error(kErrorNoConnection)); | 1087 return RespondNow(Error(kErrorNoConnection)); |
| 1088 } | 1088 } |
| 1089 | 1089 |
| 1090 const IsochronousTransferInfo& transfer = parameters->transfer_info; | 1090 const IsochronousTransferInfo& transfer = parameters->transfer_info; |
| 1091 const GenericTransferInfo& generic_transfer = transfer.transfer_info; | 1091 const GenericTransferInfo& generic_transfer = transfer.transfer_info; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 ReleaseDeviceHandle(parameters_->handle); | 1167 ReleaseDeviceHandle(parameters_->handle); |
| 1168 | 1168 |
| 1169 scoped_ptr<base::ListValue> error_args(new base::ListValue()); | 1169 scoped_ptr<base::ListValue> error_args(new base::ListValue()); |
| 1170 error_args->AppendBoolean(false); | 1170 error_args->AppendBoolean(false); |
| 1171 // Returning arguments with an error is wrong but we're stuck with it. | 1171 // Returning arguments with an error is wrong but we're stuck with it. |
| 1172 Respond(ErrorWithArguments(error_args.Pass(), kErrorResetDevice)); | 1172 Respond(ErrorWithArguments(error_args.Pass(), kErrorResetDevice)); |
| 1173 } | 1173 } |
| 1174 } | 1174 } |
| 1175 | 1175 |
| 1176 } // namespace extensions | 1176 } // namespace extensions |
| OLD | NEW |