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

Delta Between Two Patch Sets: lib/child/frameScript.js

Issue 29338242: Issue 3792 - Fix to support multiprocess firefox (Closed)
Left Patch Set: address comments Created Sept. 29, 2016, 9:52 a.m.
Right Patch Set: change comment Created Sept. 30, 2016, 12:43 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | lib/crawler.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This Source Code is subject to the terms of the Mozilla Public License 2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at 3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/. 4 * http://mozilla.org/MPL/2.0/.
5 */ 5 */
6 6
7 'use strict'; 7 "use strict";
Wladimir Palant 2016/09/29 11:44:58 Double quotation marks please.
sergei 2016/09/29 15:36:22 Done.
8 8
9 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; 9 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
10 10
11 /** 11 /**
12 * @param e exception 12 * @param e exception
13 */ 13 */
14 function reportException(e) 14 function reportException(e)
15 { 15 {
16 let stack = ""; 16 let stack = "";
17 if (e && typeof e == "object" && "stack" in e) 17 if (e && typeof e == "object" && "stack" in e)
18 stack = e.stack + "\n"; 18 stack = e.stack + "\n";
19 19
20 Cu.reportError(e); 20 Cu.reportError(e);
21 dump(e + "\n" + stack + "\n"); 21 dump(e + "\n" + stack + "\n");
22 } 22 }
23 23
24 const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {}); 24 const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
25 25
26 /** 26 /**
27 * Progress listener capturing the data of the current page and calling 27 * Progress listener capturing the data of the current page and calling
28 * onPageLoaded(data) when loading is finished, where data contains 28 * onPageLoaded(data) when loading is finished, where data contains
29 * HTTP status and headers. 29 * HTTP status and headers.
30 * 30 *
31 * @type nsIWebProgressListener 31 * @type nsIWebProgressListener
32 */ 32 */
33 const webProgressListener = 33 let webProgressListener =
34 { 34 {
35 onStateChange: function(webProgress, request, flags, status) 35 onStateChange: function(webProgress, request, flags, status)
36 { 36 {
37 if (webProgress.DOMWindow == content && 37 if (webProgress.DOMWindow == content &&
38 (flags & Ci.nsIWebProgressListener.STATE_STOP) && 38 (flags & Ci.nsIWebProgressListener.STATE_STOP))
39 (flags & Ci.nsIWebProgressListener.STATE_IS_WINDOW))
Wladimir Palant 2016/09/29 11:44:59 You don't have to check STATE_IS_WINDOW any more.
sergei 2016/09/29 15:36:21 Done. I left it just in case.
40 { 39 {
41 if (content.location.protocol == 'about:') 40 // First time we receive STATE_STOP for about:blank and the second time
41 // for our interested URL which is distinct from about:blank.
42 // However we should not process about:blank because it can happen that
43 // the message with information about about:blank is delivered when the
44 // code in crawler.js is already waiting for a message from this tab.
45 // Another case we are not interested in is about:newtab.
46 if (content.location.protocol == "about:")
42 return; 47 return;
Wladimir Palant 2016/09/29 11:44:58 This needs an explanation. Is that check necessary
sergei 2016/09/29 15:36:22 Answer is in https://codereview.adblockplus.org/29
43 const pageInfo = {channelStatus: status}; 48 let pageInfo = {channelStatus: status};
Wladimir Palant 2016/09/29 11:44:58 Please don't declare regular variables as constant
sergei 2016/09/29 15:36:21 const in javascript does not mean immutable, it's
Wladimir Palant 2016/09/30 07:43:12 Yes, that's how const is normally used - to indica
44 if (request instanceof Ci.nsIHttpChannel) 49 if (request instanceof Ci.nsIHttpChannel)
45 { 50 {
46 try 51 try
47 { 52 {
48 pageInfo.headers = []; 53 pageInfo.headers = [];
49 pageInfo.headers.push("HTTP/x.x " + request.responseStatus + " " + req uest.responseStatusText); 54 pageInfo.headers.push("HTTP/x.x " + request.responseStatus + " " + req uest.responseStatusText);
50 request.visitResponseHeaders((header, value) => pageInfo.headers.push( header + ": " + value)); 55 request.visitResponseHeaders((header, value) => pageInfo.headers.push( header + ": " + value));
51 } 56 }
52 catch (e) 57 catch (e)
53 { 58 {
(...skipping 11 matching lines...) Expand all
65 70
66 QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener, Ci.nsISuppor tsWeakReference]) 71 QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener, Ci.nsISuppor tsWeakReference])
67 }; 72 };
68 73
69 function onPageLoaded(pageInfo) 74 function onPageLoaded(pageInfo)
70 { 75 {
71 Object.assign(pageInfo, gatherPageInfo(content)); 76 Object.assign(pageInfo, gatherPageInfo(content));
72 sendAsyncMessage("abpcrawler:pageInfoGathered", pageInfo); 77 sendAsyncMessage("abpcrawler:pageInfoGathered", pageInfo);
73 }; 78 };
74 79
75 const webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor).getInterfa ce(Ci.nsIWebProgress); 80 let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor).getInterface (Ci.nsIWebProgress);
Wladimir Palant 2016/09/29 11:44:58 As above, please don't mark any variable that you
sergei 2016/09/29 15:36:21 Done.
76 webProgress.addProgressListener(webProgressListener, Ci.nsIWebProgress.NOTIFY_ST ATE_WINDOW); 81 webProgress.addProgressListener(webProgressListener, Ci.nsIWebProgress.NOTIFY_ST ATE_WINDOW);
77 82
78 /** 83 /**
79 * Gathers information about a DOM window. 84 * Gathers information about a DOM window.
80 * Currently 85 * Currently
81 * - creates a screenshot of the page 86 * - creates a screenshot of the page
82 * - serializes the page source code 87 * - serializes the page source code
83 * @param {nsIDOMWindow} wnd window to process 88 * @param {nsIDOMWindow} wnd window to process
84 * @return {Object} the object containing "screenshot" and "source" properties. 89 * @return {Object} the object containing "screenshot" and "source" properties.
85 */ 90 */
86 function gatherPageInfo(wnd) 91 function gatherPageInfo(wnd)
87 { 92 {
88 const document = wnd.document; 93 let document = wnd.document;
89 const result = {errors:[]}; 94 let result = {errors:[]};
90 if (!document.documentElement) 95 if (!document.documentElement)
91 { 96 {
92 result.errors.push('No document.documentElement'); 97 result.errors.push("No document.documentElement");
Wladimir Palant 2016/09/29 11:44:58 Double quotation marks please.
sergei 2016/09/29 15:36:21 Done.
93 return result; 98 return result;
94 } 99 }
95 100
96 try 101 try
97 { 102 {
98 const canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "can vas"); 103 let canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "canva s");
99 canvas.width = document.documentElement.scrollWidth; 104 canvas.width = document.documentElement.scrollWidth;
100 canvas.height = document.documentElement.scrollHeight; 105 canvas.height = document.documentElement.scrollHeight;
101 const context = canvas.getContext("2d"); 106 let context = canvas.getContext("2d");
102 context.drawWindow(wnd, 0, 0, canvas.width, canvas.height, "rgb(255, 255, 25 5)"); 107 context.drawWindow(wnd, 0, 0, canvas.width, canvas.height, "rgb(255, 255, 25 5)");
103 result.screenshot = canvas.toDataURL("image/jpeg", 0.8); 108 result.screenshot = canvas.toDataURL("image/jpeg", 0.8);
104 } 109 }
105 catch (e) 110 catch (e)
106 { 111 {
107 reportException(e); 112 reportException(e);
108 result.errors.push("Cannot make page screenshot"); 113 result.errors.push("Cannot make page screenshot");
109 } 114 }
110 115
111 try 116 try
112 { 117 {
113 // TODO: Capture frames as well? 118 // TODO: Capture frames as well?
114 const serializer = new wnd.XMLSerializer(); 119 let serializer = new wnd.XMLSerializer();
115 result.source = serializer.serializeToString(document.documentElement); 120 result.source = serializer.serializeToString(document.documentElement);
116 } 121 }
117 catch(e) 122 catch(e)
118 { 123 {
119 reportException(e); 124 reportException(e);
120 result.errors.push("Cannot obtain page source code"); 125 result.errors.push("Cannot obtain page source code");
121 } 126 }
122 127
123 return result; 128 return result;
124 } 129 }
LEFTRIGHT
« no previous file | lib/crawler.js » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld