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

Commit

Permalink
Issue #24 : Fixing broken login in Firefox 3.6 related to Like toolba…
Browse files Browse the repository at this point in the history
…ritem not appearing in the DOM
  • Loading branch information
brianking committed Jul 31, 2011
1 parent 183bad0 commit d31cbd8
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 35 deletions.
124 changes: 98 additions & 26 deletions chrome/content/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,18 @@ var facebook = {

try
{
if (event.originalTarget.location.hostname == "www.facebook.com")
var doc = event ? event.originalTarget : null;
if (!doc || doc.defaultView.frameElement)
{
// frame in document, do not process
fbLib.debug("Frame in page loading, not processing");
return;
}

if (facebook.filterURL(event))
return;

if (doc.location.hostname == "www.facebook.com")
{
if (!fbSvc.loggedIn)
{
Expand Down Expand Up @@ -266,29 +277,78 @@ var facebook = {
facebook.updateLikeCount();
},

clearLikeCount: function() {

fbLib.setAttributeById('facebook-like-iframe', 'collapsed', 'true');
fbLib.setAttributeById('facebook-like-iframe', 'src', 'about:blank');
/**
* Check a url for irregular types (about:, chrome:)
* @parameter aEvent - load event that carries the target page to extract the url from
* @return boolean true to filter out (not use the url), false to let it through
*/
filterURL: function(aEvent) {
var url = aEvent.originalTarget.location;
if (url) {
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var scheme = ioService.extractScheme(url);
// Weed out about and chrome urls
fbLib.debug("Loading " + scheme + "url...");
if (scheme == "about" || scheme == "chrome")
return true;
}
return false;
},

updateLikeCount: function() {

var url = gBrowser.currentURI.spec;

fbLib.debug("updateLikeCount: have url = '" + url + "'");
/**
* The like bug can not in the toolbarpalette because it does not appear in the DOM because
* of a bug in Firefox 3.6 where the localstore cache overrides any new items. And Like
* is a new item introduced recently.
* This function moves the Like item from being a clild of the toolbar to being a child of
* the palette where it then appers in the DOM and is visible in the toolbar
*/
moveLike: function() {
try {
var fBar = document.getElementById("facebook-toolbar");
var likeItem = document.getElementById("facebook-like");
var fns = document.getElementById("facebook-notification-separator");
var newLike = fBar.removeChild(likeItem);
fBar.insertBefore(newLike, fns.nextSibling);
}
catch(e) {
fbLib.debug("Error moving like : "+e);
}
},

facebook.clearLikeCount();
/**
* Reset the Like page
*/
clearLikeCount: function() {
try {
fbLib.setAttributeById('facebook-like-iframe', 'collapsed', 'true');
fbLib.setAttributeById('facebook-like-iframe', 'src', 'about:blank');
}
catch(e) {}
},

var prefSvc = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefBranch);
if (prefSvc.getBoolPref('extensions.facebook.like.enabled'))
{
if (url != null && url.match(/^http/))
/**
* Refresh the Like page
*/
updateLikeCount: function() {
try {
var url = gBrowser.currentURI.spec;

fbLib.debug("updateLikeCount: have url = '" + url + "'");

facebook.clearLikeCount();

var prefSvc = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefBranch);
if (prefSvc.getBoolPref('extensions.facebook.like.enabled'))
{
fbLib.setAttributeById('facebook-like-iframe', 'src',
'https://www.facebook.com/plugins/like.php?action=like&colorscheme=white&href='+url+'&layout=button_count&src=fftb');
if (url != null && url.match(/^http/))
{
fbLib.setAttributeById('facebook-like-iframe', 'src',
'https://www.facebook.com/plugins/like.php?action=like&colorscheme=white&href='+url+'&layout=button_count&src=fftb');
}
}
}
catch(e) {}
return;

// XX Not working yet
Expand Down Expand Up @@ -435,6 +495,9 @@ var facebook = {
return;
}

if (facebook.filterURL(event))
return;

if (event.originalTarget.location.hostname == "www.facebook.com" &&
event.originalTarget.location.href.indexOf("plugins/like.php") > 0)
{
Expand All @@ -454,11 +517,16 @@ var facebook = {
},

load: function() {
fbLib.debug( "loading toolbar..." );

gBrowser.addEventListener("DOMContentLoaded", facebook.onPageLoad, true);
gBrowser.tabContainer.addEventListener("TabSelect", facebook.onTabSelect, false);
document.getElementById("facebook-like-iframe").addEventListener("DOMContentLoaded", facebook.onLikeIframeLoad, true);
try {
facebook.moveLike();
document.getElementById("facebook-like-iframe").addEventListener("DOMContentLoaded", facebook.onLikeIframeLoad, true);
}
catch(e) {
// We did not find the Like button ... lets not stop because of it
fbLib.debug( "Like button not found. This feature will not be activated" );
}
document.getElementById("facebook-auth-iframe").addEventListener("DOMContentLoaded", facebook.onAuthIframeLoad, true);

facebook.clearLikeCount();
Expand Down Expand Up @@ -542,9 +610,12 @@ var facebook = {

startupLike: function()
{
var prefSvc = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefBranch);
if (prefSvc.getBoolPref('extensions.facebook.like.enabled'))
fbLib.setAttributeById('facebook-like', 'hidden', 'false');
try {
var prefSvc = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefBranch);
if (prefSvc.getBoolPref('extensions.facebook.like.enabled'))
fbLib.setAttributeById('facebook-like', 'hidden', 'false');
}
catch(e) {}
},

toggleLike: function()
Expand Down Expand Up @@ -574,7 +645,6 @@ var facebook = {
}
*/
prefSvc.setBoolPref('extensions.facebook.first_run_dialog', true);
//prefSvc.lockPref('extensions.facebook.first_run_dialog');
}
else {
facebook.startupLike();
Expand All @@ -589,7 +659,6 @@ var facebook = {
if (!prefSvc.getBoolPref('extensions.facebook.not_first_run')) {
getBrowser().loadOneTab('chrome://facebook/content/firstrun/welcome.html', null, null, null, false, false);
prefSvc.setBoolPref('extensions.facebook.not_first_run', true);
//prefSvc.lockPref('extensions.facebook.not_first_run');
}
},

Expand All @@ -606,7 +675,10 @@ var facebook = {
unload: function() {
gBrowser.removeEventListener("DOMContentLoaded", facebook.onPageLoad, true);
gBrowser.tabContainer.removeEventListener("TabSelect", facebook.onTabSelect, false);
document.getElementById("facebook-like-iframe").removeEventListener("DOMContentLoaded", facebook.onLikeIframeLoad, true);
try {
document.getElementById("facebook-like-iframe").removeEventListener("DOMContentLoaded", facebook.onLikeIframeLoad, true);
}
catch(e) {}
document.getElementById("facebook-auth-iframe").removeEventListener("DOMContentLoaded", facebook.onAuthIframeLoad, true);

for each (var topic in facebook.topics_of_interest)
Expand Down
15 changes: 8 additions & 7 deletions chrome/content/toolbar.xul
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

<!DOCTYPE window SYSTEM "chrome://facebook/locale/toolbar.dtd">

<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" id="facebook">
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
id="facebook">

<script type="application/x-javascript" src="chrome://browser/content/utilityOverlay.js"/>
<script type="application/x-javascript" src="chrome://facebook/content/lib.js"/>
Expand Down Expand Up @@ -49,11 +50,6 @@
tooltiptext="&toolbar.button.share.tooltip;"
oncommand="if (!fbSvc.loggedIn) { fbLib.FacebookLogin(); } else { facebook.share() }"/>

<toolbaritem id="facebook-like" align="center" pack="center" hidden="true">
<iframe id="facebook-like-iframe" src="about:blank" type="content"
height="20" flex="1" />
</toolbaritem>

<toolbarbutton id="facebook-photoupload"
class="facebook-icon-photoupload button facebook-toolbar-button"
tooltiptext="&toolbar.button.upload.tooltip;"
Expand Down Expand Up @@ -199,9 +195,14 @@
context="toolbar-context-menu"
toolbarname="&toolbar.facebook.name;"
crop="end"
defaultset="facebook-sidebar-toggle,separator,facebook-searchbox,facebook-link-menu,separator,facebook-home,separator,facebook-notification-poke,facebook-notification-reqs,facebook-notification-msgs,facebook-notification-event-invs,facebook-notification-group-invs,facebook-notification-separator,facebook-like,facebook-share,facebook-photoupload,spring,facebook-login-info">
defaultset="facebook-sidebar-toggle,separator,facebook-searchbox,facebook-link-menu,separator,facebook-home,separator,facebook-notification-poke,facebook-notification-reqs,facebook-notification-msgs,facebook-notification-event-invs,facebook-notification-group-invs,facebook-notification-separator,facebook-like,facebook-share,facebook-photoupload,spring,facebook-login-info">

<iframe id="facebook-auth-iframe" src="about:blank" type="content" collapsed="true"/>

<toolbaritem id="facebook-like" pack="center" align="center">
<iframe id="facebook-like-iframe" src="about:blank" type="content"
height="20" flex="1" collapsed="true" />
</toolbaritem>
</toolbar>
<popupset>
<popup position="after_start"
Expand Down
4 changes: 2 additions & 2 deletions install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<Description about="urn:mozilla:install-manifest">
<em:id>firefox@facebook.com</em:id>
<em:version>1.7.2</em:version>
<em:version>1.7.3</em:version>
<em:type>2</em:type>

<!-- Front End MetaData -->
Expand All @@ -30,7 +30,7 @@
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>3.6</em:minVersion>
<em:maxVersion>7.0a1</em:maxVersion>
<em:maxVersion>8.0a1</em:maxVersion>
</Description>
</em:targetApplication>

Expand Down

0 comments on commit d31cbd8

Please sign in to comment.