OLD | NEW |
(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.document; |
| 6 |
| 7 import android.annotation.TargetApi; |
| 8 import android.content.Context; |
| 9 import android.os.Build; |
| 10 import android.os.Bundle; |
| 11 |
| 12 import org.chromium.chrome.browser.cookies.CookiesFetcher; |
| 13 import org.chromium.content.browser.crypto.CipherFactory; |
| 14 import org.chromium.content.browser.crypto.CipherFactory.CipherDataObserver; |
| 15 |
| 16 /** |
| 17 * {@link DocumentActivity} for incognito tabs. |
| 18 */ |
| 19 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| 20 public class IncognitoDocumentActivity extends DocumentActivity { |
| 21 /** |
| 22 * Responsible for observing when cipher data generation is complete and sav
ing |
| 23 * the new cipher data in the CipherKeyActivity. |
| 24 */ |
| 25 private static class CipherKeySaver implements CipherDataObserver { |
| 26 private final Context mContext; |
| 27 |
| 28 public CipherKeySaver(Context context) { |
| 29 mContext = context; |
| 30 CipherFactory.getInstance().addCipherDataObserver(this); |
| 31 } |
| 32 |
| 33 @Override |
| 34 public void onCipherDataGenerated() { |
| 35 mContext.startActivity( |
| 36 CipherKeyActivity.createIntent(mContext, null, null)); |
| 37 CipherFactory.getInstance().removeCipherDataObserver(this); |
| 38 } |
| 39 } |
| 40 |
| 41 private static CipherKeySaver sCipherKeySaver; |
| 42 |
| 43 private static void maybeCreateCipherKeySaver(Context context) { |
| 44 if (sCipherKeySaver == null && !CipherFactory.getInstance().hasCipher())
{ |
| 45 sCipherKeySaver = new CipherKeySaver(context); |
| 46 } |
| 47 } |
| 48 |
| 49 @Override |
| 50 protected boolean isIncognito() { |
| 51 return true; |
| 52 } |
| 53 |
| 54 @Override |
| 55 public void preInflationStartup() { |
| 56 CipherFactory.getInstance().restoreFromBundle(getSavedInstanceState()); |
| 57 maybeCreateCipherKeySaver(this); |
| 58 super.preInflationStartup(); |
| 59 } |
| 60 |
| 61 @Override |
| 62 public void onResume() { |
| 63 super.onResume(); |
| 64 IncognitoNotificationManager.updateIncognitoNotification( |
| 65 ChromeLauncherActivity.getRemoveAllIncognitoTabsIntent(this)); |
| 66 } |
| 67 |
| 68 @Override |
| 69 public void onResumeWithNative() { |
| 70 super.onResumeWithNative(); |
| 71 CookiesFetcher.restoreCookies(this); |
| 72 } |
| 73 |
| 74 @Override |
| 75 public void onPauseWithNative() { |
| 76 CookiesFetcher.persistCookies(this); |
| 77 super.onPauseWithNative(); |
| 78 } |
| 79 |
| 80 @Override |
| 81 public void onSaveInstanceState(Bundle outState) { |
| 82 super.onSaveInstanceState(outState); |
| 83 CipherFactory.getInstance().saveToBundle(outState); |
| 84 |
| 85 // Save out the URL that was originally used to spawn this activity beca
use we don't pass it |
| 86 // in through the Intent. |
| 87 String initialUrl = determineInitialUrl(determineTabId()); |
| 88 outState.putString(KEY_INITIAL_URL, initialUrl); |
| 89 } |
| 90 |
| 91 @Override |
| 92 protected String determineInitialUrl(int tabId) { |
| 93 // Check if the URL was saved in the Bundle. |
| 94 if (getSavedInstanceState() != null) { |
| 95 String initialUrl = getSavedInstanceState().getString(KEY_INITIAL_UR
L); |
| 96 if (initialUrl != null) return initialUrl; |
| 97 } |
| 98 |
| 99 return super.determineInitialUrl(tabId); |
| 100 } |
| 101 } |
OLD | NEW |