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

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

Issue 1442433003: Add "Show saved copy" button in dino page when there's offline copy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Some minor fixes Created 5 years, 1 month 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
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 "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 280
281 // Only allows the browser-initiated navigation to use POST. 281 // Only allows the browser-initiated navigation to use POST.
282 if (params->uses_post && !params->is_renderer_initiated) { 282 if (params->uses_post && !params->is_renderer_initiated) {
283 load_url_params->load_type = 283 load_url_params->load_type =
284 NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; 284 NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST;
285 load_url_params->browser_initiated_post_data = 285 load_url_params->browser_initiated_post_data =
286 params->browser_initiated_post_data; 286 params->browser_initiated_post_data;
287 } 287 }
288 } 288 }
289 289
290 bool TabAndroid::HasOfflinePages() const { 290 bool TabAndroid::HasOfflinePages() const {
newt (away) 2015/11/13 19:20:19 All the methods related to offline pages should be
jianli 2015/11/13 22:32:13 Done.
291 if (!offline_pages::IsOfflinePagesEnabled()) 291 if (!offline_pages::IsOfflinePagesEnabled())
292 return false; 292 return false;
293 offline_pages::OfflinePageModel* offline_page_model = 293 offline_pages::OfflinePageModel* offline_page_model =
294 offline_pages::OfflinePageModelFactory::GetForBrowserContext( 294 offline_pages::OfflinePageModelFactory::GetForBrowserContext(
295 GetProfile()); 295 GetProfile());
296 return !offline_page_model->GetAllPages().empty(); 296 return !offline_page_model->GetAllPages().empty();
297 } 297 }
298 298
299 void TabAndroid::ShowOfflinePages() { 299 void TabAndroid::ShowOfflinePages() {
300 JNIEnv* env = base::android::AttachCurrentThread(); 300 JNIEnv* env = base::android::AttachCurrentThread();
301 Java_Tab_showOfflinePages(env, weak_java_tab_.get(env).obj()); 301 Java_Tab_showOfflinePages(env, weak_java_tab_.get(env).obj());
302 } 302 }
303 303
304 void TabAndroid::LoadOfflineCopy(const GURL& url) {
305 if (!offline_pages::IsOfflinePagesEnabled())
306 return;
307
308 // Offline copy is only saved for a bookmarked page.
309 int64_t bookmark_id = GetBookmarkIdHelper(true);
310 if (bookmark_id == -1)
311 return;
312
313 offline_pages::OfflinePageModel* offline_page_model =
314 offline_pages::OfflinePageModelFactory::GetForBrowserContext(
315 GetProfile());
316 if (!offline_page_model)
317 return;
318 const offline_pages::OfflinePageItem* offline_page =
319 offline_page_model->GetPageByBookmarkId(bookmark_id);
320 if (!offline_page)
321 return;
322 GURL offline_url = offline_page->GetOfflineURL();
323 if (!offline_url.is_valid())
324 return;
325
326 content::NavigationController::LoadURLParams load_params(offline_url);
327 web_contents()->GetController().LoadURLWithParams(load_params);
328 }
329
304 void TabAndroid::SwapTabContents(content::WebContents* old_contents, 330 void TabAndroid::SwapTabContents(content::WebContents* old_contents,
305 content::WebContents* new_contents, 331 content::WebContents* new_contents,
306 bool did_start_load, 332 bool did_start_load,
307 bool did_finish_load) { 333 bool did_finish_load) {
308 JNIEnv* env = base::android::AttachCurrentThread(); 334 JNIEnv* env = base::android::AttachCurrentThread();
309 Java_Tab_swapWebContents( 335 Java_Tab_swapWebContents(
310 env, 336 env,
311 weak_java_tab_.get(env).obj(), 337 weak_java_tab_.get(env).obj(),
312 new_contents->GetJavaWebContents().obj(), 338 new_contents->GetJavaWebContents().obj(),
313 did_start_load, 339 did_start_load,
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 void TabAndroid::LoadOriginalImage(JNIEnv* env, jobject obj) { 788 void TabAndroid::LoadOriginalImage(JNIEnv* env, jobject obj) {
763 content::RenderFrameHost* render_frame_host = 789 content::RenderFrameHost* render_frame_host =
764 web_contents()->GetFocusedFrame(); 790 web_contents()->GetFocusedFrame();
765 render_frame_host->Send(new ChromeViewMsg_RequestReloadImageForContextNode( 791 render_frame_host->Send(new ChromeViewMsg_RequestReloadImageForContextNode(
766 render_frame_host->GetRoutingID())); 792 render_frame_host->GetRoutingID()));
767 } 793 }
768 794
769 jlong TabAndroid::GetBookmarkId(JNIEnv* env, 795 jlong TabAndroid::GetBookmarkId(JNIEnv* env,
770 jobject obj, 796 jobject obj,
771 jboolean only_editable) { 797 jboolean only_editable) {
798 return GetBookmarkIdHelper(only_editable);
799 }
800
801 int64_t TabAndroid::GetBookmarkIdHelper(bool only_editable) const {
772 GURL url = dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl( 802 GURL url = dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(
773 web_contents()->GetURL()); 803 web_contents()->GetURL());
774 Profile* profile = GetProfile(); 804 Profile* profile = GetProfile();
775 805
776 // If the url points to an offline page, replace it with the original url. 806 // If the url points to an offline page, replace it with the original url.
777 const offline_pages::OfflinePageItem* offline_page = GetOfflinePage(url); 807 const offline_pages::OfflinePageItem* offline_page = GetOfflinePage(url);
778 if (offline_page) 808 if (offline_page)
779 url = offline_page->url; 809 url = offline_page->url;
780 810
781 // Get all the nodes for |url| and sort them by date added. 811 // Get all the nodes for |url| and sort them by date added.
782 std::vector<const bookmarks::BookmarkNode*> nodes; 812 std::vector<const bookmarks::BookmarkNode*> nodes;
783 bookmarks::ManagedBookmarkService* managed = 813 bookmarks::ManagedBookmarkService* managed =
784 ManagedBookmarkServiceFactory::GetForProfile(profile); 814 ManagedBookmarkServiceFactory::GetForProfile(profile);
785 bookmarks::BookmarkModel* model = 815 bookmarks::BookmarkModel* model =
786 BookmarkModelFactory::GetForProfile(profile); 816 BookmarkModelFactory::GetForProfile(profile);
787 model->GetNodesByURL(url, &nodes); 817 model->GetNodesByURL(url, &nodes);
788 std::sort(nodes.begin(), nodes.end(), &bookmarks::MoreRecentlyAdded); 818 std::sort(nodes.begin(), nodes.end(), &bookmarks::MoreRecentlyAdded);
789 819
790 // Return the first node matching the search criteria. 820 // Return the first node matching the search criteria.
791 for (size_t i = 0; i < nodes.size(); ++i) { 821 for (size_t i = 0; i < nodes.size(); ++i) {
792 if (only_editable && !managed->CanBeEditedByUser(nodes[i])) 822 if (only_editable && !managed->CanBeEditedByUser(nodes[i]))
793 continue; 823 continue;
794 return nodes[i]->id(); 824 return nodes[i]->id();
795 } 825 }
796 826
797 return -1; 827 return -1;
798 } 828 }
799 829
800 jboolean TabAndroid::HasOfflineCopy(JNIEnv* env, jobject obj) { 830 jboolean TabAndroid::HasOfflineCopy(JNIEnv* env, jobject obj) {
831 return HasOfflineCopyForCurrentPage();
832 }
833
834 bool TabAndroid::HasOfflineCopyForCurrentPage() const {
801 // Offline copy is only saved for a bookmarked page. 835 // Offline copy is only saved for a bookmarked page.
802 jlong bookmark_id = GetBookmarkId(env, obj, true); 836 int64_t bookmark_id = GetBookmarkIdHelper(true);
803 if (bookmark_id == -1) 837 if (bookmark_id == -1)
804 return false; 838 return false;
805 839
806 offline_pages::OfflinePageModel* offline_page_model = 840 offline_pages::OfflinePageModel* offline_page_model =
807 offline_pages::OfflinePageModelFactory::GetForBrowserContext( 841 offline_pages::OfflinePageModelFactory::GetForBrowserContext(
808 GetProfile()); 842 GetProfile());
809 if (!offline_page_model) 843 if (!offline_page_model)
810 return false; 844 return false;
811 const offline_pages::OfflinePageItem* offline_page = 845 const offline_pages::OfflinePageItem* offline_page =
812 offline_page_model->GetPageByBookmarkId(bookmark_id); 846 offline_page_model->GetPageByBookmarkId(bookmark_id);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 957 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
924 TRACE_EVENT0("native", "TabAndroid::Init"); 958 TRACE_EVENT0("native", "TabAndroid::Init");
925 // This will automatically bind to the Java object and pass ownership there. 959 // This will automatically bind to the Java object and pass ownership there.
926 new TabAndroid(env, obj); 960 new TabAndroid(env, obj);
927 } 961 }
928 962
929 // static 963 // static
930 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { 964 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) {
931 return RegisterNativesImpl(env); 965 return RegisterNativesImpl(env);
932 } 966 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698