| 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 <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/android/offline_pages/offline_page_utils.h" | 21 #include "chrome/browser/android/offline_pages/offline_page_utils.h" |
| 22 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" | 22 #include "chrome/browser/android/offline_pages/request_coordinator_factory.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/profiles/profile_android.h" | 24 #include "chrome/browser/profiles/profile_android.h" |
| 25 #include "components/offline_pages/background/request_coordinator.h" | 25 #include "components/offline_pages/background/request_coordinator.h" |
| 26 #include "components/offline_pages/background/request_queue.h" | 26 #include "components/offline_pages/background/request_queue.h" |
| 27 #include "components/offline_pages/background/save_page_request.h" | 27 #include "components/offline_pages/background/save_page_request.h" |
| 28 #include "components/offline_pages/offline_page_feature.h" | 28 #include "components/offline_pages/offline_page_feature.h" |
| 29 #include "components/offline_pages/offline_page_item.h" | 29 #include "components/offline_pages/offline_page_item.h" |
| 30 #include "components/offline_pages/offline_page_model.h" | 30 #include "components/offline_pages/offline_page_model.h" |
| 31 #include "components/offline_pages/request_header/offline_page_header.h" |
| 31 #include "content/public/browser/browser_context.h" | 32 #include "content/public/browser/browser_context.h" |
| 32 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
| 33 #include "jni/OfflinePageBridge_jni.h" | 34 #include "jni/OfflinePageBridge_jni.h" |
| 34 #include "jni/SavePageRequest_jni.h" | 35 #include "jni/SavePageRequest_jni.h" |
| 35 #include "net/base/filename_util.h" | 36 #include "net/base/filename_util.h" |
| 36 | 37 |
| 37 using base::android::ConvertJavaStringToUTF8; | 38 using base::android::ConvertJavaStringToUTF8; |
| 38 using base::android::ConvertUTF8ToJavaString; | 39 using base::android::ConvertUTF8ToJavaString; |
| 39 using base::android::JavaParamRef; | 40 using base::android::JavaParamRef; |
| 40 using base::android::ScopedJavaGlobalRef; | 41 using base::android::ScopedJavaGlobalRef; |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 offline_page_model_->DeletePagesByOfflineId( | 472 offline_page_model_->DeletePagesByOfflineId( |
| 472 offline_ids, base::Bind(&DeletePageCallback, j_callback_ref)); | 473 offline_ids, base::Bind(&DeletePageCallback, j_callback_ref)); |
| 473 } | 474 } |
| 474 | 475 |
| 475 void OfflinePageBridge::CheckMetadataConsistency( | 476 void OfflinePageBridge::CheckMetadataConsistency( |
| 476 JNIEnv* env, | 477 JNIEnv* env, |
| 477 const JavaParamRef<jobject>& obj) { | 478 const JavaParamRef<jobject>& obj) { |
| 478 offline_page_model_->CheckMetadataConsistency(); | 479 offline_page_model_->CheckMetadataConsistency(); |
| 479 } | 480 } |
| 480 | 481 |
| 482 ScopedJavaLocalRef<jstring> OfflinePageBridge::GetOfflinePageHeaderForReload( |
| 483 JNIEnv* env, |
| 484 const base::android::JavaParamRef<jobject>& obj, |
| 485 const JavaParamRef<jobject>& j_web_contents) { |
| 486 content::WebContents* web_contents = |
| 487 content::WebContents::FromJavaWebContents(j_web_contents); |
| 488 if (!web_contents) |
| 489 return ScopedJavaLocalRef<jstring>(); |
| 490 |
| 491 const offline_pages::OfflinePageHeader* offline_header = |
| 492 offline_pages::OfflinePageUtils::GetOfflineHeaderFromWebContents( |
| 493 web_contents); |
| 494 if (!offline_header) |
| 495 return ScopedJavaLocalRef<jstring>(); |
| 496 |
| 497 // Only replaces the reason field with "reload" value that is used to trigger |
| 498 // the network conditon check again in deciding whether to load the offline |
| 499 // page. All other fields in the offline header should still carry to the |
| 500 // reload request in order to keep the consistent behavior if we do decide to |
| 501 // load the offline page. For example, "id" field should be kept in order to |
| 502 // load the same offline version again if desired. |
| 503 offline_pages::OfflinePageHeader offline_header_for_reload = *offline_header; |
| 504 offline_header_for_reload.reason = |
| 505 offline_pages::OfflinePageHeader::Reason::RELOAD; |
| 506 return ScopedJavaLocalRef<jstring>(ConvertUTF8ToJavaString( |
| 507 env, offline_header_for_reload.GetCompleteHeaderString())); |
| 508 } |
| 509 |
| 481 void OfflinePageBridge::GetRequestsInQueue( | 510 void OfflinePageBridge::GetRequestsInQueue( |
| 482 JNIEnv* env, | 511 JNIEnv* env, |
| 483 const JavaParamRef<jobject>& obj, | 512 const JavaParamRef<jobject>& obj, |
| 484 const JavaParamRef<jobject>& j_callback_obj) { | 513 const JavaParamRef<jobject>& j_callback_obj) { |
| 485 ScopedJavaGlobalRef<jobject> j_callback_ref(j_callback_obj); | 514 ScopedJavaGlobalRef<jobject> j_callback_ref(j_callback_obj); |
| 486 | 515 |
| 487 RequestCoordinator* coordinator = | 516 RequestCoordinator* coordinator = |
| 488 offline_pages::RequestCoordinatorFactory::GetInstance() | 517 offline_pages::RequestCoordinatorFactory::GetInstance() |
| 489 ->GetForBrowserContext(browser_context_); | 518 ->GetForBrowserContext(browser_context_); |
| 490 | 519 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 env, ConvertUTF8ToJavaString(env, client_id.name_space), | 568 env, ConvertUTF8ToJavaString(env, client_id.name_space), |
| 540 ConvertUTF8ToJavaString(env, client_id.id)); | 569 ConvertUTF8ToJavaString(env, client_id.id)); |
| 541 } | 570 } |
| 542 | 571 |
| 543 bool RegisterOfflinePageBridge(JNIEnv* env) { | 572 bool RegisterOfflinePageBridge(JNIEnv* env) { |
| 544 return RegisterNativesImpl(env); | 573 return RegisterNativesImpl(env); |
| 545 } | 574 } |
| 546 | 575 |
| 547 } // namespace android | 576 } // namespace android |
| 548 } // namespace offline_pages | 577 } // namespace offline_pages |
| OLD | NEW |