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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java

Issue 2076463002: [Custom Tabs] Implement "Read It Later" Behind a Flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test Created 4 years, 6 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 package org.chromium.chrome.browser.customtabs; 5 package org.chromium.chrome.browser.customtabs;
6 6
7 import android.app.PendingIntent; 7 import android.app.PendingIntent;
8 import android.content.Intent; 8 import android.content.Intent;
9 import android.graphics.Bitmap; 9 import android.graphics.Bitmap;
10 import android.net.Uri; 10 import android.net.Uri;
(...skipping 14 matching lines...) Expand all
25 import android.widget.RemoteViews; 25 import android.widget.RemoteViews;
26 26
27 import org.chromium.base.ApiCompatibilityUtils; 27 import org.chromium.base.ApiCompatibilityUtils;
28 import org.chromium.base.Log; 28 import org.chromium.base.Log;
29 import org.chromium.base.ThreadUtils; 29 import org.chromium.base.ThreadUtils;
30 import org.chromium.base.VisibleForTesting; 30 import org.chromium.base.VisibleForTesting;
31 import org.chromium.base.metrics.RecordHistogram; 31 import org.chromium.base.metrics.RecordHistogram;
32 import org.chromium.base.metrics.RecordUserAction; 32 import org.chromium.base.metrics.RecordUserAction;
33 import org.chromium.chrome.R; 33 import org.chromium.chrome.R;
34 import org.chromium.chrome.browser.ChromeActivity; 34 import org.chromium.chrome.browser.ChromeActivity;
35 import org.chromium.chrome.browser.ChromeFeatureList;
35 import org.chromium.chrome.browser.ChromeSwitches; 36 import org.chromium.chrome.browser.ChromeSwitches;
36 import org.chromium.chrome.browser.ChromeTabbedActivity; 37 import org.chromium.chrome.browser.ChromeTabbedActivity;
37 import org.chromium.chrome.browser.IntentHandler; 38 import org.chromium.chrome.browser.IntentHandler;
38 import org.chromium.chrome.browser.IntentHandler.ExternalAppId; 39 import org.chromium.chrome.browser.IntentHandler.ExternalAppId;
39 import org.chromium.chrome.browser.KeyboardShortcuts; 40 import org.chromium.chrome.browser.KeyboardShortcuts;
40 import org.chromium.chrome.browser.WebContentsFactory; 41 import org.chromium.chrome.browser.WebContentsFactory;
41 import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate; 42 import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate;
42 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange Reason; 43 import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange Reason;
43 import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument; 44 import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument;
44 import org.chromium.chrome.browser.datausage.DataUseTabUIManager; 45 import org.chromium.chrome.browser.datausage.DataUseTabUIManager;
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 params.getDescription(), 591 params.getDescription(),
591 new OnClickListener() { 592 new OnClickListener() {
592 @Override 593 @Override
593 public void onClick(View v) { 594 public void onClick(View v) {
594 String creatorPackage = 595 String creatorPackage =
595 ApiCompatibilityUtils.getCreatorPackage(params.g etPendingIntent()); 596 ApiCompatibilityUtils.getCreatorPackage(params.g etPendingIntent());
596 if (mIntentDataProvider.isOpenedByChrome() 597 if (mIntentDataProvider.isOpenedByChrome()
597 && TextUtils.equals(getPackageName(), creatorPac kage)) { 598 && TextUtils.equals(getPackageName(), creatorPac kage)) {
598 RecordUserAction.record( 599 RecordUserAction.record(
599 "TaskManagement.OpenInChromeActionButtonClic ked"); 600 "TaskManagement.OpenInChromeActionButtonClic ked");
600 if (openCurrentUrlInBrowser(false)) finishAndClose() ; 601 if (openCurrentUrlInBrowser(false, true)) finishAndC lose();
601 } else { 602 } else {
602 mIntentDataProvider.sendButtonPendingIntentWithUrl( 603 mIntentDataProvider.sendButtonPendingIntentWithUrl(
603 getApplicationContext(), getActivityTab().ge tUrl()); 604 getApplicationContext(), getActivityTab().ge tUrl());
604 RecordUserAction.record("CustomTabsCustomActionButto nClick"); 605 RecordUserAction.record("CustomTabsCustomActionButto nClick");
605 } 606 }
606 } 607 }
607 }); 608 });
608 } 609 }
609 610
610 @Override 611 @Override
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 // Disable creating new tabs, bookmark, history, print, help, focus_url, etc. 652 // Disable creating new tabs, bookmark, history, print, help, focus_url, etc.
652 if (id == R.id.focus_url_bar || id == R.id.all_bookmarks_menu_id 653 if (id == R.id.focus_url_bar || id == R.id.all_bookmarks_menu_id
653 || id == R.id.print_id || id == R.id.help_id 654 || id == R.id.print_id || id == R.id.help_id
654 || id == R.id.recent_tabs_menu_id || id == R.id.new_incognito_ta b_menu_id 655 || id == R.id.recent_tabs_menu_id || id == R.id.new_incognito_ta b_menu_id
655 || id == R.id.new_tab_menu_id || id == R.id.open_history_menu_id ) { 656 || id == R.id.new_tab_menu_id || id == R.id.open_history_menu_id ) {
656 return true; 657 return true;
657 } else if (id == R.id.bookmark_this_page_id 658 } else if (id == R.id.bookmark_this_page_id
658 && !mIntentDataProvider.shouldShowBookmarkMenuItem()) { 659 && !mIntentDataProvider.shouldShowBookmarkMenuItem()) {
659 return true; 660 return true;
660 } else if (id == R.id.open_in_browser_id) { 661 } else if (id == R.id.open_in_browser_id) {
661 openCurrentUrlInBrowser(false); 662 openCurrentUrlInBrowser(false, true);
662 RecordUserAction.record("CustomTabsMenuOpenInChrome"); 663 RecordUserAction.record("CustomTabsMenuOpenInChrome");
663 return true; 664 return true;
665 } else if (id == R.id.read_it_later_id) {
666 openCurrentUrlInBrowser(false, false);
667 RecordUserAction.record("CustomTabsMenuReadItLater");
668 return true;
664 } else if (id == R.id.find_in_page_id) { 669 } else if (id == R.id.find_in_page_id) {
665 mFindToolbarManager.showToolbar(); 670 mFindToolbarManager.showToolbar();
666 if (getContextualSearchManager() != null) { 671 if (getContextualSearchManager() != null) {
667 getContextualSearchManager().hideContextualSearch(StateChangeRea son.UNKNOWN); 672 getContextualSearchManager().hideContextualSearch(StateChangeRea son.UNKNOWN);
668 } 673 }
669 if (fromMenu) { 674 if (fromMenu) {
670 RecordUserAction.record("MobileMenuFindInPage"); 675 RecordUserAction.record("MobileMenuFindInPage");
671 } else { 676 } else {
672 RecordUserAction.record("MobileShortcutFindInPage"); 677 RecordUserAction.record("MobileShortcutFindInPage");
673 } 678 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 * purposes only. 711 * purposes only.
707 */ 712 */
708 @VisibleForTesting 713 @VisibleForTesting
709 CustomTabIntentDataProvider getIntentDataProvider() { 714 CustomTabIntentDataProvider getIntentDataProvider() {
710 return mIntentDataProvider; 715 return mIntentDataProvider;
711 } 716 }
712 717
713 /** 718 /**
714 * Opens the URL currently being displayed in the Custom Tab in the regular browser. 719 * Opens the URL currently being displayed in the Custom Tab in the regular browser.
715 * @param forceReparenting Whether tab reparenting should be forced for test ing. 720 * @param forceReparenting Whether tab reparenting should be forced for test ing.
716 * 721 * @param stayInChrome Whether the user stays in Chrome after the tab is reparented.
717 * @return Whether or not the tab was sent over successfully. 722 * @return Whether or not the tab was sent over successfully.
718 */ 723 */
719 boolean openCurrentUrlInBrowser(boolean forceReparenting) { 724 boolean openCurrentUrlInBrowser(boolean forceReparenting, boolean stayInChro me) {
720 Tab tab = getActivityTab(); 725 Tab tab = getActivityTab();
721 if (tab == null) return false; 726 if (tab == null) return false;
722 727
723 String url = tab.getUrl(); 728 String url = tab.getUrl();
724 if (DomDistillerUrlUtils.isDistilledPage(url)) { 729 if (DomDistillerUrlUtils.isDistilledPage(url)) {
725 url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url); 730 url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url);
726 } 731 }
727 if (TextUtils.isEmpty(url)) url = getUrlToLoad(); 732 if (TextUtils.isEmpty(url)) url = getUrlToLoad();
728 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 733 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
729 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 734 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
730 intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PAR ENT, false); 735 intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PAR ENT, false);
736 if (ChromeFeatureList.isEnabled("ReadItLaterInMenu")) {
737 // In this trial both "open in chrome" and "read it later" should ta rget Chrome.
738 intent.setPackage(getPackageName());
739 }
731 740
732 boolean willChromeHandleIntent = getIntentDataProvider().isOpenedByChrom e(); 741 boolean willChromeHandleIntent = getIntentDataProvider().isOpenedByChrom e();
733 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); 742 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
734 StrictMode.allowThreadDiskWrites(); 743 StrictMode.allowThreadDiskWrites();
735 try { 744 try {
736 willChromeHandleIntent |= ExternalNavigationDelegateImpl 745 willChromeHandleIntent |= ExternalNavigationDelegateImpl
737 .willChromeHandleIntent(this, intent, true); 746 .willChromeHandleIntent(this, intent, true);
738 } finally { 747 } finally {
739 StrictMode.setThreadPolicy(oldPolicy); 748 StrictMode.setThreadPolicy(oldPolicy);
740 } 749 }
741 750
742 Bundle startActivityOptions = ActivityOptionsCompat.makeCustomAnimation( 751 Bundle startActivityOptions = ActivityOptionsCompat.makeCustomAnimation(
743 this, R.anim.abc_fade_in, R.anim.abc_fade_out).toBundle(); 752 this, R.anim.abc_fade_in, R.anim.abc_fade_out).toBundle();
744 if (willChromeHandleIntent || forceReparenting) { 753 if (willChromeHandleIntent || forceReparenting) {
745 Runnable finalizeCallback = new Runnable() { 754 Runnable finalizeCallback = new Runnable() {
746 @Override 755 @Override
747 public void run() { 756 public void run() {
748 finishAndClose(); 757 finishAndClose();
749 } 758 }
750 }; 759 };
751 760
752 mMainTab = null; 761 mMainTab = null;
753 tab.detachAndStartReparenting(intent, startActivityOptions, finalize Callback); 762 tab.detachAndStartReparenting(intent, startActivityOptions, finalize Callback,
763 stayInChrome);
754 } else { 764 } else {
755 // Temporarily allowing disk access while fixing. TODO: http://crbug .com/581860 765 // Temporarily allowing disk access while fixing. TODO: http://crbug .com/581860
756 StrictMode.allowThreadDiskReads(); 766 StrictMode.allowThreadDiskReads();
757 StrictMode.allowThreadDiskWrites(); 767 StrictMode.allowThreadDiskWrites();
758 try { 768 try {
759 startActivity(intent, startActivityOptions); 769 startActivity(intent, startActivityOptions);
760 } finally { 770 } finally {
761 StrictMode.setThreadPolicy(oldPolicy); 771 StrictMode.setThreadPolicy(oldPolicy);
762 } 772 }
763 } 773 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 * overridden if the Data Reduction Proxy is using Lo-Fi previews. 817 * overridden if the Data Reduction Proxy is using Lo-Fi previews.
808 */ 818 */
809 private String getUrlToLoad() { 819 private String getUrlToLoad() {
810 String url = IntentHandler.getUrlFromIntent(getIntent()); 820 String url = IntentHandler.getUrlFromIntent(getIntent());
811 if (!TextUtils.isEmpty(url)) { 821 if (!TextUtils.isEmpty(url)) {
812 url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUr l(url); 822 url = DataReductionProxySettings.getInstance().maybeRewriteWebliteUr l(url);
813 } 823 }
814 return url; 824 return url;
815 } 825 }
816 } 826 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698