Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
Flutter Inappwebview
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李增强
Flutter Inappwebview
Commits
ac962a59
Commit
ac962a59
authored
Oct 27, 2018
by
pichillilorenzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
completed CookieManager class #8 #3
parent
81a4b6ad
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
374 additions
and
87 deletions
+374
-87
.idea/workspace.xml
.idea/workspace.xml
+35
-37
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/MyCookieManager.java
...pichillilorenzo/flutter_inappbrowser/MyCookieManager.java
+73
-33
example/lib/main.dart
example/lib/main.dart
+23
-8
ios/Classes/MyCookieManager.swift
ios/Classes/MyCookieManager.swift
+167
-0
ios/Classes/SwiftFlutterPlugin.swift
ios/Classes/SwiftFlutterPlugin.swift
+6
-0
lib/flutter_inappbrowser.dart
lib/flutter_inappbrowser.dart
+70
-9
No files found.
.idea/workspace.xml
View file @
ac962a59
This diff is collapsed.
Click to expand it.
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/MyCookieManager.java
View file @
ac962a59
...
...
@@ -6,6 +6,8 @@ import android.webkit.CookieManager;
import
android.webkit.CookieSyncManager
;
import
android.webkit.ValueCallback
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Date
;
...
...
@@ -24,11 +26,13 @@ public class MyCookieManager implements MethodChannel.MethodCallHandler {
public
static
PluginRegistry
.
Registrar
registrar
;
public
static
MethodChannel
channel
;
public
static
CookieManager
cookieManager
;
public
MyCookieManager
(
PluginRegistry
.
Registrar
r
)
{
registrar
=
r
;
channel
=
new
MethodChannel
(
registrar
.
messenger
(),
"com.pichillilorenzo/flutter_inappbrowser_cookiemanager"
);
channel
.
setMethodCallHandler
(
this
);
cookieManager
=
CookieManager
.
getInstance
();
}
@Override
...
...
@@ -41,10 +45,10 @@ public class MyCookieManager implements MethodChannel.MethodCallHandler {
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
"
);
Long
expiresDate
=
new
Long
((
String
)
call
.
argument
(
"expiresDate"
));
Integer
maxAge
=
(
Integer
)
call
.
argument
(
"maxAge
"
);
Boolean
isSecure
=
(
Boolean
)
call
.
argument
(
"isSecure"
);
MyCookieManager
.
setCookie
(
url
,
name
,
value
,
domain
,
path
,
expiresDate
,
isHTTPOnly
,
isSecure
,
result
);
MyCookieManager
.
setCookie
(
url
,
name
,
value
,
domain
,
path
,
expiresDate
,
maxAge
,
isSecure
,
result
);
}
break
;
case
"getCookies"
:
...
...
@@ -54,11 +58,21 @@ public class MyCookieManager implements MethodChannel.MethodCallHandler {
{
String
url
=
(
String
)
call
.
argument
(
"url"
);
String
name
=
(
String
)
call
.
argument
(
"name"
);
MyCookieManager
.
deleteCookie
(
url
,
name
,
result
);
String
domain
=
(
String
)
call
.
argument
(
"domain"
);
String
path
=
(
String
)
call
.
argument
(
"path"
);
MyCookieManager
.
deleteCookie
(
url
,
name
,
domain
,
path
,
result
);
}
break
;
case
"deleteCookies"
:
MyCookieManager
.
deleteCookies
(
result
);
{
String
url
=
(
String
)
call
.
argument
(
"url"
);
String
domain
=
(
String
)
call
.
argument
(
"domain"
);
String
path
=
(
String
)
call
.
argument
(
"path"
);
MyCookieManager
.
deleteCookies
(
url
,
domain
,
path
,
result
);
}
break
;
case
"deleteAllCookies"
:
MyCookieManager
.
deleteAllCookies
(
result
);
break
;
default
:
result
.
notImplemented
();
...
...
@@ -71,28 +85,22 @@ public class MyCookieManager implements MethodChannel.MethodCallHandler {
String
domain
,
String
path
,
Long
expiresDate
,
Boolean
isHTTPOnly
,
Integer
maxAge
,
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
;
String
cookieValue
=
name
+
"="
+
value
+
"; Domain="
+
domain
+
"; Path="
+
path
;
if
(
expiresDate
!=
null
)
cookieValue
+=
"; Expires="
+
getCookieExpirationDate
(
expiresDate
);
if
(
isHTTPOnly
!=
null
&&
isHTTPOnly
)
cookieValue
+=
";
HttpOnly"
;
if
(
maxAge
!=
null
)
cookieValue
+=
";
Max-Age="
+
maxAge
.
toString
()
;
if
(
isSecure
!=
null
&&
isSecure
)
cookieValue
+=
"; Secure"
;
CookieManager
cookieManager
=
CookieManager
.
getInstance
()
;
cookieValue
+=
";"
;
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
cookieManager
.
setCookie
(
url
,
cookieValue
,
new
ValueCallback
<
Boolean
>()
{
...
...
@@ -117,27 +125,27 @@ public class MyCookieManager implements MethodChannel.MethodCallHandler {
final
List
<
Map
<
String
,
Object
>>
cookieListMap
=
new
ArrayList
<>();
CookieManager
cookieManager
=
CookieManager
.
getInstance
();
String
[]
cookies
=
cookieManager
.
getCookie
(
url
).
split
(
";"
);
for
(
String
cookie
:
cookies
)
{
String
[]
nameValue
=
cookie
.
split
(
"="
,
2
);
String
name
=
nameValue
[
0
].
trim
();
String
value
=
nameValue
[
1
].
trim
();
Map
<
String
,
Object
>
cookieMap
=
new
HashMap
<>();
cookieMap
.
put
(
"name"
,
name
);
cookieMap
.
put
(
"value"
,
value
);
cookieListMap
.
add
(
cookieMap
);
String
cookiesString
=
cookieManager
.
getCookie
(
url
);
if
(
cookiesString
!=
null
)
{
String
[]
cookies
=
cookiesString
.
split
(
";"
);
for
(
String
cookie
:
cookies
)
{
String
[]
nameValue
=
cookie
.
split
(
"="
,
2
);
String
name
=
nameValue
[
0
].
trim
();
String
value
=
nameValue
[
1
].
trim
();
Map
<
String
,
Object
>
cookieMap
=
new
HashMap
<>();
cookieMap
.
put
(
"name"
,
name
);
cookieMap
.
put
(
"value"
,
value
);
cookieListMap
.
add
(
cookieMap
);
}
}
return
cookieListMap
;
}
public
static
void
deleteCookie
(
String
url
,
String
cookieName
,
final
MethodChannel
.
Result
result
)
{
public
static
void
deleteCookie
(
String
url
,
String
name
,
String
domain
,
String
path
,
final
MethodChannel
.
Result
result
)
{
String
cookieValue
=
cookieName
+
"=; Expires=Thu, 01 Jan 1970 00:00:01 GMT;"
;
CookieManager
cookieManager
=
CookieManager
.
getInstance
();
String
cookieValue
=
name
+
"=; Path="
+
path
+
"; Domain="
+
domain
+
"; Max-Age=-1;"
;
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
cookieManager
.
setCookie
(
url
,
cookieValue
,
new
ValueCallback
<
Boolean
>()
{
...
...
@@ -158,8 +166,40 @@ public class MyCookieManager implements MethodChannel.MethodCallHandler {
}
}
public
static
void
deleteCookies
(
final
MethodChannel
.
Result
result
)
{
CookieManager
cookieManager
=
CookieManager
.
getInstance
();
public
static
void
deleteCookies
(
String
url
,
String
domain
,
String
path
,
final
MethodChannel
.
Result
result
)
{
CookieSyncManager
cookieSyncMngr
=
null
;
String
cookiesString
=
cookieManager
.
getCookie
(
url
);
if
(
cookiesString
!=
null
)
{
if
(
Build
.
VERSION
.
SDK_INT
<
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
cookieSyncMngr
=
CookieSyncManager
.
createInstance
(
registrar
.
context
());
cookieSyncMngr
.
startSync
();
}
String
[]
cookies
=
cookiesString
.
split
(
";"
);
for
(
String
cookie
:
cookies
)
{
String
[]
nameValue
=
cookie
.
split
(
"="
,
2
);
String
name
=
nameValue
[
0
].
trim
();
String
cookieValue
=
name
+
"=; Path="
+
path
+
"; Domain="
+
domain
+
"; Max-Age=-1;"
;
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
cookieManager
.
setCookie
(
url
,
cookieValue
,
null
);
else
cookieManager
.
setCookie
(
url
,
cookieValue
);
}
if
(
cookieSyncMngr
!=
null
)
{
cookieSyncMngr
.
stopSync
();
cookieSyncMngr
.
sync
();
}
else
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
cookieManager
.
flush
();
}
result
.
success
(
true
);
}
public
static
void
deleteAllCookies
(
final
MethodChannel
.
Result
result
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
cookieManager
.
removeAllCookies
(
new
ValueCallback
<
Boolean
>()
{
@Override
...
...
example/lib/main.dart
View file @
ac962a59
...
...
@@ -65,13 +65,26 @@ class MyInAppBrowser extends InAppBrowser {
// await this.webViewController.injectScriptCode("console.error('testError', false);");
// await this.webViewController.injectScriptCode("console.debug('testDebug', true);");
//
print
(
await
this
.
webViewController
.
injectScriptCode
(
"document.cookie"
));
print
(
""
);
print
(
await
CookieManager
.
getCookies
(
"https://flutter.io/"
));
print
(
""
);
print
(
await
CookieManager
.
getCookie
(
"https://flutter.io/"
,
"_ga"
));
print
(
""
);
// print(await this.webViewController.injectScriptCode("document.cookie"));
//
// print("");
// print(await CookieManager.getCookies(url));
// print("");
// print(await CookieManager.getCookie(url, "my_cookie2"));
// print("");
// await CookieManager.deleteCookie(url, "my_cookie2");
// await CookieManager.deleteCookie(url, "_gid", domain: ".googleblog.com");
// print("");
// print(await CookieManager.getCookies(url));
// print("");
// await CookieManager.deleteCookies(url);
// print("");
// print(await CookieManager.getCookies(url));
// print("");
// await CookieManager.deleteAllCookies();
// print("");
// print(await CookieManager.getCookies(url));
// print("");
//
// print(await this.webViewController.injectScriptCode("null"));
// print(await this.webViewController.injectScriptCode("undefined"));
...
...
@@ -277,7 +290,9 @@ class _MyAppState extends State<MyApp> {
// //"toolbarBottom": false
// });
//
await
CookieManager
.
setCookie
(
"https://flutter.io/"
,
"my_cookie2"
,
"cookieValue2"
,
"flutter.io"
,
expiresDate:
1000000
,
path:
"/get-started/install"
);
// await CookieManager.setCookie("https://flutter.io/", "my_cookie2", "cookieValue2", domain: "flutter.io", expiresDate: 1540838864611);
// await CookieManager.setCookie("https://flutter.io/", "my_cookie", "cookieValue", domain: "flutter.io", expiresDate: 1540838864611);
await
inAppBrowserFallback
.
open
(
url:
"https://flutter.io/"
,
options:
{
//"useOnLoadResource": true,
//"hidden": true,
...
...
ios/Classes/MyCookieManager.swift
0 → 100644
View file @
ac962a59
//
// MyCookieManager.swift
// flutter_inappbrowser
//
// Created by Lorenzo on 26/10/18.
//
import
Foundation
import
WebKit
@available
(
iOS
11.0
,
*
)
class
MyCookieManager
:
NSObject
,
FlutterPlugin
{
static
var
registrar
:
FlutterPluginRegistrar
?
static
var
channel
:
FlutterMethodChannel
?
static
var
httpCookieStore
:
WKHTTPCookieStore
?
static
func
register
(
with
registrar
:
FlutterPluginRegistrar
)
{
}
init
(
registrar
:
FlutterPluginRegistrar
)
{
super
.
init
()
MyCookieManager
.
registrar
=
registrar
MyCookieManager
.
httpCookieStore
=
WKWebsiteDataStore
.
default
()
.
httpCookieStore
MyCookieManager
.
channel
=
FlutterMethodChannel
(
name
:
"com.pichillilorenzo/flutter_inappbrowser_cookiemanager"
,
binaryMessenger
:
registrar
.
messenger
())
registrar
.
addMethodCallDelegate
(
self
,
channel
:
MyCookieManager
.
channel
!
)
}
public
func
handle
(
_
call
:
FlutterMethodCall
,
result
:
@escaping
FlutterResult
)
{
let
arguments
=
call
.
arguments
as?
NSDictionary
switch
call
.
method
{
case
"setCookie"
:
let
url
=
arguments
!
[
"url"
]
as!
String
let
name
=
arguments
!
[
"name"
]
as!
String
let
value
=
arguments
!
[
"value"
]
as!
String
let
domain
=
arguments
!
[
"domain"
]
as!
String
let
path
=
arguments
!
[
"path"
]
as!
String
let
expiresDate
=
arguments
!
[
"expiresDate"
]
as?
Int
let
maxAge
=
arguments
!
[
"maxAge"
]
as?
Int
let
isSecure
=
arguments
!
[
"isSecure"
]
as?
Bool
MyCookieManager
.
setCookie
(
url
:
url
,
name
:
name
,
value
:
value
,
domain
:
domain
,
path
:
path
,
expiresDate
:
expiresDate
,
maxAge
:
maxAge
,
isSecure
:
isSecure
,
result
:
result
)
break
case
"getCookies"
:
let
url
=
arguments
!
[
"url"
]
as!
String
MyCookieManager
.
getCookies
(
url
:
url
,
result
:
result
)
break
case
"deleteCookie"
:
let
url
=
arguments
!
[
"url"
]
as!
String
let
name
=
arguments
!
[
"name"
]
as!
String
let
domain
=
arguments
!
[
"domain"
]
as!
String
let
path
=
arguments
!
[
"path"
]
as!
String
MyCookieManager
.
deleteCookie
(
url
:
url
,
name
:
name
,
domain
:
domain
,
path
:
path
,
result
:
result
);
break
;
case
"deleteCookies"
:
let
url
=
arguments
!
[
"url"
]
as!
String
let
domain
=
arguments
!
[
"domain"
]
as!
String
let
path
=
arguments
!
[
"path"
]
as!
String
MyCookieManager
.
deleteCookies
(
url
:
url
,
domain
:
domain
,
path
:
path
,
result
:
result
);
break
;
case
"deleteAllCookies"
:
MyCookieManager
.
deleteAllCookies
(
result
:
result
);
break
;
default
:
result
(
FlutterMethodNotImplemented
)
break
}
}
public
static
func
setCookie
(
url
:
String
,
name
:
String
,
value
:
String
,
domain
:
String
,
path
:
String
,
expiresDate
:
Int
?,
maxAge
:
Int
?,
isSecure
:
Bool
?,
result
:
@escaping
FlutterResult
)
{
var
properties
:
[
HTTPCookiePropertyKey
:
Any
]
=
[:]
properties
[
.
originURL
]
=
url
properties
[
.
name
]
=
name
properties
[
.
value
]
=
value
properties
[
.
domain
]
=
domain
properties
[
.
path
]
=
path
if
expiresDate
!=
nil
{
properties
[
.
expires
]
=
NSDate
(
timeIntervalSince1970
:
Double
(
expiresDate
!
))
}
if
maxAge
!=
nil
{
properties
[
.
maximumAge
]
=
String
(
maxAge
!
)
}
properties
[
.
secure
]
=
(
isSecure
!=
nil
&&
isSecure
!
)
?
"TRUE"
:
"FALSE"
let
cookie
=
HTTPCookie
(
properties
:
properties
)
!
MyCookieManager
.
httpCookieStore
!.
setCookie
(
cookie
)
result
(
true
)
}
public
static
func
getCookies
(
url
:
String
,
result
:
@escaping
FlutterResult
)
{
var
cookieList
:
[[
String
:
Any
]]
=
[]
MyCookieManager
.
httpCookieStore
!.
getAllCookies
{
(
cookies
)
in
for
cookie
in
cookies
{
if
cookie
.
domain
.
contains
(
URL
(
string
:
url
)
!.
host
!
)
{
cookieList
.
append
([
"name"
:
cookie
.
name
,
"value"
:
cookie
.
value
])
}
}
result
(
cookieList
)
}
}
public
static
func
deleteCookie
(
url
:
String
,
name
:
String
,
domain
:
String
,
path
:
String
,
result
:
@escaping
FlutterResult
)
{
MyCookieManager
.
httpCookieStore
!.
getAllCookies
{
(
cookies
)
in
for
cookie
in
cookies
{
var
originURL
=
""
if
cookie
.
properties
!
[
.
originURL
]
is
String
{
originURL
=
cookie
.
properties
!
[
.
originURL
]
as!
String
}
else
if
cookie
.
properties
!
[
.
originURL
]
is
URL
{
originURL
=
(
cookie
.
properties
!
[
.
originURL
]
as!
URL
)
.
absoluteString
}
if
(
!
originURL
.
isEmpty
&&
originURL
!=
url
)
{
continue
}
if
cookie
.
domain
.
contains
(
domain
)
&&
cookie
.
name
==
name
&&
cookie
.
path
==
path
{
MyCookieManager
.
httpCookieStore
!.
delete
(
cookie
,
completionHandler
:
{
result
(
true
)
})
return
}
}
result
(
false
)
}
}
public
static
func
deleteCookies
(
url
:
String
,
domain
:
String
,
path
:
String
,
result
:
@escaping
FlutterResult
)
{
MyCookieManager
.
httpCookieStore
!.
getAllCookies
{
(
cookies
)
in
for
cookie
in
cookies
{
var
originURL
=
""
if
cookie
.
properties
!
[
.
originURL
]
is
String
{
originURL
=
cookie
.
properties
!
[
.
originURL
]
as!
String
}
else
if
cookie
.
properties
!
[
.
originURL
]
is
URL
{
originURL
=
(
cookie
.
properties
!
[
.
originURL
]
as!
URL
)
.
absoluteString
}
if
(
!
originURL
.
isEmpty
&&
originURL
!=
url
)
{
continue
}
if
cookie
.
domain
.
contains
(
domain
)
&&
cookie
.
path
==
path
{
MyCookieManager
.
httpCookieStore
!.
delete
(
cookie
,
completionHandler
:
nil
)
}
}
result
(
true
)
}
}
public
static
func
deleteAllCookies
(
result
:
@escaping
FlutterResult
)
{
let
websiteDataTypes
=
NSSet
(
array
:
[
WKWebsiteDataTypeCookies
])
let
date
=
NSDate
(
timeIntervalSince1970
:
0
)
WKWebsiteDataStore
.
default
()
.
removeData
(
ofTypes
:
websiteDataTypes
as!
Set
<
String
>
,
modifiedSince
:
date
as
Date
,
completionHandler
:{
result
(
true
)
})
}
}
ios/Classes/SwiftFlutterPlugin.swift
View file @
ac962a59
...
...
@@ -55,6 +55,12 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
let
channel
=
FlutterMethodChannel
(
name
:
"com.pichillilorenzo/flutter_inappbrowser"
,
binaryMessenger
:
registrar
.
messenger
())
let
instance
=
SwiftFlutterPlugin
(
with
:
registrar
)
registrar
.
addMethodCallDelegate
(
instance
,
channel
:
channel
)
if
#available(iOS 11.0, *)
{
MyCookieManager
(
registrar
:
registrar
)
}
else
{
// Fallback on earlier versions
}
}
public
func
handle
(
_
call
:
FlutterMethodCall
,
result
:
@escaping
FlutterResult
)
{
...
...
lib/flutter_inappbrowser.dart
View file @
ac962a59
...
...
@@ -1133,14 +1133,21 @@ class CookieManager {
}
///Sets a cookie for the given [url]. Any existing cookie with the same [host], [path] and [name] will be replaced with the new cookie. The cookie being set will be ignored if it is expired.
static
Future
<
void
>
setCookie
(
String
url
,
String
name
,
String
value
,
String
domain
,
{
String
path
=
"/"
,
///
///The default value of [path] is `"/"`.
///If [domain] is `null`, its default value will be the domain name of [url].
static
Future
<
void
>
setCookie
(
String
url
,
String
name
,
String
value
,
{
String
domain
,
String
path
=
"/"
,
int
expiresDate
,
bool
isHTTPOnly
,
int
maxAge
,
bool
isSecure
})
async
{
if
(!
_initialized
)
_init
();
if
(
domain
==
null
)
domain
=
_getDomainName
(
url
);
assert
(
url
!=
null
&&
url
.
isNotEmpty
);
assert
(
name
!=
null
&&
name
.
isNotEmpty
);
assert
(
value
!=
null
&&
value
.
isNotEmpty
);
...
...
@@ -1153,8 +1160,8 @@ class CookieManager {
args
.
putIfAbsent
(
'value'
,
()
=>
value
);
args
.
putIfAbsent
(
'domain'
,
()
=>
domain
);
args
.
putIfAbsent
(
'path'
,
()
=>
path
);
args
.
putIfAbsent
(
'expiresDate'
,
()
=>
expiresDate
);
args
.
putIfAbsent
(
'
isHTTPOnly'
,
()
=>
isHTTPOnly
);
args
.
putIfAbsent
(
'expiresDate'
,
()
=>
expiresDate
.
toString
()
);
args
.
putIfAbsent
(
'
maxAge'
,
()
=>
maxAge
);
args
.
putIfAbsent
(
'isSecure'
,
()
=>
isSecure
);
await
_channel
.
invokeMethod
(
'setCookie'
,
args
);
...
...
@@ -1175,10 +1182,10 @@ class CookieManager {
return
cookies
;
}
///Gets a cookie by its [
cookieN
ame] for the given [url].
static
Future
<
Map
<
String
,
dynamic
>>
getCookie
(
String
url
,
String
cookieN
ame
)
async
{
///Gets a cookie by its [
n
ame] for the given [url].
static
Future
<
Map
<
String
,
dynamic
>>
getCookie
(
String
url
,
String
n
ame
)
async
{
assert
(
url
!=
null
&&
url
.
isNotEmpty
);
assert
(
cookieName
!=
null
&&
cookieN
ame
.
isNotEmpty
);
assert
(
name
!=
null
&&
n
ame
.
isNotEmpty
);
Map
<
String
,
dynamic
>
args
=
<
String
,
dynamic
>{};
args
.
putIfAbsent
(
'url'
,
()
=>
url
);
...
...
@@ -1186,9 +1193,63 @@ class CookieManager {
cookies
=
cookies
.
cast
<
Map
<
dynamic
,
dynamic
>>();
for
(
var
i
=
0
;
i
<
cookies
.
length
;
i
++)
{
cookies
[
i
]
=
cookies
[
i
].
cast
<
String
,
dynamic
>();
if
(
cookies
[
i
][
"name"
]
==
cookieN
ame
)
if
(
cookies
[
i
][
"name"
]
==
n
ame
)
return
cookies
[
i
];
}
return
null
;
}
///Removes a cookie by its [name] for the given [url], [domain] and [path].
///The default value of [path] is `"/"`.
///If [domain] is `null` or empty, its default value will be the domain name of [url].
static
Future
<
void
>
deleteCookie
(
String
url
,
String
name
,
{
String
domain
=
""
,
String
path
=
"/"
})
async
{
if
(
domain
==
null
||
domain
.
isEmpty
)
domain
=
_getDomainName
(
url
);
assert
(
url
!=
null
&&
url
.
isNotEmpty
);
assert
(
name
!=
null
&&
name
.
isNotEmpty
);
assert
(
domain
!=
null
&&
url
.
isNotEmpty
);
assert
(
path
!=
null
&&
url
.
isNotEmpty
);
Map
<
String
,
dynamic
>
args
=
<
String
,
dynamic
>{};
args
.
putIfAbsent
(
'url'
,
()
=>
url
);
args
.
putIfAbsent
(
'name'
,
()
=>
name
);
args
.
putIfAbsent
(
'domain'
,
()
=>
domain
);
args
.
putIfAbsent
(
'path'
,
()
=>
path
);
await
_channel
.
invokeMethod
(
'deleteCookie'
,
args
);
}
///Removes all cookies for the given [url], [domain] and [path].
///The default value of [path] is `"/"`.
///If [domain] is `null` or empty, its default value will be the domain name of [url].
static
Future
<
void
>
deleteCookies
(
String
url
,
{
String
domain
=
""
,
String
path
=
"/"
})
async
{
if
(
domain
==
null
||
domain
.
isEmpty
)
domain
=
_getDomainName
(
url
);
assert
(
url
!=
null
&&
url
.
isNotEmpty
);
assert
(
domain
!=
null
&&
url
.
isNotEmpty
);
assert
(
path
!=
null
&&
url
.
isNotEmpty
);
Map
<
String
,
dynamic
>
args
=
<
String
,
dynamic
>{};
args
.
putIfAbsent
(
'url'
,
()
=>
url
);
args
.
putIfAbsent
(
'domain'
,
()
=>
domain
);
args
.
putIfAbsent
(
'path'
,
()
=>
path
);
await
_channel
.
invokeMethod
(
'deleteCookies'
,
args
);
}
///Removes all cookies.
static
Future
<
void
>
deleteAllCookies
()
async
{
Map
<
String
,
dynamic
>
args
=
<
String
,
dynamic
>{};
await
_channel
.
invokeMethod
(
'deleteAllCookies'
,
args
);
}
static
String
_getDomainName
(
String
url
)
{
Uri
uri
=
Uri
.
parse
(
url
);
String
domain
=
uri
.
host
;
if
(
domain
==
null
)
return
""
;
return
domain
.
startsWith
(
"www."
)
?
domain
.
substring
(
4
)
:
domain
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment