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 package org.chromium.chrome.browser.offlinepages; | 5 package org.chromium.chrome.browser.offlinepages; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.net.ConnectivityManager; | 8 import android.net.ConnectivityManager; |
9 import android.net.NetworkInfo; | 9 import android.net.NetworkInfo; |
10 import android.os.Environment; | 10 import android.os.Environment; |
11 | 11 |
12 import org.chromium.base.ApplicationStatus; | |
13 import org.chromium.base.PathUtils; | |
12 import org.chromium.base.metrics.RecordUserAction; | 14 import org.chromium.base.metrics.RecordUserAction; |
13 import org.chromium.chrome.R; | 15 import org.chromium.chrome.R; |
14 import org.chromium.chrome.browser.ChromeActivity; | 16 import org.chromium.chrome.browser.ChromeActivity; |
15 import org.chromium.chrome.browser.ChromeBrowserProviderClient; | 17 import org.chromium.chrome.browser.ChromeBrowserProviderClient; |
16 import org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarkUtils; | 18 import org.chromium.chrome.browser.enhancedbookmarks.EnhancedBookmarkUtils; |
17 import org.chromium.chrome.browser.snackbar.Snackbar; | 19 import org.chromium.chrome.browser.snackbar.Snackbar; |
18 import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController; | 20 import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController; |
19 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 21 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
20 import org.chromium.chrome.browser.tab.Tab; | 22 import org.chromium.chrome.browser.tab.Tab; |
21 import org.chromium.components.bookmarks.BookmarkId; | 23 import org.chromium.components.bookmarks.BookmarkId; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 public void onShown(Tab visibleTab) { | 109 public void onShown(Tab visibleTab) { |
108 showOfflineSnackbar(activity, visibleTab.getId(), finalSave, bookmarkId); | 110 showOfflineSnackbar(activity, visibleTab.getId(), finalSave, bookmarkId); |
109 } | 111 } |
110 }); | 112 }); |
111 } else { | 113 } else { |
112 showOfflineSnackbar(activity, tab.getId(), save, bookmarkId); | 114 showOfflineSnackbar(activity, tab.getId(), save, bookmarkId); |
113 } | 115 } |
114 } | 116 } |
115 | 117 |
116 /** | 118 /** |
119 * Check whether the URL qualifies as offline URL for the purpose of storage permission check. | |
120 * @param url A URL to check. | |
121 * @return <code>true</code> if the URL qualifies as an offline page URL, <c ode>false</code> | |
122 * otherwise. | |
123 */ | |
124 public static boolean isOfflineUrlForStoragePermissionCheck(String url) { | |
125 Context context = ApplicationStatus.getApplicationContext(); | |
126 return url != null && context != null | |
127 && url.startsWith("file://" + PathUtils.getDataDirectory(context )) | |
newt (away)
2016/01/04 19:45:05
This seems prone to silent breakage if the locatio
jianli
2016/01/04 21:42:00
The name isOfflineUrlForStoragePermissionCheck sou
fgorski
2016/01/04 23:11:35
This sits inside of the profile folder and I am no
| |
128 && url.contains("/Offline%20Pages/archives/") && url.endsWith(". mhtml"); | |
129 } | |
130 | |
131 /** | |
117 * Shows the snackbar for the current tab to provide offline specific inform ation. | 132 * Shows the snackbar for the current tab to provide offline specific inform ation. |
118 * @param activity The activity owning the tab. | 133 * @param activity The activity owning the tab. |
119 * @param tabId The ID of current tab. | 134 * @param tabId The ID of current tab. |
120 * @param save Whether to offer saving the page. | 135 * @param save Whether to offer saving the page. |
121 * @param bookmarkId Bookmark ID related to the opened page. | 136 * @param bookmarkId Bookmark ID related to the opened page. |
122 */ | 137 */ |
123 private static void showOfflineSnackbar( | 138 private static void showOfflineSnackbar( |
124 final ChromeActivity activity, final int tabId, boolean save, final long bookmarkId) { | 139 final ChromeActivity activity, final int tabId, boolean save, final long bookmarkId) { |
125 Context context = activity.getBaseContext(); | 140 Context context = activity.getBaseContext(); |
126 | 141 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 @Override | 215 @Override |
201 public void onDismissForEachType(boolean isTimeout) {} | 216 public void onDismissForEachType(boolean isTimeout) {} |
202 }; | 217 }; |
203 Snackbar snackbar = Snackbar.make(context.getString(snackbarTextId), sna ckbarController); | 218 Snackbar snackbar = Snackbar.make(context.getString(snackbarTextId), sna ckbarController); |
204 if (actionTextId != -1) { | 219 if (actionTextId != -1) { |
205 snackbar.setAction(context.getString(actionTextId), buttonType); | 220 snackbar.setAction(context.getString(actionTextId), buttonType); |
206 } | 221 } |
207 activity.getSnackbarManager().showSnackbar(snackbar); | 222 activity.getSnackbarManager().showSnackbar(snackbar); |
208 } | 223 } |
209 } | 224 } |
OLD | NEW |