data_exchange_delegate.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_EXO_DATA_EXCHANGE_DELEGATE_H_
  5. #define COMPONENTS_EXO_DATA_EXCHANGE_DELEGATE_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/callback.h"
  9. #include "base/memory/scoped_refptr.h"
  10. namespace aura {
  11. class Window;
  12. }
  13. namespace base {
  14. class Pickle;
  15. class RefCountedMemory;
  16. } // namespace base
  17. namespace ui {
  18. class DataTransferEndpoint;
  19. struct FileInfo;
  20. enum class EndpointType;
  21. } // namespace ui
  22. namespace exo {
  23. // Interface for data exchange operations that are implemented in chrome such as
  24. // file drag and drop path translations and file sharing for VMs.
  25. class DataExchangeDelegate {
  26. public:
  27. virtual ~DataExchangeDelegate() {}
  28. // Returns the endpoint type of `window`.
  29. virtual ui::EndpointType GetDataTransferEndpointType(
  30. aura::Window* window) const = 0;
  31. // Read filenames from text/uri-list |data| which was provided by |source|
  32. // endpoint. Translates paths from source to host format.
  33. virtual std::vector<ui::FileInfo> GetFilenames(
  34. ui::EndpointType source,
  35. const std::vector<uint8_t>& data) const = 0;
  36. // Returns the mime type which is used by |target| endpoint for a list of
  37. // file path URIs.
  38. virtual std::string GetMimeTypeForUriList(ui::EndpointType target) const = 0;
  39. // Sends the given list of |files| to |target| endpoint. Translates paths from
  40. // host format to the target and performs any required file sharing for VMs.
  41. using SendDataCallback =
  42. base::OnceCallback<void(scoped_refptr<base::RefCountedMemory>)>;
  43. virtual void SendFileInfo(ui::EndpointType target,
  44. const std::vector<ui::FileInfo>& files,
  45. SendDataCallback callback) const = 0;
  46. // Takes in |pickle| constructed by the web contents view and returns true if
  47. // it contains any valid filesystem URLs.
  48. virtual bool HasUrlsInPickle(const base::Pickle& pickle) const = 0;
  49. // Takes in |pickle| constructed by the web contents view containing
  50. // filesystem URLs. Provides translations for the specified |target| endpoint
  51. // and performs any required file sharing for VMs.
  52. virtual void SendPickle(ui::EndpointType target,
  53. const base::Pickle& pickle,
  54. SendDataCallback callback) = 0;
  55. // Reads pickle for FilesApp fs/sources with newline-separated filesystem
  56. // URLs. Validates that |source| is FilesApp.
  57. virtual std::vector<ui::FileInfo> ParseFileSystemSources(
  58. const ui::DataTransferEndpoint* source,
  59. const base::Pickle& pickle) const = 0;
  60. };
  61. } // namespace exo
  62. #endif // COMPONENTS_EXO_DATA_EXCHANGE_DELEGATE_H_