Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: chromecast/browser/android/apk/src/org/chromium/chromecast/shell/CastWebContentsService.java

Issue 2874943002: [Chromecast] Add service for "displaying" cast web contents. (Closed)
Patch Set: Add service for "displaying" cast web contents. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
halliwell 2017/05/19 17:04:08 nit, fix date
thoren 2017/05/19 17:19:50 Done.
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.chromecast.shell;
6
7 import android.app.Service;
8 import android.content.Intent;
9 import android.media.AudioManager;
10 import android.os.IBinder;
11
12 import org.chromium.base.Log;
13 import org.chromium.base.annotations.JNINamespace;
14 import org.chromium.content.browser.ContentView;
15 import org.chromium.content.browser.ContentViewCore;
16 import org.chromium.content_public.browser.WebContents;
17 import org.chromium.ui.base.ViewAndroidDelegate;
18 import org.chromium.ui.base.WindowAndroid;
19
20 /**
21 * Service for "displaying" a WebContents in CastShell.
22 * <p>
23 * Typically, this class is controlled by CastContentWindowAndroid, which will
24 * bind to this service.
25 */
26 @JNINamespace("chromecast::shell")
27 public class CastWebContentsService extends Service {
28 private static final String TAG = "cr_CastWebService";
29 private static final boolean DEBUG = true;
30
31 private String mInstanceId;
32 private AudioManager mAudioManager;
33 private WindowAndroid mWindow;
34 private ContentViewCore mContentViewCore;
35 private ContentView mContentView;
36
37 protected void handleIntent(Intent intent) {
38 intent.setExtrasClassLoader(WebContents.class.getClassLoader());
39 mInstanceId = intent.getData().getPath();
40
41 WebContents webContents = (WebContents) intent.getParcelableExtra(
42 CastWebContentsComponent.ACTION_EXTRA_WEB_CONTENTS);
43 if (webContents == null) {
44 Log.e(TAG, "Received null WebContents in intent.");
45 return;
46 }
47
48 detachWebContentsIfAny();
49 showWebContents(webContents);
50 }
51
52 @Override
53 public void onDestroy() {
54 if (DEBUG) Log.d(TAG, "onDestroy");
55
56 if (mAudioManager.abandonAudioFocus(null) != AudioManager.AUDIOFOCUS_REQ UEST_GRANTED) {
57 Log.e(TAG, "Failed to abandon audio focus");
58 }
59
60 super.onDestroy();
61 }
62
63 @Override
64 public void onCreate() {
65 if (DEBUG) Log.d(TAG, "onCreate");
66
67 mWindow = new WindowAndroid(this);
68 mAudioManager = CastAudioManager.getAudioManager(this);
69
70 if (mAudioManager.requestAudioFocus(
71 null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAI N)
72 != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
73 Log.e(TAG, "Failed to obtain audio focus");
74 }
75 }
76
77 @Override
78 public IBinder onBind(Intent intent) {
79 if (DEBUG) Log.d(TAG, "onBind");
80
81 handleIntent(intent);
82
83 return null;
84 }
85
86 // Sets webContents to be the currently displayed webContents.
87 private void showWebContents(WebContents webContents) {
88 if (DEBUG) Log.d(TAG, "showWebContents");
89
90 // TODO(derekjchow): productVersion
91 mContentViewCore = new ContentViewCore(this, "");
92 mContentView = ContentView.createContentView(this, mContentViewCore);
93 mContentViewCore.initialize(ViewAndroidDelegate.createBasicDelegate(mCon tentView),
94 mContentView, webContents, mWindow);
95 // Enable display of current webContents.
96 mContentViewCore.onShow();
97 }
98
99 // Remove the currently displayed webContents. no-op if nothing is being dis played.
100 private void detachWebContentsIfAny() {
101 if (DEBUG) Log.d(TAG, "detachWebContentsIfAny");
102 if (mContentView != null) {
103 mContentView = null;
104 mContentViewCore = null;
105
106 // Inform CastContentWindowAndroid we're detaching.
107 CastWebContentsComponent.onComponentClosed(this, mInstanceId);
108 }
109 }
110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698