| Index: chrome/android/java/src/org/chromium/chrome/browser/media/MediaCaptureNotificationService.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/MediaCaptureNotificationService.java b/chrome/android/java/src/org/chromium/chrome/browser/media/MediaCaptureNotificationService.java
|
| index 44e8838341b16c7dc730d63d857e565bf488c85d..4561b25656f26755051e7314b2a47cc8325814e7 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/media/MediaCaptureNotificationService.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/media/MediaCaptureNotificationService.java
|
| @@ -19,6 +19,7 @@ import org.chromium.base.ContextUtils;
|
| import org.chromium.base.Log;
|
| import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.tab.Tab;
|
| +import org.chromium.chrome.browser.tab.TabWebContentsDelegateAndroid;
|
|
|
| import java.net.MalformedURLException;
|
| import java.net.URL;
|
| @@ -36,6 +37,12 @@ public class MediaCaptureNotificationService extends Service {
|
| private static final String NOTIFICATION_ID_EXTRA = "NotificationId";
|
| private static final String NOTIFICATION_MEDIA_TYPE_EXTRA = "NotificationMediaType";
|
| private static final String NOTIFICATION_MEDIA_URL_EXTRA = "NotificationMediaUrl";
|
| + private static final String ACTION_MEDIA_CAPTURE_UPDATE =
|
| + "org.chromium.chrome.browser.media.SCREEN_CAPTURE_UPDATE";
|
| + private static final String ACTION_SCREEN_CAPTURE_STOP =
|
| + "org.chromium.chrome.browser.media.SCREEN_CAPTURE_STOP";
|
| + private static final String ACTION_SCREEN_CAPTURE_DISMISS =
|
| + "org.chromium.chrome.browser.media.SCREEN_CAPTURE_DISMISS";
|
|
|
| private static final String WEBRTC_NOTIFICATION_IDS = "WebRTCNotificationIds";
|
| private static final String TAG = "MediaCapture";
|
| @@ -44,6 +51,7 @@ public class MediaCaptureNotificationService extends Service {
|
| private static final int MEDIATYPE_AUDIO_AND_VIDEO = 1;
|
| private static final int MEDIATYPE_VIDEO_ONLY = 2;
|
| private static final int MEDIATYPE_AUDIO_ONLY = 3;
|
| + private static final int MEDIATYPE_SCREEN_CAPTURE = 4;
|
|
|
| private NotificationManager mNotificationManager;
|
| private Context mContext;
|
| @@ -83,10 +91,31 @@ public class MediaCaptureNotificationService extends Service {
|
| cancelPreviousWebRtcNotifications();
|
| stopSelf();
|
| } else {
|
| - updateNotification(
|
| - intent.getIntExtra(NOTIFICATION_ID_EXTRA, Tab.INVALID_TAB_ID),
|
| - intent.getIntExtra(NOTIFICATION_MEDIA_TYPE_EXTRA, MEDIATYPE_NO_MEDIA),
|
| - intent.getStringExtra(NOTIFICATION_MEDIA_URL_EXTRA));
|
| + String action = intent.getAction();
|
| + int notificationId = intent.getIntExtra(NOTIFICATION_ID_EXTRA, Tab.INVALID_TAB_ID);
|
| + int mediaType = intent.getIntExtra(NOTIFICATION_MEDIA_TYPE_EXTRA, MEDIATYPE_NO_MEDIA);
|
| + String url = intent.getStringExtra(NOTIFICATION_MEDIA_URL_EXTRA);
|
| +
|
| + switch (action) {
|
| + case ACTION_MEDIA_CAPTURE_UPDATE:
|
| + updateNotification(notificationId, mediaType, url);
|
| + break;
|
| +
|
| + case ACTION_SCREEN_CAPTURE_STOP:
|
| + // Notify native to stop screen capture when the STOP button in notification
|
| + // is clicked.
|
| + TabWebContentsDelegateAndroid.notifyStopped(notificationId);
|
| + break;
|
| +
|
| + case ACTION_SCREEN_CAPTURE_DISMISS:
|
| + // Update current notification without head up when the DISMISS button in
|
| + // notification is clicked.
|
| + createNotification(notificationId, mediaType, url, false);
|
| + break;
|
| +
|
| + default:
|
| + break;
|
| + }
|
| }
|
| return super.onStartCommand(intent, flags, startId);
|
| }
|
| @@ -122,7 +151,7 @@ public class MediaCaptureNotificationService extends Service {
|
| }
|
| destroyNotification(notificationId);
|
| if (mediaType != MEDIATYPE_NO_MEDIA) {
|
| - createNotification(notificationId, mediaType, url);
|
| + createNotification(notificationId, mediaType, url, true);
|
| }
|
| if (mNotifications.size() == 0) stopSelf();
|
| }
|
| @@ -145,7 +174,7 @@ public class MediaCaptureNotificationService extends Service {
|
| * @param mediaType Media type of the notification.
|
| * @param url Url of the current webrtc call.
|
| */
|
| - private void createNotification(int notificationId, int mediaType, String url) {
|
| + private void createNotification(int notificationId, int mediaType, String url, boolean headup) {
|
| int notificationContentTextId = 0;
|
| int notificationIconId = 0;
|
| if (mediaType == MEDIATYPE_AUDIO_AND_VIDEO) {
|
| @@ -157,6 +186,9 @@ public class MediaCaptureNotificationService extends Service {
|
| } else if (mediaType == MEDIATYPE_AUDIO_ONLY) {
|
| notificationContentTextId = R.string.audio_call_notification_text_2;
|
| notificationIconId = R.drawable.webrtc_audio;
|
| + } else if (mediaType == MEDIATYPE_SCREEN_CAPTURE) {
|
| + notificationContentTextId = R.string.screen_capture_notification_text;
|
| + notificationIconId = R.drawable.webrtc_video;
|
| }
|
|
|
| NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext)
|
| @@ -166,15 +198,37 @@ public class MediaCaptureNotificationService extends Service {
|
| .setSmallIcon(notificationIconId)
|
| .setLocalOnly(true);
|
|
|
| - StringBuilder contentText = new StringBuilder(
|
| - mContext.getResources().getString(notificationContentTextId)).append('.');
|
| + StringBuilder contentText =
|
| + new StringBuilder(mContext.getResources().getString(notificationContentTextId, url))
|
| + .append('.');
|
| Intent tabIntent = Tab.createBringTabToFrontIntent(notificationId);
|
| if (tabIntent != null) {
|
| PendingIntent contentIntent = PendingIntent.getActivity(
|
| mContext, notificationId, tabIntent, 0);
|
| builder.setContentIntent(contentIntent);
|
| - contentText.append(
|
| - mContext.getResources().getString(R.string.media_notification_link_text, url));
|
| + if (mediaType == MEDIATYPE_SCREEN_CAPTURE) {
|
| + // To screen capture notification, add two action buttons and enable head up
|
| + // notification if needed.
|
| + if (headup) {
|
| + // Enable the head up notification. Click Dismiss button to dismiss the head up
|
| + // notification.
|
| + builder.addAction(R.drawable.btn_close, "Dismiss",
|
| + buildPendingIntent(ACTION_SCREEN_CAPTURE_DISMISS, notificationId,
|
| + mediaType, url));
|
| + builder.setPriority(Notification.PRIORITY_HIGH);
|
| + builder.setVibrate(new long[0]);
|
| + } else {
|
| + // Disable the head up notification. Click Dismiss button to bring tab to
|
| + // front.
|
| + builder.addAction(R.drawable.btn_close, "Dismiss", contentIntent);
|
| + }
|
| + builder.addAction(R.drawable.ic_vidcontrol_stop, "Stop",
|
| + buildPendingIntent(ACTION_SCREEN_CAPTURE_STOP, notificationId, mediaType,
|
| + url));
|
| + } else {
|
| + contentText.append(mContext.getResources().getString(
|
| + R.string.media_notification_link_text, url));
|
| + }
|
| } else {
|
| contentText.append(" ").append(url);
|
| }
|
| @@ -227,10 +281,13 @@ public class MediaCaptureNotificationService extends Service {
|
| /**
|
| * @param audio If audio is being captured.
|
| * @param video If video is being captured.
|
| + * @param screen If screen is being captured.
|
| * @return A constant identify what media is being captured.
|
| */
|
| - public static int getMediaType(boolean audio, boolean video) {
|
| - if (audio && video) {
|
| + public static int getMediaType(boolean audio, boolean video, boolean screen) {
|
| + if (screen) {
|
| + return MEDIATYPE_SCREEN_CAPTURE;
|
| + } else if (audio && video) {
|
| return MEDIATYPE_AUDIO_AND_VIDEO;
|
| } else if (audio) {
|
| return MEDIATYPE_AUDIO_ONLY;
|
| @@ -264,10 +321,10 @@ public class MediaCaptureNotificationService extends Service {
|
| * @param fullUrl Url of the current webrtc call.
|
| */
|
| public static void updateMediaNotificationForTab(
|
| - Context context, int tabId, boolean audio, boolean video, String fullUrl) {
|
| - int mediaType = getMediaType(audio, video);
|
| + Context context, int tabId, int mediaType, String fullUrl) {
|
| if (!shouldStartService(context, mediaType, tabId)) return;
|
| Intent intent = new Intent(context, MediaCaptureNotificationService.class);
|
| + intent.setAction(ACTION_MEDIA_CAPTURE_UPDATE);
|
| intent.putExtra(NOTIFICATION_ID_EXTRA, tabId);
|
| String baseUrl = fullUrl;
|
| try {
|
| @@ -293,4 +350,18 @@ public class MediaCaptureNotificationService extends Service {
|
|
|
| context.startService(new Intent(context, MediaCaptureNotificationService.class));
|
| }
|
| +
|
| + /**
|
| + * Build PendingIntent for the actions of screen capture notification.
|
| + */
|
| + private PendingIntent buildPendingIntent(
|
| + String action, int notificationId, int mediaType, String url) {
|
| + Intent intent = new Intent(this, MediaCaptureNotificationService.class);
|
| + intent.setAction(action);
|
| + intent.putExtra(NOTIFICATION_ID_EXTRA, notificationId);
|
| + intent.putExtra(NOTIFICATION_MEDIA_TYPE_EXTRA, mediaType);
|
| + intent.putExtra(NOTIFICATION_MEDIA_URL_EXTRA, url);
|
| + return PendingIntent.getService(
|
| + mContext, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
| + }
|
| }
|
|
|