You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2017/12/01 16:10:47 UTC

[GitHub] marvindrion closed pull request #252: Ndth 1805

marvindrion closed pull request #252: Ndth 1805
URL: https://github.com/apache/cordova-plugin-inappbrowser/pull/252
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/package.json b/package.json
index 06562054..b89de23c 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "cordova-plugin-inappbrowser",
   "version": "1.7.3-dev",
-  "description": "Cordova InAppBrowser Plugin",
+  "description": "Thalys InAppBrowser Plugin",
   "types": "./types/index.d.ts",
   "cordova": {
     "id": "cordova-plugin-inappbrowser",
@@ -20,7 +20,7 @@
   },
   "repository": {
     "type": "git",
-    "url": "https://github.com/apache/cordova-plugin-inappbrowser"
+    "url": "https://github.com/THI-F/cordova-plugin-inappbrowser"
   },
   "bugs": {
     "url": "https://issues.apache.org/jira/browse/CB"
diff --git a/plugin.xml b/plugin.xml
index c857ec63..751bb414 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -19,11 +19,11 @@
 -->
 
 <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
-           id="cordova-plugin-inappbrowser"
+           id="thalys-plugin-inappbrowser"
       version="1.7.3-dev">
 
-    <name>InAppBrowser</name>
-    <description>Cordova InAppBrowser Plugin</description>
+    <name>Thalys InAppBrowser</name>
+    <description>Thalys InAppBrowser Plugin</description>
     <license>Apache 2.0</license>
     <keywords>cordova,in,app,browser,inappbrowser</keywords>
     <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git</repo>
diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java
index 48f68461..53d54ba6 100644
--- a/src/android/InAppBrowser.java
+++ b/src/android/InAppBrowser.java
@@ -81,6 +81,8 @@ Licensed to the Apache Software Foundation (ASF) under one
     private static final String LOCATION = "location";
     private static final String ZOOM = "zoom";
     private static final String HIDDEN = "hidden";
+    private static final String THALYS_EVENT = "thalys";
+    private static final String BACK_EVENT = "back";
     private static final String LOAD_START_EVENT = "loadstart";
     private static final String LOAD_STOP_EVENT = "loadstop";
     private static final String LOAD_ERROR_EVENT = "loaderror";
@@ -456,17 +458,44 @@ public void onPageFinished(WebView view, String url) {
      * Checks to see if it is possible to go back one page in history, then does so.
      */
     public void goBack() {
-        if (this.inAppWebView.canGoBack()) {
+       if (this.inAppWebView.canGoBack()) {
             this.inAppWebView.goBack();
         }
     }
+    
+
+    public boolean isUrlHome(String url){   
+        String[] parts = url.split("\\?"); //pour le ?mobile=android
+        String part1 = parts[0];
+        Boolean bool = false;
+        String[] languageMatrice = new String[] {"fr/fr","fr/en","be/fr","be/en","be/nl","de/de","de/en","nl/nl","nl/en"};
+        for (String language : languageMatrice) {
+             if (part1.endsWith(language)){
+                 bool = true;
+             }
+        }
+        return bool;
+    }
+    
 
     /**
      * Can the web browser go back?
      * @return boolean
      */
     public boolean canGoBack() {
-        return this.inAppWebView.canGoBack();
+        if (this.isUrlHome(this.inAppWebView.getUrl())){
+            try { //Envoi d l'?v?nement pour quitter l'application
+                JSONObject obj = new JSONObject();
+                 obj.put("type", BACK_EVENT);
+                 sendUpdate(obj, true);
+            } catch (JSONException ex) {
+                 LOG.e(LOG_TAG, "URI passed in has caused a JSON error.");
+            }
+            return false;
+        }
+        else {
+           return this.inAppWebView.canGoBack();
+        } 
     }
 
     /**
@@ -1039,6 +1068,27 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
             }
         }
 
+        /*
+        * onLoadResource fires the THALYS_EVENT
+        *
+        * @param view
+        * @param url
+        */
+        @Override
+        public void onLoadResource(WebView view, String url) {
+            super.onLoadResource(view, url);
+            if (url.startsWith("http://cordova-thalys") || url.startsWith("https://cordova-thalys")) {
+                try {
+                    JSONObject obj = new JSONObject();
+                    obj.put("type", THALYS_EVENT);
+                    obj.put("url", url);
+                    sendUpdate(obj, true);
+                } catch (JSONException ex) {
+                    LOG.e(LOG_TAG, "URI passed in has caused a JSON error.");
+                }
+            }
+        }
+
 
 
         public void onPageFinished(WebView view, String url) {
diff --git a/src/ios/CDVInAppBrowser.m b/src/ios/CDVInAppBrowser.m
index f5d05f01..93193381 100644
--- a/src/ios/CDVInAppBrowser.m
+++ b/src/ios/CDVInAppBrowser.m
@@ -448,6 +448,14 @@ - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*
 
         [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
     }
+    else if ((self.callbackId != nil) && ([url.absoluteString hasPrefix:@"http://cordova-thalys"] || [url.absoluteString hasPrefix:@"https://cordova-thalys"])) {
+        // Send a thalys event for each top-level navigation (includes redirects).
+        CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
+                                                      messageAsDictionary:@{@"type":@"thalys", @"url":[url absoluteString]}];
+        [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
+
+        [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
+    }
 
     return YES;
 }
diff --git a/www/inappbrowser.js b/www/inappbrowser.js
index 7c3e749e..a8cea27a 100644
--- a/www/inappbrowser.js
+++ b/www/inappbrowser.js
@@ -33,10 +33,12 @@
 
     function InAppBrowser () {
         this.channels = {
+            'back': channel.create('back'),
+            'thalys': channel.create('thalys'),
             'loadstart': channel.create('loadstart'),
             'loadstop': channel.create('loadstop'),
             'loaderror': channel.create('loaderror'),
-            'exit': channel.create('exit')
+            'exit': channel.create('exit')          
         };
     }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org