| 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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 offline_page_model_->DeletePagesByOfflineId( | 450 offline_page_model_->DeletePagesByOfflineId( |
| 450 offline_ids, base::Bind(&DeletePageCallback, j_callback_ref)); | 451 offline_ids, base::Bind(&DeletePageCallback, j_callback_ref)); |
| 451 } | 452 } |
| 452 | 453 |
| 453 void OfflinePageBridge::CheckMetadataConsistency( | 454 void OfflinePageBridge::CheckMetadataConsistency( |
| 454 JNIEnv* env, | 455 JNIEnv* env, |
| 455 const JavaParamRef<jobject>& obj) { | 456 const JavaParamRef<jobject>& obj) { |
| 456 offline_page_model_->CheckMetadataConsistency(); | 457 offline_page_model_->CheckMetadataConsistency(); |
| 457 } | 458 } |
| 458 | 459 |
| 460 ScopedJavaLocalRef<jstring> OfflinePageBridge::GetOfflinePageHeaderForReload( |
| 461 JNIEnv* env, |
| 462 const base::android::JavaParamRef<jobject>& obj, |
| 463 const JavaParamRef<jobject>& j_web_contents) { |
| 464 content::WebContents* web_contents = |
| 465 content::WebContents::FromJavaWebContents(j_web_contents); |
| 466 if (!web_contents) |
| 467 return ScopedJavaLocalRef<jstring>(); |
| 468 |
| 469 const offline_pages::OfflinePageHeader* offline_header = |
| 470 offline_pages::OfflinePageUtils::GetOfflineHeaderFromWebContents( |
| 471 web_contents); |
| 472 if (!offline_header) |
| 473 return ScopedJavaLocalRef<jstring>(); |
| 474 |
| 475 // Only replaces the reason field with "reload" value that is used to trigger |
| 476 // the network conditon check again in deciding whether to load the offline |
| 477 // page. All other fields in the offline header should still carry to the |
| 478 // reload request in order to keep the consistent behavior if we do decide to |
| 479 // load the offline page. For example, "id" field should be kept in order to |
| 480 // load the same offline version again if desired. |
| 481 offline_pages::OfflinePageHeader offline_header_for_reload = *offline_header; |
| 482 offline_header_for_reload.reason = |
| 483 offline_pages::OfflinePageHeader::Reason::RELOAD; |
| 484 return ScopedJavaLocalRef<jstring>(ConvertUTF8ToJavaString( |
| 485 env, offline_header_for_reload.GetCompleteHeaderString())); |
| 486 } |
| 487 |
| 459 void OfflinePageBridge::GetRequestsInQueue( | 488 void OfflinePageBridge::GetRequestsInQueue( |
| 460 JNIEnv* env, | 489 JNIEnv* env, |
| 461 const JavaParamRef<jobject>& obj, | 490 const JavaParamRef<jobject>& obj, |
| 462 const JavaParamRef<jobject>& j_callback_obj) { | 491 const JavaParamRef<jobject>& j_callback_obj) { |
| 463 ScopedJavaGlobalRef<jobject> j_callback_ref(j_callback_obj); | 492 ScopedJavaGlobalRef<jobject> j_callback_ref(j_callback_obj); |
| 464 | 493 |
| 465 RequestCoordinator* coordinator = | 494 RequestCoordinator* coordinator = |
| 466 offline_pages::RequestCoordinatorFactory::GetInstance() | 495 offline_pages::RequestCoordinatorFactory::GetInstance() |
| 467 ->GetForBrowserContext(browser_context_); | 496 ->GetForBrowserContext(browser_context_); |
| 468 | 497 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 env, ConvertUTF8ToJavaString(env, client_id.name_space), | 546 env, ConvertUTF8ToJavaString(env, client_id.name_space), |
| 518 ConvertUTF8ToJavaString(env, client_id.id)); | 547 ConvertUTF8ToJavaString(env, client_id.id)); |
| 519 } | 548 } |
| 520 | 549 |
| 521 bool RegisterOfflinePageBridge(JNIEnv* env) { | 550 bool RegisterOfflinePageBridge(JNIEnv* env) { |
| 522 return RegisterNativesImpl(env); | 551 return RegisterNativesImpl(env); |
| 523 } | 552 } |
| 524 | 553 |
| 525 } // namespace android | 554 } // namespace android |
| 526 } // namespace offline_pages | 555 } // namespace offline_pages |
| OLD | NEW |