Index: chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java |
index ab1fe0c71f3d759022bf313cb774bf24f96f6e9b..a243231a5bf2ba1435cbcf30ef502fbed5ceb630 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java |
@@ -39,6 +39,8 @@ import org.chromium.chrome.browser.appmenu.AppMenuPropertiesDelegate; |
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChangeReason; |
import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument; |
import org.chromium.chrome.browser.datausage.DataUseTabUIManager; |
+import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
+import org.chromium.chrome.browser.preferences.ChromePreferenceManager; |
import org.chromium.chrome.browser.rappor.RapporServiceBridge; |
import org.chromium.chrome.browser.tab.Tab; |
import org.chromium.chrome.browser.tab.TabIdManager; |
@@ -66,6 +68,14 @@ import java.util.List; |
*/ |
public class CustomTabActivity extends ChromeActivity { |
private static final String TAG = "CustomTabActivity"; |
+ |
+ /** |
+ * Extra used by Chrome to tell the CustomTabActivity to finish itself and open the current URL |
+ * in Chrome. Guarded explicitly for use only by PendingIntents with the Chrome package. |
+ */ |
+ public static final String EXTRA_ALLOW_OPEN_IN_BROWSER = |
+ "org.chromium.chrome.browser.customtabs.ALLOW_OPEN_IN_BROWSER"; |
Ian Wen
2016/02/10 22:08:40
Move this extra to CustomTabsIntentDataProvider, w
gone
2016/02/10 22:28:24
Went with FINISH_AFTER_OPENING_IN_BROWSER. We'll
|
+ |
private static CustomTabContentHandler sActiveContentHandler; |
private FindToolbarManager mFindToolbarManager; |
@@ -81,6 +91,7 @@ public class CustomTabActivity extends ChromeActivity { |
private boolean mRecordedStartupUma; |
private boolean mShouldReplaceCurrentEntry; |
+ private boolean mIsAllowedToOpenInBrowser; |
private CustomTabObserver mTabObserver; |
// Only the normal tab model is observed because there is no icognito tabmodel in Custom Tabs. |
@@ -174,6 +185,10 @@ public class CustomTabActivity extends ChromeActivity { |
super.preInflationStartup(); |
mIntentDataProvider = new CustomTabIntentDataProvider(getIntent(), this); |
+ mIsAllowedToOpenInBrowser = !TextUtils.isEmpty(ChromePreferenceManager.getHerbFlavor()) |
Ian Wen
2016/02/10 22:08:40
mIsAllowedToOpenInBrowser() should still be initia
gone
2016/02/10 22:28:24
Done.
|
+ && IntentUtils.safeGetBooleanExtra( |
+ getIntent(), EXTRA_ALLOW_OPEN_IN_BROWSER, false); |
+ |
supportRequestWindowFeature(Window.FEATURE_ACTION_MODE_OVERLAY); |
} |
@@ -444,7 +459,7 @@ public class CustomTabActivity extends ChromeActivity { |
* Configures the custom button on toolbar. Does nothing if invalid data is provided by clients. |
*/ |
private void showCustomButtonOnToolbar() { |
- CustomButtonParams params = mIntentDataProvider.getCustomButtonOnToolbar(); |
+ final CustomButtonParams params = mIntentDataProvider.getCustomButtonOnToolbar(); |
if (params == null) return; |
getToolbarManager().setCustomActionButton( |
params.getIcon(getResources()), |
@@ -452,9 +467,16 @@ public class CustomTabActivity extends ChromeActivity { |
new OnClickListener() { |
@Override |
public void onClick(View v) { |
- mIntentDataProvider.sendButtonPendingIntentWithUrl( |
- getApplicationContext(), getActivityTab().getUrl()); |
- RecordUserAction.record("CustomTabsCustomActionButtonClick"); |
+ if (mIsAllowedToOpenInBrowser && TextUtils.equals(getPackageName(), |
+ ApiCompatibilityUtils.getCreatorPackage( |
+ params.getPendingIntent()))) { |
+ openCurrentUrlInBrowser(); |
+ finish(); |
+ } else { |
+ mIntentDataProvider.sendButtonPendingIntentWithUrl( |
+ getApplicationContext(), getActivityTab().getUrl()); |
+ RecordUserAction.record("CustomTabsCustomActionButtonClick"); |
+ } |
} |
}); |
} |
@@ -561,22 +583,7 @@ public class CustomTabActivity extends ChromeActivity { |
|| id == R.id.new_tab_menu_id || id == R.id.open_history_menu_id) { |
return true; |
} else if (id == R.id.open_in_browser_id) { |
- String url = getTabModelSelector().getCurrentTab().getUrl(); |
- if (DomDistillerUrlUtils.isDistilledPage(url)) { |
- url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url); |
- } |
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
- |
- // Temporarily allowing disk access while fixing. TODO: http://crbug.com/581860 |
- StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
- StrictMode.allowThreadDiskWrites(); |
- try { |
- startActivity(intent); |
- } finally { |
- StrictMode.setThreadPolicy(oldPolicy); |
- } |
- |
+ openCurrentUrlInBrowser(); |
RecordUserAction.record("CustomTabsMenuOpenInChrome"); |
return true; |
} else if (id == R.id.find_in_page_id) { |
@@ -621,4 +628,26 @@ public class CustomTabActivity extends ChromeActivity { |
CustomTabIntentDataProvider getIntentDataProvider() { |
return mIntentDataProvider; |
} |
+ |
+ /** |
+ * Opens the URL currently being displayed in the Custom Tab in the regular browser. |
+ */ |
+ void openCurrentUrlInBrowser() { |
+ String url = getTabModelSelector().getCurrentTab().getUrl(); |
+ if (DomDistillerUrlUtils.isDistilledPage(url)) { |
+ url = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url); |
+ } |
+ Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
+ intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, false); |
+ |
+ // Temporarily allowing disk access while fixing. TODO: http://crbug.com/581860 |
+ StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
+ StrictMode.allowThreadDiskWrites(); |
+ try { |
+ startActivity(intent); |
+ } finally { |
+ StrictMode.setThreadPolicy(oldPolicy); |
+ } |
+ } |
} |