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

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/toolbar/ToolbarModelImpl.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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.toolbar;
6
7 import android.content.Context;
8
9 import com.google.android.apps.chrome.R;
10
11 import org.chromium.base.ApplicationStatus;
12 import org.chromium.chrome.browser.Tab;
13 import org.chromium.chrome.browser.ntp.NewTabPage;
14 import org.chromium.chrome.browser.tab.BackgroundContentViewHelper;
15 import org.chromium.chrome.browser.tab.ChromeTab;
16 import org.chromium.chrome.browser.toolbar.ToolbarModel.ToolbarModelDelegate;
17 import org.chromium.chrome.browser.util.FeatureUtilities;
18 import org.chromium.content_public.browser.WebContents;
19
20 /**
21 * Contains the data and state for the toolbar.
22 */
23 class ToolbarModelImpl extends ToolbarModel implements ToolbarDataProvider, Tool barModelDelegate {
24
25 private ChromeTab mTab;
26 private boolean mIsIncognito;
27 private int mLoadProgress;
28 private int mPrimaryColor;
29 private boolean mIsUsingBrandColor;
30
31 /**
32 * Handle any initialization that must occur after native has been initializ ed.
33 */
34 public void initializeWithNative() {
35 initialize(this);
36 }
37
38 @Override
39 public WebContents getActiveWebContents() {
40 ChromeTab tab = getTab();
41 if (tab == null) return null;
42 BackgroundContentViewHelper backgroundViewHelper = tab.getBackgroundCont entViewHelper();
43 boolean hasPendingBackgroundPage =
44 backgroundViewHelper != null && backgroundViewHelper.hasPendingB ackgroundPage();
45 if (hasPendingBackgroundPage) {
46 return backgroundViewHelper.getContentViewCore().getWebContents();
47 }
48 return tab.getWebContents();
49 }
50
51 /**
52 * Sets the tab that contains the information to be displayed in the toolbar .
53 * @param tab The tab associated currently with the toolbar.
54 * @param isIncognito Whether the incognito model is currently selected, whi ch must match the
55 * passed in tab if non-null.
56 */
57 public void setTab(ChromeTab tab, boolean isIncognito) {
58 mTab = tab;
59 if (mTab != null) {
60 assert mTab.isIncognito() == isIncognito;
61 }
62 mIsIncognito = isIncognito;
63 }
64
65 @Override
66 public ChromeTab getTab() {
67 // TODO(dtrainor, tedchoc): Remove the isInitialized() check when we no longer wait for
68 // TAB_CLOSED events to remove this tab. Otherwise there is a chance we use this tab after
69 // {@link ChromeTab#destroy()} is called.
70 return (mTab == null || !mTab.isInitialized()) ? null : mTab;
71 }
72
73 @Override
74 public NewTabPage getNewTabPageForCurrentTab() {
75 Tab currentTab = getTab();
76 if (currentTab != null && currentTab.getNativePage() instanceof NewTabPa ge) {
77 return (NewTabPage) currentTab.getNativePage();
78 }
79 return null;
80 }
81
82 @Override
83 public boolean isIncognito() {
84 return mIsIncognito;
85 }
86
87 /**
88 * Set the load progress for the current tab.
89 * @param progress The loading progress for the tab.
90 */
91 public void setLoadProgress(int progress) {
92 assert progress >= 0;
93 assert progress <= 100;
94
95 mLoadProgress = progress;
96 }
97
98 @Override
99 public int getLoadProgress() {
100 return mLoadProgress;
101 }
102
103 /**
104 * Sets the primary color and changes the state for isUsingBrandColor.
105 * @param color The primary color for the current tab.
106 */
107 public void setPrimaryColor(int color) {
108 mPrimaryColor = color;
109 Context context = ApplicationStatus.getApplicationContext();
110 mIsUsingBrandColor = FeatureUtilities.isDocumentMode(context)
111 && !isIncognito()
112 && mPrimaryColor != context.getResources().getColor(R.color.defa ult_primary_color)
113 && getTab() != null && !getTab().isNativePage();
114 }
115
116 @Override
117 public int getPrimaryColor() {
118 return mPrimaryColor;
119 }
120
121 @Override
122 public boolean isUsingBrandColor() {
123 return mIsUsingBrandColor;
124 }
125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698