[MacViews] Show comboboxes with a native NSMenu
[chromium-blink-merge.git] / chrome / test / data / extensions / tray_cast / background.js
blob2ea871a1ea412cff62369b1db7a9705e3a0eb713
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var backgroundSetup = {}
7 // If all required activity information is available, then this will return an
8 // activity structure; otherwise, it will return null. This lets us
9 // unconditionally assign to the 'activity' field in a JSON object.
10 tryCreateActivity_ = function(id, title, tabId) {
11 if (id === undefined || title === undefined || tabId === undefined)
12 return null;
14 return {
15 'id': id,
16 'title': title,
17 'tabId': tabId
21 var receiversActivities = [];
22 var sendDevices = function() {
23 chrome.cast.devicesPrivate.updateDevices(receiversActivities);
25 chrome.cast.devicesPrivate.updateDevicesRequested.addListener(sendDevices);
27 // Add a new receiver. |activityTitle| and |activityTabId| are optional
28 // parameters.
29 var addReceiver = function(id, receiverName, activityTitle, activityTabId) {
30 receiversActivities.push({
31 'receiver': {
32 'id': id,
33 'name': receiverName
35 'activity': tryCreateActivity_(id, activityTitle, activityTabId)
36 });
38 sendDevices();
41 var stopMirroringCalled = false;
42 chrome.cast.devicesPrivate.stopCast.addListener(function(reason) {
43 if (reason !== 'user-stop')
44 throw 'expected reason to be "user-stop"';
46 var foundActivity = false;
47 for (item of receiversActivities) {
48 if (item.activity != null) {
49 item.activity = null;
50 foundActivity = true;
53 if (foundActivity === false)
54 throw 'stopMirroring called when there was nothing being mirrored'
56 stopMirroringCalled = true;
57 sendDevices();
58 });
61 var launchDesktopMirroringReceiverId = '';
62 chrome.cast.devicesPrivate.startCast.addListener(function(receiverId) {
63 launchDesktopMirroringReceiverId = receiverId;
65 var tabTitle = 'Tab Title';
66 var tabId = 1;
68 for (item of receiversActivities) {
69 if (item.receiver.id == receiverId) {
70 item.activity = tryCreateActivity_(receiverId, tabTitle, tabId);
71 break;
75 sendDevices();
76 });