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

Unified Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/hosted/HostedTab.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java_staging/src/org/chromium/chrome/browser/hosted/HostedTab.java
diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/hosted/HostedTab.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/hosted/HostedTab.java
new file mode 100644
index 0000000000000000000000000000000000000000..50fb9bcc276e650cb6fca7dc4c1842d201f38d0c
--- /dev/null
+++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/hosted/HostedTab.java
@@ -0,0 +1,93 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.hosted;
+
+import android.content.Context;
+import android.text.TextUtils;
+import android.view.ContextMenu;
+import android.view.Menu;
+
+import com.google.android.apps.chrome.R;
+
+import org.chromium.chrome.browser.CompositorChromeActivity;
+import org.chromium.chrome.browser.ContentViewUtil;
+import org.chromium.chrome.browser.Tab;
+import org.chromium.chrome.browser.UrlUtilities;
+import org.chromium.chrome.browser.contextmenu.ChromeContextMenuPopulator;
+import org.chromium.chrome.browser.contextmenu.ContextMenuParams;
+import org.chromium.chrome.browser.contextmenu.ContextMenuPopulator;
+import org.chromium.chrome.browser.tab.ChromeTab;
+import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
+import org.chromium.content_public.browser.WebContents;
+import org.chromium.ui.base.WindowAndroid;
+
+/**
+ * A chrome tab that is only used in hosted mode.
+ */
+public class HostedTab extends ChromeTab {
+
+ private TabChromeContextMenuItemDelegate
+ mContextMenuDelegate = new TabChromeContextMenuItemDelegate() {
+ @Override
+ public boolean startDownload(String url, boolean isLink) {
+ // Behave similarly to ChromeTabChromeContextMenuItemDelegate in ChromeTab.
+ return !isLink || !shouldInterceptContextMenuDownload(url);
+ }
+ };
+
+ /**
+ * Construct an HostedTab. It might load a prerendered {@link WebContents} for the URL, if
+ * the hosted mode service has successfully warmed up for the url.
+ */
+ public HostedTab(CompositorChromeActivity activity, WindowAndroid windowAndroid,
+ long sessionId, String url, int parentTabId) {
+ super(Tab.generateValidId(Tab.INVALID_TAB_ID), activity, false, windowAndroid,
+ TabLaunchType.FROM_EXTERNAL_APP, parentTabId, null, null);
+ WebContents webContents = ChromeBrowserConnection.getInstance(activity.getApplication())
+ .takePrerenderedUrl(sessionId, url, null);
+ if (webContents == null) {
+ webContents = ContentViewUtil.createWebContents(isIncognito(), false);
+ }
+ initialize(webContents, activity.getTabContentManager(), false);
+ getView().requestFocus();
+ }
+
+ @Override
+ protected ContextMenuPopulator createContextMenuPopulator() {
+ return new ChromeContextMenuPopulator(mContextMenuDelegate) {
+ @Override
+ public void buildContextMenu(ContextMenu menu, Context context,
+ ContextMenuParams params) {
+ String linkUrl = params.getLinkUrl();
+ if (linkUrl != null) linkUrl = linkUrl.trim();
+ if (!TextUtils.isEmpty(linkUrl)) {
+ menu.add(Menu.NONE, org.chromium.chrome.R.id.contextmenu_copy_link_address_text,
+ Menu.NONE, org.chromium.chrome.R.string.contextmenu_copy_link_address);
+ }
+
+ String linkText = params.getLinkText();
+ if (linkText != null) linkText = linkText.trim();
+ if (!TextUtils.isEmpty(linkText)) {
+ menu.add(Menu.NONE, org.chromium.chrome.R.id.contextmenu_copy_link_text,
+ Menu.NONE, org.chromium.chrome.R.string.contextmenu_copy_link_text);
+ }
+ if (params.isImage()) {
+ menu.add(Menu.NONE, R.id.contextmenu_save_image, Menu.NONE,
+ R.string.contextmenu_save_image);
+ menu.add(Menu.NONE, R.id.contextmenu_open_image, Menu.NONE,
+ R.string.contextmenu_open_image);
+ menu.add(Menu.NONE, R.id.contextmenu_copy_image, Menu.NONE,
+ R.string.contextmenu_copy_image);
+ menu.add(Menu.NONE, R.id.contextmenu_copy_image_url, Menu.NONE,
+ R.string.contextmenu_copy_image_url);
+ } else if (UrlUtilities.isDownloadableScheme(params.getLinkUrl())) {
+ // "Save link" is not shown for image.
+ menu.add(Menu.NONE, R.id.contextmenu_save_link_as, Menu.NONE,
+ R.string.contextmenu_save_link);
+ }
+ }
+ };
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698