-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dreamer
committed
Aug 28, 2015
1 parent
ce9d3ef
commit 3692ed0
Showing
19 changed files
with
1,699 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"version": "0.1.0", | ||
"name": "com.dt-workshop.InAppBrowser", | ||
"cordova_name": "InAppBrowser", | ||
"description": "Cordova android webView and Crosswalk combination", | ||
"license": "Apache 2.0", | ||
"repo": "https://github.com/DT-Workshop/InAppCrossBrowser.git", | ||
"issue": "https://github.com/DT-Workshop/InAppCrossBrowser/issues", | ||
"keywords": [ | ||
"ecosystem:cordova", | ||
"cordova-android", | ||
"cordova", | ||
"in", | ||
"app", | ||
"browser", | ||
"inappbrowser", | ||
"crosswalk" | ||
], | ||
"platforms": [ | ||
"android" | ||
], | ||
"engines": [ | ||
{ | ||
"name": "cordova", | ||
"version": ">=3.1.0" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
|
||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="com.dt-workshop.InAppCrossBrowser" version="0.1.0"> | ||
|
||
<name>InAppCrossBrowser</name> | ||
<description>Cordova android webView and Crosswalk combination</description> | ||
<license>Apache 2.0</license> | ||
<keywords>cordova,in,app,browser,inappbrowser, crosswalk</keywords> | ||
<repo>https://github.com/DT-Workshop/InAppCrossBrowser.git</repo> | ||
<issue>https://github.com/DT-Workshop/InAppCrossBrowser/issues</issue> | ||
|
||
<engines> | ||
<engine name="cordova" version=">=3.1.0"/> | ||
<!-- Needs cordova/urlutil --> | ||
</engines> | ||
|
||
<dependency id="org.apache.cordova.inappbrowser" | ||
url="https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git"/> | ||
|
||
<!-- android --> | ||
<platform name="android"> | ||
<js-module src="www/inappcrossbrowser.js" name="inappcrossbrowser"> | ||
<clobbers target="window.open" /> | ||
</js-module> | ||
|
||
<config-file target="res/xml/config.xml" parent="/*"> | ||
<feature name="InAppCrossBrowser"> | ||
<param name="android-package" value="com.dt_workshop.InAppCrossBrowser.InAppCrossBrowser"/> | ||
</feature> | ||
</config-file> | ||
|
||
<source-file src="src/android/InAppCrossBrowser.java" target-dir="src/com/dt_workshop/InAppCrossBrowser/"/> | ||
<source-file src="src/android/InAppChromeClient.java" target-dir="src/com/dt_workshop/InAppCrossBrowser/"/> | ||
<source-file src="src/android/InAppBrowserDialog.java" target-dir="src/com/dt_workshop/InAppCrossBrowser/"/> | ||
<source-file src="src/android/WebViewBrowser.java" target-dir="src/com/dt_workshop/InAppCrossBrowser/"/> | ||
|
||
<!-- drawable src/android/resources --> | ||
<resource-file src="src/android/res/drawable-hdpi/ic_action_next_item.png" | ||
target="res/drawable-hdpi/ic_action_next_item.png"/> | ||
<resource-file src="src/android/res/drawable-mdpi/ic_action_next_item.png" | ||
target="res/drawable-mdpi/ic_action_next_item.png"/> | ||
<resource-file src="src/android/res/drawable-xhdpi/ic_action_next_item.png" | ||
target="res/drawable-xhdpi/ic_action_next_item.png"/> | ||
<resource-file src="src/android/res/drawable-xxhdpi/ic_action_next_item.png" | ||
target="res/drawable-xxhdpi/ic_action_next_item.png"/> | ||
|
||
<resource-file src="src/android/res/drawable-hdpi/ic_action_previous_item.png" | ||
target="res/drawable-hdpi/ic_action_previous_item.png"/> | ||
<resource-file src="src/android/res/drawable-mdpi/ic_action_previous_item.png" | ||
target="res/drawable-mdpi/ic_action_previous_item.png"/> | ||
<resource-file src="src/android/res/drawable-xhdpi/ic_action_previous_item.png" | ||
target="res/drawable-xhdpi/ic_action_previous_item.png"/> | ||
<resource-file src="src/android/res/drawable-xxhdpi/ic_action_previous_item.png" | ||
target="res/drawable-xxhdpi/ic_action_previous_item.png"/> | ||
|
||
<resource-file src="src/android/res/drawable-hdpi/ic_action_remove.png" | ||
target="res/drawable-hdpi/ic_action_remove.png"/> | ||
<resource-file src="src/android/res/drawable-mdpi/ic_action_remove.png" | ||
target="res/drawable-mdpi/ic_action_remove.png"/> | ||
<resource-file src="src/android/res/drawable-xhdpi/ic_action_remove.png" | ||
target="res/drawable-xhdpi/ic_action_remove.png"/> | ||
<resource-file src="src/android/res/drawable-xxhdpi/ic_action_remove.png" | ||
target="res/drawable-xxhdpi/ic_action_remove.png"/> | ||
</platform> | ||
</plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
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 com.dt_workshop.InAppCrossBrowser; | ||
|
||
import android.app.Dialog; | ||
import android.content.Context; | ||
|
||
/** | ||
* Created by Oliver on 22/11/2013. | ||
*/ | ||
public class InAppBrowserDialog extends Dialog { | ||
Context context; | ||
WebViewBrowser inAppBrowser = null; | ||
|
||
public InAppBrowserDialog(Context context, int theme) { | ||
super(context, theme); | ||
this.context = context; | ||
} | ||
|
||
public void setInAppBroswer(WebViewBrowser 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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
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 com.dt_workshop.InAppCrossBrowser; | ||
|
||
import android.webkit.GeolocationPermissions.Callback; | ||
import android.webkit.JsPromptResult; | ||
import android.webkit.WebChromeClient; | ||
import android.webkit.WebStorage; | ||
import android.webkit.WebView; | ||
|
||
import org.apache.cordova.CordovaWebView; | ||
import org.apache.cordova.LOG; | ||
import org.apache.cordova.PluginResult; | ||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
|
||
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); | ||
quotaUpdater.updateQuota(MAX_QUOTA); | ||
} | ||
|
||
/** | ||
* 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")) { | ||
if(defaultValue.startsWith("gap-iab://")) { | ||
PluginResult scriptResult; | ||
String scriptCallbackId = defaultValue.substring(10); | ||
if (scriptCallbackId.startsWith("InAppBrowser")) { | ||
if(message == null || message.length() == 0) { | ||
scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray()); | ||
} else { | ||
try { | ||
scriptResult = new PluginResult(PluginResult.Status.OK, new JSONArray(message)); | ||
} catch(JSONException e) { | ||
scriptResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage()); | ||
} | ||
} | ||
this.webView.sendPluginResult(scriptResult, scriptCallbackId); | ||
result.confirm(""); | ||
return true; | ||
} | ||
} | ||
else | ||
{ | ||
// Anything else with a gap: prefix should get this message | ||
LOG.w(LOG_TAG, "InAppBrowser does not support Cordova API calls: " + url + " " + defaultValue); | ||
result.cancel(); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
} |
Oops, something went wrong.