Skip to content
This repository has been archived by the owner on Dec 4, 2017. It is now read-only.

Commit

Permalink
Change preference handling in add-on to keep social.activeProviders p…
Browse files Browse the repository at this point in the history
…reference clean
  • Loading branch information
Standard8 committed Feb 14, 2013
1 parent 31de95b commit babc9a7
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 39 deletions.
89 changes: 52 additions & 37 deletions addon/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const kSidebarPage = "/sidebar.htm";
const kSiteImageLocation = "/icon.png";
const kPrefName = "social.manifest.webrtc-demo";
const kUserImageLocation = "/icon.png";
const kWrappsSiteURLPref = "addons.wrapps.siteURL";
const kWrappsSiteURLPref = "addons.wrapps.social.siteURL";

const BOOTSTRAP_REASONS = {
APP_STARTUP : 1,
Expand All @@ -20,6 +20,15 @@ const BOOTSTRAP_REASONS = {
};

let webrtcbrowser = {
currentSiteURL: null,

get siteURLPrefValue() {
let siteURL = kSiteURL;
if (Services.prefs.prefHasUserValue(kWrappsSiteURLPref))
siteURL = Services.prefs.getCharPref(kWrappsSiteURLPref);
return siteURL;
},

get isCurrentProvider() {
var currentProvider = "";
try {
Expand Down Expand Up @@ -167,7 +176,36 @@ let webrtcbrowser = {
}
},

setDefaultProvider: function webrtcbrowser_setDefaultProvider(aSiteURL) {
if (!aSiteURL)
aSiteURL = kSiteURL;

if (this.currentSiteURL && this.currentSiteURL != aSiteURL)
removeActiveProvider(this.currentSiteURL);

this.currentSiteURL = aSiteURL;

Services.prefs.setCharPref(kPrefName, '{"location":"' + aSiteURL + '/manifest.json","name":"' + kSiteName + '","iconURL":"' + aSiteURL + kSiteImageLocation + '","workerURL":"' + aSiteURL + '/worker.js","sidebarURL":"' + aSiteURL + kSidebarPage + '","origin":"' + aSiteURL + '","enabled":true,"last_modified":135101330568}');
var activeProviders;
try {
activeProviders = JSON.parse(Services.prefs.getCharPref("social.activeProviders"));
} catch (x) {
activeProviders = {};
}

activeProviders[aSiteURL] = 1;
Services.prefs.setCharPref("social.activeProviders", JSON.stringify(activeProviders));
Services.prefs.setCharPref("social.provider.current", aSiteURL);

Services.prefs.setBoolPref("media.navigator.enabled", true);
Services.prefs.setBoolPref("media.navigator.permission.disabled", true);
Services.prefs.setBoolPref("media.peerconnection.enabled", true);
Services.prefs.setBoolPref("dom.disable_open_during_load", false);
Services.prefs.setBoolPref("social.enabled", true);
},

init: function webrtcbrowser_init() {
this.currentSiteURL = this.siteURLPrefValue;
Services.obs.addObserver(this, "social:profile-changed", false);
this.setWidths();
this.setStyle();
Expand Down Expand Up @@ -232,28 +270,8 @@ function shutdown(data, reason) {
*/
}

function setDefaultProvider(aSiteURL) {
Services.prefs.setCharPref(kPrefName, '{"location":"' + aSiteURL + '/manifest.json","name":"' + kSiteName + '","iconURL":"' + aSiteURL + kSiteImageLocation + '","workerURL":"' + aSiteURL + '/worker.js","sidebarURL":"' + aSiteURL + kSidebarPage + '","origin":"' + aSiteURL + '","enabled":true,"last_modified":135101330568}');
var activeProviders;
try {
activeProviders = JSON.parse(Services.prefs.getCharPref("social.activeProviders"));
} catch (x) {
activeProviders = {};
}

activeProviders[aSiteURL] = 1;
Services.prefs.setCharPref("social.activeProviders", JSON.stringify(activeProviders));
Services.prefs.setCharPref("social.provider.current", aSiteURL);

Services.prefs.setBoolPref("media.navigator.enabled", true);
Services.prefs.setBoolPref("media.navigator.permission.disabled", true);
Services.prefs.setBoolPref("media.peerconnection.enabled", true);
Services.prefs.setBoolPref("dom.disable_open_during_load", false);
Services.prefs.setBoolPref("social.enabled", true);
}

function prefChangeListener(aSubject, aTopic, aData) {
setDefaultProvider(Services.prefs.getCharPref(kWrappsSiteURLPref));
webrtcbrowser.setDefaultProvider(webrtcbrowser.siteURLPrefValue);
}

function install(data, reason) {
Expand All @@ -262,13 +280,8 @@ function install(data, reason) {
case BOOTSTRAP_REASONS.ADDON_UPGRADE:
case BOOTSTRAP_REASONS.ADDON_DOWNGRADE:
{
var siteURL = kSiteURL;
if (Services.prefs.prefHasUserValue(kWrappsSiteURLPref))
siteURL = Services.prefs.getCharPref(kWrappsSiteURLPref);
else
Services.prefs.setCharPref(kWrappsSiteURLPref, siteURL);
setDefaultProvider(siteURL);

// Need to do this before init to ensure the preferences are set correctly
webrtcbrowser.setDefaultProvider(webrtcbrowser.siteURLPrefValue);
webrtcbrowser.init();
break;
}
Expand All @@ -277,6 +290,15 @@ function install(data, reason) {
}
}

function removeActiveProvider(providerURL) {
try {
var activeProviders = JSON.parse(Services.prefs.getCharPref("social.activeProviders"));
delete activeProviders[providerURL];
Services.prefs.setCharPref("social.activeProviders", JSON.stringify(activeProviders));
} catch (x) {
}
}

function uninstall(data, reason) {
Services.prefs.clearUserPref("social.enabled");
Services.prefs.clearUserPref("media.navigator.enabled");
Expand All @@ -287,13 +309,6 @@ function uninstall(data, reason) {
Services.prefs.clearUserPref(kPrefName);
Services.prefs.clearUserPref("social.provider.current");

var activeProviders;
try {
activeProviders = JSON.parse(Services.prefs.getCharPref("social.activeProviders"));
delete activeProviders[Services.prefs.getCharPref(kWrappsSiteURLPref)];
Services.prefs.setCharPref("social.activeProviders", JSON.stringify(activeProviders));
} catch (x) {
activeProviders = {};
}
removeActiveProvider(Services.prefs.getCharPref(kWrappsSiteURLPref));
webrtcbrowser.uninit();
}
2 changes: 1 addition & 1 deletion addon/options.xul
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" ?>
<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<setting pref="addons.wrapps.siteURL" type="string" title="Demo site URL"/>
<setting pref="addons.wrapps.social.siteURL" type="string" title="Demo site URL"/>
</vbox>
2 changes: 1 addition & 1 deletion static/update.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<em:maxVersion>21.0a1</em:maxVersion>
<em:updateLink>https://webrtc-demo.vcap.mozillalabs.com/webrtc.xpi</em:updateLink>
<em:updateInfoURL>https://webrtc-demo.vcap.mozillalabs.com/update.txt</em:updateInfoURL>
<em:updateHash>sha256:24f2459029905bfcdab14e6d3bc0562213281c0d7d5d8ce13b05f4dfe8a90168</em:updateHash>
<em:updateHash>sha256:df254a8428420c6a3028e08e2dd7adf4fd5d5dd086cca905491a361c265764f4</em:updateHash>
</RDF:Description>
</em:targetApplication>
</RDF:Description>
Expand Down
Binary file modified static/webrtc.xpi
Binary file not shown.

0 comments on commit babc9a7

Please sign in to comment.