Bug 1161654 - Remove some dead code in Pocket.jsm and use pktApi for checking if the user is logged in. r=dolske
authorJared Wein <jwein@mozilla.com>
Tue, 05 May 2015 17:05:45 -0700
changeset 242411 2d0c646773808b0dc63765ed7124127a7547a503
parent 242410 c99917c92085b039e1ccb58939ffc2361bc0279a
child 242412 b2e843b2300dfd71a6d2a011c389785a62834106
push id28693
push userkwierso@gmail.com
push dateWed, 06 May 2015 03:23:28 +0000
treeherdermozilla-central@f938222ff4ce [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske
bugs1161654
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1161654 - Remove some dead code in Pocket.jsm and use pktApi for checking if the user is logged in. r=dolske
browser/base/content/nsContextMenu.js
browser/components/pocket/Pocket.jsm
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -182,17 +182,17 @@ nsContextMenu.prototype = {
     if (shouldShow && window.gBrowser &&
         this.browser.getTabBrowser() == window.gBrowser) {
       let uri = this.browser.currentURI;
       canPocket =
         CustomizableUI.getPlacementOfWidget("pocket-button") &&
         (uri.schemeIs("http") || uri.schemeIs("https") ||
          (uri.schemeIs("about") && ReaderMode.getOriginalUrl(uri.spec)));
     }
-    this.showItem("context-pocket", canPocket && window.Pocket && Pocket.isLoggedIn);
+    this.showItem("context-pocket", canPocket && window.pktApi && window.pktApi.isUserLoggedIn());
   },
 
   initViewItems: function CM_initViewItems() {
     // View source is always OK, unless in directory listing.
     this.showItem("context-viewpartialsource-selection",
                   this.isContentSelected);
     this.showItem("context-viewpartialsource-mathml",
                   this.onMathML && !this.isContentSelected);
--- a/browser/components/pocket/Pocket.jsm
+++ b/browser/components/pocket/Pocket.jsm
@@ -2,128 +2,24 @@
  * 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/. */
 
 "use strict";
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 this.EXPORTED_SYMBOLS = ["Pocket"];
 
-Cu.import("resource://gre/modules/Http.jsm");
-Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
-XPCOMUtils.defineLazyGetter(this, "PocketBundle", function() {
-  const kPocketBundle = "chrome://browser/content/browser-pocket.properties";
-  return Services.strings.createBundle(kPocketBundle);
-});
 XPCOMUtils.defineLazyModuleGetter(this, "CustomizableUI",
   "resource:///modules/CustomizableUI.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "ReaderMode",
   "resource://gre/modules/ReaderMode.jsm");
 
 let Pocket = {
-  get isLoggedIn() {
-    return !!this._accessToken;
-  },
-
-  prefBranch: Services.prefs.getBranch("browser.pocket.settings."),
-
-  get hostname() Services.prefs.getCharPref("browser.pocket.hostname"),
-
-  get listURL() { return "https://" + Pocket.hostname; },
-
-  get _accessToken() {
-    let sessionId, accessToken;
-    let cookies = Services.cookies.getCookiesFromHost(this.hostname);
-    while (cookies.hasMoreElements()) {
-      let cookie = cookies.getNext().QueryInterface(Ci.nsICookie2);
-      if (cookie.name == "ftv1")
-        accessToken = cookie.value;
-      else if (cookie.name == "fsv1")
-        sessionId = cookie.value;
-    }
-
-    if (!accessToken)
-      return null;
-
-    let lastSessionId;
-    try {
-      lastSessionId = this.prefBranch.getCharPref("sessionId");
-    } catch (e) { }
-    if (sessionId != lastSessionId)
-      this.prefBranch.deleteBranch("");
-    this.prefBranch.setCharPref("sessionId", sessionId);
-
-    return accessToken;
-  },
-
-  save(url, title) {
-    let since = "0";
-    try {
-      since = this.prefBranch.getCharPref("latestSince");
-    } catch (e) { }
-
-    let data = {url: url, since: since, title: title};
-
-    return new Promise((resolve, reject) => {
-      this._send("firefox/save", data,
-        data => {
-          this.prefBranch.setCharPref("latestSince", data.since);
-          resolve(data.item);
-        },
-        error => { reject(error); }
-      );
-    });
-  },
-
-  remove(itemId) {
-    let actions = [{ action: "delete", item_id: itemId }];
-    this._send("send", {actions: JSON.stringify(actions)});
-  },
-
-  tag(itemId, tags) {
-    let actions = [{ action: "tags_add", item_id: itemId, tags: tags }];
-    this._send("send", {actions: JSON.stringify(actions)});
-  },
-
-  _send(url, data, onSuccess, onError) {
-    let token = this._accessToken;
-    if (!token)
-      throw "Attempted to send a request to Pocket while not logged in";
-
-    let browserLocale = Cc["@mozilla.org/chrome/chrome-registry;1"]
-                          .getService(Ci.nsIXULChromeRegistry)
-                          .getSelectedLocale("browser");
-
-    let postData = [
-      ["access_token", token],
-      ["consumer_key", "40249-e88c401e1b1f2242d9e441c4"],
-      ["locale_lang", browserLocale]
-    ];
-
-    for (let key in data)
-      postData.push([key, data[key]]);
-
-    httpRequest("https://" + this.hostname + "/v3/" + url, {
-      headers: [["X-Accept", "application/json"]],
-      postData: postData,
-      onLoad: (responseText) => {
-        if (onSuccess)
-          onSuccess(JSON.parse(responseText));
-      },
-      onError: function(error, responseText, xhr) {
-        if (!onError)
-          return;
-        let errorMessage = xhr.getResponseHeader("X-Error");
-        onError(new Error(error + " - " + errorMessage));
-      }
-    });
-  },
-
   /**
    * Functions related to the Pocket panel UI.
    */
   onPanelViewShowing(event) {
     let window = event.target.ownerDocument.defaultView;
     window.pktUI.pocketButtonOnCommand(event);
     window.pktUI.pocketPanelDidShow(event)
   },