OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.tab; | 5 package org.chromium.chrome.browser.tab; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.app.Application; | 9 import android.app.Application; |
10 import android.content.Context; | 10 import android.content.Context; |
11 import android.content.Intent; | 11 import android.content.Intent; |
12 import android.content.res.Resources; | 12 import android.content.res.Resources; |
13 import android.graphics.Bitmap; | 13 import android.graphics.Bitmap; |
14 import android.graphics.Color; | 14 import android.graphics.Color; |
15 import android.graphics.Rect; | 15 import android.graphics.Rect; |
16 import android.net.Uri; | 16 import android.net.Uri; |
17 import android.os.Bundle; | 17 import android.os.Bundle; |
18 import android.provider.Browser; | 18 import android.provider.Browser; |
19 import android.support.annotation.Nullable; | 19 import android.support.annotation.Nullable; |
20 import android.support.v4.view.ViewCompat; | 20 import android.support.v4.view.ViewCompat; |
21 import android.text.TextUtils; | 21 import android.text.TextUtils; |
22 import android.util.Log; | |
23 import android.view.ContextThemeWrapper; | 22 import android.view.ContextThemeWrapper; |
24 import android.view.View; | 23 import android.view.View; |
25 import android.view.View.OnClickListener; | 24 import android.view.View.OnClickListener; |
26 import android.view.ViewGroup; | 25 import android.view.ViewGroup; |
27 import android.view.accessibility.AccessibilityEvent; | 26 import android.view.accessibility.AccessibilityEvent; |
28 import android.widget.FrameLayout; | 27 import android.widget.FrameLayout; |
29 import android.widget.FrameLayout.LayoutParams; | 28 import android.widget.FrameLayout.LayoutParams; |
30 | 29 |
31 import org.chromium.base.ApiCompatibilityUtils; | 30 import org.chromium.base.ApiCompatibilityUtils; |
32 import org.chromium.base.ApplicationStatus; | 31 import org.chromium.base.ApplicationStatus; |
33 import org.chromium.base.ContextUtils; | 32 import org.chromium.base.ContextUtils; |
33 import org.chromium.base.Log; | |
34 import org.chromium.base.ObserverList; | 34 import org.chromium.base.ObserverList; |
35 import org.chromium.base.ObserverList.RewindableIterator; | 35 import org.chromium.base.ObserverList.RewindableIterator; |
36 import org.chromium.base.TraceEvent; | 36 import org.chromium.base.TraceEvent; |
37 import org.chromium.base.VisibleForTesting; | 37 import org.chromium.base.VisibleForTesting; |
38 import org.chromium.base.annotations.CalledByNative; | 38 import org.chromium.base.annotations.CalledByNative; |
39 import org.chromium.base.metrics.RecordHistogram; | 39 import org.chromium.base.metrics.RecordHistogram; |
40 import org.chromium.chrome.R; | 40 import org.chromium.chrome.R; |
41 import org.chromium.chrome.browser.AppHooks; | 41 import org.chromium.chrome.browser.AppHooks; |
42 import org.chromium.chrome.browser.ChromeActionModeCallback; | 42 import org.chromium.chrome.browser.ChromeActionModeCallback; |
43 import org.chromium.chrome.browser.ChromeActivity; | 43 import org.chromium.chrome.browser.ChromeActivity; |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 private FullscreenManager mFullscreenManager; | 339 private FullscreenManager mFullscreenManager; |
340 private float mPreviousTopControlsOffsetY = Float.NaN; | 340 private float mPreviousTopControlsOffsetY = Float.NaN; |
341 private float mPreviousBottomControlsOffsetY = Float.NaN; | 341 private float mPreviousBottomControlsOffsetY = Float.NaN; |
342 private float mPreviousContentOffsetY = Float.NaN; | 342 private float mPreviousContentOffsetY = Float.NaN; |
343 | 343 |
344 /** | 344 /** |
345 * Indicates whether this tab has been detached from its activity and the co rresponding | 345 * Indicates whether this tab has been detached from its activity and the co rresponding |
346 * {@link WindowAndroid} for reparenting to a new activity. | 346 * {@link WindowAndroid} for reparenting to a new activity. |
347 */ | 347 */ |
348 private boolean mIsDetachedForReparenting; | 348 private boolean mIsDetachedForReparenting; |
349 private Boolean mIsPendingFullscreen; | |
349 | 350 |
350 /** | 351 /** |
351 * The UMA object used to report stats for this tab. Note that this may be n ull under certain | 352 * The UMA object used to report stats for this tab. Note that this may be n ull under certain |
352 * conditions, such as incognito mode. | 353 * conditions, such as incognito mode. |
353 */ | 354 */ |
354 private TabUma mTabUma; | 355 private TabUma mTabUma; |
355 | 356 |
356 /** | 357 /** |
357 * Reference to the current sadTabView if one is defined. | 358 * Reference to the current sadTabView if one is defined. |
358 */ | 359 */ |
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1335 } finally { | 1336 } finally { |
1336 if (mTimestampMillis == INVALID_TIMESTAMP) { | 1337 if (mTimestampMillis == INVALID_TIMESTAMP) { |
1337 mTimestampMillis = System.currentTimeMillis(); | 1338 mTimestampMillis = System.currentTimeMillis(); |
1338 } | 1339 } |
1339 | 1340 |
1340 TraceEvent.end("Tab.initialize"); | 1341 TraceEvent.end("Tab.initialize"); |
1341 } | 1342 } |
1342 } | 1343 } |
1343 | 1344 |
1344 /** | 1345 /** |
1346 * Begins the tab reparenting process, see | |
1347 * {@link detachAndStartReparenting(Intent, Bundle, Runnable, Boolean). | |
1348 */ | |
1349 public boolean detachAndStartReparenting( | |
1350 Intent intent, Bundle startActivityOptions, Runnable finalizeCallbac k) { | |
1351 return detachAndStartReparenting( | |
1352 intent, startActivityOptions, finalizeCallback, null /* pendingF ullscreen */); | |
1353 } | |
1354 | |
1355 /** | |
1345 * Begins the tab reparenting process. Detaches the tab from its current act ivity and fires | 1356 * Begins the tab reparenting process. Detaches the tab from its current act ivity and fires |
1346 * an Intent to reparent the tab into its new host activity. | 1357 * an Intent to reparent the tab into its new host activity. |
1347 * | 1358 * |
1348 * @param intent An optional intent with the desired component, flags, or ex tras to use when | 1359 * @param intent An optional intent with the desired component, flags, or ex tras to use when |
1349 * launching the new host activity. This intent's URI and acti on will be | 1360 * launching the new host activity. This intent's URI and acti on will be |
1350 * overriden. This may be null if no intent customization is n eeded. | 1361 * overriden. This may be null if no intent customization is n eeded. |
1351 * @param startActivityOptions Options to pass to {@link Activity#startActiv ity(Intent, Bundle)} | 1362 * @param startActivityOptions Options to pass to {@link Activity#startActiv ity(Intent, Bundle)} |
1352 * @param finalizeCallback A callback that will be called after the tab is a ttached to the new | 1363 * @param finalizeCallback A callback that will be called after the tab is a ttached to the new |
1353 * host activity in {@link #attachAndFinishReparenti ng}. | 1364 * host activity in {@link #attachAndFinishReparenti ng}. |
1365 * @param pendingFullscreen What state fullscreen should be toggled to after finishing | |
1366 * reparenting, or null if it should be left untouc hed. | |
1354 * @return Whether reparenting succeeded. If false, the tab was not removed and the intent was | 1367 * @return Whether reparenting succeeded. If false, the tab was not removed and the intent was |
1355 * not fired. | 1368 * not fired. |
1356 */ | 1369 */ |
1357 public boolean detachAndStartReparenting(Intent intent, Bundle startActivity Options, | 1370 public boolean detachAndStartReparenting(Intent intent, Bundle startActivity Options, |
1358 Runnable finalizeCallback) { | 1371 Runnable finalizeCallback, @Nullable Boolean pendingFullscreen) { |
1359 ChromeActivity activity = getActivity(); | 1372 ChromeActivity activity = getActivity(); |
1360 if (activity == null) return false; | 1373 if (activity == null) return false; |
1361 | 1374 |
1362 if (intent == null) intent = new Intent(); | 1375 if (intent == null) intent = new Intent(); |
1363 if (intent.getComponent() == null) { | 1376 if (intent.getComponent() == null) { |
1364 intent.setClass(mThemedApplicationContext, ChromeLauncherActivity.cl ass); | 1377 intent.setClass(mThemedApplicationContext, ChromeLauncherActivity.cl ass); |
1365 } | 1378 } |
1366 intent.setAction(Intent.ACTION_VIEW); | 1379 intent.setAction(Intent.ACTION_VIEW); |
1367 if (TextUtils.isEmpty(intent.getDataString())) intent.setData(Uri.parse( getUrl())); | 1380 if (TextUtils.isEmpty(intent.getDataString())) intent.setData(Uri.parse( getUrl())); |
1368 if (isIncognito()) { | 1381 if (isIncognito()) { |
1369 intent.putExtra(Browser.EXTRA_APPLICATION_ID, | 1382 intent.putExtra(Browser.EXTRA_APPLICATION_ID, |
1370 ContextUtils.getApplicationContext().getPackageName()); | 1383 ContextUtils.getApplicationContext().getPackageName()); |
1371 intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true); | 1384 intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true); |
1372 } | 1385 } |
1373 IntentHandler.addTrustedIntentExtras(intent); | 1386 IntentHandler.addTrustedIntentExtras(intent); |
1374 | 1387 |
1375 if (ChromeFeatureList.isEnabled(ChromeFeatureList.TAB_REPARENTING)) { | 1388 if (ChromeFeatureList.isEnabled(ChromeFeatureList.TAB_REPARENTING)) { |
1376 TabModelSelector tabModelSelector = getTabModelSelector(); | 1389 TabModelSelector tabModelSelector = getTabModelSelector(); |
1377 if (tabModelSelector == null) return false; | 1390 if (tabModelSelector == null) return false; |
1378 mIsDetachedForReparenting = true; | 1391 mIsDetachedForReparenting = true; |
1392 mIsPendingFullscreen = pendingFullscreen; | |
1393 | |
1394 if (getFullscreenManager().getTab() == this) { | |
1395 getFullscreenManager().setTab(null); | |
1396 } | |
1379 | 1397 |
1380 // Add the tab to AsyncTabParamsManager before removing it from the current model to | 1398 // Add the tab to AsyncTabParamsManager before removing it from the current model to |
1381 // ensure the global count of tabs is correct. See crbug.com/611806. | 1399 // ensure the global count of tabs is correct. See crbug.com/611806. |
1382 intent.putExtra(IntentHandler.EXTRA_TAB_ID, mId); | 1400 intent.putExtra(IntentHandler.EXTRA_TAB_ID, mId); |
1383 AsyncTabParamsManager.add(mId, | 1401 AsyncTabParamsManager.add(mId, |
1384 new TabReparentingParams(this, intent, finalizeCallback)); | 1402 new TabReparentingParams(this, intent, finalizeCallback)); |
1385 | 1403 |
1386 tabModelSelector.getModel(mIncognito).removeTab(this); | 1404 tabModelSelector.getModel(mIncognito).removeTab(this); |
1387 | 1405 |
1388 // TODO(yusufo): We can't call updateWindowAndroid here and set mWin dowAndroid to null | 1406 // TODO(yusufo): We can't call updateWindowAndroid here and set mWin dowAndroid to null |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1432 | 1450 |
1433 // Reload the NativePage (if any), since the old NativePage has a refere nce to the old | 1451 // Reload the NativePage (if any), since the old NativePage has a refere nce to the old |
1434 // activity. | 1452 // activity. |
1435 maybeShowNativePage(getUrl(), true); | 1453 maybeShowNativePage(getUrl(), true); |
1436 | 1454 |
1437 mIsTabStateDirty = true; | 1455 mIsTabStateDirty = true; |
1438 | 1456 |
1439 for (TabObserver observer : mObservers) { | 1457 for (TabObserver observer : mObservers) { |
1440 observer.onReparentingFinished(this); | 1458 observer.onReparentingFinished(this); |
1441 } | 1459 } |
1460 | |
1461 if (mIsPendingFullscreen != null) { | |
Yusuf
2017/04/10 17:08:49
see the finalizeCallback in detach.. That is a run
PEConn
2017/04/11 00:54:46
Done.
| |
1462 mFullscreenManager.setTab(mIsPendingFullscreen ? this : null); | |
1463 toggleFullscreenMode(mIsPendingFullscreen); | |
1464 } | |
1465 mIsPendingFullscreen = null; | |
1442 } | 1466 } |
1443 | 1467 |
1444 /** | 1468 /** |
1445 * Update and propagate the new WindowAndroid. | 1469 * Update and propagate the new WindowAndroid. |
1446 * @param windowAndroid The WindowAndroid to propagate. | 1470 * @param windowAndroid The WindowAndroid to propagate. |
1447 */ | 1471 */ |
1448 public void updateWindowAndroid(WindowAndroid windowAndroid) { | 1472 public void updateWindowAndroid(WindowAndroid windowAndroid) { |
1449 // TODO(yusufo): mWindowAndroid can never be null until crbug.com/657007 is fixed. | 1473 // TODO(yusufo): mWindowAndroid can never be null until crbug.com/657007 is fixed. |
1450 assert windowAndroid != null; | 1474 assert windowAndroid != null; |
1451 mWindowAndroid = windowAndroid; | 1475 mWindowAndroid = windowAndroid; |
(...skipping 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3074 private native boolean nativeIsOfflinePage(long nativeTabAndroid); | 3098 private native boolean nativeIsOfflinePage(long nativeTabAndroid); |
3075 private native OfflinePageItem nativeGetOfflinePage(long nativeTabAndroid); | 3099 private native OfflinePageItem nativeGetOfflinePage(long nativeTabAndroid); |
3076 private native void nativeSetInterceptNavigationDelegate(long nativeTabAndro id, | 3100 private native void nativeSetInterceptNavigationDelegate(long nativeTabAndro id, |
3077 InterceptNavigationDelegate delegate); | 3101 InterceptNavigationDelegate delegate); |
3078 private native void nativeAttachToTabContentManager(long nativeTabAndroid, | 3102 private native void nativeAttachToTabContentManager(long nativeTabAndroid, |
3079 TabContentManager tabContentManager); | 3103 TabContentManager tabContentManager); |
3080 private native boolean nativeHasPrerenderedUrl(long nativeTabAndroid, String url); | 3104 private native boolean nativeHasPrerenderedUrl(long nativeTabAndroid, String url); |
3081 private native void nativeSetWebappManifestScope(long nativeTabAndroid, Stri ng scope); | 3105 private native void nativeSetWebappManifestScope(long nativeTabAndroid, Stri ng scope); |
3082 private native void nativeEnableEmbeddedMediaExperience(long nativeTabAndroi d, boolean enabled); | 3106 private native void nativeEnableEmbeddedMediaExperience(long nativeTabAndroi d, boolean enabled); |
3083 } | 3107 } |
OLD | NEW |