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
aa583ad6
Commit
aa583ad6
authored
Sep 23, 2018
by
pichillilorenzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added shouldOverrideUrlLoading method
parent
5978aba7
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
67 additions
and
86 deletions
+67
-86
.idea/workspace.xml
.idea/workspace.xml
+12
-59
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java
...renzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java
+1
-2
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserOptions.java
...illilorenzo/flutter_inappbrowser/InAppBrowserOptions.java
+1
-0
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java
...renzo/flutter_inappbrowser/InAppBrowserWebViewClient.java
+12
-9
example/lib/main.dart
example/lib/main.dart
+7
-1
ios/Classes/InAppBrowserOptions.swift
ios/Classes/InAppBrowserOptions.swift
+2
-1
ios/Classes/InAppBrowserWebViewController.swift
ios/Classes/InAppBrowserWebViewController.swift
+9
-3
ios/Classes/SwiftFlutterPlugin.swift
ios/Classes/SwiftFlutterPlugin.swift
+11
-7
lib/flutter_inappbrowser.dart
lib/flutter_inappbrowser.dart
+12
-4
No files found.
.idea/workspace.xml
View file @
aa583ad6
This diff is collapsed.
Click to expand it.
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserFlutterPlugin.java
View file @
aa583ad6
...
@@ -78,7 +78,6 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
...
@@ -78,7 +78,6 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
channel
.
setMethodCallHandler
(
new
InAppBrowserFlutterPlugin
(
registrar
,
registrar
.
activity
()));
channel
.
setMethodCallHandler
(
new
InAppBrowserFlutterPlugin
(
registrar
,
registrar
.
activity
()));
}
}
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
KITKAT
)
@Override
@Override
public
void
onMethodCall
(
MethodCall
call
,
final
Result
result
)
{
public
void
onMethodCall
(
MethodCall
call
,
final
Result
result
)
{
String
source
;
String
source
;
...
@@ -443,7 +442,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
...
@@ -443,7 +442,7 @@ public class InAppBrowserFlutterPlugin implements MethodCallHandler {
public
void
run
()
{
public
void
run
()
{
Map
<
String
,
Object
>
obj
=
new
HashMap
<>();
Map
<
String
,
Object
>
obj
=
new
HashMap
<>();
channel
.
invokeMethod
(
"
e
xit"
,
obj
);
channel
.
invokeMethod
(
"
onE
xit"
,
obj
);
// The JS protects against multiple calls, so this should happen only when
// The JS protects against multiple calls, so this should happen only when
// close() is called by other native code.
// close() is called by other native code.
...
...
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserOptions.java
View file @
aa583ad6
...
@@ -29,6 +29,7 @@ public class InAppBrowserOptions {
...
@@ -29,6 +29,7 @@ public class InAppBrowserOptions {
boolean
domStorageEnabled
=
true
;
boolean
domStorageEnabled
=
true
;
boolean
useWideViewPort
=
true
;
boolean
useWideViewPort
=
true
;
boolean
safeBrowsingEnabled
=
true
;
boolean
safeBrowsingEnabled
=
true
;
boolean
useShouldOverrideUrlLoading
=
false
;
public
void
parse
(
HashMap
<
String
,
Object
>
options
)
{
public
void
parse
(
HashMap
<
String
,
Object
>
options
)
{
Iterator
it
=
options
.
entrySet
().
iterator
();
Iterator
it
=
options
.
entrySet
().
iterator
();
...
...
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppBrowserWebViewClient.java
View file @
aa583ad6
...
@@ -28,7 +28,12 @@ public class InAppBrowserWebViewClient extends WebViewClient {
...
@@ -28,7 +28,12 @@ public class InAppBrowserWebViewClient extends WebViewClient {
@Override
@Override
public
boolean
shouldOverrideUrlLoading
(
WebView
webView
,
String
url
)
{
public
boolean
shouldOverrideUrlLoading
(
WebView
webView
,
String
url
)
{
//return true;
if
(
activity
.
options
.
useShouldOverrideUrlLoading
)
{
Map
<
String
,
Object
>
obj
=
new
HashMap
<>();
obj
.
put
(
"url"
,
url
);
InAppBrowserFlutterPlugin
.
channel
.
invokeMethod
(
"shouldOverrideUrlLoading"
,
obj
);
return
true
;
}
if
(
url
.
startsWith
(
WebView
.
SCHEME_TEL
))
{
if
(
url
.
startsWith
(
WebView
.
SCHEME_TEL
))
{
try
{
try
{
...
@@ -81,11 +86,9 @@ public class InAppBrowserWebViewClient extends WebViewClient {
...
@@ -81,11 +86,9 @@ public class InAppBrowserWebViewClient extends WebViewClient {
Log
.
e
(
LOG_TAG
,
"Error sending sms "
+
url
+
":"
+
e
.
toString
());
Log
.
e
(
LOG_TAG
,
"Error sending sms "
+
url
+
":"
+
e
.
toString
());
}
}
}
}
else
{
return
super
.
shouldOverrideUrlLoading
(
webView
,
url
);
}
return
false
;
return
super
.
shouldOverrideUrlLoading
(
webView
,
url
);
}
}
...
@@ -108,7 +111,7 @@ public class InAppBrowserWebViewClient extends WebViewClient {
...
@@ -108,7 +111,7 @@ public class InAppBrowserWebViewClient extends WebViewClient {
Map
<
String
,
Object
>
obj
=
new
HashMap
<>();
Map
<
String
,
Object
>
obj
=
new
HashMap
<>();
obj
.
put
(
"url"
,
url
);
obj
.
put
(
"url"
,
url
);
InAppBrowserFlutterPlugin
.
channel
.
invokeMethod
(
"
loads
tart"
,
obj
);
InAppBrowserFlutterPlugin
.
channel
.
invokeMethod
(
"
onLoadS
tart"
,
obj
);
}
}
...
@@ -131,7 +134,7 @@ public class InAppBrowserWebViewClient extends WebViewClient {
...
@@ -131,7 +134,7 @@ public class InAppBrowserWebViewClient extends WebViewClient {
Map
<
String
,
Object
>
obj
=
new
HashMap
<>();
Map
<
String
,
Object
>
obj
=
new
HashMap
<>();
obj
.
put
(
"url"
,
url
);
obj
.
put
(
"url"
,
url
);
InAppBrowserFlutterPlugin
.
channel
.
invokeMethod
(
"
loads
top"
,
obj
);
InAppBrowserFlutterPlugin
.
channel
.
invokeMethod
(
"
onLoadS
top"
,
obj
);
}
}
public
void
onReceivedError
(
WebView
view
,
int
errorCode
,
String
description
,
String
failingUrl
)
{
public
void
onReceivedError
(
WebView
view
,
int
errorCode
,
String
description
,
String
failingUrl
)
{
...
@@ -143,7 +146,7 @@ public class InAppBrowserWebViewClient extends WebViewClient {
...
@@ -143,7 +146,7 @@ public class InAppBrowserWebViewClient extends WebViewClient {
obj
.
put
(
"url"
,
failingUrl
);
obj
.
put
(
"url"
,
failingUrl
);
obj
.
put
(
"code"
,
errorCode
);
obj
.
put
(
"code"
,
errorCode
);
obj
.
put
(
"message"
,
description
);
obj
.
put
(
"message"
,
description
);
InAppBrowserFlutterPlugin
.
channel
.
invokeMethod
(
"
loade
rror"
,
obj
);
InAppBrowserFlutterPlugin
.
channel
.
invokeMethod
(
"
onLoadE
rror"
,
obj
);
}
}
public
void
onReceivedSslError
(
WebView
view
,
SslErrorHandler
handler
,
SslError
error
)
{
public
void
onReceivedSslError
(
WebView
view
,
SslErrorHandler
handler
,
SslError
error
)
{
...
@@ -175,7 +178,7 @@ public class InAppBrowserWebViewClient extends WebViewClient {
...
@@ -175,7 +178,7 @@ public class InAppBrowserWebViewClient extends WebViewClient {
break
;
break
;
}
}
obj
.
put
(
"message"
,
"SslError: "
+
message
);
obj
.
put
(
"message"
,
"SslError: "
+
message
);
InAppBrowserFlutterPlugin
.
channel
.
invokeMethod
(
"
loade
rror"
,
obj
);
InAppBrowserFlutterPlugin
.
channel
.
invokeMethod
(
"
onLoadE
rror"
,
obj
);
handler
.
cancel
();
handler
.
cancel
();
}
}
...
...
example/lib/main.dart
View file @
aa583ad6
...
@@ -52,6 +52,11 @@ class MyInAppBrowser extends InAppBrowser {
...
@@ -52,6 +52,11 @@ class MyInAppBrowser extends InAppBrowser {
print
(
"
\n\n
Browser closed!
\n\n
"
);
print
(
"
\n\n
Browser closed!
\n\n
"
);
}
}
@override
void
shouldOverrideUrlLoading
(
String
url
)
{
print
(
"
\n\n
override
$url
\n\n
"
);
this
.
loadUrl
(
url
);
}
}
}
MyInAppBrowser
inAppBrowser
=
new
MyInAppBrowser
();
MyInAppBrowser
inAppBrowser
=
new
MyInAppBrowser
();
...
@@ -80,8 +85,9 @@ class _MyAppState extends State<MyApp> {
...
@@ -80,8 +85,9 @@ class _MyAppState extends State<MyApp> {
body:
new
Center
(
body:
new
Center
(
child:
new
RaisedButton
(
onPressed:
()
{
child:
new
RaisedButton
(
onPressed:
()
{
inAppBrowser
.
open
(
"https://flutter.io/"
,
options:
{
inAppBrowser
.
open
(
"https://flutter.io/"
,
options:
{
//"hidden": true
//"hidden": true
,
//"toolbarTopFixedTitle": "Fixed title",
//"toolbarTopFixedTitle": "Fixed title",
"useShouldOverrideUrlLoading"
:
true
//"hideUrlBar": true,
//"hideUrlBar": true,
//"toolbarTop": false,
//"toolbarTop": false,
//"toolbarBottom": false
//"toolbarBottom": false
...
...
ios/Classes/InAppBrowserOptions.swift
View file @
aa583ad6
...
@@ -38,6 +38,7 @@ public class InAppBrowserOptions: NSObject {
...
@@ -38,6 +38,7 @@ public class InAppBrowserOptions: NSObject {
var
allowsPictureInPictureMediaPlayback
=
true
var
allowsPictureInPictureMediaPlayback
=
true
var
javaScriptCanOpenWindowsAutomatically
=
false
var
javaScriptCanOpenWindowsAutomatically
=
false
var
javaScriptEnabled
=
true
var
javaScriptEnabled
=
true
var
useShouldOverrideUrlLoading
=
false
override
init
(){
override
init
(){
super
.
init
()
super
.
init
()
...
@@ -45,7 +46,7 @@ public class InAppBrowserOptions: NSObject {
...
@@ -45,7 +46,7 @@ public class InAppBrowserOptions: NSObject {
public
func
parse
(
options
:
[
String
:
Any
])
{
public
func
parse
(
options
:
[
String
:
Any
])
{
for
(
key
,
value
)
in
options
{
for
(
key
,
value
)
in
options
{
if
self
.
value
(
forKey
:
key
)
!=
nil
{
if
self
.
responds
(
to
:
Selector
(
key
))
{
self
.
setValue
(
value
,
forKey
:
key
)
self
.
setValue
(
value
,
forKey
:
key
)
}
}
}
}
...
...
ios/Classes/InAppBrowserWebViewController.swift
View file @
aa583ad6
...
@@ -426,6 +426,12 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
...
@@ -426,6 +426,12 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
let
url
=
navigationAction
.
request
.
url
let
url
=
navigationAction
.
request
.
url
if
(
url
!=
nil
&&
navigationAction
.
navigationType
==
.
linkActivated
&&
(
browserOptions
?
.
useShouldOverrideUrlLoading
)
!
)
{
navigationDelegate
?
.
shouldOverrideUrlLoading
(
webView
,
url
:
url
!
)
decisionHandler
(
.
cancel
)
return
}
if
url
!=
nil
&&
(
navigationAction
.
navigationType
==
.
linkActivated
||
navigationAction
.
navigationType
==
.
backForward
)
{
if
url
!=
nil
&&
(
navigationAction
.
navigationType
==
.
linkActivated
||
navigationAction
.
navigationType
==
.
backForward
)
{
currentURL
=
url
currentURL
=
url
updateUrlTextField
(
url
:
(
url
?
.
absoluteString
)
!
)
updateUrlTextField
(
url
:
(
url
?
.
absoluteString
)
!
)
...
@@ -477,7 +483,7 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
...
@@ -477,7 +483,7 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
spinner
.
startAnimating
()
spinner
.
startAnimating
()
}
}
return
(
navigationDelegate
?
.
webViewDidStartLoad
(
webView
))
!
return
(
navigationDelegate
?
.
onLoadStart
(
webView
))
!
}
}
func
webView
(
_
webView
:
WKWebView
,
didFinish
navigation
:
WKNavigation
!
)
{
func
webView
(
_
webView
:
WKWebView
,
didFinish
navigation
:
WKNavigation
!
)
{
...
@@ -487,7 +493,7 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
...
@@ -487,7 +493,7 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
backButton
.
isEnabled
=
webView
.
canGoBack
backButton
.
isEnabled
=
webView
.
canGoBack
forwardButton
.
isEnabled
=
webView
.
canGoForward
forwardButton
.
isEnabled
=
webView
.
canGoForward
spinner
.
stopAnimating
()
spinner
.
stopAnimating
()
navigationDelegate
?
.
webViewDidFinishLoad
(
webView
)
navigationDelegate
?
.
onLoadStop
(
webView
)
}
}
// func webView(_ webView: WKWebView,
// func webView(_ webView: WKWebView,
...
@@ -505,6 +511,6 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
...
@@ -505,6 +511,6 @@ class InAppBrowserWebViewController: UIViewController, WKUIDelegate, WKNavigatio
backButton
.
isEnabled
=
webView
.
canGoBack
backButton
.
isEnabled
=
webView
.
canGoBack
forwardButton
.
isEnabled
=
webView
.
canGoForward
forwardButton
.
isEnabled
=
webView
.
canGoForward
spinner
.
stopAnimating
()
spinner
.
stopAnimating
()
navigationDelegate
?
.
webViewDidFailLoadWith
Error
(
webView
,
error
:
error
)
navigationDelegate
?
.
onLoad
Error
(
webView
,
error
:
error
)
}
}
}
}
ios/Classes/SwiftFlutterPlugin.swift
View file @
aa583ad6
...
@@ -339,25 +339,29 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
...
@@ -339,25 +339,29 @@ public class SwiftFlutterPlugin: NSObject, FlutterPlugin {
injectDeferredObject
(
arguments
[
"urlFile"
]
as!
String
,
withWrapper
:
jsWrapper
,
result
:
result
)
injectDeferredObject
(
arguments
[
"urlFile"
]
as!
String
,
withWrapper
:
jsWrapper
,
result
:
result
)
}
}
func
webViewDidStartLoad
(
_
webView
:
WKWebView
)
{
func
onLoadStart
(
_
webView
:
WKWebView
)
{
let
url
:
String
=
webViewController
!.
currentURL
!.
absoluteString
let
url
:
String
=
webViewController
!.
currentURL
!.
absoluteString
channel
.
invokeMethod
(
"
loads
tart"
,
arguments
:
[
"url"
:
url
])
channel
.
invokeMethod
(
"
onLoadS
tart"
,
arguments
:
[
"url"
:
url
])
}
}
func
webViewDidFinishLoad
(
_
webView
:
WKWebView
)
{
func
onLoadStop
(
_
webView
:
WKWebView
)
{
let
url
:
String
=
webViewController
!.
currentURL
!.
absoluteString
let
url
:
String
=
webViewController
!.
currentURL
!.
absoluteString
channel
.
invokeMethod
(
"
loads
top"
,
arguments
:
[
"url"
:
url
])
channel
.
invokeMethod
(
"
onLoadS
top"
,
arguments
:
[
"url"
:
url
])
}
}
func
webViewDidFailLoadWith
Error
(
_
webView
:
WKWebView
,
error
:
Error
)
{
func
onLoad
Error
(
_
webView
:
WKWebView
,
error
:
Error
)
{
let
url
:
String
=
webViewController
!.
currentURL
!.
absoluteString
let
url
:
String
=
webViewController
!.
currentURL
!.
absoluteString
let
arguments
=
[
"url"
:
url
,
"code"
:
error
.
_code
,
"message"
:
error
.
localizedDescription
]
as
[
String
:
Any
]
let
arguments
=
[
"url"
:
url
,
"code"
:
error
.
_code
,
"message"
:
error
.
localizedDescription
]
as
[
String
:
Any
]
channel
.
invokeMethod
(
"loaderror"
,
arguments
:
arguments
)
channel
.
invokeMethod
(
"onLoadError"
,
arguments
:
arguments
)
}
func
shouldOverrideUrlLoading
(
_
webView
:
WKWebView
,
url
:
URL
)
{
channel
.
invokeMethod
(
"shouldOverrideUrlLoading"
,
arguments
:
[
"url"
:
url
.
absoluteString
])
}
}
func
browserExit
()
{
func
browserExit
()
{
channel
.
invokeMethod
(
"
e
xit"
,
arguments
:
[])
channel
.
invokeMethod
(
"
onE
xit"
,
arguments
:
[])
// Set navigationDelegate to nil to ensure no callbacks are received from it.
// Set navigationDelegate to nil to ensure no callbacks are received from it.
webViewController
?
.
navigationDelegate
=
nil
webViewController
?
.
navigationDelegate
=
nil
...
...
lib/flutter_inappbrowser.dart
View file @
aa583ad6
...
@@ -34,23 +34,27 @@ class InAppBrowser {
...
@@ -34,23 +34,27 @@ class InAppBrowser {
Future
<
dynamic
>
_handleMethod
(
MethodCall
call
)
async
{
Future
<
dynamic
>
_handleMethod
(
MethodCall
call
)
async
{
switch
(
call
.
method
)
{
switch
(
call
.
method
)
{
case
"
loads
tart"
:
case
"
onLoadS
tart"
:
String
url
=
call
.
arguments
[
"url"
];
String
url
=
call
.
arguments
[
"url"
];
onLoadStart
(
url
);
onLoadStart
(
url
);
break
;
break
;
case
"
loads
top"
:
case
"
onLoadS
top"
:
String
url
=
call
.
arguments
[
"url"
];
String
url
=
call
.
arguments
[
"url"
];
onLoadStop
(
url
);
onLoadStop
(
url
);
break
;
break
;
case
"
loade
rror"
:
case
"
onLoadE
rror"
:
String
url
=
call
.
arguments
[
"url"
];
String
url
=
call
.
arguments
[
"url"
];
int
code
=
call
.
arguments
[
"code"
];
int
code
=
call
.
arguments
[
"code"
];
String
message
=
call
.
arguments
[
"message"
];
String
message
=
call
.
arguments
[
"message"
];
onLoadError
(
url
,
code
,
message
);
onLoadError
(
url
,
code
,
message
);
break
;
break
;
case
"
e
xit"
:
case
"
onE
xit"
:
onExit
();
onExit
();
break
;
break
;
case
"shouldOverrideUrlLoading"
:
String
url
=
call
.
arguments
[
"url"
];
shouldOverrideUrlLoading
(
url
);
break
;
}
}
return
new
Future
.
value
(
""
);
return
new
Future
.
value
(
""
);
}
}
...
@@ -226,4 +230,8 @@ class InAppBrowser {
...
@@ -226,4 +230,8 @@ class InAppBrowser {
}
}
void
shouldOverrideUrlLoading
(
String
url
)
{
}
}
}
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