From 9c2faf1f1fd39d12f459d75ca3fccd5474802eeb Mon Sep 17 00:00:00 2001 From: twellington Date: Thu, 18 Dec 2014 13:16:10 -0800 Subject: [PATCH] Upstream methods for showing the sad tab Move showSadTab(), isShowingSadTab(), removeSadTabIfPresent() upstream BUG=443664 Review URL: https://codereview.chromium.org/811363003 Cr-Commit-Position: refs/heads/master@{#309072} --- .../java/src/org/chromium/chrome/browser/Tab.java | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/chrome/android/java/src/org/chromium/chrome/browser/Tab.java b/chrome/android/java/src/org/chromium/chrome/browser/Tab.java index 0523ee9ed442..a7c314e51684 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/Tab.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/Tab.java @@ -10,6 +10,9 @@ import android.graphics.Bitmap; import android.graphics.Color; import android.view.ContextMenu; import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup.LayoutParams; +import android.widget.FrameLayout; import org.chromium.base.CalledByNative; import org.chromium.base.ObserverList; @@ -28,6 +31,7 @@ import org.chromium.chrome.browser.fullscreen.FullscreenManager; import org.chromium.chrome.browser.infobar.InfoBarContainer; import org.chromium.chrome.browser.printing.TabPrinter; import org.chromium.chrome.browser.profiles.Profile; +import org.chromium.chrome.browser.tab.SadTabViewFactory; import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; import org.chromium.chrome.browser.tabmodel.TabModelBase; import org.chromium.chrome.browser.toolbar.ToolbarModel; @@ -178,6 +182,11 @@ public class Tab { private int mFullscreenHungRendererToken = FullscreenManager.INVALID_TOKEN; /** + * Reference to the current sadTabView if one is defined. + */ + private View mSadTabView; + + /** * A default {@link ChromeContextMenuItemDelegate} that supports some of the context menu * functionality. */ @@ -544,6 +553,7 @@ public class Tab { public int loadUrl(LoadUrlParams params) { try { TraceEvent.begin("Tab.loadUrl"); + removeSadTabIfPresent(); // We load the URL from the tab rather than directly from the ContentView so the tab has // a chance of using a prerenderer page is any. @@ -993,6 +1003,56 @@ public class Tab { } /** + * Constructs and shows a sad tab (Aw, Snap!). + */ + protected void showSadTab() { + if (getContentViewCore() != null) { + OnClickListener suggestionAction = new OnClickListener() { + @Override + public void onClick(View view) { + loadUrl(new LoadUrlParams(UrlConstants.CRASH_REASON_URL)); + } + }; + OnClickListener reloadButtonAction = new OnClickListener() { + @Override + public void onClick(View view) { + reload(); + } + }; + + // Make sure we are not adding the "Aw, snap" view over an existing one. + assert mSadTabView == null; + mSadTabView = SadTabViewFactory.createSadTabView( + getApplicationContext(), suggestionAction, reloadButtonAction); + + // Show the sad tab inside ContentView. + getContentViewCore().getContainerView().addView( + mSadTabView, new FrameLayout.LayoutParams( + LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); + } + FullscreenManager fullscreenManager = getFullscreenManager(); + if (fullscreenManager != null) { + fullscreenManager.setPositionsForTabToNonFullscreen(); + } + } + + /** + * Removes the sad tab view if present. + */ + protected void removeSadTabIfPresent() { + if (isShowingSadTab()) getContentViewCore().getContainerView().removeView(mSadTabView); + mSadTabView = null; + } + + /** + * @return Whether or not the sad tab is showing. + */ + public boolean isShowingSadTab() { + return mSadTabView != null && getContentViewCore() != null + && mSadTabView.getParent() == getContentViewCore().getContainerView(); + } + + /** * Cleans up all internal state, destroying any {@link NativePage} or {@link ContentViewCore} * currently associated with this {@link Tab}. This also destroys the native counterpart * to this class, which means that all subclasses should erase their native pointers after -- 2.11.4.GIT