2 function webdeveloper_addCookie()
4 window
.openDialog("chrome://webdeveloper/content/dialogs/cookie.xul", "webdeveloper-cookie-dialog", "centerscreen,chrome,modal", "add");
7 // Clears all session cookies
8 function webdeveloper_clearSessionCookies()
10 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
12 // If the clearing is confirmed
13 if(webdeveloper_clearConfirmation(stringBundle
.getString("webdeveloper_clearSessionCookiesConfirmation")))
16 var cookieManager
= Components
.classes
["@mozilla.org/cookiemanager;1"].getService(Components
.interfaces
.nsICookieManager
);
17 var cookies
= cookieManager
.enumerator
;
20 // Loop through the cookies
21 while(cookies
.hasMoreElements())
23 cookie
= cookies
.getNext();
25 // If this is a cookie with no expiration
26 if(cookie
instanceof Components
.interfaces
.nsICookie
&& cookie
.expires
== "0")
28 cookieManager
.remove(cookie
.host
, cookie
.name
, cookie
.path
, false);
33 // If the hide informational dialogs preference is not set
34 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
36 var title
= stringBundle
.getString("webdeveloper_clearSessionCookies");
38 // If one session cookie was removed
41 webdeveloper_informationalDialog(title
, stringBundle
.getString("webdeveloper_clearSessionCookiesSingleResult"));
45 webdeveloper_informationalDialog(title
, stringBundle
.getFormattedString("webdeveloper_clearSessionCookiesMultipleResult", [removed
]));
52 function webdeveloper_deleteCookie(event
)
54 var eventTarget
= event
.target
;
56 // If there is an event target and the click was not a right click
57 if(eventTarget
&& event
.button
!= 2)
59 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
61 // If the deletion is confirmed
62 if(webdeveloper_deleteConfirmation(stringBundle
.getString("webdeveloper_deleteCookieConfirmation")))
64 Components
.classes
["@mozilla.org/cookiemanager;1"].getService(Components
.interfaces
.nsICookieManager
).remove(eventTarget
.getAttribute("cookie-host"), eventTarget
.getAttribute("cookie-name"), eventTarget
.getAttribute("cookie-path"), false);
66 // If the hide informational dialogs preference is not set
67 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
69 webdeveloper_informationalDialog(stringBundle
.getString("webdeveloper_deleteCookie"), stringBundle
.getString("webdeveloper_deleteCookieResult"));
73 event
.preventDefault();
77 // Called when a delete cookie link is moused out
78 function webdeveloper_deleteCookieMouseOut(event
)
80 // If there is an event target
83 getBrowser().contentWindow
.status
= "";
85 event
.preventDefault();
89 // Called when a delete cookie link is moused over
90 function webdeveloper_deleteCookieMouseOver(event
)
92 // If there is an event target
95 getBrowser().contentWindow
.status
= document
.getElementById("webdeveloper-string-bundle").getString("webdeveloper_deleteCookie");
97 event
.preventDefault();
101 // Deletes all the cookies for the current domain
102 function webdeveloper_deleteDomainCookies()
104 var cookies
= new Array();
105 var cookiesLength
= null;
106 var documentList
= webdeveloper_getDocuments(webdeveloper_getContentWindow());
107 var documentLength
= documentList
.length
;
109 var pageDocument
= null;
110 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
112 // Loop through the documents
113 for(var i
= 0; i
< documentLength
; i
++)
115 pageDocument
= documentList
[i
];
116 cookies
= cookies
.concat(webdeveloper_getCookies(pageDocument
.location
.hostname
, "/", false));
119 cookiesLength
= cookies
.length
;
121 // If one cookie was found
122 if(cookiesLength
== 1)
124 message
= stringBundle
.getString("webdeveloper_deleteDomainCookiesSingleConfirmation");
128 message
= stringBundle
.getFormattedString("webdeveloper_deleteDomainCookiesMultipleConfirmation", [cookiesLength
]);
131 // If the deletion is confirmed
132 if(cookiesLength
== 0 || webdeveloper_deleteConfirmation(message
))
135 var cookieManager
= Components
.classes
["@mozilla.org/cookiemanager;1"].getService(Components
.interfaces
.nsICookieManager
);
137 // Loop through all the cookies
138 for(i
= 0 ; i
< cookiesLength
; i
++)
142 cookieManager
.remove(cookie
.host
, cookie
.name
, cookie
.path
, false);
145 // If the hide informational dialogs preference is not set
146 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
148 var title
= stringBundle
.getString("webdeveloper_deleteDomainCookies");
150 // If one cookie was found
151 if(cookiesLength
== 1)
153 webdeveloper_informationalDialog(title
, stringBundle
.getString("webdeveloper_deleteDomainCookiesSingleResult"));
157 webdeveloper_informationalDialog(title
, stringBundle
.getFormattedString("webdeveloper_deleteDomainCookiesMultipleResult", [cookiesLength
]));
163 // Deletes all the cookies for the current path
164 function webdeveloper_deletePathCookies()
166 var cookies
= new Array();
167 var cookiesLength
= null;
168 var documentList
= webdeveloper_getDocuments(webdeveloper_getContentWindow());
169 var documentLength
= documentList
.length
;
171 var pageDocument
= null;
172 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
174 // Loop through the documents
175 for(var i
= 0; i
< documentLength
; i
++)
177 pageDocument
= documentList
[i
];
178 cookies
= cookies
.concat(webdeveloper_getCookies(pageDocument
.location
.hostname
, pageDocument
.location
.pathname
, false));
181 cookiesLength
= cookies
.length
;
183 // If one cookie was found
184 if(cookiesLength
== 1)
186 message
= stringBundle
.getString("webdeveloper_deletePathCookiesSingleConfirmation");
190 message
= stringBundle
.getFormattedString("webdeveloper_deletePathCookiesMultipleConfirmation", [cookiesLength
]);
193 // If the deletion is confirmed
194 if(cookiesLength
== 0 || webdeveloper_deleteConfirmation(message
))
197 var cookieManager
= Components
.classes
["@mozilla.org/cookiemanager;1"].getService(Components
.interfaces
.nsICookieManager
);
199 // Loop through all the cookies
200 for(i
= 0 ; i
< cookiesLength
; i
++)
204 cookieManager
.remove(cookie
.host
, cookie
.name
, cookie
.path
, false);
207 // If the hide informational dialogs preference is not set
208 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
210 var title
= stringBundle
.getString("webdeveloper_deletePathCookies");
212 // If one cookie was found
213 if(cookiesLength
== 1)
215 webdeveloper_informationalDialog(title
, stringBundle
.getString("webdeveloper_deletePathCookiesSingleResult"));
219 webdeveloper_informationalDialog(title
, stringBundle
.getFormattedString("webdeveloper_deletePathCookiesMultipleResult", [cookiesLength
]));
226 function webdeveloper_editCookie(event
)
228 var eventTarget
= event
.target
;
230 // If there is an event target and the click was not a right click
231 if(eventTarget
&& event
.button
!= 2)
233 window
.openDialog("chrome://webdeveloper/content/dialogs/cookie.xul", "webdeveloper-cookie-dialog", "centerscreen,chrome,modal", "edit", eventTarget
.getAttribute("cookie-name"), eventTarget
.getAttribute("cookie-value"), eventTarget
.getAttribute("cookie-host"), eventTarget
.getAttribute("cookie-path"), eventTarget
.getAttribute("cookie-expires"), eventTarget
.getAttribute("cookie-secure"));
235 event
.preventDefault();
239 // Called when an edit cookie link is moused out
240 function webdeveloper_editCookieMouseOut(event
)
242 // If there is an event target
245 getBrowser().contentWindow
.status
= "";
247 event
.preventDefault();
251 // Called when an edit cookie link is moused over
252 function webdeveloper_editCookieMouseOver(event
)
254 // If there is an event target
257 getBrowser().contentWindow
.status
= document
.getElementById("webdeveloper-string-bundle").getString("webdeveloper_editCookie");
259 event
.preventDefault();
264 function webdeveloper_toggleCookies(element
)
266 var cookieBehavior
= 0;
268 // If disabling cookies
269 if(element
.getAttribute("checked"))
274 webdeveloper_setIntegerPreference("network.cookie.cookieBehavior", cookieBehavior
);
277 // Toggles external site cookies
278 function webdeveloper_toggleExternalSiteCookies(element
)
280 var cookieBehavior
= 0;
282 // If disabling external cookies
283 if(element
.getAttribute("checked"))
288 webdeveloper_setIntegerPreference("network.cookie.cookieBehavior", cookieBehavior
);
291 // Updates the disable cookies menu
292 function webdeveloper_updateDisableCookiesMenu(suffix
)
294 var disableExternalSiteCookiesChecked
= false;
295 var disableExternalSiteCookiesMenu
= document
.getElementById("webdeveloper-disable-external-site-cookies-" + suffix
);
296 var disableCookiesChecked
= false;
297 var disableCookiesPreferenceValue
= webdeveloper_getIntegerPreference("network.cookie.cookieBehavior", true);
299 // If the cookie preference value is set to 2
300 if(disableCookiesPreferenceValue
== 2)
302 disableCookiesChecked
= true;
304 else if(disableCookiesPreferenceValue
== 1)
306 disableExternalSiteCookiesChecked
= true;
309 webdeveloper_configureElement(document
.getElementById("webdeveloper-disable-all-cookies-" + suffix
), "checked", disableCookiesChecked
);
310 webdeveloper_configureElement(disableExternalSiteCookiesMenu
, "checked", disableExternalSiteCookiesChecked
);
311 webdeveloper_configureElement(disableExternalSiteCookiesMenu
, "disabled", disableCookiesChecked
);
314 // Displays all the cookies for the page
315 function webdeveloper_viewCookieInformation()
317 var cellDataElement
= null;
318 var cellHeaderElement
= null;
320 var cookieExpires
= null;
321 var cookieHost
= null;
322 var cookieLength
= null;
323 var cookieName
= null;
324 var cookiePath
= null;
326 var cookieSecure
= null;
327 var cookieValue
= null;
328 var divElement
= null;
329 var documentList
= webdeveloper_getDocuments(webdeveloper_getContentWindow());
330 var documentLength
= documentList
.length
;
332 var linkElement
= null;
333 var listElement
= null;
334 var listItemElement
= null;
336 var oldTab
= getBrowser().selectedTab
;
337 var oldURL
= getBrowser().currentURI
.spec
;
338 var generatedDocument
= webdeveloper_generateDocument("");
339 var bodyElement
= webdeveloper_getDocumentBodyElement(generatedDocument
);
340 var headElement
= webdeveloper_getDocumentHeadElement(generatedDocument
);
341 var headerElement
= generatedDocument
.createElement("h1");
342 var pageDocument
= null;
343 var preElement
= null;
344 var scriptElement
= generatedDocument
.createElement("script");
345 var spanElement
= null;
346 var stringBundle
= document
.getElementById("webdeveloper-string-bundle");
347 var tableElement
= null;
348 var tableRowElement
= null;
349 var title
= stringBundle
.getFormattedString("webdeveloper_viewCookieInformationTitle", [oldURL
]);
351 generatedDocument
.title
= title
;
353 webdeveloper_addGeneratedStyles(generatedDocument
);
355 headerElement
.appendChild(generatedDocument
.createTextNode(title
));
356 bodyElement
.appendChild(headerElement
);
358 webdeveloper_addGeneratedTools(generatedDocument
);
360 // Loop through the documents
361 for(var i
= 0; i
< documentLength
; i
++)
364 pageDocument
= documentList
[i
];
365 location
= pageDocument
.location
;
367 // Try to get the host name
370 hostName
= location
.hostname
;
377 // If the host name is set
380 divElement
= generatedDocument
.createElement("div");
381 headerElement
= generatedDocument
.createElement("h2");
382 linkElement
= generatedDocument
.createElement("a");
383 cookies
= webdeveloper_getCookies(hostName
, location
.pathname
, true);
384 cookieLength
= cookies
.length
;
385 spanElement
= generatedDocument
.createElement("span");
387 linkElement
.setAttribute("href", pageDocument
.documentURI
);
388 linkElement
.appendChild(generatedDocument
.createTextNode(pageDocument
.documentURI
));
389 headerElement
.appendChild(linkElement
);
390 bodyElement
.appendChild(headerElement
);
392 headerElement
= generatedDocument
.createElement("h3");
394 spanElement
.setAttribute("class", "expanded pivot");
395 headerElement
.appendChild(spanElement
);
397 // If there is one cookie
398 if(cookieLength
== 1)
400 headerElement
.appendChild(generatedDocument
.createTextNode(cookieLength
+ " " + stringBundle
.getString("webdeveloper_cookie").toLowerCase()));
404 headerElement
.appendChild(generatedDocument
.createTextNode(cookieLength
+ " " + stringBundle
.getString("webdeveloper_cookies").toLowerCase()));
407 bodyElement
.appendChild(headerElement
);
409 // Loop through the cookies
410 for(var j
= 0; j
< cookieLength
; j
++)
413 cookieHost
= cookie
.host
;
414 cookieName
= cookie
.name
;
415 cookiePath
= cookie
.path
;
416 cookieSecure
= cookie
.isSecure
;
417 cookieValue
= cookie
.value
;
418 tableElement
= generatedDocument
.createElement("table");
421 cellDataElement
= generatedDocument
.createElement("td");
422 cellHeaderElement
= generatedDocument
.createElement("th");
423 tableRowElement
= generatedDocument
.createElement("tr");
425 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_name")));
426 tableRowElement
.appendChild(cellHeaderElement
);
427 cellDataElement
.appendChild(generatedDocument
.createTextNode(cookieName
));
428 tableRowElement
.appendChild(cellDataElement
);
429 tableElement
.appendChild(tableRowElement
);
432 cellDataElement
= generatedDocument
.createElement("td");
433 cellHeaderElement
= generatedDocument
.createElement("th");
434 tableRowElement
= generatedDocument
.createElement("tr");
436 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_value")));
437 tableRowElement
.appendChild(cellHeaderElement
);
438 cellDataElement
.setAttribute("class", "shaded");
439 cellDataElement
.appendChild(generatedDocument
.createTextNode(cookieValue
));
440 tableRowElement
.appendChild(cellDataElement
);
441 tableElement
.appendChild(tableRowElement
);
444 cellDataElement
= generatedDocument
.createElement("td");
445 cellHeaderElement
= generatedDocument
.createElement("th");
446 tableRowElement
= generatedDocument
.createElement("tr");
448 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_host")));
449 tableRowElement
.appendChild(cellHeaderElement
);
450 cellDataElement
.appendChild(generatedDocument
.createTextNode(cookieHost
));
451 tableRowElement
.appendChild(cellDataElement
);
452 tableElement
.appendChild(tableRowElement
);
455 cellDataElement
= generatedDocument
.createElement("td");
456 cellHeaderElement
= generatedDocument
.createElement("th");
457 tableRowElement
= generatedDocument
.createElement("tr");
459 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_path")));
460 tableRowElement
.appendChild(cellHeaderElement
);
461 cellDataElement
.setAttribute("class", "shaded");
462 cellDataElement
.appendChild(generatedDocument
.createTextNode(cookiePath
));
463 tableRowElement
.appendChild(cellDataElement
);
464 tableElement
.appendChild(tableRowElement
);
467 cellDataElement
= generatedDocument
.createElement("td");
468 cellHeaderElement
= generatedDocument
.createElement("th");
469 tableRowElement
= generatedDocument
.createElement("tr");
471 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_secure")));
472 tableRowElement
.appendChild(cellHeaderElement
);
474 // If the cookie is secure
477 cellDataElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_yes")));
481 cellDataElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_no")));
484 tableRowElement
.appendChild(cellDataElement
);
485 tableElement
.appendChild(tableRowElement
);
487 // If the cookie has an expiration date
490 cookieExpires
= new Date(cookie
.expires
* 1000).toUTCString();
494 cookieExpires
= stringBundle
.getString("webdeveloper_viewCookieInformationSession");
498 cellDataElement
= generatedDocument
.createElement("td");
499 cellHeaderElement
= generatedDocument
.createElement("th");
500 tableRowElement
= generatedDocument
.createElement("tr");
502 cellHeaderElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_expires")));
503 tableRowElement
.appendChild(cellHeaderElement
);
504 cellDataElement
.setAttribute("class", "shaded");
505 cellDataElement
.appendChild(generatedDocument
.createTextNode(cookieExpires
));
506 tableRowElement
.appendChild(cellDataElement
);
507 tableElement
.appendChild(tableRowElement
);
509 divElement
.appendChild(tableElement
);
512 linkElement
= generatedDocument
.createElement("a");
513 listElement
= generatedDocument
.createElement("ul");
514 listItemElement
= generatedDocument
.createElement("li");
516 linkElement
.addEventListener("blur", webdeveloper_editCookieMouseOut
, false);
517 linkElement
.addEventListener("click", webdeveloper_editCookie
, false);
518 linkElement
.addEventListener("focus", webdeveloper_editCookieMouseOver
, false);
519 linkElement
.addEventListener("mouseout", webdeveloper_editCookieMouseOut
, false);
520 linkElement
.addEventListener("mouseover", webdeveloper_editCookieMouseOver
, false);
521 linkElement
.setAttribute("cookie-expires", cookieExpires
);
522 linkElement
.setAttribute("cookie-host", cookieHost
);
523 linkElement
.setAttribute("cookie-name", cookieName
);
524 linkElement
.setAttribute("cookie-path", cookiePath
);
525 linkElement
.setAttribute("cookie-secure", cookieSecure
);
526 linkElement
.setAttribute("cookie-value", cookieValue
);
527 linkElement
.setAttribute("href", "http://example.com/");
529 linkElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_editCookie")));
530 listItemElement
.appendChild(linkElement
);
531 listItemElement
.setAttribute("class", "edit");
532 listElement
.appendChild(listItemElement
);
535 linkElement
= generatedDocument
.createElement("a");
536 listItemElement
= generatedDocument
.createElement("li");
538 linkElement
.addEventListener("blur", webdeveloper_deleteCookieMouseOut
, false);
539 linkElement
.addEventListener("click", webdeveloper_deleteCookie
, false);
540 linkElement
.addEventListener("focus", webdeveloper_deleteCookieMouseOver
, false);
541 linkElement
.addEventListener("mouseout", webdeveloper_deleteCookieMouseOut
, false);
542 linkElement
.addEventListener("mouseover", webdeveloper_deleteCookieMouseOver
, false);
543 linkElement
.setAttribute("cookie-host", cookieHost
);
544 linkElement
.setAttribute("cookie-name", cookieName
);
545 linkElement
.setAttribute("cookie-path", cookiePath
);
546 linkElement
.setAttribute("href", "http://example.com/");
548 linkElement
.appendChild(generatedDocument
.createTextNode(stringBundle
.getString("webdeveloper_deleteCookie")));
549 listItemElement
.appendChild(linkElement
);
550 listItemElement
.setAttribute("class", "delete");
551 listElement
.appendChild(listItemElement
);
552 listElement
.setAttribute("class", "commands");
553 divElement
.appendChild(listElement
);
554 divElement
.appendChild(generatedDocument
.createElement("hr"));
557 divElement
.setAttribute("class", "output");
558 bodyElement
.appendChild(divElement
);
562 scriptElement
.setAttribute("defer", "defer");
563 scriptElement
.setAttribute("src", "chrome://webdeveloper/content/common/xpath.js");
564 scriptElement
.setAttribute("type", "text/javascript");
565 headElement
.appendChild(scriptElement
);
567 scriptElement
= generatedDocument
.createElement("script");
569 scriptElement
.setAttribute("defer", "defer");
570 scriptElement
.setAttribute("src", "chrome://webdeveloper/content/generated/output_pivot.js");
571 scriptElement
.setAttribute("type", "text/javascript");
572 headElement
.appendChild(scriptElement
);
574 // If the open tabs in background preference is set to true
575 if(webdeveloper_getBooleanPreference("webdeveloper.open.tabs.background", true))
577 getBrowser().selectedTab
= oldTab
;