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_bridge.h" | 5 #include "chrome/browser/android/offline_pages/offline_page_bridge.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/android/jni_array.h" | 9 #include "base/android/jni_array.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
11 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" | 11 #include "chrome/browser/android/offline_pages/offline_page_mhtml_archiver.h" |
12 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 12 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" |
| 13 #include "chrome/browser/android/offline_pages/offline_page_utils.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/profiles/profile_android.h" | 15 #include "chrome/browser/profiles/profile_android.h" |
15 #include "components/offline_pages/offline_page_feature.h" | 16 #include "components/offline_pages/offline_page_feature.h" |
16 #include "components/offline_pages/offline_page_item.h" | 17 #include "components/offline_pages/offline_page_item.h" |
17 #include "components/offline_pages/offline_page_model.h" | 18 #include "components/offline_pages/offline_page_model.h" |
18 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
20 #include "jni/OfflinePageBridge_jni.h" | 21 #include "jni/OfflinePageBridge_jni.h" |
21 #include "net/base/filename_util.h" | 22 #include "net/base/filename_util.h" |
22 | 23 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 const JavaParamRef<jclass>& clazz, | 76 const JavaParamRef<jclass>& clazz, |
76 const JavaParamRef<jstring>& j_url) { | 77 const JavaParamRef<jstring>& j_url) { |
77 GURL url(ConvertJavaStringToUTF8(env, j_url)); | 78 GURL url(ConvertJavaStringToUTF8(env, j_url)); |
78 return url.is_valid() && OfflinePageModel::CanSavePage(url); | 79 return url.is_valid() && OfflinePageModel::CanSavePage(url); |
79 } | 80 } |
80 | 81 |
81 OfflinePageBridge::OfflinePageBridge(JNIEnv* env, | 82 OfflinePageBridge::OfflinePageBridge(JNIEnv* env, |
82 jobject obj, | 83 jobject obj, |
83 content::BrowserContext* browser_context) | 84 content::BrowserContext* browser_context) |
84 : weak_java_ref_(env, obj), | 85 : weak_java_ref_(env, obj), |
| 86 browser_context_(browser_context), |
85 offline_page_model_( | 87 offline_page_model_( |
86 OfflinePageModelFactory::GetForBrowserContext(browser_context)) { | 88 OfflinePageModelFactory::GetForBrowserContext(browser_context)) { |
87 NotifyIfDoneLoading(); | 89 NotifyIfDoneLoading(); |
88 offline_page_model_->AddObserver(this); | 90 offline_page_model_->AddObserver(this); |
89 } | 91 } |
90 | 92 |
91 void OfflinePageBridge::Destroy(JNIEnv*, const JavaParamRef<jobject>&) { | 93 void OfflinePageBridge::Destroy(JNIEnv*, const JavaParamRef<jobject>&) { |
92 offline_page_model_->RemoveObserver(this); | 94 offline_page_model_->RemoveObserver(this); |
93 delete this; | 95 delete this; |
94 } | 96 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 bookmark_ids, | 220 bookmark_ids, |
219 base::Bind(&DeletePageCallback, j_callback_ref)); | 221 base::Bind(&DeletePageCallback, j_callback_ref)); |
220 } | 222 } |
221 | 223 |
222 void OfflinePageBridge::CheckMetadataConsistency( | 224 void OfflinePageBridge::CheckMetadataConsistency( |
223 JNIEnv* env, | 225 JNIEnv* env, |
224 const JavaParamRef<jobject>& obj) { | 226 const JavaParamRef<jobject>& obj) { |
225 offline_page_model_->CheckForExternalFileDeletion(); | 227 offline_page_model_->CheckForExternalFileDeletion(); |
226 } | 228 } |
227 | 229 |
| 230 ScopedJavaLocalRef<jstring> OfflinePageBridge::GetOfflineUrlForOnlineUrl( |
| 231 JNIEnv* env, |
| 232 const JavaParamRef<jobject>& obj, |
| 233 const JavaParamRef<jstring>& j_online_url) { |
| 234 GURL online_url(ConvertJavaStringToUTF8(env, j_online_url)); |
| 235 GURL offline_url = |
| 236 OfflinePageUtils::GetOfflineURLForOnlineURL(browser_context_, online_url); |
| 237 return ConvertUTF8ToJavaString(env, offline_url.spec()); |
| 238 } |
| 239 |
| 240 jboolean OfflinePageBridge::IsOfflinePageUrl( |
| 241 JNIEnv* env, |
| 242 const JavaParamRef<jobject>& obj, |
| 243 const JavaParamRef<jstring>& j_offline_url) { |
| 244 GURL offline_url(ConvertJavaStringToUTF8(env, j_offline_url)); |
| 245 return OfflinePageUtils::IsOfflinePage(browser_context_, offline_url); |
| 246 } |
| 247 |
228 void OfflinePageBridge::NotifyIfDoneLoading() const { | 248 void OfflinePageBridge::NotifyIfDoneLoading() const { |
229 if (!offline_page_model_->is_loaded()) | 249 if (!offline_page_model_->is_loaded()) |
230 return; | 250 return; |
231 JNIEnv* env = base::android::AttachCurrentThread(); | 251 JNIEnv* env = base::android::AttachCurrentThread(); |
232 ScopedJavaLocalRef<jobject> obj = weak_java_ref_.get(env); | 252 ScopedJavaLocalRef<jobject> obj = weak_java_ref_.get(env); |
233 if (obj.is_null()) | 253 if (obj.is_null()) |
234 return; | 254 return; |
235 Java_OfflinePageBridge_offlinePageModelLoaded(env, obj.obj()); | 255 Java_OfflinePageBridge_offlinePageModelLoaded(env, obj.obj()); |
236 } | 256 } |
237 | 257 |
(...skipping 16 matching lines...) Expand all Loading... |
254 return reinterpret_cast<jlong>(new OfflinePageBridge( | 274 return reinterpret_cast<jlong>(new OfflinePageBridge( |
255 env, obj, ProfileAndroid::FromProfileAndroid(j_profile))); | 275 env, obj, ProfileAndroid::FromProfileAndroid(j_profile))); |
256 } | 276 } |
257 | 277 |
258 bool RegisterOfflinePageBridge(JNIEnv* env) { | 278 bool RegisterOfflinePageBridge(JNIEnv* env) { |
259 return RegisterNativesImpl(env); | 279 return RegisterNativesImpl(env); |
260 } | 280 } |
261 | 281 |
262 } // namespace android | 282 } // namespace android |
263 } // namespace offline_pages | 283 } // namespace offline_pages |
OLD | NEW |