/* * LICENSE * * POCKET MARKS * * Notwithstanding the permitted uses of the Software (as defined below) pursuant to the license set forth below, "Pocket," "Read It Later" and the Pocket icon and logos (collectively, the “Pocket Marks”) are registered and common law trademarks of Read It Later, Inc. This means that, while you have considerable freedom to redistribute and modify the Software, there are tight restrictions on your ability to use the Pocket Marks. This license does not grant you any rights to use the Pocket Marks except as they are embodied in the Software. * * --- * * SOFTWARE * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ /* * Pocket UI module * * Handles interactions with Pocket buttons, panels and menus. * */ // TODO : Get the toolbar icons from Firefox's build (Nikki needs to give us a red saved icon) // TODO : [needs clarificaiton from Fx] Firefox's plan was to hide Pocket from context menus until the user logs in. Now that it's an extension I'm wondering if we still need to do this. // TODO : [needs clarificaiton from Fx] Reader mode (might be a something they need to do since it's in html, need to investigate their code) // TODO : [needs clarificaiton from Fx] Move prefs within pktApi.s to sqlite or a local file so it's not editable (and is safer) // TODO : [nice to have] - Immediately save, buffer the actions in a local queue and send (so it works offline, works like our native extensions) // TODO : Remove console.log entries Cu.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "ReaderMode", "resource://gre/modules/ReaderMode.jsm"); var pktUI = (function() { // -- Initialization (on startup and new windows) -- // var inited = false; var currentPanelDidShow, currentPanelDidHide; var _isHidden = false; var _notificationTimeout; var prefBranch = Services.prefs.getBranch("browser.pocket.settings."); /** * Initalizes Pocket UI and panels */ function onLoad() { if (inited) return; // Install the button (Only on first run, if a user removes the button, you do not want to restore it) // TODO, only do this if in a certain language // TODO - Ask Mozilla what the best way is to have this update when a user restores browser defaults // TODO - this needs to run only on a main window - if the first run happens on a window without the toolbar, then it will never try to run it again if (!prefBranch.prefHasUserValue('installed')) { // If user has social add-on installed, uninstall it if (Social.getManifestByOrigin("https://getpocket.com")) { Social.uninstallProvider("https://getpocket.com", function(){ /* callback */ }); } // if user has legacy pkt add-on installed, flag it so we can handle it correctly prefBranch.setBoolPref('hasLegacyExtension', hasLegacyExtension()); var id = "pocket-menu-button"; var toolbar = document.getElementById("nav-bar"); var before = null; // Is the bookmarks button in the toolbar? if (toolbar.currentSet.match("bookmarks-menu-button")) { var elem = document.getElementById("bookmarks-menu-button"); if (elem) before = elem.nextElementSibling; } // Otherwise, just add it to the end of the toolbar (because before is null) toolbar.insertItem(id, before); toolbar.setAttribute("currentset", toolbar.currentSet); document.persist(toolbar.id, "currentset"); prefBranch.setBoolPref('installed', true); } // Context Menu Event document.getElementById('contentAreaContextMenu').addEventListener("popupshowing", contextOnPopupShowing, false); // Hide the extension based on certain criteria hideIntegrationIfNeeded(); inited = true; } /** * Called when window/chrome is unloaded */ function onUnload() { } /** * Mark all Pocket integration chrome elements as hidden if certain criteria apply (ex: legacy Pocket extension users or unsupported languages) */ function hideIntegrationIfNeeded() { var hideIntegration = false; // Check if the user had the legacy extension the last time we looked if (prefBranch.getBoolPref('hasLegacyExtension')) { if (hasLegacyExtension()) { hideIntegration = true; // they still have it, hide new native integration } else { // if they originally had it, but no longer do, then we should remove the pref so we no longer have to check prefBranch.setBoolPref('hasLegacyExtension', false); } } // TODO // If language other than launch languages (en-US currently) { // hideIntegration = true; //} // Hide the integration if needed if (hideIntegration) { // Note, we don't hide the context menus here, that's handled in contextOnPopupShowing var elements = ['pocket-menu-button', 'BMB_openPocketWebapp']; for(var i=0; i