OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 var backgroundSetup = {} |
| 6 |
| 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; |
| 13 |
| 14 return { |
| 15 "id": id, |
| 16 "title": title, |
| 17 "tabId": tabId |
| 18 }; |
| 19 } |
| 20 |
| 21 var receiversActivities = []; |
| 22 // Add a new receiver. |activityTitle| and |activityTabId| are optional |
| 23 // parameters. |
| 24 addReceiver = function(id, receiverName, activityTitle, activityTabId) { |
| 25 receiversActivities.push({ |
| 26 "activity": tryCreateActivity_(id, activityTitle, activityTabId), |
| 27 "receiver": { |
| 28 "id": id, |
| 29 "name": receiverName |
| 30 } |
| 31 }); |
| 32 } |
| 33 // Required API method. |
| 34 getMirrorCapableReceiversAndActivities = function() { |
| 35 // For all of the API methods, we verify that |this| points to |
| 36 // backgroundSetup. In the actual extension, the API methods are |
| 37 // also free-standing but they are really class methods on backgroundSetup. |
| 38 if (this !== backgroundSetup) |
| 39 throw 'this !== backgroundSetup'; |
| 40 |
| 41 return receiversActivities; |
| 42 } |
| 43 |
| 44 var stopMirroringReason = ""; |
| 45 var stopMirroringCalled = false; |
| 46 wasStopMirroringCalledWithUserStop = function() { |
| 47 return stopMirroringCalled && stopMirroringReason == 'user-stop'; |
| 48 } |
| 49 // Required API method. |
| 50 stopMirroring = function(reason) { |
| 51 if (this !== backgroundSetup) |
| 52 throw 'this !== backgroundSetup'; |
| 53 |
| 54 stopMirroringReason = reason; |
| 55 stopMirroringCalled = true; |
| 56 |
| 57 var foundActivity = false; |
| 58 for (item of receiversActivities) { |
| 59 if (item.activity != null) { |
| 60 item.activity = null; |
| 61 foundActivity = true; |
| 62 } |
| 63 } |
| 64 if (foundActivity === false) |
| 65 throw 'stopMirroring called when there was nothing being mirrored' |
| 66 } |
| 67 |
| 68 var launchTabId = 1; |
| 69 var launchTabTitle = "Fake Cast"; |
| 70 var launchDesktopMirroringReceiverId = ""; |
| 71 getLaunchDesktopMirroringReceiverId = function() { |
| 72 return launchDesktopMirroringReceiverId; |
| 73 } |
| 74 // Required API method. |
| 75 launchDesktopMirroring = function(receiverId) { |
| 76 if (this !== backgroundSetup) |
| 77 throw 'this !== backgroundSetup'; |
| 78 |
| 79 launchDesktopMirroringReceiverId = receiverId; |
| 80 |
| 81 for (item of receiversActivities) { |
| 82 if (item.receiver.id == receiverId) { |
| 83 item.activity = |
| 84 tryCreateActivity_(receiverId, launchTabId, launchTabTitle); |
| 85 break; |
| 86 } |
| 87 } |
| 88 } |
OLD | NEW |