2013-05-16 13:57:19 -07:00
/ *
Licensed to the Apache Software Foundation ( ASF ) under one
or more contributor license agreements . See the NOTICE file
distributed with this work for additional information
regarding copyright ownership . The ASF licenses this file
to you under the Apache License , Version 2.0 ( the
"License" ) ; you may not use this file except in compliance
with the License . You may obtain a copy of the License at
http : // www . apache . org / licenses / LICENSE -2.0
Unless required by applicable law or agreed to in writing ,
software distributed under the License is distributed on an
"AS IS" BASIS , WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND , either express or implied . See the License for the
specific language governing permissions and limitations
under the License .
* /
# import "CDVInAppBrowser.h"
2018-09-03 13:12:15 +01:00
# import "CDVInAppBrowserOptions.h"
# import "CDVUIInAppBrowser.h"
# import "CDVWKInAppBrowser.h"
2013-05-20 14:04:50 -07:00
# import < Cordova / CDVPluginResult . h >
2013-05-16 13:57:19 -07:00
# pragma mark CDVInAppBrowser
@ implementation CDVInAppBrowser
2015-03-13 20:29:55 -07:00
- ( void ) pluginInitialize
2013-05-16 13:57:19 -07:00
{
2018-09-03 13:12:15 +01:00
// default values
self . usewkwebview = NO ;
2013-05-16 13:57:19 -07:00
2018-09-03 13:12:15 +01:00
# if __has _include ( "CDVWKWebViewEngine.h" )
self . wkwebviewavailable = YES ;
2015-03-13 20:29:55 -07:00
# else
2018-09-03 13:12:15 +01:00
self . wkwebviewavailable = NO ;
2015-03-13 20:29:55 -07:00
# endif
2013-05-16 13:57:19 -07:00
}
2018-09-03 13:12:15 +01:00
- ( void ) open : ( CDVInvokedUrlCommand * ) command
2013-05-16 13:57:19 -07:00
{
2018-09-03 13:12:15 +01:00
NSString * options = [ command argumentAtIndex : 2 withDefault : @ "" andClass : [ NSString class ] ] ;
2013-11-18 15:00:25 +00:00
CDVInAppBrowserOptions * browserOptions = [ CDVInAppBrowserOptions parseOptions : options ] ;
2018-09-03 13:12:15 +01:00
if ( browserOptions . usewkwebview && ! self . wkwebviewavailable ) {
[ self . commandDelegate sendPluginResult : [ CDVPluginResult resultWithStatus : CDVCommandStatus_ERROR messageAsDictionary : @ { @ "type" : @ "loaderror" , @ "message" : @ "usewkwebview option specified but but no plugin that supplies a WKWebView engine is present" } ] callbackId : command . callbackId ] ;
2014-01-07 10:52:38 -05:00
return ;
}
2018-09-03 13:12:15 +01:00
self . usewkwebview = browserOptions . usewkwebview ;
if ( self . usewkwebview ) {
[ [ CDVWKInAppBrowser getInstance ] open : command ] ;
} else {
[ [ CDVUIInAppBrowser getInstance ] open : command ] ;
2014-01-07 10:52:38 -05:00
}
2013-06-13 15:49:11 -07:00
}
2018-09-03 13:12:15 +01:00
- ( void ) close : ( CDVInvokedUrlCommand * ) command
2015-02-05 07:20:57 -05:00
{
2018-09-03 13:12:15 +01:00
if ( self . usewkwebview ) {
[ [ CDVWKInAppBrowser getInstance ] close : command ] ;
} else {
[ [ CDVUIInAppBrowser getInstance ] close : command ] ;
2015-02-05 07:20:57 -05:00
}
}
2015-11-20 10:53:36 -08:00
2018-09-03 13:12:15 +01:00
- ( void ) show : ( CDVInvokedUrlCommand * ) command
2013-05-16 13:57:19 -07:00
{
2018-09-03 13:12:15 +01:00
if ( self . usewkwebview ) {
[ [ CDVWKInAppBrowser getInstance ] show : command ] ;
} else {
[ [ CDVUIInAppBrowser getInstance ] show : command ] ;
2018-08-22 14:43:06 -07:00
}
2013-05-16 13:57:19 -07:00
}
2018-09-03 13:12:15 +01:00
- ( void ) hide : ( CDVInvokedUrlCommand * ) command
2013-05-16 13:57:19 -07:00
{
2018-09-03 13:12:15 +01:00
if ( self . usewkwebview ) {
[ [ CDVWKInAppBrowser getInstance ] hide : command ] ;
} else {
[ [ CDVUIInAppBrowser getInstance ] hide : command ] ;
2013-05-16 13:57:19 -07:00
}
}
2018-09-03 13:12:15 +01:00
2013-05-16 13:57:19 -07:00
- ( void ) injectScriptCode : ( CDVInvokedUrlCommand * ) command
{
2018-09-03 13:12:15 +01:00
if ( self . usewkwebview ) {
[ [ CDVWKInAppBrowser getInstance ] injectScriptCode : command ] ;
} else {
[ [ CDVUIInAppBrowser getInstance ] injectScriptCode : command ] ;
2013-05-16 13:57:19 -07:00
}
}
- ( void ) injectScriptFile : ( CDVInvokedUrlCommand * ) command
{
2018-09-03 13:12:15 +01:00
if ( self . usewkwebview ) {
[ [ CDVWKInAppBrowser getInstance ] injectScriptFile : command ] ;
} else {
[ [ CDVUIInAppBrowser getInstance ] injectScriptFile : command ] ;
2013-05-16 13:57:19 -07:00
}
}
- ( void ) injectStyleCode : ( CDVInvokedUrlCommand * ) command
{
2018-09-03 13:12:15 +01:00
if ( self . usewkwebview ) {
[ [ CDVWKInAppBrowser getInstance ] injectStyleCode : command ] ;
} else {
[ [ CDVUIInAppBrowser getInstance ] injectStyleCode : command ] ;
2013-05-16 13:57:19 -07:00
}
}
- ( void ) injectStyleFile : ( CDVInvokedUrlCommand * ) command
{
2018-09-03 13:12:15 +01:00
if ( self . usewkwebview ) {
[ [ CDVWKInAppBrowser getInstance ] injectStyleFile : command ] ;
} else {
[ [ CDVUIInAppBrowser getInstance ] injectStyleFile : command ] ;
2017-10-04 16:41:31 +00:00
}
2014-04-17 16:32:34 -07:00
}
2013-05-16 13:57:19 -07:00
@ end