Skip to content

Commit

Permalink
Added Sign Out menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
Garoe committed May 8, 2017
1 parent 2ecca1d commit 96a4735
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 26 deletions.
25 changes: 0 additions & 25 deletions content/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,29 +123,4 @@ TKPManager.prototype.onToolbarButtonClick = function(event) {

} catch(e) {Cu.reportError("ThunderKeepPlus: onToolbarButtonClick " + e);}
}
TKPManager.prototype.onLogOut = function(event) {

// Log out the user by removing the google.com cookies
try{

let cookieOrigin = "google.com"; // Cookies from here will be removed
let cookieManager = Services.cookies;

let numCookies = cookieManager.countCookiesFromHost(cookieOrigin);
this.debug("Found " + numCookies + " cookies from " + cookieOrigin);

if (numCookies > 0) {
let cookies = cookieManager.getCookiesFromHost(cookieOrigin);
let cookie = null;
while (cookies.hasMoreElements()){
cookie = cookies.getNext().QueryInterface(Ci.nsICookie2);
this.debug("\tRemoving cookie [" + cookie.host + "], [" + cookie.name + "], [" + cookie.path + "]");
cookieManager.remove(cookie.host, cookie.name, cookie.path, false, cookieOrigin);
}
}

this.debug("Done removing cookies");

} catch(e) {Cu.reportError("ThunderKeepPlus: onToolbarButtonClick " + e);}
}

50 changes: 49 additions & 1 deletion content/ui.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Cu.import("resource://gre/modules/Services.jsm");
function Ui(enableDebug) {
this.enableDebug = enableDebug;
this.buttonNode = null;
this.menuNode = null;
this.window = null;
this.loaded = false;

Expand All @@ -33,6 +34,7 @@ function Ui(enableDebug) {
this.prefs_branch = Services.prefs.getBranch("extensions.thunderkeepplus.");

this.afterCustomizeFnc = this.afterCustomize.bind(this);
this.onSignOutFnc = this.onSignOut.bind(this);
}

Ui.prototype = {
Expand Down Expand Up @@ -73,6 +75,9 @@ Ui.prototype = {
if(this.buttonNode != null && this.buttonNode.parentNode != null){
this.buttonNode.parentNode.removeChild(this.buttonNode);
}
if(this.menuNode != null && this.menuNode.parentNode != null){
this.menuNode.parentNode.removeChild(this.menuNode);
}
this.buttonNode = null;
this.window = null;
} catch(e) {Cu.reportError("ThunderKeepPlus: Ui.destroy " + e);}
Expand Down Expand Up @@ -128,10 +133,28 @@ Ui.prototype = {
3000);
}
this.window.addEventListener("aftercustomization", this.afterCustomizeFnc, false);


// Create the sign out menu item in Tools
parentNode = this.window.document.getElementById("taskPopup");
this.menuNode = this.window.document.createElement("menuitem");
this.menuNode.setAttribute("id", "thunderkeepplus-menu");
this.menuNode.setAttribute("label", "Google Keep Sign Out");

// Insert before the JavaScript console menu item
let nextNode = this.window.document.getElementById("javascriptConsole");

if (nextNode != null){
parentNode.insertBefore(this.menuNode, nextNode);
} else {
parentNode.appendChild(this.menuNode);
}

this.menuNode.addEventListener("command", this.onSignOutFnc, false);
}
} catch(e) {Cu.reportError("ThunderKeepPlus: createOverlay " + e);}
},

afterCustomize: function (e) {
try{
this.debug("Ui afterCustomize");
Expand All @@ -149,6 +172,31 @@ Ui.prototype = {
this.prefs_branch.getCharPref("parentNodeId") +"\", nextNodeId: \"" +
this.prefs_branch.getCharPref("nextNodeId") + "\"");
} catch(e) {Cu.reportError("ThunderKeepPlus: createOverlay " + e);}
},

onSignOut: function(event) {
// Log out the user by removing the google.com cookies
try{

let cookieOrigin = "google.com"; // Cookies from here will be removed
let cookieManager = Services.cookies;

let numCookies = cookieManager.countCookiesFromHost(cookieOrigin);
this.debug("Found " + numCookies + " cookies from " + cookieOrigin);

if (numCookies > 0) {
let cookies = cookieManager.getCookiesFromHost(cookieOrigin);
let cookie = null;
while (cookies.hasMoreElements()){
cookie = cookies.getNext().QueryInterface(Ci.nsICookie2);
this.debug("\tRemoving cookie [" + cookie.host + "], [" + cookie.name + "], [" + cookie.path + "]");
cookieManager.remove(cookie.host, cookie.name, cookie.path, false, cookieOrigin);
}
}

this.debug("Done removing cookies");

} catch(event) {Cu.reportError("ThunderKeepPlus: onSignOut " + event);}
}
}

0 comments on commit 96a4735

Please sign in to comment.