This file is indexed.

/usr/share/xul-ext/lightbeam/resources/lightbeam/lib/shared/policy.js is in xul-ext-lightbeam 1.2.1+dfsg-1ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* global require, exports */
'use strict';

const {
  Cc, Ci
} = require('chrome');
const {
  Class
} = require('sdk/core/heritage');
const CP_NS = require('sdk/core/namespace').ns();
const {
  ensure
} = require('sdk/system/unload');
const {
  validateOptions
} = require('sdk/deprecated/api-utils');
const {
  id: ADDON_ID
} = require('sdk/self');
const xpcom = require('sdk/platform/xpcom');

const CM = Cc["@mozilla.org/categorymanager;1"]
  .getService(Ci.nsICategoryManager);

const ACCEPT = exports.ACCEPT = Ci.nsIContentPolicy.ACCEPT;
const REJECT = exports.REJECT = Ci.nsIContentPolicy.REJECT_REQUEST;

const accept = function () ACCEPT;

let ContentPolicy_ID = 0;

const RULES = {
  description: {
    map: function (v) {
      return v ? v : '';
    },
    is: ['string']
  },
  contract: {
    map: function (v) {
      if (v === undefined) {
        v = '@erikvold.com/content-policy.' + ADDON_ID + ';' + ContentPolicy_ID++;
      }
      return v;
    },
    is: ['string']
  },
  entry: {
    is: ['string', 'undefined']
  },
  shouldLoad: {
    is: ['function', 'undefined']
  },
  shouldProcess: {
    is: ['function', 'undefined']
  },
};

function getType(aType) {
  switch (aType) {
  case Ci.nsIContentPolicy.TYPE_SCRIPT:
    return 'script';
  case Ci.nsIContentPolicy.TYPE_IMAGE:
    return 'image';
  case Ci.nsIContentPolicy.TYPE_STYLESHEET:
    return 'stylesheet';
  case Ci.nsIContentPolicy.TYPE_OBJECT:
    return 'object';
  case Ci.nsIContentPolicy.TYPE_DOCUMENT:
    return 'document';
  case Ci.nsIContentPolicy.TYPE_SUBDOCUMENT:
    return 'subdocument';
  case Ci.nsIContentPolicy.TYPE_REFRESH:
    return 'refresh';
  case Ci.nsIContentPolicy.TYPE_XBL:
    return 'xbl';
  case Ci.nsIContentPolicy.TYPE_XMLHTTPREQUEST:
    return 'xhr';
  case Ci.nsIContentPolicy.TYPE_PING:
    return 'ping';
    // TODO: support more types
  }
  return 'other';
}
const getTypeMemod = memoize(getType, 12, 1);

function makeDetails(aContentType, aContentLocation, aRequestOrigin, aContext, aMimeTypeGuess) {
  return {
    type: getTypeMemod(aContentType),
    location: aContentLocation,
    origin: aRequestOrigin.spec,
    context: null, // TODO: support this in a safe way somehow..
    mimeTypeGuess: String(aMimeTypeGuess)
  };
}

let ContentPolicy = exports.ContentPolicy = Class({
  initialize: function (options) {
    const self = this;
    options = CP_NS(self).options = validateOptions(options, RULES);
    CP_NS(self).shouldLoad = options.shouldLoad || accept;
    CP_NS(self).shouldProcess = options.shouldProcess || accept;

    let factory = CP_NS(this).factory = xpcom.Factory({
      Component: getProvider(self),
      description: options.description,
      contract: options.contract
    });

    let entry = options.entry || options.contract;
    CM.addCategoryEntry('content-policy', entry, factory.contract, false, true);
    ensure(this, 'destroy');
  },
  destroy: function () {
    // already destroyed?
    if (!CP_NS(this).options)
      return;

    let options = CP_NS(this).options;
    CP_NS(this).options = null;
    CP_NS(this).shouldLoad = accept;
    CP_NS(this).shouldProcess = accept;

    CM.deleteCategoryEntry('content-policy', options.entry || options.contract, false);
  }
});

function getProvider(self) {
  return Class({
    extends: xpcom.Unknown,
    interfaces: ['nsIContentPolicy'],
    shouldLoad: function (aContentType, aContentLocation, aRequestOrigin, aContext, aMimeTypeGuess, aExtra) {
      let load = CP_NS(self).shouldLoad(makeDetails.apply(null, arguments));
      return (load == REJECT || (!load && load !== undefined)) ? REJECT : ACCEPT;
    },
    shouldProcess: function (aContentType, aContentLocation, aRequestOrigin, aContext, aMimeTypeGuess, aExtra) {
      let load = CP_NS(self).shouldProcess(makeDetails.apply(null, arguments));
      return (load == REJECT || (!load && load !== undefined)) ? REJECT : ACCEPT;
    }
  });
}

function memoize(func) {
  let cache = Object.create(null);
  return function (a) {
    let key = a.toString();
    if (!(key in cache)) {
      cache[key] = func.call(null, a);
    }
    return cache[key];
  };
}