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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/media/remote/CastNotificationControl.java

Issue 2860633002: [Cast,Android] Add origin to the Cast notification (Closed)
Patch Set: Use the tab's URL Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/media/remote/CastNotificationControl.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/remote/CastNotificationControl.java b/chrome/android/java/src/org/chromium/chrome/browser/media/remote/CastNotificationControl.java
index ff276749050a0a116b3578e76231ff3dd09142c3..809f55e07621ee96cc642ce9725146f0d84ef75d 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/media/remote/CastNotificationControl.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/media/remote/CastNotificationControl.java
@@ -5,21 +5,29 @@
package org.chromium.chrome.browser.media.remote;
import android.annotation.SuppressLint;
+import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.media.AudioManager;
+import org.chromium.base.ApplicationStatus;
+import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
+import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.media.remote.RemoteVideoInfo.PlayerState;
import org.chromium.chrome.browser.media.ui.MediaNotificationInfo;
import org.chromium.chrome.browser.media.ui.MediaNotificationListener;
import org.chromium.chrome.browser.media.ui.MediaNotificationManager;
import org.chromium.chrome.browser.metrics.MediaNotificationUma;
import org.chromium.chrome.browser.tab.Tab;
+import org.chromium.components.url_formatter.UrlFormatter;
import org.chromium.content_public.common.MediaMetadata;
+import java.net.URI;
+import java.net.URISyntaxException;
+
import javax.annotation.Nullable;
/**
@@ -28,6 +36,7 @@ import javax.annotation.Nullable;
*/
public class CastNotificationControl implements MediaRouteController.UiListener,
MediaNotificationListener, AudioManager.OnAudioFocusChangeListener {
+ private static final String TAG = "MediaFling";
@SuppressLint("StaticFieldLeak")
private static CastNotificationControl sInstance;
@@ -118,6 +127,11 @@ public class CastNotificationControl implements MediaRouteController.UiListener,
updateNotificationBuilderIfPosterIsGoodEnough();
mState = initialState;
+
+ // Set origin once per the notification so it doesn't change if another tab becomes active.
+ String origin = getCurrentTabOrigin();
+ if (origin != null) mNotificationBuilder.setOrigin(origin);
+
updateNotification();
mIsShowing = true;
}
@@ -133,6 +147,7 @@ public class CastNotificationControl implements MediaRouteController.UiListener,
if (mNotificationBuilder == null) return;
mNotificationBuilder.setMetadata(new MediaMetadata(mTitle, "", ""));
+
if (mState == PlayerState.PAUSED || mState == PlayerState.PLAYING) {
mNotificationBuilder.setPaused(mState != PlayerState.PLAYING);
mNotificationBuilder.setActions(MediaNotificationInfo.ACTION_STOP
@@ -248,4 +263,23 @@ public class CastNotificationControl implements MediaRouteController.UiListener,
mNotificationBuilder.setMediaSessionImage(poster);
}
}
+
+ private String getCurrentTabOrigin() {
+ Activity activity = ApplicationStatus.getLastTrackedFocusedActivity();
dgn 2017/05/04 09:56:03 post-review nit: Is it possible that content start
+
+ if (!(activity instanceof ChromeTabbedActivity)) return null;
+
+ Tab tab = ((ChromeTabbedActivity) activity).getActivityTab();
+ if (tab == null || !tab.isInitialized()) return null;
+
+ String url = tab.getUrl();
+ try {
+ return UrlFormatter.formatUrlForSecurityDisplay(new URI(url), true);
+ } catch (URISyntaxException | UnsatisfiedLinkError e) {
+ // UnstatisfiedLinkError can only happen in tests as the natives are not initialized
+ // yet.
+ Log.e(TAG, "Unable to parse the origin from the URL. Using the full URL instead.");
+ return url;
+ }
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698