Compare commits

..

46 Commits

Author SHA1 Message Date
Steve Gill 6c8106a706 CB-11832 Updated version and RELEASENOTES.md for release 1.5.0 2016-09-08 23:38:54 -07:00
Vladimir Kotikov 032c804937 CB-11795 Add 'protective' entry to cordovaDependencies
The entry is required to protect end-users from fetching edge versions of the plugin by incompatible version of cordova. This also assumes that we will not introduce any regressions in compatibility w/ cordova in minor and patch releases. On every major release we will need to add similar entry with _next_ major version.

 This closes #184
2016-09-08 11:54:34 +03:00
Julio César ccfbe7b8cd Closing invalid pull request: close #28 2016-08-30 00:00:36 +02:00
Julio César d08a730990 Closing invalid pull request: close #78 2016-08-29 23:57:54 +02:00
Gavin Pacini cc2ec22695 Add intent scheme to be handled by OS
The intent scheme `intent://` is [recommended by Google ](https://developer.chrome.com/multidevice/android/intents) for launching apps. Cordova should forward this to the OS to handle appropriately.

 This closes #183
2016-08-29 23:51:09 +02:00
Simon MacDonald 57b50b1d65 Plugin uses Android Log class and not Cordova LOG class 2016-08-22 16:41:34 -04:00
Norm Estabrook 4a0442b95a Adding links to guide content and reference content at the top of the readme file
Github: close #163
2016-08-22 18:03:14 +03:00
daserge 60d27b8d8d CB-10973 inAppBrowser for Browser Platform: wrong height of webview with location=yes 2016-08-22 17:31:58 +03:00
Pavel Kohoutek 22d466a050 Size and position in browser platform
CSS updated for iframe wrapper in browser platform. Styles and position of wrapper were dependent on parent element, global styles and other elements in body.
Now the wrapper/iframe should always cover entire window.
2016-08-22 17:16:04 +03:00
daserge a77b289f01 CB-10973 inAppBrowser for Windows Platform: wrong height of webview with location=yes 2016-08-19 17:43:48 +03:00
daserge 698648f15d CB-11013 IAB enabling background play of YouTube videos?
Adds shouldPause feature to stop backgound audio
2016-08-18 18:25:38 +03:00
daserge 2776b14db6 CB-10467 Hardware back button, while InAppBrowser is opened, closes the app too in addition to closing InAppBrowser 2016-08-17 19:56:51 +03:00
Julio César 3f63aaee58 CB-11178 allow to open other apps on iOS 9
This closes #177
2016-07-28 00:04:00 +02:00
Julio César 83c5e749f0 Closing stale pull request: close #152 2016-07-21 23:03:35 +02:00
Vasiliy Makarov 56dca03de7 fix some calls which used api level 16
This closes #170
2016-07-21 22:02:25 +02:00
Jesse MacFadyen 2a3a0cecab CB-5402 added extra content from wiki page 2016-07-20 13:10:14 -07:00
Jesse MacFadyen fc7452c445 CB-5402 Merge doc improvements 2016-07-20 12:55:03 -07:00
Julio César 64928480e9 Closing stale pull request: close #90 2016-07-17 20:48:50 +02:00
Julio César e9734667c6 CB-2063: (ios) Fixed presentation style
This closes #176
2016-07-17 20:35:38 +02:00
Julio César 6bdd538096 CB-11012 added some clarifications about InAppBrowser object
This closes #175
2016-07-17 13:27:31 +02:00
Connor Pearson 4ef6106259 CB-3360: Set custom inappbrowser user agent for ios
This closes #94

Signed-off-by: Shazron Abdullah <shazron@gmail.com>
2016-07-01 13:17:23 -07:00
Vladimir Kotikov 768f886c6a Add badges for paramedic builds on Jenkins 2016-06-10 12:04:16 +03:00
Rob Close bcdc0b9da0 CB-11381 android: Does not pass sonarqube scan
The problem is "Empty Catch Block", which sonarqube considers a blocker.  Added
a log message to the empty block.

 This closes #169
2016-06-08 12:40:50 +03:00
Nikhil Khandelwal aef8b9947b Add pull request template. 2016-05-23 13:53:59 -07:00
jakub-g f42226dddb doc: do not use with in JS samples
The usage of `with` JS statement is highly discouraged for a number of reasons, see

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with
http://www.2ality.com/2011/06/with-statement.html
2016-05-18 15:55:27 +02:00
Richard Knoll 066ba4c286 CB-10866: Adding engine requirements to package.json
This closes #155
2016-05-17 15:02:54 -07:00
Norm Estabrook 4543dec138 CB-110003: Adding samples to Readme.
This closes #161
2016-04-25 17:14:19 -07:00
Dmitry Blotsky fc66109f93 CB-10996 Adding front matter to README.md 2016-04-22 19:35:51 -07:00
Steve Gill 37b3d249da CB-11091 Incremented plugin version. 2016-04-15 13:45:27 -07:00
Steve Gill 56bb457c5e Updated version and RELEASENOTES.md for release 1.4.0 2016-04-15 13:08:27 -07:00
Birge Clark c6ff803113 CB-7679 add fix for iOS upload. This closes #139 2016-03-25 15:44:25 +01:00
Alexis Kofman 21f4de0e2a CB-10944 : NoSuchMethodError in InAppBrowser plugin
This closes #158
2016-03-24 11:00:51 -07:00
Alexis Kofman 68054819d8 CB-10937 fix stretched icons
This closes # 157
2016-03-23 14:28:00 -07:00
riknoll 0db344327c CB-10760: Fixing README for display on Cordova website
This closes #153
2016-03-02 13:54:43 -08:00
daserge ea1253963b CB-10636 Add JSHint for plugins 2016-02-19 15:42:34 +03:00
Julio César 555d55ac8a Fixes CB-10607
When the device is in portrait upside down the toolbar appears at the
bottom. This fix set the origin to the 0,0 point
2016-02-13 19:33:21 +01:00
Vladimir Kotikov 2d836eea0f CB-10557 Incremented plugin version. 2016-02-09 13:21:08 +03:00
Vladimir Kotikov 5cbd28edb0 CB-10557 Updated version and RELEASENOTES.md for release 1.3.0 2016-02-09 13:21:02 +03:00
Connor Pearson 98b63cc37e CB-3360: Set custom inappbrowser user agent for android
github close #95
2016-02-08 22:40:27 +03:00
sgrebnov 4f3b4df7d1 CB-10538 cordova-plugin-inappbrowser timeout issue
There are some google scripts on Apache home page preventing page to fully loaded in time in some cases. Switched to Apache Community home page as test page and increased timeout just in case.

github close #149
2016-02-08 14:12:26 +03:00
Wolfram Kriesing 234cca4e5b CB-10395 InAppBrowser's WebView not storing cookies reliable on Android
github close #147
2016-02-08 12:15:24 +03:00
t1st3 bb69b79ca3 chore: edit package.json license to match SPDX id
See [NPM package.json spec for licenses](https://docs.npmjs.com/files/package.json#license) and [SPDX license IDs](https://spdx.org/licenses/)

X-ref: https://github.com/apache/cordova-plugin-device/pull/48
2016-02-07 18:31:19 +01:00
Julio César 80c8e56fb0 CB-10305 Gray bar appears in the wrong place on iOS
This closes #137
2016-02-04 18:32:52 +03:00
Sean Kelly b51a4dc54e CB-7786 Support mediaPlaybackRequiresUserAction on Android
This closes #132
2016-02-04 14:15:41 +03:00
sgrebnov be1f6076c2 CB-7500 executeScript with callback kills/blurs inAppBrowser window on Android
github close #146
2016-02-04 14:08:22 +03:00
sgrebnov f04f37a617 CB-10505 Incremented plugin version. 2016-02-02 14:32:42 +03:00
21 changed files with 732 additions and 146 deletions
+23
View File
@@ -0,0 +1,23 @@
<!--
Please make sure the checklist boxes are all checked before submitting the PR. The checklist
is intended as a quick reference, for complete details please see our Contributor Guidelines:
http://cordova.apache.org/contribute/contribute_guidelines.html
Thanks!
-->
### Platforms affected
### What does this PR do?
### What testing has been done on this change?
### Checklist
- [ ] [ICLA](http://www.apache.org/licenses/icla.txt) has been signed and submitted to secretary@apache.org.
- [ ] [Reported an issue](http://cordova.apache.org/contribute/issues.html) in the JIRA database
- [ ] Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected.
- [ ] Added automated test coverage as appropriate for this change.
+1
View File
@@ -12,6 +12,7 @@ Thumbs.db
*.swp *.swp
*.user *.user
node_modules
+16
View File
@@ -0,0 +1,16 @@
{
"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
}
}
+4
View File
@@ -0,0 +1,4 @@
language: node_js
sudo: false
node_js:
- "4.2"
+28 -1
View File
@@ -26,7 +26,7 @@ Anyone can contribute to Cordova. And we need your contributions.
There are multiple ways to contribute: report bugs, improve the docs, and There are multiple ways to contribute: report bugs, improve the docs, and
contribute code. contribute code.
For instructions on this, start with the For instructions on this, start with the
[contribution overview](http://cordova.apache.org/contribute/). [contribution overview](http://cordova.apache.org/contribute/).
The details are explained there, but the important items are: The details are explained there, but the important items are:
@@ -35,3 +35,30 @@ The details are explained there, but the important items are:
- Run the tests so your patch doesn't break existing functionality. - Run the tests so your patch doesn't break existing functionality.
We look forward to your contributions! We look forward to your contributions!
The notes on [Commit Workflow](https://github.com/apache/cordova-coho/blob/master/docs/committer-workflow.md#commit-workflow) can be helpful even if you are not a committer.
## Running plugin tests
* clone and install [cordova-plugin-test-framework](https://github.com/apache/cordova-plugin-test-framework)
```
git clone git@github.com:apache/cordova-plugin-test-framework.git
```
* edit ```cordova-plugin-test-framework/www/assets/index.html``` and add the following line
```
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com http://cordova.apache.org http://google.co.uk https://google.co.uk 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
```
* create test project
```
cordova create plugintest
cd plugintest
cordova platform add android
cordova plugin add ../cordova-plugin-inappbrowser
cordova plugin add ../cordova-plugin-inappbrowser/tests
cordova plugin add ../cordova-plugin-test-framework
```
* edit ```config.xml``` and replace ```<content src="index.html" />``` with ```<content src="cdvtests/index.html" />```
* run application
```
cordova run
```
+298 -12
View File
@@ -1,3 +1,7 @@
---
title: Inappbrowser
description: Open an in-app browser window.
---
<!-- <!--
# license: Licensed to the Apache Software Foundation (ASF) under one # license: Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file # or more contributor license agreements. See the NOTICE file
@@ -17,8 +21,16 @@
# under the License. # under the License.
--> -->
|Android|iOS| Windows 8.1 Store | Windows 8.1 Phone | Windows 10 Store | Travis CI |
|:-:|:-:|:-:|:-:|:-:|:-:|
|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android,PLUGIN=cordova-plugin-inappbrowser)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android,PLUGIN=cordova-plugin-inappbrowser/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-inappbrowser)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-inappbrowser/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-8.1-store,PLUGIN=cordova-plugin-inappbrowser)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-8.1-store,PLUGIN=cordova-plugin-inappbrowser/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-8.1-phone,PLUGIN=cordova-plugin-inappbrowser)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-8.1-phone,PLUGIN=cordova-plugin-inappbrowser/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-inappbrowser)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-inappbrowser/)|[![Build Status](https://travis-ci.org/apache/cordova-plugin-inappbrowser.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-inappbrowser)|
# cordova-plugin-inappbrowser # cordova-plugin-inappbrowser
You can show helpful articles, videos, and web resources inside of your app. Users can view web pages without leaving your app.
> To get a few ideas, check out the [sample](#sample) at the bottom of this page or go straight to the [reference](#reference) content.
This plugin provides a web browser view that displays when calling `cordova.InAppBrowser.open()`. This plugin provides a web browser view that displays when calling `cordova.InAppBrowser.open()`.
var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
@@ -54,10 +66,10 @@ Although `window.open` is in the global scope, InAppBrowser is not available unt
console.log("window.open works well"); console.log("window.open works well");
} }
:warning: Report issues 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%22Plugin%20InAppBrowser%22%20ORDER%20BY%20priority%20DESC%2C%20summary%20ASC%2C%20updatedDate%20DESC)
## <a id="reference">Reference
## Installation ## Installation
cordova plugin add cordova-plugin-inappbrowser cordova plugin add cordova-plugin-inappbrowser
@@ -77,7 +89,7 @@ instance, or the system browser.
var ref = cordova.InAppBrowser.open(url, target, options); var ref = cordova.InAppBrowser.open(url, target, options);
- __ref__: Reference to the `InAppBrowser` window. _(InAppBrowser)_ - __ref__: Reference to the `InAppBrowser` window when the target is set to `'_blank'`. _(InAppBrowser)_
- __url__: The URL to load _(String)_. Call `encodeURI()` on this if the URL contains Unicode characters. - __url__: The URL to load _(String)_. Call `encodeURI()` on this if the URL contains Unicode characters.
@@ -100,6 +112,8 @@ instance, or the system browser.
- __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
- __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `yes`. - __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `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. - __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.
- __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)).
iOS only: iOS only:
@@ -110,7 +124,7 @@ instance, or the system browser.
- __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
- __toolbar__: set to `yes` or `no` to turn the toolbar on or off for the InAppBrowser (defaults to `yes`) - __toolbar__: set to `yes` or `no` to turn the toolbar on or off for the InAppBrowser (defaults to `yes`)
- __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`). - __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`).
- __mediaPlaybackRequiresUserAction__: Set to `yes` or `no` to prevent HTML5 audio or video from autoplaying (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`) - __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`)
- __keyboardDisplayRequiresUserAction__: Set to `yes` or `no` to open the keyboard when form elements receive focus via JavaScript's `focus()` call (defaults to `yes`). - __keyboardDisplayRequiresUserAction__: Set to `yes` or `no` to open the keyboard when form elements receive focus via JavaScript's `focus()` call (defaults to `yes`).
- __suppressesIncrementalRendering__: Set to `yes` or `no` to wait until all new view content is received before being rendered (defaults to `no`). - __suppressesIncrementalRendering__: Set to `yes` or `no` to wait until all new view content is received before being rendered (defaults to `no`).
@@ -122,6 +136,7 @@ instance, or the system browser.
- __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. - __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. - __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.
### Supported Platforms ### Supported Platforms
@@ -174,7 +189,7 @@ opened with `target='_blank'`. The rules might look like these
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'`. 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. 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 Similar to Firefox OS IAB window visual behaviour can be overridden via `inAppBrowserWrap`/`inAppBrowserWrapFullscreen` CSS classes
@@ -186,7 +201,7 @@ Similar to Firefox OS IAB window visual behaviour can be overridden via `inAppBr
## InAppBrowser ## InAppBrowser
The object returned from a call to `cordova.InAppBrowser.open`. The object returned from a call to `cordova.InAppBrowser.open` when the target is set to `'_blank'`.
### Methods ### Methods
@@ -197,7 +212,7 @@ The object returned from a call to `cordova.InAppBrowser.open`.
- executeScript - executeScript
- insertCSS - insertCSS
## addEventListener ## InAppBrowser.addEventListener
> Adds a listener for an event from the `InAppBrowser`. > Adds a listener for an event from the `InAppBrowser`.
@@ -214,6 +229,76 @@ The object returned from a call to `cordova.InAppBrowser.open`.
- __callback__: the function that executes when the event fires. The function is passed an `InAppBrowserEvent` object as a parameter. - __callback__: the function that executes when the event fires. The function is passed an `InAppBrowserEvent` object as a parameter.
## Example
```javascript
var inAppBrowserRef;
function showHelp(url) {
var target = "_blank";
var options = "location=yes,hidden=yes";
inAppBrowserRef = cordova.InAppBrowser.open(url, target, options);
inAppBrowserRef.addEventListener('loadstart', loadStartCallBack);
inAppBrowserRef.addEventListener('loadstop', loadStopCallBack);
inAppBrowserRef.addEventListener('loaderror', loadErrorCallBack);
}
function loadStartCallBack() {
$('#status-message').text("loading please wait ...");
}
function loadStopCallBack() {
if (inAppBrowserRef != undefined) {
inAppBrowserRef.insertCSS({ code: "body{font-size: 25px;" });
$('#status-message').text("");
inAppBrowserRef.show();
}
}
function loadErrorCallBack(params) {
$('#status-message').text("");
var scriptErrorMesssage =
"alert('Sorry we cannot open that page. Message from the server is : "
+ params.message + "');"
inAppBrowserRef.executeScript({ code: scriptErrorMesssage }, executeScriptCallBack);
inAppBrowserRef.close();
inAppBrowserRef = undefined;
}
function executeScriptCallBack(params) {
if (params[0] == null) {
$('#status-message').text(
"Sorry we couldn't open that page. Message from the server is : '"
+ params.message + "'");
}
}
```
### InAppBrowserEvent Properties ### InAppBrowserEvent Properties
- __type__: the eventname, either `loadstart`, `loadstop`, `loaderror`, or `exit`. _(String)_ - __type__: the eventname, either `loadstart`, `loadstop`, `loaderror`, or `exit`. _(String)_
@@ -243,7 +328,7 @@ The object returned from a call to `cordova.InAppBrowser.open`.
var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
ref.addEventListener('loadstart', function(event) { alert(event.url); }); ref.addEventListener('loadstart', function(event) { alert(event.url); });
## removeEventListener ## InAppBrowser.removeEventListener
> Removes a listener for an event from the `InAppBrowser`. > Removes a listener for an event from the `InAppBrowser`.
@@ -277,7 +362,7 @@ The function is passed an `InAppBrowserEvent` object.
ref.addEventListener('loadstart', myCallback); ref.addEventListener('loadstart', myCallback);
ref.removeEventListener('loadstart', myCallback); ref.removeEventListener('loadstart', myCallback);
## close ## InAppBrowser.close
> Closes the `InAppBrowser` window. > Closes the `InAppBrowser` window.
@@ -300,7 +385,7 @@ The function is passed an `InAppBrowserEvent` object.
var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes'); var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
ref.close(); ref.close();
## show ## InAppBrowser.show
> Displays an InAppBrowser window that was opened hidden. Calling this has no effect if the InAppBrowser was already visible. > Displays an InAppBrowser window that was opened hidden. Calling this has no effect if the InAppBrowser was already visible.
@@ -322,7 +407,7 @@ The function is passed an `InAppBrowserEvent` object.
// some time later... // some time later...
ref.show(); ref.show();
## executeScript ## InAppBrowser.executeScript
> Injects JavaScript code into the `InAppBrowser` window > Injects JavaScript code into the `InAppBrowser` window
@@ -364,7 +449,7 @@ The function is passed an `InAppBrowserEvent` object.
Due to [MSDN docs](https://msdn.microsoft.com/en-us/library/windows.ui.xaml.controls.webview.invokescriptasync.aspx) the invoked script can return only string values, otherwise the parameter, passed to __callback__ will be `[null]`. Due to [MSDN docs](https://msdn.microsoft.com/en-us/library/windows.ui.xaml.controls.webview.invokescriptasync.aspx) the invoked script can return only string values, otherwise the parameter, passed to __callback__ will be `[null]`.
## insertCSS ## InAppBrowser.insertCSS
> Injects CSS into the `InAppBrowser` window. > Injects CSS into the `InAppBrowser` window.
@@ -391,3 +476,204 @@ Due to [MSDN docs](https://msdn.microsoft.com/en-us/library/windows.ui.xaml.cont
ref.addEventListener('loadstop', function() { ref.addEventListener('loadstop', function() {
ref.insertCSS({file: "mystyles.css"}); ref.insertCSS({file: "mystyles.css"});
}); });
__
## <a id="sample"></a>Sample: Show help pages with an InAppBrowser
You can use this plugin to show helpful documentation pages within your app. Users can view online help documents and then close them without leaving the app.
Here's a few snippets that show how you do this.
* [Give users a way to ask for help](#give).
* [Load a help page](#load).
* [Let users know that you're getting their page ready](#let).
* [Show the help page](#show).
* [Handle page errors](#handle).
### <a id="give"></a>Give users a way to ask for help
There's lots of ways to do this in your app. A drop down list is a simple way to do that.
```html
<select id="help-select">
<option value="default">Need help?</option>
<option value="article">Show me a helpful article</option>
<option value="video">Show me a helpful video</option>
<option value="search">Search for other topics</option>
</select>
```
Gather the users choice in the ``onDeviceReady`` function of the page and then send an appropriate URL to a helper function in some shared library file. Our helper function is named ``showHelp()`` and we'll write that function next.
```javascript
$('#help-select').on('change', function (e) {
var url;
switch (this.value) {
case "article":
url = "https://cordova.apache.org/docs/en/latest/"
+ "reference/cordova-plugin-inappbrowser/index.html";
break;
case "video":
url = "https://youtu.be/F-GlVrTaeH0";
break;
case "search":
url = "https://www.google.com/#q=inAppBrowser+plugin";
break;
}
showHelp(url);
});
```
### <a id="load"></a>Load a help page
We'll use the ``open`` function to load the help page. We're setting the ``hidden`` property to ``yes`` so that we can show the browser only after the page content has loaded. That way, users don't see a blank browser while they wait for content to appear. When the ``loadstop`` event is raised, we'll know when the content has loaded. We'll handle that event shortly.
```javascript
function showHelp(url) {
var target = "_blank";
var options = "location=yes,hidden=yes";
inAppBrowserRef = cordova.InAppBrowser.open(url, target, options);
inAppBrowserRef.addEventListener('loadstart', loadStartCallBack);
inAppBrowserRef.addEventListener('loadstop', loadStopCallBack);
inAppBrowserRef.addEventListener('loaderror', loadErrorCallBack);
}
```
### <a id="let"></a>Let users know that you're getting their page ready
Because the browser doesn't immediately appear, we can use the ``loadstart`` event to show a status message, progress bar, or other indicator. This assures users that content is on the way.
```javascript
function loadStartCallBack() {
$('#status-message').text("loading please wait ...");
}
```
### <a id="show"></a>Show the help page
When the ``loadstopcallback`` event is raised, we know that the content has loaded and we can make the browser visible. This sort of trick can create the impression of better performance. The truth is that whether you show the browser before content loads or not, the load times are exactly the same.
```javascript
function loadStopCallBack() {
if (inAppBrowserRef != undefined) {
inAppBrowserRef.insertCSS({ code: "body{font-size: 25px;" });
$('#status-message').text("");
inAppBrowserRef.show();
}
}
```
You might have noticed the call to the ``insertCSS`` function. This serves no particular purpose in our scenario. But it gives you an idea of why you might use it. In this case, we're just making sure that the font size of your pages have a certain size. You can use this function to insert any CSS style elements. You can even point to a CSS file in your project.
### <a id="handle"></a>Handle page errors
Sometimes a page no longer exists, a script error occurs, or a user lacks permission to view the resource. How or if you handle that situation is completely up to you and your design. You can let the browser show that message or you can present it in another way.
We'll try to show that error in a message box. We can do that by injecting a script that calls the ``alert`` function. That said, this won't work in browsers on Windows devices so we'll have to look at the parameter of the ``executeScript`` callback function to see if our attempt worked. If it didn't work out for us, we'll just show the error message in a ``<div>`` on the page.
```javascript
function loadErrorCallBack(params) {
$('#status-message').text("");
var scriptErrorMesssage =
"alert('Sorry we cannot open that page. Message from the server is : "
+ params.message + "');"
inAppBrowserRef.executeScript({ code: scriptErrorMesssage }, executeScriptCallBack);
inAppBrowserRef.close();
inAppBrowserRef = undefined;
}
function executeScriptCallBack(params) {
if (params[0] == null) {
$('#status-message').text(
"Sorry we couldn't open that page. Message from the server is : '"
+ params.message + "'");
}
}
```
## More Usage Info
### Local Urls ( source is in the app package )
```
var iab = cordova.InAppBrowser;
iab.open('local-url.html'); // loads in the Cordova WebView
iab.open('local-url.html', '_self'); // loads in the Cordova WebView
iab.open('local-url.html', '_system'); // Security error: system browser, but url will not load (iOS)
iab.open('local-url.html', '_blank'); // loads in the InAppBrowser
iab.open('local-url.html', 'random_string'); // loads in the InAppBrowser
iab.open('local-url.html', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar
```
### Whitelisted Content
```
var iab = cordova.InAppBrowser;
iab.open('http://whitelisted-url.com'); // loads in the Cordova WebView
iab.open('http://whitelisted-url.com', '_self'); // loads in the Cordova WebView
iab.open('http://whitelisted-url.com', '_system'); // loads in the system browser
iab.open('http://whitelisted-url.com', '_blank'); // loads in the InAppBrowser
iab.open('http://whitelisted-url.com', 'random_string'); // loads in the InAppBrowser
iab.open('http://whitelisted-url.com', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar
```
### Urls that are not white-listed
```
var iab = cordova.InAppBrowser;
iab.open('http://url-that-fails-whitelist.com'); // loads in the InAppBrowser
iab.open('http://url-that-fails-whitelist.com', '_self'); // loads in the InAppBrowser
iab.open('http://url-that-fails-whitelist.com', '_system'); // loads in the system browser
iab.open('http://url-that-fails-whitelist.com', '_blank'); // loads in the InAppBrowser
iab.open('http://url-that-fails-whitelist.com', 'random_string'); // loads in the InAppBrowser
iab.open('http://url-that-fails-whitelist.com', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar
```
+48 -9
View File
@@ -20,6 +20,45 @@
--> -->
# Release Notes # Release Notes
### 1.5.0 (Sep 08, 2016)
* [CB-11795](https://issues.apache.org/jira/browse/CB-11795) Add 'protective' entry to cordovaDependencies
* Add intent scheme to be handled by OS
* Plugin uses `Android Log class` and not `Cordova LOG class`
* Adding links to guide content and reference content at the top of the readme file Github: close #163
* [CB-10973](https://issues.apache.org/jira/browse/CB-10973) **Browser**: wrong height of webview with `location=yes`
* Size and position in browser platform
* [CB-10973](https://issues.apache.org/jira/browse/CB-10973) **Windows**: wrong height of webview with `location=yes`
* [CB-11013](https://issues.apache.org/jira/browse/CB-11013) IAB enabling background play of YouTube videos?
* [CB-10467](https://issues.apache.org/jira/browse/CB-10467) Hardware back button, while `InAppBrowser` is opened, closes the app too in addition to closing `InAppBrowser`
* [CB-11178](https://issues.apache.org/jira/browse/CB-11178) allow to open other apps on **iOS 9**
* fix some calls which used api level 16
* [CB-5402](https://issues.apache.org/jira/browse/CB-5402) added extra content from wiki page
* [CB-2063](https://issues.apache.org/jira/browse/CB-2063) (**ios**) Fixed presentation style
* [CB-11012](https://issues.apache.org/jira/browse/CB-11012) added some clarifications about `InAppBrowser` object
* [CB-3360](https://issues.apache.org/jira/browse/CB-3360) Set custom `inappbrowser` user agent for **ios**
* Add badges for paramedic builds on Jenkins
* [CB-11381](https://issues.apache.org/jira/browse/CB-11381) android: Does not pass sonarqube scan
* Add pull request template.
* [CB-10866](https://issues.apache.org/jira/browse/CB-10866) Adding engine requirements to `package.json`
* [CB-110003](https://issues.apache.org/jira/browse/CB-110003) Adding samples to Readme.
* [CB-10996](https://issues.apache.org/jira/browse/CB-10996) Adding front matter to README.md
### 1.4.0 (Apr 15, 2016)
* [CB-7679](https://issues.apache.org/jira/browse/CB-7679) add fix for **iOS** upload.
* [CB-10944](https://issues.apache.org/jira/browse/CB-10944) `NoSuchMethodError` in `InAppBrowser` plugin
* [CB-10937](https://issues.apache.org/jira/browse/CB-10937) fix stretched icons
* [CB-10760](https://issues.apache.org/jira/browse/CB-10760) Fixing README for display on Cordova website
* [CB-10636](https://issues.apache.org/jira/browse/CB-10636) Add `JSHint` for plugins
### 1.3.0 (Feb 09, 2016)
* [CB-3360](https://issues.apache.org/jira/browse/CB-3360) Set custom inappbrowser user agent for android
* [CB-10538](https://issues.apache.org/jira/browse/CB-10538) cordova-plugin-inappbrowser timeout issue
* [CB-10395](https://issues.apache.org/jira/browse/CB-10395) InAppBrowser's WebView not storing cookies reliable on Android
* Edit package.json license to match SPDX id
* [CB-10305](https://issues.apache.org/jira/browse/CB-10305) Gray bar appears in the wrong place on iOS
* [CB-7786](https://issues.apache.org/jira/browse/CB-7786) Support mediaPlaybackRequiresUserAction on Android
* [CB-7500](https://issues.apache.org/jira/browse/CB-7500) executeScript with callback kills/blurs inAppBrowser window on Android
### 1.2.1 (Feb 02, 2016) ### 1.2.1 (Feb 02, 2016)
* [CB-10407](https://issues.apache.org/jira/browse/CB-10407) InAppBrowser not firing loadstart event on android * [CB-10407](https://issues.apache.org/jira/browse/CB-10407) InAppBrowser not firing loadstart event on android
* [CB-10428](https://issues.apache.org/jira/browse/CB-10428) Fix syntax error when browserifying inAppBrowser plugin * [CB-10428](https://issues.apache.org/jira/browse/CB-10428) Fix syntax error when browserifying inAppBrowser plugin
@@ -33,19 +72,19 @@
* [CB-10441](https://issues.apache.org/jira/browse/CB-10441) Add auto tests for InAppBrowser plugin * [CB-10441](https://issues.apache.org/jira/browse/CB-10441) Add auto tests for InAppBrowser plugin
### 1.2.0 (Jan 15, 2016) ### 1.2.0 (Jan 15, 2016)
* CB-8180: Changing methods of interception in `WebViewClient` class * [CB-8180](https://issues.apache.org/jira/browse/CB-8180) Changing methods of interception in `WebViewClient` class
* CB-10009 Improve `InAppBrowser` toolbar look and feel on **Windows** * [CB-10009](https://issues.apache.org/jira/browse/CB-10009) Improve `InAppBrowser` toolbar look and feel on **Windows**
* Open a new window on the **Browser** platform * Open a new window on the **Browser** platform
### 1.1.1 (Dec 10, 2015) ### 1.1.1 (Dec 10, 2015)
* CB-9445 Improves executeScript callbacks on iOS * [CB-9445](https://issues.apache.org/jira/browse/CB-9445) Improves executeScript callbacks on iOS
* CB-10035 Incremented plugin version. * [CB-10035](https://issues.apache.org/jira/browse/CB-10035) Incremented plugin version.
* CB-10040 - re-fix: backwards compatible with cordova-ios < 4.0 * [CB-10040](https://issues.apache.org/jira/browse/CB-10040) - re-fix: backwards compatible with cordova-ios < 4.0
* CB-8534: Allow plugins to respond to onReceivedHttpAuthRequest. This closes #82 * [CB-8534](https://issues.apache.org/jira/browse/CB-8534) Allow plugins to respond to onReceivedHttpAuthRequest. This closes #82
* CB-3750: Fixes spinner on iOS. This closes #89 * [CB-3750](https://issues.apache.org/jira/browse/CB-3750) Fixes spinner on iOS. This closes #89
* CB-7696 Document target=_self behavior for Windows * [CB-7696](https://issues.apache.org/jira/browse/CB-7696) Document target=_self behavior for Windows
* CB-10040 - Compile Error in InAppBrowser Plugin for iOS - No known instance method for selector 'URLIsWhitelisted:' * [CB-10040](https://issues.apache.org/jira/browse/CB-10040) - Compile Error in InAppBrowser Plugin for iOS - No known instance method for selector 'URLIsWhitelisted:'
### 1.1.0 (Nov 18, 2015) ### 1.1.0 (Nov 18, 2015)
* [CB-10035](https://issues.apache.org/jira/browse/CB-10035) Updated `RELEASENOTES` to be newest to oldest * [CB-10035](https://issues.apache.org/jira/browse/CB-10035) Updated `RELEASENOTES` to be newest to oldest
+18 -7
View File
@@ -1,6 +1,6 @@
{ {
"name": "cordova-plugin-inappbrowser", "name": "cordova-plugin-inappbrowser",
"version": "1.2.1", "version": "1.5.0",
"description": "Cordova InAppBrowser Plugin", "description": "Cordova InAppBrowser Plugin",
"cordova": { "cordova": {
"id": "cordova-plugin-inappbrowser", "id": "cordova-plugin-inappbrowser",
@@ -37,12 +37,23 @@
"cordova-windows", "cordova-windows",
"cordova-firefoxos" "cordova-firefoxos"
], ],
"engines": [ "scripts": {
{ "test": "npm run jshint",
"name": "cordova", "jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests"
"version": ">=3.1.0" },
"engines": {
"cordovaDependencies": {
"0.2.3": {
"cordova": ">=3.1.0"
},
"2.0.0": {
"cordova": ">100"
}
} }
], },
"author": "Apache Software Foundation", "author": "Apache Software Foundation",
"license": "Apache 2.0" "license": "Apache-2.0",
"devDependencies": {
"jshint": "^2.6.0"
}
} }
+1 -1
View File
@@ -20,7 +20,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-inappbrowser" id="cordova-plugin-inappbrowser"
version="1.2.1"> version="1.5.0">
<name>InAppBrowser</name> <name>InAppBrowser</name>
<description>Cordova InAppBrowser Plugin</description> <description>Cordova InAppBrowser Plugin</description>
+116 -45
View File
@@ -19,7 +19,6 @@
package org.apache.cordova.inappbrowser; package org.apache.cordova.inappbrowser;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import org.apache.cordova.inappbrowser.InAppBrowserDialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.provider.Browser; import android.provider.Browser;
@@ -30,7 +29,6 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputType; import android.text.InputType;
import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
@@ -41,12 +39,14 @@ import android.view.WindowManager.LayoutParams;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.webkit.CookieManager; import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.HttpAuthHandler; import android.webkit.HttpAuthHandler;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
@@ -85,6 +85,8 @@ public class InAppBrowser extends CordovaPlugin {
private static final String CLEAR_ALL_CACHE = "clearcache"; private static final String CLEAR_ALL_CACHE = "clearcache";
private static final String CLEAR_SESSION_CACHE = "clearsessioncache"; private static final String CLEAR_SESSION_CACHE = "clearsessioncache";
private static final String HARDWARE_BACK_BUTTON = "hardwareback"; private static final String HARDWARE_BACK_BUTTON = "hardwareback";
private static final String MEDIA_PLAYBACK_REQUIRES_USER_ACTION = "mediaPlaybackRequiresUserAction";
private static final String SHOULD_PAUSE = "shouldPauseOnSuspend";
private InAppBrowserDialog dialog; private InAppBrowserDialog dialog;
private WebView inAppWebView; private WebView inAppWebView;
@@ -96,6 +98,8 @@ public class InAppBrowser extends CordovaPlugin {
private boolean clearAllCache = false; private boolean clearAllCache = false;
private boolean clearSessionCache = false; private boolean clearSessionCache = false;
private boolean hadwareBackButton = true; private boolean hadwareBackButton = true;
private boolean mediaPlaybackRequiresUserGesture = false;
private boolean shouldPauseInAppBrowser = false;
/** /**
* Executes the request and returns PluginResult. * Executes the request and returns PluginResult.
@@ -116,7 +120,7 @@ public class InAppBrowser extends CordovaPlugin {
final String target = t; final String target = t;
final HashMap<String, Boolean> features = parseFeature(args.optString(2)); final HashMap<String, Boolean> features = parseFeature(args.optString(2));
Log.d(LOG_TAG, "target = " + target); LOG.d(LOG_TAG, "target = " + target);
this.cordova.getActivity().runOnUiThread(new Runnable() { this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override @Override
@@ -124,7 +128,7 @@ public class InAppBrowser extends CordovaPlugin {
String result = ""; String result = "";
// SELF // SELF
if (SELF.equals(target)) { if (SELF.equals(target)) {
Log.d(LOG_TAG, "in self"); LOG.d(LOG_TAG, "in self");
/* This code exists for compatibility between 3.x and 4.x versions of Cordova. /* This code exists for compatibility between 3.x and 4.x versions of Cordova.
* Previously the Config class had a static method, isUrlWhitelisted(). That * Previously the Config class had a static method, isUrlWhitelisted(). That
* responsibility has been moved to the plugins, with an aggregating method in * responsibility has been moved to the plugins, with an aggregating method in
@@ -139,8 +143,11 @@ public class InAppBrowser extends CordovaPlugin {
Method iuw = Config.class.getMethod("isUrlWhiteListed", String.class); Method iuw = Config.class.getMethod("isUrlWhiteListed", String.class);
shouldAllowNavigation = (Boolean)iuw.invoke(null, url); shouldAllowNavigation = (Boolean)iuw.invoke(null, url);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
LOG.d(LOG_TAG, e.getLocalizedMessage());
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
LOG.d(LOG_TAG, e.getLocalizedMessage());
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
LOG.d(LOG_TAG, e.getLocalizedMessage());
} }
} }
if (shouldAllowNavigation == null) { if (shouldAllowNavigation == null) {
@@ -150,20 +157,23 @@ public class InAppBrowser extends CordovaPlugin {
Method san = pm.getClass().getMethod("shouldAllowNavigation", String.class); Method san = pm.getClass().getMethod("shouldAllowNavigation", String.class);
shouldAllowNavigation = (Boolean)san.invoke(pm, url); shouldAllowNavigation = (Boolean)san.invoke(pm, url);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
LOG.d(LOG_TAG, e.getLocalizedMessage());
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
LOG.d(LOG_TAG, e.getLocalizedMessage());
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
LOG.d(LOG_TAG, e.getLocalizedMessage());
} }
} }
// load in webview // load in webview
if (Boolean.TRUE.equals(shouldAllowNavigation)) { if (Boolean.TRUE.equals(shouldAllowNavigation)) {
Log.d(LOG_TAG, "loading in webview"); LOG.d(LOG_TAG, "loading in webview");
webView.loadUrl(url); webView.loadUrl(url);
} }
//Load the dialer //Load the dialer
else if (url.startsWith(WebView.SCHEME_TEL)) else if (url.startsWith(WebView.SCHEME_TEL))
{ {
try { try {
Log.d(LOG_TAG, "loading in dialer"); LOG.d(LOG_TAG, "loading in dialer");
Intent intent = new Intent(Intent.ACTION_DIAL); Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse(url)); intent.setData(Uri.parse(url));
cordova.getActivity().startActivity(intent); cordova.getActivity().startActivity(intent);
@@ -173,18 +183,18 @@ public class InAppBrowser extends CordovaPlugin {
} }
// load in InAppBrowser // load in InAppBrowser
else { else {
Log.d(LOG_TAG, "loading in InAppBrowser"); LOG.d(LOG_TAG, "loading in InAppBrowser");
result = showWebPage(url, features); result = showWebPage(url, features);
} }
} }
// SYSTEM // SYSTEM
else if (SYSTEM.equals(target)) { else if (SYSTEM.equals(target)) {
Log.d(LOG_TAG, "in system"); LOG.d(LOG_TAG, "in system");
result = openExternal(url); result = openExternal(url);
} }
// BLANK - or anything else // BLANK - or anything else
else { else {
Log.d(LOG_TAG, "in blank"); LOG.d(LOG_TAG, "in blank");
result = showWebPage(url, features); result = showWebPage(url, features);
} }
@@ -200,7 +210,7 @@ public class InAppBrowser extends CordovaPlugin {
else if (action.equals("injectScriptCode")) { else if (action.equals("injectScriptCode")) {
String jsWrapper = null; String jsWrapper = null;
if (args.getBoolean(1)) { if (args.getBoolean(1)) {
jsWrapper = String.format("prompt(JSON.stringify([eval(%%s)]), 'gap-iab://%s')", callbackContext.getCallbackId()); jsWrapper = String.format("(function(){prompt(JSON.stringify([eval(%%s)]), 'gap-iab://%s')})()", callbackContext.getCallbackId());
} }
injectDeferredObject(args.getString(0), jsWrapper); injectDeferredObject(args.getString(0), jsWrapper);
} }
@@ -256,6 +266,26 @@ public class InAppBrowser extends CordovaPlugin {
closeDialog(); closeDialog();
} }
/**
* Called when the system is about to start resuming a previous activity.
*/
@Override
public void onPause(boolean multitasking) {
if (shouldPauseInAppBrowser) {
inAppWebView.onPause();
}
}
/**
* Called when the activity will start interacting with the user.
*/
@Override
public void onResume(boolean multitasking) {
if (shouldPauseInAppBrowser) {
inAppWebView.onResume();
}
}
/** /**
* Called by AccelBroker when listener is to be shut down. * Called by AccelBroker when listener is to be shut down.
* Stop listener. * Stop listener.
@@ -353,7 +383,7 @@ public class InAppBrowser extends CordovaPlugin {
this.cordova.getActivity().startActivity(intent); this.cordova.getActivity().startActivity(intent);
return ""; return "";
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
Log.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString()); LOG.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
return e.toString(); return e.toString();
} }
} }
@@ -391,7 +421,7 @@ public class InAppBrowser extends CordovaPlugin {
obj.put("type", EXIT_EVENT); obj.put("type", EXIT_EVENT);
sendUpdate(obj, false); sendUpdate(obj, false);
} catch (JSONException ex) { } catch (JSONException ex) {
Log.d(LOG_TAG, "Should never happen"); LOG.d(LOG_TAG, "Should never happen");
} }
} }
}); });
@@ -473,6 +503,8 @@ public class InAppBrowser extends CordovaPlugin {
showLocationBar = true; showLocationBar = true;
showZoomControls = true; showZoomControls = true;
openWindowHidden = false; openWindowHidden = false;
mediaPlaybackRequiresUserGesture = false;
if (features != null) { if (features != null) {
Boolean show = features.get(LOCATION); Boolean show = features.get(LOCATION);
if (show != null) { if (show != null) {
@@ -490,6 +522,10 @@ public class InAppBrowser extends CordovaPlugin {
if (hardwareBack != null) { if (hardwareBack != null) {
hadwareBackButton = hardwareBack.booleanValue(); hadwareBackButton = hardwareBack.booleanValue();
} }
Boolean mediaPlayback = features.get(MEDIA_PLAYBACK_REQUIRES_USER_ACTION);
if (mediaPlayback != null) {
mediaPlaybackRequiresUserGesture = mediaPlayback.booleanValue();
}
Boolean cache = features.get(CLEAR_ALL_CACHE); Boolean cache = features.get(CLEAR_ALL_CACHE);
if (cache != null) { if (cache != null) {
clearAllCache = cache.booleanValue(); clearAllCache = cache.booleanValue();
@@ -499,6 +535,10 @@ public class InAppBrowser extends CordovaPlugin {
clearSessionCache = cache.booleanValue(); clearSessionCache = cache.booleanValue();
} }
} }
Boolean shouldPause = features.get(SHOULD_PAUSE);
if (shouldPause != null) {
shouldPauseInAppBrowser = shouldPause.booleanValue();
}
} }
final CordovaWebView thatWebView = this.webView; final CordovaWebView thatWebView = this.webView;
@@ -555,7 +595,7 @@ public class InAppBrowser extends CordovaPlugin {
actionButtonContainer.setId(Integer.valueOf(1)); actionButtonContainer.setId(Integer.valueOf(1));
// Back button // Back button
Button back = new Button(cordova.getActivity()); ImageButton back = new ImageButton(cordova.getActivity());
RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT); backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
back.setLayoutParams(backLayoutParams); back.setLayoutParams(backLayoutParams);
@@ -564,14 +604,16 @@ public class InAppBrowser extends CordovaPlugin {
Resources activityRes = cordova.getActivity().getResources(); Resources activityRes = cordova.getActivity().getResources();
int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName()); int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName());
Drawable backIcon = activityRes.getDrawable(backResId); Drawable backIcon = activityRes.getDrawable(backResId);
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) if (Build.VERSION.SDK_INT >= 16)
{ back.setBackground(null);
back.setBackgroundDrawable(backIcon);
}
else else
{ back.setBackgroundDrawable(null);
back.setBackground(backIcon); back.setImageDrawable(backIcon);
} back.setScaleType(ImageView.ScaleType.FIT_CENTER);
back.setPadding(0, this.dpToPixels(10), 0, this.dpToPixels(10));
if (Build.VERSION.SDK_INT >= 16)
back.getAdjustViewBounds();
back.setOnClickListener(new View.OnClickListener() { back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
goBack(); goBack();
@@ -579,7 +621,7 @@ public class InAppBrowser extends CordovaPlugin {
}); });
// Forward button // Forward button
Button forward = new Button(cordova.getActivity()); ImageButton forward = new ImageButton(cordova.getActivity());
RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2); forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
forward.setLayoutParams(forwardLayoutParams); forward.setLayoutParams(forwardLayoutParams);
@@ -587,14 +629,16 @@ public class InAppBrowser extends CordovaPlugin {
forward.setId(Integer.valueOf(3)); forward.setId(Integer.valueOf(3));
int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName()); int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName());
Drawable fwdIcon = activityRes.getDrawable(fwdResId); Drawable fwdIcon = activityRes.getDrawable(fwdResId);
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) if (Build.VERSION.SDK_INT >= 16)
{ forward.setBackground(null);
forward.setBackgroundDrawable(fwdIcon);
}
else else
{ forward.setBackgroundDrawable(null);
forward.setBackground(fwdIcon); forward.setImageDrawable(fwdIcon);
} forward.setScaleType(ImageView.ScaleType.FIT_CENTER);
forward.setPadding(0, this.dpToPixels(10), 0, this.dpToPixels(10));
if (Build.VERSION.SDK_INT >= 16)
forward.getAdjustViewBounds();
forward.setOnClickListener(new View.OnClickListener() { forward.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
goForward(); goForward();
@@ -625,7 +669,7 @@ public class InAppBrowser extends CordovaPlugin {
}); });
// Close/Done button // Close/Done button
Button close = new Button(cordova.getActivity()); ImageButton close = new ImageButton(cordova.getActivity());
RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
close.setLayoutParams(closeLayoutParams); close.setLayoutParams(closeLayoutParams);
@@ -633,14 +677,16 @@ public class InAppBrowser extends CordovaPlugin {
close.setId(Integer.valueOf(5)); close.setId(Integer.valueOf(5));
int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName()); int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName());
Drawable closeIcon = activityRes.getDrawable(closeResId); Drawable closeIcon = activityRes.getDrawable(closeResId);
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) if (Build.VERSION.SDK_INT >= 16)
{ close.setBackground(null);
close.setBackgroundDrawable(closeIcon);
}
else else
{ close.setBackgroundDrawable(null);
close.setBackground(closeIcon); 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() { close.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
closeDialog(); closeDialog();
@@ -660,6 +706,20 @@ public class InAppBrowser extends CordovaPlugin {
settings.setBuiltInZoomControls(showZoomControls); settings.setBuiltInZoomControls(showZoomControls);
settings.setPluginState(android.webkit.WebSettings.PluginState.ON); settings.setPluginState(android.webkit.WebSettings.PluginState.ON);
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
settings.setMediaPlaybackRequiresUserGesture(mediaPlaybackRequiresUserGesture);
}
String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
String appendUserAgent = preferences.getString("AppendUserAgent", null);
if (overrideUserAgent != null) {
settings.setUserAgentString(overrideUserAgent);
}
if (appendUserAgent != null) {
settings.setUserAgentString(settings.getUserAgentString() + appendUserAgent);
}
//Toggle whether this is enabled or not! //Toggle whether this is enabled or not!
Bundle appSettings = cordova.getActivity().getIntent().getExtras(); Bundle appSettings = cordova.getActivity().getIntent().getExtras();
boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true); boolean enableDatabase = appSettings == null ? true : appSettings.getBoolean("InAppBrowserStorageEnabled", true);
@@ -783,7 +843,7 @@ public class InAppBrowser extends CordovaPlugin {
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString()); LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString());
} }
} else if (url.startsWith("geo:") || url.startsWith(WebView.SCHEME_MAILTO) || url.startsWith("market:")) { } else if (url.startsWith("geo:") || url.startsWith(WebView.SCHEME_MAILTO) || url.startsWith("market:") || url.startsWith("intent:")) {
try { try {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url)); intent.setData(Uri.parse(url));
@@ -870,6 +930,13 @@ public class InAppBrowser extends CordovaPlugin {
public void onPageFinished(WebView view, String url) { public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url); super.onPageFinished(view, url);
// CB-10395 InAppBrowser's WebView not storing cookies reliable to local device storage
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().flush();
} else {
CookieSyncManager.getInstance().sync();
}
try { try {
JSONObject obj = new JSONObject(); JSONObject obj = new JSONObject();
obj.put("type", LOAD_STOP_EVENT); obj.put("type", LOAD_STOP_EVENT);
@@ -877,7 +944,7 @@ public class InAppBrowser extends CordovaPlugin {
sendUpdate(obj, true); sendUpdate(obj, true);
} catch (JSONException ex) { } catch (JSONException ex) {
Log.d(LOG_TAG, "Should never happen"); LOG.d(LOG_TAG, "Should never happen");
} }
} }
@@ -893,10 +960,10 @@ public class InAppBrowser extends CordovaPlugin {
sendUpdate(obj, true, PluginResult.Status.ERROR); sendUpdate(obj, true, PluginResult.Status.ERROR);
} catch (JSONException ex) { } catch (JSONException ex) {
Log.d(LOG_TAG, "Should never happen"); LOG.d(LOG_TAG, "Should never happen");
} }
} }
/** /**
* On received http auth request. * On received http auth request.
*/ */
@@ -909,26 +976,30 @@ public class InAppBrowser extends CordovaPlugin {
Method gpm = webView.getClass().getMethod("getPluginManager"); Method gpm = webView.getClass().getMethod("getPluginManager");
pluginManager = (PluginManager)gpm.invoke(webView); pluginManager = (PluginManager)gpm.invoke(webView);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
LOG.d(LOG_TAG, e.getLocalizedMessage());
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
LOG.d(LOG_TAG, e.getLocalizedMessage());
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
LOG.d(LOG_TAG, e.getLocalizedMessage());
} }
if (pluginManager == null) { if (pluginManager == null) {
try { try {
Field pmf = webView.getClass().getField("pluginManager"); Field pmf = webView.getClass().getField("pluginManager");
pluginManager = (PluginManager)pmf.get(webView); pluginManager = (PluginManager)pmf.get(webView);
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
LOG.d(LOG_TAG, e.getLocalizedMessage());
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
LOG.d(LOG_TAG, e.getLocalizedMessage());
} }
} }
if (pluginManager != null && pluginManager.onReceivedHttpAuthRequest(webView, new CordovaHttpAuthHandler(handler), host, realm)) { if (pluginManager != null && pluginManager.onReceivedHttpAuthRequest(webView, new CordovaHttpAuthHandler(handler), host, realm)) {
return; return;
} }
// By default handle 401 like we'd normally do! // By default handle 401 like we'd normally do!
super.onReceivedHttpAuthRequest(view, handler, host, realm); super.onReceivedHttpAuthRequest(view, handler, host, realm);
} }
} }
} }
-1
View File
@@ -21,7 +21,6 @@ package org.apache.cordova.inappbrowser;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.util.Log;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
+20 -12
View File
@@ -19,10 +19,7 @@
* *
*/ */
var cordova = require('cordova'), var modulemapper = require('cordova/modulemapper');
channel = require('cordova/channel'),
modulemapper = require('cordova/modulemapper'),
urlutil = require('cordova/urlutil');
var browserWrap, var browserWrap,
popup, popup,
@@ -69,8 +66,7 @@ var IAB = {
open: function (win, lose, args) { open: function (win, lose, args) {
var strUrl = args[0], var strUrl = args[0],
target = args[1], target = args[1],
features = args[2], features = args[2];
url;
if (target === "_self" || !target) { if (target === "_self" || !target) {
window.location = strUrl; window.location = strUrl;
@@ -81,9 +77,12 @@ var IAB = {
if (!browserWrap) { if (!browserWrap) {
browserWrap = document.createElement("div"); browserWrap = document.createElement("div");
browserWrap.style.position = "absolute"; browserWrap.style.position = "absolute";
browserWrap.style.top = "0";
browserWrap.style.left = "0";
browserWrap.style.boxSizing = "border-box";
browserWrap.style.borderWidth = "40px"; browserWrap.style.borderWidth = "40px";
browserWrap.style.width = "calc(100% - 80px)"; browserWrap.style.width = "100vw";
browserWrap.style.height = "calc(100% - 80px)"; browserWrap.style.height = "100vh";
browserWrap.style.borderStyle = "solid"; browserWrap.style.borderStyle = "solid";
browserWrap.style.borderColor = "rgba(0,0,0,0.25)"; browserWrap.style.borderColor = "rgba(0,0,0,0.25)";
@@ -108,6 +107,7 @@ var IAB = {
if (features.indexOf("location=yes") !== -1 || features.indexOf("location") === -1) { if (features.indexOf("location=yes") !== -1 || features.indexOf("location") === -1) {
popup.style.height = "calc(100% - 60px)"; popup.style.height = "calc(100% - 60px)";
popup.style.marginBottom = "-4px";
navigationButtonsDiv = document.createElement("div"); navigationButtonsDiv = document.createElement("div");
navigationButtonsDiv.style.height = "60px"; navigationButtonsDiv.style.height = "60px";
@@ -193,7 +193,9 @@ var IAB = {
if (browserWrap && popup) { if (browserWrap && popup) {
try { try {
popup.contentWindow.eval(code); popup.contentWindow.eval(code);
hasCallback && win([]); if (hasCallback) {
win([]);
}
} catch(e) { } catch(e) {
console.error('Error occured while trying to injectScriptCode: ' + JSON.stringify(e)); console.error('Error occured while trying to injectScriptCode: ' + JSON.stringify(e));
} }
@@ -203,19 +205,25 @@ var IAB = {
injectScriptFile: function (win, fail, args) { injectScriptFile: function (win, fail, args) {
var msg = 'Browser cordova-plugin-inappbrowser injectScriptFile is not yet implemented'; var msg = 'Browser cordova-plugin-inappbrowser injectScriptFile is not yet implemented';
console.warn(msg); console.warn(msg);
fail && fail(msg); if (fail) {
fail(msg);
}
}, },
injectStyleCode: function (win, fail, args) { injectStyleCode: function (win, fail, args) {
var msg = 'Browser cordova-plugin-inappbrowser injectStyleCode is not yet implemented'; var msg = 'Browser cordova-plugin-inappbrowser injectStyleCode is not yet implemented';
console.warn(msg); console.warn(msg);
fail && fail(msg); if (fail) {
fail(msg);
}
}, },
injectStyleFile: function (win, fail, args) { injectStyleFile: function (win, fail, args) {
var msg = 'Browser cordova-plugin-inappbrowser injectStyleFile is not yet implemented'; var msg = 'Browser cordova-plugin-inappbrowser injectStyleFile is not yet implemented';
console.warn(msg); console.warn(msg);
fail && fail(msg); if (fail) {
fail(msg);
}
} }
}; };
+10 -14
View File
@@ -21,9 +21,7 @@
// https://developer.mozilla.org/en-US/docs/WebAPI/Browser // https://developer.mozilla.org/en-US/docs/WebAPI/Browser
var cordova = require('cordova'), var modulemapper = require('cordova/modulemapper');
channel = require('cordova/channel'),
modulemapper = require('cordova/modulemapper');
var origOpenFunc = modulemapper.getOriginalSymbol(window, 'window.open'); var origOpenFunc = modulemapper.getOriginalSymbol(window, 'window.open');
var browserWrap; var browserWrap;
@@ -49,9 +47,7 @@ var IABExecs = {
var strUrl = args[0], var strUrl = args[0],
target = args[1], target = args[1],
features_string = args[2] || "location=yes", //location=yes is default features_string = args[2] || "location=yes", //location=yes is default
features = {}, features = {};
url,
elem;
var features_list = features_string.split(','); var features_list = features_string.split(',');
features_list.forEach(function(feature) { features_list.forEach(function(feature) {
@@ -61,7 +57,7 @@ var IABExecs = {
} else if (tup[1] == 'no') { } else if (tup[1] == 'no') {
tup[1] = false; tup[1] = false;
} else { } else {
var number = parseInt(tup[1]); var number = parseInt(tup[1]);
if (!isNaN(number)) { if (!isNaN(number)) {
tup[1] = number; tup[1] = number;
} }
@@ -115,7 +111,7 @@ var IABExecs = {
back.classList.add('inAppBrowserBack'); back.classList.add('inAppBrowserBack');
forward.classList.add('inAppBrowserForward'); forward.classList.add('inAppBrowserForward');
function checkForwardBackward() { var checkForwardBackward = function () {
var backReq = browserElem.getCanGoBack(); var backReq = browserElem.getCanGoBack();
backReq.onsuccess = function() { backReq.onsuccess = function() {
if (this.result) { if (this.result) {
@@ -123,7 +119,7 @@ var IABExecs = {
} else { } else {
back.classList.add('disabled'); back.classList.add('disabled');
} }
} };
var forwardReq = browserElem.getCanGoForward(); var forwardReq = browserElem.getCanGoForward();
forwardReq.onsuccess = function() { forwardReq.onsuccess = function() {
if (this.result) { if (this.result) {
@@ -131,7 +127,7 @@ var IABExecs = {
} else { } else {
forward.classList.add('disabled'); forward.classList.add('disabled');
} }
} };
}; };
browserElem.addEventListener('mozbrowserloadend', checkForwardBackward); browserElem.addEventListener('mozbrowserloadend', checkForwardBackward);
@@ -163,16 +159,16 @@ var IABExecs = {
win({ win({
type:'loadstart', type:'loadstart',
url : e.detail url : e.detail
}) });
}, false); }, false);
browserElem.addEventListener('mozbrowserloadend', function(e){ browserElem.addEventListener('mozbrowserloadend', function(e){
win({type:'loadstop'}) win({type:'loadstop'});
}, false); }, false);
browserElem.addEventListener('mozbrowsererror', function(e){ browserElem.addEventListener('mozbrowsererror', function(e){
win({type:'loaderror'}) win({type:'loaderror'});
}, false); }, false);
browserElem.addEventListener('mozbrowserclose', function(e){ browserElem.addEventListener('mozbrowserclose', function(e){
win({type:'exit'}) win({type:'exit'});
}, false); }, false);
} else { } else {
window.location = strUrl; window.location = strUrl;
+42 -8
View File
@@ -47,6 +47,11 @@
_callbackIdPattern = nil; _callbackIdPattern = nil;
} }
- (id)settingForKey:(NSString*)key
{
return [self.commandDelegate.settings objectForKey:[key lowercaseString]];
}
- (void)onReset - (void)onReset
{ {
[self close:nil]; [self close:nil];
@@ -137,8 +142,16 @@
} }
if (self.inAppBrowserViewController == nil) { if (self.inAppBrowserViewController == nil) {
NSString* originalUA = [CDVUserAgentUtil originalUserAgent]; NSString* userAgent = [CDVUserAgentUtil originalUserAgent];
self.inAppBrowserViewController = [[CDVInAppBrowserViewController alloc] initWithUserAgent:originalUA prevUserAgent:[self.commandDelegate userAgent] browserOptions: browserOptions]; NSString* overrideUserAgent = [self settingForKey:@"OverrideUserAgent"];
NSString* appendUserAgent = [self settingForKey:@"AppendUserAgent"];
if(overrideUserAgent){
userAgent = overrideUserAgent;
}
if(appendUserAgent){
userAgent = [userAgent stringByAppendingString: appendUserAgent];
}
self.inAppBrowserViewController = [[CDVInAppBrowserViewController alloc] initWithUserAgent:userAgent prevUserAgent:[self.commandDelegate userAgent] browserOptions: browserOptions];
self.inAppBrowserViewController.navigationDelegate = self; self.inAppBrowserViewController.navigationDelegate = self;
if ([self.viewController conformsToProtocol:@protocol(CDVScreenOrientationDelegate)]) { if ([self.viewController conformsToProtocol:@protocol(CDVScreenOrientationDelegate)]) {
@@ -218,6 +231,7 @@
initWithRootViewController:self.inAppBrowserViewController]; initWithRootViewController:self.inAppBrowserViewController];
nav.orientationDelegate = self.inAppBrowserViewController; nav.orientationDelegate = self.inAppBrowserViewController;
nav.navigationBarHidden = YES; nav.navigationBarHidden = YES;
nav.modalPresentationStyle = self.inAppBrowserViewController.modalPresentationStyle;
__weak CDVInAppBrowser* weakSelf = self; __weak CDVInAppBrowser* weakSelf = self;
@@ -248,11 +262,8 @@
- (void)openInSystem:(NSURL*)url - (void)openInSystem:(NSURL*)url
{ {
if ([[UIApplication sharedApplication] canOpenURL:url]) { [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
[[UIApplication sharedApplication] openURL:url]; [[UIApplication sharedApplication] openURL:url];
} else { // handle any custom schemes to plugins
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
}
} }
// This is a helper method for the inject{Script|Style}{Code|File} API calls, which // This is a helper method for the inject{Script|Style}{Code|File} API calls, which
@@ -755,6 +766,10 @@
return UIStatusBarStyleDefault; return UIStatusBarStyleDefault;
} }
- (BOOL)prefersStatusBarHidden {
return NO;
}
- (void)close - (void)close
{ {
[CDVUserAgentUtil releaseLock:&_userAgentLockToken]; [CDVUserAgentUtil releaseLock:&_userAgentLockToken];
@@ -994,19 +1009,38 @@
@implementation CDVInAppBrowserNavigationController : UINavigationController @implementation CDVInAppBrowserNavigationController : UINavigationController
- (void) dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion {
if ( self.presentedViewController) {
[super dismissViewControllerAnimated:flag completion:completion];
}
}
- (void) viewDidLoad { - (void) viewDidLoad {
CGRect frame = [UIApplication sharedApplication].statusBarFrame; CGRect frame = [UIApplication sharedApplication].statusBarFrame;
// simplified from: http://stackoverflow.com/a/25669695/219684 // simplified from: http://stackoverflow.com/a/25669695/219684
UIToolbar* bgToolbar = [[UIToolbar alloc] initWithFrame:frame]; UIToolbar* bgToolbar = [[UIToolbar alloc] initWithFrame:[self invertFrameIfNeeded:frame]];
bgToolbar.barStyle = UIBarStyleDefault; bgToolbar.barStyle = UIBarStyleDefault;
[bgToolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[self.view addSubview:bgToolbar]; [self.view addSubview:bgToolbar];
[super viewDidLoad]; [super viewDidLoad];
} }
- (CGRect) invertFrameIfNeeded:(CGRect)rect {
// We need to invert since on iOS 7 frames are always in Portrait context
if (!IsAtLeastiOSVersion(@"8.0")) {
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
CGFloat temp = rect.size.width;
rect.size.width = rect.size.height;
rect.size.height = temp;
}
rect.origin = CGPointZero;
}
return rect;
}
#pragma mark CDVScreenOrientationDelegate #pragma mark CDVScreenOrientationDelegate
+3
View File
@@ -19,6 +19,9 @@
* *
*/ */
/* jshint -W061 */
/* global oxide */
oxide.addMessageHandler("EXECUTE", function(msg) { oxide.addMessageHandler("EXECUTE", function(msg) {
var code = msg.args.code; var code = msg.args.code;
try { try {
+56 -17
View File
@@ -19,10 +19,8 @@
* *
*/ */
/*jslint sloppy:true */ /* jslint sloppy:true */
/*global Windows:true, require, document, setTimeout, window, module */ /* global Windows:true, setImmediate */
var cordova = require('cordova'), var cordova = require('cordova'),
urlutil = require('cordova/urlutil'); urlutil = require('cordova/urlutil');
@@ -35,7 +33,8 @@ var browserWrap,
forwardButton, forwardButton,
closeButton, closeButton,
bodyOverflowStyle, bodyOverflowStyle,
navigationEventsCallback; navigationEventsCallback,
hardwareBackCallback;
// x-ms-webview is available starting from Windows 8.1 (platformId is 'windows') // x-ms-webview is available starting from Windows 8.1 (platformId is 'windows')
// http://msdn.microsoft.com/en-us/library/windows/apps/dn301831.aspx // http://msdn.microsoft.com/en-us/library/windows/apps/dn301831.aspx
@@ -107,6 +106,8 @@ var IAB = {
document.body.style.msOverflowStyle = bodyOverflowStyle; document.body.style.msOverflowStyle = bodyOverflowStyle;
browserWrap = null; browserWrap = null;
popup = null; popup = null;
document.removeEventListener("backbutton", hardwareBackCallback, false);
} }
}); });
}, },
@@ -175,9 +176,45 @@ var IAB = {
} }
popup.style.borderWidth = "0px"; popup.style.borderWidth = "0px";
popup.style.width = "100%"; popup.style.width = "100%";
popup.style.marginBottom = "-3px";
browserWrap.appendChild(popup); browserWrap.appendChild(popup);
var closeHandler = function (e) {
setTimeout(function () {
IAB.close(navigationEventsCallback);
}, 0);
};
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';
}
if (popup.canGoBack) {
popup.goBack();
} else {
closeHandler();
}
};
} else if (features.indexOf("hardwareback=no") > -1) {
hardwareBackCallback = function () {
if (browserWrap.style.display === 'none') {
// See comment above
throw 'Exit the app';
}
closeHandler();
};
}
document.addEventListener("backbutton", hardwareBackCallback, false);
if (features.indexOf("location=yes") !== -1 || features.indexOf("location") === -1) { if (features.indexOf("location=yes") !== -1 || features.indexOf("location") === -1) {
popup.style.height = "calc(100% - 70px)"; popup.style.height = "calc(100% - 70px)";
@@ -188,7 +225,7 @@ var IAB = {
}; };
navigationButtonsDivInner = document.createElement("div"); navigationButtonsDivInner = document.createElement("div");
navigationButtonsDivInner.className = "inappbrowser-app-bar-inner" navigationButtonsDivInner.className = "inappbrowser-app-bar-inner";
navigationButtonsDivInner.onclick = function (e) { navigationButtonsDivInner.onclick = function (e) {
e.cancelBubble = true; e.cancelBubble = true;
}; };
@@ -212,11 +249,7 @@ var IAB = {
closeButton = document.createElement("div"); closeButton = document.createElement("div");
closeButton.innerText = "close"; closeButton.innerText = "close";
closeButton.className = "app-bar-action action-close"; closeButton.className = "app-bar-action action-close";
closeButton.addEventListener("click", function (e) { closeButton.addEventListener("click", closeHandler);
setTimeout(function () {
IAB.close(navigationEventsCallback);
}, 0);
});
if (!isWebViewAvailable) { if (!isWebViewAvailable) {
// iframe navigation is not yet supported // iframe navigation is not yet supported
@@ -253,9 +286,11 @@ var IAB = {
if (isWebViewAvailable && browserWrap && popup) { if (isWebViewAvailable && browserWrap && popup) {
var op = popup.invokeScriptAsync("eval", code); var op = popup.invokeScriptAsync("eval", code);
op.oncomplete = function (e) { op.oncomplete = function (e) {
// return null if event target is unavailable by some reason if (hasCallback) {
var result = (e && e.target) ? [e.target.result] : [null]; // return null if event target is unavailable by some reason
hasCallback && win(result); var result = (e && e.target) ? [e.target.result] : [null];
win(result);
}
}; };
op.onerror = function () { }; op.onerror = function () { };
op.start(); op.start();
@@ -278,8 +313,10 @@ var IAB = {
Windows.Storage.FileIO.readTextAsync(file).done(function (code) { Windows.Storage.FileIO.readTextAsync(file).done(function (code) {
var op = popup.invokeScriptAsync("eval", code); var op = popup.invokeScriptAsync("eval", code);
op.oncomplete = function(e) { op.oncomplete = function(e) {
var result = [e.target.result]; if (hasCallback) {
hasCallback && win(result); var result = [e.target.result];
win(result);
}
}; };
op.onerror = function () { }; op.onerror = function () { };
op.start(); op.start();
@@ -329,7 +366,9 @@ function injectCSS (webView, cssCode, callback) {
var op = webView.invokeScriptAsync("eval", evalWrapper); var op = webView.invokeScriptAsync("eval", evalWrapper);
op.oncomplete = function() { op.oncomplete = function() {
callback && callback([]); if (callback) {
callback([]);
}
}; };
op.onerror = function () { }; op.onerror = function () { };
op.start(); op.start();
+1 -1
View File
@@ -20,7 +20,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-inappbrowser-tests" id="cordova-plugin-inappbrowser-tests"
version="1.2.1"> version="1.5.0">
<name>Cordova InAppBrowser Plugin Tests</name> <name>Cordova InAppBrowser Plugin Tests</name>
<license>Apache 2.0</license> <license>Apache 2.0</license>
+1 -1
View File
@@ -16,5 +16,5 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
var d = document.getElementById("header") var d = document.getElementById("header");
d.innerHTML = "Script file successfully injected"; d.innerHTML = "Script file successfully injected";
+3
View File
@@ -38,5 +38,8 @@
<button onclick="document.getElementById('player').play()"> play </button> <button onclick="document.getElementById('player').play()"> play </button>
<button onclick="document.getElementById('player').pause()"> pause </button> <button onclick="document.getElementById('player').pause()"> pause </button>
</div> </div>
<script>
document.getElementById('player').play();
</script>
</body> </body>
</html> </html>
+43 -12
View File
@@ -19,6 +19,9 @@
* *
*/ */
/* jshint jasmine: true */
/* global MSApp */
var cordova = require('cordova'); var cordova = require('cordova');
var isWindows = cordova.platformId == 'windows'; var isWindows = cordova.platformId == 'windows';
@@ -42,13 +45,13 @@ exports.defineAutoTests = function () {
var iabInstance; var iabInstance;
var originalTimeout; var originalTimeout;
var url = 'http://apache.org/'; var url = 'https://dist.apache.org/repos/dist/dev/cordova/';
var badUrl = 'http://bad-uri/'; var badUrl = 'http://bad-uri/';
beforeEach(function () { beforeEach(function () {
// increase timeout to ensure test url could be loaded within test time // increase timeout to ensure test url could be loaded within test time
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 15000; jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
iabInstance = null; iabInstance = null;
}); });
@@ -183,13 +186,13 @@ exports.defineManualTests = function (contentEl, createActionButton) {
if (e.url != lastLoadStartURL) { if (e.url != lastLoadStartURL) {
alert('Unexpected: ' + e.type + ' event.url != loadstart\'s event.url'); alert('Unexpected: ' + e.type + ' event.url != loadstart\'s event.url');
} }
if (numExpectedRedirects === 0 && counts['loadstart'] !== 1) { if (numExpectedRedirects === 0 && counts.loadstart !== 1) {
// Do allow a loaderror without a loadstart (e.g. in the case of an invalid URL). // Do allow a loaderror without a loadstart (e.g. in the case of an invalid URL).
if (!(e.type == 'loaderror' && counts['loadstart'] === 0)) { if (!(e.type == 'loaderror' && counts.loadstart === 0)) {
alert('Unexpected: got multiple loadstart events. (' + counts['loadstart'] + ')'); alert('Unexpected: got multiple loadstart events. (' + counts.loadstart + ')');
} }
} else if (numExpectedRedirects > 0 && counts['loadstart'] < (numExpectedRedirects + 1)) { } 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);
} }
wasReset = true; wasReset = true;
numExpectedRedirects = 0; numExpectedRedirects = 0;
@@ -197,7 +200,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
} }
// Verify that loadend / loaderror was called. // Verify that loadend / loaderror was called.
if (e.type == 'exit') { if (e.type == 'exit') {
var numStopEvents = counts['loadstop'] + counts['loaderror']; var numStopEvents = counts.loadstop + counts.loaderror;
if (numStopEvents === 0 && !wasReset) { if (numStopEvents === 0 && !wasReset) {
alert('Unexpected: browser closed without a loadstop or loaderror.'); alert('Unexpected: browser closed without a loadstop or loaderror.');
} else if (numStopEvents > 1) { } else if (numStopEvents > 1) {
@@ -423,7 +426,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
var video_tag_tests = '<h1>Video tag</h1>' + var video_tag_tests = '<h1>Video tag</h1>' +
'<div id="openRemoteVideo"></div>' + '<div id="openRemoteVideo"></div>' +
'Expected result: open successfully in InAppBrowser with an embedded video that works after clicking the "play" button.'; 'Expected result: open successfully in InAppBrowser with an embedded video plays automatically on iOS and Android.' +
'<div id="openRemoteNeedUserNoVideo"></div>' +
'Expected result: open successfully in InAppBrowser with an embedded video plays automatically on iOS and Android.' +
'<div id="openRemoteNeedUserYesVideo"></div>' +
'Expected result: open successfully in InAppBrowser with an embedded video does not play automatically on iOS and Android but rather works after clicking the "play" button.';
var local_with_anchor_tag_tests = '<h1>Local with anchor tag</h1>' + var local_with_anchor_tag_tests = '<h1>Local with anchor tag</h1>' +
'<div id="openAnchor1"></div>' + '<div id="openAnchor1"></div>' +
@@ -431,16 +438,24 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'<p/> <div id="openAnchor2"></div>' + '<p/> <div id="openAnchor2"></div>' +
'Expected result: open successfully in InAppBrowser to the local page, scrolled to the beginning of the tall div with border.'; 'Expected result: open successfully in InAppBrowser to the local page, scrolled to the beginning of the tall div with border.';
var hardwareback_tests = '<h1>HardwareBack</h1>' +
'<p/> <div id="openHardwareBackDefault"></div>' +
'Expected result: By default hardwareback is yes so pressing back button should navigate backwards in history then close InAppBrowser' +
'<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';
// CB-7490 We need to wrap this code due to Windows security restrictions // 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 // see http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx#differences for details
if (window.MSApp && window.MSApp.execUnsafeLocalFunction) { 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 + 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; css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests + hardwareback_tests;
}); });
} else { } else {
contentEl.innerHTML = info_div + local_tests + white_listed_tests + non_white_listed_tests + page_with_redirects_tests + pdf_url_tests + invalid_url_tests + 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; 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;
@@ -611,6 +626,12 @@ exports.defineManualTests = function (contentEl, createActionButton) {
createActionButton('Remote Video', function () { createActionButton('Remote Video', function () {
doOpen(videohtml, '_blank'); doOpen(videohtml, '_blank');
}, 'openRemoteVideo'); }, 'openRemoteVideo');
createActionButton('Remote Need User No Video', function () {
doOpen(videohtml, '_blank', 'mediaPlaybackRequiresUserAction=no');
}, 'openRemoteNeedUserNoVideo');
createActionButton('Remote Need User Yes Video', function () {
doOpen(videohtml, '_blank', 'mediaPlaybackRequiresUserAction=yes');
}, 'openRemoteNeedUserYesVideo');
//Local With Anchor Tag //Local With Anchor Tag
createActionButton('Anchor1', function () { createActionButton('Anchor1', function () {
@@ -619,5 +640,15 @@ exports.defineManualTests = function (contentEl, createActionButton) {
createActionButton('Anchor2', function () { createActionButton('Anchor2', function () {
doOpen(localhtml + '#anchor2', '_blank'); doOpen(localhtml + '#anchor2', '_blank');
}, 'openAnchor2'); }, 'openAnchor2');
};
// Hardwareback
createActionButton('no hardwareback (defaults to yes)', function () {
doOpen('http://cordova.apache.org', '_blank');
}, 'openHardwareBackDefault');
createActionButton('hardwareback=yes', function () {
doOpen('http://cordova.apache.org', '_blank', 'hardwareback=yes');
}, 'openHardwareBackYes');
createActionButton('hardwareback=no', function () {
doOpen('http://cordova.apache.org', '_blank', 'hardwareback=no');
}, 'openHardwareBackNo');
};
-5
View File
@@ -22,10 +22,6 @@
/*jslint sloppy:true */ /*jslint sloppy:true */
/*global Windows:true, require, document, setTimeout, window, module */ /*global Windows:true, require, document, setTimeout, window, module */
var cordova = require('cordova'),
channel = require('cordova/channel');
var browserWrap; var browserWrap;
var IAB = { var IAB = {
@@ -45,7 +41,6 @@ var IAB = {
open: function (win, lose, args) { open: function (win, lose, args) {
var strUrl = args[0], var strUrl = args[0],
target = args[1], target = args[1],
features = args[2],
url, url,
elem; elem;