From 01a2585cf00c597200e99b460b422de570ed2b02 Mon Sep 17 00:00:00 2001 From: azrdev Date: Mon, 27 Jan 2014 17:47:51 +0100 Subject: [PATCH] import from local repo, stable version --- README.md | 6 ++ bootstrap.js | 165 ++++++++++++++++++++++++++++++++++++++++++++++++ build.sh | 129 +++++++++++++++++++++++++++++++++++++ config_build.sh | 12 ++++ install.rdf | 26 ++++++++ skeleton-README | 27 ++++++++ 6 files changed, 365 insertions(+) create mode 100644 README.md create mode 100644 bootstrap.js create mode 100755 build.sh create mode 100755 config_build.sh create mode 100644 install.rdf create mode 100644 skeleton-README diff --git a/README.md b/README.md new file mode 100644 index 0000000..f3536e1 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +firefox-cookie-whitelister +===== + +This is a copy/fork of the [Cookie Whitelist, With Buttons](https://addons.mozilla.org/en-US/firefox/addon/cookie-whitelist-with-buttons/) addon for Firefox, to Fennec / Firefox Mobile. +It allows users to easily add/remove sites to the whitelist of cookie-allowed sites maintained by the browser. They should generally disallow cookies by themselves, the addon doesn't do that. + diff --git a/bootstrap.js b/bootstrap.js new file mode 100644 index 0000000..7073710 --- /dev/null +++ b/bootstrap.js @@ -0,0 +1,165 @@ +const Cc = Components.classes; +const Ci = Components.interfaces; +const Cu = Components.utils; + +Cu.import("resource://gre/modules/Services.jsm"); + +function isNativeUI() { + let appInfo = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo); + return (appInfo.ID == "{aa3c5121-dab2-40e2-81ca-7ea25febc110}"); +} + +function showToast(aWindow, message) { + aWindow.NativeWindow.toast.show(message, "short"); +} + +function getSiteURI(window) { + var host = window.BrowserApp.selectedTab.window.location.host; + host = host.replace(/^\s*([-\w]*:\/+)?/, ""); + try { + return Services.io.newURI("http://" + host, null, null); + } + catch(e) { + return null; + } +} + +// Doorhanger UI objects +const doorhangerID = "cwa-doorhanger"; +var button_allow, button_delete, button_session, buttons; + +function showDoorhanger(window) { + var siteURI = getSiteURI(window); + if(siteURI == null) { + showToast(window, "Failed to get site URI."); + return false; + } + + // initialization has to be done here, since the callbacks need 'window' + button_allow = { + label: "Permanently", + callback: function() { + dump("Add permanently to cookie whitelist: \"" + siteURI + "\""); + Services.perms.add(siteURI, "cookie", Ci.nsICookiePermission.ACCESS_ALLOW); + showToast(window, "Added Site permanently to Cookie Whitelist"); + } + }; + button_session = { + label: "Only this session", + callback: function() { + dump("Add temporarily to cookie whitelist: \"" + siteURI + "\""); + Services.perms.add(siteURI, "cookie", Ci.nsICookiePermission.ACCESS_SESSION); + showToast(window, "Added Site for this session to Cookie Whitelist"); + } + }; + button_delete = { + label: "Delete permission", + callback: function() { + dump("Remove from cookie whitelist: \"" + siteURI + "\""); + Services.perms.add(siteURI, "cookie", Ci.nsICookiePermission.ACCESS_DEFAULT); + showToast(window, "Removed Site from Cookie Whitelist"); + } + }; + buttons = []; + + switch (Services.perms.testPermission(siteURI, "cookie")) { + case Ci.nsICookiePermission.ACCESS_SESSION: + buttons.push(button_allow); + buttons.push(button_delete); + break; + case Ci.nsICookiePermission.ACCESS_ALLOW: + buttons.push(button_session); + buttons.push(button_delete); + break; + default: + buttons.push(button_allow); + buttons.push(button_session); + // button_delete here could be useful in case of errors + } + window.NativeWindow.doorhanger.show("Allow Cookies for this site?", doorhangerID, buttons); +} + +var gMenuEntry = null; + +function loadIntoWindow(window) { + if (!window) + return; + + if (isNativeUI()) { + gMenuEntry = window.NativeWindow.menu.add( + "Cookie-Whitelist", + null, + function() { + showDoorhanger(window); + }); + } +} + +function unloadFromWindow(window) { + if (!window) + return; + + if (isNativeUI()) { + window.NativeWindow.menu.remove(gMenuEntry); + } +} + + +/** + * bootstrap.js API + */ +var windowListener = { + onOpenWindow: function(aWindow) { + // Wait for the window to finish loading + let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow); + domWindow.addEventListener("load", function() { + domWindow.removeEventListener("load", arguments.callee, false); + loadIntoWindow(domWindow); + }, false); + }, + + onCloseWindow: function(aWindow) { + }, + + onWindowTitleChange: function(aWindow, aTitle) { + } +}; + +function startup(aData, aReason) { + let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); + + // Load into any existing windows + let windows = wm.getEnumerator("navigator:browser"); + while (windows.hasMoreElements()) { + let domWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow); + loadIntoWindow(domWindow); + } + + // Load into any new windows + wm.addListener(windowListener); +} + +function shutdown(aData, aReason) { + // When the application is shutting down we normally don't have to clean + // up any UI changes made + if (aReason == APP_SHUTDOWN) + return; + + let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); + + // Stop listening for new windows + wm.removeListener(windowListener); + + // Unload from any existing windows + let windows = wm.getEnumerator("navigator:browser"); + while (windows.hasMoreElements()) { + let domWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow); + unloadFromWindow(domWindow); + } +} + +function install(aData, aReason) { +} + +function uninstall(aData, aReason) { +} diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..4b233b3 --- /dev/null +++ b/build.sh @@ -0,0 +1,129 @@ +#!/bin/bash +# build.sh -- builds JAR and XPI files for mozilla extensions +# by Nickolay Ponomarev +# (original version based on Nathan Yergler's build script) +# Most recent version is at + +# This script assumes the following directory structure: +# ./ +# chrome.manifest (optional - for newer extensions) +# install.rdf +# (other files listed in $ROOT_FILES) +# +# content/ | +# locale/ |} these can be named arbitrary and listed in $CHROME_PROVIDERS +# skin/ | +# +# defaults/ | +# components/ |} these must be listed in $ROOT_DIRS in order to be packaged +# ... | +# +# It uses a temporary directory ./build when building; don't use that! +# Script's output is: +# ./$APP_NAME.xpi +# ./$APP_NAME.jar (only if $KEEP_JAR=1) +# ./files -- the list of packaged files +# +# Note: It modifies chrome.manifest when packaging so that it points to +# chrome/$APP_NAME.jar!/* + +# +# default configuration file is ./config_build.sh, unless another file is +# specified in command-line. Available config variables: +APP_NAME= # short-name, jar and xpi files name. Must be lowercase with no spaces +CHROME_PROVIDERS= # which chrome providers we have (space-separated list) +CLEAN_UP= # delete the jar / "files" when done? (1/0) +ROOT_FILES= # put these files in root of xpi (space separated list of leaf filenames) +ROOT_DIRS= # ...and these directories (space separated list) +BEFORE_BUILD= # run this before building (bash command) +AFTER_BUILD= # ...and this after the build (bash command) + +if [ -z $1 ]; then + . ./config_build.sh +else + . $1 +fi + +if [ -z $APP_NAME ]; then + echo "You need to create build config file first!" + echo "Read comments at the beginning of this script for more info." + exit; +fi + +ROOT_DIR=`pwd` +TMP_DIR=build + +#uncomment to debug +#set -x + +# remove any left-over files from previous build +rm -f $APP_NAME.jar $APP_NAME.xpi files +rm -rf $TMP_DIR + +$BEFORE_BUILD + +mkdir --parents --verbose $TMP_DIR/chrome + +# generate the JAR file, excluding CVS, SVN, and temporary files +JAR_FILE=$TMP_DIR/chrome/$APP_NAME.jar +echo "Generating $JAR_FILE..." +for CHROME_SUBDIR in $CHROME_PROVIDERS; do + find $CHROME_SUBDIR \( -path '*CVS*' -o -path '*.svn*' \) -prune -o -type f -print | grep -v \~ >> files +done + +zip -0 -r $JAR_FILE -@ < files +# The following statement should be used instead if you don't wish to use the JAR file +#cp --verbose --parents `cat files` $TMP_DIR/chrome + +# prepare components and defaults +echo "Copying various files to $TMP_DIR folder..." +for DIR in $ROOT_DIRS; do + mkdir $TMP_DIR/$DIR + FILES="`find $DIR \( -path '*CVS*' -o -path '*.svn*' \) -prune -o -type f -print | grep -v \~`" + echo $FILES >> files + cp --verbose --parents $FILES $TMP_DIR +done + +# Copy other files to the root of future XPI. +for ROOT_FILE in $ROOT_FILES install.rdf chrome.manifest; do + cp --verbose $ROOT_FILE $TMP_DIR + if [ -f $ROOT_FILE ]; then + echo $ROOT_FILE >> files + fi +done + +cd $TMP_DIR + +if [ -f "chrome.manifest" ]; then + echo "Preprocessing chrome.manifest..." + # You think this is scary? + #s/^(content\s+\S*\s+)(\S*\/)$/\1jar:chrome\/$APP_NAME\.jar!\/\2/ + #s/^(skin|locale)(\s+\S*\s+\S*\s+)(.*\/)$/\1\2jar:chrome\/$APP_NAME\.jar!\/\3/ + # + # Then try this! (Same, but with characters escaped for bash :) + sed -i -r s/^\(content\\s+\\S*\\s+\)\(\\S*\\/\)$/\\1jar:chrome\\/$APP_NAME\\.jar!\\/\\2/ chrome.manifest + sed -i -r s/^\(skin\|locale\)\(\\s+\\S*\\s+\\S*\\s+\)\(.*\\/\)$/\\1\\2jar:chrome\\/$APP_NAME\\.jar!\\/\\3/ chrome.manifest + + # (it simply adds jar:chrome/whatever.jar!/ at appropriate positions of chrome.manifest) +fi + +# generate the XPI file +echo "Generating $APP_NAME.xpi..." +zip -r ../$APP_NAME.xpi * + +cd "$ROOT_DIR" + +echo "Cleanup..." +if [ $CLEAN_UP = 0 ]; then + # save the jar file + mv $TMP_DIR/chrome/$APP_NAME.jar . +else + rm ./files +fi + +# remove the working files +rm -rf $TMP_DIR +echo "Done!" + +$AFTER_BUILD + diff --git a/config_build.sh b/config_build.sh new file mode 100755 index 0000000..b70c731 --- /dev/null +++ b/config_build.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Build config for the build script, build.sh. Look there for more info. + +APP_NAME=cookie-whitelist-fennec +CHROME_PROVIDERS= +CLEAN_UP=1 +ROOT_FILES="bootstrap.js" +ROOT_DIRS= +BEFORE_BUILD= +AFTER_BUILD= + diff --git a/install.rdf b/install.rdf new file mode 100644 index 0000000..cdaea87 --- /dev/null +++ b/install.rdf @@ -0,0 +1,26 @@ + + + + + {4661a4a7-f6f7-46f4-be5f-6747e8fd21fe} + 2 + true + Cookie Whitelist for Fennec + 0.5.3 + Makes cookie whitelisting easy, with native Android GUI. + azrdev@qrdn.de + Alexander Dietrich + https://github.com/azrdev/firefox-cookie-whitelister + + + + + {aa3c5121-dab2-40e2-81ca-7ea25febc110} + + 14.0 + 27.* + + + + + diff --git a/skeleton-README b/skeleton-README new file mode 100644 index 0000000..a47d222 --- /dev/null +++ b/skeleton-README @@ -0,0 +1,27 @@ +Skeleton for an Add-on in Firefox on Android +============================================ + +This code supplies the basic bits and pieces needed to build a simple, +restartless add-on for Firefox on Android, which uses a new native widget UI. +Since Firefox on Android does not use XUL for the UI, building an add-on is a +little different. + +For more information about building mobile add-ons, please see: +https://developer.mozilla.org/en/Extensions/Firefox_on_Android + +Using the Skeleton +================== + +Step 1: Edit the install.rdf + * Please change the ALL CAPS areas with text specific to your add-on + +Step 2: Add code to bootstrap.js + * The current code adds some menus, doorhangers and context menus that don't + do very much right now. + +Step 3: Edit config_build.sh + * If you add any additional files, make sure you add them to config_build.sh + See build.sh for more details + +Step 4: run ./build.sh + * This creates the XPI