mirror of
https://github.com/shuto-cn/cordova-plugin-inappbrowser.git
synced 2026-01-26 00:00:04 +08:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5dedae631 | ||
|
|
d0dd10103c | ||
|
|
497a23efc7 | ||
|
|
6f373f7ed9 | ||
|
|
300f1e782e | ||
|
|
4d3c7b17d2 | ||
|
|
a5201cc1e3 | ||
|
|
942d17981e | ||
|
|
17ba417572 | ||
|
|
77085aa547 | ||
|
|
26702cb072 | ||
|
|
39e64c988a | ||
|
|
cd31b3a64d | ||
|
|
4c07917c0a | ||
|
|
24e6a1feeb |
6
NOTICE
6
NOTICE
@@ -1 +1,5 @@
|
||||
Icons used in ths plugin are reproduced from work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
|
||||
Apache Cordova
|
||||
Copyright 2012 The Apache Software Foundation
|
||||
|
||||
This product includes software developed at
|
||||
The Apache Software Foundation (http://www.apache.org/).
|
||||
|
||||
@@ -73,3 +73,12 @@
|
||||
* CB-5756: Android: Use WebView.evaluateJavascript for script injection on Android 4.4+
|
||||
* Remove alive from InAppBrowser.js since it didn't catch the case where the browser is closed by the user.
|
||||
* CB-5733 Fix IAB.close() not working if called before show() animation is done
|
||||
|
||||
### 0.3.2 (Feb 26, 2014)
|
||||
* Validate that callbackId is correctly formed
|
||||
* CB-6035 Move js-module so it is not loaded on unsupported platforms
|
||||
* Removed some iOS6 Deprecations
|
||||
|
||||
### 0.3.3 (Mar 5, 2014)
|
||||
* CB-6172 Fix broken install on case-sensitive file-systems
|
||||
|
||||
|
||||
39
plugin.xml
39
plugin.xml
@@ -2,7 +2,7 @@
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
id="org.apache.cordova.inappbrowser"
|
||||
version="0.3.1">
|
||||
version="0.3.3">
|
||||
|
||||
<name>InAppBrowser</name>
|
||||
<description>Cordova InAppBrowser Plugin</description>
|
||||
@@ -14,13 +14,12 @@
|
||||
<engines>
|
||||
<engine name="cordova" version=">=3.1.0" /><!-- Needs cordova/urlutil -->
|
||||
</engines>
|
||||
|
||||
<js-module src="www/InAppBrowser.js" name="InAppBrowser">
|
||||
<clobbers target="window.open" />
|
||||
</js-module>
|
||||
|
||||
<!-- -->
|
||||
<!-- android -->
|
||||
<platform name="android">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<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"/>
|
||||
@@ -28,6 +27,7 @@
|
||||
</config-file>
|
||||
|
||||
<source-file src="src/android/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/android/InAppChromeClient.java" target-dir="src/org/apache/cordova/inappbrowser" />
|
||||
|
||||
<!-- drawable src/android/resources -->
|
||||
@@ -50,6 +50,9 @@
|
||||
|
||||
<!-- amazon-fireos -->
|
||||
<platform name="amazon-fireos">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<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"/>
|
||||
@@ -62,6 +65,9 @@
|
||||
|
||||
<!-- ubuntu -->
|
||||
<platform name="ubuntu">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<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" />
|
||||
@@ -69,7 +75,10 @@
|
||||
</platform>
|
||||
|
||||
<!-- ios -->
|
||||
<platform name="ios">
|
||||
<platform name="ios">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<clobbers target="window.open" />
|
||||
</js-module>
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="InAppBrowser">
|
||||
<param name="ios-package" value="CDVInAppBrowser" />
|
||||
@@ -82,15 +91,11 @@
|
||||
<framework src="CoreGraphics.framework" />
|
||||
</platform>
|
||||
|
||||
<!-- blackberry10 -->
|
||||
<!-- <platform name="blackberry10">
|
||||
<config-file target="www/config.xml" parent="/widget">
|
||||
<feature name="InAppBrowser" value="InAppBrowser"/>
|
||||
</config-file>
|
||||
</platform>
|
||||
-->
|
||||
<!-- wp7 -->
|
||||
<platform name="wp7">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<clobbers target="window.open" />
|
||||
</js-module>
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="InAppBrowser">
|
||||
<param name="wp-package" value="InAppBrowser"/>
|
||||
@@ -102,6 +107,9 @@
|
||||
|
||||
<!-- wp8 -->
|
||||
<platform name="wp8">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<clobbers target="window.open" />
|
||||
</js-module>
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="InAppBrowser">
|
||||
<param name="wp-package" value="InAppBrowser"/>
|
||||
@@ -113,6 +121,9 @@
|
||||
|
||||
<!-- windows8 -->
|
||||
<platform name="windows8">
|
||||
<js-module src="www/inappbrowser.js" name="inappbrowser">
|
||||
<clobbers target="window.open" />
|
||||
</js-module>
|
||||
<js-module src="www/windows8/InAppBrowserProxy.js" name="InAppBrowserProxy">
|
||||
<merges target="" />
|
||||
</js-module>
|
||||
|
||||
@@ -19,9 +19,8 @@
|
||||
package org.apache.cordova.inappbrowser;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
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;
|
||||
@@ -80,7 +79,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
private static final String CLEAR_ALL_CACHE = "clearcache";
|
||||
private static final String CLEAR_SESSION_CACHE = "clearsessioncache";
|
||||
|
||||
private Dialog dialog;
|
||||
private InAppBrowserDialog dialog;
|
||||
private WebView inAppWebView;
|
||||
private EditText edittext;
|
||||
private CallbackContext callbackContext;
|
||||
@@ -337,12 +336,21 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
this.cordova.getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
childView.loadUrl("about:blank");
|
||||
childView.setWebViewClient(new WebViewClient() {
|
||||
// NB: wait for about:blank before dismissing
|
||||
public void onPageFinished(WebView 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);
|
||||
@@ -350,7 +358,6 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
} catch (JSONException ex) {
|
||||
Log.d(LOG_TAG, "Should never happen");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -398,6 +405,10 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
return this.showLocationBar;
|
||||
}
|
||||
|
||||
private InAppBrowser getInAppBrowser(){
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a new browser with the specified URL.
|
||||
*
|
||||
@@ -448,15 +459,11 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
|
||||
public void run() {
|
||||
// Let's create the main dialog
|
||||
dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
|
||||
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.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
closeDialog();
|
||||
}
|
||||
});
|
||||
dialog.setInAppBroswer(getInAppBrowser());
|
||||
|
||||
// Main container layout
|
||||
LinearLayout main = new LinearLayout(cordova.getActivity());
|
||||
|
||||
54
src/android/InAppBrowserDialog.java
Normal file
54
src/android/InAppBrowserDialog.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
* Created by Oliver on 22/11/2013.
|
||||
*/
|
||||
public class InAppBrowserDialog extends Dialog {
|
||||
Context context;
|
||||
InAppBrowser inAppBrowser = null;
|
||||
|
||||
public InAppBrowserDialog(Context context, int theme) {
|
||||
super(context, theme);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void setInAppBroswer(InAppBrowser browser) {
|
||||
this.inAppBrowser = browser;
|
||||
}
|
||||
|
||||
public void onBackPressed () {
|
||||
if (this.inAppBrowser == null) {
|
||||
this.dismiss();
|
||||
} else {
|
||||
// better to go through the in inAppBrowser
|
||||
// because it does a clean up
|
||||
this.inAppBrowser.closeDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
@property (nonatomic, retain) CDVInAppBrowserViewController* inAppBrowserViewController;
|
||||
@property (nonatomic, copy) NSString* callbackId;
|
||||
@property (nonatomic, copy) NSRegularExpression *callbackIdPattern;
|
||||
|
||||
- (void)open:(CDVInvokedUrlCommand*)command;
|
||||
- (void)close:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
self = [super initWithWebView:theWebView];
|
||||
if (self != nil) {
|
||||
_previousStatusBarStyle = -1;
|
||||
_callbackIdPattern = nil;
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -297,6 +298,23 @@
|
||||
[self injectDeferredObject:[command argumentAtIndex:0] withWrapper:jsWrapper];
|
||||
}
|
||||
|
||||
- (BOOL)isValidCallbackId:(NSString *)callbackId
|
||||
{
|
||||
NSError *err = nil;
|
||||
// Initialize on first use
|
||||
if (self.callbackIdPattern == nil) {
|
||||
self.callbackIdPattern = [NSRegularExpression regularExpressionWithPattern:@"^InAppBrowser[0-9]{1,10}$" options:0 error:&err];
|
||||
if (err != nil) {
|
||||
// Couldn't initialize Regex; No is safer than Yes.
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
if ([self.callbackIdPattern firstMatchInString:callbackId options:0 range:NSMakeRange(0, [callbackId length])]) {
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
/**
|
||||
* The iframe 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
|
||||
@@ -323,7 +341,7 @@
|
||||
NSString* scriptCallbackId = [url host];
|
||||
CDVPluginResult* pluginResult = nil;
|
||||
|
||||
if ([scriptCallbackId hasPrefix:@"InAppBrowser"]) {
|
||||
if ([self isValidCallbackId:scriptCallbackId]) {
|
||||
NSString* scriptResult = [url path];
|
||||
NSError* __autoreleasing error = nil;
|
||||
|
||||
@@ -510,14 +528,14 @@
|
||||
self.addressLabel.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}");
|
||||
self.addressLabel.enabled = YES;
|
||||
self.addressLabel.hidden = NO;
|
||||
self.addressLabel.lineBreakMode = UILineBreakModeTailTruncation;
|
||||
self.addressLabel.minimumFontSize = 10.000;
|
||||
self.addressLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
||||
self.addressLabel.minimumScaleFactor = 10.000;
|
||||
self.addressLabel.multipleTouchEnabled = NO;
|
||||
self.addressLabel.numberOfLines = 1;
|
||||
self.addressLabel.opaque = NO;
|
||||
self.addressLabel.shadowOffset = CGSizeMake(0.0, -1.0);
|
||||
self.addressLabel.text = NSLocalizedString(@"Loading...", nil);
|
||||
self.addressLabel.textAlignment = UITextAlignmentLeft;
|
||||
self.addressLabel.textAlignment = NSTextAlignmentLeft;
|
||||
self.addressLabel.textColor = [UIColor colorWithWhite:1.000 alpha:1.000];
|
||||
self.addressLabel.userInteractionEnabled = NO;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user