summaryrefslogtreecommitdiff
path: root/Allow-.js-preference-files-to-set-locked-prefs-with-.patch
blob: 5fd4ed10a4175350373a1a2fc78a446d732502cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
From: Mike Hommey <glandium@debian.org>
Date: Sat, 21 Jun 2008 02:48:46 +0200
Subject: Allow .js preference files to set locked prefs with lockPref()

---
 modules/libpref/prefapi.cpp  |  5 ++++-
 modules/libpref/prefapi.h    |  3 ++-
 modules/libpref/prefread.cpp | 12 +++++++++---
 modules/libpref/prefread.h   |  4 +++-
 4 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/modules/libpref/prefapi.cpp b/modules/libpref/prefapi.cpp
index dd27769..bd3f8ea 100644
--- a/modules/libpref/prefapi.cpp
+++ b/modules/libpref/prefapi.cpp
@@ -967,11 +967,14 @@ void PREF_ReaderCallback(void       *closure,
                          PrefValue   value,
                          PrefType    type,
                          bool        isDefault,
-                         bool        isStickyDefault)
+                         bool        isStickyDefault,
+                         bool        isLocked)
 {
     uint32_t flags = isDefault ? kPrefSetDefault : kPrefForceSet;
     if (isDefault && isStickyDefault) {
         flags |= kPrefStickyDefault;
     }
     pref_HashPref(pref, value, type, flags);
+    if (isLocked)
+        PREF_LockPref(pref, true);
 }
diff --git a/modules/libpref/prefapi.h b/modules/libpref/prefapi.h
index 5bd8c43..0ab0d7c 100644
--- a/modules/libpref/prefapi.h
+++ b/modules/libpref/prefapi.h
@@ -186,7 +186,8 @@ void PREF_ReaderCallback( void *closure,
                           PrefValue   value,
                           PrefType    type,
                           bool        isDefault,
-                          bool        isStickyDefault);
+                          bool        isStickyDefault,
+                          bool        isLocked);
 
 #ifdef __cplusplus
 }
diff --git a/modules/libpref/prefread.cpp b/modules/libpref/prefread.cpp
index 6c4d339..16c5057 100644
--- a/modules/libpref/prefread.cpp
+++ b/modules/libpref/prefread.cpp
@@ -43,6 +43,7 @@ enum {
 #define BITS_PER_HEX_DIGIT      4
 
 static const char kUserPref[] = "user_pref";
+static const char kLockPref[] = "lockPref";
 static const char kPref[] = "pref";
 static const char kPrefSticky[] = "sticky_pref";
 static const char kTrue[] = "true";
@@ -131,7 +132,7 @@ pref_DoCallback(PrefParseState *ps)
         break;
     }
     (*ps->reader)(ps->closure, ps->lb, value, ps->vtype, ps->fdefault,
-                  ps->fstickydefault);
+                  ps->fstickydefault, ps->flock);
     return true;
 }
 
@@ -191,6 +192,7 @@ PREF_ParseBuf(PrefParseState *ps, const char *buf, int bufLen)
                 ps->vtype = PREF_INVALID;
                 ps->fdefault = false;
                 ps->fstickydefault = false;
+                ps->flock = false;
             }
             switch (c) {
             case '/':       /* begin comment block or line? */
@@ -202,8 +204,10 @@ PREF_ParseBuf(PrefParseState *ps, const char *buf, int bufLen)
             case 'u':       /* indicating user_pref */
             case 'p':       /* indicating pref */
             case 's':       /* indicating sticky_pref */
+            case 'l':       /* indicating lockPref */
                 ps->smatch = (c == 'u' ? kUserPref :
-                             (c == 's' ? kPrefSticky : kPref));
+                             (c == 's' ? kPrefSticky :
+                             (c == 'p' ? kPref : kLockPref)));
                 ps->sindex = 1;
                 ps->nextstate = PREF_PARSE_UNTIL_OPEN_PAREN;
                 state = PREF_PARSE_MATCH_STRING;
@@ -247,8 +251,10 @@ PREF_ParseBuf(PrefParseState *ps, const char *buf, int bufLen)
         /* name parsing */
         case PREF_PARSE_UNTIL_NAME:
             if (c == '\"' || c == '\'') {
-                ps->fdefault = (ps->smatch == kPref || ps->smatch == kPrefSticky);
+                ps->fdefault = (ps->smatch == kPref || ps->smatch == kPrefSticky
+                                || ps->smatch == kLockPref);
                 ps->fstickydefault = (ps->smatch == kPrefSticky);
+                ps->flock = (ps->smatch == kLockPref);
                 ps->quotechar = c;
                 ps->nextstate = PREF_PARSE_UNTIL_COMMA; /* return here when done */
                 state = PREF_PARSE_QUOTED_STRING;
diff --git a/modules/libpref/prefread.h b/modules/libpref/prefread.h
index 3c317ff..0c13057 100644
--- a/modules/libpref/prefread.h
+++ b/modules/libpref/prefread.h
@@ -34,7 +34,8 @@ typedef void (*PrefReader)(void       *closure,
                            PrefValue   val,
                            PrefType    type,
                            bool        defPref,
-                           bool        stickyPref);
+                           bool        stickyPref,
+                           bool        lockPref);
 
 /* structure fields are private */
 typedef struct PrefParseState {
@@ -56,6 +57,7 @@ typedef struct PrefParseState {
     PrefType    vtype;      /* PREF_STRING,INT,BOOL          */
     bool        fdefault;   /* true if (default) pref     */
     bool        fstickydefault; /* true if (sticky) pref     */
+    bool        flock;      /* true if pref to be locked     */
 } PrefParseState;
 
 /**
bgstack15