duckduckgo webjump
[conkeror.git] / modules / cookie.js
blobb93a9b3f27b1981e2e36fac0f61fcf6febc98b9f
1 /**
2  * (C) Copyright 2008 Jeremy Maitin-Shepard
3  *
4  * Use, modification, and distribution are subject to the terms specified in the
5  * COPYING file.
6 **/
8 in_module(null);
10 var cookie_manager = Cc["@mozilla.org/cookiemanager;1"]
11     .getService(Ci.nsICookieManager2);
13 function clear_cookies () {
14     cookie_manager.removeAll();
16 interactive("clear-cookies", "Permanently delete all existing cookies.",
17           function (I) {
18               clear_cookies();
19               I.minibuffer.message("Cookies cleared.");
20           });
22 define_label("COOKIE_LIFETIME_DEFAULT");
23 define_label("COOKIE_LIFETIME_SESSION");
24 define_label("COOKIE_LIFETIME_DAYS", "days");
25 define_label("COOKIE_LIFETIME_PROMPT");
27 define_special_variable("cookie_lifetime_policy",
28                         function () {
29                             switch (get_pref("network.cookie.lifetimePolicy")) {
30                             case 0:
31                                 return COOKIE_LIFETIME_DEFAULT;
32                             case 1:
33                                 return COOKIE_LIFETIME_PROMPT;
34                             case 2:
35                                   return COOKIE_LIFETIME_SESSION;
36                             case 3:
37                                 return COOKIE_LIFETIME_DAYS(get_pref("network.cookie.lifetime.days"));
38                             default:
39                                 return undefined;
40                             }
41                         },
42                         function (value) {
43                             switch (label_id(value)) {
44                             case COOKIE_LIFETIME_DEFAULT:
45                                 session_pref("network.cookie.lifetimePolicy", 0);
46                                 break;
47                             case COOKIE_LIFETIME_PROMPT:
48                                 session_pref("network.cookie.lifetimePolicy", 1);
49                                 break;
50                             case COOKIE_LIFETIME_SESSION:
51                                 session_pref("network.cookie.lifetimePolicy", 2);
52                                 break;
53                             case COOKIE_LIFETIME_DAYS:
54                                 session_pref("network.cookie.lifetimePolicy", 3);
55                                 session_pref("network.cookie.lifetime.days", value.days);
56                                 break;
57                             }
58                         },
59                         "Specifies the default cookie lifetime policy.");
61 provide("cookie");