forked from public/cordova-plugin-inappbrowser
Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a518026f15 | |||
|
|
180fefad1e | ||
|
|
74549a01ce | ||
|
|
2fe3ef9096 | ||
|
|
76e58cdff0 | ||
|
|
c9f18cb0e3 | ||
|
|
b956208c94 | ||
|
|
6f67da9d7c | ||
|
|
b03fa7b78e | ||
|
|
e3e70c2ffa | ||
|
|
c3d4fda5b6 | ||
|
|
4dd29759f2 | ||
|
|
bddef7d46e | ||
|
|
7fa4336a77 | ||
|
|
031d07d47b | ||
|
|
694ffb52eb | ||
|
|
b8e87a8b1d | ||
|
|
32e850e210 | ||
|
|
59be27019c | ||
|
|
0aebf7c325 | ||
|
|
bb76e20464 | ||
|
|
7c59835dca | ||
|
|
2793e16ab4 | ||
|
|
cbe345689b | ||
|
|
9b6b229509 | ||
|
|
074d4d03ea | ||
|
|
548f19ca90 | ||
|
|
4227fe8211 | ||
|
|
df4615dea4 | ||
|
|
396c085ba3 | ||
|
|
c01f037c8a | ||
|
|
11ba4c4e7e | ||
|
|
7a856bec60 | ||
|
|
4129f11e24 | ||
|
|
290841dea6 | ||
|
|
0e5f05c938 | ||
|
|
e78ffe7fc2 | ||
|
|
e658c8c201 | ||
|
|
6c55e6172c | ||
|
|
09ad59f7ef |
@@ -12,12 +12,16 @@ image:
|
||||
- Visual Studio 2017
|
||||
|
||||
environment:
|
||||
nodejs_version: "4"
|
||||
matrix:
|
||||
- PLATFORM: windows-10-store
|
||||
JUST_BUILD: --justBuild
|
||||
- nodejs_version: "10"
|
||||
- nodejs_version: "12"
|
||||
|
||||
platform:
|
||||
- x86
|
||||
- x64
|
||||
|
||||
install:
|
||||
- npm cache clean -f
|
||||
- ps: Install-Product node $env:nodejs_version
|
||||
- node --version
|
||||
- npm install -g cordova-paramedic@https://github.com/apache/cordova-paramedic.git
|
||||
- npm install -g cordova
|
||||
@@ -26,5 +30,4 @@ install:
|
||||
build: off
|
||||
|
||||
test_script:
|
||||
- npm run eslint
|
||||
- cordova-paramedic --config pr\%PLATFORM% --plugin . %JUST_BUILD%
|
||||
- cordova-paramedic --config pr\windows-10-store --plugin . --justBuild
|
||||
|
||||
22
.asf.yaml
Normal file
22
.asf.yaml
Normal file
@@ -0,0 +1,22 @@
|
||||
# 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.
|
||||
|
||||
notifications:
|
||||
commits: commits@cordova.apache.org
|
||||
issues: issues@cordova.apache.org
|
||||
pullrequests_status: issues@cordova.apache.org
|
||||
pullrequests_comment: issues@cordova.apache.org
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -22,3 +22,4 @@ node_modules
|
||||
|
||||
|
||||
|
||||
sync.sh
|
||||
|
||||
17
.npmignore
17
.npmignore
@@ -1,16 +1,3 @@
|
||||
# CI service configurations
|
||||
.travis.yml
|
||||
.appveyor.yml
|
||||
.*
|
||||
appveyor.yml
|
||||
|
||||
# Testing, code coverage, and linting
|
||||
.eslintignore
|
||||
.eslintrc.yml
|
||||
|
||||
# Git
|
||||
.git
|
||||
.gitattributes
|
||||
.gitignore
|
||||
|
||||
# Github
|
||||
.github
|
||||
tests
|
||||
|
||||
25
.travis.yml
25
.travis.yml
@@ -1,4 +1,4 @@
|
||||
# This Travis configuration file is built after a Cordova Paramedic
|
||||
# This Travis configuration file is built after a Cordova Paramedic
|
||||
# specific template with minimal modifications and adaptations:
|
||||
# https://github.com/apache/cordova-paramedic/blob/master/.travis.yml
|
||||
|
||||
@@ -12,18 +12,18 @@ addons:
|
||||
env:
|
||||
global:
|
||||
- SAUCE_USERNAME=snay
|
||||
- TRAVIS_NODE_VERSION=8
|
||||
- TRAVIS_NODE_VERSION=12
|
||||
- ANDROID_API_LEVEL=28
|
||||
- ANDROID_BUILD_TOOLS_VERSION=28.0.3
|
||||
|
||||
language: node_js
|
||||
node_js: 8
|
||||
node_js: 12
|
||||
|
||||
# yaml anchor/alias: https://medium.com/@tommyvn/travis-yml-dry-with-anchors-8b6a3ac1b027
|
||||
|
||||
_ios: &_ios
|
||||
os: osx
|
||||
osx_image: xcode10.2
|
||||
osx_image: xcode10.3
|
||||
|
||||
_android: &_android
|
||||
language: android
|
||||
@@ -35,9 +35,9 @@ _android: &_android
|
||||
- build-tools-$ANDROID_BUILD_TOOLS_VERSION
|
||||
- android-$ANDROID_API_LEVEL
|
||||
licenses:
|
||||
- 'android-sdk-preview-license-.+'
|
||||
- 'android-sdk-license-.+'
|
||||
- 'google-gdk-license-.+'
|
||||
- "android-sdk-preview-license-.+"
|
||||
- "android-sdk-license-.+"
|
||||
- "google-gdk-license-.+"
|
||||
|
||||
matrix:
|
||||
include:
|
||||
@@ -75,13 +75,13 @@ matrix:
|
||||
|
||||
before_install:
|
||||
# manually install Node for `language: android`
|
||||
- if [[ "$PLATFORM" =~ android ]]; then nvm install $TRAVIS_NODE_VERSION; fi
|
||||
- if [[ "$PLATFORM" =~ android ]]; then nvm install $TRAVIS_NODE_VERSION; fi
|
||||
- node --version
|
||||
- if [[ "$PLATFORM" =~ android ]]; then gradle --version; fi
|
||||
- if [[ "$PLATFORM" =~ ios ]]; then npm install -g ios-deploy; fi
|
||||
- npm install -g cordova
|
||||
# install paramedic if not running on paramedic repo
|
||||
- if ! [[ "$TRAVIS_REPO_SLUG" =~ cordova-paramedic ]]; then npm install -g github:apache/cordova-paramedic; fi
|
||||
- if ! [[ "$TRAVIS_REPO_SLUG" =~ cordova-paramedic ]]; then npm install -g github:apache/cordova-paramedic; fi
|
||||
|
||||
install:
|
||||
- npm install
|
||||
@@ -110,8 +110,9 @@ before_script:
|
||||
echo "PARAMEDIC_BUILDNAME=$PARAMEDIC_BUILDNAME"
|
||||
script:
|
||||
- $TEST_COMMAND
|
||||
- if [[ "$ADDITIONAL_TESTS_DIR" != "" ]]; then
|
||||
- |
|
||||
if [[ "$ADDITIONAL_TESTS_DIR" != "" ]]; then
|
||||
cd $ADDITIONAL_TESTS_DIR && npm install && npm test;
|
||||
else
|
||||
$PARAMEDIC_COMMAND --config ./pr/$PLATFORM --plugin $PARAMEDIC_PLUGIN_TO_TEST --buildName $PARAMEDIC_BUILDNAME;
|
||||
else
|
||||
$PARAMEDIC_COMMAND --config ./pr/$PLATFORM --plugin $PARAMEDIC_PLUGIN_TO_TEST --buildName $PARAMEDIC_BUILDNAME;
|
||||
fi
|
||||
|
||||
@@ -25,40 +25,13 @@ Anyone can contribute to Cordova. And we need your contributions.
|
||||
|
||||
There are multiple ways to contribute: report bugs, improve the docs, and
|
||||
contribute code.
|
||||
|
||||
|
||||
For instructions on this, start with the
|
||||
[contribution overview](http://cordova.apache.org/contribute/).
|
||||
|
||||
The details are explained there, but the important items are:
|
||||
- Sign and submit an Apache ICLA (Contributor License Agreement).
|
||||
- Have a Jira issue open that corresponds to your contribution.
|
||||
- Check for Github issues that corresponds to your contribution and link or create them if necessary.
|
||||
- Run the tests so your patch doesn't break existing functionality.
|
||||
|
||||
We look forward to your contributions!
|
||||
|
||||
The notes on [Commit Workflow](https://github.com/apache/cordova-coho/blob/master/docs/committer-workflow.md#commit-workflow) can be helpful even if you are not a committer.
|
||||
|
||||
## Running plugin tests
|
||||
|
||||
* clone and install [cordova-plugin-test-framework](https://github.com/apache/cordova-plugin-test-framework)
|
||||
```
|
||||
git clone git@github.com:apache/cordova-plugin-test-framework.git
|
||||
```
|
||||
* edit ```cordova-plugin-test-framework/www/assets/index.html``` and add the following line
|
||||
```
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com http://cordova.apache.org http://google.co.uk https://google.co.uk 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
|
||||
```
|
||||
* create test project
|
||||
```
|
||||
cordova create plugintest
|
||||
cd plugintest
|
||||
cordova platform add android
|
||||
cordova plugin add ../cordova-plugin-inappbrowser
|
||||
cordova plugin add ../cordova-plugin-inappbrowser/tests
|
||||
cordova plugin add ../cordova-plugin-test-framework
|
||||
```
|
||||
* edit ```config.xml``` and replace ```<content src="index.html" />``` with ```<content src="cdvtests/index.html" />```
|
||||
* run application
|
||||
```
|
||||
cordova run
|
||||
```
|
||||
|
||||
38
README.md
38
README.md
@@ -43,6 +43,10 @@ InAppBrowser window, by replacing window.open:
|
||||
|
||||
window.open = cordova.InAppBrowser.open;
|
||||
|
||||
If you change the browsers `window.open` function this way, it can have unintended side
|
||||
effects (especially if this plugin is included only as a dependency of another
|
||||
plugin).
|
||||
|
||||
The InAppBrowser window behaves like a standard web browser,
|
||||
and can't access Cordova APIs. For this reason, the InAppBrowser is recommended
|
||||
if you need to load third-party (untrusted) content, instead of loading that
|
||||
@@ -52,22 +56,6 @@ whitelist, nor is opening links in the system browser.
|
||||
The InAppBrowser provides by default its own GUI controls for the user (back,
|
||||
forward, done).
|
||||
|
||||
For backwards compatibility, this plugin also hooks `window.open`.
|
||||
However, the plugin-installed hook of `window.open` can have unintended side
|
||||
effects (especially if this plugin is included only as a dependency of another
|
||||
plugin). The hook of `window.open` will be removed in a future major release.
|
||||
Until the hook is removed from the plugin, apps can manually restore the default
|
||||
behaviour:
|
||||
|
||||
delete window.open // Reverts the call back to its prototype's default
|
||||
|
||||
Although `window.open` is in the global scope, InAppBrowser is not available until after the `deviceready` event.
|
||||
|
||||
document.addEventListener("deviceready", onDeviceReady, false);
|
||||
function onDeviceReady() {
|
||||
console.log("window.open works well");
|
||||
}
|
||||
|
||||
## Installation
|
||||
|
||||
cordova plugin add cordova-plugin-inappbrowser
|
||||
@@ -123,15 +111,15 @@ instance, or the system browser.
|
||||
- __hideurlbar__: set to `yes` to hide the url bar on the location toolbar, only has effect if user has location set to `yes`. The default value is `no`.
|
||||
- __navigationbuttoncolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the color of both navigation buttons from default. Only has effect if user has location set to `yes` and not hidenavigationbuttons set to `yes`.
|
||||
- __toolbarcolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the color the toolbar from default. Only has effect if user has location set to `yes`.
|
||||
- __lefttoright__: Set to `yes` to swap positions of the navigation buttons and the close button. Specifically, navigation buttons go to the left and close button to the right.
|
||||
- __lefttoright__: Set to `yes` to swap positions of the navigation buttons and the close button. Specifically, navigation buttons go to the right and close button to the left. Default value is `no`.
|
||||
- __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `yes`.
|
||||
- __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`).
|
||||
- __shouldPauseOnSuspend__: Set to `yes` to make InAppBrowser WebView to pause/resume with the app to stop background audio (this may be required to avoid Google Play issues like described in [CB-11013](https://issues.apache.org/jira/browse/CB-11013)).
|
||||
- __useWideViewPort__: Sets whether the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport. When the value of the setting is `no`, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels. When the value is `yes` and the page contains the viewport meta tag, the value of the width specified in the tag is used. If the page does not contain the tag or does not provide a width, then a wide viewport will be used. (defaults to `yes`).
|
||||
- __fullscreen__: Sets whether the InappBrowser WebView is displayed fullscreen or not. In fullscreen mode, the status bar is hidden. Default value is `yes`.
|
||||
|
||||
iOS supports these additional options:
|
||||
|
||||
- __usewkwebview__: set to `yes` to use WKWebView engine for the InappBrowser. Omit or set to `no` (default) to use UIWebView. Note: Using `usewkwebview=yes` requires that a WKWebView engine plugin be installed in the Cordova project (e.g. [cordova-plugin-wkwebview-engine](https://github.com/apache/cordova-plugin-wkwebview-engine) or [cordova-plugin-ionic-webview](https://github.com/ionic-team/cordova-plugin-ionic-webview)).
|
||||
- __hidden__: set to `yes` to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to `no` (default) to have the browser open and load normally.
|
||||
- __beforeload__: set to enable the `beforeload` event to modify which pages are actually loaded in the browser. Accepted values are `get` to intercept only GET requests, `post` to intercept on POST requests or `yes` to intercept both GET & POST requests. Note that POST requests are not currently supported and will be ignored (if you set `beforeload=post` it will raise an error).
|
||||
- __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened
|
||||
@@ -139,20 +127,18 @@ instance, or the system browser.
|
||||
- __cleardata__: set to `yes` to have the browser's entire local storage cleared (cookies, HTML5 local storage, IndexedDB, etc.) before the new window is opened
|
||||
- __closebuttoncolor__: set as a valid hex color string, for example: `#00ff00`, to change from the default __Done__ button's color. Only applicable if toolbar is not disabled.
|
||||
- __closebuttoncaption__: set to a string to use as the __Done__ button's caption. Note that you need to localize this value yourself.
|
||||
- __disallowoverscroll__: Set to `yes` or `no` (default is `no`). Turns on/off the UIWebViewBounce property.
|
||||
- __disallowoverscroll__: Set to `yes` or `no` (default is `no`). Turns on/off the the bounce of the WKWebView's UIScrollView.
|
||||
- __hidenavigationbuttons__: set to `yes` or `no` to turn the toolbar navigation buttons on or off (defaults to `no`). Only applicable if toolbar is not disabled.
|
||||
- __navigationbuttoncolor__: set as a valid hex color string, for example: `#00ff00`, to change from the default color. Only applicable if navigation buttons are visible.
|
||||
- __toolbar__: set to `yes` or `no` to turn the toolbar on or off for the InAppBrowser (defaults to `yes`)
|
||||
- __toolbarcolor__: set as a valid hex color string, for example: `#00ff00`, to change from the default color of the toolbar. Only applicable if toolbar is not disabled.
|
||||
- __toolbartranslucent__: set to `yes` or `no` to make the toolbar translucent(semi-transparent) (defaults to `yes`). Only applicable if toolbar is not disabled.
|
||||
- __lefttoright__: Set to `yes` to swap positions of the navigation buttons and the close button. Specifically, close button goes to the right and navigation buttons to the left.
|
||||
- __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`). Only applicable to UIWebView (`usewkwebview=no`) and WKWebView (`usewkwebview=yes`) on iOS 10+.
|
||||
- __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`). Applicable to UIWebView (`usewkwebview=no`) and WKWebView (`usewkwebview=yes`).
|
||||
- __allowInlineMediaPlayback__: Set to `yes` or `no` to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. The HTML's `video` element must also include the `webkit-playsinline` attribute (defaults to `no`). Applicable to UIWebView (`usewkwebview=no`) and WKWebView (`usewkwebview=yes`).
|
||||
- __keyboardDisplayRequiresUserAction__: Set to `yes` or `no` to open the keyboard when form elements receive focus via JavaScript's `focus()` call (defaults to `yes`). Only applicable to UIWebView (`usewkwebview=no`).
|
||||
- __suppressesIncrementalRendering__: Set to `yes` or `no` to wait until all new view content is received before being rendered (defaults to `no`). Only applicable to UIWebView (`usewkwebview=no`).
|
||||
- __presentationstyle__: Set to `pagesheet`, `formsheet` or `fullscreen` to set the [presentation style](http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle) (defaults to `fullscreen`).
|
||||
- __transitionstyle__: Set to `fliphorizontal`, `crossdissolve` or `coververtical` to set the [transition style](http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalTransitionStyle) (defaults to `coververtical`).
|
||||
- __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`).
|
||||
- __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`).
|
||||
- __allowInlineMediaPlayback__: Set to `yes` or `no` to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. The HTML's `video` element must also include the `webkit-playsinline` attribute (defaults to `no`).
|
||||
- __presentationstyle__: Set to `pagesheet`, `formsheet` or `fullscreen` to set the [presentation style](https://developer.apple.com/documentation/uikit/uimodalpresentationstyle) (defaults to `fullscreen`).
|
||||
- __transitionstyle__: Set to `fliphorizontal`, `crossdissolve` or `coververtical` to set the [transition style](https://developer.apple.com/documentation/uikit/uimodaltransitionstyle) (defaults to `coververtical`).
|
||||
- __toolbarposition__: Set to `top` or `bottom` (default is `bottom`). Causes the toolbar to be at the top or bottom of the window.
|
||||
- __hidespinner__: Set to `yes` or `no` to change the visibility of the loading indicator (defaults to `no`).
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cordova-plugin-inappbrowser",
|
||||
"version": "3.2.0",
|
||||
"version": "4.0.0-dev",
|
||||
"description": "Cordova InAppBrowser Plugin",
|
||||
"types": "./types/index.d.ts",
|
||||
"cordova": {
|
||||
|
||||
20
plugin.xml
20
plugin.xml
@@ -20,7 +20,7 @@
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
id="cordova-plugin-inappbrowser"
|
||||
version="3.2.0">
|
||||
version="4.0.0-dev">
|
||||
|
||||
<name>InAppBrowser</name>
|
||||
<description>Cordova InAppBrowser Plugin</description>
|
||||
@@ -37,7 +37,6 @@
|
||||
<platform name="android">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<clobbers target="cordova.InAppBrowser.open" />
|
||||
<clobbers target="window.open" />
|
||||
</js-module>
|
||||
<config-file target="res/xml/config.xml" parent="/*">
|
||||
<feature name="InAppBrowser">
|
||||
@@ -71,31 +70,17 @@
|
||||
<platform name="ios">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<clobbers target="cordova.InAppBrowser.open" />
|
||||
<clobbers target="window.open" />
|
||||
</js-module>
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="InAppBrowser">
|
||||
<param name="ios-package" value="CDVInAppBrowser" />
|
||||
<param name="onload" value="true" />
|
||||
</feature>
|
||||
<feature name="UIInAppBrowser">
|
||||
<param name="ios-package" value="CDVUIInAppBrowser" />
|
||||
<param name="onload" value="true" />
|
||||
</feature>
|
||||
<feature name="WKInAppBrowser">
|
||||
<param name="ios-package" value="CDVWKInAppBrowser" />
|
||||
<param name="onload" value="true" />
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<header-file src="src/ios/CDVInAppBrowser.h" />
|
||||
<source-file src="src/ios/CDVInAppBrowser.m" />
|
||||
<header-file src="src/ios/CDVInAppBrowserOptions.h" />
|
||||
<source-file src="src/ios/CDVInAppBrowserOptions.m" />
|
||||
<header-file src="src/ios/CDVInAppBrowserNavigationController.h" />
|
||||
<source-file src="src/ios/CDVInAppBrowserNavigationController.m" />
|
||||
<header-file src="src/ios/CDVUIInAppBrowser.h" />
|
||||
<source-file src="src/ios/CDVUIInAppBrowser.m" />
|
||||
<header-file src="src/ios/CDVWKInAppBrowser.h" />
|
||||
<source-file src="src/ios/CDVWKInAppBrowser.m" />
|
||||
<header-file src="src/ios/CDVWKInAppBrowserUIDelegate.h" />
|
||||
@@ -108,7 +93,6 @@
|
||||
<platform name="osx">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<clobbers target="cordova.InAppBrowser.open" />
|
||||
<clobbers target="window.open" />
|
||||
</js-module>
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="InAppBrowser">
|
||||
@@ -124,7 +108,6 @@
|
||||
<platform name="windows">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<clobbers target="cordova.InAppBrowser.open" />
|
||||
<clobbers target="window.open" />
|
||||
</js-module>
|
||||
<js-module src="src/windows/InAppBrowserProxy.js" name="InAppBrowserProxy">
|
||||
<runs />
|
||||
@@ -136,7 +119,6 @@
|
||||
<platform name="browser">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<clobbers target="cordova.InAppBrowser.open" />
|
||||
<clobbers target="window.open" />
|
||||
</js-module>
|
||||
<js-module src="src/browser/InAppBrowserProxy.js" name="InAppBrowserProxy">
|
||||
<runs />
|
||||
|
||||
@@ -37,6 +37,7 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
@@ -57,6 +58,7 @@ import android.webkit.WebResourceResponse;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
@@ -117,8 +119,15 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
private static final String FOOTER = "footer";
|
||||
private static final String FOOTER_COLOR = "footercolor";
|
||||
private static final String BEFORELOAD = "beforeload";
|
||||
private static final String FULLSCREEN = "fullscreen";
|
||||
private static final String STATUSBAR = "statusbar";
|
||||
private static final String TITLEBAR = "titlebar";
|
||||
private static final String COLOR = "color";
|
||||
private static final String BACKGROUND = "background";
|
||||
private static final String BACKBUTTON = "backbutton";
|
||||
private static final String CANHARDWAREBACK = "canhardwareback";
|
||||
|
||||
private static final List customizableOptions = Arrays.asList(CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR, FOOTER_COLOR);
|
||||
private static final List customizableOptions = Arrays.asList(CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR, FOOTER_COLOR,BACKGROUND,COLOR);
|
||||
|
||||
private InAppBrowserDialog dialog;
|
||||
private WebView inAppWebView;
|
||||
@@ -147,6 +156,16 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
private boolean showFooter = false;
|
||||
private String footerColor = "";
|
||||
private String beforeload = "";
|
||||
private boolean fullscreen = true;
|
||||
// 是否显示状态栏
|
||||
private boolean statusbar = true;
|
||||
// 标题栏
|
||||
private boolean titlebar = false;
|
||||
// 物理返回键是否生效
|
||||
private boolean canhardwareback = true;
|
||||
private String color = "";
|
||||
private String background = "";
|
||||
private boolean backbutton = true;
|
||||
private String[] allowedSchemes;
|
||||
private InAppBrowserClient currentClient;
|
||||
|
||||
@@ -313,7 +332,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
this.cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (dialog != null) {
|
||||
if (dialog != null && !cordova.getActivity().isFinishing()) {
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
@@ -326,7 +345,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
this.cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (dialog != null) {
|
||||
if (dialog != null && !cordova.getActivity().isFinishing()) {
|
||||
dialog.hide();
|
||||
}
|
||||
}
|
||||
@@ -335,6 +354,16 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
pluginResult.setKeepCallback(true);
|
||||
this.callbackContext.sendPluginResult(pluginResult);
|
||||
}
|
||||
else if(action.equals("back")){
|
||||
this.cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
public void run() {
|
||||
goBack();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
@@ -537,7 +566,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
childView.setWebViewClient(new WebViewClient() {
|
||||
// NB: wait for about:blank before dismissing
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
if (dialog != null) {
|
||||
if (dialog != null && !cordova.getActivity().isFinishing()) {
|
||||
dialog.dismiss();
|
||||
dialog = null;
|
||||
}
|
||||
@@ -565,6 +594,8 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
public void goBack() {
|
||||
if (this.inAppWebView.canGoBack()) {
|
||||
this.inAppWebView.goBack();
|
||||
} else {
|
||||
closeDialog();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -692,9 +723,8 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
closeButtonColor = closeButtonColorSet;
|
||||
}
|
||||
String leftToRightSet = features.get(LEFT_TO_RIGHT);
|
||||
if (leftToRightSet != null) {
|
||||
leftToRight = leftToRightSet.equals("yes") ? true : false;
|
||||
}
|
||||
leftToRight = leftToRightSet != null && leftToRightSet.equals("yes");
|
||||
|
||||
String toolbarColorSet = features.get(TOOLBAR_COLOR);
|
||||
if (toolbarColorSet != null) {
|
||||
toolbarColor = android.graphics.Color.parseColor(toolbarColorSet);
|
||||
@@ -714,6 +744,32 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
if (features.get(BEFORELOAD) != null) {
|
||||
beforeload = features.get(BEFORELOAD);
|
||||
}
|
||||
String fullscreenSet = features.get(FULLSCREEN);
|
||||
if (fullscreenSet != null) {
|
||||
fullscreen = fullscreenSet.equals("yes") ? true : false;
|
||||
}
|
||||
String statusbarSet = features.get(STATUSBAR);
|
||||
if (statusbarSet != null) {
|
||||
statusbar = statusbarSet.equals("yes") ? true : false;
|
||||
}
|
||||
String titlebarSet = features.get(TITLEBAR);
|
||||
if (titlebarSet != null) {
|
||||
titlebar = titlebarSet.equals("yes");
|
||||
}
|
||||
String backbuttonSet = features.get(BACKBUTTON);
|
||||
if (backbuttonSet != null) {
|
||||
backbutton = backbuttonSet.equals("yes");
|
||||
}
|
||||
String canhardwarebackSet = features.get(CANHARDWAREBACK);
|
||||
if (canhardwarebackSet != null) {
|
||||
canhardwareback = canhardwarebackSet.equals("yes");
|
||||
}
|
||||
if (features.get(COLOR) != null) {
|
||||
color = features.get(COLOR);
|
||||
}
|
||||
if (features.get(BACKGROUND) != null) {
|
||||
background = features.get(BACKGROUND);
|
||||
}
|
||||
}
|
||||
|
||||
final CordovaWebView thatWebView = this.webView;
|
||||
@@ -782,6 +838,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
return _close;
|
||||
}
|
||||
|
||||
TextView titleTitle = new TextView(cordova.getActivity());
|
||||
@SuppressLint("NewApi")
|
||||
public void run() {
|
||||
|
||||
@@ -791,10 +848,25 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
};
|
||||
|
||||
// Let's create the main dialog
|
||||
dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
|
||||
dialog = new InAppBrowserDialog(cordova.getActivity(),fullscreen ? android.R.style.Theme_NoTitleBar : android.R.style.Theme_Black, canhardwareback);
|
||||
dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
if (fullscreen) {
|
||||
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
}
|
||||
else if (statusbar && !titlebar) {
|
||||
// do something
|
||||
}
|
||||
else {
|
||||
// dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
dialog.getWindow().addFlags(WindowManager.LayoutParams
|
||||
.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
dialog.getWindow().setStatusBarColor(Color.TRANSPARENT);
|
||||
dialog.getWindow().setNavigationBarColor(Color.TRANSPARENT);
|
||||
}
|
||||
}
|
||||
dialog.setCancelable(true);
|
||||
dialog.setInAppBroswer(getInAppBrowser());
|
||||
|
||||
@@ -973,6 +1045,11 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
cordova.startActivityForResult(InAppBrowser.this, Intent.createChooser(content, "Select File"), FILECHOOSER_REQUESTCODE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivedTitle(WebView view, String title) {
|
||||
super.onReceivedTitle(view, title);
|
||||
titleTitle.setText(title);
|
||||
}
|
||||
});
|
||||
currentClient = new InAppBrowserClient(thatWebView, edittext, beforeload);
|
||||
inAppWebView.setWebViewClient(currentClient);
|
||||
@@ -1054,6 +1131,97 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
main.addView(toolbar);
|
||||
}
|
||||
|
||||
// titleBar 开始
|
||||
RelativeLayout titleBar = new RelativeLayout(cordova.getActivity());
|
||||
int statusBarHeight1 = 0;
|
||||
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
//获取status_bar_height资源的ID
|
||||
int resourceId = cordova.getActivity().getResources().getIdentifier("status_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
//根据资源ID获取响应的尺寸值
|
||||
statusBarHeight1 = cordova.getActivity().getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
}
|
||||
int backgroundColor = Color.WHITE;
|
||||
int fontColor = Color.BLACK;
|
||||
if(!"".equals(background)){
|
||||
backgroundColor = Color.parseColor(background);
|
||||
}
|
||||
if(!"".equals(color)){
|
||||
fontColor = Color.parseColor(color);
|
||||
}
|
||||
titleBar.setBackgroundColor(backgroundColor);
|
||||
titleBar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)+statusBarHeight1));
|
||||
titleBar.setPadding(this.dpToPixels(2), this.dpToPixels(2)+statusBarHeight1, this.dpToPixels(2), this.dpToPixels(2));
|
||||
|
||||
|
||||
RelativeLayout.LayoutParams titleTitleLayoutParams = new RelativeLayout.LayoutParams(
|
||||
titleBar.getWidth() - this.dpToPixels(128), LayoutParams.WRAP_CONTENT);
|
||||
titleTitleLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
|
||||
titleTitleLayoutParams.addRule(RelativeLayout.TEXT_ALIGNMENT_CENTER);
|
||||
titleTitle.setPadding(this.dpToPixels(64),this.dpToPixels(20),this.dpToPixels(64),0);
|
||||
titleTitle.setText("加载中...");
|
||||
titleTitle.setText(inAppWebView.getTitle());
|
||||
titleTitle.setEllipsize(TextUtils.TruncateAt.END);
|
||||
titleTitle.setSingleLine(true);
|
||||
titleTitle.setTextColor(fontColor);
|
||||
titleTitle.setTextSize(18);
|
||||
titleTitle.setBackgroundColor(backgroundColor);
|
||||
titleTitle.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||
titleTitle.setGravity(Gravity.CENTER);
|
||||
titleBar.addView(titleTitle,titleTitleLayoutParams);
|
||||
|
||||
TextView titleBack = new TextView(cordova.getActivity());
|
||||
RelativeLayout.LayoutParams titleBackLayoutParams = new RelativeLayout.LayoutParams(
|
||||
this.dpToPixels(44), this.dpToPixels(32));
|
||||
titleBackLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
|
||||
titleBack.setPadding(this.dpToPixels(10), 0,
|
||||
this.dpToPixels(10),0);
|
||||
titleBack.setText("❮");
|
||||
titleBack.setTextSize(20);
|
||||
titleBack.setTextColor(fontColor);
|
||||
titleBack.setGravity(Gravity.CENTER);
|
||||
titleBack.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||
titleBack.setBackgroundColor(backgroundColor);
|
||||
|
||||
titleBack.setLayoutParams(titleBackLayoutParams);
|
||||
titleBack.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
goBack();
|
||||
}
|
||||
});
|
||||
if(backbutton) {
|
||||
titleBar.addView(titleBack, backLayoutParams);
|
||||
}
|
||||
|
||||
TextView titleClose = new TextView(cordova.getActivity());
|
||||
RelativeLayout.LayoutParams titleCloseLayoutParams = new RelativeLayout.LayoutParams(
|
||||
this.dpToPixels(44), this.dpToPixels(32));
|
||||
titleCloseLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
titleClose.setPadding(this.dpToPixels(10), this.dpToPixels(5),
|
||||
this.dpToPixels(10),0);
|
||||
titleClose.setText("⊗");
|
||||
titleClose.setTextSize(23);
|
||||
titleClose.setTextColor(fontColor);
|
||||
titleClose.setBackgroundColor(backgroundColor);
|
||||
titleClose.setGravity(Gravity.CENTER);
|
||||
titleClose.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
||||
titleClose.setLayoutParams(titleBackLayoutParams);
|
||||
titleClose.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
closeDialog();
|
||||
}
|
||||
});
|
||||
titleBar.addView(titleClose,titleCloseLayoutParams);
|
||||
|
||||
// Don't add the title bar if its been disabled
|
||||
if (titlebar) {
|
||||
// Add our title bar to our main view/layout
|
||||
main.addView(titleBar);
|
||||
}
|
||||
// titleBar 结束
|
||||
|
||||
|
||||
// Add our webview to our main view/layout
|
||||
RelativeLayout webViewLayout = new RelativeLayout(cordova.getActivity());
|
||||
webViewLayout.addView(inAppWebView);
|
||||
@@ -1362,7 +1530,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
* New (added in API 21)
|
||||
* For Android 5.0 and above.
|
||||
*
|
||||
* @param webView
|
||||
* @param view
|
||||
* @param request
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
|
||||
@@ -31,10 +31,12 @@ import org.json.JSONObject;
|
||||
public class InAppBrowserDialog extends Dialog {
|
||||
Context context;
|
||||
InAppBrowser inAppBrowser = null;
|
||||
boolean canHardwareBack = true;
|
||||
|
||||
public InAppBrowserDialog(Context context, int theme) {
|
||||
public InAppBrowserDialog(Context context, int theme, boolean canHardwareBack) {
|
||||
super(context, theme);
|
||||
this.context = context;
|
||||
this.canHardwareBack = canHardwareBack;
|
||||
}
|
||||
|
||||
public void setInAppBroswer(InAppBrowser browser) {
|
||||
@@ -42,16 +44,19 @@ public class InAppBrowserDialog extends Dialog {
|
||||
}
|
||||
|
||||
public void onBackPressed () {
|
||||
if (this.inAppBrowser == null) {
|
||||
this.dismiss();
|
||||
} else {
|
||||
// better to go through the in inAppBrowser
|
||||
// because it does a clean up
|
||||
if (this.inAppBrowser.hardwareBack() && this.inAppBrowser.canGoBack()) {
|
||||
this.inAppBrowser.goBack();
|
||||
} else {
|
||||
this.inAppBrowser.closeDialog();
|
||||
if (canHardwareBack){
|
||||
if (this.inAppBrowser == null) {
|
||||
this.dismiss();
|
||||
} else {
|
||||
// better to go through the in inAppBrowser
|
||||
// because it does a clean up
|
||||
if (this.inAppBrowser.hardwareBack() && this.inAppBrowser.canGoBack()) {
|
||||
this.inAppBrowser.goBack();
|
||||
} else {
|
||||
this.inAppBrowser.closeDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
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 <Cordova/CDVPlugin.h>
|
||||
#import <Cordova/CDVInvokedUrlCommand.h>
|
||||
|
||||
@interface CDVInAppBrowser : CDVPlugin {}
|
||||
|
||||
@property (nonatomic, assign) BOOL wkwebviewavailable;
|
||||
@property (nonatomic, assign) BOOL usewkwebview;
|
||||
|
||||
- (void)open:(CDVInvokedUrlCommand*)command;
|
||||
- (void)close:(CDVInvokedUrlCommand*)command;
|
||||
- (void)injectScriptCode:(CDVInvokedUrlCommand*)command;
|
||||
- (void)show:(CDVInvokedUrlCommand*)command;
|
||||
- (void)hide:(CDVInvokedUrlCommand*)command;
|
||||
- (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
@end
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
/*
|
||||
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"
|
||||
#import "CDVInAppBrowserOptions.h"
|
||||
#if !WK_WEB_VIEW_ONLY
|
||||
#import "CDVUIInAppBrowser.h"
|
||||
#endif
|
||||
#import "CDVWKInAppBrowser.h"
|
||||
#import <Cordova/CDVPluginResult.h>
|
||||
|
||||
|
||||
#pragma mark CDVInAppBrowser
|
||||
|
||||
@implementation CDVInAppBrowser
|
||||
|
||||
- (void)pluginInitialize
|
||||
{
|
||||
// default values
|
||||
self.usewkwebview = NO;
|
||||
|
||||
#if __has_include("CDVWKWebViewEngine.h")
|
||||
self.wkwebviewavailable = YES;
|
||||
#else
|
||||
self.wkwebviewavailable = NO;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)open:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
NSString* options = [command argumentAtIndex:2 withDefault:@"" andClass:[NSString class]];
|
||||
CDVInAppBrowserOptions* browserOptions = [CDVInAppBrowserOptions parseOptions:options];
|
||||
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];
|
||||
return;
|
||||
}
|
||||
self.usewkwebview = browserOptions.usewkwebview;
|
||||
#if WK_WEB_VIEW_ONLY
|
||||
[[CDVWKInAppBrowser getInstance] open:command];
|
||||
#else
|
||||
if(self.usewkwebview){
|
||||
[[CDVWKInAppBrowser getInstance] open:command];
|
||||
}else{
|
||||
[[CDVUIInAppBrowser getInstance] open:command];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)close:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
#if WK_WEB_VIEW_ONLY
|
||||
[[CDVWKInAppBrowser getInstance] close:command];
|
||||
#else
|
||||
if(self.usewkwebview){
|
||||
[[CDVWKInAppBrowser getInstance] close:command];
|
||||
}else{
|
||||
[[CDVUIInAppBrowser getInstance] close:command];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
- (void)show:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
#if WK_WEB_VIEW_ONLY
|
||||
[[CDVWKInAppBrowser getInstance] show:command];
|
||||
#else
|
||||
if(self.usewkwebview){
|
||||
[[CDVWKInAppBrowser getInstance] show:command];
|
||||
}else{
|
||||
[[CDVUIInAppBrowser getInstance] show:command];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)hide:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
#if WK_WEB_VIEW_ONLY
|
||||
[[CDVWKInAppBrowser getInstance] hide:command];
|
||||
#else
|
||||
if(self.usewkwebview){
|
||||
[[CDVWKInAppBrowser getInstance] hide:command];
|
||||
}else{
|
||||
[[CDVUIInAppBrowser getInstance] hide:command];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
- (void)injectScriptCode:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
#if WK_WEB_VIEW_ONLY
|
||||
[[CDVWKInAppBrowser getInstance] injectScriptCode:command];
|
||||
#else
|
||||
if(self.usewkwebview){
|
||||
[[CDVWKInAppBrowser getInstance] injectScriptCode:command];
|
||||
}else{
|
||||
[[CDVUIInAppBrowser getInstance] injectScriptCode:command];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)injectScriptFile:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
#if WK_WEB_VIEW_ONLY
|
||||
[[CDVWKInAppBrowser getInstance] injectScriptFile:command];
|
||||
#else
|
||||
if(self.usewkwebview){
|
||||
[[CDVWKInAppBrowser getInstance] injectScriptFile:command];
|
||||
}else{
|
||||
[[CDVUIInAppBrowser getInstance] injectScriptFile:command];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)injectStyleCode:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
#if WK_WEB_VIEW_ONLY
|
||||
[[CDVWKInAppBrowser getInstance] injectStyleCode:command];
|
||||
#else
|
||||
if(self.usewkwebview){
|
||||
[[CDVWKInAppBrowser getInstance] injectStyleCode:command];
|
||||
}else{
|
||||
[[CDVUIInAppBrowser getInstance] injectStyleCode:command];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)injectStyleFile:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
#if WK_WEB_VIEW_ONLY
|
||||
[[CDVWKInAppBrowser getInstance] injectStyleFile:command];
|
||||
#else
|
||||
if(self.usewkwebview){
|
||||
[[CDVWKInAppBrowser getInstance] injectStyleFile:command];
|
||||
}else{
|
||||
[[CDVUIInAppBrowser getInstance] injectStyleFile:command];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
#if WK_WEB_VIEW_ONLY
|
||||
[[CDVWKInAppBrowser getInstance] loadAfterBeforeload:command];
|
||||
#else
|
||||
if(self.usewkwebview){
|
||||
[[CDVWKInAppBrowser getInstance] loadAfterBeforeload:command];
|
||||
}else{
|
||||
[[CDVUIInAppBrowser getInstance] loadAfterBeforeload:command];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -63,7 +63,7 @@
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSUInteger)supportedInterfaceOrientations
|
||||
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
|
||||
{
|
||||
if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(supportedInterfaceOrientations)]) {
|
||||
return [self.orientationDelegate supportedInterfaceOrientations];
|
||||
@@ -72,14 +72,4 @@
|
||||
return 1 << UIInterfaceOrientationPortrait;
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
||||
{
|
||||
if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)]) {
|
||||
return [self.orientationDelegate shouldAutorotateToInterfaceOrientation:interfaceOrientation];
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -20,8 +20,12 @@
|
||||
|
||||
@interface CDVInAppBrowserOptions : NSObject {}
|
||||
|
||||
@property (nonatomic, assign) BOOL usewkwebview;
|
||||
@property (nonatomic, assign) BOOL location;
|
||||
@property (nonatomic, assign) BOOL statusbar;
|
||||
@property (nonatomic, assign) BOOL titlebar;
|
||||
@property (nonatomic, copy) NSString* color;
|
||||
@property (nonatomic, copy) NSString* background;
|
||||
@property (nonatomic, assign) BOOL backbutton;
|
||||
@property (nonatomic, assign) BOOL toolbar;
|
||||
@property (nonatomic, copy) NSString* closebuttoncaption;
|
||||
@property (nonatomic, copy) NSString* closebuttoncolor;
|
||||
@@ -42,8 +46,6 @@
|
||||
@property (nonatomic, assign) BOOL enableviewportscale;
|
||||
@property (nonatomic, assign) BOOL mediaplaybackrequiresuseraction;
|
||||
@property (nonatomic, assign) BOOL allowinlinemediaplayback;
|
||||
@property (nonatomic, assign) BOOL keyboarddisplayrequiresuseraction;
|
||||
@property (nonatomic, assign) BOOL suppressesincrementalrendering;
|
||||
@property (nonatomic, assign) BOOL hidden;
|
||||
@property (nonatomic, assign) BOOL disallowoverscroll;
|
||||
@property (nonatomic, copy) NSString* beforeload;
|
||||
|
||||
@@ -25,9 +25,12 @@
|
||||
{
|
||||
if (self = [super init]) {
|
||||
// default values
|
||||
self.usewkwebview = NO;
|
||||
self.location = YES;
|
||||
self.toolbar = YES;
|
||||
self.titlebar = NO;
|
||||
self.backbutton= YES;
|
||||
self.color = nil;
|
||||
self.background = nil;
|
||||
self.closebuttoncaption = nil;
|
||||
self.toolbarposition = @"bottom";
|
||||
self.cleardata = NO;
|
||||
@@ -38,8 +41,6 @@
|
||||
self.enableviewportscale = NO;
|
||||
self.mediaplaybackrequiresuseraction = NO;
|
||||
self.allowinlinemediaplayback = NO;
|
||||
self.keyboarddisplayrequiresuseraction = YES;
|
||||
self.suppressesincrementalrendering = NO;
|
||||
self.hidden = NO;
|
||||
self.disallowoverscroll = NO;
|
||||
self.hidenavigationbuttons = NO;
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#if !WK_WEB_VIEW_ONLY
|
||||
|
||||
#import <Cordova/CDVPlugin.h>
|
||||
#import <Cordova/CDVInvokedUrlCommand.h>
|
||||
#import <Cordova/CDVScreenOrientationDelegate.h>
|
||||
#import "CDVInAppBrowserOptions.h"
|
||||
#import "CDVInAppBrowserNavigationController.h"
|
||||
|
||||
#ifdef __CORDOVA_4_0_0
|
||||
#import <Cordova/CDVUIWebViewDelegate.h>
|
||||
#else
|
||||
#import <Cordova/CDVWebViewDelegate.h>
|
||||
#endif
|
||||
|
||||
@class CDVUIInAppBrowserViewController;
|
||||
|
||||
@interface CDVUIInAppBrowser : CDVPlugin {
|
||||
UIWindow * tmpWindow;
|
||||
|
||||
@private
|
||||
NSString* _beforeload;
|
||||
BOOL _waitForBeforeload;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) CDVUIInAppBrowserViewController* inAppBrowserViewController;
|
||||
@property (nonatomic, copy) NSString* callbackId;
|
||||
@property (nonatomic, copy) NSRegularExpression *callbackIdPattern;
|
||||
|
||||
+ (id) getInstance;
|
||||
- (void)open:(CDVInvokedUrlCommand*)command;
|
||||
- (void)close:(CDVInvokedUrlCommand*)command;
|
||||
- (void)injectScriptCode:(CDVInvokedUrlCommand*)command;
|
||||
- (void)show:(CDVInvokedUrlCommand*)command;
|
||||
- (void)hide:(CDVInvokedUrlCommand*)command;
|
||||
- (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
@end
|
||||
|
||||
@interface CDVUIInAppBrowserViewController : UIViewController <UIWebViewDelegate, CDVScreenOrientationDelegate>{
|
||||
@private
|
||||
NSString* _userAgent;
|
||||
NSString* _prevUserAgent;
|
||||
NSInteger _userAgentLockToken;
|
||||
CDVInAppBrowserOptions *_browserOptions;
|
||||
|
||||
#ifdef __CORDOVA_4_0_0
|
||||
CDVUIWebViewDelegate* _webViewDelegate;
|
||||
#else
|
||||
CDVWebViewDelegate* _webViewDelegate;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@property (nonatomic, strong) IBOutlet UIWebView* webView;
|
||||
@property (nonatomic, strong) IBOutlet UIBarButtonItem* closeButton;
|
||||
@property (nonatomic, strong) IBOutlet UILabel* addressLabel;
|
||||
@property (nonatomic, strong) IBOutlet UIBarButtonItem* backButton;
|
||||
@property (nonatomic, strong) IBOutlet UIBarButtonItem* forwardButton;
|
||||
@property (nonatomic, strong) IBOutlet UIActivityIndicatorView* spinner;
|
||||
@property (nonatomic, strong) IBOutlet UIToolbar* toolbar;
|
||||
|
||||
@property (nonatomic, weak) id <CDVScreenOrientationDelegate> orientationDelegate;
|
||||
@property (nonatomic, weak) CDVUIInAppBrowser* navigationDelegate;
|
||||
@property (nonatomic) NSURL* currentURL;
|
||||
|
||||
- (void)close;
|
||||
- (void)navigateTo:(NSURL*)url;
|
||||
- (void)showLocationBar:(BOOL)show;
|
||||
- (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition;
|
||||
- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) buttonIndex;
|
||||
|
||||
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -36,27 +36,32 @@
|
||||
|
||||
@property (nonatomic, retain) CDVWKInAppBrowser* instance;
|
||||
@property (nonatomic, retain) CDVWKInAppBrowserViewController* inAppBrowserViewController;
|
||||
@property (nonatomic, strong) IBOutlet CDVInAppBrowserOptions* browserOptions;
|
||||
@property (nonatomic, copy) NSString* callbackId;
|
||||
@property (nonatomic, copy) NSRegularExpression *callbackIdPattern;
|
||||
|
||||
@property (nonatomic) BOOL* statusbar;
|
||||
|
||||
+ (id) getInstance;
|
||||
- (void)open:(CDVInvokedUrlCommand*)command;
|
||||
- (void)close:(CDVInvokedUrlCommand*)command;
|
||||
- (void)injectScriptCode:(CDVInvokedUrlCommand*)command;
|
||||
- (void)show:(CDVInvokedUrlCommand*)command;
|
||||
- (void)hide:(CDVInvokedUrlCommand*)command;
|
||||
- (void)back:(CDVInvokedUrlCommand*)command;
|
||||
- (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command;
|
||||
- (void)showStatusbar:(BOOL)show;
|
||||
- (int)statusbarHieght;
|
||||
|
||||
@end
|
||||
|
||||
@interface CDVWKInAppBrowserViewController : UIViewController <CDVScreenOrientationDelegate,WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler>{
|
||||
@private
|
||||
NSString* _userAgent;
|
||||
NSString* _prevUserAgent;
|
||||
NSInteger _userAgentLockToken;
|
||||
CDVInAppBrowserOptions *_browserOptions;
|
||||
NSDictionary *_settings;
|
||||
}
|
||||
|
||||
@property (nonatomic, strong) IBOutlet UIViewController* parent;
|
||||
@property (nonatomic, strong) IBOutlet WKWebView* webView;
|
||||
@property (nonatomic, strong) IBOutlet WKWebViewConfiguration* configuration;
|
||||
@property (nonatomic, strong) IBOutlet UIBarButtonItem* closeButton;
|
||||
@@ -65,18 +70,34 @@
|
||||
@property (nonatomic, strong) IBOutlet UIBarButtonItem* forwardButton;
|
||||
@property (nonatomic, strong) IBOutlet UIActivityIndicatorView* spinner;
|
||||
@property (nonatomic, strong) IBOutlet UIToolbar* toolbar;
|
||||
@property (nonatomic, strong) IBOutlet UIView*statusbar;
|
||||
@property (nonatomic, strong) IBOutlet UIView*titlebar;
|
||||
@property (nonatomic, strong) IBOutlet UIButton*titleBackButton;
|
||||
@property (nonatomic, strong) IBOutlet UIButton*titleCloseButton;
|
||||
@property (nonatomic, strong) IBOutlet UILabel*titleTitle;
|
||||
@property (nonatomic, strong) IBOutlet CDVWKInAppBrowserUIDelegate* webViewUIDelegate;
|
||||
|
||||
@property (nonatomic, weak) id <CDVScreenOrientationDelegate> orientationDelegate;
|
||||
@property (nonatomic, weak) CDVWKInAppBrowser* navigationDelegate;
|
||||
@property (nonatomic) NSURL* currentURL;
|
||||
|
||||
@property (nonatomic) BOOL* hasStatusbar;
|
||||
@property (nonatomic) BOOL* hasLocationbar;
|
||||
@property (nonatomic) BOOL* hasToolbar;
|
||||
@property (nonatomic) BOOL* hasTitlebar;
|
||||
|
||||
|
||||
- (void)close;
|
||||
- (void)navigateTo:(NSURL*)url;
|
||||
- (void)showStatusbar:(BOOL)show;
|
||||
- (int)statusbarHieght;
|
||||
- (void)showLocationBar:(BOOL)show;
|
||||
- (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition;
|
||||
- (void)showToolBar:(BOOL)show;
|
||||
- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) buttonIndex;
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context;
|
||||
|
||||
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions;
|
||||
- (id)initWithBrowserOptions: (CDVInAppBrowserOptions*) browserOptions andSettings:(NSDictionary*) settings andParent:(UIViewController*) parent;
|
||||
|
||||
- (void)showTitleBar:(BOOL)show;
|
||||
- (void)resetWebviewSize: (NSString *) toolbarPosition;
|
||||
@end
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#endif
|
||||
|
||||
#import <Cordova/CDVPluginResult.h>
|
||||
#import <Cordova/CDVUserAgentUtil.h>
|
||||
|
||||
#define kInAppBrowserTargetSelf @"_self"
|
||||
#define kInAppBrowserTargetSystem @"_system"
|
||||
@@ -36,10 +35,11 @@
|
||||
#define IAB_BRIDGE_NAME @"cordova_iab"
|
||||
|
||||
#define TOOLBAR_HEIGHT 44.0
|
||||
#define STATUSBAR_HEIGHT 20.0
|
||||
#define LOCATIONBAR_HEIGHT 21.0
|
||||
#define FOOTER_HEIGHT ((TOOLBAR_HEIGHT) + (LOCATIONBAR_HEIGHT))
|
||||
|
||||
#define TITLEBAR_HEIGHT 44.0
|
||||
|
||||
#pragma mark CDVWKInAppBrowser
|
||||
|
||||
@interface CDVWKInAppBrowser () {
|
||||
@@ -64,15 +64,14 @@ static CDVWKInAppBrowser* instance = nil;
|
||||
_waitForBeforeload = NO;
|
||||
}
|
||||
|
||||
- (id)settingForKey:(NSString*)key
|
||||
{
|
||||
return [self.commandDelegate.settings objectForKey:[key lowercaseString]];
|
||||
}
|
||||
|
||||
- (void)onReset
|
||||
{
|
||||
[self close:nil];
|
||||
}
|
||||
- (void)showStatusbar:(BOOL)show
|
||||
{
|
||||
self.statusbar = show;
|
||||
}
|
||||
|
||||
- (void)close:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
@@ -80,7 +79,6 @@ static CDVWKInAppBrowser* instance = nil;
|
||||
NSLog(@"IAB.close() called but it was already closed.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Things are cleaned up in browserExit.
|
||||
[self.inAppBrowserViewController close];
|
||||
}
|
||||
@@ -105,11 +103,7 @@ static CDVWKInAppBrowser* instance = nil;
|
||||
self.callbackId = command.callbackId;
|
||||
|
||||
if (url != nil) {
|
||||
#ifdef __CORDOVA_4_0_0
|
||||
NSURL* baseUrl = [self.webViewEngine URL];
|
||||
#else
|
||||
NSURL* baseUrl = [self.webView.request URL];
|
||||
#endif
|
||||
NSURL* absoluteUrl = [[NSURL URLWithString:url relativeToURL:baseUrl] absoluteURL];
|
||||
|
||||
if ([self isSystemUrl:absoluteUrl]) {
|
||||
@@ -136,7 +130,13 @@ static CDVWKInAppBrowser* instance = nil;
|
||||
- (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options
|
||||
{
|
||||
CDVInAppBrowserOptions* browserOptions = [CDVInAppBrowserOptions parseOptions:options];
|
||||
|
||||
if(browserOptions.titlebar){
|
||||
browserOptions.statusbar = NO;
|
||||
browserOptions.toolbar = NO;
|
||||
browserOptions.location = NO;
|
||||
|
||||
}
|
||||
self.browserOptions = browserOptions;
|
||||
WKWebsiteDataStore* dataStore = [WKWebsiteDataStore defaultDataStore];
|
||||
if (browserOptions.cleardata) {
|
||||
|
||||
@@ -209,16 +209,7 @@ static CDVWKInAppBrowser* instance = nil;
|
||||
}
|
||||
|
||||
if (self.inAppBrowserViewController == nil) {
|
||||
NSString* userAgent = [CDVUserAgentUtil originalUserAgent];
|
||||
NSString* overrideUserAgent = [self settingForKey:@"OverrideUserAgent"];
|
||||
NSString* appendUserAgent = [self settingForKey:@"AppendUserAgent"];
|
||||
if(overrideUserAgent){
|
||||
userAgent = overrideUserAgent;
|
||||
}
|
||||
if(appendUserAgent){
|
||||
userAgent = [userAgent stringByAppendingString: appendUserAgent];
|
||||
}
|
||||
self.inAppBrowserViewController = [[CDVWKInAppBrowserViewController alloc] initWithUserAgent:userAgent prevUserAgent:[self.commandDelegate userAgent] browserOptions: browserOptions];
|
||||
self.inAppBrowserViewController = [[CDVWKInAppBrowserViewController alloc] initWithBrowserOptions: browserOptions andSettings:self.commandDelegate.settings andParent: self.viewController];
|
||||
self.inAppBrowserViewController.navigationDelegate = self;
|
||||
|
||||
if ([self.viewController conformsToProtocol:@protocol(CDVScreenOrientationDelegate)]) {
|
||||
@@ -226,8 +217,12 @@ static CDVWKInAppBrowser* instance = nil;
|
||||
}
|
||||
}
|
||||
|
||||
[self.inAppBrowserViewController showStatusbar:browserOptions.statusbar];
|
||||
[self showStatusbar:browserOptions.statusbar];
|
||||
[self.inAppBrowserViewController showLocationBar:browserOptions.location];
|
||||
[self.inAppBrowserViewController showToolBar:browserOptions.toolbar :browserOptions.toolbarposition];
|
||||
[self.inAppBrowserViewController showToolBar:browserOptions.toolbar ];
|
||||
[self.inAppBrowserViewController showTitleBar:browserOptions.titlebar];
|
||||
[self.inAppBrowserViewController resetWebviewSize:browserOptions.toolbarposition];
|
||||
if (browserOptions.closebuttoncaption != nil || browserOptions.closebuttoncolor != nil) {
|
||||
int closeButtonIndex = browserOptions.lefttoright ? (browserOptions.hidenavigationbuttons ? 1 : 4) : 0;
|
||||
[self.inAppBrowserViewController setCloseButtonTitle:browserOptions.closebuttoncaption :browserOptions.closebuttoncolor :closeButtonIndex];
|
||||
@@ -274,7 +269,6 @@ static CDVWKInAppBrowser* instance = nil;
|
||||
_beforeload = @"yes";
|
||||
}
|
||||
_waitForBeforeload = ![_beforeload isEqualToString:@""];
|
||||
|
||||
[self.inAppBrowserViewController navigateTo:url];
|
||||
if (!browserOptions.hidden) {
|
||||
[self show:nil withNoAnimate:browserOptions.hidden];
|
||||
@@ -316,24 +310,11 @@ static CDVWKInAppBrowser* instance = nil;
|
||||
// Run later to avoid the "took a long time" log message.
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (weakSelf.inAppBrowserViewController != nil) {
|
||||
float osVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
|
||||
__strong __typeof(weakSelf) strongSelf = weakSelf;
|
||||
if (!strongSelf->tmpWindow) {
|
||||
CGRect frame = [[UIScreen mainScreen] bounds];
|
||||
if(initHidden && osVersion < 11){
|
||||
frame.origin.x = -10000;
|
||||
}
|
||||
strongSelf->tmpWindow = [[UIWindow alloc] initWithFrame:frame];
|
||||
}
|
||||
UIViewController *tmpController = [[UIViewController alloc] init];
|
||||
|
||||
[strongSelf->tmpWindow setRootViewController:tmpController];
|
||||
[strongSelf->tmpWindow setWindowLevel:UIWindowLevelNormal];
|
||||
|
||||
if(!initHidden || osVersion < 11){
|
||||
[self->tmpWindow makeKeyAndVisible];
|
||||
}
|
||||
[tmpController presentViewController:nav animated:!noAnimate completion:nil];
|
||||
/* 开始处理遮挡相机插件问题*/
|
||||
self.inAppBrowserViewController.view.frame = CGRectMake(0, 0,
|
||||
self.inAppBrowserViewController.view.frame.size.width,self.inAppBrowserViewController.view.frame.size.height);
|
||||
[self.viewController.view addSubview:self.inAppBrowserViewController.view];
|
||||
/* 结束处理遮挡相机插件问题*/
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -343,6 +324,7 @@ static CDVWKInAppBrowser* instance = nil;
|
||||
// Set tmpWindow to hidden to make main webview responsive to touch again
|
||||
// https://stackoverflow.com/questions/4544489/how-to-remove-a-uiwindow
|
||||
self->tmpWindow.hidden = YES;
|
||||
self->tmpWindow = nil;
|
||||
|
||||
if (self.inAppBrowserViewController == nil) {
|
||||
NSLog(@"Tried to hide IAB after it was closed.");
|
||||
@@ -365,28 +347,30 @@ static CDVWKInAppBrowser* instance = nil;
|
||||
}
|
||||
});
|
||||
}
|
||||
- (void)back:(CDVInvokedUrlCommand *)command
|
||||
{
|
||||
if([self.inAppBrowserViewController.webView canGoBack]){
|
||||
[self.inAppBrowserViewController.webView goBack];
|
||||
} else {
|
||||
[self close:(command)];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options
|
||||
{
|
||||
NSURLRequest* request = [NSURLRequest requestWithURL:url];
|
||||
|
||||
#ifdef __CORDOVA_4_0_0
|
||||
// the webview engine itself will filter for this according to <allow-navigation> policy
|
||||
// in config.xml for cordova-ios-4.0
|
||||
[self.webViewEngine loadRequest:request];
|
||||
#else
|
||||
if ([self.commandDelegate URLIsWhitelisted:url]) {
|
||||
[self.webView loadRequest:request];
|
||||
} else { // this assumes the InAppBrowser can be excepted from the white-list
|
||||
[self openInInAppBrowser:url withOptions:options];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)openInSystem:(NSURL*)url
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
|
||||
[[UIApplication sharedApplication] openURL:url];
|
||||
if ([[UIApplication sharedApplication] openURL:url] == NO) {
|
||||
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
|
||||
[[UIApplication sharedApplication] openURL:url];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command
|
||||
@@ -703,7 +687,8 @@ static CDVWKInAppBrowser* instance = nil;
|
||||
// Set tmpWindow to hidden to make main webview responsive to touch again
|
||||
// Based on https://stackoverflow.com/questions/4544489/how-to-remove-a-uiwindow
|
||||
self->tmpWindow.hidden = YES;
|
||||
|
||||
self->tmpWindow = nil;
|
||||
|
||||
if (IsAtLeastiOSVersion(@"7.0")) {
|
||||
if (_previousStatusBarStyle != -1) {
|
||||
[[UIApplication sharedApplication] setStatusBarStyle:_previousStatusBarStyle];
|
||||
@@ -724,20 +709,24 @@ static CDVWKInAppBrowser* instance = nil;
|
||||
|
||||
BOOL viewRenderedAtLeastOnce = FALSE;
|
||||
BOOL isExiting = FALSE;
|
||||
|
||||
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
|
||||
if ([keyPath isEqualToString:@"title"] && object == self.webView)
|
||||
{
|
||||
self.titleTitle.text = self.webView.title;
|
||||
}
|
||||
}
|
||||
- (id)initWithBrowserOptions: (CDVInAppBrowserOptions*) browserOptions andSettings:(NSDictionary *)settings andParent:(UIViewController*) parent
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_userAgent = userAgent;
|
||||
_prevUserAgent = prevUserAgent;
|
||||
_browserOptions = browserOptions;
|
||||
_settings = settings;
|
||||
self.webViewUIDelegate = [[CDVWKInAppBrowserUIDelegate alloc] initWithTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]];
|
||||
[self.webViewUIDelegate setViewController:self];
|
||||
|
||||
self.parent = parent;
|
||||
[self createViews];
|
||||
[self.webView addObserver:self forKeyPath:@"title" options:NSKeyValueObservingOptionNew context:NULL];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -755,6 +744,15 @@ BOOL isExiting = FALSE;
|
||||
WKUserContentController* userContentController = [[WKUserContentController alloc] init];
|
||||
|
||||
WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
|
||||
|
||||
NSString *userAgent = configuration.applicationNameForUserAgent;
|
||||
if (
|
||||
[self settingForKey:@"OverrideUserAgent"] == nil &&
|
||||
[self settingForKey:@"AppendUserAgent"] != nil
|
||||
) {
|
||||
userAgent = [NSString stringWithFormat:@"%@ %@", userAgent, [self settingForKey:@"AppendUserAgent"]];
|
||||
}
|
||||
configuration.applicationNameForUserAgent = userAgent;
|
||||
configuration.userContentController = userContentController;
|
||||
#if __has_include("CDVWKProcessPoolFactory.h")
|
||||
configuration.processPool = [[CDVWKProcessPoolFactory sharedFactory] sharedProcessPool];
|
||||
@@ -762,7 +760,8 @@ BOOL isExiting = FALSE;
|
||||
[configuration.userContentController addScriptMessageHandler:self name:IAB_BRIDGE_NAME];
|
||||
|
||||
//WKWebView options
|
||||
configuration.allowsInlineMediaPlayback = _browserOptions.allowinlinemediaplayback;
|
||||
// configuration.allowsInlineMediaPlayback = _browserOptions.allowinlinemediaplayback;
|
||||
configuration.allowsInlineMediaPlayback = YES;
|
||||
if (IsAtLeastiOSVersion(@"10.0")) {
|
||||
configuration.ignoresViewportScaleLimits = _browserOptions.enableviewportscale;
|
||||
if(_browserOptions.mediaplaybackrequiresuseraction == YES){
|
||||
@@ -785,6 +784,9 @@ BOOL isExiting = FALSE;
|
||||
self.webView.navigationDelegate = self;
|
||||
self.webView.UIDelegate = self.webViewUIDelegate;
|
||||
self.webView.backgroundColor = [UIColor whiteColor];
|
||||
if ([self settingForKey:@"OverrideUserAgent"] != nil) {
|
||||
self.webView.customUserAgent = [self settingForKey:@"OverrideUserAgent"];
|
||||
}
|
||||
|
||||
self.webView.clearsContextBeforeDrawing = YES;
|
||||
self.webView.clipsToBounds = YES;
|
||||
@@ -796,7 +798,7 @@ BOOL isExiting = FALSE;
|
||||
[self.webView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
|
||||
self.webView.allowsLinkPreview = NO;
|
||||
self.webView.allowsBackForwardNavigationGestures = NO;
|
||||
|
||||
|
||||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
|
||||
if (@available(iOS 11.0, *)) {
|
||||
[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
|
||||
@@ -908,13 +910,67 @@ BOOL isExiting = FALSE;
|
||||
} else {
|
||||
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]];
|
||||
}
|
||||
// 状态栏和标题栏的通用配置
|
||||
float offsetY=[UIApplication sharedApplication].statusBarFrame.size.height;
|
||||
UIColor *backgroundColor = nil;
|
||||
if(_browserOptions.background == nil) {
|
||||
backgroundColor = [UIColor grayColor];
|
||||
}else{
|
||||
backgroundColor = [self colorFromHexString:_browserOptions.background];
|
||||
}
|
||||
UIColor *fontColor = nil;
|
||||
if(_browserOptions.color == nil) {
|
||||
fontColor = [UIColor whiteColor];
|
||||
}else{
|
||||
fontColor = [self colorFromHexString:_browserOptions.color];
|
||||
}
|
||||
// 开始添加状态栏
|
||||
self.statusbar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, offsetY)];
|
||||
self.statusbar.backgroundColor = backgroundColor;
|
||||
self.statusbar.hidden = YES;
|
||||
// 结束添加状态栏
|
||||
// 开始添加标题栏
|
||||
self.titlebar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, TITLEBAR_HEIGHT + offsetY)]; //self.navigationController.navigationBar;
|
||||
|
||||
|
||||
self.titlebar.backgroundColor = backgroundColor;
|
||||
self.titlebar.tintColor =fontColor;
|
||||
|
||||
// 返回按钮
|
||||
self.titleBackButton =[[UIButton alloc] initWithFrame:CGRectMake(self.view.safeAreaInsets.left, offsetY, TITLEBAR_HEIGHT, TITLEBAR_HEIGHT)];
|
||||
[self.titleBackButton setTitle:@"く" forState:UIControlStateNormal];
|
||||
[self.titleBackButton addTarget:self action:@selector(goBack:) forControlEvents:UIControlEventTouchUpInside];
|
||||
if(_browserOptions.backbutton){
|
||||
[self.titlebar addSubview:self.titleBackButton];
|
||||
}
|
||||
self.titleCloseButton =[[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width - TITLEBAR_HEIGHT - self.view.safeAreaInsets.right, offsetY, TITLEBAR_HEIGHT, TITLEBAR_HEIGHT)];
|
||||
[self.titleCloseButton setTitle:@"ⓧ" forState:UIControlStateNormal];
|
||||
[self.titleCloseButton addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.titlebar addSubview:self.titleCloseButton];
|
||||
self.titleTitle = [[UILabel alloc] initWithFrame:CGRectMake(self.titleBackButton.frame.origin.x + self.titleBackButton.frame.size.width,offsetY,
|
||||
self.view.frame.size.width - TITLEBAR_HEIGHT - self.view.safeAreaInsets.right - self.titleBackButton.frame.size.width - self.titleBackButton.frame.origin.x, TITLEBAR_HEIGHT)];
|
||||
[self.titleTitle setText:@"加载中..."];
|
||||
self.titleTitle.textAlignment = NSTextAlignmentCenter;
|
||||
self.titleTitle.numberOfLines = 1;
|
||||
[self.titleTitle setTextColor:fontColor];
|
||||
[self.titlebar addSubview:self.titleTitle];
|
||||
// 结束添加标题栏
|
||||
|
||||
self.view.backgroundColor = [UIColor grayColor];
|
||||
[self.view addSubview:self.statusbar];
|
||||
[self.view addSubview:self.toolbar];
|
||||
[self.view addSubview:self.addressLabel];
|
||||
[self.view addSubview:self.titlebar];
|
||||
[self.view addSubview:self.spinner];
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (id)settingForKey:(NSString*)key
|
||||
{
|
||||
return [_settings objectForKey:[key lowercaseString]];
|
||||
}
|
||||
|
||||
- (void) setWebViewFrame : (CGRect) frame {
|
||||
NSLog(@"Setting the WebView's frame to %@", NSStringFromCGRect(frame));
|
||||
[self.webView setFrame:frame];
|
||||
@@ -935,123 +991,96 @@ BOOL isExiting = FALSE;
|
||||
[items replaceObjectAtIndex:buttonIndex withObject:self.closeButton];
|
||||
[self.toolbar setItems:items];
|
||||
}
|
||||
|
||||
- (void)showStatusbar:(BOOL)show
|
||||
{
|
||||
self.hasStatusbar = show;
|
||||
}
|
||||
- (void)showLocationBar:(BOOL)show
|
||||
{
|
||||
CGRect locationbarFrame = self.addressLabel.frame;
|
||||
|
||||
BOOL toolbarVisible = !self.toolbar.hidden;
|
||||
|
||||
// prevent double show/hide
|
||||
if (show == !(self.addressLabel.hidden)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (show) {
|
||||
self.addressLabel.hidden = NO;
|
||||
|
||||
if (toolbarVisible) {
|
||||
// toolBar at the bottom, leave as is
|
||||
// put locationBar on top of the toolBar
|
||||
|
||||
CGRect webViewBounds = self.view.bounds;
|
||||
webViewBounds.size.height -= FOOTER_HEIGHT;
|
||||
[self setWebViewFrame:webViewBounds];
|
||||
|
||||
locationbarFrame.origin.y = webViewBounds.size.height;
|
||||
self.addressLabel.frame = locationbarFrame;
|
||||
} else {
|
||||
// no toolBar, so put locationBar at the bottom
|
||||
|
||||
CGRect webViewBounds = self.view.bounds;
|
||||
webViewBounds.size.height -= LOCATIONBAR_HEIGHT;
|
||||
[self setWebViewFrame:webViewBounds];
|
||||
|
||||
locationbarFrame.origin.y = webViewBounds.size.height;
|
||||
self.addressLabel.frame = locationbarFrame;
|
||||
}
|
||||
} else {
|
||||
self.addressLabel.hidden = YES;
|
||||
|
||||
if (toolbarVisible) {
|
||||
// locationBar is on top of toolBar, hide locationBar
|
||||
|
||||
// webView take up whole height less toolBar height
|
||||
CGRect webViewBounds = self.view.bounds;
|
||||
webViewBounds.size.height -= TOOLBAR_HEIGHT;
|
||||
[self setWebViewFrame:webViewBounds];
|
||||
} else {
|
||||
// no toolBar, expand webView to screen dimensions
|
||||
[self setWebViewFrame:self.view.bounds];
|
||||
}
|
||||
}
|
||||
self.hasLocationbar = show;
|
||||
}
|
||||
|
||||
- (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition
|
||||
- (void)showToolBar:(BOOL)show
|
||||
{
|
||||
self.hasToolbar = show;
|
||||
}
|
||||
|
||||
- (void)showTitleBar:(BOOL)show
|
||||
{
|
||||
self.hasTitlebar = show;
|
||||
}
|
||||
|
||||
-(void) resetWebviewSize: (NSString *) toolbarPosition{
|
||||
float offsetY=[UIApplication sharedApplication].statusBarFrame.size.height;
|
||||
CGRect webViewBounds = self.view.bounds;
|
||||
CGRect toolbarFrame = self.toolbar.frame;
|
||||
CGRect locationbarFrame = self.addressLabel.frame;
|
||||
|
||||
BOOL locationbarVisible = !self.addressLabel.hidden;
|
||||
|
||||
// prevent double show/hide
|
||||
if (show == !(self.toolbar.hidden)) {
|
||||
return;
|
||||
if(self.hasTitlebar){
|
||||
self.hasStatusbar = NO;
|
||||
self.hasToolbar = NO;
|
||||
self.hasLocationbar = NO;
|
||||
}
|
||||
if(self.hasStatusbar){
|
||||
self.statusbar.hidden = NO;
|
||||
webViewBounds.size.height -= offsetY;
|
||||
webViewBounds.origin.y +=offsetY;
|
||||
} else {
|
||||
self.statusbar.hidden = YES;
|
||||
}
|
||||
|
||||
if (show) {
|
||||
if(self.hasLocationbar){
|
||||
self.addressLabel.hidden = NO;
|
||||
webViewBounds.size.height -= LOCATIONBAR_HEIGHT;
|
||||
self.addressLabel.frame = locationbarFrame;
|
||||
locationbarFrame.origin.y = webViewBounds.origin.y + webViewBounds.size.height ;
|
||||
} else {
|
||||
self.addressLabel.hidden = YES;
|
||||
}
|
||||
if(self.hasToolbar){
|
||||
self.toolbar.hidden = NO;
|
||||
CGRect webViewBounds = self.view.bounds;
|
||||
|
||||
if (locationbarVisible) {
|
||||
// locationBar at the bottom, move locationBar up
|
||||
// put toolBar at the bottom
|
||||
webViewBounds.size.height -= FOOTER_HEIGHT;
|
||||
locationbarFrame.origin.y = webViewBounds.size.height;
|
||||
self.addressLabel.frame = locationbarFrame;
|
||||
self.toolbar.frame = toolbarFrame;
|
||||
} else {
|
||||
// no locationBar, so put toolBar at the bottom
|
||||
CGRect webViewBounds = self.view.bounds;
|
||||
webViewBounds.size.height -= TOOLBAR_HEIGHT;
|
||||
self.toolbar.frame = toolbarFrame;
|
||||
}
|
||||
|
||||
webViewBounds.size.height -= TOOLBAR_HEIGHT;
|
||||
self.toolbar.frame = toolbarFrame;
|
||||
if ([toolbarPosition isEqualToString:kInAppBrowserToolbarBarPositionTop]) {
|
||||
toolbarFrame.origin.y = 0;
|
||||
toolbarFrame.origin.y = webViewBounds.origin.y;
|
||||
if(self.hasLocationbar){
|
||||
locationbarFrame.origin.y = toolbarFrame.origin.y + toolbarFrame.size.height ;
|
||||
webViewBounds.origin.y += locationbarFrame.size.height;
|
||||
}
|
||||
webViewBounds.origin.y += toolbarFrame.size.height;
|
||||
[self setWebViewFrame:webViewBounds];
|
||||
} else {
|
||||
toolbarFrame.origin.y = (webViewBounds.size.height + LOCATIONBAR_HEIGHT);
|
||||
toolbarFrame.origin.y = webViewBounds.size.height + webViewBounds.origin.y;
|
||||
if(self.hasLocationbar){
|
||||
locationbarFrame.origin.y = webViewBounds.origin.y + webViewBounds.size.height ;
|
||||
toolbarFrame.origin.y += locationbarFrame.size.height;
|
||||
}
|
||||
}
|
||||
[self setWebViewFrame:webViewBounds];
|
||||
|
||||
} else {
|
||||
self.toolbar.hidden = YES;
|
||||
|
||||
if (locationbarVisible) {
|
||||
// locationBar is on top of toolBar, hide toolBar
|
||||
// put locationBar at the bottom
|
||||
|
||||
// webView take up whole height less locationBar height
|
||||
CGRect webViewBounds = self.view.bounds;
|
||||
webViewBounds.size.height -= LOCATIONBAR_HEIGHT;
|
||||
[self setWebViewFrame:webViewBounds];
|
||||
|
||||
// move locationBar down
|
||||
locationbarFrame.origin.y = webViewBounds.size.height;
|
||||
self.addressLabel.frame = locationbarFrame;
|
||||
} else {
|
||||
// no locationBar, expand webView to screen dimensions
|
||||
[self setWebViewFrame:self.view.bounds];
|
||||
}
|
||||
}
|
||||
}
|
||||
if(self.hasTitlebar){
|
||||
self.titlebar.hidden = NO;
|
||||
webViewBounds.size.height -= offsetY + TITLEBAR_HEIGHT;
|
||||
webViewBounds.origin.y =offsetY + TITLEBAR_HEIGHT;
|
||||
} else {
|
||||
self.titlebar.hidden = YES;
|
||||
}
|
||||
if(self.hasLocationbar){
|
||||
}
|
||||
[self setWebViewFrame:webViewBounds];
|
||||
|
||||
}
|
||||
-(void) viewDidLayoutSubviews{
|
||||
[super viewDidLayoutSubviews];
|
||||
NSLog(@"viewDidLayoutSubviews");
|
||||
[self rePositionViews];
|
||||
}
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
viewRenderedAtLeastOnce = FALSE;
|
||||
[super viewDidLoad];
|
||||
NSLog(@"viewDidLoad");
|
||||
|
||||
}
|
||||
|
||||
- (void)viewDidDisappear:(BOOL)animated
|
||||
@@ -1068,19 +1097,45 @@ BOOL isExiting = FALSE;
|
||||
return UIStatusBarStyleDefault;
|
||||
}
|
||||
|
||||
|
||||
/// 判断当前是否使用暗黑外观
|
||||
- (BOOL)inDarkAppearance{
|
||||
BOOL res = NO;
|
||||
if (@available(iOS 13.0, *)) {
|
||||
switch (UITraitCollection.currentTraitCollection.userInterfaceStyle) {
|
||||
case UIUserInterfaceStyleDark:
|
||||
NSLog(@"深色模式");
|
||||
res = YES;
|
||||
break;
|
||||
case UIUserInterfaceStyleLight:
|
||||
NSLog(@"浅色模式");
|
||||
break;
|
||||
case UIUserInterfaceStyleUnspecified:
|
||||
NSLog(@"未指定");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
- (BOOL)prefersStatusBarHidden {
|
||||
return NO;
|
||||
return !self.statusbar;
|
||||
}
|
||||
|
||||
- (void)close
|
||||
{
|
||||
[CDVUserAgentUtil releaseLock:&_userAgentLockToken];
|
||||
self.currentURL = nil;
|
||||
|
||||
[self.webView removeObserver:self forKeyPath:@"title" context: NULL];
|
||||
__weak UIViewController* weakSelf = self;
|
||||
__weak UIViewController* weakParentSelf = self.parent;
|
||||
|
||||
// Run later to avoid the "took a long time" log message.
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIView *lastView;
|
||||
for(UIView *subview in [weakParentSelf.view subviews]) {
|
||||
lastView = subview;
|
||||
}
|
||||
[lastView removeFromSuperview];
|
||||
isExiting = TRUE;
|
||||
if ([weakSelf respondsToSelector:@selector(presentingViewController)]) {
|
||||
[[weakSelf presentingViewController] dismissViewControllerAnimated:YES completion:nil];
|
||||
@@ -1093,22 +1148,16 @@ BOOL isExiting = FALSE;
|
||||
- (void)navigateTo:(NSURL*)url
|
||||
{
|
||||
NSURLRequest* request = [NSURLRequest requestWithURL:url];
|
||||
|
||||
if (_userAgentLockToken != 0) {
|
||||
[self.webView loadRequest:request];
|
||||
} else {
|
||||
__weak CDVWKInAppBrowserViewController* weakSelf = self;
|
||||
[CDVUserAgentUtil acquireLock:^(NSInteger lockToken) {
|
||||
_userAgentLockToken = lockToken;
|
||||
[CDVUserAgentUtil setUserAgent:_userAgent lockToken:lockToken];
|
||||
[weakSelf.webView loadRequest:request];
|
||||
}];
|
||||
}
|
||||
[self.webView loadRequest:request];
|
||||
}
|
||||
|
||||
- (void)goBack:(id)sender
|
||||
{
|
||||
[self.webView goBack];
|
||||
if(self.webView.canGoBack){
|
||||
[self.webView goBack];
|
||||
} else {
|
||||
[self close];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)goForward:(id)sender
|
||||
@@ -1116,18 +1165,8 @@ BOOL isExiting = FALSE;
|
||||
[self.webView goForward];
|
||||
}
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
if (IsAtLeastiOSVersion(@"7.0") && !viewRenderedAtLeastOnce) {
|
||||
viewRenderedAtLeastOnce = TRUE;
|
||||
CGRect viewBounds = [self.webView bounds];
|
||||
viewBounds.origin.y = STATUSBAR_HEIGHT;
|
||||
viewBounds.size.height = viewBounds.size.height - STATUSBAR_HEIGHT;
|
||||
self.webView.frame = viewBounds;
|
||||
[[UIApplication sharedApplication] setStatusBarStyle:[self preferredStatusBarStyle]];
|
||||
}
|
||||
[self rePositionViews];
|
||||
|
||||
[super viewWillAppear:animated];
|
||||
}
|
||||
|
||||
@@ -1151,7 +1190,6 @@ BOOL isExiting = FALSE;
|
||||
|
||||
// Helper function to convert hex color string to UIColor
|
||||
// Assumes input like "#00FF00" (#RRGGBB).
|
||||
// Taken from https://stackoverflow.com/questions/1560081/how-can-i-create-a-uicolor-from-a-hex-string
|
||||
- (UIColor *)colorFromHexString:(NSString *)hexString {
|
||||
unsigned rgbValue = 0;
|
||||
NSScanner *scanner = [NSScanner scannerWithString:hexString];
|
||||
@@ -1167,6 +1205,7 @@ BOOL isExiting = FALSE;
|
||||
// loading url, start spinner, update back/forward
|
||||
|
||||
self.addressLabel.text = NSLocalizedString(@"Loading...", nil);
|
||||
[self.titleTitle setText:@"加载中..."];
|
||||
self.backButton.enabled = theWebView.canGoBack;
|
||||
self.forwardButton.enabled = theWebView.canGoForward;
|
||||
|
||||
@@ -1195,32 +1234,14 @@ BOOL isExiting = FALSE;
|
||||
- (void)webView:(WKWebView *)theWebView didFinishNavigation:(WKNavigation *)navigation
|
||||
{
|
||||
// update url, stop spinner, update back/forward
|
||||
|
||||
self.addressLabel.text = [self.currentURL absoluteString];
|
||||
self.backButton.enabled = theWebView.canGoBack;
|
||||
self.forwardButton.enabled = theWebView.canGoForward;
|
||||
theWebView.scrollView.contentInset = UIEdgeInsetsZero;
|
||||
|
||||
[self.titleTitle setText:theWebView.title];
|
||||
// self.titlebar.hidden = NO;
|
||||
[self.spinner stopAnimating];
|
||||
|
||||
// Work around a bug where the first time a PDF is opened, all UIWebViews
|
||||
// reload their User-Agent from NSUserDefaults.
|
||||
// This work-around makes the following assumptions:
|
||||
// 1. The app has only a single Cordova Webview. If not, then the app should
|
||||
// take it upon themselves to load a PDF in the background as a part of
|
||||
// their start-up flow.
|
||||
// 2. That the PDF does not require any additional network requests. We change
|
||||
// the user-agent here back to that of the CDVViewController, so requests
|
||||
// from it must pass through its white-list. This *does* break PDFs that
|
||||
// contain links to other remote PDF/websites.
|
||||
// More info at https://issues.apache.org/jira/browse/CB-2225
|
||||
BOOL isPDF = NO;
|
||||
//TODO webview class
|
||||
//BOOL isPDF = [@"true" isEqualToString :[theWebView evaluateJavaScript:@"document.body==null"]];
|
||||
if (isPDF) {
|
||||
[CDVUserAgentUtil setUserAgent:_prevUserAgent lockToken:_userAgentLockToken];
|
||||
}
|
||||
|
||||
[self.navigationDelegate didFinishNavigation:theWebView];
|
||||
}
|
||||
|
||||
@@ -1231,7 +1252,11 @@ BOOL isExiting = FALSE;
|
||||
self.backButton.enabled = theWebView.canGoBack;
|
||||
self.forwardButton.enabled = theWebView.canGoForward;
|
||||
[self.spinner stopAnimating];
|
||||
|
||||
[self.titleTitle setText: @"加载出错"];
|
||||
if(!self.hasToolbar){
|
||||
self.titlebar.hidden = NO;
|
||||
self.titleBackButton.hidden = YES;
|
||||
}
|
||||
self.addressLabel.text = NSLocalizedString(@"Load Error", nil);
|
||||
|
||||
[self.navigationDelegate webView:theWebView didFailNavigation:error];
|
||||
@@ -1266,7 +1291,7 @@ BOOL isExiting = FALSE;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSUInteger)supportedInterfaceOrientations
|
||||
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
|
||||
{
|
||||
if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(supportedInterfaceOrientations)]) {
|
||||
return [self.orientationDelegate supportedInterfaceOrientations];
|
||||
@@ -1275,14 +1300,4 @@ BOOL isExiting = FALSE;
|
||||
return 1 << UIInterfaceOrientationPortrait;
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
||||
{
|
||||
if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)]) {
|
||||
return [self.orientationDelegate shouldAutorotateToInterfaceOrientation:interfaceOrientation];
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
@end //CDVWKInAppBrowserViewController
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cordova-plugin-inappbrowser-tests",
|
||||
"version": "3.2.0",
|
||||
"version": "4.0.0-dev",
|
||||
"description": "",
|
||||
"cordova": {
|
||||
"id": "cordova-plugin-inappbrowser-tests",
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
id="cordova-plugin-inappbrowser-tests"
|
||||
version="3.2.0">
|
||||
version="4.0.0-dev">
|
||||
<name>Cordova InAppBrowser Plugin Tests</name>
|
||||
<license>Apache 2.0</license>
|
||||
|
||||
|
||||
@@ -182,24 +182,13 @@ exports.defineAutoTests = function () {
|
||||
});
|
||||
});
|
||||
};
|
||||
if (isIos) {
|
||||
createTests('usewkwebview=no');
|
||||
createTests('usewkwebview=yes');
|
||||
} else {
|
||||
createTests();
|
||||
}
|
||||
createTests();
|
||||
};
|
||||
|
||||
exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
|
||||
var platformOpts = '';
|
||||
var platform_info = '';
|
||||
if (isIos) {
|
||||
platformOpts = 'usewkwebview=no';
|
||||
platform_info = '<h1>Webview</h1>' +
|
||||
'<p>Use this button to toggle the Webview implementation.</p>' +
|
||||
'<div id="webviewToggle"></div>';
|
||||
}
|
||||
|
||||
function doOpen (url, target, params, numExpectedRedirects, useWindowOpen) {
|
||||
numExpectedRedirects = numExpectedRedirects || 0;
|
||||
@@ -543,20 +532,6 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
var injectjs = isWindows ? basePath + 'inject.js' : 'inject.js';
|
||||
var injectcss = isWindows ? basePath + 'inject.css' : 'inject.css';
|
||||
var videohtml = basePath + 'video.html';
|
||||
if (isIos) {
|
||||
createActionButton('Webview=UIWebView', function () {
|
||||
var webviewOption = 'usewkwebview=';
|
||||
var webviewToggle = document.getElementById('webviewToggle');
|
||||
var button = webviewToggle.getElementsByClassName('topcoat-button')[0];
|
||||
if (platformOpts === webviewOption + 'yes') {
|
||||
platformOpts = webviewOption + 'no';
|
||||
button.textContent = 'Webview=UIWebView';
|
||||
} else {
|
||||
platformOpts = webviewOption + 'yes';
|
||||
button.textContent = 'Webview=WKWebView';
|
||||
}
|
||||
}, 'webviewToggle');
|
||||
}
|
||||
|
||||
// Local
|
||||
createActionButton('target=Default', function () {
|
||||
|
||||
11
types/index.d.ts
vendored
11
types/index.d.ts
vendored
@@ -6,7 +6,7 @@
|
||||
// Copyright (c) Microsoft Open Technologies Inc
|
||||
// Licensed under the MIT license.
|
||||
// TypeScript Version: 2.3
|
||||
type channel = "loadstart" | "loadstop" | "loaderror" | "exit" | "message";
|
||||
type channel = "loadstart" | "loadstop" | "loaderror" | "exit" | "message" | "customscheme";
|
||||
|
||||
interface Window {
|
||||
/**
|
||||
@@ -40,6 +40,13 @@ interface InAppBrowser extends Window {
|
||||
* passed an InAppBrowserEvent object as a parameter.
|
||||
*/
|
||||
addEventListener(type: channel, callback: InAppBrowserEventListenerOrEventListenerObject): void;
|
||||
/**
|
||||
* Adds a listener for an event from the InAppBrowser.
|
||||
* @param type any custom event that might occur.
|
||||
* @param callback the function that executes when the event fires. The function is
|
||||
* passed an InAppBrowserEvent object as a parameter.
|
||||
*/
|
||||
addEventListener(type: string, callback: InAppBrowserEventListenerOrEventListenerObject): void;
|
||||
// removeEventListener overloads
|
||||
/**
|
||||
* Removes a listener for an event from the InAppBrowser.
|
||||
@@ -61,6 +68,8 @@ interface InAppBrowser extends Window {
|
||||
* if the InAppBrowser was already visible.
|
||||
*/
|
||||
show(): void;
|
||||
|
||||
back(): void;
|
||||
/**
|
||||
* Injects JavaScript code into the InAppBrowser window.
|
||||
* @param script Details of the script to run, specifying either a file or code key.
|
||||
|
||||
@@ -20,12 +20,6 @@
|
||||
*/
|
||||
|
||||
(function () {
|
||||
// special patch to correctly work on Ripple emulator (CB-9760)
|
||||
if (window.parent && !!window.parent.ripple) { // https://gist.github.com/triceam/4658021
|
||||
module.exports = window.open.bind(window); // fallback to default window.open behaviour
|
||||
return;
|
||||
}
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
var channel = require('cordova/channel');
|
||||
var modulemapper = require('cordova/modulemapper');
|
||||
@@ -66,6 +60,9 @@
|
||||
hide: function (eventname) {
|
||||
exec(null, null, 'InAppBrowser', 'hide', []);
|
||||
},
|
||||
back: function(eventname) {
|
||||
exec(null, null, 'InAppBrowser', 'back', []);
|
||||
},
|
||||
addEventListener: function (eventname, f) {
|
||||
if (eventname in this.channels) {
|
||||
this.channels[eventname].subscribe(f);
|
||||
|
||||
Reference in New Issue
Block a user