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
81a4b6ad
Commit
81a4b6ad
authored
Oct 26, 2018
by
pichillilorenzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added deleteCookie() and deleteCookies() on Android (#8)
parent
40dccfde
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
14 deletions
+79
-14
.idea/workspace.xml
.idea/workspace.xml
+7
-12
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/MyCookieManager.java
...pichillilorenzo/flutter_inappbrowser/MyCookieManager.java
+72
-2
No files found.
.idea/workspace.xml
View file @
81a4b6ad
...
@@ -15,12 +15,8 @@
...
@@ -15,12 +15,8 @@
</component>
</component>
<component
name=
"ChangeListManager"
>
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"9b41f7a2-a71e-4923-91fb-249d7815b3e7"
name=
"Default"
comment=
""
>
<list
default=
"true"
id=
"9b41f7a2-a71e-4923-91fb-249d7815b3e7"
name=
"Default"
comment=
""
>
<change
beforePath=
"$PROJECT_DIR$/.idea/workspace.xml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/.idea/workspace.xml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/MyCookieManager.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/MyCookieManager.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/MyCookieManager.java"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/MyCookieManager.java"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/example/android/build.gradle"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/example/android/build.gradle"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/ios/Classes/InAppBrowserWebViewController.swift"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/example/lib/main.dart"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/example/lib/main.dart"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/lib/flutter_inappbrowser.dart"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/lib/flutter_inappbrowser.dart"
afterDir=
"false"
/>
</list>
</list>
<ignored
path=
"$PROJECT_DIR$/.dart_tool/"
/>
<ignored
path=
"$PROJECT_DIR$/.dart_tool/"
/>
<ignored
path=
"$PROJECT_DIR$/.idea/"
/>
<ignored
path=
"$PROJECT_DIR$/.idea/"
/>
...
@@ -40,8 +36,8 @@
...
@@ -40,8 +36,8 @@
<file
leaf-file-name=
"flutter_inappbrowser.dart"
pinned=
"false"
current-in-tab=
"true"
>
<file
leaf-file-name=
"flutter_inappbrowser.dart"
pinned=
"false"
current-in-tab=
"true"
>
<entry
file=
"file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart"
>
<entry
file=
"file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"
542
"
>
<state
relative-caret-position=
"
269
"
>
<caret
line=
"117
8"
column=
"47"
selection-start-line=
"1178"
selection-start-column=
"38"
selection-end-line=
"1178"
selection-end-column=
"47
"
/>
<caret
line=
"117
9"
column=
"42"
lean-forward=
"true"
selection-start-line=
"1179"
selection-start-column=
"42"
selection-end-line=
"1179"
selection-end-column=
"42
"
/>
<folding>
<folding>
<element
signature=
"e#814#831#0"
expanded=
"true"
/>
<element
signature=
"e#814#831#0"
expanded=
"true"
/>
</folding>
</folding>
...
@@ -152,7 +148,7 @@
...
@@ -152,7 +148,7 @@
</option>
</option>
</component>
</component>
<component
name=
"ProjectFrameBounds"
>
<component
name=
"ProjectFrameBounds"
>
<option
name=
"x"
value=
"
205
3"
/>
<option
name=
"x"
value=
"
13
3"
/>
<option
name=
"y"
value=
"23"
/>
<option
name=
"y"
value=
"23"
/>
<option
name=
"width"
value=
"1787"
/>
<option
name=
"width"
value=
"1787"
/>
<option
name=
"height"
value=
"1057"
/>
<option
name=
"height"
value=
"1057"
/>
...
@@ -349,8 +345,7 @@
...
@@ -349,8 +345,7 @@
<servers
/>
<servers
/>
</component>
</component>
<component
name=
"ToolWindowManager"
>
<component
name=
"ToolWindowManager"
>
<frame
x=
"2053"
y=
"23"
width=
"1787"
height=
"1057"
extended-state=
"0"
/>
<frame
x=
"133"
y=
"23"
width=
"1787"
height=
"1057"
extended-state=
"0"
/>
<editor
active=
"true"
/>
<layout>
<layout>
<window_info
anchor=
"bottom"
id=
"Android Profiler"
order=
"7"
show_stripe_button=
"false"
/>
<window_info
anchor=
"bottom"
id=
"Android Profiler"
order=
"7"
show_stripe_button=
"false"
/>
<window_info
anchor=
"bottom"
id=
"TODO"
order=
"6"
/>
<window_info
anchor=
"bottom"
id=
"TODO"
order=
"6"
/>
...
@@ -664,8 +659,8 @@
...
@@ -664,8 +659,8 @@
</entry>
</entry>
<entry
file=
"file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart"
>
<entry
file=
"file://$PROJECT_DIR$/lib/flutter_inappbrowser.dart"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<provider
selected=
"true"
editor-type-id=
"text-editor"
>
<state
relative-caret-position=
"
542
"
>
<state
relative-caret-position=
"
269
"
>
<caret
line=
"117
8"
column=
"47"
selection-start-line=
"1178"
selection-start-column=
"38"
selection-end-line=
"1178"
selection-end-column=
"47
"
/>
<caret
line=
"117
9"
column=
"42"
lean-forward=
"true"
selection-start-line=
"1179"
selection-start-column=
"42"
selection-end-line=
"1179"
selection-end-column=
"42
"
/>
<folding>
<folding>
<element
signature=
"e#814#831#0"
expanded=
"true"
/>
<element
signature=
"e#814#831#0"
expanded=
"true"
/>
</folding>
</folding>
...
...
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/MyCookieManager.java
View file @
81a4b6ad
...
@@ -3,13 +3,16 @@ package com.pichillilorenzo.flutter_inappbrowser;
...
@@ -3,13 +3,16 @@ package com.pichillilorenzo.flutter_inappbrowser;
import
android.os.Build
;
import
android.os.Build
;
import
android.util.Log
;
import
android.util.Log
;
import
android.webkit.CookieManager
;
import
android.webkit.CookieManager
;
import
android.webkit.CookieSyncManager
;
import
android.webkit.ValueCallback
;
import
android.webkit.ValueCallback
;
import
java.
net.HttpCookie
;
import
java.
text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.TimeZone
;
import
io.flutter.plugin.common.MethodCall
;
import
io.flutter.plugin.common.MethodCall
;
import
io.flutter.plugin.common.MethodChannel
;
import
io.flutter.plugin.common.MethodChannel
;
...
@@ -47,6 +50,16 @@ public class MyCookieManager implements MethodChannel.MethodCallHandler {
...
@@ -47,6 +50,16 @@ public class MyCookieManager implements MethodChannel.MethodCallHandler {
case
"getCookies"
:
case
"getCookies"
:
result
.
success
(
MyCookieManager
.
getCookies
((
String
)
call
.
argument
(
"url"
)));
result
.
success
(
MyCookieManager
.
getCookies
((
String
)
call
.
argument
(
"url"
)));
break
;
break
;
case
"deleteCookie"
:
{
String
url
=
(
String
)
call
.
argument
(
"url"
);
String
name
=
(
String
)
call
.
argument
(
"name"
);
MyCookieManager
.
deleteCookie
(
url
,
name
,
result
);
}
break
;
case
"deleteCookies"
:
MyCookieManager
.
deleteCookies
(
result
);
break
;
default
:
default
:
result
.
notImplemented
();
result
.
notImplemented
();
}
}
...
@@ -71,7 +84,7 @@ public class MyCookieManager implements MethodChannel.MethodCallHandler {
...
@@ -71,7 +84,7 @@ public class MyCookieManager implements MethodChannel.MethodCallHandler {
cookieValue
+=
"; Path="
+
path
;
cookieValue
+=
"; Path="
+
path
;
if
(
expiresDate
!=
null
)
if
(
expiresDate
!=
null
)
cookieValue
+=
";
Max-Age="
+
expiresDate
.
toString
(
);
cookieValue
+=
";
Expires="
+
getCookieExpirationDate
(
expiresDate
);
if
(
isHTTPOnly
!=
null
&&
isHTTPOnly
)
if
(
isHTTPOnly
!=
null
&&
isHTTPOnly
)
cookieValue
+=
"; HttpOnly"
;
cookieValue
+=
"; HttpOnly"
;
...
@@ -88,10 +101,15 @@ public class MyCookieManager implements MethodChannel.MethodCallHandler {
...
@@ -88,10 +101,15 @@ public class MyCookieManager implements MethodChannel.MethodCallHandler {
result
.
success
(
true
);
result
.
success
(
true
);
}
}
});
});
cookieManager
.
flush
();
}
}
else
{
else
{
CookieSyncManager
cookieSyncMngr
=
CookieSyncManager
.
createInstance
(
registrar
.
context
());
cookieSyncMngr
.
startSync
();
cookieManager
.
setCookie
(
url
,
cookieValue
);
cookieManager
.
setCookie
(
url
,
cookieValue
);
result
.
success
(
true
);
result
.
success
(
true
);
cookieSyncMngr
.
stopSync
();
cookieSyncMngr
.
sync
();
}
}
}
}
...
@@ -115,4 +133,56 @@ public class MyCookieManager implements MethodChannel.MethodCallHandler {
...
@@ -115,4 +133,56 @@ public class MyCookieManager implements MethodChannel.MethodCallHandler {
}
}
public
static
void
deleteCookie
(
String
url
,
String
cookieName
,
final
MethodChannel
.
Result
result
)
{
String
cookieValue
=
cookieName
+
"=; Expires=Thu, 01 Jan 1970 00:00:01 GMT;"
;
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
);
}
});
cookieManager
.
flush
();
}
else
{
CookieSyncManager
cookieSyncMngr
=
CookieSyncManager
.
createInstance
(
registrar
.
context
());
cookieSyncMngr
.
startSync
();
cookieManager
.
setCookie
(
url
,
cookieValue
);
result
.
success
(
true
);
cookieSyncMngr
.
stopSync
();
cookieSyncMngr
.
sync
();
}
}
public
static
void
deleteCookies
(
final
MethodChannel
.
Result
result
)
{
CookieManager
cookieManager
=
CookieManager
.
getInstance
();
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
cookieManager
.
removeAllCookies
(
new
ValueCallback
<
Boolean
>()
{
@Override
public
void
onReceiveValue
(
Boolean
aBoolean
)
{
result
.
success
(
true
);
}
});
cookieManager
.
flush
();
}
else
{
CookieSyncManager
cookieSyncMngr
=
CookieSyncManager
.
createInstance
(
registrar
.
context
());
cookieSyncMngr
.
startSync
();
cookieManager
.
removeAllCookie
();
result
.
success
(
true
);
cookieSyncMngr
.
stopSync
();
cookieSyncMngr
.
sync
();
}
}
public
static
String
getCookieExpirationDate
(
Long
timestamp
)
{
final
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"EEE, d MMM yyyy hh:mm:ss z"
);
sdf
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT"
));
return
sdf
.
format
(
new
Date
(
timestamp
));
}
}
}
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