Chromium Code Reviews| Index: chrome/browser/android/tab_android.cc |
| diff --git a/chrome/browser/android/tab_android.cc b/chrome/browser/android/tab_android.cc |
| index a0e5897d7a52551babfceaed467d0c6b6580238f..7e8a73edf9cdaee74b83a2c8a4d9b51e85e4f8dc 100644 |
| --- a/chrome/browser/android/tab_android.cc |
| +++ b/chrome/browser/android/tab_android.cc |
| @@ -68,6 +68,7 @@ |
| #include "components/offline_pages/offline_page_feature.h" |
| #include "components/offline_pages/offline_page_item.h" |
| #include "components/offline_pages/offline_page_model.h" |
| +#include "components/offline_pages/request_header/offline_page_header.h" |
| #include "components/sessions/content/content_live_tab.h" |
| #include "components/sessions/core/tab_restore_service.h" |
| #include "components/url_formatter/url_fixer.h" |
| @@ -818,6 +819,10 @@ jboolean TabAndroid::IsOfflinePage(JNIEnv* env, |
| const JavaParamRef<jobject>& obj) { |
| return offline_pages::OfflinePageUtils::GetOfflinePageFromWebContents( |
| web_contents()) != nullptr; |
| + const offline_pages::OfflinePageItem* offline_page = |
| + offline_pages::OfflinePageUtils::GetOfflinePageFromWebContents( |
| + web_contents()); |
| + return offline_page && offline_page->url == GetURL(); |
| } |
| ScopedJavaLocalRef<jobject> TabAndroid::GetOfflinePage( |
| @@ -826,13 +831,35 @@ ScopedJavaLocalRef<jobject> TabAndroid::GetOfflinePage( |
| const offline_pages::OfflinePageItem* offline_page = |
| offline_pages::OfflinePageUtils::GetOfflinePageFromWebContents( |
| web_contents()); |
| - if (!offline_page) |
| + if (!offline_page || offline_page->url != GetURL()) |
| return ScopedJavaLocalRef<jobject>(); |
| return offline_pages::android::OfflinePageBridge::ConvertToJavaOfflinePage( |
| env, *offline_page); |
| } |
| +ScopedJavaLocalRef<jstring> TabAndroid::GetOfflinePageHeaderForReload( |
|
Ted C
2016/09/19 21:53:49
Do we need to add these to tab_android? Could we
jianli
2016/09/19 22:26:06
Done.
|
| + JNIEnv* env, |
| + const base::android::JavaParamRef<jobject>& obj) { |
| + const offline_pages::OfflinePageHeader* offline_header = |
| + offline_pages::OfflinePageUtils::GetOfflineHeaderFromWebContents( |
| + web_contents()); |
| + if (!offline_header) |
| + return ScopedJavaLocalRef<jstring>(); |
| + |
| + // Only replaces the reason field with "reload" value that is used to trigger |
| + // the network conditon check again in deciding whether to load the offline |
| + // page. All other fields in the offline header should still carry to the |
| + // reload request in order to keep the consistent behavior if we do decide to |
| + // load the offline page. For example, "id" field should be kept in order to |
| + // load the same offline version again if desired. |
| + offline_pages::OfflinePageHeader offline_header_for_reload = *offline_header; |
| + offline_header_for_reload.reason = |
| + offline_pages::OfflinePageHeader::Reason::RELOAD; |
| + return ScopedJavaLocalRef<jstring>(ConvertUTF8ToJavaString( |
| + env, offline_header_for_reload.GetCompleteHeaderString())); |
| +} |
| + |
| bool TabAndroid::HasPrerenderedUrl(JNIEnv* env, |
| const JavaParamRef<jobject>& obj, |
| const JavaParamRef<jstring>& url) { |