OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/android/offline_pages/offline_page_utils.h" | 5 #include "chrome/browser/android/offline_pages/offline_page_utils.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/guid.h" | 8 #include "base/guid.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "chrome/browser/net/net_error_tab_helper.h" | 21 #include "chrome/browser/net/net_error_tab_helper.h" |
22 #include "components/offline_pages/core/background/request_coordinator.h" | 22 #include "components/offline_pages/core/background/request_coordinator.h" |
23 #include "components/offline_pages/core/background/save_page_request.h" | 23 #include "components/offline_pages/core/background/save_page_request.h" |
24 #include "components/offline_pages/core/client_namespace_constants.h" | 24 #include "components/offline_pages/core/client_namespace_constants.h" |
25 #include "components/offline_pages/core/client_policy_controller.h" | 25 #include "components/offline_pages/core/client_policy_controller.h" |
26 #include "components/offline_pages/core/offline_page_feature.h" | 26 #include "components/offline_pages/core/offline_page_feature.h" |
27 #include "components/offline_pages/core/offline_page_item.h" | 27 #include "components/offline_pages/core/offline_page_item.h" |
28 #include "components/offline_pages/core/offline_page_model.h" | 28 #include "components/offline_pages/core/offline_page_model.h" |
29 #include "components/offline_pages/core/request_header/offline_page_header.h" | 29 #include "components/offline_pages/core/request_header/offline_page_header.h" |
30 #include "content/public/browser/browser_context.h" | 30 #include "content/public/browser/browser_context.h" |
31 #include "content/public/browser/navigation_entry.h" | |
31 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
32 #include "url/gurl.h" | |
33 | 33 |
34 namespace offline_pages { | 34 namespace offline_pages { |
35 namespace { | 35 namespace { |
36 | 36 |
37 void OnGetPagesByURLDone( | 37 void OnGetPagesByURLDone( |
38 const GURL& url, | 38 const GURL& url, |
39 int tab_id, | 39 int tab_id, |
40 const std::vector<std::string>& namespaces_to_show_in_original_tab, | 40 const std::vector<std::string>& namespaces_to_show_in_original_tab, |
41 const base::Callback<void(const OfflinePageItem*)>& callback, | 41 const base::Callback<void(const OfflinePageItem*)>& callback, |
42 const MultipleOfflinePageItemResult& pages) { | 42 const MultipleOfflinePageItemResult& pages) { |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 content::BrowserContext* context, | 236 content::BrowserContext* context, |
237 const GURL& url) { | 237 const GURL& url) { |
238 RequestCoordinator* request_coordinator = | 238 RequestCoordinator* request_coordinator = |
239 RequestCoordinatorFactory::GetForBrowserContext(context); | 239 RequestCoordinatorFactory::GetForBrowserContext(context); |
240 | 240 |
241 // TODO(dimich): Enable in Incognito when Android Downloads implement | 241 // TODO(dimich): Enable in Incognito when Android Downloads implement |
242 // Incognito story. | 242 // Incognito story. |
243 if (!request_coordinator) | 243 if (!request_coordinator) |
244 return; | 244 return; |
245 | 245 |
246 ClientId client_id(kDownloadNamespace, base::GenerateGUID()); | 246 RequestCoordinator::SavePageLaterParams params; |
247 request_coordinator->SavePageLater( | 247 params.url = url; |
248 url, client_id, true, | 248 params.client_id = ClientId(kDownloadNamespace, base::GenerateGUID()); |
249 RequestCoordinator::RequestAvailability::ENABLED_FOR_OFFLINER); | 249 params.user_requested = true; |
fgorski
2017/02/27 17:34:35
are you missing availability here?
jianli
2017/02/27 23:20:06
ditto
| |
250 request_coordinator->SavePageLater(params); | |
250 | 251 |
251 android::OfflinePageNotificationBridge notification_bridge; | 252 android::OfflinePageNotificationBridge notification_bridge; |
252 notification_bridge.ShowDownloadingToast(); | 253 notification_bridge.ShowDownloadingToast(); |
253 } | 254 } |
254 | 255 |
256 // static | |
257 GURL OfflinePageUtils::GetOriginalURLFromWebContents( | |
258 content::WebContents* web_contents) { | |
259 content::NavigationEntry* entry = | |
260 web_contents->GetController().GetLastCommittedEntry(); | |
261 if (!entry || entry->GetRedirectChain().size() <= 1) | |
262 return GURL(); | |
263 return entry->GetRedirectChain().front(); | |
264 } | |
265 | |
255 } // namespace offline_pages | 266 } // namespace offline_pages |
OLD | NEW |