All Projects → braintree → Popup Bridge Android

braintree / Popup Bridge Android

Licence: mit
PopupBridge allows WebViews to open popup windows in a browser and send data back to the WebView

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Popup Bridge Android

Django Admin Interface
django's default admin interface made customizable. popup windows replaced by modals. :mage: ⚡️
Stars: ✭ 717 (+2212.9%)
Mutual labels:  popup
Powermenu
🔥 The powerful and easiest way to implement modern material popup menu.
Stars: ✭ 822 (+2551.61%)
Mutual labels:  popup
Paypal Checkout Components
Javascript Integration for PayPal Button and PayPal Checkout
Stars: ✭ 938 (+2925.81%)
Mutual labels:  popup
Anylayer
Android稳定高效的浮层创建管理框架
Stars: ✭ 745 (+2303.23%)
Mutual labels:  popup
Cardpresentationcontroller
Custom UIPresentationController which mimics the behavior of Apple Music UI
Stars: ✭ 778 (+2409.68%)
Mutual labels:  popup
Holler Box
Smart, stylish WordPress popup plugin
Stars: ✭ 16 (-48.39%)
Mutual labels:  popup
Sweet Alert
A BEAUTIFUL, RESPONSIVE, CUSTOMIZABLE, ACCESSIBLE (WAI-ARIA) REPLACEMENT FOR JAVASCRIPT'S POPUP BOXES FOR LARAVEL
Stars: ✭ 696 (+2145.16%)
Mutual labels:  popup
Ajmessage
Simple popup message
Stars: ✭ 30 (-3.23%)
Mutual labels:  popup
Ybpopupmenu
快速集成popupMenu
Stars: ✭ 816 (+2532.26%)
Mutual labels:  popup
Bitcoin Donate
Add simple donate buttons to any website
Stars: ✭ 24 (-22.58%)
Mutual labels:  popup
Multi
Create a custom, lightweight macOS app from a group of websites
Stars: ✭ 755 (+2335.48%)
Mutual labels:  webview
Axwebviewcontroller
AXWebViewController is a webViewController to browse web content inside applications. It’s a lightweight controller on iOS platform based on WKWebView (UIWebView would be the base Kit under iOS 8.0). It added navigation tool bar to refresh, go back, go forward and so on. It support the navigation style on WeChat. It is a simple-using and convenient web view controller using inside applications.
Stars: ✭ 770 (+2383.87%)
Mutual labels:  webview
Data Collection Dotnet
Data collection application built using the .NET Runtime SDK.
Stars: ✭ 17 (-45.16%)
Mutual labels:  popup
Webview deno
🌐 Deno bindings for webview, a tiny library for creating web-based desktop GUIs
Stars: ✭ 729 (+2251.61%)
Mutual labels:  webview
Arek
AREK is a clean and easy way to request any kind of iOS permission (with some nifty features 🤖)
Stars: ✭ 947 (+2954.84%)
Mutual labels:  popup
Hwpanmodal
HWPanModal presents controller from bottom and drag to dismiss, high customize. iOS13 default modalPresentationStyle. 任意形式的底部弹框动画;头条、知乎、抖音弹出评论效果;地图浮层,iOS13 present默认模态效果。
Stars: ✭ 713 (+2200%)
Mutual labels:  popup
Quickmyanimelist
[Abandoned] The dream Chrome Extension for you with a MyAnimeList account.
Stars: ✭ 6 (-80.65%)
Mutual labels:  popup
Tiny.scatter
Scatter compatible eos injection library
Stars: ✭ 31 (+0%)
Mutual labels:  webview
React Electron Webview
React component for the <webview> element in Electron.
Stars: ✭ 29 (-6.45%)
Mutual labels:  webview
Slimsocial For Twitter
Light version of Twitter. Light not only in weight but also in the use.
Stars: ✭ 24 (-22.58%)
Mutual labels:  webview

PopupBridge

Build Status

PopupBridge is an Android library that allows WebViews to open popup windows in a browser and send data back to the parent page in the WebView.

PopupBridge Demo gif

📣  A new major version of the SDK is available in beta. See the v4 migration guide for details.

PopupBridge is also available for iOS.

See the Frequently Asked Questions to learn more about PopupBridge. See Using PayPal in a WebView to use PopupBridge with PayPal.

Requirements

  • Android SDK 21

Installation

Add the dependency in your build.gradle:

dependencies {
  implementation 'com.braintreepayments:popup-bridge:3.1.0'
}

To use the latest build from the master branch use:

dependencies {
  implementation 'com.braintreepayments:popup-bridge:3.1.1-SNAPSHOT'
}

Quick Start

  1. Add PopupBridgeActivity to AndroidManifest.xml and register a custom URL scheme:
<activity android:name="com.braintreepayments.popupbridge.PopupBridgeActivity"
    android:launchMode="singleTask">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="${applicationId}.popupbridge" />
    </intent-filter>
</activity>
  1. Include PopupBridge in your app code:

    import com.braintreepayments.popupbridge.PopupBridge;
    
    class MyWebViewActivity extends Activity {
        private WebView mWebView;
    
        @Override
        public void onCreate() {
            // Connect your web view.
            // ...
    
            // ...and then attach PopupBridge.
            PopupBridge.newInstance(this, mWebView);
        }
    }
    
  2. Use PopupBridge from the web page by writing some JavaScript:

    var url = 'http://localhost:4567/'; // the url you wish to open in a popup
    
    if (window.popupBridge) {
      // Open the popup in a browser, and give it the deep link back to the app
      popupBridge.open(url + '?popupBridgeReturnUrlPrefix=' + popupBridge.getReturnUrlPrefix());
    
      // Optional: define a callback to process results of interaction with the popup
      popupBridge.onComplete = function (err, payload) {
        if (err) {
          console.error('PopupBridge onComplete Error:', err);
        } else if (!err && !payload) {
          console.log('User closed popup.');
        } else {
          alert('Your favorite color is ' + payload.queryItems.color);
    
          console.log(payload.path) // defaults to ""
          console.log(payload.hash) // defaults to ""
        }
      };
    } else {
      var popup = window.open(url);
    
      window.addEventListener('message', function (event) {
        var color = JSON.parse(event.data).color;
    
        if (color) {
          popup.close();
          alert('Your favorite color is ' + color);
        }
      });
    }
    
  3. Redirect back to the app inside of the popup:

    <h1>What is your favorite color?</h1>
    
    <a href="#" data-color="red">Red</a>
    <a href="#" data-color="green">Green</a>
    <a href="#" data-color="blue">Blue</a>
    
    <script src="jquery.js"></script>
    <script>
    $('a').on('click', function (event) {
      var color = $(this).data('color');
    
      if (location.search.indexOf('popupBridgeReturnUrlPrefix') !== -1) {
        var prefix = location.search.split('popupBridgeReturnUrlPrefix=')[1];
        // Open the deep link back to the app, and send some data
        location.href = prefix + '?color=' + color;
      } else {
        window.opener.postMessage(JSON.stringify({ color: color }), '*');
      }
    });
    </script>
    

Frequently Asked Questions

Why use PopupBridge?

By default, WebViews cannot open popups -- window.open will not work.

You can use setSupportMultipleWindows() and roll your own WebChromeClient and manage the windows yourself, but this does not allow popups to communicate back to the parent WebView.

What are some use cases for using PopupBridge?

  • Apps with WebViews that need to open a popup
  • When a popup window needs to send data from the popup back to the WebView
  • When the popup window needs to display the HTTPS lock icon to increase user trust
  • Apps that use OAuth

How does it work?

  • PopupBridge attaches to a WebView through the Android JavaScript interface
    • This exposes a JavaScript interface (via window.popupBridge) for the web page to interact with the Android app code
  • The web page detects whether the page has access to window.popupBridge; if so, it uses popupBridge.open to open the popup URL
    • popupBridge.open creates an Intent to open the popup URL, which Android forwards to the user's selected browser
    • The web page can also use popupBridge.onComplete as a callback
  • The popup web page uses a deep link URL to return back to the app
    • The deep link is in the format of ${applicationId}.popupbridge, which is registered as a custom URL scheme in AndroidManifest.xml

    • One way to avoid hard-coding the deep link is by adding it as a query parameter to the popup URL:

        popupBridge.open(url + '?popupBridgeReturnUrlPrefix=' + popupBridge.getReturnUrlPrefix());
      
      • Optionally, you can add path components, query parameters, hash values to the deep link URL to return data to the parent page, which are provided in the payload of popupBridge.onComplete
  • If the user hits the back button or manually navigates back to the app, popupBridge.onComplete gets called with the error and payload as null

Who built PopupBridge?

We are a team of engineers who work on the Developer Experience team at Braintree.

Why did Braintree build PopupBridge?

Short answer: to accept PayPal as a payment option when mobile apps are using a WebView to power the checkout process.

PayPal used to support authentication via a modal iframe, but authentication now occurs in a popup window to increase user confidence that their account information is protected from malicious actors (the address bar shows paypal.com with the HTTPS lock icon). However, this causes issues with Braintree merchants who use a web page to power payments within their apps: they cannot accept PayPal because WebViews cannot open popups and return the PayPal payment authorization data to the parent checkout page.

PopupBridge solves this problem by allowing braintree-web or PayPal's Checkout.js to open the PayPal popup from a secure mini-browser.

Using PayPal in a WebView

WebView-based checkout flows can accept PayPal with PopupBridge and the Braintree JS SDK or PayPal's Checkout.js. For the authentication flow, PayPal requires a popup window—which can be simulated with PopupBridge.

Setup

  1. Create a web-based checkout that accepts PayPal using Checkout.js or the Braintree JS SDK
  2. Create a native mobile app that opens the checkout in a WebView (see steps 1-2 in quick start)
  3. Integrate the PopupBridge library
  4. Collect device data
    • To help detect fraudulent activity, collect device data before performing PayPal transactions. This is similar to collecting device data with our native Android SDK:
      1. Include PayPalDataCollector in your build.gradle dependencies, e.g. compile 'com.paypal.android.sdk:data-collector:2.+'
      2. Implement a method in your native app for sending device data. See the Android code snippet for PayPal + PopupBridge
  5. Profit!

Author

Braintree, [email protected]

License

PopupBridge is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].