| 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.view.View; | 8 import android.view.View; |
| 9 import android.view.ViewGroup; | 9 import android.view.ViewGroup; |
| 10 | 10 |
| 11 import org.chromium.base.Log; | |
| 12 import org.chromium.base.StreamUtil; | |
| 13 import org.chromium.base.annotations.SuppressFBWarnings; | 11 import org.chromium.base.annotations.SuppressFBWarnings; |
| 14 import org.chromium.chrome.R; | 12 import org.chromium.chrome.R; |
| 15 import org.chromium.chrome.browser.ChromeActivity; | 13 import org.chromium.chrome.browser.ChromeActivity; |
| 16 import org.chromium.chrome.browser.TabState; | 14 import org.chromium.chrome.browser.TabState; |
| 17 import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument; | 15 import org.chromium.chrome.browser.compositor.layouts.LayoutManagerDocument; |
| 18 import org.chromium.chrome.browser.tab.Tab; | 16 import org.chromium.chrome.browser.tab.Tab; |
| 19 import org.chromium.chrome.browser.tab.TabDelegateFactory; | 17 import org.chromium.chrome.browser.tab.TabDelegateFactory; |
| 20 import org.chromium.chrome.browser.tab.TabUma.TabCreationState; | 18 import org.chromium.chrome.browser.tab.TabUma.TabCreationState; |
| 21 import org.chromium.chrome.browser.tabmodel.SingleTabModelSelector; | 19 import org.chromium.chrome.browser.tabmodel.SingleTabModelSelector; |
| 22 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 20 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| 23 import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; | 21 import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; |
| 24 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; | 22 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; |
| 25 import org.chromium.chrome.browser.widget.ControlContainer; | 23 import org.chromium.chrome.browser.widget.ControlContainer; |
| 26 import org.chromium.content_public.browser.LoadUrlParams; | 24 import org.chromium.content_public.browser.LoadUrlParams; |
| 27 import org.chromium.content_public.browser.WebContentsObserver; | 25 import org.chromium.content_public.browser.WebContentsObserver; |
| 28 | 26 |
| 29 import java.io.File; | 27 import java.io.File; |
| 30 import java.io.FileInputStream; | |
| 31 import java.io.FileNotFoundException; | |
| 32 import java.io.IOException; | |
| 33 | 28 |
| 34 /** | 29 /** |
| 35 * Base class for task-focused activities that need to display web content in a
nearly UI-less | 30 * Base class for task-focused activities that need to display web content in a
nearly UI-less |
| 36 * Chrome (InfoBars still appear). | 31 * Chrome (InfoBars still appear). |
| 37 * | 32 * |
| 38 * This is vaguely analogous to a WebView, but in Chrome. Example applications t
hat might use this | 33 * This is vaguely analogous to a WebView, but in Chrome. Example applications t
hat might use this |
| 39 * Activity would be webapps and streaming media activities - anything where use
r interaction with | 34 * 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. | 35 * the regular browser's UI is either unnecessary or undesirable. |
| 41 * Subclasses can override {@link #createUI()} if they need something more exoti
c. | 36 * Subclasses can override {@link #createUI()} if they need something more exoti
c. |
| 42 */ | 37 */ |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 boolean unfreeze = false; | 109 boolean unfreeze = false; |
| 115 | 110 |
| 116 int tabId = Tab.INVALID_TAB_ID; | 111 int tabId = Tab.INVALID_TAB_ID; |
| 117 String tabUrl = null; | 112 String tabUrl = null; |
| 118 if (getSavedInstanceState() != null) { | 113 if (getSavedInstanceState() != null) { |
| 119 tabId = getSavedInstanceState().getInt(BUNDLE_TAB_ID, Tab.INVALID_TA
B_ID); | 114 tabId = getSavedInstanceState().getInt(BUNDLE_TAB_ID, Tab.INVALID_TA
B_ID); |
| 120 tabUrl = getSavedInstanceState().getString(BUNDLE_TAB_URL); | 115 tabUrl = getSavedInstanceState().getString(BUNDLE_TAB_URL); |
| 121 } | 116 } |
| 122 | 117 |
| 123 if (tabId != Tab.INVALID_TAB_ID && tabUrl != null && getActivityDirector
y() != null) { | 118 if (tabId != Tab.INVALID_TAB_ID && tabUrl != null && getActivityDirector
y() != null) { |
| 124 FileInputStream stream = null; | 119 // Restore the tab. |
| 125 try { | 120 TabState tabState = TabState.restoreTabState(getActivityDirectory(),
tabId); |
| 126 // Restore the tab. | 121 tab = new Tab(tabId, Tab.INVALID_TAB_ID, false, this, getWindowAndro
id(), |
| 127 stream = new FileInputStream(getTabFile(getActivityDirectory(),
tabId)); | 122 TabLaunchType.FROM_RESTORE, |
| 128 TabState tabState = TabState.readState(stream, false); | 123 TabCreationState.FROZEN_ON_RESTORE, tabState); |
| 129 tab = new Tab(tabId, Tab.INVALID_TAB_ID, false, this, getWindowA
ndroid(), | 124 unfreeze = true; |
| 130 TabLaunchType.FROM_RESTORE, | |
| 131 TabCreationState.FROZEN_ON_RESTORE, tabState); | |
| 132 unfreeze = true; | |
| 133 } catch (FileNotFoundException exception) { | |
| 134 Log.e(TAG, "Failed to restore tab state.", exception); | |
| 135 } catch (IOException exception) { | |
| 136 Log.e(TAG, "Failed to restore tab state.", exception); | |
| 137 } finally { | |
| 138 StreamUtil.closeQuietly(stream); | |
| 139 } | |
| 140 } | 125 } |
| 141 | 126 |
| 142 if (tab == null) { | 127 if (tab == null) { |
| 143 tab = new Tab(Tab.INVALID_TAB_ID, Tab.INVALID_TAB_ID, false, this, g
etWindowAndroid(), | 128 tab = new Tab(Tab.INVALID_TAB_ID, Tab.INVALID_TAB_ID, false, this, g
etWindowAndroid(), |
| 144 TabLaunchType.FROM_CHROME_UI, null, null); | 129 TabLaunchType.FROM_CHROME_UI, null, null); |
| 145 } | 130 } |
| 146 | 131 |
| 147 tab.initialize(null, getTabContentManager(), createTabDelegateFactory(),
false, unfreeze); | 132 tab.initialize(null, getTabContentManager(), createTabDelegateFactory(),
false, unfreeze); |
| 148 mWebContentsObserver = new WebContentsObserver(tab.getWebContents()) { | 133 mWebContentsObserver = new WebContentsObserver(tab.getWebContents()) { |
| 149 @Override | 134 @Override |
| (...skipping 17 matching lines...) Expand all Loading... |
| 167 return new FullScreenDelegateFactory(); | 152 return new FullScreenDelegateFactory(); |
| 168 } | 153 } |
| 169 | 154 |
| 170 /** | 155 /** |
| 171 * @return {@link File} pointing at a directory specific for this class. | 156 * @return {@link File} pointing at a directory specific for this class. |
| 172 */ | 157 */ |
| 173 protected File getActivityDirectory() { | 158 protected File getActivityDirectory() { |
| 174 return null; | 159 return null; |
| 175 } | 160 } |
| 176 | 161 |
| 177 /** | |
| 178 * @return {@link File} pointing at the tab state for this Activity. | |
| 179 */ | |
| 180 protected static File getTabFile(File activityDirectory, int tabId) { | |
| 181 return new File(activityDirectory, TabState.getTabStateFilename(tabId, f
alse)); | |
| 182 } | |
| 183 | |
| 184 @Override | 162 @Override |
| 185 protected boolean handleBackPressed() { | 163 protected boolean handleBackPressed() { |
| 186 if (mTab == null) return false; | 164 if (mTab == null) return false; |
| 187 if (mTab.canGoBack()) { | 165 if (mTab.canGoBack()) { |
| 188 mTab.goBack(); | 166 mTab.goBack(); |
| 189 return true; | 167 return true; |
| 190 } | 168 } |
| 191 return false; | 169 return false; |
| 192 } | 170 } |
| 193 | 171 |
| 194 @Override | 172 @Override |
| 195 public void onCheckForUpdate(boolean updateAvailable) { | 173 public void onCheckForUpdate(boolean updateAvailable) { |
| 196 } | 174 } |
| 197 } | 175 } |
| OLD | NEW |