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

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: Update button color for "Show all saved pages" per UI review Created 5 years 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') | chrome/browser/net/net_error_tab_helper.h » ('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 "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 {
291 if (!offline_pages::IsOfflinePagesEnabled())
292 return false;
293 offline_pages::OfflinePageModel* offline_page_model =
294 offline_pages::OfflinePageModelFactory::GetForBrowserContext(
295 GetProfile());
296 return !offline_page_model->GetAllPages().empty();
297 }
298
299 void TabAndroid::ShowOfflinePages() {
300 JNIEnv* env = base::android::AttachCurrentThread();
301 Java_Tab_showOfflinePages(env, weak_java_tab_.get(env).obj());
302 }
303
304 void TabAndroid::SwapTabContents(content::WebContents* old_contents, 290 void TabAndroid::SwapTabContents(content::WebContents* old_contents,
305 content::WebContents* new_contents, 291 content::WebContents* new_contents,
306 bool did_start_load, 292 bool did_start_load,
307 bool did_finish_load) { 293 bool did_finish_load) {
308 JNIEnv* env = base::android::AttachCurrentThread(); 294 JNIEnv* env = base::android::AttachCurrentThread();
309 Java_Tab_swapWebContents( 295 Java_Tab_swapWebContents(
310 env, 296 env,
311 weak_java_tab_.get(env).obj(), 297 weak_java_tab_.get(env).obj(),
312 new_contents->GetJavaWebContents().obj(), 298 new_contents->GetJavaWebContents().obj(),
313 did_start_load, 299 did_start_load,
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 void TabAndroid::LoadOriginalImage(JNIEnv* env, jobject obj) { 748 void TabAndroid::LoadOriginalImage(JNIEnv* env, jobject obj) {
763 content::RenderFrameHost* render_frame_host = 749 content::RenderFrameHost* render_frame_host =
764 web_contents()->GetFocusedFrame(); 750 web_contents()->GetFocusedFrame();
765 render_frame_host->Send(new ChromeViewMsg_RequestReloadImageForContextNode( 751 render_frame_host->Send(new ChromeViewMsg_RequestReloadImageForContextNode(
766 render_frame_host->GetRoutingID())); 752 render_frame_host->GetRoutingID()));
767 } 753 }
768 754
769 jlong TabAndroid::GetBookmarkId(JNIEnv* env, 755 jlong TabAndroid::GetBookmarkId(JNIEnv* env,
770 jobject obj, 756 jobject obj,
771 jboolean only_editable) { 757 jboolean only_editable) {
758 return GetBookmarkIdHelper(only_editable);
759 }
760
761 int64_t TabAndroid::GetBookmarkIdHelper(bool only_editable) const {
772 GURL url = dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl( 762 GURL url = dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(
773 web_contents()->GetURL()); 763 web_contents()->GetURL());
774 Profile* profile = GetProfile(); 764 Profile* profile = GetProfile();
775 765
776 // If the url points to an offline page, replace it with the original url. 766 // If the url points to an offline page, replace it with the original url.
777 const offline_pages::OfflinePageItem* offline_page = GetOfflinePage(url); 767 const offline_pages::OfflinePageItem* offline_page = GetOfflinePage(url);
778 if (offline_page) 768 if (offline_page)
779 url = offline_page->url; 769 url = offline_page->url;
780 770
781 // Get all the nodes for |url| and sort them by date added. 771 // Get all the nodes for |url| and sort them by date added.
782 std::vector<const bookmarks::BookmarkNode*> nodes; 772 std::vector<const bookmarks::BookmarkNode*> nodes;
783 bookmarks::ManagedBookmarkService* managed = 773 bookmarks::ManagedBookmarkService* managed =
784 ManagedBookmarkServiceFactory::GetForProfile(profile); 774 ManagedBookmarkServiceFactory::GetForProfile(profile);
785 bookmarks::BookmarkModel* model = 775 bookmarks::BookmarkModel* model =
786 BookmarkModelFactory::GetForProfile(profile); 776 BookmarkModelFactory::GetForProfile(profile);
787 model->GetNodesByURL(url, &nodes); 777 model->GetNodesByURL(url, &nodes);
788 std::sort(nodes.begin(), nodes.end(), &bookmarks::MoreRecentlyAdded); 778 std::sort(nodes.begin(), nodes.end(), &bookmarks::MoreRecentlyAdded);
789 779
790 // Return the first node matching the search criteria. 780 // Return the first node matching the search criteria.
791 for (size_t i = 0; i < nodes.size(); ++i) { 781 for (size_t i = 0; i < nodes.size(); ++i) {
792 if (only_editable && !managed->CanBeEditedByUser(nodes[i])) 782 if (only_editable && !managed->CanBeEditedByUser(nodes[i]))
793 continue; 783 continue;
794 return nodes[i]->id(); 784 return nodes[i]->id();
795 } 785 }
796 786
797 return -1; 787 return -1;
798 } 788 }
799 789
790 bool TabAndroid::HasOfflinePages() const {
791 if (!offline_pages::IsOfflinePagesEnabled())
792 return false;
793 offline_pages::OfflinePageModel* offline_page_model =
794 offline_pages::OfflinePageModelFactory::GetForBrowserContext(
795 GetProfile());
796 return !offline_page_model->GetAllPages().empty();
797 }
798
799 void TabAndroid::ShowOfflinePages() {
800 JNIEnv* env = base::android::AttachCurrentThread();
801 Java_Tab_showOfflinePages(env, weak_java_tab_.get(env).obj());
802 }
803
804 void TabAndroid::LoadOfflineCopy(const GURL& url) {
805 if (!offline_pages::IsOfflinePagesEnabled())
806 return;
807
808 // Offline copy is only saved for a bookmarked page.
809 int64_t bookmark_id = GetBookmarkIdHelper(true);
810 if (bookmark_id == -1)
811 return;
812
813 offline_pages::OfflinePageModel* offline_page_model =
814 offline_pages::OfflinePageModelFactory::GetForBrowserContext(
815 GetProfile());
816 if (!offline_page_model)
817 return;
818
819 const offline_pages::OfflinePageItem* offline_page =
820 offline_page_model->GetPageByBookmarkId(bookmark_id);
821 if (!offline_page || offline_page->url != url)
822 return;
823
824 GURL offline_url = offline_page->GetOfflineURL();
825 if (!offline_url.is_valid())
826 return;
827
828 content::NavigationController::LoadURLParams load_params(offline_url);
829 web_contents()->GetController().LoadURLWithParams(load_params);
830 }
831
800 jboolean TabAndroid::HasOfflineCopy(JNIEnv* env, jobject obj) { 832 jboolean TabAndroid::HasOfflineCopy(JNIEnv* env, jobject obj) {
801 // Offline copy is only saved for a bookmarked page. 833 // Offline copy is only saved for a bookmarked page.
802 jlong bookmark_id = GetBookmarkId(env, obj, true); 834 int64_t bookmark_id = GetBookmarkIdHelper(true);
803 if (bookmark_id == -1) 835 if (bookmark_id == -1)
804 return false; 836 return false;
805 837
806 offline_pages::OfflinePageModel* offline_page_model = 838 offline_pages::OfflinePageModel* offline_page_model =
807 offline_pages::OfflinePageModelFactory::GetForBrowserContext( 839 offline_pages::OfflinePageModelFactory::GetForBrowserContext(
808 GetProfile()); 840 GetProfile());
809 if (!offline_page_model) 841 if (!offline_page_model)
810 return false; 842 return false;
811 const offline_pages::OfflinePageItem* offline_page = 843 const offline_pages::OfflinePageItem* offline_page =
812 offline_page_model->GetPageByBookmarkId(bookmark_id); 844 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) { 955 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
924 TRACE_EVENT0("native", "TabAndroid::Init"); 956 TRACE_EVENT0("native", "TabAndroid::Init");
925 // This will automatically bind to the Java object and pass ownership there. 957 // This will automatically bind to the Java object and pass ownership there.
926 new TabAndroid(env, obj); 958 new TabAndroid(env, obj);
927 } 959 }
928 960
929 // static 961 // static
930 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { 962 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) {
931 return RegisterNativesImpl(env); 963 return RegisterNativesImpl(env);
932 } 964 }
OLDNEW
« no previous file with comments | « chrome/browser/android/tab_android.h ('k') | chrome/browser/net/net_error_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698