~ubuntu-branches/ubuntu/precise/lightning-extension/precise-security

« back to all changes in this revision

Viewing changes to mozilla/testing/mozbase/mozprofile/mozprofile/permissions.py

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-11-08 10:00:06 UTC
  • mfrom: (1.3.8)
  • Revision ID: package-import@ubuntu.com-20121108100006-5u86nbolqjem85q5
Tags: 1.9+build1-0ubuntu0.12.04.1
* New upstream stable release to support Thunderbird 17 (CALENDAR_1_9_BUILD1)
  - see LP: #1080212 for USN information

Show diffs side-by-side

added added

removed removed

Lines of Context:
128
128
            if self.hasPrimary:
129
129
                raise MultiplePrimaryLocationsError()
130
130
            self.hasPrimary = True
131
 
        for loc in self._locations:
132
 
            if loc.isEqual(location):
133
 
                raise DuplicateLocationError(location.url())
 
131
 
134
132
        self._locations.append(location)
135
133
        if self.add_callback and not suppress_callback:
136
134
            self.add_callback([location])
150
148
 
151
149
        This format:
152
150
        http://mxr.mozilla.org/mozilla-central/source/build/pgo/server-locations.txt
153
 
        The only exception is that the port, if not defined, defaults to 80.
 
151
        The only exception is that the port, if not defined, defaults to 80 or 443.
154
152
 
155
153
        FIXME: Shouldn't this default to the protocol-appropriate port?  Is
156
154
        there any reason to have defaults at all?
185
183
                host, port = netloc.rsplit(':', 1)
186
184
            except ValueError:
187
185
                host = netloc
188
 
                port = '80'
 
186
                default_ports = {'http': '80',
 
187
                                 'https': '443',
 
188
                                 'ws': '443',
 
189
                                 'wss': '443'}
 
190
                port = default_ports.get(scheme, '80')
189
191
 
190
192
            try:
191
193
                location = Location(scheme, host, port, options)
229
231
        # Open database and create table
230
232
        permDB = sqlite3.connect(os.path.join(self._profileDir, "permissions.sqlite"))
231
233
        cursor = permDB.cursor();
 
234
 
 
235
        cursor.execute("PRAGMA user_version=3");
 
236
 
232
237
        # SQL copied from
233
238
        # http://mxr.mozilla.org/mozilla-central/source/extensions/cookie/nsPermissionManager.cpp
234
239
        cursor.execute("""CREATE TABLE IF NOT EXISTS moz_hosts (
237
242
           type TEXT,
238
243
           permission INTEGER,
239
244
           expireType INTEGER,
240
 
           expireTime INTEGER)""")
 
245
           expireTime INTEGER,
 
246
           appId INTEGER,
 
247
           isInBrowserElement INTEGER)""")
241
248
 
242
249
        for location in locations:
243
250
            # set the permissions
248
255
                    permission_type = 1
249
256
                else:
250
257
                    permission_type = 2
251
 
                cursor.execute("INSERT INTO moz_hosts values(?, ?, ?, ?, 0, 0)",
 
258
                cursor.execute("INSERT INTO moz_hosts values(?, ?, ?, ?, 0, 0, 0, 0)",
252
259
                               (self._num_permissions, location.host, perm,
253
260
                                permission_type))
254
261
 
268
275
        for (i, l) in itertools.izip(itertools.count(1), privileged):
269
276
            prefs.append(("capability.principal.codebase.p%s.granted" % i, "UniversalXPConnect"))
270
277
 
271
 
            # TODO: do we need the port?
272
 
            prefs.append(("capability.principal.codebase.p%s.id" % i, l.scheme + "://" + l.host))
 
278
            prefs.append(("capability.principal.codebase.p%s.id" % i, "%s://%s:%s" %
 
279
                        (l.scheme, l.host, l.port)))
273
280
            prefs.append(("capability.principal.codebase.p%s.subjectName" % i, ""))
274
281
 
275
282
        if proxy:
289
296
 
290
297
        # We need to proxy every server but the primary one.
291
298
        origins = ["'%s'" % l.url()
292
 
                   for l in self._locations
293
 
                   if "primary" not in l.options]
 
299
                   for l in self._locations]
 
300
 
294
301
        origins = ", ".join(origins)
295
302
 
296
 
        # TODO: this is not a reliable way to determine the Proxy host
297
303
        for l in self._locations:
298
304
            if "primary" in l.options:
299
305
                webServer = l.host
300
 
                httpPort  = l.port
301
 
                sslPort   = 443
 
306
                port = l.port
302
307
 
303
308
        # TODO: this should live in a template!
 
309
        # TODO: So changing the 5th line of the regex below from (\\\\\\\\d+)
 
310
        # to (\\\\d+) makes this code work. Not sure why there would be this
 
311
        # difference between automation.py.in and this file.
304
312
        pacURL = """data:text/plain,
305
313
function FindProxyForURL(url, host)
306
314
{
309
317
                         '://' +
310
318
                         '(?:[^/@]*@)?' +
311
319
                         '(.*?)' +
312
 
                         '(?::(\\\\\\\\d+))?/');
 
320
                         '(?::(\\\\d+))?/');
313
321
  var matches = regex.exec(url);
314
322
  if (!matches)
315
323
    return 'DIRECT';
330
338
  var origin = matches[1] + '://' + matches[2] + ':' + matches[3];
331
339
  if (origins.indexOf(origin) < 0)
332
340
    return 'DIRECT';
333
 
  if (isHttp)
334
 
    return 'PROXY %(remote)s:%(httpport)s';
335
 
  if (isHttps || isWebSocket || isWebSocketSSL)
336
 
    return 'PROXY %(remote)s:%(sslport)s';
 
341
  if (isHttp || isHttps || isWebSocket || isWebSocketSSL)
 
342
    return 'PROXY %(remote)s:%(port)s';
337
343
  return 'DIRECT';
338
344
}""" % { "origins": origins,
339
345
         "remote":  webServer,
340
 
         "httpport":httpPort,
341
 
         "sslport": sslPort }
 
346
         "port": port }
342
347
        pacURL = "".join(pacURL.splitlines())
343
348
 
344
349
        prefs.append(("network.proxy.type", 2))