Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit beef6ae

Browse files
committed
Bug 869687 - Uplift Add-on SDK integration branch to Firefox
1 parent 2e93a2b commit beef6ae

30 files changed

Lines changed: 540 additions & 133 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

addon-sdk/source/doc/dev-guide-source/guides/content-scripts/communicating-with-other-scripts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using either the `port.emit()` API or the `postMessage()` API. See the
2121
articles on
2222
[using `postMessage()`](dev-guide/guides/content-scripts/using-postmessage.html)
2323
and
24-
[using `port`](dev-guide/guides/content-scripts//using-port.html) for details.
24+
[using `port`](dev-guide/guides/content-scripts/using-port.html) for details.
2525

2626
## Content Scripts ##
2727

addon-sdk/source/lib/sdk/context-menu.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { Class, mix } = require("./core/heritage");
1111
const { addCollectionProperty } = require("./util/collection");
1212
const { ns } = require("./core/namespace");
1313
const { validateOptions, getTypeOf } = require("./deprecated/api-utils");
14-
const { URL } = require("./url");
14+
const { URL, isValidURI } = require("./url");
1515
const { WindowTracker, browserWindowIterator } = require("./deprecated/window-utils");
1616
const { isBrowser, getInnerId } = require("./window/utils");
1717
const { Ci } = require("chrome");
@@ -264,7 +264,13 @@ let labelledItemRules = mix(baseItemRules, {
264264
},
265265
image: {
266266
map: stringOrNull,
267-
is: ["string", "undefined", "null"]
267+
is: ["string", "undefined", "null"],
268+
ok: function (url) {
269+
if (!url)
270+
return true;
271+
return isValidURI(url);
272+
},
273+
msg: "Image URL validation failed"
268274
}
269275
});
270276

addon-sdk/source/lib/sdk/io/data.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,51 @@ module.metadata = {
1010

1111
const { Cc, Ci, Cu } = require("chrome");
1212
const base64 = require("../base64");
13+
const { defer } = require("../core/promise");
14+
const { newURI } = require("../url/utils");
1315

1416
const IOService = Cc["@mozilla.org/network/io-service;1"].
1517
getService(Ci.nsIIOService);
1618

19+
const { deprecateFunction } = require('../util/deprecate');
1720
const { NetUtil } = Cu.import("resource://gre/modules/NetUtil.jsm");
1821
const FaviconService = Cc["@mozilla.org/browser/favicon-service;1"].
1922
getService(Ci.nsIFaviconService);
20-
const { deprecateFunction } = require("../util/deprecate");
23+
const AsyncFavicons = FaviconService.QueryInterface(Ci.mozIAsyncFavicons);
2124

2225
const PNG_B64 = "data:image/png;base64,";
2326
const DEF_FAVICON_URI = "chrome://mozapps/skin/places/defaultFavicon.png";
2427
let DEF_FAVICON = null;
2528

29+
/**
30+
* Takes URI of the page and returns a promise that resolves
31+
* to the page's favicon URI.
32+
* @param {String} uri
33+
* @param {Function} (callback)
34+
* @returns {Promise}
35+
*/
36+
37+
exports.getFavicon = function getFavicon(uri, callback) {
38+
let pageURI = newURI(uri);
39+
let deferred = defer();
40+
AsyncFavicons.getFaviconURLForPage(pageURI, function (aURI) {
41+
if (aURI && aURI.spec)
42+
deferred.resolve(aURI.spec.toString());
43+
else
44+
deferred.reject(null);
45+
});
46+
if (callback) deferred.promise.then(callback, callback);
47+
return deferred.promise;
48+
};
49+
2650
/**
2751
* Takes URI of the page and returns associated favicon URI.
2852
* If page under passed uri has no favicon then base64 encoded data URI of
2953
* default faveicon is returned.
3054
* @param {String} uri
3155
* @returns {String}
3256
*/
33-
exports.getFaviconURIForLocation = function getFaviconURIForLocation(uri) {
57+
function getFaviconURIForLocation(uri) {
3458
let pageURI = NetUtil.newURI(uri);
3559
try {
3660
return FaviconService.getFaviconDataAsDataURL(
@@ -44,6 +68,7 @@ exports.getFaviconURIForLocation = function getFaviconURIForLocation(uri) {
4468
return DEF_FAVICON;
4569
}
4670
}
71+
exports.getFaviconURIForLocation = getFaviconURIForLocation;
4772

4873
/**
4974
* Takes chrome URI and returns content under that URI.

addon-sdk/source/lib/sdk/test/httpd.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ nsHttpServer.prototype =
511511
dumpn(">>> listening on port " + socket.port + ", " + maxConnections +
512512
" pending connections");
513513
socket.asyncListen(this);
514-
this._identity._initialize(port, host, true);
514+
this._identity._initialize(socket.port, host, true);
515515
this._socket = socket;
516516
}
517517
catch (e)
@@ -5178,7 +5178,6 @@ function server(port, basePath)
51785178
if (lp)
51795179
srv.registerDirectory("/", lp);
51805180
srv.registerContentType("sjs", SJS_TYPE);
5181-
srv.identity.setPrimary("http", "localhost", port);
51825181
srv.start(port);
51835182

51845183
var thread = gThreadManager.currentThread;
@@ -5205,7 +5204,6 @@ function startServerAsync(port, basePath)
52055204
if (lp)
52065205
srv.registerDirectory("/", lp);
52075206
srv.registerContentType("sjs", "sjs");
5208-
srv.identity.setPrimary("http", "localhost", port);
52095207
srv.start(port);
52105208
return srv;
52115209
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
"use strict";
6+
7+
module.metadata = {
8+
"stability": "experimental"
9+
};
10+
11+
const { Cc, Ci, Cr } = require("chrome");
12+
const IOService = Cc["@mozilla.org/network/io-service;1"].
13+
getService(Ci.nsIIOService);
14+
const { isValidURI } = require("../url");
15+
16+
function newURI (uri) {
17+
if (!isValidURI(uri))
18+
throw new Error("malformed URI: " + uri);
19+
return IOService.newURI(uri, null, null);
20+
}
21+
exports.newURI = newURI;

addon-sdk/source/python-lib/cuddlefish/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,9 @@ def run(arguments=sys.argv[1:], target_cfg=None, pkg_cfg=None,
899899
xpi_path=xpi_path,
900900
harness_options=harness_options,
901901
limit_to=used_files,
902-
extra_harness_options=extra_harness_options)
902+
extra_harness_options=extra_harness_options,
903+
bundle_sdk=True,
904+
pkgdir=options.pkgdir)
903905
else:
904906
from cuddlefish.runner import run_app
905907

@@ -931,7 +933,8 @@ def run(arguments=sys.argv[1:], target_cfg=None, pkg_cfg=None,
931933
env_root=env_root,
932934
is_running_tests=(command == "test"),
933935
overload_modules=options.overload_modules,
934-
bundle_sdk=options.bundle_sdk)
936+
bundle_sdk=options.bundle_sdk,
937+
pkgdir=options.pkgdir)
935938
except ValueError, e:
936939
print ""
937940
print "A given cfx option has an inappropriate value:"

addon-sdk/source/python-lib/cuddlefish/runner.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# The purpose of this timeout is to recover from infinite loops. It should be
3131
# longer than the amount of time any test run takes, including those on slow
3232
# machines running slow (debug) versions of Firefox.
33-
RUN_TIMEOUT = 30 * 60 # 30 minutes
33+
RUN_TIMEOUT = 45 * 60 # 45 minutes
3434

3535
# Maximum time we'll wait for tests to emit output, in seconds.
3636
# The purpose of this timeout is to recover from hangs. It should be longer
@@ -412,7 +412,8 @@ def run_app(harness_root_dir, manifest_rdf, harness_options,
412412
env_root=None,
413413
is_running_tests=False,
414414
overload_modules=False,
415-
bundle_sdk=True):
415+
bundle_sdk=True,
416+
pkgdir=""):
416417
if binary:
417418
binary = os.path.expanduser(binary)
418419

@@ -516,7 +517,8 @@ def maybe_remove_logfile():
516517
xpi_path=xpi_path,
517518
harness_options=harness_options,
518519
limit_to=used_files,
519-
bundle_sdk=bundle_sdk)
520+
bundle_sdk=bundle_sdk,
521+
pkgdir=pkgdir)
520522
addons.append(xpi_path)
521523

522524
starttime = last_output_time = time.time()

addon-sdk/source/python-lib/cuddlefish/xpi.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ def mkzipdir(zf, path):
2323

2424
def build_xpi(template_root_dir, manifest, xpi_path,
2525
harness_options, limit_to=None, extra_harness_options={},
26-
bundle_sdk=True):
26+
bundle_sdk=True, pkgdir=""):
27+
IGNORED_FILES = [".hgignore", ".DS_Store", "install.rdf",
28+
"application.ini", xpi_path]
29+
30+
files_to_copy = {} # maps zipfile path to local-disk abspath
31+
dirs_to_create = set() # zipfile paths, no trailing slash
32+
2733
zf = zipfile.ZipFile(xpi_path, "w", zipfile.ZIP_DEFLATED)
2834

2935
open('.install.rdf', 'w').write(str(manifest))
@@ -39,6 +45,31 @@ def build_xpi(template_root_dir, manifest, xpi_path,
3945
zf.write(str(harness_options['icon64']), 'icon64.png')
4046
del harness_options['icon64']
4147

48+
# chrome.manifest
49+
if os.path.isfile(os.path.join(pkgdir, 'chrome.manifest')):
50+
files_to_copy['chrome.manifest'] = os.path.join(pkgdir, 'chrome.manifest')
51+
52+
# chrome folder (would contain content, skin, and locale folders typically)
53+
folder = 'chrome'
54+
if os.path.exists(os.path.join(pkgdir, folder)):
55+
dirs_to_create.add('chrome')
56+
# cp -r folder
57+
abs_dirname = os.path.join(pkgdir, folder)
58+
for dirpath, dirnames, filenames in os.walk(abs_dirname):
59+
goodfiles = list(filter_filenames(filenames, IGNORED_FILES))
60+
dirnames[:] = filter_dirnames(dirnames)
61+
for dirname in dirnames:
62+
arcpath = make_zipfile_path(template_root_dir,
63+
os.path.join(dirpath, dirname))
64+
dirs_to_create.add(arcpath)
65+
for filename in goodfiles:
66+
abspath = os.path.join(dirpath, filename)
67+
arcpath = ZIPSEP.join(
68+
[folder,
69+
make_zipfile_path(abs_dirname, os.path.join(dirpath, filename)),
70+
])
71+
files_to_copy[str(arcpath)] = str(abspath)
72+
4273
# Handle simple-prefs
4374
if 'preferences' in harness_options:
4475
from options_xul import parse_options, validate_prefs
@@ -63,12 +94,6 @@ def build_xpi(template_root_dir, manifest, xpi_path,
6394
os.remove('.prefs.js')
6495

6596

66-
IGNORED_FILES = [".hgignore", ".DS_Store", "install.rdf",
67-
"application.ini", xpi_path]
68-
69-
files_to_copy = {} # maps zipfile path to local-disk abspath
70-
dirs_to_create = set() # zipfile paths, no trailing slash
71-
7297
for dirpath, dirnames, filenames in os.walk(template_root_dir):
7398
filenames = list(filter_filenames(filenames, IGNORED_FILES))
7499
dirnames[:] = filter_dirnames(dirnames)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
content test chrome/content/
2+
skin test classic/1.0 chrome/skin/
3+
4+
locale test en-US chrome/locale/en-US/
5+
locale test ja-JP chrome/locale/ja-JP/

0 commit comments

Comments
 (0)