OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.webapps; | 5 package org.chromium.chrome.browser.webapps; |
6 | 6 |
7 import android.content.Intent; | 7 import android.content.Intent; |
8 import android.util.Pair; | 8 import android.util.Pair; |
9 import android.view.View; | 9 import android.view.View; |
10 import android.view.ViewGroup; | 10 import android.view.ViewGroup; |
(...skipping 28 matching lines...) Expand all Loading... |
39 * Activity would be webapps and streaming media activities - anything where use
r interaction with | 39 * Activity would be webapps and streaming media activities - anything where use
r interaction with |
40 * the regular browser's UI is either unnecessary or undesirable. | 40 * the regular browser's UI is either unnecessary or undesirable. |
41 * Subclasses can override {@link #createUI()} if they need something more exoti
c. | 41 * Subclasses can override {@link #createUI()} if they need something more exoti
c. |
42 */ | 42 */ |
43 @SuppressFBWarnings("URF_UNREAD_FIELD") | 43 @SuppressFBWarnings("URF_UNREAD_FIELD") |
44 public abstract class FullScreenActivity extends ChromeActivity { | 44 public abstract class FullScreenActivity extends ChromeActivity { |
45 protected static final String BUNDLE_TAB_ID = "tabId"; | 45 protected static final String BUNDLE_TAB_ID = "tabId"; |
46 protected static final String BUNDLE_TAB_URL = "tabUrl"; | 46 protected static final String BUNDLE_TAB_URL = "tabUrl"; |
47 private static final String TAG = "FullScreenActivity"; | 47 private static final String TAG = "FullScreenActivity"; |
48 | 48 |
| 49 private Tab mTab; |
| 50 |
49 private WebContents mWebContents; | 51 private WebContents mWebContents; |
50 @SuppressWarnings("unused") // Reference needed to prevent GC. | 52 @SuppressWarnings("unused") // Reference needed to prevent GC. |
51 private WebContentsObserver mWebContentsObserver; | 53 private WebContentsObserver mWebContentsObserver; |
52 | 54 |
53 @Override | 55 @Override |
54 protected void onNewIntent(Intent intent) { | 56 protected void onNewIntent(Intent intent) { |
55 super.onNewIntent(intent); | 57 super.onNewIntent(intent); |
56 setIntent(intent); | 58 setIntent(intent); |
57 } | 59 } |
58 | 60 |
(...skipping 16 matching lines...) Expand all Loading... |
75 | 77 |
76 /** Creates TabDelegates for opening new Tabs. */ | 78 /** Creates TabDelegates for opening new Tabs. */ |
77 protected TabDelegate createTabDelegate(boolean incognito) { | 79 protected TabDelegate createTabDelegate(boolean incognito) { |
78 return new TabDelegate(incognito); | 80 return new TabDelegate(incognito); |
79 } | 81 } |
80 | 82 |
81 @Override | 83 @Override |
82 public void initializeState() { | 84 public void initializeState() { |
83 super.initializeState(); | 85 super.initializeState(); |
84 | 86 |
85 Tab tab = createTab(); | 87 mTab = createTab(); |
86 getTabModelSelector().setTab(tab); | |
87 handleTabContentChanged(); | 88 handleTabContentChanged(); |
88 tab.show(TabSelectionType.FROM_NEW); | 89 getTabModelSelector().setTab(mTab); |
| 90 mTab.show(TabSelectionType.FROM_NEW); |
89 } | 91 } |
90 | 92 |
91 @Override | 93 @Override |
92 public void finishNativeInitialization() { | 94 public void finishNativeInitialization() { |
93 ControlContainer controlContainer = (ControlContainer) findViewById(R.id
.control_container); | 95 ControlContainer controlContainer = (ControlContainer) findViewById(R.id
.control_container); |
94 initializeCompositorContent(new LayoutManagerDocument(getCompositorViewH
older()), | 96 initializeCompositorContent(new LayoutManagerDocument(getCompositorViewH
older()), |
95 (View) controlContainer, (ViewGroup) findViewById(android.R.id.c
ontent), | 97 (View) controlContainer, (ViewGroup) findViewById(android.R.id.c
ontent), |
96 controlContainer); | 98 controlContainer); |
97 | 99 |
98 if (getFullscreenManager() != null) getFullscreenManager().setTab(getAct
ivityTab()); | 100 if (getFullscreenManager() != null) getFullscreenManager().setTab(getAct
ivityTab()); |
99 super.finishNativeInitialization(); | 101 super.finishNativeInitialization(); |
100 } | 102 } |
101 | 103 |
102 @Override | 104 @Override |
103 protected void initializeToolbar() { } | 105 protected void initializeToolbar() { } |
104 | 106 |
105 @Override | 107 @Override |
106 public SingleTabModelSelector getTabModelSelector() { | 108 public SingleTabModelSelector getTabModelSelector() { |
107 return (SingleTabModelSelector) super.getTabModelSelector(); | 109 return (SingleTabModelSelector) super.getTabModelSelector(); |
108 } | 110 } |
109 | 111 |
| 112 @Override |
| 113 public final Tab getActivityTab() { |
| 114 return mTab; |
| 115 } |
| 116 |
110 /** | 117 /** |
111 * Creates the {@link Tab} used by the FullScreenActivity. | 118 * Creates the {@link Tab} used by the FullScreenActivity. |
112 * If the {@code savedInstanceState} exists, then the user did not intention
ally close the app | 119 * If the {@code savedInstanceState} exists, then the user did not intention
ally close the app |
113 * by swiping it away in the recent tasks list. In that case, we try to res
tore the tab from | 120 * by swiping it away in the recent tasks list. In that case, we try to res
tore the tab from |
114 * disk. | 121 * disk. |
115 */ | 122 */ |
116 protected Tab createTab() { | 123 private Tab createTab() { |
117 Tab tab = null; | 124 Tab tab = null; |
118 boolean unfreeze = false; | 125 boolean unfreeze = false; |
119 | 126 |
120 int tabId = Tab.INVALID_TAB_ID; | 127 int tabId = Tab.INVALID_TAB_ID; |
121 String tabUrl = null; | 128 String tabUrl = null; |
122 if (getSavedInstanceState() != null) { | 129 if (getSavedInstanceState() != null) { |
123 tabId = getSavedInstanceState().getInt(BUNDLE_TAB_ID, Tab.INVALID_TA
B_ID); | 130 tabId = getSavedInstanceState().getInt(BUNDLE_TAB_ID, Tab.INVALID_TA
B_ID); |
124 tabUrl = getSavedInstanceState().getString(BUNDLE_TAB_URL); | 131 tabUrl = getSavedInstanceState().getString(BUNDLE_TAB_URL); |
125 } | 132 } |
126 | 133 |
127 if (tabId != Tab.INVALID_TAB_ID && tabUrl != null && getActivityDirector
y() != null) { | 134 if (tabId != Tab.INVALID_TAB_ID && tabUrl != null && getActivityDirector
y() != null) { |
128 // Restore the tab. | 135 // Restore the tab. |
129 TabState tabState = TabState.restoreTabState(getActivityDirectory(),
tabId); | 136 TabState tabState = TabState.restoreTabState(getActivityDirectory(),
tabId); |
130 tab = new Tab(tabId, Tab.INVALID_TAB_ID, false, this, getWindowAndro
id(), | 137 tab = new Tab(tabId, Tab.INVALID_TAB_ID, false, this, getWindowAndro
id(), |
131 TabLaunchType.FROM_RESTORE, | 138 TabLaunchType.FROM_RESTORE, |
132 TabCreationState.FROZEN_ON_RESTORE, tabState); | 139 TabCreationState.FROZEN_ON_RESTORE, tabState); |
133 unfreeze = true; | 140 unfreeze = true; |
134 } | 141 } |
135 | 142 |
136 if (tab == null) { | 143 if (tab == null) { |
137 tab = new Tab(Tab.INVALID_TAB_ID, Tab.INVALID_TAB_ID, false, this, g
etWindowAndroid(), | 144 tab = new Tab(Tab.INVALID_TAB_ID, Tab.INVALID_TAB_ID, false, this, g
etWindowAndroid(), |
138 TabLaunchType.FROM_CHROME_UI, null, null); | 145 TabLaunchType.FROM_CHROME_UI, null, null); |
139 } | 146 } |
140 | 147 |
141 tab.initialize(null, getTabContentManager(), createTabDelegateFactory(),
false, unfreeze); | 148 tab.initialize(null, getTabContentManager(), createTabDelegateFactory(),
false, unfreeze); |
142 tab.addObserver(new EmptyTabObserver() { | 149 tab.addObserver(new EmptyTabObserver() { |
143 @Override | 150 @Override |
144 public void onContentChanged(Tab tab) { | 151 public void onContentChanged(Tab tab) { |
145 assert tab == getActivityTab(); | 152 assert tab == mTab; |
146 handleTabContentChanged(); | 153 handleTabContentChanged(); |
147 } | 154 } |
148 }); | 155 }); |
149 return tab; | 156 return tab; |
150 } | 157 } |
151 | 158 |
152 private void handleTabContentChanged() { | 159 private void handleTabContentChanged() { |
153 final Tab tab = getActivityTab(); | 160 assert mTab != null; |
154 assert tab != null; | |
155 | 161 |
156 WebContents webContents = tab.getWebContents(); | 162 WebContents webContents = mTab.getWebContents(); |
157 if (mWebContents == webContents) return; | 163 if (mWebContents == webContents) return; |
158 | 164 |
159 // Clean up any old references to the previous WebContents. | 165 // Clean up any old references to the previous WebContents. |
160 if (mWebContentsObserver != null) { | 166 if (mWebContentsObserver != null) { |
161 mWebContentsObserver.destroy(); | 167 mWebContentsObserver.destroy(); |
162 mWebContentsObserver = null; | 168 mWebContentsObserver = null; |
163 } | 169 } |
164 | 170 |
165 mWebContents = webContents; | 171 mWebContents = webContents; |
166 if (mWebContents == null) return; | 172 if (mWebContents == null) return; |
167 | 173 |
168 ContentViewCore.fromWebContents(webContents).setFullscreenRequiredForOri
entationLock(false); | 174 ContentViewCore.fromWebContents(webContents).setFullscreenRequiredForOri
entationLock(false); |
169 mWebContentsObserver = new WebContentsObserver(webContents) { | 175 mWebContentsObserver = new WebContentsObserver(webContents) { |
170 @Override | 176 @Override |
171 public void didFinishNavigation(String url, boolean isInMainFrame, b
oolean isErrorPage, | 177 public void didFinishNavigation(String url, boolean isInMainFrame, b
oolean isErrorPage, |
172 boolean hasCommitted, boolean isSameDocument, boolean isFrag
mentNavigation, | 178 boolean hasCommitted, boolean isSameDocument, boolean isFrag
mentNavigation, |
173 Integer pageTransition, int errorCode, String errorDescripti
on, | 179 Integer pageTransition, int errorCode, String errorDescripti
on, |
174 int httpStatusCode) { | 180 int httpStatusCode) { |
175 if (hasCommitted && isInMainFrame) { | 181 if (hasCommitted && isInMainFrame) { |
176 // Notify the renderer to permanently hide the top controls
since they do | 182 // Notify the renderer to permanently hide the top controls
since they do |
177 // not apply to fullscreen content views. | 183 // not apply to fullscreen content views. |
178 tab.updateBrowserControlsState(tab.getBrowserControlsStateCo
nstraints(), true); | 184 mTab.updateBrowserControlsState( |
| 185 mTab.getBrowserControlsStateConstraints(), true); |
179 } | 186 } |
180 } | 187 } |
181 }; | 188 }; |
182 } | 189 } |
183 | 190 |
184 /** | 191 /** |
185 * @return {@link TabDelegateFactory} to be used while creating the associat
ed {@link Tab}. | 192 * @return {@link TabDelegateFactory} to be used while creating the associat
ed {@link Tab}. |
186 */ | 193 */ |
187 protected TabDelegateFactory createTabDelegateFactory() { | 194 protected TabDelegateFactory createTabDelegateFactory() { |
188 return new FullScreenDelegateFactory(); | 195 return new FullScreenDelegateFactory(); |
189 } | 196 } |
190 | 197 |
191 /** | 198 /** |
192 * @return {@link File} pointing at a directory specific for this class. | 199 * @return {@link File} pointing at a directory specific for this class. |
193 */ | 200 */ |
194 protected File getActivityDirectory() { | 201 protected File getActivityDirectory() { |
195 return null; | 202 return null; |
196 } | 203 } |
197 | 204 |
198 @Override | 205 @Override |
199 protected boolean handleBackPressed() { | 206 protected boolean handleBackPressed() { |
200 Tab tab = getActivityTab(); | 207 if (mTab == null) return false; |
201 if (tab == null) return false; | |
202 | 208 |
203 if (exitFullscreenIfShowing()) return true; | 209 if (exitFullscreenIfShowing()) return true; |
204 | 210 |
205 if (tab.canGoBack()) { | 211 if (mTab.canGoBack()) { |
206 tab.goBack(); | 212 mTab.goBack(); |
207 return true; | 213 return true; |
208 } | 214 } |
209 return false; | 215 return false; |
210 } | 216 } |
211 | 217 |
212 @Override | 218 @Override |
213 public void onCheckForUpdate(boolean updateAvailable) { | 219 public void onCheckForUpdate(boolean updateAvailable) { |
214 } | 220 } |
215 } | 221 } |
OLD | NEW |