download_callback_proxy.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2019 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 WEBLAYER_BROWSER_DOWNLOAD_CALLBACK_PROXY_H_
  5. #define WEBLAYER_BROWSER_DOWNLOAD_CALLBACK_PROXY_H_
  6. #include <jni.h>
  7. #include "base/android/scoped_java_ref.h"
  8. #include "base/callback.h"
  9. #include "base/memory/raw_ptr.h"
  10. #include "weblayer/public/download_delegate.h"
  11. namespace weblayer {
  12. class Profile;
  13. // Forwards DownloadDelegate calls to the java-side DownloadCallbackProxy.
  14. class DownloadCallbackProxy : public DownloadDelegate {
  15. public:
  16. DownloadCallbackProxy(JNIEnv* env, jobject obj, Profile* profile);
  17. DownloadCallbackProxy(const DownloadCallbackProxy&) = delete;
  18. DownloadCallbackProxy& operator=(const DownloadCallbackProxy&) = delete;
  19. ~DownloadCallbackProxy() override;
  20. // DownloadDelegate:
  21. bool InterceptDownload(const GURL& url,
  22. const std::string& user_agent,
  23. const std::string& content_disposition,
  24. const std::string& mime_type,
  25. int64_t content_length) override;
  26. void AllowDownload(Tab* tab,
  27. const GURL& url,
  28. const std::string& request_method,
  29. absl::optional<url::Origin> request_initiator,
  30. AllowDownloadCallback callback) override;
  31. void DownloadStarted(Download* download) override;
  32. void DownloadProgressChanged(Download* download) override;
  33. void DownloadCompleted(Download* download) override;
  34. void DownloadFailed(Download* download) override;
  35. private:
  36. raw_ptr<Profile> profile_;
  37. base::android::ScopedJavaGlobalRef<jobject> java_delegate_;
  38. };
  39. } // namespace weblayer
  40. #endif // WEBLAYER_BROWSER_DOWNLOAD_CALLBACK_PROXY_H_