Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(850)

Side by Side Diff: chrome/browser/android/tab_android.cc

Issue 2337363002: Load live version when reloading an offline page on connected network (Closed)
Patch Set: More fix Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/android/tab_android.h ('k') | components/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/tab_android.h" 5 #include "chrome/browser/android/tab_android.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "components/bookmarks/browser/bookmark_node.h" 61 #include "components/bookmarks/browser/bookmark_node.h"
62 #include "components/bookmarks/browser/bookmark_utils.h" 62 #include "components/bookmarks/browser/bookmark_utils.h"
63 #include "components/bookmarks/managed/managed_bookmark_service.h" 63 #include "components/bookmarks/managed/managed_bookmark_service.h"
64 #include "components/dom_distiller/core/url_utils.h" 64 #include "components/dom_distiller/core/url_utils.h"
65 #include "components/favicon/content/content_favicon_driver.h" 65 #include "components/favicon/content/content_favicon_driver.h"
66 #include "components/navigation_interception/intercept_navigation_delegate.h" 66 #include "components/navigation_interception/intercept_navigation_delegate.h"
67 #include "components/navigation_interception/navigation_params.h" 67 #include "components/navigation_interception/navigation_params.h"
68 #include "components/offline_pages/offline_page_feature.h" 68 #include "components/offline_pages/offline_page_feature.h"
69 #include "components/offline_pages/offline_page_item.h" 69 #include "components/offline_pages/offline_page_item.h"
70 #include "components/offline_pages/offline_page_model.h" 70 #include "components/offline_pages/offline_page_model.h"
71 #include "components/offline_pages/request_header/offline_page_header.h"
71 #include "components/sessions/content/content_live_tab.h" 72 #include "components/sessions/content/content_live_tab.h"
72 #include "components/sessions/core/tab_restore_service.h" 73 #include "components/sessions/core/tab_restore_service.h"
73 #include "components/url_formatter/url_fixer.h" 74 #include "components/url_formatter/url_fixer.h"
74 #include "content/public/browser/android/compositor.h" 75 #include "content/public/browser/android/compositor.h"
75 #include "content/public/browser/browser_thread.h" 76 #include "content/public/browser/browser_thread.h"
76 #include "content/public/browser/interstitial_page.h" 77 #include "content/public/browser/interstitial_page.h"
77 #include "content/public/browser/navigation_entry.h" 78 #include "content/public/browser/navigation_entry.h"
78 #include "content/public/browser/notification_service.h" 79 #include "content/public/browser/notification_service.h"
79 #include "content/public/browser/render_frame_host.h" 80 #include "content/public/browser/render_frame_host.h"
80 #include "content/public/browser/render_process_host.h" 81 #include "content/public/browser/render_process_host.h"
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 812
812 void TabAndroid::ShowOfflinePages() { 813 void TabAndroid::ShowOfflinePages() {
813 JNIEnv* env = base::android::AttachCurrentThread(); 814 JNIEnv* env = base::android::AttachCurrentThread();
814 Java_Tab_showOfflinePages(env, weak_java_tab_.get(env)); 815 Java_Tab_showOfflinePages(env, weak_java_tab_.get(env));
815 } 816 }
816 817
817 jboolean TabAndroid::IsOfflinePage(JNIEnv* env, 818 jboolean TabAndroid::IsOfflinePage(JNIEnv* env,
818 const JavaParamRef<jobject>& obj) { 819 const JavaParamRef<jobject>& obj) {
819 return offline_pages::OfflinePageUtils::GetOfflinePageFromWebContents( 820 return offline_pages::OfflinePageUtils::GetOfflinePageFromWebContents(
820 web_contents()) != nullptr; 821 web_contents()) != nullptr;
822 const offline_pages::OfflinePageItem* offline_page =
Dmitry Titov 2016/09/19 22:06:13 This is unreachable code :) It might be not needed
jianli 2016/09/19 22:26:06 Removed line 820-821.
823 offline_pages::OfflinePageUtils::GetOfflinePageFromWebContents(
824 web_contents());
825 return offline_page && offline_page->url == GetURL();
821 } 826 }
822 827
823 ScopedJavaLocalRef<jobject> TabAndroid::GetOfflinePage( 828 ScopedJavaLocalRef<jobject> TabAndroid::GetOfflinePage(
824 JNIEnv* env, 829 JNIEnv* env,
825 const JavaParamRef<jobject>& obj) { 830 const JavaParamRef<jobject>& obj) {
826 const offline_pages::OfflinePageItem* offline_page = 831 const offline_pages::OfflinePageItem* offline_page =
827 offline_pages::OfflinePageUtils::GetOfflinePageFromWebContents( 832 offline_pages::OfflinePageUtils::GetOfflinePageFromWebContents(
828 web_contents()); 833 web_contents());
829 if (!offline_page) 834 if (!offline_page || offline_page->url != GetURL())
830 return ScopedJavaLocalRef<jobject>(); 835 return ScopedJavaLocalRef<jobject>();
831 836
832 return offline_pages::android::OfflinePageBridge::ConvertToJavaOfflinePage( 837 return offline_pages::android::OfflinePageBridge::ConvertToJavaOfflinePage(
833 env, *offline_page); 838 env, *offline_page);
834 } 839 }
835 840
841 ScopedJavaLocalRef<jstring> TabAndroid::GetOfflinePageHeaderForReload(
Dmitry Titov 2016/09/19 22:06:13 +1 to what Ted said on moving this into OfflinePag
jianli 2016/09/19 22:26:06 Done.
842 JNIEnv* env,
843 const base::android::JavaParamRef<jobject>& obj) {
844 const offline_pages::OfflinePageHeader* offline_header =
845 offline_pages::OfflinePageUtils::GetOfflineHeaderFromWebContents(
846 web_contents());
847 if (!offline_header)
848 return ScopedJavaLocalRef<jstring>();
849
850 // Only replaces the reason field with "reload" value that is used to trigger
851 // the network conditon check again in deciding whether to load the offline
852 // page. All other fields in the offline header should still carry to the
853 // reload request in order to keep the consistent behavior if we do decide to
854 // load the offline page. For example, "id" field should be kept in order to
855 // load the same offline version again if desired.
856 offline_pages::OfflinePageHeader offline_header_for_reload = *offline_header;
857 offline_header_for_reload.reason =
858 offline_pages::OfflinePageHeader::Reason::RELOAD;
859 return ScopedJavaLocalRef<jstring>(ConvertUTF8ToJavaString(
860 env, offline_header_for_reload.GetCompleteHeaderString()));
861 }
862
836 bool TabAndroid::HasPrerenderedUrl(JNIEnv* env, 863 bool TabAndroid::HasPrerenderedUrl(JNIEnv* env,
837 const JavaParamRef<jobject>& obj, 864 const JavaParamRef<jobject>& obj,
838 const JavaParamRef<jstring>& url) { 865 const JavaParamRef<jstring>& url) {
839 GURL gurl(base::android::ConvertJavaStringToUTF8(env, url)); 866 GURL gurl(base::android::ConvertJavaStringToUTF8(env, url));
840 return HasPrerenderedUrl(gurl); 867 return HasPrerenderedUrl(gurl);
841 } 868 }
842 869
843 namespace { 870 namespace {
844 871
845 class ChromeInterceptNavigationDelegate : public InterceptNavigationDelegate { 872 class ChromeInterceptNavigationDelegate : public InterceptNavigationDelegate {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 942 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
916 TRACE_EVENT0("native", "TabAndroid::Init"); 943 TRACE_EVENT0("native", "TabAndroid::Init");
917 // This will automatically bind to the Java object and pass ownership there. 944 // This will automatically bind to the Java object and pass ownership there.
918 new TabAndroid(env, obj); 945 new TabAndroid(env, obj);
919 } 946 }
920 947
921 // static 948 // static
922 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { 949 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) {
923 return RegisterNativesImpl(env); 950 return RegisterNativesImpl(env);
924 } 951 }
OLDNEW
« no previous file with comments | « chrome/browser/android/tab_android.h ('k') | components/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698