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
35233f09
Commit
35233f09
authored
Oct 24, 2018
by
pichillilorenzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on CookieManager class (Manage cookies #8)
parent
aa88e7d7
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
229 additions
and
107 deletions
+229
-107
.idea/workspace.xml
.idea/workspace.xml
+76
-101
CHANGELOG.md
CHANGELOG.md
+4
-0
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java
...renzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java
+4
-0
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/MyCookieManager.java
...pichillilorenzo/flutter_inappbrowser/MyCookieManager.java
+96
-0
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/Util.java
...n/java/com/pichillilorenzo/flutter_inappbrowser/Util.java
+3
-2
example/lib/main.dart
example/lib/main.dart
+2
-1
lib/flutter_inappbrowser.dart
lib/flutter_inappbrowser.dart
+43
-2
pubspec.yaml
pubspec.yaml
+1
-1
No files found.
.idea/workspace.xml
View file @
35233f09
This diff is collapsed.
Click to expand it.
CHANGELOG.md
View file @
35233f09
## 0.5.3
-
added
`CookieManager`
class
## 0.5.2
-
fixed some missing
`result.success()`
on Android and iOS
...
...
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java
View file @
35233f09
...
...
@@ -39,6 +39,8 @@ import com.pichillilorenzo.flutter_inappbrowser.ChromeCustomTabs.CustomTabActivi
import
java.io.IOException
;
import
java.io.Serializable
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -78,6 +80,8 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
final
MethodChannel
channel
=
new
MethodChannel
(
registrar
.
messenger
(),
"com.pichillilorenzo/flutter_inappbrowser"
);
channel
.
setMethodCallHandler
(
new
InAppBrowserFlutterPlugin
(
registrar
,
activity
));
new
MyCookieManager
(
registrar
);
registrar
.
platformViewRegistry
()
.
registerViewFactory
(
...
...
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/MyCookieManager.java
0 → 100644
View file @
35233f09
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
);
}
}
}
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/Util.java
View file @
35233f09
...
...
@@ -4,14 +4,14 @@ import android.content.res.AssetManager;
import
java.io.IOException
;
import
java.io.InputStream
;
import
io.flutter.plugin.common.PluginRegistry
;
public
class
Util
{
static
final
String
LOG_TAG
=
"Util"
;
public
static
final
String
ANDROID_ASSET_URL
=
"file:///android_asset/"
;
public
static
String
getUrlAsset
(
PluginRegistry
.
Registrar
registrar
,
String
assetFilePath
)
throws
IOException
{
public
static
String
getUrlAsset
(
PluginRegistry
.
Registrar
registrar
,
String
assetFilePath
)
throws
IOException
{
String
key
=
registrar
.
lookupKeyForAsset
(
assetFilePath
);
AssetManager
mg
=
registrar
.
activeContext
().
getResources
().
getAssets
();
InputStream
is
=
null
;
...
...
@@ -36,4 +36,5 @@ public class Util {
return
ANDROID_ASSET_URL
+
key
;
}
}
example/lib/main.dart
View file @
35233f09
...
...
@@ -65,7 +65,7 @@ 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.body.innerHTML
"));
print
(
await
this
.
webViewController
.
injectScriptCode
(
"document.cookie
"
));
//
// print(await this.webViewController.injectScriptCode("null"));
// print(await this.webViewController.injectScriptCode("undefined"));
...
...
@@ -271,6 +271,7 @@ 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
inAppBrowserFallback
.
open
(
url:
"https://flutter.io/"
,
options:
{
//"useOnLoadResource": true,
//"hidden": true,
...
...
lib/flutter_inappbrowser.dart
View file @
35233f09
...
...
@@ -86,7 +86,7 @@ class ConsoleMessage {
class
_ChannelManager
{
static
const
MethodChannel
channel
=
const
MethodChannel
(
'com.pichillilorenzo/flutter_inappbrowser'
);
static
fina
l
initialized
=
false
;
static
boo
l
initialized
=
false
;
static
final
listeners
=
HashMap
<
String
,
ListenerCallback
>();
static
Future
<
dynamic
>
_handleMethod
(
MethodCall
call
)
async
{
...
...
@@ -102,6 +102,7 @@ class _ChannelManager {
static
void
init
()
{
channel
.
setMethodCallHandler
(
_handleMethod
);
initialized
=
true
;
}
}
...
...
@@ -1116,4 +1117,44 @@ class InAppLocalhostServer {
}
}
}
\ No newline at end of file
}
class
CookieManager
{
static
bool
_initialized
=
false
;
static
const
MethodChannel
_channel
=
const
MethodChannel
(
'com.pichillilorenzo/flutter_inappbrowser_cookiemanager'
);
static
void
_init
()
{
_channel
.
setMethodCallHandler
(
_handleMethod
);
_initialized
=
true
;
}
static
Future
<
dynamic
>
_handleMethod
(
MethodCall
call
)
async
{
}
static
Future
<
void
>
setCookie
(
String
url
,
String
name
,
String
value
,
String
domain
,
{
String
path
=
"/"
,
int
expiresDate
,
bool
isHTTPOnly
,
bool
isSecure
})
async
{
if
(!
_initialized
)
_init
();
assert
(
url
!=
null
&&
url
.
isNotEmpty
);
assert
(
name
!=
null
&&
name
.
isNotEmpty
);
assert
(
value
!=
null
&&
value
.
isNotEmpty
);
assert
(
domain
!=
null
&&
domain
.
isNotEmpty
);
assert
(
path
!=
null
&&
path
.
isNotEmpty
);
Map
<
String
,
dynamic
>
args
=
<
String
,
dynamic
>{};
args
.
putIfAbsent
(
'url'
,
()
=>
url
);
args
.
putIfAbsent
(
'name'
,
()
=>
name
);
args
.
putIfAbsent
(
'value'
,
()
=>
value
);
args
.
putIfAbsent
(
'domain'
,
()
=>
domain
);
args
.
putIfAbsent
(
'path'
,
()
=>
path
);
args
.
putIfAbsent
(
'expiresDate'
,
()
=>
expiresDate
);
args
.
putIfAbsent
(
'isHTTPOnly'
,
()
=>
isHTTPOnly
);
args
.
putIfAbsent
(
'isSecure'
,
()
=>
isSecure
);
await
_channel
.
invokeMethod
(
'setCookie'
,
args
);
}
}
pubspec.yaml
View file @
35233f09
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 <pichillilorenzo@gmail.com>
homepage
:
https://github.com/pichillilorenzo/flutter_inappbrowser
...
...
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