author | Gavin Sharp <gavin@gavinsharp.com> |
Tue, 26 Jun 2012 19:03:32 -0700 | |
changeset 98447 | c265b644a72cb0121684c4664bec9892efe360ef |
parent 98446 | 7851dc0f395cc916ce188de45d276223080444fb |
child 98448 | e548482bc255ebafb9da74f5be97053e4db05a77 |
push id | 23057 |
push user | ryanvm@gmail.com |
push date | Fri, 06 Jul 2012 00:26:58 +0000 |
treeherder | mozilla-central@4b1249ae1906 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | jaws, adw |
bugs | 766403 |
milestone | 16.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -1177,8 +1177,11 @@ pref("pdfjs.firstRun", true); // became the default. pref("pdfjs.previousHandler.preferredAction", 0); pref("pdfjs.previousHandler.alwaysAskBeforeHandling", false); // The maximum amount of decoded image data we'll willingly keep around (we // might keep around more than this, but we'll try to get down to this value). // (This is intentionally on the high side; see bug 746055.) pref("image.mem.max_decoded_image_kb", 256000); + +// Example social provider +pref("social.manifest.motown", "{\"origin\":\"https://motown-dev.mozillalabs.com\",\"name\":\"MoTown\",\"workerURL\":\"https://motown-dev.mozillalabs.com/social/worker.js\"}");
--- a/toolkit/components/social/Makefile.in +++ b/toolkit/components/social/Makefile.in @@ -7,15 +7,16 @@ topsrcdir = @top_srcdir@ srcdir = @srcdir@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk EXTRA_JS_MODULES = \ FrameWorker.jsm \ SocialService.jsm \ + SocialProvider.jsm \ $(NULL) TEST_DIRS += \ test \ $(NULL) include $(topsrcdir)/config/rules.mk
new file mode 100644 --- /dev/null +++ b/toolkit/components/social/SocialProvider.jsm @@ -0,0 +1,55 @@ +/* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* 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/. */ + +const {classes: Cc, interfaces: Ci, utils: Cu} = Components; + +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/FrameWorker.jsm"); + +const EXPORTED_SYMBOLS = ["SocialProvider"]; + +/** + * The SocialProvider object represents a social provider, and allows + * controlling its FrameWorker. + * + * @constructor + * @param {jsobj} object representing the manifest file describing this provider + */ +function SocialProvider(input) { + if (!input.name) + throw new Error("SocialProvider must be passed a name"); + if (!input.workerURL) + throw new Error("SocialProvider must be passed a workerURL"); + if (!input.origin) + throw new Error("SocialProvider must be passed an origin"); + + this.name = input.name; + this.workerURL = input.workerURL; + this.origin = input.origin; +} + +SocialProvider.prototype = { + /** + * Terminate's the provider's FrameWorker, closing all of its ports. + */ + terminate: function shutdown() { + try { + getFrameWorkerHandle(this.workerURL, null).terminate(); + } catch (e) { + Cu.reportError("SocialProvider termination failed: " + e); + } + }, + + /** + * Instantiates a FrameWorker for the provider if one doesn't exist, and + * returns a reference to a port to that FrameWorker. + * + * @param {DOMWindow} window (optional) + */ + getWorkerPort: function getWorkerPort(window) { + return getFrameWorkerHandle(this.workerURL, window).port; + } +}
--- a/toolkit/components/social/SocialService.jsm +++ b/toolkit/components/social/SocialService.jsm @@ -1,30 +1,32 @@ /* 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/. */ const EXPORTED_SYMBOLS = ["SocialService"]; const { classes: Cc, interfaces: Ci, utils: Cu } = Components; + Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/SocialProvider.jsm"); const MANIFEST_PREFS = Services.prefs.getBranch("social.manifest."); const SocialService = { _init: function _init() { let origins = MANIFEST_PREFS.getChildList("", {}); this._providers = origins.reduce(function (memo, origin) { try { var manifest = JSON.parse(MANIFEST_PREFS.getCharPref(origin)); } catch (err) {} if (manifest && typeof(manifest) == "object") { - memo[manifest.origin] = Object.create(manifest); + memo[manifest.origin] = new SocialProvider(manifest); } return memo; }, {}, this); }, getProvider: function getProvider(origin, onDone) { schedule((function () { onDone(this._providers[origin] || null);
--- a/toolkit/components/social/test/xpcshell/test_getProvider.js +++ b/toolkit/components/social/test/xpcshell/test_getProvider.js @@ -1,17 +1,18 @@ /* 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/. */ function run_test() { let manifests = [0, 1, 2].map(function (i) { return { - origin: "http://example" + i + ".com", name: "provider " + i, + workerURL: "http://example" + i + ".com/worker.js", + origin: "http://example" + i + ".com" }; }); manifests.forEach(function (manifest) { MANIFEST_PREFS.setCharPref(manifest.origin, JSON.stringify(manifest)); }); do_register_cleanup(function () MANIFEST_PREFS.deleteBranch("")); Cu.import("resource://gre/modules/SocialService.jsm"); @@ -21,13 +22,14 @@ function run_test() { runner.next(); } function test(manifests, next) { for (let i = 0; i < manifests.length; i++) { let manifest = manifests[i]; let provider = yield SocialService.getProvider(manifest.origin, next); do_check_neq(provider, null); + do_check_eq(provider.name, manifest.name); + do_check_eq(provider.workerURL, manifest.workerURL); do_check_eq(provider.origin, manifest.origin); - do_check_eq(provider.name, manifest.name); } do_check_eq((yield SocialService.getProvider("bogus", next)), null); }