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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/FullScreenActivity.java

Issue 2807663002: 📺 Move fullscreen web content to a new Activity. (Closed)
Patch Set: Fix test. Created 3 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
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
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
51 private WebContents mWebContents; 49 private WebContents mWebContents;
52 @SuppressWarnings("unused") // Reference needed to prevent GC. 50 @SuppressWarnings("unused") // Reference needed to prevent GC.
53 private WebContentsObserver mWebContentsObserver; 51 private WebContentsObserver mWebContentsObserver;
54 52
55 @Override 53 @Override
56 protected void onNewIntent(Intent intent) { 54 protected void onNewIntent(Intent intent) {
57 super.onNewIntent(intent); 55 super.onNewIntent(intent);
58 setIntent(intent); 56 setIntent(intent);
59 } 57 }
60 58
(...skipping 16 matching lines...) Expand all
77 75
78 /** Creates TabDelegates for opening new Tabs. */ 76 /** Creates TabDelegates for opening new Tabs. */
79 protected TabDelegate createTabDelegate(boolean incognito) { 77 protected TabDelegate createTabDelegate(boolean incognito) {
80 return new TabDelegate(incognito); 78 return new TabDelegate(incognito);
81 } 79 }
82 80
83 @Override 81 @Override
84 public void initializeState() { 82 public void initializeState() {
85 super.initializeState(); 83 super.initializeState();
86 84
87 mTab = createTab(); 85 Tab tab = createTab();
86 getTabModelSelector().setTab(tab);
88 handleTabContentChanged(); 87 handleTabContentChanged();
89 getTabModelSelector().setTab(mTab); 88 tab.show(TabSelectionType.FROM_NEW);
90 mTab.show(TabSelectionType.FROM_NEW);
91 } 89 }
92 90
93 @Override 91 @Override
94 public void finishNativeInitialization() { 92 public void finishNativeInitialization() {
95 ControlContainer controlContainer = (ControlContainer) findViewById(R.id .control_container); 93 ControlContainer controlContainer = (ControlContainer) findViewById(R.id .control_container);
96 initializeCompositorContent(new LayoutManagerDocument(getCompositorViewH older()), 94 initializeCompositorContent(new LayoutManagerDocument(getCompositorViewH older()),
97 (View) controlContainer, (ViewGroup) findViewById(android.R.id.c ontent), 95 (View) controlContainer, (ViewGroup) findViewById(android.R.id.c ontent),
98 controlContainer); 96 controlContainer);
99 97
100 if (getFullscreenManager() != null) getFullscreenManager().setTab(getAct ivityTab()); 98 if (getFullscreenManager() != null) getFullscreenManager().setTab(getAct ivityTab());
101 super.finishNativeInitialization(); 99 super.finishNativeInitialization();
102 } 100 }
103 101
104 @Override 102 @Override
105 protected void initializeToolbar() { } 103 protected void initializeToolbar() { }
106 104
107 @Override 105 @Override
108 public SingleTabModelSelector getTabModelSelector() { 106 public SingleTabModelSelector getTabModelSelector() {
109 return (SingleTabModelSelector) super.getTabModelSelector(); 107 return (SingleTabModelSelector) super.getTabModelSelector();
110 } 108 }
111 109
112 @Override
113 public final Tab getActivityTab() {
114 return mTab;
115 }
116
117 /** 110 /**
118 * Creates the {@link Tab} used by the FullScreenActivity. 111 * Creates the {@link Tab} used by the FullScreenActivity.
119 * If the {@code savedInstanceState} exists, then the user did not intention ally close the app 112 * If the {@code savedInstanceState} exists, then the user did not intention ally close the app
120 * by swiping it away in the recent tasks list. In that case, we try to res tore the tab from 113 * by swiping it away in the recent tasks list. In that case, we try to res tore the tab from
121 * disk. 114 * disk.
122 */ 115 */
123 private Tab createTab() { 116 protected Tab createTab() {
124 Tab tab = null; 117 Tab tab = null;
125 boolean unfreeze = false; 118 boolean unfreeze = false;
126 119
127 int tabId = Tab.INVALID_TAB_ID; 120 int tabId = Tab.INVALID_TAB_ID;
128 String tabUrl = null; 121 String tabUrl = null;
129 if (getSavedInstanceState() != null) { 122 if (getSavedInstanceState() != null) {
130 tabId = getSavedInstanceState().getInt(BUNDLE_TAB_ID, Tab.INVALID_TA B_ID); 123 tabId = getSavedInstanceState().getInt(BUNDLE_TAB_ID, Tab.INVALID_TA B_ID);
131 tabUrl = getSavedInstanceState().getString(BUNDLE_TAB_URL); 124 tabUrl = getSavedInstanceState().getString(BUNDLE_TAB_URL);
132 } 125 }
133 126
134 if (tabId != Tab.INVALID_TAB_ID && tabUrl != null && getActivityDirector y() != null) { 127 if (tabId != Tab.INVALID_TAB_ID && tabUrl != null && getActivityDirector y() != null) {
135 // Restore the tab. 128 // Restore the tab.
136 TabState tabState = TabState.restoreTabState(getActivityDirectory(), tabId); 129 TabState tabState = TabState.restoreTabState(getActivityDirectory(), tabId);
137 tab = new Tab(tabId, Tab.INVALID_TAB_ID, false, this, getWindowAndro id(), 130 tab = new Tab(tabId, Tab.INVALID_TAB_ID, false, this, getWindowAndro id(),
138 TabLaunchType.FROM_RESTORE, 131 TabLaunchType.FROM_RESTORE,
139 TabCreationState.FROZEN_ON_RESTORE, tabState); 132 TabCreationState.FROZEN_ON_RESTORE, tabState);
140 unfreeze = true; 133 unfreeze = true;
141 } 134 }
142 135
143 if (tab == null) { 136 if (tab == null) {
144 tab = new Tab(Tab.INVALID_TAB_ID, Tab.INVALID_TAB_ID, false, this, g etWindowAndroid(), 137 tab = new Tab(Tab.INVALID_TAB_ID, Tab.INVALID_TAB_ID, false, this, g etWindowAndroid(),
145 TabLaunchType.FROM_CHROME_UI, null, null); 138 TabLaunchType.FROM_CHROME_UI, null, null);
146 } 139 }
147 140
148 tab.initialize(null, getTabContentManager(), createTabDelegateFactory(), false, unfreeze); 141 tab.initialize(null, getTabContentManager(), createTabDelegateFactory(), false, unfreeze);
149 tab.addObserver(new EmptyTabObserver() { 142 tab.addObserver(new EmptyTabObserver() {
150 @Override 143 @Override
151 public void onContentChanged(Tab tab) { 144 public void onContentChanged(Tab tab) {
152 assert tab == mTab; 145 assert tab == getActivityTab();
153 handleTabContentChanged(); 146 handleTabContentChanged();
154 } 147 }
155 }); 148 });
156 return tab; 149 return tab;
157 } 150 }
158 151
159 private void handleTabContentChanged() { 152 private void handleTabContentChanged() {
160 assert mTab != null; 153 final Tab tab = getActivityTab();
154 assert tab != null;
161 155
162 WebContents webContents = mTab.getWebContents(); 156 WebContents webContents = tab.getWebContents();
163 if (mWebContents == webContents) return; 157 if (mWebContents == webContents) return;
164 158
165 // Clean up any old references to the previous WebContents. 159 // Clean up any old references to the previous WebContents.
166 if (mWebContentsObserver != null) { 160 if (mWebContentsObserver != null) {
167 mWebContentsObserver.destroy(); 161 mWebContentsObserver.destroy();
168 mWebContentsObserver = null; 162 mWebContentsObserver = null;
169 } 163 }
170 164
171 mWebContents = webContents; 165 mWebContents = webContents;
172 if (mWebContents == null) return; 166 if (mWebContents == null) return;
173 167
174 ContentViewCore.fromWebContents(webContents).setFullscreenRequiredForOri entationLock(false); 168 ContentViewCore.fromWebContents(webContents).setFullscreenRequiredForOri entationLock(false);
175 mWebContentsObserver = new WebContentsObserver(webContents) { 169 mWebContentsObserver = new WebContentsObserver(webContents) {
176 @Override 170 @Override
177 public void didFinishNavigation(String url, boolean isInMainFrame, b oolean isErrorPage, 171 public void didFinishNavigation(String url, boolean isInMainFrame, b oolean isErrorPage,
178 boolean hasCommitted, boolean isSameDocument, boolean isFrag mentNavigation, 172 boolean hasCommitted, boolean isSameDocument, boolean isFrag mentNavigation,
179 Integer pageTransition, int errorCode, String errorDescripti on, 173 Integer pageTransition, int errorCode, String errorDescripti on,
180 int httpStatusCode) { 174 int httpStatusCode) {
181 if (hasCommitted && isInMainFrame) { 175 if (hasCommitted && isInMainFrame) {
182 // Notify the renderer to permanently hide the top controls since they do 176 // Notify the renderer to permanently hide the top controls since they do
183 // not apply to fullscreen content views. 177 // not apply to fullscreen content views.
184 mTab.updateBrowserControlsState( 178 tab.updateBrowserControlsState(tab.getBrowserControlsStateCo nstraints(), true);
185 mTab.getBrowserControlsStateConstraints(), true);
186 } 179 }
187 } 180 }
188 }; 181 };
189 } 182 }
190 183
191 /** 184 /**
192 * @return {@link TabDelegateFactory} to be used while creating the associat ed {@link Tab}. 185 * @return {@link TabDelegateFactory} to be used while creating the associat ed {@link Tab}.
193 */ 186 */
194 protected TabDelegateFactory createTabDelegateFactory() { 187 protected TabDelegateFactory createTabDelegateFactory() {
195 return new FullScreenDelegateFactory(); 188 return new FullScreenDelegateFactory();
196 } 189 }
197 190
198 /** 191 /**
199 * @return {@link File} pointing at a directory specific for this class. 192 * @return {@link File} pointing at a directory specific for this class.
200 */ 193 */
201 protected File getActivityDirectory() { 194 protected File getActivityDirectory() {
202 return null; 195 return null;
203 } 196 }
204 197
205 @Override 198 @Override
206 protected boolean handleBackPressed() { 199 protected boolean handleBackPressed() {
207 if (mTab == null) return false; 200 Tab tab = getActivityTab();
201 if (tab == null) return false;
208 202
209 if (exitFullscreenIfShowing()) return true; 203 if (exitFullscreenIfShowing()) return true;
210 204
211 if (mTab.canGoBack()) { 205 if (tab.canGoBack()) {
212 mTab.goBack(); 206 tab.goBack();
213 return true; 207 return true;
214 } 208 }
215 return false; 209 return false;
216 } 210 }
217 211
218 @Override 212 @Override
219 public void onCheckForUpdate(boolean updateAvailable) { 213 public void onCheckForUpdate(boolean updateAvailable) {
220 } 214 }
221 } 215 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/tabmodel/SingleTabModel.java ('k') | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698