Skip to content

Commit

Permalink
Merge pull request #258 from patricksnape/issue_257
Browse files Browse the repository at this point in the history
Fixes #257 and #260 - User account switcher broken
  • Loading branch information
honestbleeps committed Mar 9, 2013
2 parents ea04833 + aa6bb4a commit 9989ef8
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 108 deletions.
10 changes: 8 additions & 2 deletions Chrome/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ XHRCache = {
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse) {
switch(request.requestType) {
case 'deleteCookie':
// Get chrome cookie handler
if (!chrome.cookies) {
chrome.cookies = chrome.experimental.cookies;
}
chrome.cookies.remove({'url': 'http://reddit.com', 'name': request.cname});
break;
case 'GM_xmlhttpRequest':
if (request.aggressiveCache || XHRCache.forceCache) {
var cachedResult = XHRCache.check(request.url);
Expand All @@ -98,12 +105,11 @@ chrome.extension.onMessage.addListener(
return;
}
}

var xhr = new XMLHttpRequest();
xhr.open(request.method, request.url, true);
if (request.method == "POST") {
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// xhr.setRequestHeader("Content-length", request.data.length);
// xhr.setRequestHeader("Connection", "close");
}
xhr.onreadystatechange = function(a) {
if (xhr.readyState == 4) {
Expand Down
1 change: 1 addition & 0 deletions Chrome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"128": "icon128.png"
},
"permissions": [
"cookies",
"tabs",
"history",
"http://redditenhancementsuite.com/",
Expand Down
15 changes: 8 additions & 7 deletions XPI/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ var tabs = require("tabs");
var ss = require("simple-storage");

// require chrome allows us to use XPCOM objects...
// var {Cc, Cu, Cr} = require("chrome");
const {Cc,Ci} = require("chrome");
// from XPCOM, use the NSIGlobalHistory2 service...
// var historyService = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsIGlobalHistory2);
var historyService = Cc["@mozilla.org/browser/global-history;2"].getService(Ci.nsIGlobalHistory2)
const {Cc,Ci,Cu} = require("chrome");
var historyService = Cc["@mozilla.org/browser/global-history;2"].getService(Ci.nsIGlobalHistory2);
// Cookie manager for new API login
var cookieManager = Cc["@mozilla.org/cookiemanager;1"].getService().QueryInterface(Ci.nsICookieManager2);

// this function takes in a string (and optional charset, paseURI) and creates an nsURI object, which is required by historyService.addURI...
function makeURI(aURL, aOriginCharset, aBaseURI) {
var ioService = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
return ioService.newURI(aURL, aOriginCharset, aBaseURI);
}

Expand Down Expand Up @@ -129,6 +127,9 @@ pageMod.PageMod({
worker.on('message', function(data) {
var request = data;
switch(request.requestType) {
case 'deleteCookie':
cookieManager.remove('.reddit.com', request.cname, '/', false);
break;
case 'GM_xmlhttpRequest':
var responseObj = {
XHRID: request.XHRID,
Expand Down
Loading

0 comments on commit 9989ef8

Please sign in to comment.