forked from mirrors/gecko-dev
Bug 1337467 - 1. Convert "Window:Resize" observer to event; r=rbarker Bug 1337467 - 2. Convert "ScrollTo:FocusedInput" observer to event; r=rbarker Bug 1337467 - 3. Convert "Update:CheckResult" observer to event; r=sebastian Also remove notifyCheckUpdateResult from GeckoInterface. Bug 1337467 - 4. Convert "GeckoView:ImportScript" observer to event; r=sebastian Bug 1337467 - 5. Convert accessibility observers to events; r=sebastian Bug 1337467 - 6. Convert media/casting observers to events; r=sebastian Bug 1337467 - 7. Convert "Sanitize:ClearData" observer to event; r=sebastian Bug 1337467 - 8. Convert "Notification:Event" observer to event; r=sebastian Bug 1337467 - 9. Convert BrowserApp observers to events; r=sebastian Bug 1337467 - 10. Convert Tab observers to events; r=sebastian Bug 1337467 - 11. Convert "Passwords:Init" and "FormHistory:Init" observers to events; r=sebastian Bug 1337467 - 12. Convert Reader observers to events; r=sebastian Bug 1337467 - 13. Convert Distribution observers to events; r=sebastian Bug 1337467 - 14. Convert "Fonts:Reload" observer to event; r=sebastian Bug 1337467 - 15. Convert RecentTabsAdapter observers to events; r=sebastian Bug 1337467 - 16. Convert "Session:Prefetch" observer to event; r=sebastian Bug 1337467 - 17. Convert "Browser:Quit" and "FullScreen:Exit" observers to events; r=sebastian Bug 1337467 - 18. Convert SessionStore observers to events; r=sebastian The "Session:NotifyLocationChange" observer is sent by browser.js and requires passing a browser reference, so it's left as an observer. Bug 1337467 - 19. Remove unused "Tab:Screenshot:Cancel" notifyObserver call; r=me Bug 1337467 - 20. Convert "Session:Navigate" observer to event; r=sebastian Bug 1337467 - 21. Convert "Locale:*" observers to events; r=sebastian Bug 1337467 - Add log for unhandled events; r=me Add back the log indicating no listener for an event, which can be useful when reading logcat. r=me for trivial change. Bug 1337467 - Don't return error from EventDispatcher when OnEvent fails; r=me When a listener's OnEvent method returns an error, continue to dispatch to other listeners and don't return an error from the dispatch function. This avoids unexpected errors when dispatching events. r=me for trivial patch.
107 lines
4.1 KiB
Java
107 lines
4.1 KiB
Java
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
* vim: ts=4 sw=4 expandtab:
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
import org.mozilla.gecko.R;
|
|
import org.mozilla.gecko.util.EventCallback;
|
|
import org.mozilla.gecko.util.GeckoBundle;
|
|
|
|
import com.google.android.gms.cast.CastDevice;
|
|
import com.google.android.gms.cast.CastRemoteDisplayLocalService;
|
|
import com.google.android.gms.common.ConnectionResult;
|
|
import com.google.android.gms.common.GooglePlayServicesUtil;
|
|
import com.google.android.gms.common.api.Status;
|
|
|
|
import android.app.PendingIntent;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.support.v7.media.MediaRouter.RouteInfo;
|
|
import android.util.Log;
|
|
|
|
public class ChromeCastDisplay implements GeckoPresentationDisplay {
|
|
|
|
static final String REMOTE_DISPLAY_APP_ID = "4574A331";
|
|
|
|
private static final String LOGTAG = "GeckoChromeCastDisplay";
|
|
private final Context context;
|
|
private final RouteInfo route;
|
|
private CastDevice castDevice;
|
|
|
|
public ChromeCastDisplay(Context context, RouteInfo route) {
|
|
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
|
|
if (status != ConnectionResult.SUCCESS) {
|
|
throw new IllegalStateException("Play services are required for Chromecast support (got status code " + status + ")");
|
|
}
|
|
|
|
this.context = context;
|
|
this.route = route;
|
|
this.castDevice = CastDevice.getFromBundle(route.getExtras());
|
|
}
|
|
|
|
@Override // GeckoPresentationDisplay
|
|
public GeckoBundle toBundle() {
|
|
if (castDevice == null) {
|
|
return null;
|
|
}
|
|
|
|
final GeckoBundle obj = new GeckoBundle(3);
|
|
obj.putString("uuid", route.getId());
|
|
obj.putString("friendlyName", castDevice.getFriendlyName());
|
|
obj.putString("type", "chromecast");
|
|
return obj;
|
|
}
|
|
|
|
@Override
|
|
public void start(final EventCallback callback) {
|
|
|
|
if (CastRemoteDisplayLocalService.getInstance() != null) {
|
|
Log.d(LOGTAG, "CastRemoteDisplayLocalService already existed.");
|
|
GeckoAppShell.notifyObservers("presentation-view-ready", route.getId());
|
|
callback.sendSuccess("Succeed to start presentation.");
|
|
return;
|
|
}
|
|
|
|
Intent intent = new Intent(context, RemotePresentationService.class);
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
PendingIntent notificationPendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
|
|
|
CastRemoteDisplayLocalService.NotificationSettings settings =
|
|
new CastRemoteDisplayLocalService.NotificationSettings.Builder()
|
|
.setNotificationPendingIntent(notificationPendingIntent).build();
|
|
|
|
CastRemoteDisplayLocalService.startService(
|
|
context,
|
|
RemotePresentationService.class,
|
|
REMOTE_DISPLAY_APP_ID,
|
|
castDevice,
|
|
settings,
|
|
new CastRemoteDisplayLocalService.Callbacks() {
|
|
@Override
|
|
public void onServiceCreated(CastRemoteDisplayLocalService service) {
|
|
((RemotePresentationService) service).setDeviceId(route.getId());
|
|
}
|
|
|
|
@Override
|
|
public void onRemoteDisplaySessionStarted(CastRemoteDisplayLocalService service) {
|
|
Log.d(LOGTAG, "Remote presentation launched!");
|
|
callback.sendSuccess("Succeed to start presentation.");
|
|
}
|
|
|
|
@Override
|
|
public void onRemoteDisplaySessionError(Status errorReason) {
|
|
int code = errorReason.getStatusCode();
|
|
callback.sendError("Fail to start presentation. Error code: " + code);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void stop(EventCallback callback) {
|
|
CastRemoteDisplayLocalService.stopService();
|
|
callback.sendSuccess("Succeed to stop presentation.");
|
|
}
|
|
}
|