OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 | |
5 #include "chrome/browser/android/offline_pages/downloads/resource_throttle.h" | |
asanka
2016/12/07 16:37:40
You could use the SaveLinkAsReferrerPolicyOrigin t
| |
6 | |
7 #include "base/logging.h" | |
8 #include "chrome/browser/android/offline_pages/offline_page_utils.h" | |
9 #include "content/public/browser/browser_thread.h" | |
10 #include "content/public/browser/resource_controller.h" | |
11 #include "content/public/browser/resource_request_info.h" | |
12 #include "content/public/browser/web_contents.h" | |
13 #include "net/base/mime_util.h" | |
14 | |
15 namespace { | |
asanka
2016/12/07 16:37:40
Nit: whitespace. Perhaps run this through 'git cl
| |
16 // Mime type of download resource that should trigger handoff to OfflinePages | |
17 // backend for full page load and snapshot. | |
18 const char kHTMLMimeType[] = "text/html"; | |
asanka
2016/12/07 16:37:40
SavePackage considers both text/html and applicati
| |
19 | |
20 void WillStartOfflineRequestOnUIThread( | |
21 const GURL& url, | |
22 const content::ResourceRequestInfo::WebContentsGetter& contents_getter) { | |
23 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
24 content::WebContents* web_contents = contents_getter.Run(); | |
25 if (!web_contents) | |
26 return; | |
27 offline_pages::OfflinePageUtils::StartOfflinePageDownload( | |
28 web_contents->GetBrowserContext(), url); | |
29 } | |
30 } // namespace | |
31 | |
32 namespace offline_pages { | |
33 namespace downloads { | |
34 | |
35 ResourceThrottle::ResourceThrottle(const net::URLRequest* request) | |
36 : request_(request) { | |
37 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
38 } | |
39 | |
40 ResourceThrottle::~ResourceThrottle() { | |
41 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
42 } | |
43 | |
44 void ResourceThrottle::WillProcessResponse(bool* defer) { | |
45 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
46 std::string mime_type; | |
47 request_->GetMimeType(&mime_type); | |
48 if (net::MatchesMimeType(kHTMLMimeType, mime_type)) { | |
49 controller()->Cancel(); | |
asanka
2016/12/07 16:37:40
Let's defer the Cancel() call until after you're d
| |
50 | |
51 const content::ResourceRequestInfo* info = | |
52 content::ResourceRequestInfo::ForRequest(request_); | |
53 if (!info) | |
54 return; | |
55 content::BrowserThread::PostTask( | |
56 content::BrowserThread::UI, FROM_HERE, | |
57 base::Bind(&WillStartOfflineRequestOnUIThread, | |
58 request_->url(), | |
59 info->GetWebContentsGetterForRequest())); | |
60 } | |
61 } | |
62 | |
63 const char* ResourceThrottle::GetNameForLogging() const { | |
64 return "offline_pages::downloads::ResourceThrottle"; | |
65 } | |
66 | |
67 } // namespace downloads | |
68 } // namespace offline_pages | |
69 | |
OLD | NEW |