summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryusufo <yusufo@chromium.org>2015-10-30 14:21:48 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-30 21:22:41 +0000
commitd596824f94df067d3c2da4d8d09bfc758837846c (patch)
tree1b58273cfa0ba5ab0470fbf7695e161df1120f39
parent61b4efdc0d24cc2278eebd60df5ec4f538ea813c (diff)
downloadchromium_src-d596824f94df067d3c2da4d8d09bfc758837846c.zip
chromium_src-d596824f94df067d3c2da4d8d09bfc758837846c.tar.gz
chromium_src-d596824f94df067d3c2da4d8d09bfc758837846c.tar.bz2
Start using a themed application context for constructing views in Tab
*Changes the inner field for application context to a ContextThemeWrapper wrapped with the corresponding theme for the activity. *Uses the above wrapper inside all the places it can be used including view construction for layouts that belong to the tab BUG=546737 Review URL: https://codereview.chromium.org/1416173006 Cr-Commit-Position: refs/heads/master@{#357197}
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchTabHelper.java15
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java38
-rw-r--r--printing/android/java/src/org/chromium/printing/PrintManagerDelegateImpl.java5
3 files changed, 33 insertions, 25 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchTabHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchTabHelper.java
index 0947286..4081bf2 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchTabHelper.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchTabHelper.java
@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.contextualsearch;
+import android.app.Activity;
+
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChangeReason;
@@ -43,6 +45,8 @@ public class ContextualSearchTabHelper extends EmptyTabObserver {
private long mNativeHelper = 0;
+ private final Tab mTab;
+
/**
* Creates a contextual search tab helper for the given tab.
* @param tab The tab whose contextual search actions will be handled by this helper.
@@ -52,6 +56,7 @@ public class ContextualSearchTabHelper extends EmptyTabObserver {
}
private ContextualSearchTabHelper(Tab tab) {
+ mTab = tab;
tab.addObserver(this);
}
@@ -161,7 +166,7 @@ public class ContextualSearchTabHelper extends EmptyTabObserver {
/**
* @return whether Contextual Search is enabled and active in this tab.
*/
- private static boolean isContextualSearchActive(ContentViewCore cvc) {
+ private boolean isContextualSearchActive(ContentViewCore cvc) {
return !cvc.getWebContents().isIncognito() && getContextualSearchManager(cvc) != null
&& !PrefServiceBridge.getInstance().isContextualSearchDisabled()
&& TemplateUrlService.getInstance().isDefaultSearchEngineGoogle()
@@ -175,10 +180,10 @@ public class ContextualSearchTabHelper extends EmptyTabObserver {
/**
* @return the Contextual Search manager.
*/
- private static ContextualSearchManager getContextualSearchManager(ContentViewCore cvc) {
- // TODO(yfriedman): Decouple this from the activity.
- if (cvc.getContext() instanceof ChromeActivity) {
- return ((ChromeActivity) cvc.getContext()).getContextualSearchManager();
+ private ContextualSearchManager getContextualSearchManager(ContentViewCore cvc) {
+ Activity activity = mTab.getWindowAndroid().getActivity().get();
+ if (activity instanceof ChromeActivity) {
+ return ((ChromeActivity) activity).getContextualSearchManager();
}
return null;
}
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java b/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java
index 2edc697..fed11c8 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tab/Tab.java
@@ -15,6 +15,7 @@ import android.os.Message;
import android.provider.Browser;
import android.text.TextUtils;
import android.util.Log;
+import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
@@ -135,7 +136,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
/**
* The {@link Activity} used to create {@link View}s and other Android components. Unlike
- * {@link #mApplicationContext}, this is not publicly exposed to help prevent leaking the
+ * {@link #mThemedApplicationContext}, this is not publicly exposed to help prevent leaking the
* {@link Activity}.
*/
protected final ChromeActivity mActivity;
@@ -152,7 +153,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
* An Application {@link Context}. Unlike {@link #mActivity}, this is the only one that is
* publicly exposed to help prevent leaking the {@link Activity}.
*/
- private final Context mApplicationContext;
+ private final Context mThemedApplicationContext;
/** Gives {@link Tab} a way to interact with the Android window. */
private final WindowAndroid mWindowAndroid;
@@ -543,11 +544,12 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
mParentId = parentId;
mIncognito = incognito;
mActivity = activity;
- mApplicationContext = activity != null ? activity.getApplicationContext() : null;
+ mThemedApplicationContext = activity != null ? new ContextThemeWrapper(
+ activity.getApplicationContext(), ChromeActivity.getThemeId()) : null;
mWindowAndroid = window;
mLaunchType = type;
- if (mActivity != null) {
- Resources resources = mActivity.getResources();
+ if (mThemedApplicationContext != null) {
+ Resources resources = mThemedApplicationContext.getResources();
mIdealFaviconSize = resources.getDimensionPixelSize(R.dimen.default_favicon_size);
mDefaultThemeColor = mIncognito
? ApiCompatibilityUtils.getColor(resources, R.color.incognito_primary_color)
@@ -805,7 +807,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
* @return The application {@link Context} associated with this tab.
*/
protected Context getApplicationContext() {
- return mApplicationContext;
+ return mThemedApplicationContext.getApplicationContext();
}
/**
@@ -1480,9 +1482,9 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
* {@link ContentViewCore}.
*/
protected void initContentViewCore(WebContents webContents) {
- ContentViewCore cvc = new ContentViewCore(mActivity);
- ContentView cv = ContentView.createContentView(mActivity, cvc);
- cv.setContentDescription(mActivity.getResources().getString(
+ ContentViewCore cvc = new ContentViewCore(mThemedApplicationContext);
+ ContentView cv = ContentView.createContentView(mThemedApplicationContext, cvc);
+ cv.setContentDescription(mThemedApplicationContext.getResources().getString(
R.string.accessibility_content_view));
cvc.initialize(cv, cv, webContents, getWindowAndroid());
setContentViewCore(cvc);
@@ -1518,7 +1520,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
assert false;
mContentViewParent.removeAllViews();
}
- mContentViewParent = new FrameLayout(mActivity);
+ mContentViewParent = new FrameLayout(mThemedApplicationContext);
mContentViewParent.addView(cvc.getContainerView(),
new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
@@ -1542,14 +1544,14 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
if (mInfoBarContainer == null) {
// The InfoBarContainer needs to be created after the ContentView has been natively
// initialized.
- mInfoBarContainer =
- new InfoBarContainer(mActivity, getId(), mContentViewParent, this);
+ mInfoBarContainer = new InfoBarContainer(
+ mThemedApplicationContext, getId(), mContentViewParent, this);
} else {
mInfoBarContainer.onParentViewChanged(getId(), mContentViewParent);
}
mInfoBarContainer.setContentViewCore(mContentViewCore);
- mSwipeRefreshHandler = new SwipeRefreshHandler(mActivity);
+ mSwipeRefreshHandler = new SwipeRefreshHandler(mThemedApplicationContext);
mSwipeRefreshHandler.setContentViewCore(mContentViewCore);
for (TabObserver observer : mObservers) observer.onContentChanged(this);
@@ -1559,7 +1561,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
// web views.
mContentViewCore.setShouldSetAccessibilityFocusOnPageLoad(true);
- mDownloadDelegate = new ChromeDownloadDelegate(mActivity,
+ mDownloadDelegate = new ChromeDownloadDelegate(mThemedApplicationContext,
mActivity.getTabModelSelector(), this);
cvc.setDownloadDelegate(mDownloadDelegate);
@@ -1641,7 +1643,7 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
// Make sure we are not adding the "Aw, snap" view over an existing one.
assert mSadTabView == null;
mSadTabView = SadTabViewFactory.createSadTabView(
- mActivity, suggestionAction, reloadButtonAction);
+ mThemedApplicationContext, suggestionAction, reloadButtonAction);
// Show the sad tab inside ContentView.
getContentViewCore().getContainerView().addView(
@@ -2138,9 +2140,9 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener,
@CalledByNative
public void swapWebContents(
WebContents webContents, boolean didStartLoad, boolean didFinishLoad) {
- ContentViewCore cvc = new ContentViewCore(mActivity);
- ContentView cv = ContentView.createContentView(mActivity, cvc);
- cv.setContentDescription(mActivity.getResources().getString(
+ ContentViewCore cvc = new ContentViewCore(mThemedApplicationContext);
+ ContentView cv = ContentView.createContentView(mThemedApplicationContext, cvc);
+ cv.setContentDescription(mThemedApplicationContext.getResources().getString(
R.string.accessibility_content_view));
cvc.initialize(cv, cv, webContents, getWindowAndroid());
swapContentViewCore(cvc, false, didStartLoad, didFinishLoad);
diff --git a/printing/android/java/src/org/chromium/printing/PrintManagerDelegateImpl.java b/printing/android/java/src/org/chromium/printing/PrintManagerDelegateImpl.java
index 7cdaeae..15a15df 100644
--- a/printing/android/java/src/org/chromium/printing/PrintManagerDelegateImpl.java
+++ b/printing/android/java/src/org/chromium/printing/PrintManagerDelegateImpl.java
@@ -5,6 +5,7 @@
package org.chromium.printing;
import android.annotation.TargetApi;
+import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.print.PrintAttributes;
@@ -27,8 +28,8 @@ public class PrintManagerDelegateImpl implements PrintManagerDelegate {
private static final String TAG = "cr.printing";
private final PrintManager mPrintManager;
- public PrintManagerDelegateImpl(Context context) {
- mPrintManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
+ public PrintManagerDelegateImpl(Activity activity) {
+ mPrintManager = (PrintManager) activity.getSystemService(Context.PRINT_SERVICE);
}
@Override