-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working on CookieManager class (Manage cookies #8)
- Loading branch information
1 parent
aa88e7d
commit 35233f0
Showing
8 changed files
with
229 additions
and
107 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.5.3 | ||
|
||
- added `CookieManager` class | ||
|
||
## 0.5.2 | ||
|
||
- fixed some missing `result.success()` on Android and iOS | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/MyCookieManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.pichillilorenzo.flutter_inappbrowser; | ||
|
||
import android.os.Build; | ||
import android.text.TextUtils; | ||
import android.util.Log; | ||
import android.webkit.CookieManager; | ||
import android.webkit.ValueCallback; | ||
|
||
import java.net.HttpCookie; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.List; | ||
|
||
import io.flutter.plugin.common.MethodCall; | ||
import io.flutter.plugin.common.MethodChannel; | ||
import io.flutter.plugin.common.PluginRegistry; | ||
|
||
public class MyCookieManager implements MethodChannel.MethodCallHandler { | ||
|
||
static final String LOG_TAG = "MyCookieManager"; | ||
|
||
public static PluginRegistry.Registrar registrar; | ||
public static MethodChannel channel; | ||
|
||
public MyCookieManager(PluginRegistry.Registrar r) { | ||
registrar = r; | ||
channel = new MethodChannel(registrar.messenger(), "com.pichillilorenzo/flutter_inappbrowser_cookiemanager"); | ||
channel.setMethodCallHandler(this); | ||
} | ||
|
||
@Override | ||
public void onMethodCall(MethodCall call, MethodChannel.Result result) { | ||
switch (call.method) { | ||
case "setCookie": | ||
{ | ||
String url = (String) call.argument("url"); | ||
String name = (String) call.argument("name"); | ||
String value = (String) call.argument("value"); | ||
String domain = (String) call.argument("domain"); | ||
String path = (String) call.argument("path"); | ||
Long expiresDate = new Long((Integer) call.argument("expiresDate")); | ||
Boolean isHTTPOnly = (Boolean) call.argument("isHTTPOnly"); | ||
Boolean isSecure = (Boolean) call.argument("isSecure"); | ||
MyCookieManager.setCookie(url, name, value, domain, path, expiresDate, isHTTPOnly, isSecure, result); | ||
} | ||
break; | ||
default: | ||
result.notImplemented(); | ||
} | ||
} | ||
|
||
public static void setCookie(String url, | ||
String name, | ||
String value, | ||
String domain, | ||
String path, | ||
Long expiresDate, | ||
Boolean isHTTPOnly, | ||
Boolean isSecure, | ||
final MethodChannel.Result result) { | ||
|
||
String cookieValue = name + "=" + value; | ||
|
||
if (domain != null && !domain.isEmpty()) | ||
cookieValue += "; Domain=" + domain; | ||
|
||
if (path != null && !path.isEmpty()) | ||
cookieValue += "; Path=" + path; | ||
|
||
if (expiresDate != null) | ||
cookieValue += "; Max-Age=" + expiresDate.toString(); | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) | ||
if (isHTTPOnly != null && isHTTPOnly) | ||
cookieValue += "; HttpOnly"; | ||
|
||
if (isSecure != null && isSecure) | ||
cookieValue += "; Secure"; | ||
|
||
CookieManager cookieManager = CookieManager.getInstance(); | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
cookieManager.setCookie(url, cookieValue, new ValueCallback<Boolean>() { | ||
@Override | ||
public void onReceiveValue(Boolean aBoolean) { | ||
result.success(true); | ||
} | ||
}); | ||
} | ||
else { | ||
cookieManager.setCookie(url, cookieValue); | ||
result.success(true); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: flutter_inappbrowser | ||
description: A Flutter plugin that allows you to add an inline webview or open an in-app browser window. (inspired by the popular cordova-plugin-inappbrowser). | ||
version: 0.5.2 | ||
version: 0.5.3 | ||
author: Lorenzo Pichilli <[email protected]> | ||
homepage: https://github.com/pichillilorenzo/flutter_inappbrowser | ||
|
||
|