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

Side by Side Diff: chrome/content/ui/sendReport.js

Issue 29333308: Issue 3486 - Issue reporter: move frame scanning into the content process (Closed)
Patch Set: Created Jan. 7, 2016, 6:59 p.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 | « no previous file | lib/child/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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 subscriptionXML.setAttribute("softExpiration", subscription.softExpira tion - now); 310 subscriptionXML.setAttribute("softExpiration", subscription.softExpira tion - now);
311 if (subscription.expires) 311 if (subscription.expires)
312 subscriptionXML.setAttribute("hardExpiration", subscription.expires - now); 312 subscriptionXML.setAttribute("hardExpiration", subscription.expires - now);
313 subscriptionXML.setAttribute("downloadStatus", subscription.downloadStat us); 313 subscriptionXML.setAttribute("downloadStatus", subscription.downloadStat us);
314 } 314 }
315 } 315 }
316 callback(); 316 callback();
317 } 317 }
318 }; 318 };
319 319
320 var remoteDataSource =
321 {
322 collectData: function(wnd, windowURI, callback)
323 {
324 let outerWindowID = wnd.QueryInterface(Ci.nsIInterfaceRequestor)
325 .getInterface(Ci.nsIDOMWindowUtils)
326 .outerWindowID;
327 let dataCollector = require("dataCollector");
328 let screenshotWidth = screenshotDataSource.getWidth();
329 dataCollector.collectData(outerWindowID, screenshotWidth, data => {
330 screenshotDataSource.setData(data && data.screenshot);
331 framesDataSource.setData(windowURI, data && data.opener, data && data.refe rrer, data && data.frames);
332 callback();
333 });
334 }
335 }
336
320 var screenshotDataSource = 337 var screenshotDataSource =
321 { 338 {
322 imageOffset: 10, 339 imageOffset: 10,
323 340
324 // Fields used for user interaction 341 // Fields used for user interaction
325 _enabled: true, 342 _enabled: true,
326 _canvas: null, 343 _canvas: null,
327 _context: null, 344 _context: null,
328 _selectionType: "mark", 345 _selectionType: "mark",
329 _currentData: null, 346 _currentData: null,
330 _undoQueue: [], 347 _undoQueue: [],
331 348
332 collectData: function(wnd, windowURI, callback) 349 getWidth: function()
333 { 350 {
334 let outerWindowID = wnd.QueryInterface(Ci.nsIInterfaceRequestor)
335 .getInterface(Ci.nsIDOMWindowUtils)
336 .outerWindowID;
337 let dataCollector = require("dataCollector");
338 let canvas = E("screenshotCanvas"); 351 let canvas = E("screenshotCanvas");
339 let screenshotWidth = canvas.offsetWidth - this.imageOffset * 2; 352 return canvas.offsetWidth - this.imageOffset * 2;
353 },
354
355 setData: function(screenshot)
356 {
357 let canvas = E("screenshotCanvas");
340 358
341 // Do not resize canvas any more (no idea why Gecko requires both to be set) 359 // Do not resize canvas any more (no idea why Gecko requires both to be set)
342 canvas.parentNode.style.MozBoxAlign = "center"; 360 canvas.parentNode.style.MozBoxAlign = "center";
343 canvas.parentNode.align = "center"; 361 canvas.parentNode.align = "center";
344 362
345 // Init canvas settings 363 // Init canvas settings
346 let context = canvas.getContext("2d"); 364 let context = canvas.getContext("2d");
347 context.fillStyle = "rgb(0, 0, 0)"; 365 context.fillStyle = "rgb(0, 0, 0)";
348 context.strokeStyle = "rgba(255, 0, 0, 0.7)"; 366 context.strokeStyle = "rgba(255, 0, 0, 0.7)";
349 context.lineWidth = 3; 367 context.lineWidth = 3;
350 context.lineJoin = "round"; 368 context.lineJoin = "round";
351 369
352 this._canvas = canvas; 370 this._canvas = canvas;
353 this._context = context; 371 this._context = context;
354 372
355 dataCollector.collectData(outerWindowID, screenshotWidth, data => { 373 if (screenshot)
356 if (data && data.screenshot) 374 {
357 { 375 let image = new Image();
358 let image = new Image(); 376 image.src = screenshot;
359 image.src = data.screenshot; 377 image.addEventListener("load", () => {
360 image.addEventListener("load", () => { 378 canvas.width = image.width + this.imageOffset * 2;
361 canvas.width = image.width + this.imageOffset * 2; 379 canvas.height = image.height + this.imageOffset * 2;
362 canvas.height = image.height + this.imageOffset * 2; 380 context.drawImage(image, this.imageOffset, this.imageOffset);
363 context.drawImage(image, this.imageOffset, this.imageOffset); 381 });
364 }); 382 }
365 }
366 callback();
367 });
368 }, 383 },
369 384
370 get enabled() this._enabled, 385 get enabled() this._enabled,
371 set enabled(enabled) 386 set enabled(enabled)
372 { 387 {
373 if (this._enabled == enabled) 388 if (this._enabled == enabled)
374 return; 389 return;
375 390
376 this._enabled = enabled; 391 this._enabled = enabled;
377 this._canvas.style.opacity = this._enabled ? "" : "0.3" 392 this._canvas.style.opacity = this._enabled ? "" : "0.3"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 537
523 if (!this._undoQueue.length) 538 if (!this._undoQueue.length)
524 E("screenshotUndoButton").disabled = true; 539 E("screenshotUndoButton").disabled = true;
525 } 540 }
526 }; 541 };
527 542
528 var framesDataSource = 543 var framesDataSource =
529 { 544 {
530 site: null, 545 site: null,
531 546
532 collectData: function(wnd, windowURI, callback) 547 setData: function(windowURI, opener, referrer, frames)
533 { 548 {
534 try 549 try
535 { 550 {
536 this.site = windowURI.host; 551 this.site = windowURI.host;
537 if (this.site) 552 if (this.site)
538 document.title += " (" + this.site + ")"; 553 document.title += " (" + this.site + ")";
539 } 554 }
540 catch (e) 555 catch (e)
541 { 556 {
542 // Expected exception - not all URL schemes have a host name 557 // Expected exception - not all URL schemes have a host name
543 } 558 }
544 559
545 let window = reportElement("window"); 560 let window = reportElement("window");
546 window.setAttribute("url", censorURL(windowURI ? windowURI.spec : wnd.locati on.href)); 561 window.setAttribute("url", censorURL(windowURI.spec));
547 if (wnd.opener && wnd.opener.location.href) 562 if (opener)
548 window.setAttribute("opener", censorURL(wnd.opener.location.href)); 563 window.setAttribute("opener", censorURL(opener));
549 if (wnd.document.referrer) 564 if (referrer)
550 window.setAttribute("referrer", censorURL(wnd.document.referrer)); 565 window.setAttribute("referrer", censorURL(referrer));
551 this.scanFrames(wnd, window); 566 this.addFrames(frames || [], window);
552
553 callback();
554 }, 567 },
555 568
556 scanFrames: function(wnd, xmlList) 569 addFrames: function(frames, xmlList)
557 { 570 {
558 try 571 for (let frame of frames)
559 { 572 {
560 for (let i = 0; i < wnd.frames.length; i++) 573 let frameXML = appendElement(xmlList, "frame", {
561 { 574 url: censorURL(frame.url)
562 let frame = wnd.frames[i]; 575 });
563 let frameXML = appendElement(xmlList, "frame", { 576 this.addFrames(frame.frames, frameXML);
564 url: censorURL(frame.location.href)
565 });
566 this.scanFrames(frame, frameXML);
567 }
568 }
569 catch (e)
570 {
571 // Don't break if something goes wrong
572 Cu.reportError(e);
573 } 577 }
574 } 578 }
575 }; 579 };
576 580
577 var errorsDataSource = 581 var errorsDataSource =
578 { 582 {
579 collectData: function(wnd, windowURI, callback) 583 collectData: function(wnd, windowURI, callback)
580 { 584 {
581 let {addonID} = require("info"); 585 let {addonID} = require("info");
582 addonID = addonID.replace(/[\{\}]/g, ""); 586 addonID = addonID.replace(/[\{\}]/g, "");
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 subscription.disabled = false; 1142 subscription.disabled = false;
1139 1143
1140 node.parentNode.removeChild(node); 1144 node.parentNode.removeChild(node);
1141 if (!E("issuesDisabledSubscriptions").firstChild) 1145 if (!E("issuesDisabledSubscriptions").firstChild)
1142 E("issuesDisabledSubscriptionsBox").hidden = true; 1146 E("issuesDisabledSubscriptionsBox").hidden = true;
1143 this.forceReload(); 1147 this.forceReload();
1144 } 1148 }
1145 }; 1149 };
1146 1150
1147 let dataCollectors = [reportsListDataSource, requestsDataSource, filtersDataSour ce, subscriptionsDataSource, 1151 let dataCollectors = [reportsListDataSource, requestsDataSource, filtersDataSour ce, subscriptionsDataSource,
1148 screenshotDataSource, framesDataSource, errorsDataSource, extensionsDataSource, 1152 remoteDataSource, errorsDataSource, extensionsDataSource,
1149 subscriptionUpdateDataSource, issuesDataSource]; 1153 subscriptionUpdateDataSource, issuesDataSource];
1150 1154
1151 // 1155 //
1152 // Wizard logic 1156 // Wizard logic
1153 // 1157 //
1154 1158
1155 function initWizard() 1159 function initWizard()
1156 { 1160 {
1157 // Make sure no issue type is selected by default 1161 // Make sure no issue type is selected by default
1158 E("typeGroup").selectedItem = null; 1162 E("typeGroup").selectedItem = null;
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 1549
1546 function censorURL(url) 1550 function censorURL(url)
1547 { 1551 {
1548 return url.replace(/([?;&\/#][^?;&\/#]+?=)[^?;&\/#]+/g, "$1*"); 1552 return url.replace(/([?;&\/#][^?;&\/#]+?=)[^?;&\/#]+/g, "$1*");
1549 } 1553 }
1550 1554
1551 function encodeHTML(str) 1555 function encodeHTML(str)
1552 { 1556 {
1553 return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"). replace(/"/g, "&quot;"); 1557 return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"). replace(/"/g, "&quot;");
1554 } 1558 }
OLDNEW
« no previous file with comments | « no previous file | lib/child/dataCollector.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld