Compare commits
64 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7eb2e1ea03 | ||
|
|
98ee2e148c | ||
|
|
b73ba93884 | ||
|
|
c80c338e51 | ||
|
|
8e3f2f2c53 | ||
|
|
8f66f075dd | ||
|
|
1876869a05 | ||
|
|
260542d13c | ||
|
|
b9e0a80837 | ||
|
|
7c1ea3b5c2 | ||
|
|
3a2c4ef5c0 | ||
|
|
5f072a752d | ||
|
|
e428556e25 | ||
|
|
d85991accb | ||
|
|
309cdef070 | ||
|
|
2c547a1a1e | ||
|
|
84a4644cd1 | ||
|
|
0f2f14a563 | ||
|
|
b9c577044c | ||
|
|
cc2299e1c3 | ||
|
|
7fb19f6bdc | ||
|
|
d46f5d45d5 | ||
|
|
ff230d429a | ||
|
|
ec2f12c872 | ||
|
|
6c2a8f4576 | ||
|
|
55b02285f9 | ||
|
|
4af420c592 | ||
|
|
e691212c96 | ||
|
|
8711ee3f21 | ||
|
|
71201b10a6 | ||
|
|
50ac05ca41 | ||
|
|
dcc00fc3bd | ||
|
|
e9878ddecd | ||
|
|
aee699a0e5 | ||
|
|
d78cfdc4d4 | ||
|
|
bf6945feb0 | ||
|
|
ad4a0a3120 | ||
|
|
3882924c4a | ||
|
|
6eb9bbbf75 | ||
|
|
7ac56842aa | ||
|
|
dbf3316df3 | ||
|
|
171e7dfea7 | ||
|
|
6ea100a9fe | ||
|
|
bfe8763918 | ||
|
|
902427525f | ||
|
|
7611645469 | ||
|
|
72ac4d7eca | ||
|
|
32d867f8e4 | ||
|
|
6e058624d6 | ||
|
|
ed139eeb34 | ||
|
|
aa82a5d6c8 | ||
|
|
15685d7a21 | ||
|
|
4f144d9e82 | ||
|
|
b6ed0bbaca | ||
|
|
711c605212 | ||
|
|
c630159c22 | ||
|
|
ff6a765fac | ||
|
|
531a508c0d | ||
|
|
bfb33988be | ||
|
|
b923e88b23 | ||
|
|
c9ff78abfd | ||
|
|
0f5de8524f | ||
|
|
0ddc31d3f4 | ||
|
|
a74510ba00 |
28
.appveyor.yml
Normal file
28
.appveyor.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
# appveyor file
|
||||
# http://www.appveyor.com/docs/appveyor-yml
|
||||
|
||||
max_jobs: 1
|
||||
|
||||
shallow_clone: true
|
||||
|
||||
init:
|
||||
- git config --global core.autocrlf true
|
||||
|
||||
image:
|
||||
- Visual Studio 2017
|
||||
|
||||
environment:
|
||||
nodejs_version: "4"
|
||||
matrix:
|
||||
- PLATFORM: windows-10-store
|
||||
JUST_BUILD: --justBuild
|
||||
install:
|
||||
- npm cache clean -f
|
||||
- node --version
|
||||
- npm install -g cordova-paramedic@https://github.com/apache/cordova-paramedic.git
|
||||
- npm install -g cordova
|
||||
|
||||
build: off
|
||||
|
||||
test_script:
|
||||
- cordova-paramedic --config pr\%PLATFORM% --plugin . %JUST_BUILD%
|
||||
10
.eslintrc.yml
Normal file
10
.eslintrc.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
root: true
|
||||
extends: semistandard
|
||||
rules:
|
||||
indent:
|
||||
- error
|
||||
- 4
|
||||
camelcase: off
|
||||
padded-blocks: off
|
||||
operator-linebreak: off
|
||||
no-throw-literal: off
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -21,4 +21,3 @@ node_modules
|
||||
|
||||
|
||||
|
||||
|
||||
16
.jshintrc
16
.jshintrc
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"browser": true
|
||||
, "devel": true
|
||||
, "bitwise": true
|
||||
, "undef": true
|
||||
, "trailing": true
|
||||
, "quotmark": false
|
||||
, "indent": 4
|
||||
, "unused": "vars"
|
||||
, "latedef": "nofunc"
|
||||
, "globals": {
|
||||
"module": false,
|
||||
"exports": false,
|
||||
"require": false
|
||||
}
|
||||
}
|
||||
96
.travis.yml
96
.travis.yml
@@ -1,4 +1,94 @@
|
||||
language: node_js
|
||||
sudo: false
|
||||
node_js:
|
||||
- "4.2"
|
||||
addons:
|
||||
jwt:
|
||||
secure: TZ88IEvAw1bsWPWxvDzXdpi2NK0i3PN4hG15+vDpIt6wXGVPknjxuXWJeLj7TqBpAIvP7XDfS8ZvHVPLe7fe8oOchZPLuiDw9VVIk6cnHjE6wpoavdGc/1mDJ3Bi4PDcHwRUr5ng5spYQqqlTwcECkH/q7iPgudiFM6rlOlGRyA=
|
||||
env:
|
||||
global:
|
||||
- SAUCE_USERNAME=snay
|
||||
- TRAVIS_NODE_VERSION="4.2"
|
||||
matrix:
|
||||
include:
|
||||
- env: PLATFORM=browser-chrome
|
||||
os: linux
|
||||
language: node_js
|
||||
node_js: '4.2'
|
||||
- env: PLATFORM=browser-firefox
|
||||
os: linux
|
||||
language: node_js
|
||||
node_js: '4.2'
|
||||
- env: PLATFORM=browser-safari
|
||||
os: linux
|
||||
language: node_js
|
||||
node_js: '4.2'
|
||||
- env: PLATFORM=browser-edge
|
||||
os: linux
|
||||
language: node_js
|
||||
node_js: '4.2'
|
||||
- env: PLATFORM=ios-9.3
|
||||
os: osx
|
||||
osx_image: xcode7.3
|
||||
language: node_js
|
||||
node_js: '4.2'
|
||||
- env: PLATFORM=ios-10.0
|
||||
os: osx
|
||||
osx_image: xcode7.3
|
||||
language: node_js
|
||||
node_js: '4.2'
|
||||
- env: PLATFORM=android-4.4
|
||||
os: linux
|
||||
language: android
|
||||
jdk: oraclejdk8
|
||||
android:
|
||||
components:
|
||||
- tools
|
||||
- platform-tools
|
||||
- tools
|
||||
- build-tools-26.0.2
|
||||
- env: PLATFORM=android-5.1
|
||||
os: linux
|
||||
language: android
|
||||
jdk: oraclejdk8
|
||||
android:
|
||||
components:
|
||||
- tools
|
||||
- platform-tools
|
||||
- tools
|
||||
- build-tools-26.0.2
|
||||
- env: PLATFORM=android-6.0
|
||||
os: linux
|
||||
language: android
|
||||
jdk: oraclejdk8
|
||||
android:
|
||||
components:
|
||||
- tools
|
||||
- platform-tools
|
||||
- tools
|
||||
- build-tools-26.0.2
|
||||
- env: PLATFORM=android-7.0
|
||||
os: linux
|
||||
language: android
|
||||
jdk: oraclejdk8
|
||||
android:
|
||||
components:
|
||||
- tools
|
||||
- platform-tools
|
||||
- tools
|
||||
- build-tools-26.0.2
|
||||
before_install:
|
||||
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm
|
||||
&& git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm
|
||||
install $TRAVIS_NODE_VERSION
|
||||
- node --version
|
||||
- if [[ "$PLATFORM" =~ android ]]; then gradle --version; fi
|
||||
- if [[ "$PLATFORM" =~ ios ]]; then npm install -g ios-deploy; fi
|
||||
- if [[ "$PLATFORM" =~ android ]]; then echo y | android update sdk -u --filter android-22,android-23,android-24,android-25,android-26;
|
||||
fi
|
||||
- git clone https://github.com/apache/cordova-paramedic /tmp/paramedic && pushd /tmp/paramedic
|
||||
&& npm install && popd
|
||||
- npm install -g cordova
|
||||
install:
|
||||
- npm install
|
||||
script:
|
||||
- npm test
|
||||
- node /tmp/paramedic/main.js --config pr/$PLATFORM --plugin $(pwd) --shouldUseSauce
|
||||
--buildName travis-plugin-inappbrowser-$TRAVIS_JOB_NUMBER
|
||||
|
||||
127
README.md
127
README.md
@@ -21,9 +21,9 @@ description: Open an in-app browser window.
|
||||
# under the License.
|
||||
-->
|
||||
|
||||
|Android 4.4|Android 5.1|iOS 9.3|iOS 10.0|Windows 10 Store|Travis CI|
|
||||
|:-:|:-:|:-:|:-:|:-:|:-:|
|
||||
|[](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android-4.4,PLUGIN=cordova-plugin-inappbrowser/)|[](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android-5.1,PLUGIN=cordova-plugin-inappbrowser/)|[](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios-9.3,PLUGIN=cordova-plugin-inappbrowser/)|[](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios-10.0,PLUGIN=cordova-plugin-inappbrowser/)|[](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-inappbrowser/)|[](https://travis-ci.org/apache/cordova-plugin-inappbrowser)|
|
||||
|AppVeyor|Travis CI|
|
||||
|:-:|:-:|
|
||||
|[](https://ci.appveyor.com/project/ApacheSoftwareFoundation/cordova-plugin-inappbrowser)|[](https://travis-ci.org/apache/cordova-plugin-inappbrowser)|
|
||||
|
||||
# cordova-plugin-inappbrowser
|
||||
|
||||
@@ -57,7 +57,7 @@ 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 it's prototype's default
|
||||
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.
|
||||
|
||||
@@ -66,7 +66,7 @@ Although `window.open` is in the global scope, InAppBrowser is not available unt
|
||||
console.log("window.open works well");
|
||||
}
|
||||
|
||||
Report issues with this plugin on the [Apache Cordova issue tracker](https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20%28Open%2C%20%22In%20Progress%22%2C%20Reopened%29%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22Plugin%20InAppBrowser%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC)
|
||||
Report issues with this plugin on the [Apache Cordova issue tracker](https://issues.apache.org/jira/issues/?jql=project%20%3D%20CB%20AND%20status%20in%20%28Open%2C%20%22In%20Progress%22%2C%20Reopened%29%20AND%20resolution%20%3D%20Unresolved%20AND%20component%20%3D%20%22cordova-plugin-inappbrowser%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC)
|
||||
|
||||
|
||||
## <a id="reference">Reference</a>
|
||||
@@ -101,29 +101,46 @@ instance, or the system browser.
|
||||
|
||||
- __options__: Options for the `InAppBrowser`. Optional, defaulting to: `location=yes`. _(String)_
|
||||
|
||||
The `options` string must not contain any blank space, and each feature's name/value pairs must be separated by a comma. Feature names are case insensitive. All platforms support the value below:
|
||||
The `options` string must not contain any blank space, and each feature's name/value pairs must be separated by a comma. Feature names are case insensitive.
|
||||
|
||||
All platforms support:
|
||||
|
||||
- __location__: Set to `yes` or `no` to turn the `InAppBrowser`'s location bar on or off.
|
||||
|
||||
Android only:
|
||||
Android supports these additional options:
|
||||
|
||||
- __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.
|
||||
- __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened
|
||||
- __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened
|
||||
- __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `yes`.
|
||||
- __closebuttoncaption__: set to a string to use as the close button's caption instead of a X. Note that you need to localize this value yourself.
|
||||
- __closebuttoncolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the
|
||||
close button color from default, regardless of being a text or default X. Only has effect if user has location set to `yes`.
|
||||
- __footer__: set to `yes` to show a close button in the footer similar to the iOS __Done__ button.
|
||||
The close button will appear the same as for the header hence use __closebuttoncaption__ and __closebuttoncolor__ to set its properties.
|
||||
- __footercolor__: set to a valid hex color string, for example `#00ff00` or `#CC00ff00` (`#aarrggbb`) , and it will change the footer color from default.
|
||||
Only has effect if user has __footer__ set to `yes`.
|
||||
- __hardwareback__: set to `yes` to use the hardware back button to navigate backwards through the `InAppBrowser`'s history. If there is no previous page, the `InAppBrowser` will close. The default value is `yes`, so you must set it to `no` if you want the back button to simply close the InAppBrowser.
|
||||
- __hidenavigationbuttons__: set to `yes` to hide the navigation buttons on the location toolbar, only has effect if user has location set to `yes`. The default value is `no`.
|
||||
- __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`.
|
||||
- __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`).
|
||||
|
||||
iOS only:
|
||||
iOS supports these additional options:
|
||||
|
||||
- __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.
|
||||
- __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.
|
||||
- __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened
|
||||
- __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened
|
||||
- __clearsessioncache__: set to `yes` to have the session cookie cache cleared 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.
|
||||
- __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.
|
||||
- __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.
|
||||
- __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`)
|
||||
@@ -133,74 +150,32 @@ instance, or the system browser.
|
||||
- __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`).
|
||||
- __toolbarposition__: Set to `top` or `bottom` (default is `bottom`). Causes the toolbar to be at the top or bottom of the window.
|
||||
|
||||
Windows only:
|
||||
Windows supports these additional options:
|
||||
|
||||
- __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.
|
||||
- __fullscreen__: set to `yes` to create the browser control without a border around it. Please note that if __location=no__ is also specified, there will be no control presented to user to close IAB window.
|
||||
- __hardwareback__: works the same way as on Android platform.
|
||||
- __fullscreen__: set to `yes` to create the browser control without a border around it. Please note that if __location=no__ is also specified, there will be no control presented to user to close IAB window.
|
||||
|
||||
|
||||
### Supported Platforms
|
||||
|
||||
- Amazon Fire OS
|
||||
- Android
|
||||
- BlackBerry 10
|
||||
- Firefox OS
|
||||
- Browser
|
||||
- iOS
|
||||
- OSX
|
||||
- Windows 8 and 8.1
|
||||
- Windows Phone 7 and 8
|
||||
- Browser
|
||||
- Windows
|
||||
|
||||
### Example
|
||||
|
||||
var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
|
||||
var ref2 = cordova.InAppBrowser.open(encodeURI('http://ja.m.wikipedia.org/wiki/ハングル'), '_blank', 'location=yes');
|
||||
|
||||
### Firefox OS Quirks
|
||||
|
||||
As plugin doesn't enforce any design there is a need to add some CSS rules if
|
||||
opened with `target='_blank'`. The rules might look like these
|
||||
|
||||
``` css
|
||||
.inAppBrowserWrap {
|
||||
background-color: rgba(0,0,0,0.75);
|
||||
color: rgba(235,235,235,1.0);
|
||||
}
|
||||
.inAppBrowserWrap menu {
|
||||
overflow: auto;
|
||||
list-style-type: none;
|
||||
padding-left: 0;
|
||||
}
|
||||
.inAppBrowserWrap menu li {
|
||||
font-size: 25px;
|
||||
height: 25px;
|
||||
float: left;
|
||||
margin: 0 10px;
|
||||
padding: 3px 10px;
|
||||
text-decoration: none;
|
||||
color: #ccc;
|
||||
display: block;
|
||||
background: rgba(30,30,30,0.50);
|
||||
}
|
||||
.inAppBrowserWrap menu li.disabled {
|
||||
color: #777;
|
||||
}
|
||||
```
|
||||
|
||||
### OSX Quirks
|
||||
|
||||
At the moment the only supported target in OSX is `_system`.
|
||||
|
||||
`_blank` and `_self` targets are not yet implemented and are ignored silently. Pull requests and patches to get these to work are greatly appreciated.
|
||||
|
||||
### Windows Quirks
|
||||
|
||||
Windows 8.0, 8.1 and Windows Phone 8.1 don't support remote urls to be opened in the Cordova WebView so remote urls are always showed in the system's web browser if opened with `target='_self'`.
|
||||
|
||||
On Windows 10 if the URL is NOT in the white list and is opened with `target='_self'` it will be showed in the system's web browser instead of InAppBrowser popup.
|
||||
|
||||
Similar to Firefox OS IAB window visual behaviour can be overridden via `inAppBrowserWrap`/`inAppBrowserWrapFullscreen` CSS classes
|
||||
|
||||
### Browser Quirks
|
||||
|
||||
- Plugin is implemented via iframe,
|
||||
@@ -321,12 +296,11 @@ function executeScriptCallBack(params) {
|
||||
|
||||
### Supported Platforms
|
||||
|
||||
- Amazon Fire OS
|
||||
- Android
|
||||
- iOS
|
||||
- Windows 8 and 8.1
|
||||
- Windows Phone 7 and 8
|
||||
- Browser
|
||||
- iOS
|
||||
- Windows
|
||||
- OSX
|
||||
|
||||
### Browser Quirks
|
||||
|
||||
@@ -357,12 +331,10 @@ The function is passed an `InAppBrowserEvent` object.
|
||||
|
||||
### Supported Platforms
|
||||
|
||||
- Amazon Fire OS
|
||||
- Android
|
||||
- iOS
|
||||
- Windows 8 and 8.1
|
||||
- Windows Phone 7 and 8
|
||||
- Browser
|
||||
- iOS
|
||||
- Windows
|
||||
|
||||
### Quick Example
|
||||
|
||||
@@ -381,13 +353,10 @@ The function is passed an `InAppBrowserEvent` object.
|
||||
|
||||
### Supported Platforms
|
||||
|
||||
- Amazon Fire OS
|
||||
- Android
|
||||
- Firefox OS
|
||||
- iOS
|
||||
- Windows 8 and 8.1
|
||||
- Windows Phone 7 and 8
|
||||
- Browser
|
||||
- iOS
|
||||
- Windows
|
||||
|
||||
### Quick Example
|
||||
|
||||
@@ -404,11 +373,10 @@ The function is passed an `InAppBrowserEvent` object.
|
||||
|
||||
### Supported Platforms
|
||||
|
||||
- Amazon Fire OS
|
||||
- Android
|
||||
- iOS
|
||||
- Windows 8 and 8.1
|
||||
- Browser
|
||||
- iOS
|
||||
- Windows
|
||||
|
||||
### Quick Example
|
||||
|
||||
@@ -426,10 +394,9 @@ The function is passed an `InAppBrowserEvent` object.
|
||||
|
||||
### Supported Platforms
|
||||
|
||||
- Amazon Fire OS
|
||||
- Android
|
||||
- iOS
|
||||
- Windows 8 and 8.1
|
||||
- Windows
|
||||
|
||||
### Quick Example
|
||||
|
||||
@@ -458,11 +425,10 @@ The function is passed an `InAppBrowserEvent` object.
|
||||
|
||||
### Supported Platforms
|
||||
|
||||
- Amazon Fire OS
|
||||
- Android
|
||||
- iOS
|
||||
- Windows 8 and 8.1
|
||||
- Browser
|
||||
- iOS
|
||||
- Windows
|
||||
|
||||
### Quick Example
|
||||
|
||||
@@ -495,7 +461,6 @@ Due to [MSDN docs](https://msdn.microsoft.com/en-us/library/windows.ui.xaml.cont
|
||||
|
||||
### Supported Platforms
|
||||
|
||||
- Amazon Fire OS
|
||||
- Android
|
||||
- iOS
|
||||
- Windows
|
||||
|
||||
@@ -20,6 +20,49 @@
|
||||
-->
|
||||
# Release Notes
|
||||
|
||||
### 2.0.2 (Jan 24, 2018)
|
||||
* [CB-13791](https://issues.apache.org/jira/browse/CB-13791) Add **Android** support for a footer close button
|
||||
* [CB-13409](https://issues.apache.org/jira/browse/CB-13409) restore gitignore to default
|
||||
* [CB-13409](https://issues.apache.org/jira/browse/CB-13409) restore gitignore to default
|
||||
* [CB-13409](https://issues.apache.org/jira/browse/CB-13409) restore gitignore to default
|
||||
* [CB-13409](https://issues.apache.org/jira/browse/CB-13409) restore gitignore to default
|
||||
* [CB-13409](https://issues.apache.org/jira/browse/CB-13409) ignore idea folder
|
||||
* [CB-13409](https://issues.apache.org/jira/browse/CB-13409) change hidetoolbarnavigationbuttons to hidenavigationbuttons in iso
|
||||
* [CB-13409](https://issues.apache.org/jira/browse/CB-13409) **Android** works well now, all changes are now documented
|
||||
* [CB-13409](https://issues.apache.org/jira/browse/CB-13409) Lets user adjust color of toolbar, hide navigation buttons and set custom text on close button
|
||||
* [CB-13746](https://issues.apache.org/jira/browse/CB-13746) Add build-tools-26.0.2 to travis
|
||||
|
||||
### 2.0.1 (Dec 27, 2017)
|
||||
* [CB-13699](https://issues.apache.org/jira/browse/CB-13699) Fix to allow 2.0.0 version install
|
||||
|
||||
### 2.0.0 (Dec 15, 2017)
|
||||
* [CB-13662](https://issues.apache.org/jira/browse/CB-13662) remove deprecated platforms
|
||||
|
||||
### 1.7.2 (Nov 06, 2017)
|
||||
* [CB-13473](https://issues.apache.org/jira/browse/CB-13473) (CI) Removed **Browser** builds from AppVeyor
|
||||
* [CB-13472](https://issues.apache.org/jira/browse/CB-13472) (CI) Fixed Travis **Android** builds again
|
||||
* [CB-13347](https://issues.apache.org/jira/browse/CB-13347) Enable thirdparty cookies on `>=Android 5.0` device
|
||||
* [CB-12895](https://issues.apache.org/jira/browse/CB-12895) added `eslint` and removed `jshint`
|
||||
* [CB-12975](https://issues.apache.org/jira/browse/CB-12975) (docs) Resort and reword `cordova.InAppBrowser.open` `options` lists
|
||||
* [CB-12586](https://issues.apache.org/jira/browse/CB-12586) (iOS) fix method `hide` doesn't work
|
||||
* [CB-12847](https://issues.apache.org/jira/browse/CB-12847) added `bugs` entry to `package.json`.
|
||||
|
||||
### 1.7.1 (Apr 27, 2017)
|
||||
* [CB-12622](https://issues.apache.org/jira/browse/CB-12622) Added **Android 6.0** build badges to `README`
|
||||
* [CB-12266](https://issues.apache.org/jira/browse/CB-12266) (browser platform) loadstop event.url is now a string instead of an object, aligning it with the other platforms.
|
||||
* [CB-12685](https://issues.apache.org/jira/browse/CB-12685) added `package.json` to tests folder
|
||||
* [CB-11248](https://issues.apache.org/jira/browse/CB-11248) `InAppBrowser` no focus on input text fields
|
||||
|
||||
### 1.7.0 (Feb 28, 2017)
|
||||
* [CB-12366](https://issues.apache.org/jira/browse/CB-12366) **iOS:** Reduce `tmpWindow` level to prevent overlapping statusbar
|
||||
* [CB-12364](https://issues.apache.org/jira/browse/CB-12364) **Windows:** `Inappbrowser` inject file manual tests are not working
|
||||
* [CB-12353](https://issues.apache.org/jira/browse/CB-12353) Corrected merges usage in `plugin.xml`
|
||||
* [CB-12369](https://issues.apache.org/jira/browse/CB-12369) Add plugin typings from `DefinitelyTyped`
|
||||
* [CB-12363](https://issues.apache.org/jira/browse/CB-12363) Added build badges for **iOS 9.3** and **iOS 10.0**
|
||||
* [CB-9148](https://issues.apache.org/jira/browse/CB-9148) **Android:** Add Support for `input[type=file]` File Chooser
|
||||
* [CB-11136](https://issues.apache.org/jira/browse/CB-11136) (ios) Fix `InAppBrowser` when closing with `WKWebView`
|
||||
* [CB-10799](https://issues.apache.org/jira/browse/CB-10799) **iOS:** fix toolbar is shown in incorrect position when in-call status bar
|
||||
|
||||
### 1.6.1 (Dec 14, 2016)
|
||||
* [CB-12237](https://issues.apache.org/jira/browse/CB-12237) - Update version in package.json to correct 1.6.1-dev
|
||||
* [CB-12236](https://issues.apache.org/jira/browse/CB-12236) - Fixed RELEASENOTES for cordova-plugin-inappbrowser
|
||||
|
||||
37
package.json
37
package.json
@@ -1,27 +1,25 @@
|
||||
{
|
||||
"name": "cordova-plugin-inappbrowser",
|
||||
"version": "1.6.2-dev",
|
||||
"version": "2.0.2",
|
||||
"description": "Cordova InAppBrowser Plugin",
|
||||
"types": "./types/index.d.ts",
|
||||
"cordova": {
|
||||
"id": "cordova-plugin-inappbrowser",
|
||||
"platforms": [
|
||||
"android",
|
||||
"amazon-fireos",
|
||||
"ubuntu",
|
||||
"browser",
|
||||
"ios",
|
||||
"osx",
|
||||
"wp7",
|
||||
"wp8",
|
||||
"windows8",
|
||||
"windows",
|
||||
"firefoxos"
|
||||
"windows"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/apache/cordova-plugin-inappbrowser"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://issues.apache.org/jira/browse/CB"
|
||||
},
|
||||
"keywords": [
|
||||
"cordova",
|
||||
"in",
|
||||
@@ -30,26 +28,21 @@
|
||||
"inappbrowser",
|
||||
"ecosystem:cordova",
|
||||
"cordova-android",
|
||||
"cordova-amazon-fireos",
|
||||
"cordova-ubuntu",
|
||||
"cordova-browser",
|
||||
"cordova-ios",
|
||||
"cordova-osx",
|
||||
"cordova-wp7",
|
||||
"cordova-wp8",
|
||||
"cordova-windows8",
|
||||
"cordova-windows",
|
||||
"cordova-firefoxos"
|
||||
"cordova-windows"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "npm run jshint",
|
||||
"jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests"
|
||||
"test": "npm run eslint",
|
||||
"eslint": "node node_modules/eslint/bin/eslint www && node node_modules/eslint/bin/eslint src && node node_modules/eslint/bin/eslint tests"
|
||||
},
|
||||
"engines": {
|
||||
"cordovaDependencies": {
|
||||
"0.2.3": {
|
||||
"cordova": ">=3.1.0"
|
||||
},
|
||||
"2.0.0": {
|
||||
"3.0.0": {
|
||||
"cordova": ">100"
|
||||
}
|
||||
}
|
||||
@@ -57,6 +50,12 @@
|
||||
"author": "Apache Software Foundation",
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"jshint": "^2.6.0"
|
||||
"eslint": "^4.0.0",
|
||||
"eslint-config-semistandard": "^11.0.0",
|
||||
"eslint-config-standard": "^10.2.1",
|
||||
"eslint-plugin-import": "^2.3.0",
|
||||
"eslint-plugin-node": "^5.0.0",
|
||||
"eslint-plugin-promise": "^3.5.0",
|
||||
"eslint-plugin-standard": "^3.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
127
plugin.xml
127
plugin.xml
@@ -20,7 +20,7 @@
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
id="cordova-plugin-inappbrowser"
|
||||
version="1.6.2-dev">
|
||||
version="2.0.2">
|
||||
|
||||
<name>InAppBrowser</name>
|
||||
<description>Cordova InAppBrowser Plugin</description>
|
||||
@@ -40,7 +40,7 @@
|
||||
<clobbers target="window.open" />
|
||||
</js-module>
|
||||
<config-file target="res/xml/config.xml" parent="/*">
|
||||
<feature name="InAppBrowser">
|
||||
<feature name="InAppBrowser">
|
||||
<param name="android-package" value="org.apache.cordova.inappbrowser.InAppBrowser"/>
|
||||
</feature>
|
||||
</config-file>
|
||||
@@ -67,67 +67,21 @@
|
||||
|
||||
</platform>
|
||||
|
||||
<!-- amazon-fireos -->
|
||||
<platform name="amazon-fireos">
|
||||
<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">
|
||||
<param name="android-package" value="org.apache.cordova.inappbrowser.InAppBrowser"/>
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<source-file src="src/amazon/InAppBrowser.java" target-dir="src/org/apache/cordova/inappbrowser" />
|
||||
<source-file src="src/android/InAppBrowserDialog.java" target-dir="src/org/apache/cordova/inappbrowser" />
|
||||
<source-file src="src/amazon/InAppChromeClient.java" target-dir="src/org/apache/cordova/inappbrowser" />
|
||||
|
||||
<!-- drawable src/android/resources -->
|
||||
<resource-file src="src/android/res/drawable-hdpi/ic_action_next_item.png" target="res/drawable-hdpi/ic_action_next_item.png" />
|
||||
<resource-file src="src/android/res/drawable-mdpi/ic_action_next_item.png" target="res/drawable-mdpi/ic_action_next_item.png" />
|
||||
<resource-file src="src/android/res/drawable-xhdpi/ic_action_next_item.png" target="res/drawable-xhdpi/ic_action_next_item.png" />
|
||||
<resource-file src="src/android/res/drawable-xxhdpi/ic_action_next_item.png" target="res/drawable-xxhdpi/ic_action_next_item.png" />
|
||||
|
||||
<resource-file src="src/android/res/drawable-hdpi/ic_action_previous_item.png" target="res/drawable-hdpi/ic_action_previous_item.png" />
|
||||
<resource-file src="src/android/res/drawable-mdpi/ic_action_previous_item.png" target="res/drawable-mdpi/ic_action_previous_item.png" />
|
||||
<resource-file src="src/android/res/drawable-xhdpi/ic_action_previous_item.png" target="res/drawable-xhdpi/ic_action_previous_item.png" />
|
||||
<resource-file src="src/android/res/drawable-xxhdpi/ic_action_previous_item.png" target="res/drawable-xxhdpi/ic_action_previous_item.png" />
|
||||
|
||||
<resource-file src="src/android/res/drawable-hdpi/ic_action_remove.png" target="res/drawable-hdpi/ic_action_remove.png" />
|
||||
<resource-file src="src/android/res/drawable-mdpi/ic_action_remove.png" target="res/drawable-mdpi/ic_action_remove.png" />
|
||||
<resource-file src="src/android/res/drawable-xhdpi/ic_action_remove.png" target="res/drawable-xhdpi/ic_action_remove.png" />
|
||||
<resource-file src="src/android/res/drawable-xxhdpi/ic_action_remove.png" target="res/drawable-xxhdpi/ic_action_remove.png" />
|
||||
</platform>
|
||||
|
||||
<!-- ubuntu -->
|
||||
<platform name="ubuntu">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<clobbers target="cordova.InAppBrowser.open" />
|
||||
<clobbers target="window.open" />
|
||||
</js-module>
|
||||
<header-file src="src/ubuntu/inappbrowser.h" />
|
||||
<source-file src="src/ubuntu/inappbrowser.cpp" />
|
||||
<resource-file src="src/ubuntu/InAppBrowser.qml" />
|
||||
<resource-file src="src/ubuntu/InAppBrowser_escapeScript.js" />
|
||||
<resource-file src="src/ubuntu/close.png" />
|
||||
</platform>
|
||||
|
||||
<!-- ios -->
|
||||
<platform name="ios">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<clobbers target="cordova.InAppBrowser.open" />
|
||||
<clobbers target="window.open" />
|
||||
</js-module>
|
||||
</js-module>
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="InAppBrowser">
|
||||
<param name="ios-package" value="CDVInAppBrowser" />
|
||||
<param name="ios-package" value="CDVInAppBrowser" />
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<header-file src="src/ios/CDVInAppBrowser.h" />
|
||||
<source-file src="src/ios/CDVInAppBrowser.m" />
|
||||
|
||||
|
||||
<framework src="CoreGraphics.framework" />
|
||||
</platform>
|
||||
|
||||
@@ -147,63 +101,6 @@
|
||||
<source-file src="src/osx/CDVInAppBrowser.m" />
|
||||
</platform>
|
||||
|
||||
<!-- wp7 -->
|
||||
<platform name="wp7">
|
||||
<config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
|
||||
<Capability Name="ID_CAP_NETWORKING"/>
|
||||
</config-file>
|
||||
|
||||
<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="wp-package" value="InAppBrowser"/>
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
|
||||
<Capability Name="ID_CAP_NETWORKING" />
|
||||
</config-file>
|
||||
|
||||
<source-file src="src/wp/InAppBrowser.cs" />
|
||||
</platform>
|
||||
|
||||
<!-- wp8 -->
|
||||
<platform name="wp8">
|
||||
<config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
|
||||
<Capability Name="ID_CAP_NETWORKING"/>
|
||||
</config-file>
|
||||
|
||||
<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="wp-package" value="InAppBrowser"/>
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
|
||||
<Capability Name="ID_CAP_NETWORKING" />
|
||||
</config-file>
|
||||
|
||||
<source-file src="src/wp/InAppBrowser.cs" />
|
||||
</platform>
|
||||
|
||||
<!-- windows8 -->
|
||||
<platform name="windows8">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<clobbers target="cordova.InAppBrowser.open" />
|
||||
<clobbers target="window.open" />
|
||||
</js-module>
|
||||
<js-module src="www/windows8/InAppBrowserProxy.js" name="InAppBrowserProxy">
|
||||
<merges target="" />
|
||||
</js-module>
|
||||
</platform>
|
||||
|
||||
<!-- windows universal apps (Windows 8.1, Windows Phone 8.1, Windows 8.0) -->
|
||||
<platform name="windows">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
@@ -216,20 +113,6 @@
|
||||
<asset src="www/inappbrowser.css" target="css/inappbrowser.css" />
|
||||
</platform>
|
||||
|
||||
<!-- firefoxos -->
|
||||
<platform name="firefoxos">
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<permission name="browser" description="Enables the app to implement a browser in an iframe." privileged="true"/>
|
||||
</config-file>
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<clobbers target="cordova.InAppBrowser.open" />
|
||||
<clobbers target="window.open" />
|
||||
</js-module>
|
||||
<js-module src="src/firefoxos/InAppBrowserProxy.js" name="InAppBrowserProxy">
|
||||
<runs />
|
||||
</js-module>
|
||||
</platform>
|
||||
|
||||
<!-- browser -->
|
||||
<platform name="browser">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
|
||||
@@ -1,879 +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.
|
||||
*/
|
||||
package org.apache.cordova.inappbrowser;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import org.apache.cordova.inappbrowser.InAppBrowserDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.WindowManager.LayoutParams;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import com.amazon.android.webkit.AmazonWebChromeClient;
|
||||
import com.amazon.android.webkit.AmazonGeolocationPermissions.Callback;
|
||||
import com.amazon.android.webkit.AmazonJsPromptResult;
|
||||
import com.amazon.android.webkit.AmazonWebSettings;
|
||||
import com.amazon.android.webkit.AmazonWebStorage;
|
||||
import com.amazon.android.webkit.AmazonWebView;
|
||||
import com.amazon.android.webkit.AmazonWebViewClient;
|
||||
import com.amazon.android.webkit.AmazonCookieManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.Config;
|
||||
import org.apache.cordova.CordovaArgs;
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.apache.cordova.LOG;
|
||||
import org.apache.cordova.PluginResult;
|
||||
import org.apache.cordova.CordovaActivity;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
public class InAppBrowser extends CordovaPlugin {
|
||||
|
||||
private static final String NULL = "null";
|
||||
protected static final String LOG_TAG = "InAppBrowser";
|
||||
private static final String SELF = "_self";
|
||||
private static final String SYSTEM = "_system";
|
||||
// private static final String BLANK = "_blank";
|
||||
private static final String EXIT_EVENT = "exit";
|
||||
private static final String LOCATION = "location";
|
||||
private static final String HIDDEN = "hidden";
|
||||
private static final String ZOOM = "zoom";
|
||||
private static final String LOAD_START_EVENT = "loadstart";
|
||||
private static final String LOAD_STOP_EVENT = "loadstop";
|
||||
private static final String LOAD_ERROR_EVENT = "loaderror";
|
||||
private static final String CLEAR_ALL_CACHE = "clearcache";
|
||||
private static final String CLEAR_SESSION_CACHE = "clearsessioncache";
|
||||
private static final String HARDWARE_BACK_BUTTON = "hardwareback";
|
||||
|
||||
private InAppBrowserDialog dialog;
|
||||
private AmazonWebView inAppWebView;
|
||||
private EditText edittext;
|
||||
private CallbackContext callbackContext;
|
||||
private boolean showLocationBar = true;
|
||||
private boolean showZoomControls = true;
|
||||
private boolean openWindowHidden = false;
|
||||
private boolean clearAllCache= false;
|
||||
private boolean clearSessionCache=false;
|
||||
private boolean hadwareBackButton=true;
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args JSONArry of arguments for the plugin.
|
||||
* @param callbackId The callback id used when calling back into JavaScript.
|
||||
* @return A PluginResult object with a status and message.
|
||||
*/
|
||||
public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException {
|
||||
if (action.equals("open")) {
|
||||
this.callbackContext = callbackContext;
|
||||
final String url = args.getString(0);
|
||||
String t = args.optString(1);
|
||||
if (t == null || t.equals("") || t.equals(NULL)) {
|
||||
t = SELF;
|
||||
}
|
||||
final String target = t;
|
||||
final HashMap<String, Boolean> features = parseFeature(args.optString(2));
|
||||
|
||||
Log.d(LOG_TAG, "target = " + target);
|
||||
|
||||
this.cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String result = "";
|
||||
// SELF
|
||||
if (SELF.equals(target)) {
|
||||
Log.d(LOG_TAG, "in self");
|
||||
// load in webview
|
||||
if (url.startsWith("file://") || url.startsWith("javascript:")
|
||||
|| Config.isUrlWhiteListed(url)) {
|
||||
Log.d(LOG_TAG, "loading in webview");
|
||||
webView.loadUrl(url);
|
||||
}
|
||||
//Load the dialer
|
||||
else if (url.startsWith(AmazonWebView.SCHEME_TEL))
|
||||
{
|
||||
try {
|
||||
Log.d(LOG_TAG, "loading in dialer");
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL);
|
||||
intent.setData(Uri.parse(url));
|
||||
cordova.getActivity().startActivity(intent);
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString());
|
||||
}
|
||||
}
|
||||
// load in InAppBrowser
|
||||
else {
|
||||
Log.d(LOG_TAG, "loading in InAppBrowser");
|
||||
result = showWebPage(url, features);
|
||||
}
|
||||
}
|
||||
// SYSTEM
|
||||
else if (SYSTEM.equals(target)) {
|
||||
Log.d(LOG_TAG, "in system");
|
||||
result = openExternal(url);
|
||||
}
|
||||
// BLANK - or anything else
|
||||
else {
|
||||
Log.d(LOG_TAG, "in blank");
|
||||
result = showWebPage(url, features);
|
||||
}
|
||||
|
||||
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result);
|
||||
pluginResult.setKeepCallback(true);
|
||||
callbackContext.sendPluginResult(pluginResult);
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (action.equals("close")) {
|
||||
closeDialog();
|
||||
}
|
||||
else if (action.equals("injectScriptCode")) {
|
||||
String jsWrapper = null;
|
||||
if (args.getBoolean(1)) {
|
||||
jsWrapper = String.format("prompt(JSON.stringify([eval(%%s)]), 'gap-iab://%s')", callbackContext.getCallbackId());
|
||||
}
|
||||
injectDeferredObject(args.getString(0), jsWrapper);
|
||||
}
|
||||
else if (action.equals("injectScriptFile")) {
|
||||
String jsWrapper;
|
||||
if (args.getBoolean(1)) {
|
||||
jsWrapper = String.format("(function(d) { var c = d.createElement('script'); c.src = %%s; c.onload = function() { prompt('', 'gap-iab://%s'); }; d.body.appendChild(c); })(document)", callbackContext.getCallbackId());
|
||||
} else {
|
||||
jsWrapper = "(function(d) { var c = d.createElement('script'); c.src = %s; d.body.appendChild(c); })(document)";
|
||||
}
|
||||
injectDeferredObject(args.getString(0), jsWrapper);
|
||||
}
|
||||
else if (action.equals("injectStyleCode")) {
|
||||
String jsWrapper;
|
||||
if (args.getBoolean(1)) {
|
||||
jsWrapper = String.format("(function(d) { var c = d.createElement('style'); c.innerHTML = %%s; d.body.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId());
|
||||
} else {
|
||||
jsWrapper = "(function(d) { var c = d.createElement('style'); c.innerHTML = %s; d.body.appendChild(c); })(document)";
|
||||
}
|
||||
injectDeferredObject(args.getString(0), jsWrapper);
|
||||
}
|
||||
else if (action.equals("injectStyleFile")) {
|
||||
String jsWrapper;
|
||||
if (args.getBoolean(1)) {
|
||||
jsWrapper = String.format("(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %%s; d.head.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId());
|
||||
} else {
|
||||
jsWrapper = "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %s; d.head.appendChild(c); })(document)";
|
||||
}
|
||||
injectDeferredObject(args.getString(0), jsWrapper);
|
||||
}
|
||||
else if (action.equals("show")) {
|
||||
this.cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
|
||||
pluginResult.setKeepCallback(true);
|
||||
this.callbackContext.sendPluginResult(pluginResult);
|
||||
}
|
||||
else if (action.equals("hide")) {
|
||||
this.cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
dialog.hide();
|
||||
}
|
||||
});
|
||||
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK);
|
||||
pluginResult.setKeepCallback(true);
|
||||
this.callbackContext.sendPluginResult(pluginResult);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the view navigates.
|
||||
*/
|
||||
@Override
|
||||
public void onReset() {
|
||||
closeDialog();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by AccelBroker when listener is to be shut down.
|
||||
* Stop listener.
|
||||
*/
|
||||
public void onDestroy() {
|
||||
closeDialog();
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject an object (script or style) into the InAppBrowser AmazonWebView.
|
||||
*
|
||||
* This is a helper method for the inject{Script|Style}{Code|File} API calls, which
|
||||
* provides a consistent method for injecting JavaScript code into the document.
|
||||
*
|
||||
* If a wrapper string is supplied, then the source string will be JSON-encoded (adding
|
||||
* quotes) and wrapped using string formatting. (The wrapper string should have a single
|
||||
* '%s' marker)
|
||||
*
|
||||
* @param source The source object (filename or script/style text) to inject into
|
||||
* the document.
|
||||
* @param jsWrapper A JavaScript string to wrap the source string in, so that the object
|
||||
* is properly injected, or null if the source string is JavaScript text
|
||||
* which should be executed directly.
|
||||
*/
|
||||
private void injectDeferredObject(String source, String jsWrapper) {
|
||||
final String scriptToInject;
|
||||
if (jsWrapper != null) {
|
||||
org.json.JSONArray jsonEsc = new org.json.JSONArray();
|
||||
jsonEsc.put(source);
|
||||
String jsonRepr = jsonEsc.toString();
|
||||
String jsonSourceString = jsonRepr.substring(1, jsonRepr.length()-1);
|
||||
scriptToInject = String.format(jsWrapper, jsonSourceString);
|
||||
} else {
|
||||
scriptToInject = source;
|
||||
}
|
||||
final String finalScriptToInject = scriptToInject;
|
||||
this.cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
public void run() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
// This action will have the side-effect of blurring the currently focused element
|
||||
inAppWebView.loadUrl("javascript:" + finalScriptToInject);
|
||||
} /*else {
|
||||
inAppWebView.evaluateJavascript(finalScriptToInject, null);
|
||||
}*/
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the list of features into a hash map
|
||||
*
|
||||
* @param optString
|
||||
* @return
|
||||
*/
|
||||
private HashMap<String, Boolean> parseFeature(String optString) {
|
||||
if (optString.equals(NULL)) {
|
||||
return null;
|
||||
} else {
|
||||
HashMap<String, Boolean> map = new HashMap<String, Boolean>();
|
||||
StringTokenizer features = new StringTokenizer(optString, ",");
|
||||
StringTokenizer option;
|
||||
while(features.hasMoreElements()) {
|
||||
option = new StringTokenizer(features.nextToken(), "=");
|
||||
if (option.hasMoreElements()) {
|
||||
String key = option.nextToken();
|
||||
Boolean value = option.nextToken().equals("no") ? Boolean.FALSE : Boolean.TRUE;
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a new browser with the specified URL.
|
||||
*
|
||||
* @param url The url to load.
|
||||
* @param usePhoneGap Load url in PhoneGap webview
|
||||
* @return "" if ok, or error message.
|
||||
*/
|
||||
public String openExternal(String url) {
|
||||
try {
|
||||
Intent intent = null;
|
||||
intent = new Intent(Intent.ACTION_VIEW);
|
||||
// Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
|
||||
// Adding the MIME type to http: URLs causes them to not be handled by the downloader.
|
||||
Uri uri = Uri.parse(url);
|
||||
if ("file".equals(uri.getScheme())) {
|
||||
intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
|
||||
} else {
|
||||
intent.setData(uri);
|
||||
}
|
||||
this.cordova.getActivity().startActivity(intent);
|
||||
return "";
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
|
||||
return e.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the dialog
|
||||
*/
|
||||
public void closeDialog() {
|
||||
final AmazonWebView childView = this.inAppWebView;
|
||||
// The JS protects against multiple calls, so this should happen only when
|
||||
// closeDialog() is called by other native code.
|
||||
if (childView == null) {
|
||||
return;
|
||||
}
|
||||
this.cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
childView.setWebViewClient(new AmazonWebViewClient() {
|
||||
// NB: wait for about:blank before dismissing
|
||||
public void onPageFinished(AmazonWebView view, String url) {
|
||||
if (dialog != null) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
// NB: From SDK 19: "If you call methods on WebView from any thread
|
||||
// other than your app's UI thread, it can cause unexpected results."
|
||||
// http://developer.android.com/guide/webapps/migrating.html#Threads
|
||||
childView.loadUrl("about:blank");
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("type", EXIT_EVENT);
|
||||
sendUpdate(obj, false);
|
||||
} catch (JSONException ex) {
|
||||
Log.d(LOG_TAG, "Should never happen");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Checks to see if it is possible to go back one page in history, then does so.
|
||||
*/
|
||||
public void goBack() {
|
||||
this.cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (InAppBrowser.this.inAppWebView.canGoBack()) {
|
||||
InAppBrowser.this.inAppWebView.goBack();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the web browser go back?
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean canGoBack() {
|
||||
return this.inAppWebView.canGoBack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Has the user set the hardware back button to go back
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean hardwareBack() {
|
||||
return hadwareBackButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if it is possible to go forward one page in history, then does so.
|
||||
*/
|
||||
private void goForward() {
|
||||
this.cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (InAppBrowser.this.inAppWebView.canGoForward()) {
|
||||
InAppBrowser.this.inAppWebView.goForward();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigate to the new page
|
||||
*
|
||||
* @param url to load
|
||||
*/
|
||||
private void navigate(final String url) {
|
||||
InputMethodManager imm = (InputMethodManager)this.cordova.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
|
||||
|
||||
this.cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (!url.startsWith("http") && !url.startsWith("file:")) {
|
||||
InAppBrowser.this.inAppWebView.loadUrl("http://" + url);
|
||||
} else {
|
||||
InAppBrowser.this.inAppWebView.loadUrl(url);
|
||||
}
|
||||
InAppBrowser.this.inAppWebView.requestFocus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Should we show the location bar?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private boolean getShowLocationBar() {
|
||||
return this.showLocationBar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should we show the zoom controls?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private boolean getShowZoomControls() {
|
||||
return this.showZoomControls;
|
||||
}
|
||||
|
||||
private InAppBrowser getInAppBrowser(){
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a new browser with the specified URL.
|
||||
*
|
||||
* @param url The url to load.
|
||||
* @param jsonObject
|
||||
*/
|
||||
public String showWebPage(final String url, HashMap<String, Boolean> features) {
|
||||
// Determine if we should hide the location bar.
|
||||
showLocationBar = true;
|
||||
showZoomControls = true;
|
||||
openWindowHidden = false;
|
||||
if (features != null) {
|
||||
Boolean show = features.get(LOCATION);
|
||||
if (show != null) {
|
||||
showLocationBar = show.booleanValue();
|
||||
}
|
||||
Boolean zoom = features.get(ZOOM);
|
||||
if (zoom != null) {
|
||||
showZoomControls = zoom.booleanValue();
|
||||
}
|
||||
Boolean hidden = features.get(HIDDEN);
|
||||
if (hidden != null) {
|
||||
openWindowHidden = hidden.booleanValue();
|
||||
}
|
||||
Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON);
|
||||
if (hardwareBack != null) {
|
||||
hadwareBackButton = hardwareBack.booleanValue();
|
||||
}
|
||||
Boolean cache = features.get(CLEAR_ALL_CACHE);
|
||||
if (cache != null) {
|
||||
clearAllCache = cache.booleanValue();
|
||||
} else {
|
||||
cache = features.get(CLEAR_SESSION_CACHE);
|
||||
if (cache != null) {
|
||||
clearSessionCache = cache.booleanValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final CordovaWebView thatWebView = this.webView;
|
||||
|
||||
// Create dialog in new thread
|
||||
Runnable runnable = new Runnable() {
|
||||
/**
|
||||
* Convert our DIP units to Pixels
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private int dpToPixels(int dipValue) {
|
||||
int value = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP,
|
||||
(float) dipValue,
|
||||
cordova.getActivity().getResources().getDisplayMetrics()
|
||||
);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public void run() {
|
||||
// Let's create the main dialog
|
||||
dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
|
||||
dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setCancelable(true);
|
||||
dialog.setInAppBroswer(getInAppBrowser());
|
||||
|
||||
// Main container layout
|
||||
LinearLayout main = new LinearLayout(cordova.getActivity());
|
||||
main.setOrientation(LinearLayout.VERTICAL);
|
||||
|
||||
// Toolbar layout
|
||||
RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
|
||||
//Please, no more black!
|
||||
toolbar.setBackgroundColor(android.graphics.Color.LTGRAY);
|
||||
toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
|
||||
toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
|
||||
toolbar.setHorizontalGravity(Gravity.LEFT);
|
||||
toolbar.setVerticalGravity(Gravity.TOP);
|
||||
|
||||
// Action Button Container layout
|
||||
RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
|
||||
actionButtonContainer.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
|
||||
actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
|
||||
actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
|
||||
actionButtonContainer.setId(1);
|
||||
|
||||
// Back button
|
||||
Button back = new Button(cordova.getActivity());
|
||||
RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
|
||||
backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
|
||||
back.setLayoutParams(backLayoutParams);
|
||||
back.setContentDescription("Back Button");
|
||||
back.setId(2);
|
||||
Resources activityRes = cordova.getActivity().getResources();
|
||||
int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName());
|
||||
Drawable backIcon = activityRes.getDrawable(backResId);
|
||||
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
|
||||
{
|
||||
back.setBackgroundDrawable(backIcon);
|
||||
}
|
||||
else
|
||||
{
|
||||
back.setBackground(backIcon);
|
||||
}
|
||||
|
||||
back.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
goBack();
|
||||
}
|
||||
});
|
||||
|
||||
// Forward button
|
||||
Button forward = new Button(cordova.getActivity());
|
||||
RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
|
||||
forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
|
||||
forward.setLayoutParams(forwardLayoutParams);
|
||||
forward.setContentDescription("Forward Button");
|
||||
forward.setId(3);
|
||||
int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName());
|
||||
Drawable fwdIcon = activityRes.getDrawable(fwdResId);
|
||||
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
|
||||
{
|
||||
forward.setBackgroundDrawable(fwdIcon);
|
||||
}
|
||||
else
|
||||
{
|
||||
forward.setBackground(fwdIcon);
|
||||
}
|
||||
forward.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
goForward();
|
||||
}
|
||||
});
|
||||
|
||||
// Edit Text Box
|
||||
edittext = new EditText(cordova.getActivity());
|
||||
RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||
textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
|
||||
textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
|
||||
edittext.setLayoutParams(textLayoutParams);
|
||||
edittext.setId(4);
|
||||
edittext.setSingleLine(true);
|
||||
edittext.setText(url);
|
||||
edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
|
||||
edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
|
||||
edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
|
||||
edittext.setOnKeyListener(new View.OnKeyListener() {
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
// If the event is a key-down event on the "enter" button
|
||||
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
|
||||
navigate(edittext.getText().toString());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Close/Done button
|
||||
Button close = new Button(cordova.getActivity());
|
||||
RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
|
||||
closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
close.setLayoutParams(closeLayoutParams);
|
||||
forward.setContentDescription("Close Button");
|
||||
close.setId(5);
|
||||
int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName());
|
||||
Drawable closeIcon = activityRes.getDrawable(closeResId);
|
||||
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
|
||||
{
|
||||
close.setBackgroundDrawable(closeIcon);
|
||||
}
|
||||
else
|
||||
{
|
||||
close.setBackground(closeIcon);
|
||||
}
|
||||
close.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
closeDialog();
|
||||
}
|
||||
});
|
||||
|
||||
// WebView
|
||||
inAppWebView = new AmazonWebView(cordova.getActivity());
|
||||
|
||||
CordovaActivity app = (CordovaActivity) cordova.getActivity();
|
||||
cordova.getFactory().initializeWebView(inAppWebView, 0x00FF00, false, null);
|
||||
|
||||
inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
|
||||
inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
|
||||
AmazonWebViewClient client = new InAppBrowserClient(thatWebView, edittext);
|
||||
inAppWebView.setWebViewClient(client);
|
||||
AmazonWebSettings settings = inAppWebView.getSettings();
|
||||
settings.setJavaScriptEnabled(true);
|
||||
settings.setJavaScriptCanOpenWindowsAutomatically(true);
|
||||
settings.setBuiltInZoomControls(getShowZoomControls());
|
||||
settings.setPluginState(com.amazon.android.webkit.AmazonWebSettings.PluginState.ON);
|
||||
|
||||
//Toggle whether this is enabled or not!
|
||||
Bundle appSettings = cordova.getActivity().getIntent().getExtras();
|
||||
boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
|
||||
if (enableDatabase) {
|
||||
String databasePath = cordova.getActivity().getApplicationContext().getDir("inAppBrowserDB", Context.MODE_PRIVATE).getPath();
|
||||
settings.setDatabasePath(databasePath);
|
||||
settings.setDatabaseEnabled(true);
|
||||
}
|
||||
settings.setDomStorageEnabled(true);
|
||||
|
||||
if (clearAllCache) {
|
||||
AmazonCookieManager.getInstance().removeAllCookie();
|
||||
} else if (clearSessionCache) {
|
||||
AmazonCookieManager.getInstance().removeSessionCookie();
|
||||
}
|
||||
|
||||
inAppWebView.loadUrl(url);
|
||||
inAppWebView.setId(6);
|
||||
inAppWebView.getSettings().setLoadWithOverviewMode(true);
|
||||
inAppWebView.getSettings().setUseWideViewPort(true);
|
||||
inAppWebView.requestFocus();
|
||||
inAppWebView.requestFocusFromTouch();
|
||||
|
||||
// Add the back and forward buttons to our action button container layout
|
||||
actionButtonContainer.addView(back);
|
||||
actionButtonContainer.addView(forward);
|
||||
|
||||
// Add the views to our toolbar
|
||||
toolbar.addView(actionButtonContainer);
|
||||
toolbar.addView(edittext);
|
||||
toolbar.addView(close);
|
||||
|
||||
// Don't add the toolbar if its been disabled
|
||||
if (getShowLocationBar()) {
|
||||
// Add our toolbar to our main view/layout
|
||||
main.addView(toolbar);
|
||||
}
|
||||
|
||||
// Add our webview to our main view/layout
|
||||
main.addView(inAppWebView);
|
||||
|
||||
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
|
||||
lp.copyFrom(dialog.getWindow().getAttributes());
|
||||
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
|
||||
dialog.setContentView(main);
|
||||
dialog.show();
|
||||
dialog.getWindow().setAttributes(lp);
|
||||
// the goal of openhidden is to load the url and not display it
|
||||
// Show() needs to be called to cause the URL to be loaded
|
||||
if(openWindowHidden) {
|
||||
dialog.hide();
|
||||
}
|
||||
}
|
||||
};
|
||||
this.cordova.getActivity().runOnUiThread(runnable);
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin success result and send it back to JavaScript
|
||||
*
|
||||
* @param obj a JSONObject contain event payload information
|
||||
*/
|
||||
private void sendUpdate(JSONObject obj, boolean keepCallback) {
|
||||
sendUpdate(obj, keepCallback, PluginResult.Status.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin result and send it back to JavaScript
|
||||
*
|
||||
* @param obj a JSONObject contain event payload information
|
||||
* @param status the status code to return to the JavaScript environment
|
||||
*/
|
||||
private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) {
|
||||
if (callbackContext != null) {
|
||||
PluginResult result = new PluginResult(status, obj);
|
||||
result.setKeepCallback(keepCallback);
|
||||
callbackContext.sendPluginResult(result);
|
||||
if (!keepCallback) {
|
||||
callbackContext = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The webview client receives notifications about appView
|
||||
*/
|
||||
public class InAppBrowserClient extends AmazonWebViewClient {
|
||||
EditText edittext;
|
||||
CordovaWebView webView;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param mContext
|
||||
* @param edittext
|
||||
*/
|
||||
public InAppBrowserClient(CordovaWebView webView, EditText mEditText) {
|
||||
this.webView = webView;
|
||||
this.edittext = mEditText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the host application that a page has started loading.
|
||||
*
|
||||
* @param view The webview initiating the callback.
|
||||
* @param url The url of the page.
|
||||
*/
|
||||
@Override
|
||||
public void onPageStarted(AmazonWebView view, String url, Bitmap favicon) {
|
||||
super.onPageStarted(view, url, favicon);
|
||||
String newloc = "";
|
||||
if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) {
|
||||
newloc = url;
|
||||
}
|
||||
// If dialing phone (tel:5551212)
|
||||
else if (url.startsWith(AmazonWebView.SCHEME_TEL)) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL);
|
||||
intent.setData(Uri.parse(url));
|
||||
cordova.getActivity().startActivity(intent);
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
else if (url.startsWith("geo:") || url.startsWith(AmazonWebView.SCHEME_MAILTO) || url.startsWith("market:")) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(url));
|
||||
cordova.getActivity().startActivity(intent);
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
LOG.e(LOG_TAG, "Error with " + url + ": " + e.toString());
|
||||
}
|
||||
}
|
||||
// If sms:5551212?body=This is the message
|
||||
else if (url.startsWith("sms:")) {
|
||||
try {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
|
||||
// Get address
|
||||
String address = null;
|
||||
int parmIndex = url.indexOf('?');
|
||||
if (parmIndex == -1) {
|
||||
address = url.substring(4);
|
||||
}
|
||||
else {
|
||||
address = url.substring(4, parmIndex);
|
||||
|
||||
// If body, then set sms body
|
||||
Uri uri = Uri.parse(url);
|
||||
String query = uri.getQuery();
|
||||
if (query != null) {
|
||||
if (query.startsWith("body=")) {
|
||||
intent.putExtra("sms_body", query.substring(5));
|
||||
}
|
||||
}
|
||||
}
|
||||
intent.setData(Uri.parse("sms:" + address));
|
||||
intent.putExtra("address", address);
|
||||
intent.setType("vnd.android-dir/mms-sms");
|
||||
cordova.getActivity().startActivity(intent);
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
LOG.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString());
|
||||
}
|
||||
}
|
||||
else {
|
||||
newloc = "http://" + url;
|
||||
}
|
||||
|
||||
if (!newloc.equals(edittext.getText().toString())) {
|
||||
edittext.setText(newloc);
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("type", LOAD_START_EVENT);
|
||||
obj.put("url", newloc);
|
||||
|
||||
sendUpdate(obj, true);
|
||||
} catch (JSONException ex) {
|
||||
Log.d(LOG_TAG, "Should never happen");
|
||||
}
|
||||
}
|
||||
|
||||
public void onPageFinished(AmazonWebView view, String url) {
|
||||
super.onPageFinished(view, url);
|
||||
|
||||
try {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("type", LOAD_STOP_EVENT);
|
||||
obj.put("url", url);
|
||||
|
||||
sendUpdate(obj, true);
|
||||
} catch (JSONException ex) {
|
||||
Log.d(LOG_TAG, "Should never happen");
|
||||
}
|
||||
}
|
||||
|
||||
public void onReceivedError(AmazonWebView view, int errorCode, String description, String failingUrl) {
|
||||
super.onReceivedError(view, errorCode, description, failingUrl);
|
||||
|
||||
try {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("type", LOAD_ERROR_EVENT);
|
||||
obj.put("url", failingUrl);
|
||||
obj.put("code", errorCode);
|
||||
obj.put("message", description);
|
||||
|
||||
sendUpdate(obj, true, PluginResult.Status.ERROR);
|
||||
} catch (JSONException ex) {
|
||||
Log.d(LOG_TAG, "Should never happen");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,146 +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.
|
||||
*/
|
||||
package org.apache.cordova.inappbrowser;
|
||||
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.apache.cordova.LOG;
|
||||
import org.apache.cordova.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import com.amazon.android.webkit.AmazonWebChromeClient;
|
||||
import com.amazon.android.webkit.AmazonGeolocationPermissions.Callback;
|
||||
import com.amazon.android.webkit.AmazonJsPromptResult;
|
||||
import com.amazon.android.webkit.AmazonWebStorage;
|
||||
import com.amazon.android.webkit.AmazonWebView;
|
||||
import com.amazon.android.webkit.AmazonWebViewClient;
|
||||
|
||||
public class InAppChromeClient extends AmazonWebChromeClient {
|
||||
|
||||
private CordovaWebView webView;
|
||||
private String LOG_TAG = "InAppChromeClient";
|
||||
private long MAX_QUOTA = 100 * 1024 * 1024;
|
||||
|
||||
public InAppChromeClient(CordovaWebView webView) {
|
||||
super();
|
||||
this.webView = webView;
|
||||
}
|
||||
/**
|
||||
* Handle database quota exceeded notification.
|
||||
*
|
||||
* @param url
|
||||
* @param databaseIdentifier
|
||||
* @param currentQuota
|
||||
* @param estimatedSize
|
||||
* @param totalUsedQuota
|
||||
* @param quotaUpdater
|
||||
*/
|
||||
@Override
|
||||
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize,
|
||||
long totalUsedQuota, AmazonWebStorage.QuotaUpdater quotaUpdater)
|
||||
{
|
||||
LOG.d(LOG_TAG, "onExceededDatabaseQuota estimatedSize: %d currentQuota: %d totalUsedQuota: %d", estimatedSize, currentQuota, totalUsedQuota);
|
||||
|
||||
if (estimatedSize < MAX_QUOTA)
|
||||
{
|
||||
//increase for 1Mb
|
||||
long newQuota = estimatedSize;
|
||||
LOG.d(LOG_TAG, "calling quotaUpdater.updateQuota newQuota: %d", newQuota);
|
||||
quotaUpdater.updateQuota(newQuota);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the quota to whatever it is and force an error
|
||||
// TODO: get docs on how to handle this properly
|
||||
quotaUpdater.updateQuota(currentQuota);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instructs the client to show a prompt to ask the user to set the Geolocation permission state for the specified origin.
|
||||
*
|
||||
* @param origin
|
||||
* @param callback
|
||||
*/
|
||||
@Override
|
||||
public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
|
||||
super.onGeolocationPermissionsShowPrompt(origin, callback);
|
||||
callback.invoke(origin, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell the client to display a prompt dialog to the user.
|
||||
* If the client returns true, WebView will assume that the client will
|
||||
* handle the prompt dialog and call the appropriate JsPromptResult method.
|
||||
*
|
||||
* The prompt bridge provided for the InAppBrowser is capable of executing any
|
||||
* oustanding callback belonging to the InAppBrowser plugin. Care has been
|
||||
* taken that other callbacks cannot be triggered, and that no other code
|
||||
* execution is possible.
|
||||
*
|
||||
* To trigger the bridge, the prompt default value should be of the form:
|
||||
*
|
||||
* gap-iab://<callbackId>
|
||||
*
|
||||
* where <callbackId> is the string id of the callback to trigger (something
|
||||
* like "InAppBrowser0123456789")
|
||||
*
|
||||
* If present, the prompt message is expected to be a JSON-encoded value to
|
||||
* pass to the callback. A JSON_EXCEPTION is returned if the JSON is invalid.
|
||||
*
|
||||
* @param view
|
||||
* @param url
|
||||
* @param message
|
||||
* @param defaultValue
|
||||
* @param result
|
||||
*/
|
||||
@Override
|
||||
public boolean onJsPrompt(AmazonWebView view, String url, String message, String defaultValue, AmazonJsPromptResult result) {
|
||||
// See if the prompt string uses the 'gap-iab' protocol. If so, the remainder should be the id of a callback to execute.
|
||||
if (defaultValue != null && defaultValue.startsWith("gap")) {
|
||||
if(defaultValue.startsWith("gap-iab://")) {
|
||||
PluginResult scriptResult;
|
||||
String scriptCallbackId = defaultValue.substring(10);
|
||||
if (scriptCallbackId.startsWith("InAppBrowser")) {
|
||||
if(message == null || message.length() == 0) {
|
||||
scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray());
|
||||
} else {
|
||||
try {
|
||||
scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray(message));
|
||||
} catch(JSONException e) {
|
||||
scriptResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
|
||||
}
|
||||
}
|
||||
this.webView.sendPluginResult(scriptResult, scriptCallbackId);
|
||||
result.confirm("");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Anything else with a gap: prefix should get this message
|
||||
LOG.w(LOG_TAG, "InAppBrowser does not support Cordova API calls: " + url + " " + defaultValue);
|
||||
result.cancel();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,9 @@ import android.provider.Browser;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -51,6 +54,7 @@ import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.Config;
|
||||
@@ -67,6 +71,8 @@ import org.json.JSONObject;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
@@ -91,6 +97,16 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
private static final String SHOULD_PAUSE = "shouldPauseOnSuspend";
|
||||
private static final Boolean DEFAULT_HARDWARE_BACK = true;
|
||||
private static final String USER_WIDE_VIEW_PORT = "useWideViewPort";
|
||||
private static final String TOOLBAR_COLOR = "toolbarcolor";
|
||||
private static final String CLOSE_BUTTON_CAPTION = "closebuttoncaption";
|
||||
private static final String CLOSE_BUTTON_COLOR = "closebuttoncolor";
|
||||
private static final String HIDE_NAVIGATION = "hidenavigationbuttons";
|
||||
private static final String NAVIGATION_COLOR = "navigationbuttoncolor";
|
||||
private static final String HIDE_URL = "hideurlbar";
|
||||
private static final String FOOTER = "footer";
|
||||
private static final String FOOTER_COLOR = "footercolor";
|
||||
|
||||
private static final List customizableOptions = Arrays.asList(CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR, FOOTER_COLOR);
|
||||
|
||||
private InAppBrowserDialog dialog;
|
||||
private WebView inAppWebView;
|
||||
@@ -109,6 +125,14 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
private ValueCallback<Uri[]> mUploadCallbackLollipop;
|
||||
private final static int FILECHOOSER_REQUESTCODE = 1;
|
||||
private final static int FILECHOOSER_REQUESTCODE_LOLLIPOP = 2;
|
||||
private String closeButtonCaption = "";
|
||||
private String closeButtonColor = "";
|
||||
private int toolbarColor = android.graphics.Color.LTGRAY;
|
||||
private boolean hideNavigationButtons = false;
|
||||
private String navigationButtonColor = "";
|
||||
private boolean hideUrlBar = false;
|
||||
private boolean showFooter = false;
|
||||
private String footerColor = "";
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
@@ -127,7 +151,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
t = SELF;
|
||||
}
|
||||
final String target = t;
|
||||
final HashMap<String, Boolean> features = parseFeature(args.optString(2));
|
||||
final HashMap<String, String> features = parseFeature(args.optString(2));
|
||||
|
||||
LOG.d(LOG_TAG, "target = " + target);
|
||||
|
||||
@@ -366,18 +390,21 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
* @param optString
|
||||
* @return
|
||||
*/
|
||||
private HashMap<String, Boolean> parseFeature(String optString) {
|
||||
private HashMap<String, String> parseFeature(String optString) {
|
||||
if (optString.equals(NULL)) {
|
||||
return null;
|
||||
} else {
|
||||
HashMap<String, Boolean> map = new HashMap<String, Boolean>();
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
StringTokenizer features = new StringTokenizer(optString, ",");
|
||||
StringTokenizer option;
|
||||
while(features.hasMoreElements()) {
|
||||
option = new StringTokenizer(features.nextToken(), "=");
|
||||
if (option.hasMoreElements()) {
|
||||
String key = option.nextToken();
|
||||
Boolean value = option.nextToken().equals("no") ? Boolean.FALSE : Boolean.TRUE;
|
||||
String value = option.nextToken();
|
||||
if (!customizableOptions.contains(key)){
|
||||
value = value.equals("yes") || value.equals("no") ? value : "yes";
|
||||
}
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
@@ -406,7 +433,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
|
||||
this.cordova.getActivity().startActivity(intent);
|
||||
return "";
|
||||
// not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
|
||||
// not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
|
||||
} catch (java.lang.RuntimeException e) {
|
||||
LOG.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
|
||||
return e.toString();
|
||||
@@ -523,7 +550,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
* @param url the url to load.
|
||||
* @param features jsonObject
|
||||
*/
|
||||
public String showWebPage(final String url, HashMap<String, Boolean> features) {
|
||||
public String showWebPage(final String url, HashMap<String, String> features) {
|
||||
// Determine if we should hide the location bar.
|
||||
showLocationBar = true;
|
||||
showZoomControls = true;
|
||||
@@ -531,44 +558,74 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
mediaPlaybackRequiresUserGesture = false;
|
||||
|
||||
if (features != null) {
|
||||
Boolean show = features.get(LOCATION);
|
||||
String show = features.get(LOCATION);
|
||||
if (show != null) {
|
||||
showLocationBar = show.booleanValue();
|
||||
showLocationBar = show.equals("yes") ? true : false;
|
||||
}
|
||||
Boolean zoom = features.get(ZOOM);
|
||||
if(showLocationBar) {
|
||||
String hideNavigation = features.get(HIDE_NAVIGATION);
|
||||
String hideUrl = features.get(HIDE_URL);
|
||||
if(hideNavigation != null) hideNavigationButtons = hideNavigation.equals("yes") ? true : false;
|
||||
if(hideUrl != null) hideUrlBar = hideUrl.equals("yes") ? true : false;
|
||||
}
|
||||
String zoom = features.get(ZOOM);
|
||||
if (zoom != null) {
|
||||
showZoomControls = zoom.booleanValue();
|
||||
showZoomControls = zoom.equals("yes") ? true : false;
|
||||
}
|
||||
Boolean hidden = features.get(HIDDEN);
|
||||
String hidden = features.get(HIDDEN);
|
||||
if (hidden != null) {
|
||||
openWindowHidden = hidden.booleanValue();
|
||||
openWindowHidden = hidden.equals("yes") ? true : false;
|
||||
}
|
||||
Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON);
|
||||
String hardwareBack = features.get(HARDWARE_BACK_BUTTON);
|
||||
if (hardwareBack != null) {
|
||||
hadwareBackButton = hardwareBack.booleanValue();
|
||||
hadwareBackButton = hardwareBack.equals("yes") ? true : false;
|
||||
} else {
|
||||
hadwareBackButton = DEFAULT_HARDWARE_BACK;
|
||||
}
|
||||
Boolean mediaPlayback = features.get(MEDIA_PLAYBACK_REQUIRES_USER_ACTION);
|
||||
String mediaPlayback = features.get(MEDIA_PLAYBACK_REQUIRES_USER_ACTION);
|
||||
if (mediaPlayback != null) {
|
||||
mediaPlaybackRequiresUserGesture = mediaPlayback.booleanValue();
|
||||
mediaPlaybackRequiresUserGesture = mediaPlayback.equals("yes") ? true : false;
|
||||
}
|
||||
Boolean cache = features.get(CLEAR_ALL_CACHE);
|
||||
String cache = features.get(CLEAR_ALL_CACHE);
|
||||
if (cache != null) {
|
||||
clearAllCache = cache.booleanValue();
|
||||
clearAllCache = cache.equals("yes") ? true : false;
|
||||
} else {
|
||||
cache = features.get(CLEAR_SESSION_CACHE);
|
||||
if (cache != null) {
|
||||
clearSessionCache = cache.booleanValue();
|
||||
clearSessionCache = cache.equals("yes") ? true : false;
|
||||
}
|
||||
}
|
||||
Boolean shouldPause = features.get(SHOULD_PAUSE);
|
||||
String shouldPause = features.get(SHOULD_PAUSE);
|
||||
if (shouldPause != null) {
|
||||
shouldPauseInAppBrowser = shouldPause.booleanValue();
|
||||
shouldPauseInAppBrowser = shouldPause.equals("yes") ? true : false;
|
||||
}
|
||||
Boolean wideViewPort = features.get(USER_WIDE_VIEW_PORT);
|
||||
String wideViewPort = features.get(USER_WIDE_VIEW_PORT);
|
||||
if (wideViewPort != null ) {
|
||||
useWideViewPort = wideViewPort.booleanValue();
|
||||
useWideViewPort = wideViewPort.equals("yes") ? true : false;
|
||||
}
|
||||
String closeButtonCaptionSet = features.get(CLOSE_BUTTON_CAPTION);
|
||||
if (closeButtonCaptionSet != null) {
|
||||
closeButtonCaption = closeButtonCaptionSet;
|
||||
}
|
||||
String closeButtonColorSet = features.get(CLOSE_BUTTON_COLOR);
|
||||
if (closeButtonColorSet != null) {
|
||||
closeButtonColor = closeButtonColorSet;
|
||||
}
|
||||
String toolbarColorSet = features.get(TOOLBAR_COLOR);
|
||||
if (toolbarColorSet != null) {
|
||||
toolbarColor = android.graphics.Color.parseColor(toolbarColorSet);
|
||||
}
|
||||
String navigationButtonColorSet = features.get(NAVIGATION_COLOR);
|
||||
if (navigationButtonColorSet != null) {
|
||||
navigationButtonColor = navigationButtonColorSet;
|
||||
}
|
||||
String showFooterSet = features.get(FOOTER);
|
||||
if (showFooterSet != null) {
|
||||
showFooter = showFooterSet.equals("yes") ? true : false;
|
||||
}
|
||||
String footerColorSet = features.get(FOOTER_COLOR);
|
||||
if (footerColorSet != null) {
|
||||
footerColor = footerColorSet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -583,13 +640,60 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
*/
|
||||
private int dpToPixels(int dipValue) {
|
||||
int value = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP,
|
||||
(float) dipValue,
|
||||
cordova.getActivity().getResources().getDisplayMetrics()
|
||||
(float) dipValue,
|
||||
cordova.getActivity().getResources().getDisplayMetrics()
|
||||
);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private View createCloseButton(int id){
|
||||
View _close;
|
||||
Resources activityRes = cordova.getActivity().getResources();
|
||||
|
||||
if (closeButtonCaption != "") {
|
||||
// Use TextView for text
|
||||
TextView close = new TextView(cordova.getActivity());
|
||||
close.setText(closeButtonCaption);
|
||||
close.setTextSize(20);
|
||||
if (closeButtonColor != "") close.setTextColor(android.graphics.Color.parseColor(closeButtonColor));
|
||||
close.setGravity(android.view.Gravity.CENTER_VERTICAL);
|
||||
close.setPadding(this.dpToPixels(10), 0, this.dpToPixels(10), 0);
|
||||
_close = close;
|
||||
}
|
||||
else {
|
||||
ImageButton close = new ImageButton(cordova.getActivity());
|
||||
int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName());
|
||||
Drawable closeIcon = activityRes.getDrawable(closeResId);
|
||||
if (closeButtonColor != "") close.setColorFilter(android.graphics.Color.parseColor(closeButtonColor));
|
||||
close.setImageDrawable(closeIcon);
|
||||
close.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||
if (Build.VERSION.SDK_INT >= 16)
|
||||
close.getAdjustViewBounds();
|
||||
|
||||
_close = close;
|
||||
}
|
||||
|
||||
RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
|
||||
closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
_close.setLayoutParams(closeLayoutParams);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 16)
|
||||
_close.setBackground(null);
|
||||
else
|
||||
_close.setBackgroundDrawable(null);
|
||||
|
||||
_close.setContentDescription("Close Button");
|
||||
_close.setId(Integer.valueOf(id));
|
||||
_close.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
closeDialog();
|
||||
}
|
||||
});
|
||||
|
||||
return _close;
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public void run() {
|
||||
|
||||
@@ -612,7 +716,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
// Toolbar layout
|
||||
RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
|
||||
//Please, no more black!
|
||||
toolbar.setBackgroundColor(android.graphics.Color.LTGRAY);
|
||||
toolbar.setBackgroundColor(toolbarColor);
|
||||
toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
|
||||
toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
|
||||
toolbar.setHorizontalGravity(Gravity.LEFT);
|
||||
@@ -635,6 +739,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
Resources activityRes = cordova.getActivity().getResources();
|
||||
int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName());
|
||||
Drawable backIcon = activityRes.getDrawable(backResId);
|
||||
if (navigationButtonColor != "") back.setColorFilter(android.graphics.Color.parseColor(navigationButtonColor));
|
||||
if (Build.VERSION.SDK_INT >= 16)
|
||||
back.setBackground(null);
|
||||
else
|
||||
@@ -660,6 +765,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
forward.setId(Integer.valueOf(3));
|
||||
int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName());
|
||||
Drawable fwdIcon = activityRes.getDrawable(fwdResId);
|
||||
if (navigationButtonColor != "") forward.setColorFilter(android.graphics.Color.parseColor(navigationButtonColor));
|
||||
if (Build.VERSION.SDK_INT >= 16)
|
||||
forward.setBackground(null);
|
||||
else
|
||||
@@ -692,37 +798,37 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
// If the event is a key-down event on the "enter" button
|
||||
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
|
||||
navigate(edittext.getText().toString());
|
||||
return true;
|
||||
navigate(edittext.getText().toString());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Close/Done button
|
||||
ImageButton close = new ImageButton(cordova.getActivity());
|
||||
RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
|
||||
closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
close.setLayoutParams(closeLayoutParams);
|
||||
close.setContentDescription("Close Button");
|
||||
close.setId(Integer.valueOf(5));
|
||||
int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName());
|
||||
Drawable closeIcon = activityRes.getDrawable(closeResId);
|
||||
if (Build.VERSION.SDK_INT >= 16)
|
||||
close.setBackground(null);
|
||||
else
|
||||
close.setBackgroundDrawable(null);
|
||||
close.setImageDrawable(closeIcon);
|
||||
close.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||
back.setPadding(0, this.dpToPixels(10), 0, this.dpToPixels(10));
|
||||
if (Build.VERSION.SDK_INT >= 16)
|
||||
close.getAdjustViewBounds();
|
||||
|
||||
close.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
closeDialog();
|
||||
}
|
||||
});
|
||||
// Header Close/Done button
|
||||
View close = createCloseButton(5);
|
||||
toolbar.addView(close);
|
||||
|
||||
// Footer
|
||||
RelativeLayout footer = new RelativeLayout(cordova.getActivity());
|
||||
int _footerColor;
|
||||
if(footerColor != ""){
|
||||
_footerColor = Color.parseColor(footerColor);
|
||||
}else{
|
||||
_footerColor = android.graphics.Color.LTGRAY;
|
||||
}
|
||||
footer.setBackgroundColor(_footerColor);
|
||||
RelativeLayout.LayoutParams footerLayout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44));
|
||||
footerLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
|
||||
footer.setLayoutParams(footerLayout);
|
||||
if (closeButtonCaption != "") footer.setPadding(this.dpToPixels(8), this.dpToPixels(8), this.dpToPixels(8), this.dpToPixels(8));
|
||||
footer.setHorizontalGravity(Gravity.LEFT);
|
||||
footer.setVerticalGravity(Gravity.BOTTOM);
|
||||
|
||||
View footerClose = createCloseButton(7);
|
||||
footer.addView(footerClose);
|
||||
|
||||
|
||||
// WebView
|
||||
inAppWebView = new WebView(cordova.getActivity());
|
||||
@@ -809,6 +915,11 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
CookieManager.getInstance().removeSessionCookie();
|
||||
}
|
||||
|
||||
// Enable Thirdparty Cookies on >=Android 5.0 device
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
||||
CookieManager.getInstance().setAcceptThirdPartyCookies(inAppWebView,true);
|
||||
}
|
||||
|
||||
inAppWebView.loadUrl(url);
|
||||
inAppWebView.setId(Integer.valueOf(6));
|
||||
inAppWebView.getSettings().setLoadWithOverviewMode(true);
|
||||
@@ -820,10 +931,9 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
actionButtonContainer.addView(back);
|
||||
actionButtonContainer.addView(forward);
|
||||
|
||||
// Add the views to our toolbar
|
||||
toolbar.addView(actionButtonContainer);
|
||||
toolbar.addView(edittext);
|
||||
toolbar.addView(close);
|
||||
// Add the views to our toolbar if they haven't been disabled
|
||||
if (!hideNavigationButtons) toolbar.addView(actionButtonContainer);
|
||||
if (!hideUrlBar) toolbar.addView(edittext);
|
||||
|
||||
// Don't add the toolbar if its been disabled
|
||||
if (getShowLocationBar()) {
|
||||
@@ -832,7 +942,14 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
}
|
||||
|
||||
// Add our webview to our main view/layout
|
||||
main.addView(inAppWebView);
|
||||
RelativeLayout webViewLayout = new RelativeLayout(cordova.getActivity());
|
||||
webViewLayout.addView(inAppWebView);
|
||||
main.addView(webViewLayout);
|
||||
|
||||
// Don't add the footer unless it's been enabled
|
||||
if (showFooter) {
|
||||
webViewLayout.addView(footer);
|
||||
}
|
||||
|
||||
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
|
||||
lp.copyFrom(dialog.getWindow().getAttributes());
|
||||
@@ -1022,7 +1139,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
// Update the UI if we haven't already
|
||||
if (!newloc.equals(edittext.getText().toString())) {
|
||||
edittext.setText(newloc);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject obj = new JSONObject();
|
||||
@@ -1046,6 +1163,10 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
CookieSyncManager.getInstance().sync();
|
||||
}
|
||||
|
||||
// https://issues.apache.org/jira/browse/CB-11248
|
||||
view.clearFocus();
|
||||
view.requestFocus();
|
||||
|
||||
try {
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("type", LOAD_STOP_EVENT);
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
<!---
|
||||
license: 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.
|
||||
-->
|
||||
# BlackBerry 10 In-App-Browser Plugin
|
||||
|
||||
The in app browser functionality is entirely contained within common js. There is no native implementation required.
|
||||
To install this plugin, follow the [Command-line Interface Guide](http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface).
|
||||
|
||||
If you are not using the Cordova Command-line Interface, follow [Using Plugman to Manage Plugins](http://cordova.apache.org/docs/en/edge/guide_plugin_ref_plugman.md.html).
|
||||
./cordova-plugin-battery-status/README.md
|
||||
./cordova-plugin-camera/README.md
|
||||
./cordova-plugin-console/README.md
|
||||
./cordova-plugin-contacts/README.md
|
||||
./cordova-plugin-device/README.md
|
||||
./cordova-plugin-device-motion/README.md
|
||||
./cordova-plugin-device-orientation/README.md
|
||||
./cordova-plugin-device-orientation/src/blackberry10/README.md
|
||||
./cordova-plugin-file/README.md
|
||||
./cordova-plugin-file-transfer/README.md
|
||||
./cordova-plugin-geolocation/README.md
|
||||
./cordova-plugin-globalization/README.md
|
||||
./cordova-plugin-inappbrowser/README.md
|
||||
./cordova-plugin-inappbrowser/src/blackberry10/README.md
|
||||
./cordova-plugin-media/README.md
|
||||
./cordova-plugin-media-capture/README.md
|
||||
./cordova-plugin-network-information/README.md
|
||||
./cordova-plugin-splashscreen/README.md
|
||||
./cordova-plugin-vibration/README.md
|
||||
@@ -1,24 +0,0 @@
|
||||
<!---
|
||||
license: 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.
|
||||
-->
|
||||
|
||||
# BlackBerry 10-In-App-Browser-Plugin
|
||||
|
||||
Die Funktionalität ist im app-Browser vollständig in gemeinsamen Js enthalten. Es gibt keine native Implementierung benötigt. Um dieses Plugin zu installieren, folgen Sie dem [Command-Line Interface Guide](http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface).
|
||||
|
||||
Wenn Sie nicht die Cordova-Befehlszeilenschnittstelle verwenden, folgen Sie [Verwenden Plugman zu Plugins verwalten](http://cordova.apache.org/docs/en/edge/guide_plugin_ref_plugman.md.html). ./cordova-plugin-battery-status/README.md ./cordova-plugin-camera/README.md ./cordova-plugin-console/README.md ./cordova-plugin-contacts/README.md ./cordova-plugin-device/README.md ./cordova-plugin-device-motion/README.md ./cordova-plugin-device-orientation/README.md ./cordova-plugin-device-orientation/src/blackberry10/README.md ./cordova-plugin-file/README.md ./cordova-plugin-file-transfer/README.md ./cordova-plugin-geolocation/README.md ./cordova-plugin-globalization/README.md ./cordova-plugin-inappbrowser/README.md ./cordova-plugin-inappbrowser/src/blackberry10/README.md ./cordova-plugin-media/README.md ./cordova-plugin-media-capture/README.md ./cordova-plugin-network-information/README.md ./cordova-plugin-splashscreen/README.md ./cordova-plugin-vibration/README.md
|
||||
@@ -1,24 +0,0 @@
|
||||
<!---
|
||||
license: 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.
|
||||
-->
|
||||
|
||||
# BlackBerry 10 In-App-Browser Plugin
|
||||
|
||||
El en el navegador de aplicación funcionalidad está enteramente dentro de js común. No hay ninguna aplicación nativa necesaria. Para instalar este plugin, siga la [Guía de la interfaz de línea de comandos](http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface).
|
||||
|
||||
Si no utiliza la interfaz de línea de comandos de Cordova, siga [Usando Plugman para gestionar Plugins](http://cordova.apache.org/docs/en/edge/guide_plugin_ref_plugman.md.html). ./cordova-plugin-battery-status/README.md ./cordova-plugin-camera/README.md ./cordova-plugin-console/README.md ./cordova-plugin-contacts/README.md ./cordova-plugin-device/README.md ./cordova-plugin-device-motion/README.md ./cordova-plugin-device-orientation/README.md ./cordova-plugin-device-orientation/src/blackberry10/README.md ./cordova-plugin-file/README.md ./cordova-plugin-file-transfer/README.md ./cordova-plugin-geolocation/README.md ./cordova-plugin-globalization/README.md ./cordova-plugin-inappbrowser/README.md ./cordova-plugin-inappbrowser/src/blackberry10/README.md ./cordova-plugin-media/README.md ./cordova-plugin-media-capture/README.md ./cordova-plugin-network-information/README.md ./cordova-plugin-splashscreen/README.md ./cordova-plugin-vibration/README.md
|
||||
@@ -1,24 +0,0 @@
|
||||
<!---
|
||||
license: 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.
|
||||
-->
|
||||
|
||||
# BlackBerry 10 In-App-Browser Plugin
|
||||
|
||||
Le dans le navigateur de l'application, la fonctionnalité est entièrement contenue dans js commun. Il n'y a aucune implémentation native requise. Pour installer ce plugin, suivez le [Guide de l'Interface de ligne de commande](http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface).
|
||||
|
||||
Si vous n'utilisez pas l'Interface de ligne de commande de Cordova, suivez [Les Plugman à l'aide à gérer les Plugins](http://cordova.apache.org/docs/en/edge/guide_plugin_ref_plugman.md.html). ./cordova-plugin-battery-status/README.md ./cordova-plugin-camera/README.md ./cordova-plugin-console/README.md ./cordova-plugin-contacts/README.md ./cordova-plugin-device/README.md ./cordova-plugin-device-motion/README.md ./cordova-plugin-device-orientation/README.md ./cordova-plugin-device-orientation/src/blackberry10/README.md ./cordova-plugin-file/README.md ./cordova-plugin-file-transfer/README.md ./cordova-plugin-geolocation/README.md ./cordova-plugin-globalization/README.md ./cordova-plugin-inappbrowser/README.md ./cordova-plugin-inappbrowser/src/blackberry10/README.md ./cordova-plugin-media/README.md ./cordova-plugin-media-capture/README.md ./cordova-plugin-network-information/README.md ./cordova-plugin-splashscreen/README.md ./cordova-plugin-vibration/README.md
|
||||
@@ -1,24 +0,0 @@
|
||||
<!---
|
||||
license: 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.
|
||||
-->
|
||||
|
||||
# BlackBerry 10 In-App-Browser Plugin
|
||||
|
||||
Il browser app funzionalità è interamente contenuta nel comune js. Non esiste alcuna implementazione nativa richiesto. Per installare questo plugin, seguire la [Guida per l'interfaccia della riga di comando](http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface).
|
||||
|
||||
Se non si utilizza l'interfaccia della riga di comando di Cordova, seguire [Utilizzando Plugman per gestire i plugin](http://cordova.apache.org/docs/en/edge/guide_plugin_ref_plugman.md.html). ./cordova-plugin-battery-status/README.md ./cordova-plugin-camera/README.md ./cordova-plugin-console/README.md ./cordova-plugin-contacts/README.md ./cordova-plugin-device/README.md ./cordova-plugin-device-motion/README.md ./cordova-plugin-device-orientation/README.md ./cordova-plugin-device-orientation/src/blackberry10/README.md ./cordova-plugin-file/README.md ./cordova-plugin-file-transfer/README.md ./cordova-plugin-geolocation/README.md ./cordova-plugin-globalization/README.md ./cordova-plugin-inappbrowser/README.md ./cordova-plugin-inappbrowser/src/blackberry10/README.md ./cordova-plugin-media/README.md ./cordova-plugin-media-capture/README.md ./cordova-plugin-network-information/README.md ./cordova-plugin-splashscreen/README.md ./cordova-plugin-vibration/README.md
|
||||
@@ -1,24 +0,0 @@
|
||||
<!---
|
||||
license: 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.
|
||||
-->
|
||||
|
||||
# BlackBerry 10 In-App-Browser Plugin
|
||||
|
||||
アプリケーション ブラウザーの機能は全く一般的な js に含まれています。 ネイティブ実装する必要はありません。 このプラグインをインストールするには[コマンド ライン インターフェイス ガイド](http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface).
|
||||
|
||||
コルドバのコマンド ライン インターフェイスを使用していない場合は場合、[管理のプラグインを使用して Plugman](http://cordova.apache.org/docs/en/edge/guide_plugin_ref_plugman.md.html)に従ってください。 ./cordova-plugin-battery-status/README.md ./cordova-plugin-camera/README.md ./cordova-plugin-console/README.md ./cordova-plugin-contacts/README.md ./cordova-plugin-device/README.md ./cordova-plugin-device-motion/README.md ./cordova-plugin-device-orientation/README.md ./cordova-plugin-device-orientation/src/blackberry10/README.md ./cordova-plugin-file/README.md ./cordova-plugin-file-transfer/README.md ./cordova-plugin-geolocation/README.md ./cordova-plugin-globalization/README.md ./cordova-plugin-inappbrowser/README.md ./cordova-plugin-inappbrowser/src/blackberry10/README.md ./cordova-plugin-media/README.md ./cordova-plugin-media-capture/README.md ./cordova-plugin-network-information/README.md ./cordova-plugin-splashscreen/README.md ./cordova-plugin-vibration/README.md
|
||||
@@ -1,24 +0,0 @@
|
||||
<!---
|
||||
license: 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.
|
||||
-->
|
||||
|
||||
# 블랙베리 10 애플 리 케이 션-브라우저 플러그인
|
||||
|
||||
응용 프로그램 브라우저에서 기능은 완전히 포함 된 일반적인 js. 필요 없는 기본 구현이입니다. 이 플러그인을 설치 하려면 [명령줄 인터페이스 가이드](http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface) 를 따라합니다.
|
||||
|
||||
코르도바 명령줄 인터페이스를 사용 하지 않는 경우 [관리 플러그인을 사용 하 여 Plugman](http://cordova.apache.org/docs/en/edge/guide_plugin_ref_plugman.md.html)를 따르십시오. ./cordova-plugin-battery-status/README.md ./cordova-plugin-camera/README.md ./cordova-plugin-console/README.md ./cordova-plugin-contacts/README.md ./cordova-plugin-device/README.md ./cordova-plugin-device-motion/README.md ./cordova-plugin-device-orientation/README.md ./cordova-plugin-device-orientation/src/blackberry10/README.md ./cordova-plugin-file/README.md ./cordova-plugin-file-transfer/README.md ./cordova-plugin-geolocation/README.md ./cordova-plugin-globalization/README.md ./cordova-plugin-inappbrowser/README.md ./cordova-plugin-inappbrowser/src/blackberry10/README.md ./cordova-plugin-media/README.md ./cordova-plugin-media-capture/README.md ./cordova-plugin-network-information/README.md ./cordova-plugin-splashscreen/README.md ./cordova-plugin-vibration/README.md
|
||||
@@ -1,24 +0,0 @@
|
||||
<!---
|
||||
license: 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.
|
||||
-->
|
||||
|
||||
# BlackBerry 10 In-App-Browser Plugin
|
||||
|
||||
W aplikacji Przeglądarka funkcjonalność jest całkowicie zawarty w wspólnej js. Tam jest nie native wdrażania wymagane. Aby zainstalować ten plugin, następować po ten [Przewodnik interfejsu wiersza polecenia](http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface).
|
||||
|
||||
Jeśli nie używasz interfejsu wiersza polecenia Cordova, następować po [Przy użyciu Plugman do zarządzania wtyczki](http://cordova.apache.org/docs/en/edge/guide_plugin_ref_plugman.md.html). ./cordova-plugin-battery-status/README.md ./cordova-plugin-camera/README.md ./cordova-plugin-console/README.md ./cordova-plugin-contacts/README.md ./cordova-plugin-device/README.md ./cordova-plugin-device-motion/README.md ./cordova-plugin-device-orientation/README.md ./cordova-plugin-device-orientation/src/blackberry10/README.md ./cordova-plugin-file/README.md ./cordova-plugin-file-transfer/README.md ./cordova-plugin-geolocation/README.md ./cordova-plugin-globalization/README.md ./cordova-plugin-inappbrowser/README.md ./cordova-plugin-inappbrowser/src/blackberry10/README.md ./cordova-plugin-media/README.md ./cordova-plugin-media-capture/README.md ./cordova-plugin-network-information/README.md ./cordova-plugin-splashscreen/README.md ./cordova-plugin-vibration/README.md
|
||||
@@ -1,24 +0,0 @@
|
||||
<!---
|
||||
license: 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.
|
||||
-->
|
||||
|
||||
# 黑莓 10 的應用程式瀏覽器外掛程式
|
||||
|
||||
在應用程式瀏覽器功能完全包含在常見的 js。 還有沒有本機的實施所需。 若要安裝此外掛程式,請按照[命令列介面指南](http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface).
|
||||
|
||||
如果你不使用的科爾多瓦命令列介面,請按照[使用 Plugman 管理外掛程式](http://cordova.apache.org/docs/en/edge/guide_plugin_ref_plugman.md.html)。 ./cordova-plugin-battery-status/README.md ./cordova-plugin-camera/README.md ./cordova-plugin-console/README.md ./cordova-plugin-contacts/README.md ./cordova-plugin-device/README.md ./cordova-plugin-device-motion/README.md ./cordova-plugin-device-orientation/README.md ./cordova-plugin-device-orientation/src/blackberry10/README.md ./cordova-plugin-file/README.md ./cordova-plugin-file-transfer/README.md ./cordova-plugin-geolocation/README.md ./cordova-plugin-globalization/README.md ./cordova-plugin-inappbrowser/README.md ./cordova-plugin-inappbrowser/src/blackberry10/README.md ./cordova-plugin-media/README.md ./cordova-plugin-media-capture/README.md ./cordova-plugin-network-information/README.md ./cordova-plugin-splashscreen/README.md ./cordova-plugin-vibration/README.md
|
||||
@@ -29,27 +29,43 @@ var browserWrap,
|
||||
forwardButton,
|
||||
closeButton;
|
||||
|
||||
function attachNavigationEvents(element, callback) {
|
||||
function attachNavigationEvents (element, callback) {
|
||||
var onError = function () {
|
||||
callback({ type: "loaderror", url: this.contentWindow.location}, {keepCallback: true});
|
||||
try {
|
||||
callback({ type: 'loaderror', url: this.contentWindow.location.href }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
|
||||
} catch (err) {
|
||||
// blocked by CORS :\
|
||||
callback({ type: 'loaderror', url: null }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
|
||||
}
|
||||
};
|
||||
|
||||
element.addEventListener("pageshow", function () {
|
||||
callback({ type: "loadstart", url: this.contentWindow.location}, {keepCallback: true});
|
||||
element.addEventListener('pageshow', function () {
|
||||
try {
|
||||
callback({ type: 'loadstart', url: this.contentWindow.location.href }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
|
||||
} catch (err) {
|
||||
// blocked by CORS :\
|
||||
callback({ type: 'loadstart', url: null }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
|
||||
}
|
||||
});
|
||||
|
||||
element.addEventListener("load", function () {
|
||||
callback({ type: "loadstop", url: this.contentWindow.location}, {keepCallback: true});
|
||||
element.addEventListener('load', function () {
|
||||
try {
|
||||
callback({ type: 'loadstop', url: this.contentWindow.location.href }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
|
||||
} catch (err) {
|
||||
// blocked by CORS :\
|
||||
callback({ type: 'loadstop', url: null }, {keepCallback: true}); // eslint-disable-line standard/no-callback-literal
|
||||
}
|
||||
});
|
||||
|
||||
element.addEventListener("error", onError);
|
||||
element.addEventListener("abort", onError);
|
||||
element.addEventListener('error', onError);
|
||||
element.addEventListener('abort', onError);
|
||||
}
|
||||
|
||||
var IAB = {
|
||||
close: function (win, lose) {
|
||||
if (browserWrap) {
|
||||
if (win) win({ type: "exit" });
|
||||
// use the "open" function callback so that the exit event is fired properly
|
||||
if (IAB._win) IAB._win({ type: 'exit' });
|
||||
|
||||
browserWrap.parentNode.removeChild(browserWrap);
|
||||
browserWrap = null;
|
||||
@@ -59,109 +75,108 @@ var IAB = {
|
||||
|
||||
show: function (win, lose) {
|
||||
if (browserWrap) {
|
||||
browserWrap.style.display = "block";
|
||||
browserWrap.style.display = 'block';
|
||||
}
|
||||
},
|
||||
|
||||
open: function (win, lose, args) {
|
||||
var strUrl = args[0],
|
||||
target = args[1],
|
||||
features = args[2];
|
||||
var strUrl = args[0];
|
||||
var target = args[1];
|
||||
var features = args[2];
|
||||
|
||||
if (target === "_self" || !target) {
|
||||
IAB._win = win;
|
||||
|
||||
if (target === '_self' || !target) {
|
||||
window.location = strUrl;
|
||||
} else if (target === "_system") {
|
||||
modulemapper.getOriginalSymbol(window, 'window.open').call(window, strUrl, "_blank");
|
||||
} else if (target === '_system') {
|
||||
modulemapper.getOriginalSymbol(window, 'window.open').call(window, strUrl, '_blank');
|
||||
} else {
|
||||
// "_blank" or anything else
|
||||
if (!browserWrap) {
|
||||
browserWrap = document.createElement("div");
|
||||
browserWrap.style.position = "absolute";
|
||||
browserWrap.style.top = "0";
|
||||
browserWrap.style.left = "0";
|
||||
browserWrap.style.boxSizing = "border-box";
|
||||
browserWrap.style.borderWidth = "40px";
|
||||
browserWrap.style.width = "100vw";
|
||||
browserWrap.style.height = "100vh";
|
||||
browserWrap.style.borderStyle = "solid";
|
||||
browserWrap.style.borderColor = "rgba(0,0,0,0.25)";
|
||||
browserWrap = document.createElement('div');
|
||||
browserWrap.style.position = 'absolute';
|
||||
browserWrap.style.top = '0';
|
||||
browserWrap.style.left = '0';
|
||||
browserWrap.style.boxSizing = 'border-box';
|
||||
browserWrap.style.borderWidth = '40px';
|
||||
browserWrap.style.width = '100vw';
|
||||
browserWrap.style.height = '100vh';
|
||||
browserWrap.style.borderStyle = 'solid';
|
||||
browserWrap.style.borderColor = 'rgba(0,0,0,0.25)';
|
||||
|
||||
browserWrap.onclick = function () {
|
||||
setTimeout(function () {
|
||||
IAB.close(win);
|
||||
IAB.close();
|
||||
}, 0);
|
||||
};
|
||||
|
||||
document.body.appendChild(browserWrap);
|
||||
}
|
||||
|
||||
if (features.indexOf("hidden=yes") !== -1) {
|
||||
browserWrap.style.display = "none";
|
||||
if (features.indexOf('hidden=yes') !== -1) {
|
||||
browserWrap.style.display = 'none';
|
||||
}
|
||||
|
||||
popup = document.createElement("iframe");
|
||||
popup.style.borderWidth = "0px";
|
||||
popup.style.width = "100%";
|
||||
popup = document.createElement('iframe');
|
||||
popup.style.borderWidth = '0px';
|
||||
popup.style.width = '100%';
|
||||
|
||||
browserWrap.appendChild(popup);
|
||||
|
||||
if (features.indexOf("location=yes") !== -1 || features.indexOf("location") === -1) {
|
||||
popup.style.height = "calc(100% - 60px)";
|
||||
popup.style.marginBottom = "-4px";
|
||||
if (features.indexOf('location=yes') !== -1 || features.indexOf('location') === -1) {
|
||||
popup.style.height = 'calc(100% - 60px)';
|
||||
popup.style.marginBottom = '-4px';
|
||||
|
||||
navigationButtonsDiv = document.createElement("div");
|
||||
navigationButtonsDiv.style.height = "60px";
|
||||
navigationButtonsDiv.style.backgroundColor = "#404040";
|
||||
navigationButtonsDiv.style.zIndex = "999";
|
||||
navigationButtonsDiv = document.createElement('div');
|
||||
navigationButtonsDiv.style.height = '60px';
|
||||
navigationButtonsDiv.style.backgroundColor = '#404040';
|
||||
navigationButtonsDiv.style.zIndex = '999';
|
||||
navigationButtonsDiv.onclick = function (e) {
|
||||
e.cancelBubble = true;
|
||||
};
|
||||
|
||||
navigationButtonsDivInner = document.createElement("div");
|
||||
navigationButtonsDivInner.style.paddingTop = "10px";
|
||||
navigationButtonsDivInner.style.height = "50px";
|
||||
navigationButtonsDivInner.style.width = "160px";
|
||||
navigationButtonsDivInner.style.margin = "0 auto";
|
||||
navigationButtonsDivInner.style.backgroundColor = "#404040";
|
||||
navigationButtonsDivInner.style.zIndex = "999";
|
||||
navigationButtonsDivInner = document.createElement('div');
|
||||
navigationButtonsDivInner.style.paddingTop = '10px';
|
||||
navigationButtonsDivInner.style.height = '50px';
|
||||
navigationButtonsDivInner.style.width = '160px';
|
||||
navigationButtonsDivInner.style.margin = '0 auto';
|
||||
navigationButtonsDivInner.style.backgroundColor = '#404040';
|
||||
navigationButtonsDivInner.style.zIndex = '999';
|
||||
navigationButtonsDivInner.onclick = function (e) {
|
||||
e.cancelBubble = true;
|
||||
};
|
||||
|
||||
backButton = document.createElement('button');
|
||||
backButton.style.width = '40px';
|
||||
backButton.style.height = '40px';
|
||||
backButton.style.borderRadius = '40px';
|
||||
|
||||
backButton = document.createElement("button");
|
||||
backButton.style.width = "40px";
|
||||
backButton.style.height = "40px";
|
||||
backButton.style.borderRadius = "40px";
|
||||
|
||||
backButton.innerHTML = "←";
|
||||
backButton.addEventListener("click", function (e) {
|
||||
if (popup.canGoBack)
|
||||
popup.goBack();
|
||||
backButton.innerHTML = '←';
|
||||
backButton.addEventListener('click', function (e) {
|
||||
if (popup.canGoBack) { popup.goBack(); }
|
||||
});
|
||||
|
||||
forwardButton = document.createElement("button");
|
||||
forwardButton.style.marginLeft = "20px";
|
||||
forwardButton.style.width = "40px";
|
||||
forwardButton.style.height = "40px";
|
||||
forwardButton.style.borderRadius = "40px";
|
||||
forwardButton = document.createElement('button');
|
||||
forwardButton.style.marginLeft = '20px';
|
||||
forwardButton.style.width = '40px';
|
||||
forwardButton.style.height = '40px';
|
||||
forwardButton.style.borderRadius = '40px';
|
||||
|
||||
forwardButton.innerHTML = "→";
|
||||
forwardButton.addEventListener("click", function (e) {
|
||||
if (popup.canGoForward)
|
||||
popup.goForward();
|
||||
forwardButton.innerHTML = '→';
|
||||
forwardButton.addEventListener('click', function (e) {
|
||||
if (popup.canGoForward) { popup.goForward(); }
|
||||
});
|
||||
|
||||
closeButton = document.createElement("button");
|
||||
closeButton.style.marginLeft = "20px";
|
||||
closeButton.style.width = "40px";
|
||||
closeButton.style.height = "40px";
|
||||
closeButton.style.borderRadius = "40px";
|
||||
closeButton = document.createElement('button');
|
||||
closeButton.style.marginLeft = '20px';
|
||||
closeButton.style.width = '40px';
|
||||
closeButton.style.height = '40px';
|
||||
closeButton.style.borderRadius = '40px';
|
||||
|
||||
closeButton.innerHTML = "✖";
|
||||
closeButton.addEventListener("click", function (e) {
|
||||
closeButton.innerHTML = '✖';
|
||||
closeButton.addEventListener('click', function (e) {
|
||||
setTimeout(function () {
|
||||
IAB.close(win);
|
||||
IAB.close();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
@@ -176,7 +191,7 @@ var IAB = {
|
||||
|
||||
browserWrap.appendChild(navigationButtonsDiv);
|
||||
} else {
|
||||
popup.style.height = "100%";
|
||||
popup.style.height = '100%';
|
||||
}
|
||||
|
||||
// start listening for navigation events
|
||||
@@ -187,8 +202,8 @@ var IAB = {
|
||||
},
|
||||
|
||||
injectScriptCode: function (win, fail, args) {
|
||||
var code = args[0],
|
||||
hasCallback = args[1];
|
||||
var code = args[0];
|
||||
var hasCallback = args[1];
|
||||
|
||||
if (browserWrap && popup) {
|
||||
try {
|
||||
@@ -196,7 +211,7 @@ var IAB = {
|
||||
if (hasCallback) {
|
||||
win([]);
|
||||
}
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
console.error('Error occured while trying to injectScriptCode: ' + JSON.stringify(e));
|
||||
}
|
||||
}
|
||||
@@ -208,7 +223,7 @@ var IAB = {
|
||||
if (fail) {
|
||||
fail(msg);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
injectStyleCode: function (win, fail, args) {
|
||||
var msg = 'Browser cordova-plugin-inappbrowser injectStyleCode is not yet implemented';
|
||||
@@ -229,4 +244,4 @@ var IAB = {
|
||||
|
||||
module.exports = IAB;
|
||||
|
||||
require("cordova/exec/proxy").add("InAppBrowser", module.exports);
|
||||
require('cordova/exec/proxy').add('InAppBrowser', module.exports);
|
||||
|
||||
@@ -1,191 +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.
|
||||
*
|
||||
*/
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/WebAPI/Browser
|
||||
|
||||
var modulemapper = require('cordova/modulemapper');
|
||||
|
||||
var origOpenFunc = modulemapper.getOriginalSymbol(window, 'window.open');
|
||||
var browserWrap;
|
||||
|
||||
var IABExecs = {
|
||||
|
||||
close: function (win, lose) {
|
||||
if (browserWrap) {
|
||||
browserWrap.parentNode.removeChild(browserWrap);
|
||||
browserWrap = null;
|
||||
if (typeof(win) == "function") win({type:'exit'});
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* Reveal browser if opened hidden
|
||||
*/
|
||||
show: function (win, lose) {
|
||||
console.error('[FirefoxOS] show not implemented');
|
||||
},
|
||||
|
||||
hide: function (win, lose) {
|
||||
console.error('[FirefoxOS] hide not implemented');
|
||||
},
|
||||
|
||||
open: function (win, lose, args) {
|
||||
var strUrl = args[0],
|
||||
target = args[1],
|
||||
features_string = args[2] || "location=yes", //location=yes is default
|
||||
features = {};
|
||||
|
||||
var features_list = features_string.split(',');
|
||||
features_list.forEach(function(feature) {
|
||||
var tup = feature.split('=');
|
||||
if (tup[1] == 'yes') {
|
||||
tup[1] = true;
|
||||
} else if (tup[1] == 'no') {
|
||||
tup[1] = false;
|
||||
} else {
|
||||
var number = parseInt(tup[1]);
|
||||
if (!isNaN(number)) {
|
||||
tup[1] = number;
|
||||
}
|
||||
}
|
||||
features[tup[0]] = tup[1];
|
||||
});
|
||||
|
||||
function updateIframeSizeNoLocation() {
|
||||
browserWrap.style.width = window.innerWidth + 'px';
|
||||
browserWrap.style.height = window.innerHeight + 'px';
|
||||
browserWrap.style.zIndex = '999999999';
|
||||
browserWrap.browser.style.height = (window.innerHeight - 60) + 'px';
|
||||
browserWrap.browser.style.width = browserWrap.style.width;
|
||||
}
|
||||
|
||||
if (target === '_system') {
|
||||
origOpenFunc.apply(window, [strUrl, '_blank']);
|
||||
} else if (target === '_blank') {
|
||||
var browserElem = document.createElement('iframe');
|
||||
browserElem.setAttribute('mozbrowser', true);
|
||||
// make this loaded in its own child process
|
||||
browserElem.setAttribute('remote', true);
|
||||
browserElem.setAttribute('src', strUrl);
|
||||
if (browserWrap) {
|
||||
document.body.removeChild(browserWrap);
|
||||
}
|
||||
browserWrap = document.createElement('div');
|
||||
// assign browser element to browserWrap for future reference
|
||||
browserWrap.browser = browserElem;
|
||||
|
||||
browserWrap.classList.add('inAppBrowserWrap');
|
||||
// position fixed so that it works even when page is scrolled
|
||||
browserWrap.style.position = 'fixed';
|
||||
browserElem.style.position = 'absolute';
|
||||
browserElem.style.border = 0;
|
||||
browserElem.style.top = '60px';
|
||||
browserElem.style.left = '0px';
|
||||
updateIframeSizeNoLocation();
|
||||
|
||||
var menu = document.createElement('menu');
|
||||
menu.setAttribute('type', 'toolbar');
|
||||
var close = document.createElement('li');
|
||||
var back = document.createElement('li');
|
||||
var forward = document.createElement('li');
|
||||
|
||||
close.appendChild(document.createTextNode('×'));
|
||||
back.appendChild(document.createTextNode('<'));
|
||||
forward.appendChild(document.createTextNode('>'));
|
||||
|
||||
close.classList.add('inAppBrowserClose');
|
||||
back.classList.add('inAppBrowserBack');
|
||||
forward.classList.add('inAppBrowserForward');
|
||||
|
||||
var checkForwardBackward = function () {
|
||||
var backReq = browserElem.getCanGoBack();
|
||||
backReq.onsuccess = function() {
|
||||
if (this.result) {
|
||||
back.classList.remove('disabled');
|
||||
} else {
|
||||
back.classList.add('disabled');
|
||||
}
|
||||
};
|
||||
var forwardReq = browserElem.getCanGoForward();
|
||||
forwardReq.onsuccess = function() {
|
||||
if (this.result) {
|
||||
forward.classList.remove('disabled');
|
||||
} else {
|
||||
forward.classList.add('disabled');
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
browserElem.addEventListener('mozbrowserloadend', checkForwardBackward);
|
||||
|
||||
close.addEventListener('click', function () {
|
||||
setTimeout(function () {
|
||||
IABExecs.close(win, lose);
|
||||
}, 0);
|
||||
}, false);
|
||||
|
||||
back.addEventListener('click', function () {
|
||||
browserElem.goBack();
|
||||
}, false);
|
||||
|
||||
forward.addEventListener('click', function () {
|
||||
browserElem.goForward();
|
||||
}, false);
|
||||
|
||||
menu.appendChild(back);
|
||||
menu.appendChild(forward);
|
||||
menu.appendChild(close);
|
||||
|
||||
browserWrap.appendChild(menu);
|
||||
browserWrap.appendChild(browserElem);
|
||||
document.body.appendChild(browserWrap);
|
||||
|
||||
//we use mozbrowserlocationchange instead of mozbrowserloadstart to get the url
|
||||
browserElem.addEventListener('mozbrowserlocationchange', function(e){
|
||||
win({
|
||||
type:'loadstart',
|
||||
url : e.detail
|
||||
});
|
||||
}, false);
|
||||
browserElem.addEventListener('mozbrowserloadend', function(e){
|
||||
win({type:'loadstop'});
|
||||
}, false);
|
||||
browserElem.addEventListener('mozbrowsererror', function(e){
|
||||
win({type:'loaderror'});
|
||||
}, false);
|
||||
browserElem.addEventListener('mozbrowserclose', function(e){
|
||||
win({type:'exit'});
|
||||
}, false);
|
||||
} else {
|
||||
window.location = strUrl;
|
||||
}
|
||||
},
|
||||
injectScriptCode: function (code, bCB) {
|
||||
console.error('[FirefoxOS] injectScriptCode not implemented');
|
||||
},
|
||||
injectScriptFile: function (file, bCB) {
|
||||
console.error('[FirefoxOS] injectScriptFile not implemented');
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = IABExecs;
|
||||
|
||||
require('cordova/exec/proxy').add('InAppBrowser', module.exports);
|
||||
@@ -49,7 +49,11 @@
|
||||
@property (nonatomic, assign) BOOL location;
|
||||
@property (nonatomic, assign) BOOL toolbar;
|
||||
@property (nonatomic, copy) NSString* closebuttoncaption;
|
||||
@property (nonatomic, copy) NSString* closebuttoncolor;
|
||||
@property (nonatomic, copy) NSString* toolbarposition;
|
||||
@property (nonatomic, copy) NSString* toolbarcolor;
|
||||
@property (nonatomic, assign) BOOL toolbartranslucent;
|
||||
@property (nonatomic, assign) BOOL hidenavigationbuttons;
|
||||
@property (nonatomic, assign) BOOL clearcache;
|
||||
@property (nonatomic, assign) BOOL clearsessioncache;
|
||||
|
||||
@@ -74,13 +78,13 @@
|
||||
NSString* _prevUserAgent;
|
||||
NSInteger _userAgentLockToken;
|
||||
CDVInAppBrowserOptions *_browserOptions;
|
||||
|
||||
|
||||
#ifdef __CORDOVA_4_0_0
|
||||
CDVUIWebViewDelegate* _webViewDelegate;
|
||||
#else
|
||||
CDVWebViewDelegate* _webViewDelegate;
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
@property (nonatomic, strong) IBOutlet UIWebView* webView;
|
||||
@@ -99,7 +103,7 @@
|
||||
- (void)navigateTo:(NSURL*)url;
|
||||
- (void)showLocationBar:(BOOL)show;
|
||||
- (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition;
|
||||
- (void)setCloseButtonTitle:(NSString*)title;
|
||||
- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString;
|
||||
|
||||
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions;
|
||||
|
||||
@@ -110,4 +114,3 @@
|
||||
@property (nonatomic, weak) id <CDVScreenOrientationDelegate> orientationDelegate;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -162,8 +162,8 @@
|
||||
|
||||
[self.inAppBrowserViewController showLocationBar:browserOptions.location];
|
||||
[self.inAppBrowserViewController showToolBar:browserOptions.toolbar :browserOptions.toolbarposition];
|
||||
if (browserOptions.closebuttoncaption != nil) {
|
||||
[self.inAppBrowserViewController setCloseButtonTitle:browserOptions.closebuttoncaption];
|
||||
if (browserOptions.closebuttoncaption != nil || browserOptions.closebuttoncolor != nil) {
|
||||
[self.inAppBrowserViewController setCloseButtonTitle:browserOptions.closebuttoncaption :browserOptions.closebuttoncolor];
|
||||
}
|
||||
// Set Presentation Style
|
||||
UIModalPresentationStyle presentationStyle = UIModalPresentationFullScreen; // default
|
||||
@@ -270,7 +270,7 @@
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (self.inAppBrowserViewController != nil) {
|
||||
_previousStatusBarStyle = -1;
|
||||
[self.viewController dismissViewControllerAnimated:YES completion:nil];
|
||||
[self.inAppBrowserViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -599,6 +599,12 @@
|
||||
self.toolbar.multipleTouchEnabled = NO;
|
||||
self.toolbar.opaque = NO;
|
||||
self.toolbar.userInteractionEnabled = YES;
|
||||
if (_browserOptions.toolbarcolor != nil) { // Set toolbar color if user sets it in options
|
||||
self.toolbar.barTintColor = [self colorFromHexString:_browserOptions.toolbarcolor];
|
||||
}
|
||||
if (!_browserOptions.toolbartranslucent) { // Set toolbar translucent to no if user sets it in options
|
||||
self.toolbar.translucent = NO;
|
||||
}
|
||||
|
||||
CGFloat labelInset = 5.0;
|
||||
float locationBarY = toolbarIsAtBottom ? self.view.bounds.size.height - FOOTER_HEIGHT : self.view.bounds.size.height - LOCATIONBAR_HEIGHT;
|
||||
@@ -642,7 +648,13 @@
|
||||
self.backButton.enabled = YES;
|
||||
self.backButton.imageInsets = UIEdgeInsetsZero;
|
||||
|
||||
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]];
|
||||
// Filter out Navigation Buttons if user requests so
|
||||
if (_browserOptions.hidenavigationbuttons) {
|
||||
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton]];
|
||||
} else {
|
||||
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]];
|
||||
}
|
||||
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton]];
|
||||
|
||||
self.view.backgroundColor = [UIColor grayColor];
|
||||
[self.view addSubview:self.toolbar];
|
||||
@@ -655,14 +667,16 @@
|
||||
[self.webView setFrame:frame];
|
||||
}
|
||||
|
||||
- (void)setCloseButtonTitle:(NSString*)title
|
||||
- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString
|
||||
{
|
||||
// the advantage of using UIBarButtonSystemItemDone is the system will localize it for you automatically
|
||||
// but, if you want to set this yourself, knock yourself out (we can't set the title for a system Done button, so we have to create a new one)
|
||||
self.closeButton = nil;
|
||||
self.closeButton = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStyleBordered target:self action:@selector(close)];
|
||||
// Initialize with title if title is set, otherwise the title will be 'Done' localized
|
||||
self.closeButton = title != nil ? [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStyleBordered target:self action:@selector(close)] : [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(close)];
|
||||
self.closeButton.enabled = YES;
|
||||
self.closeButton.tintColor = [UIColor colorWithRed:60.0 / 255.0 green:136.0 / 255.0 blue:230.0 / 255.0 alpha:1];
|
||||
// If color on closebutton is requested then initialize with that that color, otherwise use initialize with default
|
||||
self.closeButton.tintColor = colorString != nil ? [self colorFromHexString:colorString] : [UIColor colorWithRed:60.0 / 255.0 green:136.0 / 255.0 blue:230.0 / 255.0 alpha:1];
|
||||
|
||||
NSMutableArray* items = [self.toolbar.items mutableCopy];
|
||||
[items replaceObjectAtIndex:0 withObject:self.closeButton];
|
||||
@@ -877,6 +891,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 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];
|
||||
[scanner setScanLocation:1]; // bypass '#' character
|
||||
[scanner scanHexInt:&rgbValue];
|
||||
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
|
||||
}
|
||||
|
||||
#pragma mark UIWebViewDelegate
|
||||
|
||||
- (void)webViewDidStartLoad:(UIWebView*)theWebView
|
||||
@@ -995,6 +1020,10 @@
|
||||
self.suppressesincrementalrendering = NO;
|
||||
self.hidden = NO;
|
||||
self.disallowoverscroll = NO;
|
||||
self.hidenavigationbuttons = NO;
|
||||
self.closebuttoncolor = nil;
|
||||
self.toolbarcolor = nil;
|
||||
self.toolbartranslucent = YES;
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -1104,4 +1133,3 @@
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2013 Canonical Ltd.
|
||||
*
|
||||
* 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 QtQuick 2.0
|
||||
import Ubuntu.Components.Popups 0.1
|
||||
import Ubuntu.Components 0.1
|
||||
import com.canonical.Oxide 1.0
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
id: inappbrowser
|
||||
property string url1
|
||||
Rectangle {
|
||||
border.color: "black"
|
||||
width: parent.width
|
||||
height: urlEntry.height
|
||||
color: "gray"
|
||||
TextInput {
|
||||
id: urlEntry
|
||||
width: parent.width - closeButton.width
|
||||
text: url1
|
||||
activeFocusOnPress: false
|
||||
}
|
||||
Image {
|
||||
id: closeButton
|
||||
width: height
|
||||
x: parent.width - width
|
||||
height: parent.height
|
||||
source: "close.png"
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
root.exec("InAppBrowser", "close", [0, 0])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
property string usContext: "oxide://main-world/2"
|
||||
|
||||
function executeJS(scId, code) {
|
||||
var req = _view.rootFrame.sendMessage(usContext, "EXECUTE", {code: code});
|
||||
|
||||
req.onreply = function(response) {
|
||||
var code = 'cordova.callback(' + scId + ', JSON.parse(\'' + JSON.stringify(response.result) + '\'))';
|
||||
console.warn(code);
|
||||
cordova.javaScriptExecNeeded(code);
|
||||
console.warn("RESP:" + JSON.stringify(response));
|
||||
};
|
||||
}
|
||||
|
||||
WebView {
|
||||
width: parent.width
|
||||
y: urlEntry.height
|
||||
height: parent.height - y
|
||||
url: url1
|
||||
id: _view
|
||||
onLoadingStateChanged: {
|
||||
root.exec("InAppBrowser", "loadFinished", [_view.loading])
|
||||
}
|
||||
context: WebContext {
|
||||
id: webcontext
|
||||
|
||||
userScripts: [
|
||||
UserScript {
|
||||
context: usContext
|
||||
emulateGreasemonkey: true
|
||||
url: "InAppBrowser_escapeScript.js"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +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.
|
||||
*
|
||||
*/
|
||||
|
||||
/* jshint -W061 */
|
||||
/* global oxide */
|
||||
|
||||
oxide.addMessageHandler("EXECUTE", function(msg) {
|
||||
var code = msg.args.code;
|
||||
try {
|
||||
msg.reply({result: eval(code)});
|
||||
} catch(e) {
|
||||
msg.error("Code threw exception: \"" + e + "\"");
|
||||
}
|
||||
});
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 461 B |
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2013 Canonical Ltd.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QQuickView>
|
||||
#include <QQuickItem>
|
||||
|
||||
#include "inappbrowser.h"
|
||||
#include <cordova.h>
|
||||
|
||||
Inappbrowser::Inappbrowser(Cordova *cordova): CPlugin(cordova), _eventCb(0) {
|
||||
}
|
||||
|
||||
const char code[] = "\
|
||||
var component; \
|
||||
function createObject() { \
|
||||
component = Qt.createComponent(%1); \
|
||||
if (component.status == Component.Ready) \
|
||||
finishCreation(); \
|
||||
else \
|
||||
component.statusChanged.connect(finishCreation); \
|
||||
} \
|
||||
function finishCreation() { \
|
||||
CordovaWrapper.global.inappbrowser = component.createObject(root, \
|
||||
{root: root, cordova: cordova, url1: %2}); \
|
||||
} \
|
||||
createObject()";
|
||||
|
||||
const char EXIT_EVENT[] = "{type: 'exit'}";
|
||||
const char LOADSTART_EVENT[] = "{type: 'loadstart'}";
|
||||
const char LOADSTOP_EVENT[] = "{type: 'loadstop'}";
|
||||
const char LOADERROR_EVENT[] = "{type: 'loaderror'}";
|
||||
|
||||
void Inappbrowser::open(int cb, int, const QString &url, const QString &, const QString &) {
|
||||
assert(_eventCb == 0);
|
||||
|
||||
_eventCb = cb;
|
||||
|
||||
QString path = m_cordova->get_app_dir() + "/../qml/InAppBrowser.qml";
|
||||
QString qml = QString(code)
|
||||
.arg(CordovaInternal::format(path)).arg(CordovaInternal::format(url));
|
||||
m_cordova->execQML(qml);
|
||||
}
|
||||
|
||||
void Inappbrowser::show(int, int) {
|
||||
m_cordova->execQML("CordovaWrapper.global.inappbrowser.visible = true");
|
||||
}
|
||||
|
||||
void Inappbrowser::hide(int, int) {
|
||||
m_cordova->execQML("CordovaWrapper.global.inappbrowser.visible = false");
|
||||
}
|
||||
|
||||
void Inappbrowser::close(int, int) {
|
||||
m_cordova->execQML("CordovaWrapper.global.inappbrowser.destroy()");
|
||||
this->callbackWithoutRemove(_eventCb, EXIT_EVENT);
|
||||
_eventCb = 0;
|
||||
}
|
||||
|
||||
void Inappbrowser::injectStyleFile(int scId, int ecId, const QString& src, bool b) {
|
||||
QString code("(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %1; d.head.appendChild(c);})(document)");
|
||||
code = code.arg(CordovaInternal::format(src));
|
||||
|
||||
injectScriptCode(scId, ecId, code, b);
|
||||
}
|
||||
|
||||
void Inappbrowser::injectStyleCode(int scId, int ecId, const QString& src, bool b) {
|
||||
QString code("(function(d) { var c = d.createElement('style'); c.innerHTML = %1; d.body.appendChild(c); })(document)");
|
||||
code = code.arg(CordovaInternal::format(src));
|
||||
|
||||
injectScriptCode(scId, ecId, code, b);
|
||||
}
|
||||
|
||||
void Inappbrowser::injectScriptFile(int scId, int ecId, const QString& src, bool b) {
|
||||
QString code("(function(d) { var c = d.createElement('script'); c.src = %1; d.body.appendChild(c);})(document)");
|
||||
code = code.arg(CordovaInternal::format(src));
|
||||
|
||||
injectScriptCode(scId, ecId, code, b);
|
||||
}
|
||||
|
||||
void Inappbrowser::injectScriptCode(int scId, int, const QString& code, bool) {
|
||||
m_cordova->execQML(QString("CordovaWrapper.global.inappbrowser.executeJS(%2, %1)").arg(CordovaInternal::format(code)).arg(scId));
|
||||
}
|
||||
|
||||
void Inappbrowser::loadFinished(bool status) {
|
||||
if (!status) {
|
||||
this->callbackWithoutRemove(_eventCb, LOADSTOP_EVENT);
|
||||
} else {
|
||||
this->callbackWithoutRemove(_eventCb, LOADSTART_EVENT);
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2013 Canonical Ltd.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
#ifndef INAPPBROWSER_H
|
||||
#define INAPPBROWSER_H
|
||||
|
||||
#include <QtCore>
|
||||
#include <cplugin.h>
|
||||
|
||||
class Inappbrowser: public CPlugin {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Inappbrowser(Cordova *cordova);
|
||||
|
||||
virtual const QString fullName() override {
|
||||
return Inappbrowser::fullID();
|
||||
}
|
||||
|
||||
virtual const QString shortName() override {
|
||||
return "InAppBrowser";
|
||||
}
|
||||
|
||||
static const QString fullID() {
|
||||
return "InAppBrowser";
|
||||
}
|
||||
|
||||
public slots:
|
||||
void open(int cb, int, const QString &url, const QString &windowName, const QString &windowFeatures);
|
||||
void show(int, int);
|
||||
void hide(int, int);
|
||||
void close(int, int);
|
||||
void injectStyleFile(int cb, int, const QString&, bool);
|
||||
void injectStyleCode(int cb, int, const QString&, bool);
|
||||
void injectScriptFile(int cb, int, const QString&, bool);
|
||||
void injectScriptCode(int cb, int, const QString&, bool);
|
||||
|
||||
void loadFinished(bool status);
|
||||
|
||||
private:
|
||||
int _eventCb;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
@@ -21,9 +21,10 @@
|
||||
|
||||
/* jslint sloppy:true */
|
||||
/* global Windows:true, setImmediate */
|
||||
/* eslint standard/no-callback-literal : 0 */
|
||||
|
||||
var cordova = require('cordova'),
|
||||
urlutil = require('cordova/urlutil');
|
||||
var cordova = require('cordova');
|
||||
var urlutil = require('cordova/urlutil');
|
||||
|
||||
var browserWrap,
|
||||
popup,
|
||||
@@ -40,56 +41,56 @@ var browserWrap,
|
||||
// http://msdn.microsoft.com/en-us/library/windows/apps/dn301831.aspx
|
||||
var isWebViewAvailable = cordova.platformId === 'windows';
|
||||
|
||||
function attachNavigationEvents(element, callback) {
|
||||
function attachNavigationEvents (element, callback) {
|
||||
if (isWebViewAvailable) {
|
||||
element.addEventListener("MSWebViewNavigationStarting", function (e) {
|
||||
callback({ type: "loadstart", url: e.uri}, {keepCallback: true} );
|
||||
element.addEventListener('MSWebViewNavigationStarting', function (e) {
|
||||
callback({ type: 'loadstart', url: e.uri }, {keepCallback: true});
|
||||
});
|
||||
|
||||
element.addEventListener("MSWebViewNavigationCompleted", function (e) {
|
||||
element.addEventListener('MSWebViewNavigationCompleted', function (e) {
|
||||
if (e.isSuccess) {
|
||||
callback({ type: "loadstop", url: e.uri }, { keepCallback: true });
|
||||
callback({ type: 'loadstop', url: e.uri }, { keepCallback: true });
|
||||
} else {
|
||||
callback({ type: "loaderror", url: e.uri, code: e.webErrorStatus, message: "Navigation failed with error code " + e.webErrorStatus}, { keepCallback: true });
|
||||
callback({ type: 'loaderror', url: e.uri, code: e.webErrorStatus, message: 'Navigation failed with error code ' + e.webErrorStatus }, { keepCallback: true });
|
||||
}
|
||||
});
|
||||
|
||||
element.addEventListener("MSWebViewUnviewableContentIdentified", function (e) {
|
||||
element.addEventListener('MSWebViewUnviewableContentIdentified', function (e) {
|
||||
// WebView found the content to be not HTML.
|
||||
// http://msdn.microsoft.com/en-us/library/windows/apps/dn609716.aspx
|
||||
callback({ type: "loaderror", url: e.uri, code: e.webErrorStatus, message: "Navigation failed with error code " + e.webErrorStatus}, { keepCallback: true });
|
||||
callback({ type: 'loaderror', url: e.uri, code: e.webErrorStatus, message: 'Navigation failed with error code ' + e.webErrorStatus }, { keepCallback: true });
|
||||
});
|
||||
|
||||
element.addEventListener("MSWebViewContentLoading", function (e) {
|
||||
element.addEventListener('MSWebViewContentLoading', function (e) {
|
||||
if (navigationButtonsDiv && popup) {
|
||||
if (popup.canGoBack) {
|
||||
backButton.removeAttribute("disabled");
|
||||
backButton.removeAttribute('disabled');
|
||||
} else {
|
||||
backButton.setAttribute("disabled", "true");
|
||||
backButton.setAttribute('disabled', 'true');
|
||||
}
|
||||
|
||||
if (popup.canGoForward) {
|
||||
forwardButton.removeAttribute("disabled");
|
||||
forwardButton.removeAttribute('disabled');
|
||||
} else {
|
||||
forwardButton.setAttribute("disabled", "true");
|
||||
forwardButton.setAttribute('disabled', 'true');
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var onError = function () {
|
||||
callback({ type: "loaderror", url: this.contentWindow.location}, {keepCallback: true});
|
||||
callback({ type: 'loaderror', url: this.contentWindow.location }, {keepCallback: true});
|
||||
};
|
||||
|
||||
element.addEventListener("unload", function () {
|
||||
callback({ type: "loadstart", url: this.contentWindow.location}, {keepCallback: true});
|
||||
element.addEventListener('unload', function () {
|
||||
callback({ type: 'loadstart', url: this.contentWindow.location }, {keepCallback: true});
|
||||
});
|
||||
|
||||
element.addEventListener("load", function () {
|
||||
callback({ type: "loadstop", url: this.contentWindow.location}, {keepCallback: true});
|
||||
element.addEventListener('load', function () {
|
||||
callback({ type: 'loadstop', url: this.contentWindow.location }, {keepCallback: true});
|
||||
});
|
||||
|
||||
element.addEventListener("error", onError);
|
||||
element.addEventListener("abort", onError);
|
||||
element.addEventListener('error', onError);
|
||||
element.addEventListener('abort', onError);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +99,7 @@ var IAB = {
|
||||
setImmediate(function () {
|
||||
if (browserWrap) {
|
||||
if (navigationEventsCallback) {
|
||||
navigationEventsCallback({ type: "exit" });
|
||||
navigationEventsCallback({ type: 'exit' });
|
||||
}
|
||||
|
||||
browserWrap.parentNode.removeChild(browserWrap);
|
||||
@@ -107,52 +108,52 @@ var IAB = {
|
||||
browserWrap = null;
|
||||
popup = null;
|
||||
|
||||
document.removeEventListener("backbutton", hardwareBackCallback, false);
|
||||
document.removeEventListener('backbutton', hardwareBackCallback, false);
|
||||
}
|
||||
});
|
||||
},
|
||||
show: function (win, lose) {
|
||||
setImmediate(function () {
|
||||
if (browserWrap) {
|
||||
browserWrap.style.display = "block";
|
||||
browserWrap.style.display = 'block';
|
||||
}
|
||||
});
|
||||
},
|
||||
hide: function (win, lose) {
|
||||
if (browserWrap) {
|
||||
browserWrap.style.display = "none";
|
||||
browserWrap.style.display = 'none';
|
||||
}
|
||||
},
|
||||
open: function (win, lose, args) {
|
||||
// make function async so that we can add navigation events handlers before view is loaded and navigation occured
|
||||
setImmediate(function () {
|
||||
var strUrl = args[0],
|
||||
target = args[1],
|
||||
features = args[2],
|
||||
url;
|
||||
var strUrl = args[0];
|
||||
var target = args[1];
|
||||
var features = args[2];
|
||||
var url;
|
||||
|
||||
navigationEventsCallback = win;
|
||||
|
||||
if (target === "_system") {
|
||||
if (target === '_system') {
|
||||
url = new Windows.Foundation.Uri(strUrl);
|
||||
Windows.System.Launcher.launchUriAsync(url);
|
||||
} else if (target === "_self" || !target) {
|
||||
} else if (target === '_self' || !target) {
|
||||
window.location = strUrl;
|
||||
} else {
|
||||
// "_blank" or anything else
|
||||
if (!browserWrap) {
|
||||
var browserWrapStyle = document.createElement('link');
|
||||
browserWrapStyle.rel = "stylesheet";
|
||||
browserWrapStyle.type = "text/css";
|
||||
browserWrapStyle.href = urlutil.makeAbsolute("/www/css/inappbrowser.css");
|
||||
browserWrapStyle.rel = 'stylesheet';
|
||||
browserWrapStyle.type = 'text/css';
|
||||
browserWrapStyle.href = urlutil.makeAbsolute('/www/css/inappbrowser.css');
|
||||
|
||||
document.head.appendChild(browserWrapStyle);
|
||||
|
||||
browserWrap = document.createElement("div");
|
||||
browserWrap.className = "inAppBrowserWrap";
|
||||
browserWrap = document.createElement('div');
|
||||
browserWrap.className = 'inAppBrowserWrap';
|
||||
|
||||
if (features.indexOf("fullscreen=yes") > -1) {
|
||||
browserWrap.classList.add("inAppBrowserWrapFullscreen");
|
||||
if (features.indexOf('fullscreen=yes') > -1) {
|
||||
browserWrap.classList.add('inAppBrowserWrapFullscreen');
|
||||
}
|
||||
|
||||
// Save body overflow style to be able to reset it back later
|
||||
@@ -166,22 +167,22 @@ var IAB = {
|
||||
|
||||
document.body.appendChild(browserWrap);
|
||||
// Hide scrollbars for the whole body while inappbrowser's window is open
|
||||
document.body.style.msOverflowStyle = "none";
|
||||
document.body.style.msOverflowStyle = 'none';
|
||||
}
|
||||
|
||||
if (features.indexOf("hidden=yes") !== -1) {
|
||||
browserWrap.style.display = "none";
|
||||
if (features.indexOf('hidden=yes') !== -1) {
|
||||
browserWrap.style.display = 'none';
|
||||
}
|
||||
|
||||
popup = document.createElement(isWebViewAvailable ? "x-ms-webview" : "iframe");
|
||||
if (popup instanceof HTMLIFrameElement) {
|
||||
popup = document.createElement(isWebViewAvailable ? 'x-ms-webview' : 'iframe');
|
||||
if (popup instanceof HTMLIFrameElement) { // eslint-disable-line no-undef
|
||||
// For iframe we need to override bacground color of parent element here
|
||||
// otherwise pages without background color set will have transparent background
|
||||
popup.style.backgroundColor = "white";
|
||||
popup.style.backgroundColor = 'white';
|
||||
}
|
||||
popup.style.borderWidth = "0px";
|
||||
popup.style.width = "100%";
|
||||
popup.style.marginBottom = "-5px";
|
||||
popup.style.borderWidth = '0px';
|
||||
popup.style.width = '100%';
|
||||
popup.style.marginBottom = '-5px';
|
||||
|
||||
browserWrap.appendChild(popup);
|
||||
|
||||
@@ -191,14 +192,14 @@ var IAB = {
|
||||
}, 0);
|
||||
};
|
||||
|
||||
if (features.indexOf("hardwareback=yes") > -1 || features.indexOf("hardwareback") === -1) {
|
||||
if (features.indexOf('hardwareback=yes') > -1 || features.indexOf('hardwareback') === -1) {
|
||||
hardwareBackCallback = function () {
|
||||
if (browserWrap.style.display === 'none') {
|
||||
// NOTE: backbutton handlers have to throw an exception in order to prevent
|
||||
// returning 'true' inside cordova-js, which would mean that the event is handled by user.
|
||||
// Throwing an exception means that the default/system navigation behavior will take place,
|
||||
// which is to exit the app if the navigation stack is empty.
|
||||
throw 'Exit the app';
|
||||
throw 'Exit the app'; // eslint-disable-line no-throw-literal
|
||||
}
|
||||
|
||||
if (popup.canGoBack) {
|
||||
@@ -207,59 +208,57 @@ var IAB = {
|
||||
closeHandler();
|
||||
}
|
||||
};
|
||||
} else if (features.indexOf("hardwareback=no") > -1) {
|
||||
} else if (features.indexOf('hardwareback=no') > -1) {
|
||||
hardwareBackCallback = function () {
|
||||
if (browserWrap.style.display === 'none') {
|
||||
// See comment above
|
||||
throw 'Exit the app';
|
||||
throw 'Exit the app'; // eslint-disable-line no-throw-literal
|
||||
}
|
||||
|
||||
closeHandler();
|
||||
};
|
||||
}
|
||||
|
||||
document.addEventListener("backbutton", hardwareBackCallback, false);
|
||||
document.addEventListener('backbutton', hardwareBackCallback, false);
|
||||
|
||||
if (features.indexOf("location=yes") !== -1 || features.indexOf("location") === -1) {
|
||||
popup.style.height = "calc(100% - 70px)";
|
||||
if (features.indexOf('location=yes') !== -1 || features.indexOf('location') === -1) {
|
||||
popup.style.height = 'calc(100% - 70px)';
|
||||
|
||||
navigationButtonsDiv = document.createElement("div");
|
||||
navigationButtonsDiv.className = "inappbrowser-app-bar";
|
||||
navigationButtonsDiv = document.createElement('div');
|
||||
navigationButtonsDiv.className = 'inappbrowser-app-bar';
|
||||
navigationButtonsDiv.onclick = function (e) {
|
||||
e.cancelBubble = true;
|
||||
};
|
||||
|
||||
navigationButtonsDivInner = document.createElement("div");
|
||||
navigationButtonsDivInner.className = "inappbrowser-app-bar-inner";
|
||||
navigationButtonsDivInner = document.createElement('div');
|
||||
navigationButtonsDivInner.className = 'inappbrowser-app-bar-inner';
|
||||
navigationButtonsDivInner.onclick = function (e) {
|
||||
e.cancelBubble = true;
|
||||
};
|
||||
|
||||
backButton = document.createElement("div");
|
||||
backButton.innerText = "back";
|
||||
backButton.className = "app-bar-action action-back";
|
||||
backButton.addEventListener("click", function (e) {
|
||||
if (popup.canGoBack)
|
||||
popup.goBack();
|
||||
backButton = document.createElement('div');
|
||||
backButton.innerText = 'back';
|
||||
backButton.className = 'app-bar-action action-back';
|
||||
backButton.addEventListener('click', function (e) {
|
||||
if (popup.canGoBack) { popup.goBack(); }
|
||||
});
|
||||
|
||||
forwardButton = document.createElement("div");
|
||||
forwardButton.innerText = "forward";
|
||||
forwardButton.className = "app-bar-action action-forward";
|
||||
forwardButton.addEventListener("click", function (e) {
|
||||
if (popup.canGoForward)
|
||||
popup.goForward();
|
||||
forwardButton = document.createElement('div');
|
||||
forwardButton.innerText = 'forward';
|
||||
forwardButton.className = 'app-bar-action action-forward';
|
||||
forwardButton.addEventListener('click', function (e) {
|
||||
if (popup.canGoForward) { popup.goForward(); }
|
||||
});
|
||||
|
||||
closeButton = document.createElement("div");
|
||||
closeButton.innerText = "close";
|
||||
closeButton.className = "app-bar-action action-close";
|
||||
closeButton.addEventListener("click", closeHandler);
|
||||
closeButton = document.createElement('div');
|
||||
closeButton.innerText = 'close';
|
||||
closeButton.className = 'app-bar-action action-close';
|
||||
closeButton.addEventListener('click', closeHandler);
|
||||
|
||||
if (!isWebViewAvailable) {
|
||||
// iframe navigation is not yet supported
|
||||
backButton.setAttribute("disabled", "true");
|
||||
forwardButton.setAttribute("disabled", "true");
|
||||
backButton.setAttribute('disabled', 'true');
|
||||
forwardButton.setAttribute('disabled', 'true');
|
||||
}
|
||||
|
||||
navigationButtonsDivInner.appendChild(backButton);
|
||||
@@ -269,14 +268,14 @@ var IAB = {
|
||||
|
||||
browserWrap.appendChild(navigationButtonsDiv);
|
||||
} else {
|
||||
popup.style.height = "100%";
|
||||
popup.style.height = '100%';
|
||||
}
|
||||
|
||||
// start listening for navigation events
|
||||
attachNavigationEvents(popup, navigationEventsCallback);
|
||||
|
||||
if (isWebViewAvailable) {
|
||||
strUrl = strUrl.replace("ms-appx://", "ms-appx-web://");
|
||||
strUrl = strUrl.replace('ms-appx://', 'ms-appx-web://');
|
||||
}
|
||||
popup.src = strUrl;
|
||||
}
|
||||
@@ -285,11 +284,11 @@ var IAB = {
|
||||
|
||||
injectScriptCode: function (win, fail, args) {
|
||||
setImmediate(function () {
|
||||
var code = args[0],
|
||||
hasCallback = args[1];
|
||||
var code = args[0];
|
||||
var hasCallback = args[1];
|
||||
|
||||
if (isWebViewAvailable && browserWrap && popup) {
|
||||
var op = popup.invokeScriptAsync("eval", code);
|
||||
var op = popup.invokeScriptAsync('eval', code);
|
||||
op.oncomplete = function (e) {
|
||||
if (hasCallback) {
|
||||
// return null if event target is unavailable by some reason
|
||||
@@ -305,10 +304,10 @@ var IAB = {
|
||||
|
||||
injectScriptFile: function (win, fail, args) {
|
||||
setImmediate(function () {
|
||||
var filePath = args[0],
|
||||
hasCallback = args[1];
|
||||
var filePath = args[0];
|
||||
var hasCallback = args[1];
|
||||
|
||||
if (!!filePath) {
|
||||
if (filePath) {
|
||||
filePath = urlutil.makeAbsolute(filePath);
|
||||
}
|
||||
|
||||
@@ -317,8 +316,8 @@ var IAB = {
|
||||
var uri = new Windows.Foundation.Uri(filePath.replace('ms-appx-web:', 'ms-appx:'));
|
||||
Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).done(function (file) {
|
||||
Windows.Storage.FileIO.readTextAsync(file).done(function (code) {
|
||||
var op = popup.invokeScriptAsync("eval", code);
|
||||
op.oncomplete = function(e) {
|
||||
var op = popup.invokeScriptAsync('eval', code);
|
||||
op.oncomplete = function (e) {
|
||||
if (hasCallback) {
|
||||
var result = [e.target.result];
|
||||
win(result);
|
||||
@@ -334,8 +333,8 @@ var IAB = {
|
||||
|
||||
injectStyleCode: function (win, fail, args) {
|
||||
setImmediate(function () {
|
||||
var code = args[0],
|
||||
hasCallback = args[1];
|
||||
var code = args[0];
|
||||
var hasCallback = args[1];
|
||||
|
||||
if (isWebViewAvailable && browserWrap && popup) {
|
||||
injectCSS(popup, code, hasCallback && win);
|
||||
@@ -345,8 +344,8 @@ var IAB = {
|
||||
|
||||
injectStyleFile: function (win, fail, args) {
|
||||
setImmediate(function () {
|
||||
var filePath = args[0],
|
||||
hasCallback = args[1];
|
||||
var filePath = args[0];
|
||||
var hasCallback = args[1];
|
||||
|
||||
filePath = filePath && urlutil.makeAbsolute(filePath);
|
||||
|
||||
@@ -368,11 +367,11 @@ var IAB = {
|
||||
function injectCSS (webView, cssCode, callback) {
|
||||
// This will automatically escape all thing that we need (quotes, slashes, etc.)
|
||||
var escapedCode = JSON.stringify(cssCode);
|
||||
var evalWrapper = "(function(d){var c=d.createElement('style');c.innerHTML=%s;d.head.appendChild(c);})(document)"
|
||||
var evalWrapper = '(function(d){var c=d.createElement(\'style\');c.innerHTML=%s;d.head.appendChild(c);})(document)'
|
||||
.replace('%s', escapedCode);
|
||||
|
||||
var op = webView.invokeScriptAsync("eval", evalWrapper);
|
||||
op.oncomplete = function() {
|
||||
var op = webView.invokeScriptAsync('eval', evalWrapper);
|
||||
op.oncomplete = function () {
|
||||
if (callback) {
|
||||
callback([]);
|
||||
}
|
||||
@@ -383,4 +382,4 @@ function injectCSS (webView, cssCode, callback) {
|
||||
|
||||
module.exports = IAB;
|
||||
|
||||
require("cordova/exec/proxy").add("InAppBrowser", module.exports);
|
||||
require('cordova/exec/proxy').add('InAppBrowser', module.exports);
|
||||
|
||||
@@ -1,530 +0,0 @@
|
||||
/*
|
||||
Licensed 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.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using Microsoft.Phone.Controls;
|
||||
using Microsoft.Phone.Shell;
|
||||
|
||||
#if WP8
|
||||
using System.Threading.Tasks;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.Storage;
|
||||
using Windows.System;
|
||||
|
||||
//Use alias in case Cordova File Plugin is enabled. Then the File class will be declared in both and error will occur.
|
||||
using IOFile = System.IO.File;
|
||||
#else
|
||||
using Microsoft.Phone.Tasks;
|
||||
#endif
|
||||
|
||||
namespace WPCordovaClassLib.Cordova.Commands
|
||||
{
|
||||
[DataContract]
|
||||
public class BrowserOptions
|
||||
{
|
||||
[DataMember]
|
||||
public string url;
|
||||
|
||||
[DataMember]
|
||||
public bool isGeolocationEnabled;
|
||||
}
|
||||
|
||||
public class InAppBrowser : BaseCommand
|
||||
{
|
||||
|
||||
private static WebBrowser browser;
|
||||
private static ApplicationBarIconButton backButton;
|
||||
private static ApplicationBarIconButton fwdButton;
|
||||
|
||||
protected ApplicationBar AppBar;
|
||||
|
||||
protected bool ShowLocation {get;set;}
|
||||
protected bool StartHidden {get;set;}
|
||||
|
||||
protected string NavigationCallbackId { get; set; }
|
||||
|
||||
public void open(string options)
|
||||
{
|
||||
// reset defaults on ShowLocation + StartHidden features
|
||||
ShowLocation = true;
|
||||
StartHidden = false;
|
||||
|
||||
string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
|
||||
//BrowserOptions opts = JSON.JsonHelper.Deserialize<BrowserOptions>(options);
|
||||
string urlLoc = args[0];
|
||||
string target = args[1];
|
||||
string featString = args[2];
|
||||
this.NavigationCallbackId = args[3];
|
||||
|
||||
if (!string.IsNullOrEmpty(featString))
|
||||
{
|
||||
string[] features = featString.Split(',');
|
||||
foreach (string str in features)
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] split = str.Split('=');
|
||||
switch (split[0])
|
||||
{
|
||||
case "location":
|
||||
ShowLocation = split[1].StartsWith("yes", StringComparison.OrdinalIgnoreCase);
|
||||
break;
|
||||
case "hidden":
|
||||
StartHidden = split[1].StartsWith("yes", StringComparison.OrdinalIgnoreCase);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// some sort of invalid param was passed, moving on ...
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
_self - opens in the Cordova WebView if url is in the white-list, else it opens in the InAppBrowser
|
||||
_blank - always open in the InAppBrowser
|
||||
_system - always open in the system web browser
|
||||
*/
|
||||
switch (target)
|
||||
{
|
||||
case "_blank":
|
||||
ShowInAppBrowser(urlLoc);
|
||||
break;
|
||||
case "_self":
|
||||
ShowCordovaBrowser(urlLoc);
|
||||
break;
|
||||
case "_system":
|
||||
ShowSystemBrowser(urlLoc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void show(string options)
|
||||
{
|
||||
string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
|
||||
|
||||
|
||||
if (browser != null)
|
||||
{
|
||||
Deployment.Current.Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
browser.Visibility = Visibility.Visible;
|
||||
AppBar.IsVisible = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void hide(string options)
|
||||
{
|
||||
string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
|
||||
|
||||
|
||||
if (browser != null)
|
||||
{
|
||||
Deployment.Current.Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
browser.Visibility = Visibility.Collapsed;
|
||||
AppBar.IsVisible = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void injectScriptCode(string options)
|
||||
{
|
||||
string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
|
||||
|
||||
bool bCallback = false;
|
||||
if (bool.TryParse(args[1], out bCallback)) { };
|
||||
|
||||
string callbackId = args[2];
|
||||
|
||||
if (browser != null)
|
||||
{
|
||||
Deployment.Current.Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
var res = browser.InvokeScript("eval", new string[] { args[0] });
|
||||
|
||||
if (bCallback)
|
||||
{
|
||||
PluginResult result = new PluginResult(PluginResult.Status.OK, res.ToString());
|
||||
result.KeepCallback = false;
|
||||
this.DispatchCommandResult(result);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void injectScriptFile(string options)
|
||||
{
|
||||
Debug.WriteLine("Error : Windows Phone cordova-plugin-inappbrowser does not currently support executeScript");
|
||||
string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
|
||||
// throw new NotImplementedException("Windows Phone does not currently support 'executeScript'");
|
||||
}
|
||||
|
||||
public void injectStyleCode(string options)
|
||||
{
|
||||
Debug.WriteLine("Error : Windows Phone cordova-plugin-inappbrowser does not currently support insertCSS");
|
||||
return;
|
||||
|
||||
//string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
|
||||
//bool bCallback = false;
|
||||
//if (bool.TryParse(args[1], out bCallback)) { };
|
||||
|
||||
//string callbackId = args[2];
|
||||
|
||||
//if (browser != null)
|
||||
//{
|
||||
//Deployment.Current.Dispatcher.BeginInvoke(() =>
|
||||
//{
|
||||
// if (bCallback)
|
||||
// {
|
||||
// string cssInsertString = "try{(function(doc){var c = '<style>body{background-color:#ffff00;}</style>'; doc.head.innerHTML += c;})(document);}catch(ex){alert('oops : ' + ex.message);}";
|
||||
// //cssInsertString = cssInsertString.Replace("_VALUE_", args[0]);
|
||||
// Debug.WriteLine("cssInsertString = " + cssInsertString);
|
||||
// var res = browser.InvokeScript("eval", new string[] { cssInsertString });
|
||||
// if (bCallback)
|
||||
// {
|
||||
// PluginResult result = new PluginResult(PluginResult.Status.OK, res.ToString());
|
||||
// result.KeepCallback = false;
|
||||
// this.DispatchCommandResult(result);
|
||||
// }
|
||||
// }
|
||||
|
||||
//});
|
||||
//}
|
||||
}
|
||||
|
||||
public void injectStyleFile(string options)
|
||||
{
|
||||
Debug.WriteLine("Error : Windows Phone cordova-plugin-inappbrowser does not currently support insertCSS");
|
||||
return;
|
||||
|
||||
//string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
|
||||
//throw new NotImplementedException("Windows Phone does not currently support 'insertCSS'");
|
||||
}
|
||||
|
||||
private void ShowCordovaBrowser(string url)
|
||||
{
|
||||
Uri loc = new Uri(url, UriKind.RelativeOrAbsolute);
|
||||
Deployment.Current.Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame;
|
||||
if (frame != null)
|
||||
{
|
||||
PhoneApplicationPage page = frame.Content as PhoneApplicationPage;
|
||||
if (page != null)
|
||||
{
|
||||
CordovaView cView = page.FindName("CordovaView") as CordovaView;
|
||||
if (cView != null)
|
||||
{
|
||||
WebBrowser br = cView.Browser;
|
||||
br.Navigate2(loc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#if WP8
|
||||
private async void ShowSystemBrowser(string url)
|
||||
{
|
||||
var pathUri = new Uri(url, UriKind.Absolute);
|
||||
if (pathUri.Scheme == Uri.UriSchemeHttp || pathUri.Scheme == Uri.UriSchemeHttps)
|
||||
{
|
||||
await Launcher.LaunchUriAsync(pathUri);
|
||||
return;
|
||||
}
|
||||
|
||||
var file = await GetFile(pathUri.AbsolutePath.Replace('/', Path.DirectorySeparatorChar));
|
||||
if (file != null)
|
||||
{
|
||||
await Launcher.LaunchFileAsync(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine("File not found.");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<StorageFile> GetFile(string fileName)
|
||||
{
|
||||
//first try to get the file from the isolated storage
|
||||
var localFolder = ApplicationData.Current.LocalFolder;
|
||||
if (IOFile.Exists(Path.Combine(localFolder.Path, fileName)))
|
||||
{
|
||||
return await localFolder.GetFileAsync(fileName);
|
||||
}
|
||||
|
||||
//if file is not found try to get it from the xap
|
||||
var filePath = Path.Combine(Package.Current.InstalledLocation.Path, fileName);
|
||||
if (IOFile.Exists(filePath))
|
||||
{
|
||||
return await StorageFile.GetFileFromPathAsync(filePath);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
#else
|
||||
private void ShowSystemBrowser(string url)
|
||||
{
|
||||
WebBrowserTask webBrowserTask = new WebBrowserTask();
|
||||
webBrowserTask.Uri = new Uri(url, UriKind.Absolute);
|
||||
webBrowserTask.Show();
|
||||
}
|
||||
#endif
|
||||
|
||||
private void ShowInAppBrowser(string url)
|
||||
{
|
||||
Uri loc = new Uri(url, UriKind.RelativeOrAbsolute);
|
||||
|
||||
Deployment.Current.Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
//browser.IsGeolocationEnabled = opts.isGeolocationEnabled;
|
||||
browser.Navigate2(loc);
|
||||
}
|
||||
else
|
||||
{
|
||||
PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame;
|
||||
if (frame != null)
|
||||
{
|
||||
PhoneApplicationPage page = frame.Content as PhoneApplicationPage;
|
||||
|
||||
string baseImageUrl = "Images/";
|
||||
|
||||
if (page != null)
|
||||
{
|
||||
Grid grid = page.FindName("LayoutRoot") as Grid;
|
||||
if (grid != null)
|
||||
{
|
||||
browser = new WebBrowser();
|
||||
browser.IsScriptEnabled = true;
|
||||
browser.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(browser_LoadCompleted);
|
||||
|
||||
browser.Navigating += new EventHandler<NavigatingEventArgs>(browser_Navigating);
|
||||
browser.NavigationFailed += new System.Windows.Navigation.NavigationFailedEventHandler(browser_NavigationFailed);
|
||||
browser.Navigated += new EventHandler<System.Windows.Navigation.NavigationEventArgs>(browser_Navigated);
|
||||
browser.Navigate2(loc);
|
||||
|
||||
if (StartHidden)
|
||||
{
|
||||
browser.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
//browser.IsGeolocationEnabled = opts.isGeolocationEnabled;
|
||||
grid.Children.Add(browser);
|
||||
}
|
||||
|
||||
ApplicationBar bar = new ApplicationBar();
|
||||
bar.BackgroundColor = Colors.Gray;
|
||||
bar.IsMenuEnabled = false;
|
||||
|
||||
backButton = new ApplicationBarIconButton();
|
||||
backButton.Text = "Back";
|
||||
|
||||
backButton.IconUri = new Uri(baseImageUrl + "appbar.back.rest.png", UriKind.Relative);
|
||||
backButton.Click += new EventHandler(backButton_Click);
|
||||
bar.Buttons.Add(backButton);
|
||||
|
||||
|
||||
fwdButton = new ApplicationBarIconButton();
|
||||
fwdButton.Text = "Forward";
|
||||
fwdButton.IconUri = new Uri(baseImageUrl + "appbar.next.rest.png", UriKind.Relative);
|
||||
fwdButton.Click += new EventHandler(fwdButton_Click);
|
||||
bar.Buttons.Add(fwdButton);
|
||||
|
||||
ApplicationBarIconButton closeBtn = new ApplicationBarIconButton();
|
||||
closeBtn.Text = "Close";
|
||||
closeBtn.IconUri = new Uri(baseImageUrl + "appbar.close.rest.png", UriKind.Relative);
|
||||
closeBtn.Click += new EventHandler(closeBtn_Click);
|
||||
bar.Buttons.Add(closeBtn);
|
||||
|
||||
page.ApplicationBar = bar;
|
||||
bar.IsVisible = !StartHidden;
|
||||
AppBar = bar;
|
||||
|
||||
page.BackKeyPress += page_BackKeyPress;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void page_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
#if WP8
|
||||
if (browser.CanGoBack)
|
||||
{
|
||||
browser.GoBack();
|
||||
}
|
||||
else
|
||||
{
|
||||
close();
|
||||
}
|
||||
e.Cancel = true;
|
||||
#else
|
||||
browser.InvokeScript("execScript", "history.back();");
|
||||
#endif
|
||||
}
|
||||
|
||||
void browser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void fwdButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
#if WP8
|
||||
browser.GoForward();
|
||||
#else
|
||||
browser.InvokeScript("execScript", "history.forward();");
|
||||
#endif
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void backButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
#if WP8
|
||||
browser.GoBack();
|
||||
#else
|
||||
browser.InvokeScript("execScript", "history.back();");
|
||||
#endif
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void closeBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.close();
|
||||
}
|
||||
|
||||
|
||||
public void close(string options = "")
|
||||
{
|
||||
if (browser != null)
|
||||
{
|
||||
Deployment.Current.Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame;
|
||||
if (frame != null)
|
||||
{
|
||||
PhoneApplicationPage page = frame.Content as PhoneApplicationPage;
|
||||
if (page != null)
|
||||
{
|
||||
Grid grid = page.FindName("LayoutRoot") as Grid;
|
||||
if (grid != null)
|
||||
{
|
||||
grid.Children.Remove(browser);
|
||||
}
|
||||
page.ApplicationBar = null;
|
||||
page.BackKeyPress -= page_BackKeyPress;
|
||||
}
|
||||
}
|
||||
|
||||
browser = null;
|
||||
string message = "{\"type\":\"exit\"}";
|
||||
PluginResult result = new PluginResult(PluginResult.Status.OK, message);
|
||||
result.KeepCallback = false;
|
||||
this.DispatchCommandResult(result, NavigationCallbackId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
|
||||
{
|
||||
#if WP8
|
||||
if (browser != null)
|
||||
{
|
||||
backButton.IsEnabled = browser.CanGoBack;
|
||||
fwdButton.IsEnabled = browser.CanGoForward;
|
||||
|
||||
}
|
||||
#endif
|
||||
string message = "{\"type\":\"loadstop\", \"url\":\"" + e.Uri.OriginalString + "\"}";
|
||||
PluginResult result = new PluginResult(PluginResult.Status.OK, message);
|
||||
result.KeepCallback = true;
|
||||
this.DispatchCommandResult(result, NavigationCallbackId);
|
||||
}
|
||||
|
||||
void browser_NavigationFailed(object sender, System.Windows.Navigation.NavigationFailedEventArgs e)
|
||||
{
|
||||
string message = "{\"type\":\"error\",\"url\":\"" + e.Uri.OriginalString + "\"}";
|
||||
PluginResult result = new PluginResult(PluginResult.Status.ERROR, message);
|
||||
result.KeepCallback = true;
|
||||
this.DispatchCommandResult(result, NavigationCallbackId);
|
||||
}
|
||||
|
||||
void browser_Navigating(object sender, NavigatingEventArgs e)
|
||||
{
|
||||
string message = "{\"type\":\"loadstart\",\"url\":\"" + e.Uri.OriginalString + "\"}";
|
||||
PluginResult result = new PluginResult(PluginResult.Status.OK, message);
|
||||
result.KeepCallback = true;
|
||||
this.DispatchCommandResult(result, NavigationCallbackId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal static class WebBrowserExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Improved method to initiate request to the provided URI. Supports 'data:text/html' urls.
|
||||
/// </summary>
|
||||
/// <param name="browser">The browser instance</param>
|
||||
/// <param name="uri">The requested uri</param>
|
||||
internal static void Navigate2(this WebBrowser browser, Uri uri)
|
||||
{
|
||||
// IE10 does not support data uri so we use NavigateToString method instead
|
||||
if (uri.Scheme == "data")
|
||||
{
|
||||
// we should remove the scheme identifier and unescape the uri
|
||||
string uriString = Uri.UnescapeDataString(uri.AbsoluteUri);
|
||||
// format is 'data:text/html, ...'
|
||||
string html = new System.Text.RegularExpressions.Regex("^data:text/html,").Replace(uriString, "");
|
||||
browser.NavigateToString(html);
|
||||
}
|
||||
else
|
||||
{
|
||||
browser.Navigate(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
tests/.eslintrc.yml
Normal file
2
tests/.eslintrc.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
env:
|
||||
jasmine: true
|
||||
14
tests/package.json
Normal file
14
tests/package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "cordova-plugin-inappbrowser-tests",
|
||||
"version": "1.7.1-dev",
|
||||
"description": "",
|
||||
"cordova": {
|
||||
"id": "cordova-plugin-inappbrowser-tests",
|
||||
"platforms": []
|
||||
},
|
||||
"keywords": [
|
||||
"ecosystem:cordova"
|
||||
],
|
||||
"author": "",
|
||||
"license": "Apache 2.0"
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
id="cordova-plugin-inappbrowser-tests"
|
||||
version="1.6.2-dev">
|
||||
version="2.0.2">
|
||||
<name>Cordova InAppBrowser Plugin Tests</name>
|
||||
<license>Apache 2.0</license>
|
||||
|
||||
|
||||
@@ -16,5 +16,5 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
var d = document.getElementById("header");
|
||||
d.innerHTML = "Script file successfully injected";
|
||||
var d = document.getElementById('header');
|
||||
d.innerHTML = 'Script file successfully injected';
|
||||
|
||||
165
tests/tests.js
165
tests/tests.js
@@ -19,11 +19,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* jshint jasmine: true */
|
||||
/* global MSApp */
|
||||
|
||||
var cordova = require('cordova');
|
||||
var isWindows = cordova.platformId == 'windows';
|
||||
var isWindows = cordova.platformId === 'windows';
|
||||
var isBrowser = cordova.platformId === 'browser';
|
||||
|
||||
window.alert = window.alert || navigator.notification.alert;
|
||||
if (isWindows && navigator && navigator.notification && navigator.notification.alert) {
|
||||
@@ -35,11 +35,11 @@ exports.defineAutoTests = function () {
|
||||
|
||||
describe('cordova.InAppBrowser', function () {
|
||||
|
||||
it("inappbrowser.spec.1 should exist", function () {
|
||||
it('inappbrowser.spec.1 should exist', function () {
|
||||
expect(cordova.InAppBrowser).toBeDefined();
|
||||
});
|
||||
|
||||
it("inappbrowser.spec.2 should contain open function", function () {
|
||||
it('inappbrowser.spec.2 should contain open function', function () {
|
||||
expect(cordova.InAppBrowser.open).toBeDefined();
|
||||
expect(cordova.InAppBrowser.open).toEqual(jasmine.any(Function));
|
||||
});
|
||||
@@ -47,7 +47,7 @@ exports.defineAutoTests = function () {
|
||||
|
||||
describe('open method', function () {
|
||||
|
||||
if (cordova.platformId == 'osx') {
|
||||
if (cordova.platformId === 'osx') {
|
||||
pending('Open method not fully supported on OSX.');
|
||||
return;
|
||||
}
|
||||
@@ -77,15 +77,16 @@ exports.defineAutoTests = function () {
|
||||
setTimeout(done, 2000);
|
||||
});
|
||||
|
||||
function verifyEvent(evt, type) {
|
||||
function verifyEvent (evt, type) {
|
||||
expect(evt).toBeDefined();
|
||||
expect(evt.type).toEqual(type);
|
||||
if (type !== 'exit') { // `exit` event does not have url field
|
||||
// `exit` event does not have url field, browser returns null url for CORS requests
|
||||
if (type !== 'exit' && !isBrowser) {
|
||||
expect(evt.url).toEqual(url);
|
||||
}
|
||||
}
|
||||
|
||||
function verifyLoadErrorEvent(evt) {
|
||||
function verifyLoadErrorEvent (evt) {
|
||||
expect(evt).toBeDefined();
|
||||
expect(evt.type).toEqual('loaderror');
|
||||
expect(evt.url).toEqual(badUrl);
|
||||
@@ -93,7 +94,7 @@ exports.defineAutoTests = function () {
|
||||
expect(evt.message).toEqual(jasmine.any(String));
|
||||
}
|
||||
|
||||
it("inappbrowser.spec.3 should retun InAppBrowser instance with required methods", function () {
|
||||
it('inappbrowser.spec.3 should return InAppBrowser instance with required methods', function () {
|
||||
iabInstance = cordova.InAppBrowser.open(url, '_blank');
|
||||
|
||||
expect(iabInstance).toBeDefined();
|
||||
@@ -107,7 +108,7 @@ exports.defineAutoTests = function () {
|
||||
expect(iabInstance.insertCSS).toEqual(jasmine.any(Function));
|
||||
});
|
||||
|
||||
it("inappbrowser.spec.4 should support loadstart and loadstop events", function (done) {
|
||||
it('inappbrowser.spec.4 should support loadstart and loadstop events', function (done) {
|
||||
var onLoadStart = jasmine.createSpy('loadstart event callback').and.callFake(function (evt) {
|
||||
verifyEvent(evt, 'loadstart');
|
||||
});
|
||||
@@ -116,12 +117,16 @@ exports.defineAutoTests = function () {
|
||||
iabInstance.addEventListener('loadstart', onLoadStart);
|
||||
iabInstance.addEventListener('loadstop', function (evt) {
|
||||
verifyEvent(evt, 'loadstop');
|
||||
expect(onLoadStart).toHaveBeenCalled();
|
||||
if (!isBrowser) {
|
||||
// according to documentation, "loadstart" event is not supported on browser
|
||||
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
|
||||
expect(onLoadStart).toHaveBeenCalled();
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("inappbrowser.spec.5 should support exit event", function (done) {
|
||||
it('inappbrowser.spec.5 should support exit event', function (done) {
|
||||
iabInstance = cordova.InAppBrowser.open(url, '_blank');
|
||||
iabInstance.addEventListener('exit', function (evt) {
|
||||
verifyEvent(evt, 'exit');
|
||||
@@ -131,7 +136,12 @@ exports.defineAutoTests = function () {
|
||||
iabInstance = null;
|
||||
});
|
||||
|
||||
it("inappbrowser.spec.6 should support loaderror event", function (done) {
|
||||
it('inappbrowser.spec.6 should support loaderror event', function (done) {
|
||||
if (isBrowser) {
|
||||
// according to documentation, "loaderror" event is not supported on browser
|
||||
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
|
||||
pending('Browser platform doesn\'t support loaderror event');
|
||||
}
|
||||
iabInstance = cordova.InAppBrowser.open(badUrl, '_blank');
|
||||
iabInstance.addEventListener('loaderror', function (evt) {
|
||||
verifyLoadErrorEvent(evt);
|
||||
@@ -143,15 +153,15 @@ exports.defineAutoTests = function () {
|
||||
|
||||
exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
|
||||
function doOpen(url, target, params, numExpectedRedirects, useWindowOpen) {
|
||||
function doOpen (url, target, params, numExpectedRedirects, useWindowOpen) {
|
||||
numExpectedRedirects = numExpectedRedirects || 0;
|
||||
useWindowOpen = useWindowOpen || false;
|
||||
console.log("Opening " + url);
|
||||
console.log('Opening ' + url);
|
||||
|
||||
var counts;
|
||||
var lastLoadStartURL;
|
||||
var wasReset = false;
|
||||
function reset() {
|
||||
function reset () {
|
||||
counts = {
|
||||
'loaderror': 0,
|
||||
'loadstart': 0,
|
||||
@@ -172,49 +182,48 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
if (useWindowOpen) {
|
||||
console.log('Use window.open() for url');
|
||||
iab = window.open(url, target, params, callbacks);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
iab = cordova.InAppBrowser.open(url, target, params, callbacks);
|
||||
}
|
||||
if (!iab) {
|
||||
alert('open returned ' + iab);
|
||||
alert('open returned ' + iab); // eslint-disable-line no-undef
|
||||
return;
|
||||
}
|
||||
|
||||
function logEvent(e) {
|
||||
function logEvent (e) {
|
||||
console.log('IAB event=' + JSON.stringify(e));
|
||||
counts[e.type]++;
|
||||
// Verify that event.url gets updated on redirects.
|
||||
if (e.type == 'loadstart') {
|
||||
if (e.url == lastLoadStartURL) {
|
||||
alert('Unexpected: loadstart fired multiple times for the same URL.');
|
||||
if (e.type === 'loadstart') {
|
||||
if (e.url === lastLoadStartURL) {
|
||||
alert('Unexpected: loadstart fired multiple times for the same URL.'); // eslint-disable-line no-undef
|
||||
}
|
||||
lastLoadStartURL = e.url;
|
||||
}
|
||||
// Verify the right number of loadstart events were fired.
|
||||
if (e.type == 'loadstop' || e.type == 'loaderror') {
|
||||
if (e.url != lastLoadStartURL) {
|
||||
alert('Unexpected: ' + e.type + ' event.url != loadstart\'s event.url');
|
||||
if (e.type === 'loadstop' || e.type === 'loaderror') {
|
||||
if (e.url !== lastLoadStartURL) {
|
||||
alert('Unexpected: ' + e.type + ' event.url != loadstart\'s event.url'); // eslint-disable-line no-undef
|
||||
}
|
||||
if (numExpectedRedirects === 0 && counts.loadstart !== 1) {
|
||||
// Do allow a loaderror without a loadstart (e.g. in the case of an invalid URL).
|
||||
if (!(e.type == 'loaderror' && counts.loadstart === 0)) {
|
||||
alert('Unexpected: got multiple loadstart events. (' + counts.loadstart + ')');
|
||||
if (!(e.type === 'loaderror' && counts.loadstart === 0)) {
|
||||
alert('Unexpected: got multiple loadstart events. (' + counts.loadstart + ')'); // eslint-disable-line no-undef
|
||||
}
|
||||
} else if (numExpectedRedirects > 0 && counts.loadstart < (numExpectedRedirects + 1)) {
|
||||
alert('Unexpected: should have got at least ' + (numExpectedRedirects + 1) + ' loadstart events, but got ' + counts.loadstart);
|
||||
alert('Unexpected: should have got at least ' + (numExpectedRedirects + 1) + ' loadstart events, but got ' + counts.loadstart); // eslint-disable-line no-undef
|
||||
}
|
||||
wasReset = true;
|
||||
numExpectedRedirects = 0;
|
||||
reset();
|
||||
}
|
||||
// Verify that loadend / loaderror was called.
|
||||
if (e.type == 'exit') {
|
||||
if (e.type === 'exit') {
|
||||
var numStopEvents = counts.loadstop + counts.loaderror;
|
||||
if (numStopEvents === 0 && !wasReset) {
|
||||
alert('Unexpected: browser closed without a loadstop or loaderror.');
|
||||
alert('Unexpected: browser closed without a loadstop or loaderror.'); // eslint-disable-line no-undef
|
||||
} else if (numStopEvents > 1) {
|
||||
alert('Unexpected: got multiple loadstop/loaderror events.');
|
||||
alert('Unexpected: got multiple loadstop/loaderror events.'); // eslint-disable-line no-undef
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -222,33 +231,31 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
return iab;
|
||||
}
|
||||
|
||||
function doHookOpen(url, target, params, numExpectedRedirects) {
|
||||
function doHookOpen (url, target, params, numExpectedRedirects) {
|
||||
var originalFunc = window.open;
|
||||
var wasClobbered = window.hasOwnProperty('open');
|
||||
window.open = cordova.InAppBrowser.open;
|
||||
|
||||
try {
|
||||
doOpen(url, target, params, numExpectedRedirects, true);
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
if (wasClobbered) {
|
||||
window.open = originalFunc;
|
||||
}
|
||||
else {
|
||||
console.log('just delete, to restore open from prototype');
|
||||
} else {
|
||||
console.log('just delete, to restore open from prototype');
|
||||
delete window.open;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function openWithStyle(url, cssUrl, useCallback) {
|
||||
function openWithStyle (url, cssUrl, useCallback) {
|
||||
var iab = doOpen(url, '_blank', 'location=yes');
|
||||
var callback = function (results) {
|
||||
if (results && results.length === 0) {
|
||||
alert('Results verified');
|
||||
alert('Results verified'); // eslint-disable-line no-undef
|
||||
} else {
|
||||
console.log(results);
|
||||
alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results));
|
||||
alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results)); // eslint-disable-line no-undef
|
||||
}
|
||||
};
|
||||
if (cssUrl) {
|
||||
@@ -258,21 +265,21 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
} else {
|
||||
iab.addEventListener('loadstop', function (event) {
|
||||
iab.insertCSS({ code: '#style-update-literal { \ndisplay: block !important; \n}' },
|
||||
useCallback && callback);
|
||||
useCallback && callback);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function openWithScript(url, jsUrl, useCallback) {
|
||||
function openWithScript (url, jsUrl, useCallback) {
|
||||
var iab = doOpen(url, '_blank', 'location=yes');
|
||||
if (jsUrl) {
|
||||
iab.addEventListener('loadstop', function (event) {
|
||||
iab.executeScript({ file: jsUrl }, useCallback && function (results) {
|
||||
if (results && results.length === 0) {
|
||||
alert('Results verified');
|
||||
alert('Results verified'); // eslint-disable-line no-undef
|
||||
} else {
|
||||
console.log(results);
|
||||
alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results));
|
||||
alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results)); // eslint-disable-line no-undef
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -285,33 +292,33 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
'})()';
|
||||
iab.executeScript({ code: code }, useCallback && function (results) {
|
||||
if (results && results.length === 1 && results[0] === 'abc') {
|
||||
alert('Results verified');
|
||||
alert('Results verified'); // eslint-disable-line no-undef
|
||||
} else {
|
||||
console.log(results);
|
||||
alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results));
|
||||
alert('Got: ' + typeof (results) + '\n' + JSON.stringify(results)); // eslint-disable-line no-undef
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
var hiddenwnd = null;
|
||||
var loadlistener = function (event) { alert('background window loaded '); };
|
||||
function openHidden(url, startHidden) {
|
||||
var loadlistener = function (event) { alert('background window loaded '); }; // eslint-disable-line no-undef
|
||||
function openHidden (url, startHidden) {
|
||||
var shopt = (startHidden) ? 'hidden=yes' : '';
|
||||
hiddenwnd = cordova.InAppBrowser.open(url, 'random_string', shopt);
|
||||
if (!hiddenwnd) {
|
||||
alert('cordova.InAppBrowser.open returned ' + hiddenwnd);
|
||||
alert('cordova.InAppBrowser.open returned ' + hiddenwnd); // eslint-disable-line no-undef
|
||||
return;
|
||||
}
|
||||
if (startHidden) hiddenwnd.addEventListener('loadstop', loadlistener);
|
||||
}
|
||||
function showHidden() {
|
||||
if (!!hiddenwnd) {
|
||||
function showHidden () {
|
||||
if (hiddenwnd) {
|
||||
hiddenwnd.show();
|
||||
}
|
||||
}
|
||||
function closeHidden() {
|
||||
if (!!hiddenwnd) {
|
||||
function closeHidden () {
|
||||
if (hiddenwnd) {
|
||||
hiddenwnd.removeEventListener('loadstop', loadlistener);
|
||||
hiddenwnd.close();
|
||||
hiddenwnd = null;
|
||||
@@ -456,14 +463,14 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
'<p/> <div id="openHardwareBackYes"></div>' +
|
||||
'Expected result: hardwareback=yes pressing back button should navigate backwards in history then close InAppBrowser' +
|
||||
'<p/> <div id="openHardwareBackNo"></div>' +
|
||||
'Expected result: hardwareback=no pressing back button should close InAppBrowser regardless history' +
|
||||
'Expected result: hardwareback=no pressing back button should close InAppBrowser regardless history' +
|
||||
'<p/> <div id="openHardwareBackDefaultAfterNo"></div>' +
|
||||
'Expected result: consistently open browsers with with the appropriate option: hardwareback=defaults to yes then hardwareback=no then hardwareback=defaults to yes. By default hardwareback is yes so pressing back button should navigate backwards in history then close InAppBrowser';
|
||||
|
||||
// CB-7490 We need to wrap this code due to Windows security restrictions
|
||||
// see http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx#differences for details
|
||||
if (window.MSApp && window.MSApp.execUnsafeLocalFunction) {
|
||||
MSApp.execUnsafeLocalFunction(function() {
|
||||
MSApp.execUnsafeLocalFunction(function () {
|
||||
contentEl.innerHTML = info_div + local_tests + white_listed_tests + non_white_listed_tests + page_with_redirects_tests + pdf_url_tests + invalid_url_tests +
|
||||
css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests + hardwareback_tests;
|
||||
});
|
||||
@@ -472,18 +479,18 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests + hardwareback_tests;
|
||||
}
|
||||
|
||||
document.getElementById("user-agent").textContent = navigator.userAgent;
|
||||
document.getElementById('user-agent').textContent = navigator.userAgent;
|
||||
|
||||
// we are already in cdvtests directory
|
||||
var basePath = 'iab-resources/';
|
||||
var localhtml = basePath + 'local.html',
|
||||
localpdf = basePath + 'local.pdf',
|
||||
injecthtml = basePath + 'inject.html',
|
||||
injectjs = isWindows ? basePath + 'inject.js' : 'inject.js',
|
||||
injectcss = isWindows ? basePath + 'inject.css' : 'inject.css',
|
||||
videohtml = basePath + 'video.html';
|
||||
var localhtml = basePath + 'local.html';
|
||||
var localpdf = basePath + 'local.pdf';
|
||||
var injecthtml = basePath + 'inject.html';
|
||||
var injectjs = isWindows ? basePath + 'inject.js' : 'inject.js';
|
||||
var injectcss = isWindows ? basePath + 'inject.css' : 'inject.css';
|
||||
var videohtml = basePath + 'video.html';
|
||||
|
||||
//Local
|
||||
// Local
|
||||
createActionButton('target=Default', function () {
|
||||
doOpen(localhtml);
|
||||
}, 'openLocal');
|
||||
@@ -512,7 +519,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
doOpen(localhtml, 'random_string', 'toolbarposition=top,location=no');
|
||||
}, 'openLocalRandomToolBarTopNoLocation');
|
||||
|
||||
//White Listed
|
||||
// White Listed
|
||||
createActionButton('* target=Default', function () {
|
||||
doOpen('http://cordova.apache.org');
|
||||
}, 'openWhiteListed');
|
||||
@@ -535,7 +542,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
doOpen('http://cordova.apache.org', 'random_string', 'location=no');
|
||||
}, 'openWhiteListedRandomNoLocation');
|
||||
|
||||
//Non White Listed
|
||||
// Non White Listed
|
||||
createActionButton('target=Default', function () {
|
||||
doOpen('http://www.apple.com');
|
||||
}, 'openNonWhiteListed');
|
||||
@@ -558,7 +565,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
doOpen('http://www.apple.com', 'random_string', 'location=no');
|
||||
}, 'openNonWhiteListedRandomNoLocation');
|
||||
|
||||
//Page with redirect
|
||||
// Page with redirect
|
||||
createActionButton('http://google.co.uk', function () {
|
||||
doOpen('http://google.co.uk', 'random_string', '', 1);
|
||||
}, 'openRedirect301');
|
||||
@@ -566,7 +573,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
doOpen('http://goo.gl/pUFqg', 'random_string', '', 2);
|
||||
}, 'openRedirect302');
|
||||
|
||||
//PDF URL
|
||||
// PDF URL
|
||||
createActionButton('Remote URL', function () {
|
||||
doOpen('http://www.stluciadance.com/prospectus_file/sample.pdf');
|
||||
}, 'openPDF');
|
||||
@@ -574,7 +581,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
doOpen(localpdf, '_blank');
|
||||
}, 'openPDFBlank');
|
||||
|
||||
//Invalid URL
|
||||
// Invalid URL
|
||||
createActionButton('Invalid Scheme', function () {
|
||||
doOpen('x-ttp://www.invalid.com/', '_blank');
|
||||
}, 'openInvalidScheme');
|
||||
@@ -585,7 +592,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
doOpen('nonexistent.html', '_blank');
|
||||
}, 'openInvalidMissing');
|
||||
|
||||
//CSS / JS injection
|
||||
// CSS / JS injection
|
||||
createActionButton('Original Document', function () {
|
||||
doOpen(injecthtml, '_blank');
|
||||
}, 'openOriginalDocument');
|
||||
@@ -614,7 +621,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
openWithScript(injecthtml, null, true);
|
||||
}, 'openScriptLiteralInjectionCallback');
|
||||
|
||||
//Open hidden
|
||||
// Open hidden
|
||||
createActionButton('Create Hidden', function () {
|
||||
openHidden('https://www.google.co.uk', true);
|
||||
}, 'openHidden');
|
||||
@@ -634,7 +641,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
}, 2000);
|
||||
}, 'openVisibleAndHide');
|
||||
|
||||
//Clearing cache
|
||||
// Clearing cache
|
||||
createActionButton('Clear Browser Cache', function () {
|
||||
doOpen('https://www.google.co.uk', '_blank', 'clearcache=yes');
|
||||
}, 'openClearCache');
|
||||
@@ -642,7 +649,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
doOpen('https://www.google.co.uk', '_blank', 'clearsessioncache=yes');
|
||||
}, 'openClearSessionCache');
|
||||
|
||||
//Video tag
|
||||
// Video tag
|
||||
createActionButton('Remote Video', function () {
|
||||
doOpen(videohtml, '_blank');
|
||||
}, 'openRemoteVideo');
|
||||
@@ -653,7 +660,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
doOpen(videohtml, '_blank', 'mediaPlaybackRequiresUserAction=yes');
|
||||
}, 'openRemoteNeedUserYesVideo');
|
||||
|
||||
//Local With Anchor Tag
|
||||
// Local With Anchor Tag
|
||||
createActionButton('Anchor1', function () {
|
||||
doOpen(localhtml + '#bogusanchor', '_blank');
|
||||
}, 'openAnchor1');
|
||||
@@ -671,17 +678,17 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
createActionButton('hardwareback=no', function () {
|
||||
doOpen('http://cordova.apache.org', '_blank', 'hardwareback=no');
|
||||
}, 'openHardwareBackNo');
|
||||
createActionButton('no hardwareback -> hardwareback=no -> no hardwareback', function() {
|
||||
createActionButton('no hardwareback -> hardwareback=no -> no hardwareback', function () {
|
||||
var ref = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes');
|
||||
ref.addEventListener('loadstop', function() {
|
||||
ref.addEventListener('loadstop', function () {
|
||||
ref.close();
|
||||
});
|
||||
ref.addEventListener('exit', function() {
|
||||
ref.addEventListener('exit', function () {
|
||||
var ref2 = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes,hardwareback=no');
|
||||
ref2.addEventListener('loadstop', function() {
|
||||
ref2.addEventListener('loadstop', function () {
|
||||
ref2.close();
|
||||
});
|
||||
ref2.addEventListener('exit', function() {
|
||||
ref2.addEventListener('exit', function () {
|
||||
cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes');
|
||||
});
|
||||
});
|
||||
|
||||
2
types/index.d.ts
vendored
2
types/index.d.ts
vendored
@@ -168,6 +168,8 @@ interface InAppBrowser extends Window {
|
||||
removeEventListener(type: string, callback: (event: Event) => void): void;
|
||||
/** Closes the InAppBrowser window. */
|
||||
close(): void;
|
||||
/** Hides the InAppBrowser window. Calling this has no effect if the InAppBrowser was already hidden. */
|
||||
hide(): void;
|
||||
/**
|
||||
* Displays an InAppBrowser window that was opened hidden. Calling this has no effect
|
||||
* if the InAppBrowser was already visible.
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
(function() {
|
||||
(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
|
||||
@@ -31,13 +31,13 @@
|
||||
var modulemapper = require('cordova/modulemapper');
|
||||
var urlutil = require('cordova/urlutil');
|
||||
|
||||
function InAppBrowser() {
|
||||
this.channels = {
|
||||
function InAppBrowser () {
|
||||
this.channels = {
|
||||
'loadstart': channel.create('loadstart'),
|
||||
'loadstop' : channel.create('loadstop'),
|
||||
'loaderror' : channel.create('loaderror'),
|
||||
'exit' : channel.create('exit')
|
||||
};
|
||||
'loadstop': channel.create('loadstop'),
|
||||
'loaderror': channel.create('loaderror'),
|
||||
'exit': channel.create('exit')
|
||||
};
|
||||
}
|
||||
|
||||
InAppBrowser.prototype = {
|
||||
@@ -47,47 +47,47 @@
|
||||
}
|
||||
},
|
||||
close: function (eventname) {
|
||||
exec(null, null, "InAppBrowser", "close", []);
|
||||
exec(null, null, 'InAppBrowser', 'close', []);
|
||||
},
|
||||
show: function (eventname) {
|
||||
exec(null, null, "InAppBrowser", "show", []);
|
||||
exec(null, null, 'InAppBrowser', 'show', []);
|
||||
},
|
||||
hide: function (eventname) {
|
||||
exec(null, null, "InAppBrowser", "hide", []);
|
||||
exec(null, null, 'InAppBrowser', 'hide', []);
|
||||
},
|
||||
addEventListener: function (eventname,f) {
|
||||
addEventListener: function (eventname, f) {
|
||||
if (eventname in this.channels) {
|
||||
this.channels[eventname].subscribe(f);
|
||||
}
|
||||
},
|
||||
removeEventListener: function(eventname, f) {
|
||||
removeEventListener: function (eventname, f) {
|
||||
if (eventname in this.channels) {
|
||||
this.channels[eventname].unsubscribe(f);
|
||||
}
|
||||
},
|
||||
|
||||
executeScript: function(injectDetails, cb) {
|
||||
executeScript: function (injectDetails, cb) {
|
||||
if (injectDetails.code) {
|
||||
exec(cb, null, "InAppBrowser", "injectScriptCode", [injectDetails.code, !!cb]);
|
||||
exec(cb, null, 'InAppBrowser', 'injectScriptCode', [injectDetails.code, !!cb]);
|
||||
} else if (injectDetails.file) {
|
||||
exec(cb, null, "InAppBrowser", "injectScriptFile", [injectDetails.file, !!cb]);
|
||||
exec(cb, null, 'InAppBrowser', 'injectScriptFile', [injectDetails.file, !!cb]);
|
||||
} else {
|
||||
throw new Error('executeScript requires exactly one of code or file to be specified');
|
||||
}
|
||||
},
|
||||
|
||||
insertCSS: function(injectDetails, cb) {
|
||||
insertCSS: function (injectDetails, cb) {
|
||||
if (injectDetails.code) {
|
||||
exec(cb, null, "InAppBrowser", "injectStyleCode", [injectDetails.code, !!cb]);
|
||||
exec(cb, null, 'InAppBrowser', 'injectStyleCode', [injectDetails.code, !!cb]);
|
||||
} else if (injectDetails.file) {
|
||||
exec(cb, null, "InAppBrowser", "injectStyleFile", [injectDetails.file, !!cb]);
|
||||
exec(cb, null, 'InAppBrowser', 'injectStyleFile', [injectDetails.file, !!cb]);
|
||||
} else {
|
||||
throw new Error('insertCSS requires exactly one of code or file to be specified');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = function(strUrl, strWindowName, strWindowFeatures, callbacks) {
|
||||
module.exports = function (strUrl, strWindowName, strWindowFeatures, callbacks) {
|
||||
// Don't catch calls that write to existing frames (e.g. named iframes).
|
||||
if (window.frames && window.frames[strWindowName]) {
|
||||
var origOpenFunc = modulemapper.getOriginalSymbol(window, 'open');
|
||||
@@ -102,13 +102,13 @@
|
||||
iab.addEventListener(callbackName, callbacks[callbackName]);
|
||||
}
|
||||
|
||||
var cb = function(eventname) {
|
||||
iab._eventHandler(eventname);
|
||||
var cb = function (eventname) {
|
||||
iab._eventHandler(eventname);
|
||||
};
|
||||
|
||||
strWindowFeatures = strWindowFeatures || "";
|
||||
strWindowFeatures = strWindowFeatures || '';
|
||||
|
||||
exec(cb, cb, "InAppBrowser", "open", [strUrl, strWindowName, strWindowFeatures]);
|
||||
exec(cb, cb, 'InAppBrowser', 'open', [strUrl, strWindowName, strWindowFeatures]);
|
||||
return iab;
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -1,130 +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.
|
||||
*
|
||||
*/
|
||||
|
||||
/*jslint sloppy:true */
|
||||
/*global Windows:true, require, document, setTimeout, window, module */
|
||||
|
||||
var browserWrap;
|
||||
|
||||
var IAB = {
|
||||
|
||||
close: function (win, lose) {
|
||||
if (browserWrap) {
|
||||
browserWrap.parentNode.removeChild(browserWrap);
|
||||
browserWrap = null;
|
||||
}
|
||||
},
|
||||
show: function (win, lose) {
|
||||
/* empty block, ran out of bacon?
|
||||
if (browserWrap) {
|
||||
|
||||
}*/
|
||||
},
|
||||
hide: function (win, lose) {
|
||||
/* empty block, ran out of bacon?
|
||||
if (browserWrap) {
|
||||
|
||||
}*/
|
||||
},
|
||||
open: function (win, lose, args) {
|
||||
var strUrl = args[0],
|
||||
target = args[1],
|
||||
url,
|
||||
elem;
|
||||
|
||||
if (target === "_system") {
|
||||
url = new Windows.Foundation.Uri(strUrl);
|
||||
Windows.System.Launcher.launchUriAsync(url);
|
||||
} else if (target === "_blank") {
|
||||
if (!browserWrap) {
|
||||
browserWrap = document.createElement("div");
|
||||
browserWrap.style.position = "absolute";
|
||||
browserWrap.style.width = (window.innerWidth - 80) + "px";
|
||||
browserWrap.style.height = (window.innerHeight - 80) + "px";
|
||||
browserWrap.style.borderWidth = "40px";
|
||||
browserWrap.style.borderStyle = "solid";
|
||||
browserWrap.style.borderColor = "rgba(0,0,0,0.25)";
|
||||
browserWrap.style.zIndex = "9999999";
|
||||
|
||||
browserWrap.onclick = function () {
|
||||
setTimeout(function () {
|
||||
IAB.close();
|
||||
}, 0);
|
||||
};
|
||||
|
||||
document.body.appendChild(browserWrap);
|
||||
}
|
||||
var localFile = (strUrl.indexOf('ms-appdata:///') > -1);
|
||||
if (localFile) {
|
||||
elem = document.createElement("x-ms-webview");
|
||||
elem.style.width = (window.innerWidth - 80) + "px";
|
||||
elem.style.height = (window.innerHeight - 80) + "px";
|
||||
elem.style.borderWidth = "0px";
|
||||
elem.name = "targetFrame";
|
||||
elem.src = strUrl;
|
||||
|
||||
window.addEventListener("resize", function () {
|
||||
if (browserWrap && elem) {
|
||||
elem.style.width = (window.innerWidth - 80) + "px";
|
||||
elem.style.height = (window.innerHeight - 80) + "px";
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
elem = document.createElement("iframe");
|
||||
elem.style.width = (window.innerWidth - 80) + "px";
|
||||
elem.style.height = (window.innerHeight - 80) + "px";
|
||||
elem.style.borderWidth = "0px";
|
||||
elem.name = "targetFrame";
|
||||
elem.src = strUrl;
|
||||
|
||||
|
||||
window.addEventListener("resize", function () {
|
||||
if (browserWrap && elem) {
|
||||
elem.style.width = (window.innerWidth - 80) + "px";
|
||||
elem.style.height = (window.innerHeight - 80) + "px";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
browserWrap.appendChild(elem);
|
||||
} else {
|
||||
window.location = strUrl;
|
||||
}
|
||||
|
||||
//var object = new WinJS.UI.HtmlControl(elem, { uri: strUrl });
|
||||
|
||||
},
|
||||
|
||||
injectScriptCode: function (code, bCB) {
|
||||
|
||||
// "(function(d) { var c = d.createElement('script'); c.src = %@; d.body.appendChild(c); })(document)"
|
||||
},
|
||||
|
||||
injectScriptFile: function (file, bCB) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = IAB;
|
||||
|
||||
|
||||
require("cordova/exec/proxy").add("InAppBrowser", module.exports);
|
||||
Reference in New Issue
Block a user