summaryrefslogtreecommitdiffstats
path: root/rdpweb/webclient.js
blob: ece8503f39d4eb17303267c41a3c54d613b14765 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/* JS helpers for the Flash RDP Web Control.
 *
 * Methods started with '_' are for internal use and must not be called.
 * Methods started with '_control' are called from the SWF.
 */
var RDPWebClient = {
    RDPWebUUID: "747f07ac-c30b-4439-826d-7b5c67fd47e7",
    embedSWF: function (FlashFileName, FlashId)
    {
      /* Create the Flash object. */
      var flashvars = {};
      flashvars.flashId = FlashId;

      var params = {};
      params.wmode="opaque";
      params.menu="false";
      params.bgcolor="#ffffff";
      params.quality="low";
      params.allowScriptAccess="always";

      var attributes = {};

      /* Make sure that the SWF will be reloaded from the server, not from browser cache. */
      var stamp = new Date();
      var seed = "?s=" + stamp.getTime();

      swfobject.embedSWF(FlashFileName + seed, FlashId, "100%", "100%", "9.0.0",
                         "", flashvars, params, attributes);
    },
    isRDPWebControlById: function(Id)
    {
        var flash = RDPWebClient.getFlashById(Id);
        return RDPWebClient.isRDPWebControlByElement(flash);
    },
    isRDPWebControlByElement: function(element)
    {
        if (element && element.getProperty)
        {
            var uuid = element.getProperty("UUID");
            if (uuid == RDPWebClient.RDPWebUUID)
            {
                return true;
            }
        }
        return false;
    },
    _controlInit: function (FlashId)
    {
        var flash = RDPWebClient.getFlashById(FlashId);

        if (flash)
        {
            if (window.addEventListener)
            {
                /* Mozilla */
                window.addEventListener("contextmenu", function(event) { return RDPWebClient._MozillaContextMenu(event); }, true);
                window.addEventListener("mousedown", function(event) { return RDPWebClient._MozillaMouse(event, true); }, true);
                window.addEventListener("mouseup", function(event) { return RDPWebClient._MozillaMouse(event, false); }, true);
                flash.addEventListener("mouseout", function(event) { return RDPWebClient._MozillaMouseOut(event); }, true);
            }
            else
            {
                document.oncontextmenu = function() { return RDPWebClient._IEContextMenu(); }
                flash.parentNode.onmousedown = function() { return RDPWebClient._IEMouse(true); }
                flash.parentNode.onmouseup = function() { return RDPWebClient._IEMouse(false); }
                flash.onmouseout=function() {return RDPWebClient._IEMouseOut(); }
            }
        }
    },
    _controlResize: function(flashId, width, height, reason)
    {
        var e = document.getElementById(flashId + 'Container');
        if (e)
        {
            e.style.width=width + "px";
            e.style.height=height +  "px";
        }
    },
    _IEMouseOut: function()
    {
        if (window.event && RDPWebClient.isRDPWebControlById(window.event.srcElement.id))
        {
            RDPWebClient._callMouseOut(window.event.srcElement.id);
        }
        return true;
    },
    _IECancelEvent: function()
    {
        window.event.returnValue = false;
        window.event.cancelBubble = true;
        return false;
    },
    _IEContextMenu: function()
    {
        if (window.event && RDPWebClient.isRDPWebControlById(window.event.srcElement.id))
        {
            return RDPWebClient._IECancelEvent();
        }
    },
    _IEMouse: function(fMouseDown)
    {
        if (window.event && RDPWebClient.isRDPWebControlById(window.event.srcElement.id))
        {
            if (window.event.button == 2)
            {
                if (fMouseDown == true)
                {
                    RDPWebClient.getFlashById(window.event.srcElement.id).parentNode.setCapture();
                    RDPWebClient._callRightMouseDown(window.event.srcElement.id);
                }
                else
                {
                    RDPWebClient._callRightMouseUp(window.event.srcElement.id);
                    RDPWebClient.getFlashById(window.event.srcElement.id).parentNode.releaseCapture();
                }
                return RDPWebClient._IECancelEvent();
            }
        }
    },
    _MozillaMouseOut: function(event)
    {
        if (RDPWebClient.isRDPWebControlById(event.target.id))
        {
            RDPWebClient._callMouseOut(event.target.id);
        }
        return true;
    },
    _MozillaCancelEvent: function(event)
    {
        if (event)
        {
            if (event.preventBubble) event.preventBubble();
            if (event.preventCapture) event.preventCapture();
            if (event.preventDefault) event.preventDefault();
            if (event.stopPropagation) event.stopPropagation();
        }
    },
    _MozillaContextMenu: function(event)
    {
        if (RDPWebClient.isRDPWebControlById(event.target.id))
        {
            RDPWebClient._MozillaCancelEvent(event);
        }
    },
    _MozillaMouse: function(event, fMouseDown)
    {
        if (RDPWebClient.isRDPWebControlById(event.target.id))
        {
            if (event.button == 2)
            {
                if (fMouseDown)
                {
                    RDPWebClient._callRightMouseDown(event.target.id);
                }
                else
                {
                    RDPWebClient._callRightMouseUp(event.target.id);
                }
                RDPWebClient._MozillaCancelEvent(event);
            }
        }
    },
    _callRightMouseDown: function(FlashId)
    {
        var flash = RDPWebClient.getFlashById(FlashId);
        if (flash && flash.rightMouseDown)
        {
            try
            {
                flash.rightMouseDown();
            }
            catch (e) {}; /* Hack for IE, which calls the Flash method but then throws the exception. */
        }
    },
    _callRightMouseUp: function(FlashId)
    {
        var flash = RDPWebClient.getFlashById(FlashId);
        if (flash && flash.rightMouseUp)
        {
            try
            {
               flash.rightMouseUp();
            }
            catch (e) {}; /* Hack for IE, which calls the Flash method but then throws the exception. */
        }
    },
    _callMouseOut: function(FlashId)
    {
        var flash = RDPWebClient.getFlashById(FlashId);
        if (flash && flash.mouseOut)
        {
            try
            {
               flash.mouseOut();
            }
            catch (e) {}; /* Hack for IE, which calls the Flash method but then throws the exception. */
        }
    },
    getFlashById: function(flashId)
    {
        if (document.embeds && document.embeds[flashId])
            return document.embeds[flashId];

        return document.getElementById(flashId);
    }
}