diff options
author | dfalcantara <dfalcantara@chromium.org> | 2015-06-29 14:46:03 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-29 21:46:36 +0000 |
commit | 45e48112cf464db57bd8531f35f5cae8fd02b217 (patch) | |
tree | 5ca9aa26cd052a2258810810106e9f7b9bbf0260 | |
parent | ea4a57276d184133b06f1460f4c58ab0939a2db1 (diff) | |
download | chromium_src-45e48112cf464db57bd8531f35f5cae8fd02b217.zip chromium_src-45e48112cf464db57bd8531f35f5cae8fd02b217.tar.gz chromium_src-45e48112cf464db57bd8531f35f5cae8fd02b217.tar.bz2 |
[Document mode] Fix incognito always opening in the foreground
* Fixes the TabDelegateImpl not opening new Incognito tabs
in the foreground from other Incognito tabs.
* Deletes the DocumentTab's ContextMenuItemDelegate. Changing
it to using a TabCreator/TabDelegate removed the final logical
differences between it and the ChromeTab's ContextMenuItemDelegate.
* Updates one DocumentModeTest with new opening in the foreground
checks, and adds a new test specifically for catching the
Incognito scenario.
BUG=451453,505355
TEST=DocumentModeTest
Review URL: https://codereview.chromium.org/1213233004
Cr-Commit-Position: refs/heads/master@{#336654}
4 files changed, 62 insertions, 89 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/document/DocumentTab.java b/chrome/android/java/src/org/chromium/chrome/browser/document/DocumentTab.java index 591788f..0f32153 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/document/DocumentTab.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/document/DocumentTab.java @@ -8,7 +8,6 @@ import android.graphics.Bitmap; import org.chromium.base.ObserverList.RewindableIterator; import org.chromium.base.VisibleForTesting; -import org.chromium.base.metrics.RecordUserAction; import org.chromium.chrome.browser.ChromeMobileApplication; import org.chromium.chrome.browser.EmptyTabObserver; import org.chromium.chrome.browser.IntentHandler; @@ -19,17 +18,11 @@ import org.chromium.chrome.browser.TabUma.TabCreationState; import org.chromium.chrome.browser.WarmupManager; import org.chromium.chrome.browser.WebContentsFactory; import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager; -import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator; -import org.chromium.chrome.browser.contextmenu.ContextMenuPopulator; -import org.chromium.chrome.browser.preferences.PrefServiceBridge; import org.chromium.chrome.browser.tab.ChromeTab; import org.chromium.chrome.browser.tabmodel.TabModel; import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; import org.chromium.chrome.browser.tabmodel.document.ActivityDelegate; -import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.WebContents; -import org.chromium.content_public.common.Referrer; -import org.chromium.ui.base.PageTransition; import org.chromium.ui.base.WindowAndroid; /** @@ -162,76 +155,6 @@ public class DocumentTab extends ChromeTab { } } - private class DocumentContextMenuItemDelegate extends TabChromeContextMenuItemDelegate { - @Override - public boolean isIncognitoSupported() { - return PrefServiceBridge.getInstance().isIncognitoModeEnabled(); - } - - @Override - public boolean canLoadOriginalImage() { - return mUsedSpdyProxy && !mUsedSpdyProxyWithPassthrough; - } - - @Override - public boolean isDataReductionProxyEnabledForURL(String url) { - return isSpdyProxyEnabledForUrl(url); - } - - @Override - public boolean startDownload(String url, boolean isLink) { - if (isLink && shouldInterceptContextMenuDownload(url)) { - return false; - } - return true; - } - - @Override - public void onOpenInNewTab(String url, Referrer referrer) { - LoadUrlParams params = new LoadUrlParams(url); - params.setReferrer(referrer); - mActivity.getTabModelSelector().openNewTab(params, - TabLaunchType.FROM_LONGPRESS_BACKGROUND, DocumentTab.this, isIncognito()); - } - - @Override - public void onOpenInNewIncognitoTab(String url) { - mActivity.getTabModelSelector().openNewTab( - new LoadUrlParams(url), - TabLaunchType.FROM_LONGPRESS_FOREGROUND, DocumentTab.this, true); - } - - @Override - public void onOpenImageInNewTab(String url, Referrer referrer) { - boolean useOriginal = isSpdyProxyEnabledForUrl(url); - - LoadUrlParams loadUrlParams = new LoadUrlParams(url); - loadUrlParams.setVerbatimHeaders(useOriginal ? PAGESPEED_PASSTHROUGH_HEADERS : null); - loadUrlParams.setReferrer(referrer); - mActivity.getTabModelSelector().openNewTab(loadUrlParams, - TabLaunchType.FROM_LONGPRESS_BACKGROUND, DocumentTab.this, isIncognito()); - } - - @Override - public void onOpenImageUrl(String url, Referrer referrer) { - LoadUrlParams loadUrlParams = new LoadUrlParams(url); - loadUrlParams.setTransitionType(PageTransition.AUTO_BOOKMARK); - loadUrlParams.setReferrer(referrer); - loadUrl(loadUrlParams); - } - - @Override - public void onSearchByImageInNewTab() { - RecordUserAction.record("MobileContextMenuSearchByImage"); - triggerSearchByImage(); - } - } - - @Override - protected ContextMenuPopulator createContextMenuPopulator() { - return new ChromeContextMenuPopulator(new DocumentContextMenuItemDelegate()); - } - /** * A web contents delegate for handling opening new windows in Document mode. */ diff --git a/chrome/android/java/src/org/chromium/chrome/browser/document/TabDelegateImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/document/TabDelegateImpl.java index 607c0442..beb63f6 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/document/TabDelegateImpl.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/document/TabDelegateImpl.java @@ -123,8 +123,14 @@ public class TabDelegateImpl implements TabDelegate { int launchMode; if (TextUtils.equals(UrlConstants.NTP_URL, loadUrlParams.getUrl())) { launchMode = ChromeLauncherActivity.LAUNCH_MODE_RETARGET; - } else if (type == TabLaunchType.FROM_LONGPRESS_BACKGROUND && !mIsIncognito) { - launchMode = ChromeLauncherActivity.LAUNCH_MODE_AFFILIATED; + } else if (type == TabLaunchType.FROM_LONGPRESS_BACKGROUND) { + if (!parent.isIncognito() && mIsIncognito) { + // Incognito tabs opened from regular tabs open in the foreground for privacy + // concerns. + launchMode = ChromeLauncherActivity.LAUNCH_MODE_FOREGROUND; + } else { + launchMode = ChromeLauncherActivity.LAUNCH_MODE_AFFILIATED; + } } else { launchMode = ChromeLauncherActivity.LAUNCH_MODE_FOREGROUND; } diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTest.java index 9196407..e88ab1f 100644 --- a/chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTest.java +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTest.java @@ -377,6 +377,43 @@ public class DocumentModeTest extends DocumentModeTestBase { } /** + * Tests that opening an Incognito tab via a context menu while in Incognito mode opens the tab + * in the background. + */ + @MediumTest + public void testIncognitoOpensInBackgroundFromIncognito() throws Exception { + // Create an Incognito tab via an Intent extra. + assertFalse(ChromeMobileApplication.isDocumentTabModelSelectorInitializedForTests()); + final int firstId = launchViaLaunchDocumentInstance(true, HREF_LINK, "href link page"); + assertTrue(ChromeMobileApplication.isDocumentTabModelSelectorInitializedForTests()); + final DocumentTabModelSelector selector = + ChromeMobileApplication.getDocumentTabModelSelector(); + final TabModel incognitoModel = selector.getModel(true); + assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() { + @Override + public boolean isSatisfied() { + return firstId == selector.getCurrentTabId() && selector.getTotalTabCount() == 1; + } + })); + assertEquals(incognitoModel, selector.getCurrentModel()); + + Activity firstActivity = ApplicationStatus.getLastTrackedFocusedActivity(); + assertTrue(firstActivity instanceof IncognitoDocumentActivity); + + // The context menu for links in Incognito mode lacks an "Open in new Incognito tab" option. + // Instead, the regular "Open in new tab" option opens a new incognito tab. + openLinkInNewTabViaContextMenu(false, true); + assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() { + @Override + public boolean isSatisfied() { + return firstId == selector.getCurrentTabId() && selector.getTotalTabCount() == 2; + } + })); + assertEquals(incognitoModel, selector.getCurrentModel()); + assertEquals(firstActivity, ApplicationStatus.getLastTrackedFocusedActivity()); + } + + /** * Confirm that the incognito tabs and TabModel are destroyed when the "close all" notification * Intent is fired. */ @@ -474,16 +511,17 @@ public class DocumentModeTest extends DocumentModeTestBase { } /** - * Tests that Incognito tabs are opened in the foreground. + * Tests that Incognito tabs are opened in the foreground when spawned from a regular tab. */ @MediumTest public void testIncognitoOpensInForegroundViaLinkContextMenu() throws Exception { launchViaLaunchDocumentInstance(false, HREF_LINK, "href link page"); // Save the current tab info. - Activity regularActivity = ApplicationStatus.getLastTrackedFocusedActivity(); - assertTrue(regularActivity instanceof DocumentActivity); - assertFalse(regularActivity instanceof IncognitoDocumentActivity); + Activity activity = ApplicationStatus.getLastTrackedFocusedActivity(); + assertTrue(activity instanceof DocumentActivity); + assertFalse(activity instanceof IncognitoDocumentActivity); + final DocumentActivity regularActivity = (DocumentActivity) activity; final DocumentTabModelSelector selector = ChromeMobileApplication.getDocumentTabModelSelector(); @@ -492,7 +530,7 @@ public class DocumentModeTest extends DocumentModeTestBase { final int regularTabId = selector.getCurrentTabId(); // Open a link in incognito via the context menu. - openLinkInNewTabViaContextMenu(true); + openLinkInNewTabViaContextMenu(true, true); final DocumentActivity secondActivity = (DocumentActivity) ApplicationStatus.getLastTrackedFocusedActivity(); final int secondTabId = selector.getCurrentTabId(); @@ -522,7 +560,8 @@ public class DocumentModeTest extends DocumentModeTestBase { public void run() { LoadUrlParams params = new LoadUrlParams(URL_1); secondActivity.getTabModelSelector().openNewTab( - params, TabModel.TabLaunchType.FROM_LONGPRESS_BACKGROUND, null, true); + params, TabModel.TabLaunchType.FROM_LONGPRESS_BACKGROUND, + regularActivity.getActivityTab(), true); } }; DocumentActivity thirdActivity = ActivityUtils.waitForActivity(getInstrumentation(), diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTestBase.java b/chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTestBase.java index 8fb0671..a300e3a 100644 --- a/chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTestBase.java +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/document/DocumentModeTestBase.java @@ -217,7 +217,7 @@ public class DocumentModeTestBase extends MultiActivityTestBase { final DocumentActivity expectedActivity = (DocumentActivity) ApplicationStatus.getLastTrackedFocusedActivity(); - openLinkInNewTabViaContextMenu(false); + openLinkInNewTabViaContextMenu(false, false); assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() { @Override @@ -234,8 +234,13 @@ public class DocumentModeTestBase extends MultiActivityTestBase { /** * Long presses at the center of the page and opens a new Tab via a link's context menu. + * @param selectIncognitoItem If true, selects "Open in incognito tab". + * If false, selects "Open in new tab". + * @param waitForIncognito If true, waits for an IncognitoDocumentActivity to start. + * If false, waits for a DocumentActivity to start. */ - protected void openLinkInNewTabViaContextMenu(final boolean incognito) throws Exception { + protected void openLinkInNewTabViaContextMenu( + final boolean selectIncognitoItem, final boolean waitForIncognito) throws Exception { // Long press the center of the page, which should bring up the context menu. final TestTabObserver observer = new TestTabObserver(); final DocumentActivity activity = @@ -259,11 +264,11 @@ public class DocumentModeTestBase extends MultiActivityTestBase { // Select the "open in new tab" option. DocumentActivity newActivity = ActivityUtils.waitForActivity(getInstrumentation(), - incognito ? IncognitoDocumentActivity.class : DocumentActivity.class, + waitForIncognito ? IncognitoDocumentActivity.class : DocumentActivity.class, new Runnable() { @Override public void run() { - if (incognito) { + if (selectIncognitoItem) { assertTrue(observer.mContextMenu.performIdentifierAction( R.id.contextmenu_open_in_incognito_tab, 0)); } else { |