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

Side by Side Diff: lib/typedItCollector.js

Issue 8382011: Applied changes from emailed code review (Closed)
Patch Set: Applied remaining changes Created Sept. 26, 2012, 9:02 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
OLDNEW
1 /* This Source Code Form is subject to the terms of the Mozilla Public 1 /* This Source Code Form is subject to the terms of the Mozilla Public
Wladimir Palant 2012/09/28 09:29:34 Comments from previous review haven't been address
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
4 4
5 Cu.import("resource://gre/modules/Services.jsm"); 5 Cu.import("resource://gre/modules/Services.jsm");
6 6
7 let {Prefs} = require("prefs"); 7 let {Prefs} = require("prefs");
8 let {WindowObserver} = require("windowObserver"); 8 let {WindowObserver} = require("windowObserver");
9 9
10 let domains = null; 10 let domains = null;
11 let userCorrections = null; 11 let userCorrections = null;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 if (!("service" in privateBrowsingEnabled)) 141 if (!("service" in privateBrowsingEnabled))
142 privateBrowsingEnabled.service = Cc["@mozilla.org/privatebrowsing;1"].getSer vice(Ci.nsIPrivateBrowsingService); 142 privateBrowsingEnabled.service = Cc["@mozilla.org/privatebrowsing;1"].getSer vice(Ci.nsIPrivateBrowsingService);
143 143
144 return privateBrowsingEnabled.service.privateBrowsingEnabled; 144 return privateBrowsingEnabled.service.privateBrowsingEnabled;
145 } 145 }
146 146
147 function sendAnonymousData() 147 function sendAnonymousData()
148 { 148 {
149 if (!Prefs.domainOptIn || (domains.length == 0 && falsePositives.length == 0 & & userCorrections.length == 0) || privateBrowsingEnabled()) 149 if (!Prefs.domainOptIn || (domains.length == 0 && falsePositives.length == 0 & & userCorrections.length == 0) || privateBrowsingEnabled())
150 return; 150 return;
151 151
152 let args = []; 152 let postData = {};
153 let savedDomains = domains; 153 let savedDomains = domains;
154 let savedFalsePositives = falsePositives; 154 let savedFalsePositives = falsePositives;
155 let savedUserCorrections = userCorrections; 155 let savedUserCorrections = userCorrections;
156 156
157 if(domains.length > 0) 157 if(domains.length > 0)
158 { 158 {
159 args.push(domains.map(function(d) "domains[]=" + encodeURIComponent(d)).join ("&")); 159 postData.domains = domains;
160 domains = []; 160 domains = [];
161 } 161 }
162 if(falsePositives.length > 0) 162 if(falsePositives.length > 0)
163 { 163 {
164 args.push( 164 postData.falsePositives = falsePositives;
165 falsePositives.map(
166 function(fp)
167 {
168 return "falsePositives[]=" + encodeURIComponent(
169 encodeURIComponent(fp[0]) + ((fp[1]) ? "&" + encodeURIComponent(fp[1 ]) : "")
170 );
171 }
172 ).join("&")
173 );
174 falsePositives = []; 165 falsePositives = [];
175 } 166 }
176 if(userCorrections.length > 0) 167 if(userCorrections.length > 0)
177 { 168 {
178 args.push( 169 postData.userCorrections = userCorrections;
179 userCorrections.map(
180 function(uc)
181 {
182 return "userCorrections[]=" + encodeURIComponent(
183 encodeURIComponent(uc[0]) + ((uc[1]) ? "&" + encodeURIComponent(uc[1 ]) : "")
184 );
185 }
186 ).join("&")
187 );
188 userCorrections = []; 170 userCorrections = [];
189 } 171 }
190 172
191 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci. nsIXMLHttpRequest); 173 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci. nsIXMLHttpRequest);
192 request.open("POST", "http://typed.it/submitData"); 174 request.open("POST", "http://typed.it/submitData");
193 request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 175 request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
194 request.addEventListener("load", function(event) 176 request.addEventListener("load", function(event)
195 { 177 {
196 if (event.target.status != 200) 178 if (event.target.status != 200)
197 { 179 {
198 domains = domains.concat(savedDomains); 180 domains = domains.concat(savedDomains);
199 falsePositives = falsePositives.concat(savedFalsePositives); 181 falsePositives = falsePositives.concat(savedFalsePositives);
200 userCorrections = userCorrections.concat(savedUserCorrections); 182 userCorrections = userCorrections.concat(savedUserCorrections);
201 } 183 }
202 }, false); 184 }, false);
203 request.send(args.join("&")); 185 request.send("data=" + JSON.stringify(postData));
204 } 186 }
205 187
206 function initWebUI(event) 188 function initWebUI(event)
207 { 189 {
208 if (Prefs.domainOptIn) 190 if (Prefs.domainOptIn)
209 return; 191 return;
210 192
211 let container = event.target; 193 let container = event.target;
212 let source = container.ownerDocument.defaultView.location.hostname; 194 let source = container.ownerDocument.defaultView.location.hostname;
213 if (!/(^|\.)urlfixer\.org$/.test(source)) 195 if (!/(^|\.)urlfixer\.org$/.test(source))
(...skipping 12 matching lines...) Expand all
226 208
227 Prefs.domainOptInAsk = true; 209 Prefs.domainOptInAsk = true;
228 Prefs.domainOptIn = true; 210 Prefs.domainOptIn = true;
229 button.style.display = "none"; 211 button.style.display = "none";
230 message.style.display = ""; 212 message.style.display = "";
231 }, false); 213 }, false);
232 214
233 message.style.display = "none"; 215 message.style.display = "none";
234 container.style.display = ""; 216 container.style.display = "";
235 } 217 }
OLDNEW

Powered by Google App Engine
This is Rietveld