Skip to content

Commit

Permalink
Bug 766403: add provider class for the social service, r=jaws,adw
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinsharp committed Jun 27, 2012
1 parent 92a6b07 commit dab5797
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
3 changes: 3 additions & 0 deletions browser/app/profile/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -1182,3 +1182,6 @@ pref("pdfjs.previousHandler.alwaysAskBeforeHandling", false);
// 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\"}");
1 change: 1 addition & 0 deletions toolkit/components/social/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ include $(DEPTH)/config/autoconf.mk
EXTRA_JS_MODULES = \
FrameWorker.jsm \
SocialService.jsm \
SocialProvider.jsm \
$(NULL)

TEST_DIRS += \
Expand Down
55 changes: 55 additions & 0 deletions toolkit/components/social/SocialProvider.jsm
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 3 additions & 1 deletion toolkit/components/social/SocialService.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
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.");

Expand All @@ -19,7 +21,7 @@ const SocialService = {
}
catch (err) {}
if (manifest && typeof(manifest) == "object") {
memo[manifest.origin] = Object.create(manifest);
memo[manifest.origin] = new SocialProvider(manifest);
}
return memo;
}, {}, this);
Expand Down
6 changes: 4 additions & 2 deletions toolkit/components/social/test/xpcshell/test_getProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
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) {
Expand All @@ -26,8 +27,9 @@ function test(manifests, next) {
let manifest = manifests[i];
let provider = yield SocialService.getProvider(manifest.origin, next);
do_check_neq(provider, null);
do_check_eq(provider.origin, manifest.origin);
do_check_eq(provider.name, manifest.name);
do_check_eq(provider.workerURL, manifest.workerURL);
do_check_eq(provider.origin, manifest.origin);
}
do_check_eq((yield SocialService.getProvider("bogus", next)), null);
}

0 comments on commit dab5797

Please sign in to comment.