Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #763 from erikvold/820582
Browse files Browse the repository at this point in the history
Fix Bug 820582 adding private-browsing flag to package.json r=@Gozala
  • Loading branch information
erikvold committed Feb 20, 2013
2 parents d6a76a2 + 9ded485 commit d1f3d51
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 11 deletions.
9 changes: 9 additions & 0 deletions app-extension/bootstrap.js
Expand Up @@ -74,6 +74,15 @@ function startup(data, reasonCode) {

let id = options.jetpackID;
let name = options.name;

// Clean the metadata
options.metadata[name]['permissions'] = options.metadata[name]['permissions'] || {};

// freeze the permissionss
Object.freeze(options.metadata[name]['permissions']);
// freeze the metadata
Object.freeze(options.metadata[name]);

// Register a new resource 'domain' for this addon which is mapping to
// XPI's `resources` folder.
// Generate the domain name by using jetpack ID, which is the extension ID
Expand Down
6 changes: 5 additions & 1 deletion doc/dev-guide-source/package-spec.md
Expand Up @@ -93,7 +93,11 @@ called `package.json`. This file is also referred to as the
`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`, where `x` represents a single
hexadecimal digit. It is used as a `classID` (CID) of the "harness service"
XPCOM component. Defaults to a random GUID generated by `cfx`.


* `permissions` - a set of permissions that the add-on needs.
* `private-browsing` - A Boolean indicating whether or not the
package supports private browsing. If this value is not `true`
then the package will not see private windows.

## Documentation ##

Expand Down
8 changes: 8 additions & 0 deletions doc/module-source/sdk/self.md
Expand Up @@ -51,6 +51,12 @@ downgrade

</api>

<api name="isPrivateBrowsingSupported">
@property {boolean}
This property indicates add-on's support for private browsing. It comes from the
`private-browsing` property set in the `package.json` file in the main package.
</api>

<api name="data">
@property {object}
The `data` object is used to access data that was bundled with the add-on.
Expand Down Expand Up @@ -92,3 +98,5 @@ as the Panel:
@returns {String}
</api>
</api>


6 changes: 3 additions & 3 deletions lib/sdk/self.js
Expand Up @@ -2,16 +2,14 @@
* 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/. */

"use strict";

module.metadata = {
"stability": "stable"
};


const { CC } = require('chrome');
const { id, name, prefixURI, rootURI,
const { id, name, prefixURI, rootURI, metadata,
version, loadReason } = require('@loader/options');

const { readURISync } = require('./net/url');
Expand Down Expand Up @@ -39,3 +37,5 @@ exports.data = Object.freeze({
return readURISync(uri(path));
}
});
exports.isPrivateBrowsingSupported = ((metadata.permissions || {})['private-browsing'] === true) ?
true : false;
2 changes: 2 additions & 0 deletions python-lib/cuddlefish/__init__.py
Expand Up @@ -832,10 +832,12 @@ def run(arguments=sys.argv[1:], target_cfg=None, pkg_cfg=None,

if command == 'xpi':
from cuddlefish.xpi import build_xpi
# Generate extra options
extra_harness_options = {}
for kv in options.extra_harness_option_args:
key,value = kv.split("=", 1)
extra_harness_options[key] = value
# Generate xpi filepath
xpi_path = XPI_FILENAME % target_cfg.name
print >>stdout, "Exporting extension to %s." % xpi_path
build_xpi(template_root_dir=app_extension_dir,
Expand Down
2 changes: 1 addition & 1 deletion python-lib/cuddlefish/packaging.py
Expand Up @@ -23,7 +23,7 @@

METADATA_PROPS = ['name', 'description', 'keywords', 'author', 'version',
'translators', 'contributors', 'license', 'homepage', 'icon',
'icon64', 'main', 'directories']
'icon64', 'main', 'directories', 'permissions']

RESOURCE_HOSTNAME_RE = re.compile(r'^[a-z0-9_\-]+$')

Expand Down
7 changes: 6 additions & 1 deletion python-lib/cuddlefish/xpi.py
Expand Up @@ -29,6 +29,7 @@ def build_xpi(template_root_dir, manifest, xpi_path,
zf.write('.install.rdf', 'install.rdf')
os.remove('.install.rdf')

# Handle add-on icon
if 'icon' in harness_options:
zf.write(str(harness_options['icon']), 'icon.png')
del harness_options['icon']
Expand All @@ -37,6 +38,7 @@ def build_xpi(template_root_dir, manifest, xpi_path,
zf.write(str(harness_options['icon64']), 'icon64.png')
del harness_options['icon64']

# Handle simple-prefs
if 'preferences' in harness_options:
from options_xul import parse_options, validate_prefs

Expand Down Expand Up @@ -133,20 +135,23 @@ def build_xpi(template_root_dir, manifest, xpi_path,
parentpath = ZIPSEP.join(bits[0:i])
dirs_to_create.add(parentpath)

# create zipfile in alphabetical order, with each directory before its
# Create zipfile in alphabetical order, with each directory before its
# files
for name in sorted(dirs_to_create.union(set(files_to_copy))):
if name in dirs_to_create:
mkzipdir(zf, name+"/")
if name in files_to_copy:
zf.write(files_to_copy[name], name)

# Add extra harness options
harness_options = harness_options.copy()
for key,value in extra_harness_options.items():
if key in harness_options:
msg = "Can't use --harness-option for existing key '%s'" % key
raise HarnessOptionAlreadyDefinedError(msg)
harness_options[key] = value

# Write harness-options.json
open('.options.json', 'w').write(json.dumps(harness_options, indent=1,
sort_keys=True))
zf.write('.options.json', 'harness-options.json')
Expand Down
13 changes: 13 additions & 0 deletions test/addons/private-browsing-supported/main.js
@@ -0,0 +1,13 @@
/* 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/. */
'use strict';

const { isPrivateBrowsingSupported } = require('sdk/self');

exports.testIsPrivateBrowsingTrue = function(assert) {
assert.ok(isPrivateBrowsingSupported,
'isPrivateBrowsingSupported property is true');
};

require('sdk/test/runner').runTestsFromModule(module);
6 changes: 6 additions & 0 deletions test/addons/private-browsing-supported/package.json
@@ -0,0 +1,6 @@
{
"id": "private-browsing-mode-test@jetpack",
"permissions": {
"private-browsing": true
}
}
37 changes: 33 additions & 4 deletions test/test-packaging.js
@@ -1,15 +1,44 @@
/* 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/. */
"use strict";

var url = require("sdk/url");
var file = require("sdk/io/file");
var {Cm,Ci} = require("chrome");
var options = require("@loader/options");

exports.testPackaging = function(test) {

test.assertEqual(options.metadata.description,
"Add-on development made easy.",
"packaging metadata should be available");
try {
options.metadata.description = 'new description';
test.fail('should not have been able to set options.metadata property');
}
catch (e) {}

test.assertEqual(options.metadata.description,
"Add-on development made easy.",
"packaging metadata should be frozen");

test.assertEqual(options.metadata.permissions['private-browsing'], undefined,
"private browsing metadata should be undefined");
test.assertEqual(options.metadata['private-browsing'], undefined,
"private browsing metadata should be be frozen");
test.assertEqual(options['private-browsing'], undefined,
"private browsing metadata should be be frozen");

try {
options.metadata['private-browsing'] = true;
test.fail('should not have been able to set options.metadata property');
}
catch(e) {}
test.assertEqual(options.metadata['private-browsing'], undefined,
"private browsing metadata should be be frozen");

try {
options.metadata.permissions['private-browsing'] = true;
test.fail('should not have been able to set options.metadata.permissions property');
}
catch (e) {}
test.assertEqual(options.metadata.permissions['private-browsing'], undefined,
"private browsing metadata should be be frozen");
};
8 changes: 7 additions & 1 deletion test/test-private-browsing.js
Expand Up @@ -8,6 +8,7 @@ const { pb, pbUtils, getOwnerWindow } = require('./private-browsing/helper');
const { merge } = require('sdk/util/object');
const windows = require('sdk/windows').browserWindows;
const winUtils = require('sdk/window/utils');
const { isPrivateBrowsingSupported } = require('sdk/self');
const { is } = require('sdk/system/xul-app');
const { isPrivate } = require('sdk/private-browsing');

Expand Down Expand Up @@ -57,6 +58,11 @@ exports.testIsActiveDefault = function(test) {
'pb.isActive returns false when private browsing isn\'t supported');
};

exports.testIsPrivateBrowsingFalseDefault = function(test) {
test.assertEqual(isPrivateBrowsingSupported, false,
'usePrivateBrowsing property is false by default');
};

exports.testGetOwnerWindow = function(test) {
test.waitUntilDone();

Expand Down Expand Up @@ -84,4 +90,4 @@ exports.testGetOwnerWindow = function(test) {
tab.close(function() test.done());
}
});
}
};
3 changes: 3 additions & 0 deletions test/test-self.js
Expand Up @@ -32,6 +32,9 @@ exports.testSelf = function(test) {
// loadReason may change here, as we change the way tests addons are installed
test.assertEqual(self.loadReason, "startup",
"self.loadReason is always `startup` on test runs");

test.assertEqual(self.isPrivateBrowsingSupported, false,
'usePrivateBrowsing property is false by default');
};

exports.testSelfID = function(test) {
Expand Down

0 comments on commit d1f3d51

Please sign in to comment.