OLD | NEW |
| (Empty) |
1 // Copyright 2017 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; | |
6 | |
7 import android.app.Activity; | |
8 import android.content.ComponentName; | |
9 import android.content.Intent; | |
10 import android.provider.Browser; | |
11 | |
12 import org.chromium.base.Log; | |
13 import org.chromium.chrome.R; | |
14 import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; | |
15 import org.chromium.chrome.browser.tab.Tab; | |
16 import org.chromium.chrome.browser.tabmodel.AsyncTabParamsManager; | |
17 import org.chromium.chrome.browser.tabmodel.TabReparentingParams; | |
18 import org.chromium.chrome.browser.util.IntentUtils; | |
19 import org.chromium.chrome.browser.webapps.FullScreenActivity; | |
20 | |
21 /** | |
22 * An Activity used to display fullscreen WebContents. | |
23 */ | |
24 public class FullscreenWebContentsActivity extends FullScreenActivity { | |
25 private static final String TAG = "FullWebConActivity"; | |
26 | |
27 @Override | |
28 protected Tab createTab() { | |
29 assert getIntent().hasExtra(IntentHandler.EXTRA_TAB_ID); | |
30 | |
31 int tabId = IntentUtils.safeGetIntExtra( | |
32 getIntent(), IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID); | |
33 TabReparentingParams params = (TabReparentingParams) AsyncTabParamsManag
er.remove(tabId); | |
34 | |
35 Tab tab = params.getTabToReparent(); | |
36 tab.attachAndFinishReparenting(this, createTabDelegateFactory(), params)
; | |
37 return tab; | |
38 } | |
39 | |
40 @Override | |
41 protected int getControlContainerLayoutId() { | |
42 // TODO(peconn): Determine if there's something more suitable to use her
e. | |
43 return R.layout.webapp_control_container; | |
44 } | |
45 | |
46 @Override | |
47 protected ChromeFullscreenManager createFullscreenManager() { | |
48 // Create a Fullscreen manager that won't change the Tab's fullscreen st
ate when the | |
49 // Activity ends - we handle leaving fullscreen ourselves. | |
50 return new ChromeFullscreenManager(this, false, false); | |
51 } | |
52 | |
53 @Override | |
54 public boolean supportsFullscreenActivity() { | |
55 return true; | |
56 } | |
57 | |
58 public static void toggleFullscreenMode(final boolean enableFullscreen, fina
l Tab tab) { | |
59 if (tab.getFullscreenManager() == null) { | |
60 Log.w(TAG, "Cannot toggle fullscreen, manager is null."); | |
61 return; | |
62 } | |
63 | |
64 if (tab.getFullscreenManager().getTab() == tab) { | |
65 tab.getFullscreenManager().setTab(null); | |
66 } | |
67 | |
68 Runnable setFullscreen = new Runnable() { | |
69 @Override | |
70 public void run() { | |
71 // The Tab's FullscreenManager changes when it is moved. | |
72 tab.getFullscreenManager().setTab(tab); | |
73 tab.toggleFullscreenMode(enableFullscreen); | |
74 } | |
75 }; | |
76 | |
77 Intent intent = new Intent(); | |
78 Activity activity = tab.getActivity(); | |
79 | |
80 if (enableFullscreen) { | |
81 // Send to the FullscreenWebContentsActivity. | |
82 intent.setClass(tab.getActivity(), FullscreenWebContentsActivity.cla
ss); | |
83 | |
84 intent.putExtra(IntentHandler.EXTRA_PARENT_COMPONENT, activity.getCo
mponentName()); | |
85 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
86 // In multiwindow mode we want both activities to be able to launch
independent | |
87 // FullscreenWebContentsActivity's. | |
88 intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); | |
89 } else { | |
90 // Send back to the Activity it came from. | |
91 ComponentName parent = IntentUtils.safeGetParcelableExtra( | |
92 activity.getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT); | |
93 if (parent != null) { | |
94 intent.setComponent(parent); | |
95 } else { | |
96 Log.d(TAG, "Cannot return fullscreen tab to parent Activity."); | |
97 // Tab.detachAndStartReparenting will give the intent a default
component if it | |
98 // has none. | |
99 } | |
100 | |
101 // TODO(peconn): Deal with tricky multiwindow scenarios. | |
102 } | |
103 intent.putExtra(Browser.EXTRA_APPLICATION_ID, activity.getPackageName())
; | |
104 | |
105 tab.detachAndStartReparenting(intent, null, setFullscreen); | |
106 } | |
107 } | |
OLD | NEW |