Chromium Code Reviews| 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.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
| 9 import android.graphics.Color; | 9 import android.graphics.Color; |
| 10 import android.graphics.drawable.Drawable; | 10 import android.graphics.drawable.Drawable; |
| 11 import android.net.Uri; | 11 import android.net.Uri; |
| 12 import android.os.Bundle; | 12 import android.os.Bundle; |
| 13 import android.os.StrictMode; | 13 import android.os.StrictMode; |
| 14 import android.os.SystemClock; | |
| 14 import android.text.TextUtils; | 15 import android.text.TextUtils; |
| 15 import android.view.LayoutInflater; | 16 import android.view.LayoutInflater; |
| 16 import android.view.View; | 17 import android.view.View; |
| 17 import android.view.ViewGroup; | 18 import android.view.ViewGroup; |
| 18 import android.widget.FrameLayout; | 19 import android.widget.FrameLayout; |
| 19 import android.widget.ImageView; | 20 import android.widget.ImageView; |
| 20 import android.widget.TextView; | 21 import android.widget.TextView; |
| 21 | 22 |
| 22 import org.chromium.base.ActivityState; | 23 import org.chromium.base.ActivityState; |
| 23 import org.chromium.base.ApiCompatibilityUtils; | 24 import org.chromium.base.ApiCompatibilityUtils; |
| 24 import org.chromium.base.ApplicationStatus; | 25 import org.chromium.base.ApplicationStatus; |
| 25 import org.chromium.base.Log; | 26 import org.chromium.base.Log; |
| 26 import org.chromium.base.StreamUtil; | 27 import org.chromium.base.StreamUtil; |
| 27 import org.chromium.base.VisibleForTesting; | 28 import org.chromium.base.VisibleForTesting; |
| 29 import org.chromium.base.metrics.RecordHistogram; | |
| 28 import org.chromium.blink_public.platform.WebDisplayMode; | 30 import org.chromium.blink_public.platform.WebDisplayMode; |
| 29 import org.chromium.chrome.R; | 31 import org.chromium.chrome.R; |
| 30 import org.chromium.chrome.browser.TabState; | 32 import org.chromium.chrome.browser.TabState; |
| 31 import org.chromium.chrome.browser.document.DocumentUtils; | 33 import org.chromium.chrome.browser.document.DocumentUtils; |
| 32 import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; | 34 import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; |
| 33 import org.chromium.chrome.browser.metrics.WebappUma; | 35 import org.chromium.chrome.browser.metrics.WebappUma; |
| 34 import org.chromium.chrome.browser.tab.EmptyTabObserver; | 36 import org.chromium.chrome.browser.tab.EmptyTabObserver; |
| 35 import org.chromium.chrome.browser.tab.Tab; | 37 import org.chromium.chrome.browser.tab.Tab; |
| 36 import org.chromium.chrome.browser.tab.TabDelegateFactory; | 38 import org.chromium.chrome.browser.tab.TabDelegateFactory; |
| 37 import org.chromium.chrome.browser.tab.TabObserver; | 39 import org.chromium.chrome.browser.tab.TabObserver; |
| 38 import org.chromium.chrome.browser.tab.TopControlsVisibilityDelegate; | 40 import org.chromium.chrome.browser.tab.TopControlsVisibilityDelegate; |
| 39 import org.chromium.chrome.browser.util.ColorUtils; | 41 import org.chromium.chrome.browser.util.ColorUtils; |
| 40 import org.chromium.chrome.browser.util.UrlUtilities; | 42 import org.chromium.chrome.browser.util.UrlUtilities; |
| 41 import org.chromium.components.security_state.ConnectionSecurityLevel; | 43 import org.chromium.components.security_state.ConnectionSecurityLevel; |
| 42 import org.chromium.content.browser.ScreenOrientationProvider; | 44 import org.chromium.content.browser.ScreenOrientationProvider; |
| 43 import org.chromium.content_public.browser.LoadUrlParams; | 45 import org.chromium.content_public.browser.LoadUrlParams; |
| 44 import org.chromium.net.NetworkChangeNotifier; | 46 import org.chromium.net.NetworkChangeNotifier; |
| 45 import org.chromium.ui.base.PageTransition; | 47 import org.chromium.ui.base.PageTransition; |
| 46 | 48 |
| 47 import java.io.File; | 49 import java.io.File; |
| 48 import java.io.FileNotFoundException; | 50 import java.io.FileNotFoundException; |
| 49 import java.io.FileOutputStream; | 51 import java.io.FileOutputStream; |
| 50 import java.io.IOException; | 52 import java.io.IOException; |
| 53 import java.util.concurrent.TimeUnit; | |
| 51 | 54 |
| 52 /** | 55 /** |
| 53 * Displays a webapp in a nearly UI-less Chrome (InfoBars still appear). | 56 * Displays a webapp in a nearly UI-less Chrome (InfoBars still appear). |
| 54 */ | 57 */ |
| 55 public class WebappActivity extends FullScreenActivity { | 58 public class WebappActivity extends FullScreenActivity { |
| 56 public static final String WEBAPP_SCHEME = "webapp"; | 59 public static final String WEBAPP_SCHEME = "webapp"; |
| 57 | 60 |
| 58 private static final String TAG = "WebappActivity"; | 61 private static final String TAG = "WebappActivity"; |
| 59 private static final long MS_BEFORE_NAVIGATING_BACK_FROM_INTERSTITIAL = 1000 ; | 62 private static final long MS_BEFORE_NAVIGATING_BACK_FROM_INTERSTITIAL = 1000 ; |
| 60 | 63 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 * Saves the tab data out to a file. | 165 * Saves the tab data out to a file. |
| 163 */ | 166 */ |
| 164 void saveState(File activityDirectory) { | 167 void saveState(File activityDirectory) { |
| 165 File tabFile = getTabFile(activityDirectory, getActivityTab().getId()); | 168 File tabFile = getTabFile(activityDirectory, getActivityTab().getId()); |
| 166 | 169 |
| 167 FileOutputStream foutput = null; | 170 FileOutputStream foutput = null; |
| 168 // Temporarily allowing disk access while fixing. TODO: http://crbug.com /525781 | 171 // Temporarily allowing disk access while fixing. TODO: http://crbug.com /525781 |
| 169 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); | 172 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 170 StrictMode.allowThreadDiskWrites(); | 173 StrictMode.allowThreadDiskWrites(); |
| 171 try { | 174 try { |
| 175 long time = SystemClock.elapsedRealtime(); | |
| 172 foutput = new FileOutputStream(tabFile); | 176 foutput = new FileOutputStream(tabFile); |
| 173 TabState.saveState(foutput, getActivityTab().getState(), false); | 177 TabState.saveState(foutput, getActivityTab().getState(), false); |
| 178 RecordHistogram.recordTimesHistogram("Android.StrictMode.WebappSaveS tate", | |
| 179 SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS) ; | |
| 174 } catch (FileNotFoundException exception) { | 180 } catch (FileNotFoundException exception) { |
| 175 Log.e(TAG, "Failed to save out tab state.", exception); | 181 Log.e(TAG, "Failed to save out tab state.", exception); |
| 176 } catch (IOException exception) { | 182 } catch (IOException exception) { |
| 177 Log.e(TAG, "Failed to save out tab state.", exception); | 183 Log.e(TAG, "Failed to save out tab state.", exception); |
| 178 } finally { | 184 } finally { |
| 179 StreamUtil.closeQuietly(foutput); | 185 StreamUtil.closeQuietly(foutput); |
| 180 StrictMode.setThreadPolicy(oldPolicy); | 186 StrictMode.setThreadPolicy(oldPolicy); |
| 181 } | 187 } |
| 182 } | 188 } |
| 183 | 189 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 int splashScreenIconType; | 288 int splashScreenIconType; |
| 283 if (splashImage == null) { | 289 if (splashImage == null) { |
| 284 splashScreenIconType = WebappUma.SPLASHSCREEN_ICON_TYPE_FALLBACK ; | 290 splashScreenIconType = WebappUma.SPLASHSCREEN_ICON_TYPE_FALLBACK ; |
| 285 } else if (isUsingSmallSplashImage) { | 291 } else if (isUsingSmallSplashImage) { |
| 286 splashScreenIconType = WebappUma.SPLASHSCREEN_ICON_TYPE_CUSTOM_S MALL; | 292 splashScreenIconType = WebappUma.SPLASHSCREEN_ICON_TYPE_CUSTOM_S MALL; |
| 287 } else { | 293 } else { |
| 288 splashScreenIconType = WebappUma.SPLASHSCREEN_ICON_TYPE_CUSTOM; | 294 splashScreenIconType = WebappUma.SPLASHSCREEN_ICON_TYPE_CUSTOM; |
| 289 } | 295 } |
| 290 mWebappUma.recordSplashscreenIconType(splashScreenIconType); | 296 mWebappUma.recordSplashscreenIconType(splashScreenIconType); |
| 291 mWebappUma.recordSplashscreenIconSize( | 297 mWebappUma.recordSplashscreenIconSize( |
| 292 Math.round((float) displayIcon.getWidth() | 298 Math.round(displayIcon.getWidth() |
|
Yaron
2016/01/21 20:48:15
was this removal intentional?
Peter Wen
2016/01/21 20:59:45
Yeah, eclipse auto-removed it since density is a f
| |
| 293 / getResources().getDisplayMetrics().density)); | 299 / getResources().getDisplayMetrics().density)); |
| 294 } | 300 } |
| 295 | 301 |
| 296 ViewGroup subLayout = (ViewGroup) LayoutInflater.from(WebappActivity.thi s) | 302 ViewGroup subLayout = (ViewGroup) LayoutInflater.from(WebappActivity.thi s) |
| 297 .inflate(layoutId, mSplashScreen, true); | 303 .inflate(layoutId, mSplashScreen, true); |
| 298 | 304 |
| 299 // Set up the elements of the splash screen. | 305 // Set up the elements of the splash screen. |
| 300 TextView appNameView = (TextView) subLayout.findViewById( | 306 TextView appNameView = (TextView) subLayout.findViewById( |
| 301 R.id.webapp_splash_screen_name); | 307 R.id.webapp_splash_screen_name); |
| 302 ImageView splashIconView = (ImageView) subLayout.findViewById( | 308 ImageView splashIconView = (ImageView) subLayout.findViewById( |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 return visible; | 569 return visible; |
| 564 } | 570 } |
| 565 | 571 |
| 566 // We're temporarily disable CS on webapp since there are some issues. (http ://crbug.com/471950) | 572 // We're temporarily disable CS on webapp since there are some issues. (http ://crbug.com/471950) |
| 567 // TODO(changwan): re-enable it once the issues are resolved. | 573 // TODO(changwan): re-enable it once the issues are resolved. |
| 568 @Override | 574 @Override |
| 569 protected boolean isContextualSearchAllowed() { | 575 protected boolean isContextualSearchAllowed() { |
| 570 return false; | 576 return false; |
| 571 } | 577 } |
| 572 } | 578 } |
| OLD | NEW |