aw_download_manager_delegate.cc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (c) 2012 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. #include "android_webview/browser/aw_download_manager_delegate.h"
  5. #include "android_webview/browser/aw_content_browser_client.h"
  6. #include "android_webview/browser/aw_contents_client_bridge.h"
  7. #include "content/public/browser/browser_task_traits.h"
  8. #include "content/public/browser/browser_thread.h"
  9. #include "content/public/browser/web_contents.h"
  10. namespace android_webview {
  11. AwDownloadManagerDelegate::AwDownloadManagerDelegate() = default;
  12. AwDownloadManagerDelegate::~AwDownloadManagerDelegate() = default;
  13. bool AwDownloadManagerDelegate::InterceptDownloadIfApplicable(
  14. const GURL& url,
  15. const std::string& user_agent,
  16. const std::string& content_disposition,
  17. const std::string& mime_type,
  18. const std::string& request_origin,
  19. int64_t content_length,
  20. bool is_transient,
  21. content::WebContents* web_contents) {
  22. DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
  23. if (!web_contents)
  24. return true;
  25. AwContentsClientBridge* client =
  26. AwContentsClientBridge::FromWebContents(web_contents);
  27. if (!client)
  28. return true;
  29. std::string aw_user_agent =
  30. web_contents->GetUserAgentOverride().ua_string_override;
  31. if (aw_user_agent.empty()) {
  32. // use default user agent if nothing is provided
  33. aw_user_agent = user_agent.empty() ? GetUserAgent() : user_agent;
  34. }
  35. client->NewDownload(url, aw_user_agent, content_disposition, mime_type,
  36. content_length);
  37. return true;
  38. }
  39. } // namespace android_webview