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