diff options
author | tedchoc <tedchoc@chromium.org> | 2016-03-09 12:10:16 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-09 20:12:24 +0000 |
commit | 42e21a0e7325f5f06626a494bd2710913195863b (patch) | |
tree | ed307fc066037c996bc26a9bdb1b99c5302e4ae5 | |
parent | 1e2eb58c114b87acb269b022a9074d7290fcdbde (diff) | |
download | chromium_src-42e21a0e7325f5f06626a494bd2710913195863b.zip chromium_src-42e21a0e7325f5f06626a494bd2710913195863b.tar.gz chromium_src-42e21a0e7325f5f06626a494bd2710913195863b.tar.bz2 |
Revert "Revert of Switch back to open image in new tab where applicable. (patchset #4 id:60001 of https://codereview.chromium.org/1741153002/ )"
This reverts commit aea0d270c480410ad8764473797bbf5b5f6c6189.
BUG=593316
Review URL: https://codereview.chromium.org/1775013005
Cr-Commit-Position: refs/heads/master@{#380193}
6 files changed, 72 insertions, 41 deletions
diff --git a/chrome/android/java/res/menu/chrome_context_menu.xml b/chrome/android/java/res/menu/chrome_context_menu.xml index d2e2f7c..477ac1b 100644 --- a/chrome/android/java/res/menu/chrome_context_menu.xml +++ b/chrome/android/java/res/menu/chrome_context_menu.xml @@ -28,6 +28,8 @@ android:title="@string/contextmenu_save_image"/> <item android:id="@+id/contextmenu_open_image" android:title="@string/contextmenu_open_image"/> + <item android:id="@+id/contextmenu_open_image_in_new_tab" + android:title="@string/contextmenu_open_image_in_new_tab"/> <!-- Title is set in Java. Suppress lint warning about missing title. --> <!--suppress MenuTitle --> <item android:id="@+id/contextmenu_search_by_image" /> diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java index 4e6240d..93e88fc 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ChromeContextMenuPopulator.java @@ -47,7 +47,7 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { R.id.contextmenu_open_in_incognito_tab, R.id.contextmenu_save_link_as, R.id.contextmenu_load_original_image, - R.id.contextmenu_open_image, + R.id.contextmenu_open_image_in_new_tab, R.id.contextmenu_search_by_image, }; @@ -77,6 +77,7 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { static final int ACTION_SAVE_LINK = 5; static final int ACTION_SAVE_IMAGE = 6; static final int ACTION_OPEN_IMAGE = 7; + static final int ACTION_OPEN_IMAGE_IN_NEW_TAB = 8; static final int ACTION_SEARCH_BY_IMAGE = 11; static final int ACTION_LOAD_IMAGES = 12; static final int ACTION_LOAD_ORIGINAL_IMAGE = 13; @@ -279,6 +280,9 @@ public class ChromeContextMenuPopulator implements ContextMenuPopulator { } else if (itemId == R.id.contextmenu_open_image) { ContextMenuUma.record(params, ContextMenuUma.ACTION_OPEN_IMAGE); mDelegate.onOpenImageUrl(params.getSrcUrl(), params.getReferrer()); + } else if (itemId == R.id.contextmenu_open_image_in_new_tab) { + ContextMenuUma.record(params, ContextMenuUma.ACTION_OPEN_IMAGE_IN_NEW_TAB); + mDelegate.onOpenImageInNewTab(params.getSrcUrl(), params.getReferrer()); } else if (itemId == R.id.contextmenu_load_images) { ContextMenuUma.record(params, ContextMenuUma.ACTION_LOAD_IMAGES); DataReductionProxyUma.dataReductionProxyLoFiUIAction( diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuItemDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuItemDelegate.java index 5f08746..6dc2a46 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuItemDelegate.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/ContextMenuItemDelegate.java @@ -63,6 +63,12 @@ public interface ContextMenuItemDelegate { void onOpenImageUrl(String url, Referrer referrer); /** + * Called when the {@code url} is of an image and should be opened in a new tab. + * @param url The image URL to open. + */ + void onOpenImageInNewTab(String url, Referrer referrer); + + /** * Reloads all the Lo-Fi images in a Tab. */ void onReloadLoFiImages(); diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tab/TabContextMenuItemDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/tab/TabContextMenuItemDelegate.java index 6873f39..06fc49d 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/tab/TabContextMenuItemDelegate.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/tab/TabContextMenuItemDelegate.java @@ -27,6 +27,9 @@ import java.util.Locale; * A default {@link ContextMenuItemDelegate} that supports the context menu functionality in Tab. */ public class TabContextMenuItemDelegate implements ContextMenuItemDelegate { + public static final String PAGESPEED_PASSTHROUGH_HEADERS = + "Chrome-Proxy: pass-through\nCache-Control: no-cache"; + private final Clipboard mClipboard; private final Tab mTab; @@ -108,6 +111,16 @@ public class TabContextMenuItemDelegate implements ContextMenuItemDelegate { } @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); + mTab.getActivity().getTabModelSelector().openNewTab(loadUrlParams, + TabLaunchType.FROM_LONGPRESS_BACKGROUND, mTab, isIncognito()); + } + + @Override public void onOpenInChrome(String linkUrl, String pageUrl) { Intent chromeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl)); chromeIntent.setPackage(mTab.getApplicationContext().getPackageName()); diff --git a/chrome/android/java/strings/android_chrome_strings.grd b/chrome/android/java/strings/android_chrome_strings.grd index f0fbc26..eb6d92d 100644 --- a/chrome/android/java/strings/android_chrome_strings.grd +++ b/chrome/android/java/strings/android_chrome_strings.grd @@ -1325,6 +1325,9 @@ You are signing in with a managed account and giving its administrator control o <message name="IDS_CONTEXTMENU_OPEN_IMAGE" desc="Context sensitive menu item for opening/viewing the selected image. [CHAR-LIMIT=30]"> Open image </message> + <message name="IDS_CONTEXTMENU_OPEN_IMAGE_IN_NEW_TAB" desc="Context sensitive menu item for opening/viewing the selected image in a new tab. [CHAR-LIMIT=30]"> + Open image in new tab + </message> <message name="IDS_CONTEXTMENU_LOAD_IMAGES" desc="Context sensitive menu item for Data Saver low fidelity placeholder images that reloads the page with the original images. [CHAR-LIMIT=30]"> Load images </message> diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java index bf400dc..8d69889 100644 --- a/chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java @@ -10,10 +10,10 @@ import android.content.Context; import android.os.Environment; import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.MediumTest; +import android.text.TextUtils; import android.view.ContextMenu; import android.view.KeyEvent; -import org.chromium.base.ThreadUtils; import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.DisableIf; import org.chromium.base.test.util.Feature; @@ -22,19 +22,19 @@ import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.compositor.layouts.LayoutManager; import org.chromium.chrome.browser.download.DownloadTestBase; import org.chromium.chrome.browser.tab.Tab; +import org.chromium.chrome.browser.tabmodel.EmptyTabModelSelectorObserver; import org.chromium.chrome.browser.tabmodel.TabModel; import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils; +import org.chromium.content.browser.test.util.CallbackHelper; import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.DOMUtils; -import org.chromium.content.browser.test.util.TestCallbackHelperContainer; -import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageFinishedHelper; import org.chromium.content.browser.test.util.TestTouchUtils; import org.chromium.net.test.EmbeddedTestServer; import java.io.IOException; -import java.util.concurrent.Callable; import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicReference; /** * Context menu related tests @@ -111,57 +111,60 @@ public class ContextMenuTest extends DownloadTestBase { @MediumTest @Feature({"Browser"}) + @CommandLineFlags.Add(ChromeSwitches.DISABLE_DOCUMENT_MODE) public void testLongPressOnImage() throws InterruptedException, TimeoutException { - final Tab tab = getActivity().getActivityTab(); - - TestCallbackHelperContainer helper = - new TestCallbackHelperContainer(tab.getContentViewCore()); + checkOpenImageInNewTab( + "testImage", "/chrome/test/data/android/contextmenu/test_image.png"); + } - OnPageFinishedHelper callback = helper.getOnPageFinishedHelper(); - int callbackCount = callback.getCallCount(); + @MediumTest + @Feature({"Browser"}) + @CommandLineFlags.Add(ChromeSwitches.DISABLE_DOCUMENT_MODE) + public void testLongPressOnImageLink() throws InterruptedException, TimeoutException { + checkOpenImageInNewTab( + "testImageLink", "/chrome/test/data/android/contextmenu/test_image.png"); + } - ContextMenuUtils.selectContextMenuItem(this, tab, "testImage", - R.id.contextmenu_open_image); + private void checkOpenImageInNewTab(String domId, final String expectedPath) + throws InterruptedException, TimeoutException { + final Tab activityTab = getActivity().getActivityTab(); - callback.waitForCallback(callbackCount); + final CallbackHelper newTabCallback = new CallbackHelper(); + final AtomicReference<Tab> newTab = new AtomicReference<>(); + getActivity().getTabModelSelector().addObserver(new EmptyTabModelSelectorObserver() { + @Override + public void onNewTabCreated(Tab tab) { + super.onNewTabCreated(tab); - String expectedUrl = mTestServer.getURL( - "/chrome/test/data/android/contextmenu/test_image.png"); + if (tab.getParentId() != activityTab.getId()) return; + newTab.set(tab); + newTabCallback.notifyCalled(); - String actualUrl = ThreadUtils.runOnUiThreadBlockingNoException(new Callable<String>() { - @Override - public String call() throws Exception { - return tab.getUrl(); + getActivity().getTabModelSelector().removeObserver(this); } }); - assertEquals("Failed to navigate to the image", expectedUrl, actualUrl); - } - - @MediumTest - @Feature({"Browser"}) - public void testLongPressOnImageLink() throws InterruptedException, TimeoutException { - final Tab tab = getActivity().getActivityTab(); - - TestCallbackHelperContainer helper = - new TestCallbackHelperContainer(tab.getContentViewCore()); - - OnPageFinishedHelper callback = helper.getOnPageFinishedHelper(); - int callbackCount = callback.getCallCount(); + int callbackCount = newTabCallback.getCallCount(); - ContextMenuUtils.selectContextMenuItem(this, tab, "testImage", - R.id.contextmenu_open_image); + ContextMenuUtils.selectContextMenuItem(this, activityTab, domId, + R.id.contextmenu_open_image_in_new_tab); - callback.waitForCallback(callbackCount); + try { + newTabCallback.waitForCallback(callbackCount); + } catch (TimeoutException ex) { + fail("New tab never created from context menu press"); + } - String actualTitle = ThreadUtils.runOnUiThreadBlockingNoException(new Callable<String>() { + // Only check for the URL matching as the tab will not be fully created in svelte mode. + final String expectedUrl = mTestServer.getURL(expectedPath); + CriteriaHelper.pollForUIThreadCriteria(new Criteria() { @Override - public String call() throws Exception { - return tab.getTitle(); + public boolean isSatisfied() { + String actualUrl = newTab.get().getUrl(); + updateFailureReason("Expected URL: " + expectedUrl + ", actual: " + actualUrl); + return TextUtils.equals(actualUrl, expectedUrl); } }); - - assertTrue("Navigated to the wrong page.", actualTitle.startsWith("test_image.png")); } @MediumTest |