Skip to content

Commit

Permalink
Revert of Add getThemeColor to Tab and add plumbing for ChromeActivit…
Browse files Browse the repository at this point in the history
…es. (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}

[email protected],[email protected]
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=507340

Review URL: https://codereview.chromium.org/1260523004

Cr-Commit-Position: refs/heads/master@{#341332}
  • Loading branch information
Steelskin authored and Anton Obzhirov committed Aug 7, 2015
1 parent fda680c commit 77d0820
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -212,8 +211,6 @@ public AppMenuHandler get(Activity activity,

private OnPreDrawListener mFirstDrawListener;

protected int mThemeColor;

private final Locale mCurrentLocale = Locale.getDefault();

private AssistStatusHandler mAssistStatusHandler;
Expand Down Expand Up @@ -501,42 +498,13 @@ 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) {
mAssistStatusHandler.setTabModelSelector(tabModelSelector);
}
}

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();
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -568,7 +572,7 @@ public void onTitleUpdated(Tab tab) {

@Override
public void onSSLStateUpdated(Tab tab) {
if (hasSecurityWarningOrError(tab)) resetIcon();
if (hasSecurityWarningOrError(tab)) resetThemeColorAndIcon();
}

@Override
Expand All @@ -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);
Expand Down Expand Up @@ -627,7 +655,8 @@ private boolean hasSecurityWarningOrError(Tab tab) {
}
}

private void resetIcon() {
private void resetThemeColorAndIcon() {
mThemeColor = null;
mIcon = null;
updateTaskDescription();
}
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -265,7 +256,6 @@ public ChromeTab(int id, boolean incognito) {
super(id, incognito, null, null);
mActivity = null;
mTabRedirectHandler = new TabRedirectHandler(null);
mDefaultThemeColor = 0;
}

/**
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 77d0820

Please sign in to comment.