CB-4864, CB-4865: Minor improvements to InAppBrowser
This commit is contained in:
parent
e5d3973a13
commit
eef27f8891
@ -22,6 +22,7 @@
|
|||||||
</config-file>
|
</config-file>
|
||||||
|
|
||||||
<source-file src="src/android/InAppBrowser.java" target-dir="src/org/apache/cordova/inappbrowser" />
|
<source-file src="src/android/InAppBrowser.java" target-dir="src/org/apache/cordova/inappbrowser" />
|
||||||
|
<source-file src="src/android/InAppChromeClient.java" target-dir="src/org/apache/cordova/inappbrowser" />
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
<!-- ios -->
|
<!-- ios -->
|
||||||
|
@ -82,8 +82,6 @@ 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 long MAX_QUOTA = 100 * 1024 * 1024;
|
|
||||||
|
|
||||||
private Dialog dialog;
|
private Dialog dialog;
|
||||||
private WebView inAppWebView;
|
private WebView inAppWebView;
|
||||||
private EditText edittext;
|
private EditText edittext;
|
||||||
@ -457,6 +455,8 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
|
|
||||||
// Toolbar layout
|
// Toolbar layout
|
||||||
RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
|
RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
|
||||||
|
//Please, no more black!
|
||||||
|
toolbar.setBackgroundColor(android.graphics.Color.LTGRAY);
|
||||||
toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
|
toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
|
||||||
toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
|
toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
|
||||||
toolbar.setHorizontalGravity(Gravity.LEFT);
|
toolbar.setHorizontalGravity(Gravity.LEFT);
|
||||||
@ -626,108 +626,7 @@ public class InAppBrowser extends CordovaPlugin {
|
|||||||
this.callbackContext.sendPluginResult(result);
|
this.callbackContext.sendPluginResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class InAppChromeClient extends WebChromeClient {
|
|
||||||
|
|
||||||
private CordovaWebView webView;
|
|
||||||
|
|
||||||
public InAppChromeClient(CordovaWebView webView) {
|
|
||||||
super();
|
|
||||||
this.webView = webView;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Handle database quota exceeded notification.
|
|
||||||
*
|
|
||||||
* @param url
|
|
||||||
* @param databaseIdentifier
|
|
||||||
* @param currentQuota
|
|
||||||
* @param estimatedSize
|
|
||||||
* @param totalUsedQuota
|
|
||||||
* @param quotaUpdater
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize,
|
|
||||||
long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)
|
|
||||||
{
|
|
||||||
LOG.d(LOG_TAG, "onExceededDatabaseQuota estimatedSize: %d currentQuota: %d totalUsedQuota: %d", estimatedSize, currentQuota, totalUsedQuota);
|
|
||||||
|
|
||||||
if (estimatedSize < MAX_QUOTA)
|
|
||||||
{
|
|
||||||
//increase for 1Mb
|
|
||||||
long newQuota = estimatedSize;
|
|
||||||
LOG.d(LOG_TAG, "calling quotaUpdater.updateQuota newQuota: %d", newQuota);
|
|
||||||
quotaUpdater.updateQuota(newQuota);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Set the quota to whatever it is and force an error
|
|
||||||
// TODO: get docs on how to handle this properly
|
|
||||||
quotaUpdater.updateQuota(currentQuota);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instructs the client to show a prompt to ask the user to set the Geolocation permission state for the specified origin.
|
|
||||||
*
|
|
||||||
* @param origin
|
|
||||||
* @param callback
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
|
|
||||||
super.onGeolocationPermissionsShowPrompt(origin, callback);
|
|
||||||
callback.invoke(origin, true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tell the client to display a prompt dialog to the user.
|
|
||||||
* If the client returns true, WebView will assume that the client will
|
|
||||||
* handle the prompt dialog and call the appropriate JsPromptResult method.
|
|
||||||
*
|
|
||||||
* The prompt bridge provided for the InAppBrowser is capable of executing any
|
|
||||||
* oustanding callback belonging to the InAppBrowser plugin. Care has been
|
|
||||||
* taken that other callbacks cannot be triggered, and that no other code
|
|
||||||
* execution is possible.
|
|
||||||
*
|
|
||||||
* To trigger the bridge, the prompt default value should be of the form:
|
|
||||||
*
|
|
||||||
* gap-iab://<callbackId>
|
|
||||||
*
|
|
||||||
* where <callbackId> is the string id of the callback to trigger (something
|
|
||||||
* like "InAppBrowser0123456789")
|
|
||||||
*
|
|
||||||
* If present, the prompt message is expected to be a JSON-encoded value to
|
|
||||||
* pass to the callback. A JSON_EXCEPTION is returned if the JSON is invalid.
|
|
||||||
*
|
|
||||||
* @param view
|
|
||||||
* @param url
|
|
||||||
* @param message
|
|
||||||
* @param defaultValue
|
|
||||||
* @param result
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
|
|
||||||
// See if the prompt string uses the 'gap-iab' protocol. If so, the remainder should be the id of a callback to execute.
|
|
||||||
if (defaultValue != null && defaultValue.startsWith("gap-iab://")) {
|
|
||||||
PluginResult scriptResult;
|
|
||||||
String scriptCallbackId = defaultValue.substring(10);
|
|
||||||
if (scriptCallbackId.startsWith("InAppBrowser")) {
|
|
||||||
if(message == null || message.length() == 0) {
|
|
||||||
scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray());
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray(message));
|
|
||||||
} catch(JSONException e) {
|
|
||||||
scriptResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.webView.sendPluginResult(scriptResult, scriptCallbackId);
|
|
||||||
result.confirm("");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The webview client receives notifications about appView
|
* The webview client receives notifications about appView
|
||||||
|
119
src/android/InAppChromeClient.java
Normal file
119
src/android/InAppChromeClient.java
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
package org.apache.cordova.inappbrowser;
|
||||||
|
|
||||||
|
import org.apache.cordova.CordovaWebView;
|
||||||
|
import org.apache.cordova.LOG;
|
||||||
|
import org.apache.cordova.PluginResult;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
|
||||||
|
import android.webkit.JsPromptResult;
|
||||||
|
import android.webkit.WebChromeClient;
|
||||||
|
import android.webkit.WebStorage;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
import android.webkit.WebViewClient;
|
||||||
|
import android.webkit.GeolocationPermissions.Callback;
|
||||||
|
|
||||||
|
public class InAppChromeClient extends WebChromeClient {
|
||||||
|
|
||||||
|
private CordovaWebView webView;
|
||||||
|
private String LOG_TAG = "InAppChromeClient";
|
||||||
|
private long MAX_QUOTA = 100 * 1024 * 1024;
|
||||||
|
|
||||||
|
public InAppChromeClient(CordovaWebView webView) {
|
||||||
|
super();
|
||||||
|
this.webView = webView;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Handle database quota exceeded notification.
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
* @param databaseIdentifier
|
||||||
|
* @param currentQuota
|
||||||
|
* @param estimatedSize
|
||||||
|
* @param totalUsedQuota
|
||||||
|
* @param quotaUpdater
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize,
|
||||||
|
long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater)
|
||||||
|
{
|
||||||
|
LOG.d(LOG_TAG, "onExceededDatabaseQuota estimatedSize: %d currentQuota: %d totalUsedQuota: %d", estimatedSize, currentQuota, totalUsedQuota);
|
||||||
|
|
||||||
|
if (estimatedSize < MAX_QUOTA)
|
||||||
|
{
|
||||||
|
//increase for 1Mb
|
||||||
|
long newQuota = estimatedSize;
|
||||||
|
LOG.d(LOG_TAG, "calling quotaUpdater.updateQuota newQuota: %d", newQuota);
|
||||||
|
quotaUpdater.updateQuota(newQuota);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Set the quota to whatever it is and force an error
|
||||||
|
// TODO: get docs on how to handle this properly
|
||||||
|
quotaUpdater.updateQuota(currentQuota);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instructs the client to show a prompt to ask the user to set the Geolocation permission state for the specified origin.
|
||||||
|
*
|
||||||
|
* @param origin
|
||||||
|
* @param callback
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
|
||||||
|
super.onGeolocationPermissionsShowPrompt(origin, callback);
|
||||||
|
callback.invoke(origin, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tell the client to display a prompt dialog to the user.
|
||||||
|
* If the client returns true, WebView will assume that the client will
|
||||||
|
* handle the prompt dialog and call the appropriate JsPromptResult method.
|
||||||
|
*
|
||||||
|
* The prompt bridge provided for the InAppBrowser is capable of executing any
|
||||||
|
* oustanding callback belonging to the InAppBrowser plugin. Care has been
|
||||||
|
* taken that other callbacks cannot be triggered, and that no other code
|
||||||
|
* execution is possible.
|
||||||
|
*
|
||||||
|
* To trigger the bridge, the prompt default value should be of the form:
|
||||||
|
*
|
||||||
|
* gap-iab://<callbackId>
|
||||||
|
*
|
||||||
|
* where <callbackId> is the string id of the callback to trigger (something
|
||||||
|
* like "InAppBrowser0123456789")
|
||||||
|
*
|
||||||
|
* If present, the prompt message is expected to be a JSON-encoded value to
|
||||||
|
* pass to the callback. A JSON_EXCEPTION is returned if the JSON is invalid.
|
||||||
|
*
|
||||||
|
* @param view
|
||||||
|
* @param url
|
||||||
|
* @param message
|
||||||
|
* @param defaultValue
|
||||||
|
* @param result
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
|
||||||
|
// See if the prompt string uses the 'gap-iab' protocol. If so, the remainder should be the id of a callback to execute.
|
||||||
|
if (defaultValue != null && defaultValue.startsWith("gap-iab://")) {
|
||||||
|
PluginResult scriptResult;
|
||||||
|
String scriptCallbackId = defaultValue.substring(10);
|
||||||
|
if (scriptCallbackId.startsWith("InAppBrowser")) {
|
||||||
|
if(message == null || message.length() == 0) {
|
||||||
|
scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray());
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray(message));
|
||||||
|
} catch(JSONException e) {
|
||||||
|
scriptResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.webView.sendPluginResult(scriptResult, scriptCallbackId);
|
||||||
|
result.confirm("");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user