Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | let testPort, sidebarPort, apiPort; |
michael@0 | 6 | |
michael@0 | 7 | onconnect = function(e) { |
michael@0 | 8 | let port = e.ports[0]; |
michael@0 | 9 | port.onmessage = function onMessage(event) { |
michael@0 | 10 | let topic = event.data.topic; |
michael@0 | 11 | switch (topic) { |
michael@0 | 12 | case "test-init": |
michael@0 | 13 | testPort = port; |
michael@0 | 14 | port.postMessage({topic: "test-init-done"}); |
michael@0 | 15 | break; |
michael@0 | 16 | case "ping": |
michael@0 | 17 | port.postMessage({topic: "pong"}); |
michael@0 | 18 | break; |
michael@0 | 19 | case "test-logout": |
michael@0 | 20 | apiPort.postMessage({topic: "social.user-profile", data: {}}); |
michael@0 | 21 | break; |
michael@0 | 22 | case "sidebar-message": |
michael@0 | 23 | sidebarPort = port; |
michael@0 | 24 | if (testPort && event.data.result == "ok") |
michael@0 | 25 | testPort.postMessage({topic:"got-sidebar-message"}); |
michael@0 | 26 | break; |
michael@0 | 27 | case "service-window-message": |
michael@0 | 28 | testPort.postMessage({topic:"got-service-window-message", |
michael@0 | 29 | location: event.data.location}); |
michael@0 | 30 | break; |
michael@0 | 31 | case "service-window-closed-message": |
michael@0 | 32 | testPort.postMessage({topic:"got-service-window-closed-message"}); |
michael@0 | 33 | break; |
michael@0 | 34 | case "test-service-window": |
michael@0 | 35 | sidebarPort.postMessage({topic:"test-service-window"}); |
michael@0 | 36 | break; |
michael@0 | 37 | case "test-service-window-twice": |
michael@0 | 38 | sidebarPort.postMessage({topic:"test-service-window-twice"}); |
michael@0 | 39 | break; |
michael@0 | 40 | case "test-service-window-twice-result": |
michael@0 | 41 | testPort.postMessage({topic: "test-service-window-twice-result", result: event.data.result }) |
michael@0 | 42 | break; |
michael@0 | 43 | case "test-close-service-window": |
michael@0 | 44 | sidebarPort.postMessage({topic:"test-close-service-window"}); |
michael@0 | 45 | break; |
michael@0 | 46 | case "panel-message": |
michael@0 | 47 | if (testPort && event.data.result == "ok") |
michael@0 | 48 | testPort.postMessage({topic:"got-panel-message", |
michael@0 | 49 | location: event.data.location |
michael@0 | 50 | }); |
michael@0 | 51 | break; |
michael@0 | 52 | case "status-panel-visibility": |
michael@0 | 53 | testPort.postMessage({topic:"got-social-panel-visibility", result: event.data.result }); |
michael@0 | 54 | break; |
michael@0 | 55 | case "test-chatbox-open": |
michael@0 | 56 | sidebarPort.postMessage(event.data); |
michael@0 | 57 | break; |
michael@0 | 58 | case "chatbox-opened": |
michael@0 | 59 | testPort.postMessage(event.data); |
michael@0 | 60 | break; |
michael@0 | 61 | case "chatbox-message": |
michael@0 | 62 | testPort.postMessage({topic:"got-chatbox-message", result: event.data.result}); |
michael@0 | 63 | break; |
michael@0 | 64 | case "chatbox-visibility": |
michael@0 | 65 | testPort.postMessage({topic:"got-chatbox-visibility", result: event.data.result}); |
michael@0 | 66 | break; |
michael@0 | 67 | case "test-flyout-open": |
michael@0 | 68 | sidebarPort.postMessage({topic:"test-flyout-open"}); |
michael@0 | 69 | break; |
michael@0 | 70 | case "flyout-message": |
michael@0 | 71 | testPort.postMessage({topic:"got-flyout-message", result: event.data.result}); |
michael@0 | 72 | break; |
michael@0 | 73 | case "flyout-visibility": |
michael@0 | 74 | testPort.postMessage({topic:"got-flyout-visibility", result: event.data.result}); |
michael@0 | 75 | break; |
michael@0 | 76 | case "test-flyout-close": |
michael@0 | 77 | sidebarPort.postMessage({topic:"test-flyout-close"}); |
michael@0 | 78 | break; |
michael@0 | 79 | case "test-worker-chat": |
michael@0 | 80 | apiPort.postMessage({topic: "social.request-chat", data: event.data.data }); |
michael@0 | 81 | break; |
michael@0 | 82 | case "social.initialize": |
michael@0 | 83 | // This is the workerAPI port, respond and set up a notification icon. |
michael@0 | 84 | // For multiprovider tests, we support acting like different providers |
michael@0 | 85 | // based on the domain we load from. |
michael@0 | 86 | apiPort = port; |
michael@0 | 87 | // purposely fall through and set the profile on initialization |
michael@0 | 88 | case "test-set-profile": |
michael@0 | 89 | let profile; |
michael@0 | 90 | if (location.href.indexOf("https://test1.example.com") == 0) { |
michael@0 | 91 | profile = { |
michael@0 | 92 | portrait: "https://test1.example.com/portrait.jpg", |
michael@0 | 93 | userName: "tester", |
michael@0 | 94 | displayName: "Test1 User", |
michael@0 | 95 | }; |
michael@0 | 96 | } else { |
michael@0 | 97 | profile = { |
michael@0 | 98 | portrait: "https://example.com/portrait.jpg", |
michael@0 | 99 | userName: "trickster", |
michael@0 | 100 | displayName: "Kuma Lisa", |
michael@0 | 101 | profileURL: "http://en.wikipedia.org/wiki/Kuma_Lisa" |
michael@0 | 102 | }; |
michael@0 | 103 | } |
michael@0 | 104 | apiPort.postMessage({topic: "social.user-profile", data: profile}); |
michael@0 | 105 | break; |
michael@0 | 106 | case "test-ambient-notification": |
michael@0 | 107 | apiPort.postMessage({topic: "social.ambient-notification", data: event.data.data}); |
michael@0 | 108 | break; |
michael@0 | 109 | case "test-isVisible": |
michael@0 | 110 | sidebarPort.postMessage({topic: "test-isVisible"}); |
michael@0 | 111 | break; |
michael@0 | 112 | case "test-isVisible-response": |
michael@0 | 113 | testPort.postMessage({topic: "got-isVisible-response", result: event.data.result}); |
michael@0 | 114 | break; |
michael@0 | 115 | case "share-data-message": |
michael@0 | 116 | if (testPort) |
michael@0 | 117 | testPort.postMessage({topic:"got-share-data-message", result: event.data.result}); |
michael@0 | 118 | break; |
michael@0 | 119 | case "worker.update": |
michael@0 | 120 | apiPort.postMessage({topic: 'social.manifest-get'}); |
michael@0 | 121 | break; |
michael@0 | 122 | case "social.manifest": |
michael@0 | 123 | event.data.data.version = 2; |
michael@0 | 124 | apiPort.postMessage({topic: 'social.manifest-set', data: event.data.data}); |
michael@0 | 125 | break; |
michael@0 | 126 | } |
michael@0 | 127 | } |
michael@0 | 128 | } |