Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/child/dataCollector.js

Issue 29338283: Issue 3499 - Use the new messaging API for the issue reporter (Closed)
Patch Set: Created March 15, 2016, 10:57 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/content/ui/sendReport.js ('k') | lib/dataCollector.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** 18 /**
19 * @fileOverview Collects some data for a content window, to be attached to 19 * @fileOverview Collects some data for a content window, to be attached to
20 * issue reports. 20 * issue reports.
21 */ 21 */
22 22
23 "use strict"; 23 "use strict";
24 24
25 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); 25 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
26 let {Task} = Cu.import("resource://gre/modules/Task.jsm", {}); 26 let {Task} = Cu.import("resource://gre/modules/Task.jsm", {});
27 let {PrivateBrowsingUtils} = Cu.import("resource://gre/modules/PrivateBrowsingUt ils.jsm", {}); 27 let {PrivateBrowsingUtils} = Cu.import("resource://gre/modules/PrivateBrowsingUt ils.jsm", {});
28 28
29 let {port} = require("messaging");
29 let {Utils} = require("utils"); 30 let {Utils} = require("utils");
30 31
31 addMessageListener("AdblockPlus:CollectData", onCollectData); 32 port.on("collectData", onCollectData);
32 onShutdown.add(() => {
33 removeMessageListener("AdblockPlus:CollectData", onCollectData);
34 });
35 33
36 function onCollectData(message) 34 function onCollectData({outerWindowID, screenshotWidth}, sender)
37 { 35 {
38 let {outerWindowID, screenshotWidth, responseID} = message.data;
39
40 function success(data)
41 {
42 sendAsyncMessage("AdblockPlus:CollectDataResponse", {
43 responseID,
44 data
45 });
46 }
47
48 function error(e)
49 {
50 Cu.reportError(e);
51 sendAsyncMessage("AdblockPlus:CollectDataResponse", {
52 responseID,
53 data: null
54 });
55 }
56
57 let window = Services.wm.getOuterWindowWithId(outerWindowID); 36 let window = Services.wm.getOuterWindowWithId(outerWindowID);
58 if (window) 37 if (window)
59 { 38 {
60 Task.spawn(function*() 39 return Task.spawn(function*()
61 { 40 {
62 let data = {}; 41 let data = {};
63 data.isPrivate = PrivateBrowsingUtils.isContentWindowPrivate(window); 42 data.isPrivate = PrivateBrowsingUtils.isContentWindowPrivate(window);
64 data.opener = window.opener ? window.opener.location.href : null; 43 data.opener = window.opener ? window.opener.location.href : null;
65 data.referrer = window.document.referrer; 44 data.referrer = window.document.referrer;
66 data.frames = yield scanFrames(window); 45 data.frames = yield scanFrames(window);
67 data.screenshot = yield createScreenshot(window, screenshotWidth); 46 data.screenshot = yield createScreenshot(window, screenshotWidth);
68 return data; 47 return data;
69 }).then(success, error); 48 });
70 } 49 }
71 } 50 }
72 51
73 function scanFrames(window) 52 function scanFrames(window)
74 { 53 {
75 let frames = []; 54 let frames = [];
76 for (let i = 0; i < window.frames.length; i++) 55 for (let i = 0; i < window.frames.length; i++)
77 { 56 {
78 let frame = window.frames[i]; 57 let frame = window.frames[i];
79 frames.push({ 58 frames.push({
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 99
121 if (i % 5000 == 0) 100 if (i % 5000 == 0)
122 { 101 {
123 // Take a break every 5000 bytes to prevent browser hangs 102 // Take a break every 5000 bytes to prevent browser hangs
124 yield new Promise((resolve, reject) => Utils.runAsync(resolve)); 103 yield new Promise((resolve, reject) => Utils.runAsync(resolve));
125 } 104 }
126 } 105 }
127 106
128 return pixelData; 107 return pixelData;
129 } 108 }
OLDNEW
« no previous file with comments | « chrome/content/ui/sendReport.js ('k') | lib/dataCollector.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld