Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 |
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 | 8 |
9 let surveyLang = null; | 9 let surveyLang = null; |
10 let surveyUrl = "http://urlfixer.org"; //"http://adblockplus.org/usersurvey/inde x.php?sid=68316"; | 10 let surveyUrl = null; //"http://urlfixer.org/usersurvey/..."; |
11 | 11 |
12 exports.incrementCorrectionsCounter = incrementCorrectionsCounter; | 12 exports.incrementCorrectionsCounter = incrementCorrectionsCounter; |
13 function incrementCorrectionsCounter() | 13 function incrementCorrectionsCounter() |
14 { | 14 { |
15 // Only if survey exists | |
16 if (!surveyUrl) | |
17 return; | |
18 | |
15 // Only users with 5 URL corrections | 19 // Only users with 5 URL corrections |
16 if (++Prefs.corrections_count == 5) | 20 if (++Prefs.corrections_count == 5) |
17 { | 21 { |
18 initSurvey(); | 22 initSurvey(); |
19 } | 23 } |
20 } | 24 } |
21 | 25 |
22 function initSurvey() | 26 function initSurvey() |
23 { | 27 { |
24 // Don't ask after 2012-10-15 | 28 // Don't ask after 2012-10-15 |
(...skipping 17 matching lines...) Expand all Loading... | |
42 // Delay survey question by 5 seconds | 46 // Delay survey question by 5 seconds |
43 surveyTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); | 47 surveyTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); |
44 surveyTimer.initWithCallback(runSurvey, 5000, Ci.nsITimer.TYPE_ONE_SHOT); | 48 surveyTimer.initWithCallback(runSurvey, 5000, Ci.nsITimer.TYPE_ONE_SHOT); |
45 } | 49 } |
46 | 50 |
47 function runSurvey() | 51 function runSurvey() |
48 { | 52 { |
49 //open panel | 53 //open panel |
50 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci. nsIXMLHttpRequest); | 54 let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci. nsIXMLHttpRequest); |
51 request.open("GET", "chrome://url-fixer/content/survey.xul"); | 55 request.open("GET", "chrome://url-fixer/content/survey.xul"); |
52 request.setRequestHeader("Content-Type", "text/html"); | |
Wladimir Palant
2012/09/28 09:29:34
What's that good for in a non-network request? Rem
| |
53 request.addEventListener("load", function(event) | 56 request.addEventListener("load", function(event) |
54 { | 57 { |
55 let window = Services.wm.getMostRecentWindow("navigator:browser"); | 58 let window = Services.wm.getMostRecentWindow("navigator:browser"); |
56 let document = window.document; | 59 let document = window.document; |
57 | 60 |
58 let style = document.createProcessingInstruction('xml-stylesheet', 'href="ch rome://url-fixer/skin/survey.css?' + (new Date().getTime()) + '" type="text/css" '); | 61 let style = document.createProcessingInstruction('xml-stylesheet', 'href="ch rome://url-fixer/skin/survey.css" type="text/css"'); |
Wladimir Palant
2012/09/28 09:29:34
Why randomize the URL here? It's a static file, no
| |
59 document.insertBefore(style, document.firstChild); | 62 document.insertBefore(style, document.firstChild); |
60 | 63 |
61 let panel = new window.DOMParser().parseFromString(request.responseText, "te xt/xml").documentElement; | 64 let panel = new window.DOMParser().parseFromString(request.responseText, "te xt/xml").documentElement; |
62 if (!document.getElementById(panel.id)) | 65 let oldPanel = document.getElementById(panel.id); |
66 if (oldPanel) | |
67 oldPanel.parentNode.removeChild(oldPanel); | |
68 document.getElementById("mainPopupSet").appendChild(panel); | |
69 document.getElementById("url-fixer-icon").setAttribute("src", require("info" ).addonRoot + "icon64.png"); | |
70 document.getElementById("url-fixer-accept-button").addEventListener("command ", function() | |
63 { | 71 { |
64 document.getElementById("mainPopupSet").appendChild(panel); | 72 openSurvey(); |
65 } | 73 panel.hidePopup(); |
66 else | 74 }); |
75 document.getElementById("url-fixer-cancel-button").addEventListener("command ", function() | |
67 { | 76 { |
68 panel = document.getElementById(panel.id); | 77 panel.hidePopup(); |
Wladimir Palant
2012/09/28 09:29:34
Our panel is already in the browser document at th
| |
69 } | 78 }); |
70 panel.querySelector("#icon").setAttribute("src", require("info").addonRoot + "icon64.png"); | 79 panel.addEventListener("popuphidden", function() |
Wladimir Palant
2012/09/28 09:29:34
If you use unique IDs then you can use document.ge
| |
71 panel.querySelector("#accept-button").addEventListener("click", function() | 80 { |
Wladimir Palant
2012/09/28 09:29:34
Don't listen to "click" events, these are mouse-on
| |
72 { | 81 panel.parentNode.removeChild(panel); |
Wladimir Palant
2012/09/28 09:29:34
This bracket should not be indented...
| |
73 openSurvey(); | 82 style.parentNode.removeChild(style); |
74 panel.hidePopup(); | 83 }); |
75 } | |
76 ); | |
77 panel.querySelector("#cancel-button").addEventListener("click", function() | |
78 { | |
Wladimir Palant
2012/09/28 09:29:34
This bracket should not be indented...
| |
79 panel.hidePopup(); | |
80 } | |
81 ); | |
82 | 84 |
83 let anchor = document.getElementById("identity-box"); | 85 let anchor = document.getElementById("identity-box"); |
84 panel.openPopup(anchor, "after_start", 0, 0, false, true); | 86 panel.openPopup(anchor, "after_start", 0, 0, false, true); |
85 }, false); | 87 }, false); |
86 request.send(null); | 88 request.send(null); |
87 } | 89 } |
88 | 90 |
89 function openSurvey() | 91 function openSurvey() |
90 { | 92 { |
91 require("appIntegration").getBrowser(Services.wm.getMostRecentWindow("navigato r:browser")).loadOneTab(surveyUrl + "&lang=" + surveyLang, { | 93 let window = Services.wm.getMostRecentWindow("navigator:browser"); |
Wladimir Palant
2012/09/28 09:29:34
Taking over comment from previous review: line too
| |
92 referrerURI: Services.io.newURI("http://url.fixer/", null, null), | 94 if (window) |
93 inBackground: false | 95 { |
94 }); | 96 let browser = require("appIntegration").getBrowser(window); |
97 browser.loadOneTab(surveyUrl + "&lang=" + surveyLang, { | |
98 referrerURI: Services.io.newURI("http://url.fixer/", null, null), | |
99 inBackground: false | |
100 }); | |
101 } | |
95 } | 102 } |
LEFT | RIGHT |