OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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::GetAllOfflinePageURLS( | |
Dmitry Titov
2015/11/20 01:53:39
URLS->URLs
jianli
2015/11/20 02:51:12
Removed since this function is not longer needed.
| |
800 std::vector<GURL>* offline_page_urls) const { | |
801 if (!offline_pages::IsOfflinePagesEnabled()) | |
802 return; | |
803 offline_pages::OfflinePageModel* offline_page_model = | |
804 offline_pages::OfflinePageModelFactory::GetForBrowserContext( | |
805 GetProfile()); | |
806 for (const auto& item : offline_page_model->GetAllPages()) | |
807 offline_page_urls->push_back(item.url); | |
808 } | |
809 | |
810 void TabAndroid::ShowOfflinePages() { | |
811 JNIEnv* env = base::android::AttachCurrentThread(); | |
812 Java_Tab_showOfflinePages(env, weak_java_tab_.get(env).obj()); | |
813 } | |
814 | |
815 void TabAndroid::LoadOfflineCopy(const GURL& url) { | |
816 if (!offline_pages::IsOfflinePagesEnabled()) | |
817 return; | |
818 | |
819 // Offline copy is only saved for a bookmarked page. | |
820 int64_t bookmark_id = GetBookmarkIdHelper(true); | |
821 if (bookmark_id == -1) | |
822 return; | |
823 | |
824 offline_pages::OfflinePageModel* offline_page_model = | |
825 offline_pages::OfflinePageModelFactory::GetForBrowserContext( | |
826 GetProfile()); | |
827 if (!offline_page_model) | |
828 return; | |
829 | |
830 const offline_pages::OfflinePageItem* offline_page = | |
831 offline_page_model->GetPageByBookmarkId(bookmark_id); | |
832 if (!offline_page || offline_page->url != url) | |
833 return; | |
834 | |
835 GURL offline_url = offline_page->GetOfflineURL(); | |
836 if (!offline_url.is_valid()) | |
837 return; | |
838 | |
839 content::NavigationController::LoadURLParams load_params(offline_url); | |
840 web_contents()->GetController().LoadURLWithParams(load_params); | |
841 } | |
842 | |
800 jboolean TabAndroid::HasOfflineCopy(JNIEnv* env, jobject obj) { | 843 jboolean TabAndroid::HasOfflineCopy(JNIEnv* env, jobject obj) { |
801 // Offline copy is only saved for a bookmarked page. | 844 // Offline copy is only saved for a bookmarked page. |
802 jlong bookmark_id = GetBookmarkId(env, obj, true); | 845 int64_t bookmark_id = GetBookmarkIdHelper(true); |
803 if (bookmark_id == -1) | 846 if (bookmark_id == -1) |
804 return false; | 847 return false; |
805 | 848 |
806 offline_pages::OfflinePageModel* offline_page_model = | 849 offline_pages::OfflinePageModel* offline_page_model = |
807 offline_pages::OfflinePageModelFactory::GetForBrowserContext( | 850 offline_pages::OfflinePageModelFactory::GetForBrowserContext( |
808 GetProfile()); | 851 GetProfile()); |
809 if (!offline_page_model) | 852 if (!offline_page_model) |
810 return false; | 853 return false; |
811 const offline_pages::OfflinePageItem* offline_page = | 854 const offline_pages::OfflinePageItem* offline_page = |
812 offline_page_model->GetPageByBookmarkId(bookmark_id); | 855 offline_page_model->GetPageByBookmarkId(bookmark_id); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
923 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 966 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
924 TRACE_EVENT0("native", "TabAndroid::Init"); | 967 TRACE_EVENT0("native", "TabAndroid::Init"); |
925 // This will automatically bind to the Java object and pass ownership there. | 968 // This will automatically bind to the Java object and pass ownership there. |
926 new TabAndroid(env, obj); | 969 new TabAndroid(env, obj); |
927 } | 970 } |
928 | 971 |
929 // static | 972 // static |
930 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 973 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
931 return RegisterNativesImpl(env); | 974 return RegisterNativesImpl(env); |
932 } | 975 } |
OLD | NEW |