Version 0.0.1

This commit is contained in:
Dr. E 2013-12-02 16:01:38 +01:00
parent 184bb03d8c
commit 3279797431
8 changed files with 238 additions and 25 deletions

24
.gitignore vendored
View File

@ -1,26 +1,4 @@
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
# Eclipse project files
.classpath
.project
# Proguard folder generated by Eclipse
proguard/
.DS_Store
# Intellij project files
*.iml

View File

@ -1,4 +1,27 @@
Cookies
Phonegap Cookies Plugin
=======
Phonegap Cookies plugin
Phonegap/Cordova plugin that allows you to clear cookies of the webview. Use it for logging out the user, restart analytics session etc.
## Why a plugin?
On Phonegap `document.cookie` is empty, index.html and all other files are loaded with `file://` protocol.
Phonegap manages cookies internally, but doesn't expose any function for clearing them.
## Installation:
### Automatically (CLI / Plugman)
Cookies is compatible with [Cordova Plugman](https://github.com/apache/cordova-plugman) and ready for the [PhoneGap 3.0 CLI](http://docs.phonegap.com/en/3.0.0/guide_cli_index.md.html#The%20Command-line%20Interface_add_features), here's how it works with the CLI:
```
$ phonegap local plugin add https://github.com/bez4pieci/Cookies.git
```
## Usage
```javascript
window.cookies.clear(function() {
console.log('Cookies cleared!');
});
```

13
package.json Normal file
View File

@ -0,0 +1,13 @@
{
"version": "0.0.1",
"name": "com.bez4pieci.cookies",
"cordova_name": "Cookies",
"description": "Cordova Cookies Plugin",
"license": "Apache 2.0",
"keywords": [
"cordova",
"phonegap",
"cookies"
],
"engines": []
}

38
plugin.xml Normal file
View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="com.bez4pieci.cookies" version="0.0.1">
<name>Cookies</name>
<description>Cordova Device Plugin</description>
<license>MIT</license>
<keywords>cordova,phonegap,cookies</keywords>
<engines>
<engine name="cordova" version=">=3.0.0" />
</engines>
<js-module src="www/cookies.js" name="cookies">
<clobbers target="cookies" />
</js-module>
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="Cookies">
<param name="ios-package" value="CDVCookies"/>
</feature>
</config-file>
<header-file src="src/ios/CDVCookies.h" />
<source-file src="src/ios/CDVCookies.m" />
</platform>
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="Cookies" >
<param name="android-package" value="com.bez4pieci.cookies.Cookies"/>
</feature>
</config-file>
<source-file src="src/android/Cookies.java" target-dir="com/bez4pieci/cookies" />
</platform>
</plugin>

57
src/android/Cookies.java Normal file
View File

@ -0,0 +1,57 @@
/*
* Copyright 2013 Ernests Karlsons
* https://github.com/bez4pieci
* http://www.karlsons.net
*
* 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.
*/
package com.bez4pieci.cookies;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
import android.util.Log;
import android.webkit.CookieManager;
public class Cookies extends CordovaPlugin {
private final String TAG = "CookiesPlugin";
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if ("clear".equals(action)) {
this.clear();
callbackContext.success();
return true;
}
return false; // Returning false results in a "MethodNotFound" error.
}
public void clear() {
Log.v(TAG, "Clearing cookies...");
CookieManager.getInstance().removeAllCookie();
}
}

15
src/ios/CDVCookies.h Normal file
View File

@ -0,0 +1,15 @@
//
// CDVCookies.h
// Dreamflat
//
// Created by Dr. E on 25/11/13.
//
//
#import <Cordova/CDVPlugin.h>
@interface CDVCookies : CDVPlugin
- (void)clear:(CDVInvokedUrlCommand*)command;
@end

43
src/ios/CDVCookies.m Normal file
View File

@ -0,0 +1,43 @@
/*
* Copyright 2013 Ernests Karlsons
* https://github.com/bez4pieci
* http://www.karlsons.net
*
* 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.
*/
#import "CDVCookies.h"
@implementation CDVCookies
- (void)clear:(CDVInvokedUrlCommand*)command
{
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies]) {
[storage deleteCookie:cookie];
}
[[NSUserDefaults standardUserDefaults] synchronize];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@end

46
www/cookies.js Normal file
View File

@ -0,0 +1,46 @@
/*
* Copyright 2013 Ernests Karlsons
* https://github.com/bez4pieci
* http://www.karlsons.net
*
* 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.
*/
var exec = require('cordova/exec');
/**
* @constructor
*/
function Cookies() {
}
/**
* Get device info
*
* @param {Function} successCallback The function to call when cookies cleared successfully
* @param {Function} errorCallback The function to call when there was an error (OPTIONAL)
*/
Cookies.prototype.clear = function(successCallback, errorCallback) {
exec(successCallback, errorCallback, "Cookies", "clear", []);
};
module.exports = new Cookies();