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 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_UTILS_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_UTILS_H_ |
6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_UTILS_H_ | 6 #define CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_UTILS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 | 11 |
12 class GURL; | 12 class GURL; |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 class BrowserContext; | 15 class BrowserContext; |
16 class WebContents; | 16 class WebContents; |
17 } | 17 } |
18 | 18 |
19 namespace offline_pages { | 19 namespace offline_pages { |
20 struct OfflinePageItem; | 20 struct OfflinePageItem; |
21 | 21 |
22 class OfflinePageUtils { | 22 class OfflinePageUtils { |
23 public: | 23 public: |
24 // Returns true if |url| might point to an offline page. | |
25 static bool MightBeOfflineURL(const GURL& url); | |
26 | |
27 // Returns via callback an offline page saved for |online_url|, if any. The | 24 // Returns via callback an offline page saved for |online_url|, if any. The |
28 // page is chosen based on creation date; a more recently created offline | 25 // page is chosen based on creation date; a more recently created offline |
29 // page will be preferred over an older one. The offline page captured from | 26 // page will be preferred over an older one. The offline page captured from |
30 // last visit in the tab will not be considered if its tab id does not match | 27 // last visit in the tab will not be considered if its tab id does not match |
31 // the provided |tab_id|. | 28 // the provided |tab_id|. |
32 static void SelectPageForOnlineURL( | 29 static void SelectPageForOnlineURL( |
33 content::BrowserContext* browser_context, | 30 content::BrowserContext* browser_context, |
34 const GURL& online_url, | 31 const GURL& online_url, |
35 int tab_id, | 32 int tab_id, |
36 const base::Callback<void(const OfflinePageItem*)>& callback); | 33 const base::Callback<void(const OfflinePageItem*)>& callback); |
37 | 34 |
38 // Gets an online URL of an offline page with |offline_url| if one exists. | |
39 // Deprecated. Use |GetOnlineURLForOfflineURL|. | |
40 static GURL MaybeGetOnlineURLForOfflineURL( | |
41 content::BrowserContext* browser_context, | |
42 const GURL& offline_url); | |
43 | |
44 static void GetOnlineURLForOfflineURL( | |
45 content::BrowserContext* browser_context, | |
46 const GURL& offline_url, | |
47 const base::Callback<void(const GURL&)>& callback); | |
48 | |
49 // Checks whether |offline_url| points to an offline page. | |
50 // Deprecated. Use something else. | |
51 static bool IsOfflinePage(content::BrowserContext* browser_context, | |
52 const GURL& offline_url); | |
53 | |
54 // Marks that the offline page related to the |offline_url| has been accessed. | |
55 static void MarkPageAccessed(content::BrowserContext* browser_context, | |
56 const GURL& offline_url); | |
57 | |
58 // Gets the offline page corresponding to the given web contents. The | 35 // Gets the offline page corresponding to the given web contents. The |
59 // returned pointer is owned by the web_contents and may be deleted by user | 36 // returned pointer is owned by the web_contents and may be deleted by user |
60 // navigation, so it is unsafe to store a copy of the returned pointer. | 37 // navigation, so it is unsafe to store a copy of the returned pointer. |
61 static const OfflinePageItem* GetOfflinePageFromWebContents( | 38 static const OfflinePageItem* GetOfflinePageFromWebContents( |
62 content::WebContents* web_contents); | 39 content::WebContents* web_contents); |
63 | 40 |
64 // Gets an Android Tab ID from a tab containing |web_contents|. Returns false, | 41 // Gets an Android Tab ID from a tab containing |web_contents|. Returns false, |
65 // when tab is not available. Returns true otherwise and sets |tab_id| to the | 42 // when tab is not available. Returns true otherwise and sets |tab_id| to the |
66 // ID of the tab. | 43 // ID of the tab. |
67 static bool GetTabId(content::WebContents* web_contents, int* tab_id); | 44 static bool GetTabId(content::WebContents* web_contents, int* tab_id); |
68 }; | 45 }; |
69 | 46 |
70 } // namespace offline_pages | 47 } // namespace offline_pages |
71 | 48 |
72 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_UTILS_H_ | 49 #endif // CHROME_BROWSER_ANDROID_OFFLINE_PAGES_OFFLINE_PAGE_UTILS_H_ |
OLD | NEW |