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.chromecast.shell; | 5 package org.chromium.chromecast.shell; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.Intent; | 8 import android.content.Intent; |
9 import android.net.Uri; | 9 import android.net.Uri; |
10 import android.support.v4.content.LocalBroadcastManager; | 10 import android.support.v4.content.LocalBroadcastManager; |
11 import android.text.TextUtils; | 11 import android.text.TextUtils; |
12 import android.util.AttributeSet; | 12 import android.util.AttributeSet; |
13 import android.util.Log; | 13 import android.util.Log; |
14 import android.view.ViewGroup; | 14 import android.view.ViewGroup; |
15 import android.widget.FrameLayout; | 15 import android.widget.FrameLayout; |
16 import android.widget.LinearLayout; | 16 import android.widget.LinearLayout; |
17 | 17 |
18 import org.chromium.base.CalledByNative; | 18 import org.chromium.base.CalledByNative; |
19 import org.chromium.base.JNINamespace; | 19 import org.chromium.base.JNINamespace; |
20 import org.chromium.content.browser.ContentView; | 20 import org.chromium.content.browser.ContentView; |
21 import org.chromium.content.browser.ContentViewCore; | 21 import org.chromium.content.browser.ContentViewCore; |
22 import org.chromium.content.browser.ContentViewRenderView; | 22 import org.chromium.content.browser.ContentViewRenderView; |
23 import org.chromium.content.browser.WebContentsObserverAndroid; | 23 import org.chromium.content.browser.WebContentsObserver; |
24 import org.chromium.content_public.browser.LoadUrlParams; | 24 import org.chromium.content_public.browser.LoadUrlParams; |
25 import org.chromium.ui.base.WindowAndroid; | 25 import org.chromium.ui.base.WindowAndroid; |
26 | 26 |
27 /** | 27 /** |
28 * Container for the various UI components that make up a shell window. | 28 * Container for the various UI components that make up a shell window. |
29 */ | 29 */ |
30 @JNINamespace("chromecast::shell") | 30 @JNINamespace("chromecast::shell") |
31 public class CastWindowAndroid extends LinearLayout { | 31 public class CastWindowAndroid extends LinearLayout { |
32 public static final String TAG = "CastWindowAndroid"; | 32 public static final String TAG = "CastWindowAndroid"; |
33 | 33 |
34 public static final String ACTION_PAGE_LOADED = "castPageLoaded"; | 34 public static final String ACTION_PAGE_LOADED = "castPageLoaded"; |
35 public static final String ACTION_ENABLE_DEV_TOOLS = "castEnableDevTools"; | 35 public static final String ACTION_ENABLE_DEV_TOOLS = "castEnableDevTools"; |
36 public static final String ACTION_DISABLE_DEV_TOOLS = "castDisableDevTools"; | 36 public static final String ACTION_DISABLE_DEV_TOOLS = "castDisableDevTools"; |
37 | 37 |
38 private ContentViewCore mContentViewCore; | 38 private ContentViewCore mContentViewCore; |
39 private ContentViewRenderView mContentViewRenderView; | 39 private ContentViewRenderView mContentViewRenderView; |
40 private WebContentsObserverAndroid mWebContentsObserver; | 40 private WebContentsObserver mWebContentsObserver; |
41 private WindowAndroid mWindow; | 41 private WindowAndroid mWindow; |
42 | 42 |
43 /** | 43 /** |
44 * Constructor for inflating via XML. | 44 * Constructor for inflating via XML. |
45 */ | 45 */ |
46 public CastWindowAndroid(Context context, AttributeSet attrs) { | 46 public CastWindowAndroid(Context context, AttributeSet attrs) { |
47 super(context, attrs); | 47 super(context, attrs); |
48 } | 48 } |
49 | 49 |
50 /** | 50 /** |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 mContentViewCore.initialize(view, view, nativeWebContents, mWindow); | 119 mContentViewCore.initialize(view, view, nativeWebContents, mWindow); |
120 | 120 |
121 if (getParent() != null) mContentViewCore.onShow(); | 121 if (getParent() != null) mContentViewCore.onShow(); |
122 ((FrameLayout) findViewById(R.id.contentview_holder)).addView(view, | 122 ((FrameLayout) findViewById(R.id.contentview_holder)).addView(view, |
123 new FrameLayout.LayoutParams( | 123 new FrameLayout.LayoutParams( |
124 FrameLayout.LayoutParams.MATCH_PARENT, | 124 FrameLayout.LayoutParams.MATCH_PARENT, |
125 FrameLayout.LayoutParams.MATCH_PARENT)); | 125 FrameLayout.LayoutParams.MATCH_PARENT)); |
126 view.requestFocus(); | 126 view.requestFocus(); |
127 mContentViewRenderView.setCurrentContentViewCore(mContentViewCore); | 127 mContentViewRenderView.setCurrentContentViewCore(mContentViewCore); |
128 | 128 |
129 mWebContentsObserver = new WebContentsObserverAndroid(mContentViewCore.g
etWebContents()) { | 129 mWebContentsObserver = new WebContentsObserver(mContentViewCore.getWebCo
ntents()) { |
130 @Override | 130 @Override |
131 public void didStopLoading(String url) { | 131 public void didStopLoading(String url) { |
132 Uri intentUri = Uri.parse(mContentViewCore | 132 Uri intentUri = Uri.parse(mContentViewCore |
133 .getOriginalUrlForActiveNavigationEntry()); | 133 .getOriginalUrlForActiveNavigationEntry()); |
134 Log.v(TAG, "Broadcast ACTION_PAGE_LOADED: scheme=" + intentUri.g
etScheme() | 134 Log.v(TAG, "Broadcast ACTION_PAGE_LOADED: scheme=" + intentUri.g
etScheme() |
135 + ", host=" + intentUri.getHost()); | 135 + ", host=" + intentUri.getHost()); |
136 LocalBroadcastManager.getInstance(getContext()).sendBroadcast( | 136 LocalBroadcastManager.getInstance(getContext()).sendBroadcast( |
137 new Intent(ACTION_PAGE_LOADED, intentUri)); | 137 new Intent(ACTION_PAGE_LOADED, intentUri)); |
138 } | 138 } |
139 }; | 139 }; |
140 } | 140 } |
141 | 141 |
142 /** | 142 /** |
143 * @return The {@link ViewGroup} currently shown by this Shell. | 143 * @return The {@link ViewGroup} currently shown by this Shell. |
144 */ | 144 */ |
145 public ViewGroup getContentView() { | 145 public ViewGroup getContentView() { |
146 return mContentViewCore.getContainerView(); | 146 return mContentViewCore.getContainerView(); |
147 } | 147 } |
148 | 148 |
149 /** | 149 /** |
150 * @return The {@link ContentViewCore} currently managing the view shown by
this Shell. | 150 * @return The {@link ContentViewCore} currently managing the view shown by
this Shell. |
151 */ | 151 */ |
152 public ContentViewCore getContentViewCore() { | 152 public ContentViewCore getContentViewCore() { |
153 return mContentViewCore; | 153 return mContentViewCore; |
154 } | 154 } |
155 } | 155 } |
OLD | NEW |