You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/01/17 20:03:00 UTC

[jira] [Commented] (CB-12969) InAppBrowser - Cannot open data URLs in system browser

    [ https://issues.apache.org/jira/browse/CB-12969?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16329360#comment-16329360 ] 

ASF GitHub Bot commented on CB-12969:
-------------------------------------

infil00p closed pull request #227: CB-12969 android: Added support for data URIs
URL: https://github.com/apache/cordova-plugin-inappbrowser/pull/227
 
 
   

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/README.md b/README.md
index 735b7364..df373722 100644
--- a/README.md
+++ b/README.md
@@ -707,3 +707,18 @@ iab.open('http://url-that-fails-whitelist.com', 'random_string'); // loads in th
 iab.open('http://url-that-fails-whitelist.com', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar
 
 ```
+
+### Data Urls (format: data:[<mediatype>][;base64],<data>)
+
+Supported by android, windows and browser platforms 
+```
+var iab = cordova.InAppbrowser;
+iab.open('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E');                  // loads in the Cordova WebView (android, browser) 
+iab.open('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E', '_self');         // loads in the Cordova WebView (android, browser) 
+iab.open('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E', '_system');       // loads in the system browser
+iab.open('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E', '_blank');        // loads in the InAppBrowser (android, browser)
+iab.open('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E', 'random_string'); // loads in the InAppBrowser (android, browser)
+iab.open('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E', 'random_string', 'location=no'); // loads in the InAppBrowser, no location bar (android, browser)
+
+```  
+
diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java
index fefbcece..abcc74b2 100644
--- a/src/android/InAppBrowser.java
+++ b/src/android/InAppBrowser.java
@@ -393,22 +393,27 @@ public void run() {
      */
     public String openExternal(String url) {
         try {
-            Intent intent = null;
-            intent = new Intent(Intent.ACTION_VIEW);
             // Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
             // Adding the MIME type to http: URLs causes them to not be handled by the downloader.
             Uri uri = Uri.parse(url);
-            if ("file".equals(uri.getScheme())) {
+            String scheme = uri.getScheme();
+
+            Intent intent = "data".equals(scheme)
+                    ? Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_BROWSER)
+                    : new Intent(Intent.ACTION_VIEW);
+
+            if ("file".equals(scheme)) {
                 intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
             } else {
                 intent.setData(uri);
             }
+
             intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
             this.cordova.getActivity().startActivity(intent);
             return "";
-        // not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
+            // not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
         } catch (java.lang.RuntimeException 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();
         }
     }
diff --git a/src/windows/InAppBrowserProxy.js b/src/windows/InAppBrowserProxy.js
index dec91dba..b03e8206 100644
--- a/src/windows/InAppBrowserProxy.js
+++ b/src/windows/InAppBrowserProxy.js
@@ -135,7 +135,12 @@ var IAB = {
 
             if (target === "_system") {
                 url = new Windows.Foundation.Uri(strUrl);
-                Windows.System.Launcher.launchUriAsync(url);
+                var options = new Windows.System.LauncherOptions();
+                if (url.schemeName === 'data') {
+                    options.contentType = "text/html";
+                }
+
+                Windows.System.Launcher.launchUriAsync(url, options);
             } else if (target === "_self" || !target) {
                 window.location = strUrl;
             } else {


 

----------------------------------------------------------------
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


> InAppBrowser - Cannot open data URLs in system browser
> ------------------------------------------------------
>
>                 Key: CB-12969
>                 URL: https://issues.apache.org/jira/browse/CB-12969
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-plugin-inappbrowser
>         Environment: iOS, Android
>            Reporter: Sachitra Malwatte
>            Assignee: Nikita Matrosov
>            Priority: Critical
>
> I want to open data URLs in system browser. So I did this,
> {code:java}
> window.open('data:text/html, <html><body><h1>Hello</h1></body></html>', '_system');
> {code}
> But nothing happens (browser won't open).
> It works with normal URLs. e.g. window.open('https://github.com/apache/cordova-plugin-inappbrowser', '_system'); But not with data URIs.
> inappbrowser version: 1.7.1
> Please help.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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