Bug 1884547 - Skip Snap QA because of CAPCTHAs r=mboldan
[gecko.git] / toolkit / actors / ControllersChild.sys.mjs
blobd975c1f4314756b8c53d365fb9f8bcbaa66a44a2
1 /* vim: set ts=2 sw=2 sts=2 et tw=80: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 export class ControllersChild extends JSWindowActorChild {
7   receiveMessage(message) {
8     switch (message.name) {
9       case "ControllerCommands:Do":
10         if (this.docShell && this.docShell.isCommandEnabled(message.data)) {
11           this.docShell.doCommand(message.data);
12         }
13         break;
15       case "ControllerCommands:DoWithParams":
16         var data = message.data;
17         if (this.docShell && this.docShell.isCommandEnabled(data.cmd)) {
18           var params = Cu.createCommandParams();
19           let substituteXY = false;
20           let x = 0;
21           let y = 0;
22           if (
23             data.cmd == "cmd_lookUpDictionary" &&
24             "x" in data.params &&
25             "y" in data.params &&
26             data.params.x.type == "long" &&
27             data.params.y.type == "long"
28           ) {
29             substituteXY = true;
30             x = parseInt(data.params.x.value);
31             y = parseInt(data.params.y.value);
33             let rect =
34               this.contentWindow.windowUtils.convertFromParentProcessWidgetToLocal(
35                 x,
36                 y,
37                 1,
38                 1
39               );
40             x = Math.round(rect.x);
41             y = Math.round(rect.y);
42           }
44           for (var name in data.params) {
45             var value = data.params[name];
46             if (value.type == "long") {
47               if (substituteXY && name === "x") {
48                 params.setLongValue(name, x);
49               } else if (substituteXY && name === "y") {
50                 params.setLongValue(name, y);
51               } else {
52                 params.setLongValue(name, parseInt(value.value));
53               }
54             } else {
55               throw Components.Exception("", Cr.NS_ERROR_NOT_IMPLEMENTED);
56             }
57           }
58           this.docShell.doCommandWithParams(data.cmd, params);
59         }
60         break;
61     }
62   }