| 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 "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 void ToJavaOfflinePageList(JNIEnv* env, | 55 void ToJavaOfflinePageList(JNIEnv* env, |
| 56 jobject j_result_obj, | 56 jobject j_result_obj, |
| 57 const std::vector<OfflinePageItem>& offline_pages) { | 57 const std::vector<OfflinePageItem>& offline_pages) { |
| 58 for (const OfflinePageItem& offline_page : offline_pages) { | 58 for (const OfflinePageItem& offline_page : offline_pages) { |
| 59 Java_OfflinePageBridge_createOfflinePageAndAddToList( | 59 Java_OfflinePageBridge_createOfflinePageAndAddToList( |
| 60 env, j_result_obj, | 60 env, j_result_obj, |
| 61 ConvertUTF8ToJavaString(env, offline_page.url.spec()).obj(), | 61 ConvertUTF8ToJavaString(env, offline_page.url.spec()).obj(), |
| 62 offline_page.bookmark_id, | 62 offline_page.bookmark_id, |
| 63 ConvertUTF8ToJavaString(env, offline_page.GetOfflineURL().spec()).obj(), | 63 ConvertUTF8ToJavaString(env, offline_page.GetOfflineURL().spec()).obj(), |
| 64 offline_page.file_size); | 64 offline_page.file_size, |
| 65 offline_page.access_count); |
| 65 } | 66 } |
| 66 } | 67 } |
| 67 | 68 |
| 68 } // namespace | 69 } // namespace |
| 69 | 70 |
| 70 static jboolean IsOfflinePagesEnabled(JNIEnv* env, | 71 static jboolean IsOfflinePagesEnabled(JNIEnv* env, |
| 71 const JavaParamRef<jclass>& clazz) { | 72 const JavaParamRef<jclass>& clazz) { |
| 72 return offline_pages::IsOfflinePagesEnabled(); | 73 return offline_pages::IsOfflinePagesEnabled(); |
| 73 } | 74 } |
| 74 | 75 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 jlong bookmark_id) { | 120 jlong bookmark_id) { |
| 120 const OfflinePageItem* offline_page = | 121 const OfflinePageItem* offline_page = |
| 121 offline_page_model_->GetPageByBookmarkId(bookmark_id); | 122 offline_page_model_->GetPageByBookmarkId(bookmark_id); |
| 122 if (!offline_page) | 123 if (!offline_page) |
| 123 return ScopedJavaLocalRef<jobject>(); | 124 return ScopedJavaLocalRef<jobject>(); |
| 124 | 125 |
| 125 return Java_OfflinePageBridge_createOfflinePageItem( | 126 return Java_OfflinePageBridge_createOfflinePageItem( |
| 126 env, ConvertUTF8ToJavaString(env, offline_page->url.spec()).obj(), | 127 env, ConvertUTF8ToJavaString(env, offline_page->url.spec()).obj(), |
| 127 offline_page->bookmark_id, | 128 offline_page->bookmark_id, |
| 128 ConvertUTF8ToJavaString(env, offline_page->GetOfflineURL().spec()).obj(), | 129 ConvertUTF8ToJavaString(env, offline_page->GetOfflineURL().spec()).obj(), |
| 129 offline_page->file_size); | 130 offline_page->file_size, |
| 131 offline_page->access_count); |
| 130 } | 132 } |
| 131 | 133 |
| 132 void OfflinePageBridge::SavePage(JNIEnv* env, | 134 void OfflinePageBridge::SavePage(JNIEnv* env, |
| 133 jobject obj, | 135 jobject obj, |
| 134 jobject j_callback_obj, | 136 jobject j_callback_obj, |
| 135 jobject j_web_contents, | 137 jobject j_web_contents, |
| 136 jlong bookmark_id) { | 138 jlong bookmark_id) { |
| 137 DCHECK(j_callback_obj); | 139 DCHECK(j_callback_obj); |
| 138 DCHECK(j_web_contents); | 140 DCHECK(j_web_contents); |
| 139 | 141 |
| 140 ScopedJavaGlobalRef<jobject> j_callback_ref; | 142 ScopedJavaGlobalRef<jobject> j_callback_ref; |
| 141 j_callback_ref.Reset(env, j_callback_obj); | 143 j_callback_ref.Reset(env, j_callback_obj); |
| 142 | 144 |
| 143 content::WebContents* web_contents = | 145 content::WebContents* web_contents = |
| 144 content::WebContents::FromJavaWebContents(j_web_contents); | 146 content::WebContents::FromJavaWebContents(j_web_contents); |
| 145 GURL url(web_contents->GetLastCommittedURL()); | 147 GURL url(web_contents->GetLastCommittedURL()); |
| 146 | 148 |
| 147 scoped_ptr<OfflinePageArchiver> archiver( | 149 scoped_ptr<OfflinePageArchiver> archiver( |
| 148 new OfflinePageMHTMLArchiver( | 150 new OfflinePageMHTMLArchiver( |
| 149 web_contents, GetDownloadsPath(browser_context_))); | 151 web_contents, GetDownloadsPath(browser_context_))); |
| 150 | 152 |
| 151 offline_page_model_->SavePage( | 153 offline_page_model_->SavePage( |
| 152 url, bookmark_id, archiver.Pass(), | 154 url, bookmark_id, archiver.Pass(), |
| 153 base::Bind(&SavePageCallback, j_callback_ref, url)); | 155 base::Bind(&SavePageCallback, j_callback_ref, url)); |
| 154 } | 156 } |
| 155 | 157 |
| 158 void OfflinePageBridge::MarkPageAccessed(JNIEnv* env, |
| 159 jobject obj, |
| 160 jlong bookmark_id) { |
| 161 offline_page_model_->MarkPageAccessed(bookmark_id); |
| 162 } |
| 163 |
| 156 void OfflinePageBridge::DeletePage(JNIEnv* env, | 164 void OfflinePageBridge::DeletePage(JNIEnv* env, |
| 157 jobject obj, | 165 jobject obj, |
| 158 jobject j_callback_obj, | 166 jobject j_callback_obj, |
| 159 jlong bookmark_id) { | 167 jlong bookmark_id) { |
| 160 DCHECK(j_callback_obj); | 168 DCHECK(j_callback_obj); |
| 161 | 169 |
| 162 ScopedJavaGlobalRef<jobject> j_callback_ref; | 170 ScopedJavaGlobalRef<jobject> j_callback_ref; |
| 163 j_callback_ref.Reset(env, j_callback_obj); | 171 j_callback_ref.Reset(env, j_callback_obj); |
| 164 | 172 |
| 165 offline_page_model_->DeletePageByBookmarkId(bookmark_id, base::Bind( | 173 offline_page_model_->DeletePageByBookmarkId(bookmark_id, base::Bind( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 return reinterpret_cast<jlong>(new OfflinePageBridge( | 231 return reinterpret_cast<jlong>(new OfflinePageBridge( |
| 224 env, obj, ProfileAndroid::FromProfileAndroid(j_profile))); | 232 env, obj, ProfileAndroid::FromProfileAndroid(j_profile))); |
| 225 } | 233 } |
| 226 | 234 |
| 227 bool RegisterOfflinePageBridge(JNIEnv* env) { | 235 bool RegisterOfflinePageBridge(JNIEnv* env) { |
| 228 return RegisterNativesImpl(env); | 236 return RegisterNativesImpl(env); |
| 229 } | 237 } |
| 230 | 238 |
| 231 } // namespace android | 239 } // namespace android |
| 232 } // namespace offline_pages | 240 } // namespace offline_pages |
| OLD | NEW |