From 77d0820201b15b6f5b4894395ca9f577056ea7bc Mon Sep 17 00:00:00 2001 From: fdegans Date: Fri, 31 Jul 2015 08:15:45 -0700 Subject: [PATCH] Revert of Add getThemeColor to Tab and add plumbing for ChromeActivites. (patchset #3 id:40001 of https://codereview.chromium.org/1254423006/) Reason for revert: Speculative revert. This seems to have broken BrandColorTest.testBrandColorInterstitial BrandColorTest.testNavigatingToBrandColorAndBack BrandColorTest.testNoBrandColor on Lollipop in Document Mde. Original issue's description: > Add getThemeColor to Tab and add plumbing for ChromeActivites. > > Moves all theme color computing logic to tab. Adds the necessary > update signals to ChromeActivity and adds an onUpdate call to be > overridden by extending classes. > > The main outcome of all this is, all ChromeActivities become color change aware. Doesn't add any visual changes. Yet. > > BUG=507340 > > Committed: https://crrev.com/25d23c547cd7661fe2e679d74e4272917dae2985 > Cr-Commit-Position: refs/heads/master@{#341226} TBR=dtrainor@chromium.org,yusufo@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=507340 Review URL: https://codereview.chromium.org/1260523004 Cr-Commit-Position: refs/heads/master@{#341332} --- .../chrome/browser/ChromeActivity.java | 43 -------------- .../browser/document/DocumentActivity.java | 57 +++++++++++++++---- .../chrome/browser/tab/ChromeTab.java | 28 --------- 3 files changed, 47 insertions(+), 81 deletions(-) diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java index 82fb4f0ece09..52b22c66c292 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java @@ -97,7 +97,6 @@ import org.chromium.chrome.browser.snackbar.SnackbarManager; import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarManageable; import org.chromium.chrome.browser.sync.ProfileSyncService; -import org.chromium.chrome.browser.tab.ChromeTab; import org.chromium.chrome.browser.tab.EmptyTabObserver; import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.TabObserver; @@ -212,8 +211,6 @@ public AppMenuHandler get(Activity activity, private OnPreDrawListener mFirstDrawListener; - protected int mThemeColor; - private final Locale mCurrentLocale = Locale.getDefault(); private AssistStatusHandler mAssistStatusHandler; @@ -501,27 +498,6 @@ public void onPageLoadFinished(Tab tab) { public void onCrash(Tab tab, boolean sadTabShown) { postDeferredStartupIfNeeded(); } - - @Override - public void onDidChangeThemeColor(int color) { - checkThemeColorUpdate(); - } - - @Override - public void onWebContentsSwapped(Tab tab, boolean didStartLoad, boolean didFinishLoad) { - if (!didStartLoad) return; - checkThemeColorUpdate(); - } - - @Override - public void onSSLStateUpdated(Tab tab) { - checkThemeColorUpdate(); - } - - @Override - public void onDidAttachInterstitialPage(Tab tab) { - checkThemeColorUpdate(); - } }; if (mAssistStatusHandler != null) { @@ -529,14 +505,6 @@ public void onDidAttachInterstitialPage(Tab tab) { } } - private void checkThemeColorUpdate() { - if (getActivityTab() == null) return; - int themeColor = ChromeTab.fromTab(getActivityTab()).getThemeColor(); - if (mThemeColor == themeColor) return; - mThemeColor = themeColor; - onThemeColorUpdate(); - } - @Override public void onStartWithNative() { super.onStartWithNative(); @@ -1482,15 +1450,4 @@ public void onTabSelectionHinted(int tabId) { } @Override public void onSceneChange(Layout layout) { } - - /** - * Gets called when the theme color corresponding to current tab changes. - */ - protected void onThemeColorUpdate() { - if (mToolbarManager == null) return; - mToolbarManager.updatePrimaryColor(mThemeColor); - ControlContainer controlContainer = - (ControlContainer) findViewById(R.id.control_container); - controlContainer.getToolbarResourceAdapter().invalidate(null); - } } diff --git a/chrome/android/java/src/org/chromium/chrome/browser/document/DocumentActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/document/DocumentActivity.java index b22e66a8afb4..1ede45b25d91 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/document/DocumentActivity.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/document/DocumentActivity.java @@ -58,6 +58,7 @@ import org.chromium.chrome.browser.toolbar.ToolbarControlContainer; import org.chromium.chrome.browser.util.FeatureUtilities; import org.chromium.chrome.browser.util.IntentUtils; +import org.chromium.chrome.browser.widget.ControlContainer; import org.chromium.chrome.browser.widget.RoundedIconGenerator; import org.chromium.chrome.browser.widget.findinpage.FindToolbarManager; import org.chromium.components.service_tab_launcher.ServiceTabLauncher; @@ -103,6 +104,7 @@ public class DocumentActivity extends ChromeActivity { // Indicates whether mIcon was generated by RoundedIconGenerator. private boolean mIsUsingGeneratedIcon; + private Integer mThemeColor; private int mDefaultThemeColor; private DocumentTab mDocumentTab; @@ -532,7 +534,9 @@ public void onPageLoadStarted(Tab tab, String url) { @Override public void onWebContentsSwapped(Tab tab, boolean didStartLoad, boolean didFinishLoad) { if (!didStartLoad) return; - onFaviconReceived(tab.getFavicon()); + mThemeColor = tab.getWebContents().getThemeColor(mDefaultThemeColor); + mIcon = null; + updateTaskDescription(); } @Override @@ -568,7 +572,7 @@ public void onTitleUpdated(Tab tab) { @Override public void onSSLStateUpdated(Tab tab) { - if (hasSecurityWarningOrError(tab)) resetIcon(); + if (hasSecurityWarningOrError(tab)) resetThemeColorAndIcon(); } @Override @@ -587,6 +591,30 @@ public void onLoadStopped(Tab tab) { mTabModel.updateEntry(getIntent(), mDocumentTab); } + @Override + public void onDidChangeThemeColor(int color) { + if (hasSecurityWarningOrError(mDocumentTab)) return; + if (color == Color.TRANSPARENT) color = mDefaultThemeColor; + + // Ignore any transparency value. + color |= 0xFF000000; + + mThemeColor = Integer.valueOf(color); + updateTaskDescription(); + } + + @Override + public void onDidAttachInterstitialPage(Tab tab) { + resetThemeColorAndIcon(); + } + + @Override + public void onDidDetachInterstitialPage(Tab tab) { + mThemeColor = tab.getWebContents().getThemeColor(mDefaultThemeColor); + mIcon = null; + updateTaskDescription(); + } + @Override public void onCrash(Tab tab, boolean sadTabShown) { int currentState = ApplicationStatus.getStateForActivity(DocumentActivity.this); @@ -627,7 +655,8 @@ private boolean hasSecurityWarningOrError(Tab tab) { } } - private void resetIcon() { + private void resetThemeColorAndIcon() { + mThemeColor = null; mIcon = null; updateTaskDescription(); } @@ -799,19 +828,27 @@ private void updateTaskDescription() { updateTaskDescription(label, mIcon); } + protected int getThemeColor() { + if (isIncognito()) { + return mDefaultThemeColor; + } else { + return mThemeColor != null ? mThemeColor.intValue() : mDefaultThemeColor; + } + } + private boolean shouldUseDefaultStatusBarColor() { - return isIncognito() || mThemeColor == mDefaultThemeColor; + return isIncognito() || mThemeColor == null || mThemeColor == mDefaultThemeColor; } protected void updateTaskDescription(String label, Bitmap icon) { - DocumentUtils.updateTaskDescription(this, label, icon, mThemeColor, + int color = getThemeColor(); + DocumentUtils.updateTaskDescription(this, label, icon, color, shouldUseDefaultStatusBarColor()); - } + getToolbarManager().updatePrimaryColor(color); - @Override - protected void onThemeColorUpdate() { - super.onThemeColorUpdate(); - updateTaskDescription(); + ControlContainer controlContainer = + (ControlContainer) findViewById(R.id.control_container); + controlContainer.getToolbarResourceAdapter().invalidate(null); } /** diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tab/ChromeTab.java b/chrome/android/java/src/org/chromium/chrome/browser/tab/ChromeTab.java index 02e9e4ca85ef..12a3c6f75732 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/tab/ChromeTab.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/tab/ChromeTab.java @@ -8,7 +8,6 @@ import android.app.ActivityManager; import android.content.Context; import android.content.Intent; -import android.content.res.Resources; import android.graphics.Rect; import android.media.AudioManager; import android.os.Build; @@ -59,7 +58,6 @@ import org.chromium.chrome.browser.preferences.PrefServiceBridge; import org.chromium.chrome.browser.rlz.RevenueStats; import org.chromium.chrome.browser.search_engines.TemplateUrlService; -import org.chromium.chrome.browser.ssl.ConnectionSecurityLevel; import org.chromium.chrome.browser.tab.TabUma.TabCreationState; import org.chromium.chrome.browser.tabmodel.TabCreatorManager.TabCreator; import org.chromium.chrome.browser.tabmodel.TabModel; @@ -194,8 +192,6 @@ private boolean isParentInAndroidOverview() { private boolean mShouldClearRedirectHistoryForTabClobbering; - private final int mDefaultThemeColor; - /** * Basic constructor. This is hidden, so that explicitly named factory methods are used to * create tabs. initialize() needs to be called afterwards to complete the second level @@ -233,11 +229,6 @@ public void handleMessage(Message msg) { if (mActivity != null && creationState != null) { setTabUma(new TabUma( this, creationState, mActivity.getTabModelSelector().getModel(incognito))); - Resources resources = mActivity.getResources(); - mDefaultThemeColor = incognito ? resources.getColor(R.color.incognito_primary_color) - : resources.getColor(R.color.default_primary_color); - } else { - mDefaultThemeColor = 0; } if (incognito) { @@ -265,7 +256,6 @@ public ChromeTab(int id, boolean incognito) { super(id, incognito, null, null); mActivity = null; mTabRedirectHandler = new TabRedirectHandler(null); - mDefaultThemeColor = 0; } /** @@ -1381,22 +1371,4 @@ public void onWebContentsSwapped(Tab tab, boolean didStartLoad, boolean didFinis public OverrideUrlLoadingResult getLastOverrideUrlLoadingResultForTests() { return mLastOverrideUrlLoadingResult; } - - /** - * @return The theme color based on declared color and the security state. - */ - public int getThemeColor() { - int securityLevel = getSecurityLevel(); - if (securityLevel == ConnectionSecurityLevel.SECURITY_ERROR - || securityLevel == ConnectionSecurityLevel.SECURITY_WARNING - || securityLevel == ConnectionSecurityLevel.SECURITY_POLICY_WARNING) { - return mDefaultThemeColor; - } - if (isShowingInterstitialPage()) return mDefaultThemeColor; - if (isIncognito()) return mDefaultThemeColor; - - int color = getWebContents().getThemeColor(mDefaultThemeColor); - color |= 0xFF000000; - return color; - } }