Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headers #2

Merged
merged 7 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ InAppBrowser.removeAllListeners();
* [`addListener('browserClosed' | 'browserPageLoaded', ...)`](#addlistenerbrowserclosed--browserpageloaded-)
* [`removeAllListeners()`](#removealllisteners)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)
* [Enums](#enums)

</docgen-index>
Expand Down Expand Up @@ -281,9 +282,10 @@ Defines the options for opening a URL in the system browser.

Defines the options for opening a URL in the external browser and used by the others.

| Prop | Type | Description |
| --------- | ------------------- | -------------------------------------------------------------------------------------- |
| **`url`** | <code>string</code> | The URL to be opened. It must contain either 'http' or 'https' as the protocol prefix. |
| Prop | Type | Description |
| ------------- | --------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| **`url`** | <code>string</code> | The URL to be opened. It must contain either 'http' or 'https' as the protocol prefix. |
| **`headers`** | <code><a href="#record">Record</a>&lt;string, string&gt;</code> | The headers for the http request |


#### PluginListenerHandle
Expand All @@ -293,6 +295,16 @@ Defines the options for opening a URL in the external browser and used by the ot
| **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |


### Type Aliases


#### Record

Construct a type with a set of properties K of type T

<code>{ [P in K]: T; }</code>


### Enums


Expand Down
14 changes: 8 additions & 6 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ kotlin {
jvmToolchain(17)
}

repositories {
google()
mavenCentral()
allprojects {
repositories {
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
}


dependencies {
// implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':capacitor-android')
implementation "com.capacitorjs:osinappbrowser-android:1.2.1@aar"
implementation 'com.github.trading-point:OSInAppBrowserLib-Android:v2-headers'
implementation 'androidx.browser:browser:1.8.0'
implementation "androidx.constraintlayout:constraintlayout:2.2.0-alpha13"
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ import com.getcapacitor.Plugin
import com.getcapacitor.PluginCall
import com.getcapacitor.PluginMethod
import com.getcapacitor.annotation.CapacitorPlugin
import com.outsystems.plugins.inappbrowser.osinappbrowserlib.OSIABClosable
import com.outsystems.plugins.inappbrowser.osinappbrowserlib.OSIABEngine
import com.outsystems.plugins.inappbrowser.osinappbrowserlib.OSIABRouter
import com.outsystems.plugins.inappbrowser.osinappbrowserlib.helpers.OSIABFlowHelper
import com.outsystems.plugins.inappbrowser.osinappbrowserlib.models.OSIABAnimation
import com.outsystems.plugins.inappbrowser.osinappbrowserlib.models.OSIABBottomSheet
import com.outsystems.plugins.inappbrowser.osinappbrowserlib.models.OSIABCustomTabsOptions
import com.outsystems.plugins.inappbrowser.osinappbrowserlib.models.OSIABToolbarPosition
import com.outsystems.plugins.inappbrowser.osinappbrowserlib.models.OSIABViewStyle
import com.outsystems.plugins.inappbrowser.osinappbrowserlib.models.OSIABWebViewOptions
import com.outsystems.plugins.inappbrowser.osinappbrowserlib.routeradapters.OSIABCustomTabsRouterAdapter
import com.outsystems.plugins.inappbrowser.osinappbrowserlib.routeradapters.OSIABExternalBrowserRouterAdapter
import com.outsystems.plugins.inappbrowser.osinappbrowserlib.routeradapters.OSIABWebViewRouterAdapter
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.tradingpoint.plugins.inappbrowser.osinappbrowserlib.OSIABClosable
import com.tradingpoint.plugins.inappbrowser.osinappbrowserlib.OSIABEngine
import com.tradingpoint.plugins.inappbrowser.osinappbrowserlib.OSIABRouter
import com.tradingpoint.plugins.inappbrowser.osinappbrowserlib.helpers.OSIABFlowHelper
import com.tradingpoint.plugins.inappbrowser.osinappbrowserlib.models.OSIABAnimation
import com.tradingpoint.plugins.inappbrowser.osinappbrowserlib.models.OSIABBottomSheet
import com.tradingpoint.plugins.inappbrowser.osinappbrowserlib.models.OSIABCustomTabsOptions
import com.tradingpoint.plugins.inappbrowser.osinappbrowserlib.models.OSIABToolbarPosition
import com.tradingpoint.plugins.inappbrowser.osinappbrowserlib.models.OSIABViewStyle
import com.tradingpoint.plugins.inappbrowser.osinappbrowserlib.models.OSIABWebViewOptions
import com.tradingpoint.plugins.inappbrowser.osinappbrowserlib.routeradapters.OSIABCustomTabsRouterAdapter
import com.tradingpoint.plugins.inappbrowser.osinappbrowserlib.routeradapters.OSIABExternalBrowserRouterAdapter
import com.tradingpoint.plugins.inappbrowser.osinappbrowserlib.routeradapters.OSIABWebViewRouterAdapter

@CapacitorPlugin(name = "InAppBrowser")
class InAppBrowserPlugin : Plugin() {
Expand All @@ -38,6 +40,10 @@ class InAppBrowserPlugin : Plugin() {
return
}

val headersObject = call.getObject("headers", JSObject()) ?: JSObject()
val type = object: TypeToken<HashMap<String, String>>(){}.type
val headersMap: HashMap<String, String> = Gson().fromJson(headersObject.toString(), type)

if (!isSchemeValid(url)) {
call.reject("The URL provided must begin with either http:// or https://.")
return
Expand All @@ -46,7 +52,7 @@ class InAppBrowserPlugin : Plugin() {
try {
val externalBrowserRouter = OSIABExternalBrowserRouterAdapter(context)

engine?.openExternalBrowser(externalBrowserRouter, url) { success ->
engine?.openExternalBrowser(externalBrowserRouter, url, headersMap) { success ->
if (success) {
call.resolve()
} else {
Expand All @@ -63,6 +69,10 @@ class InAppBrowserPlugin : Plugin() {
val url = call.getString("url")
val options = call.getObject("options")

val headersObject = call.getObject("headers", JSObject()) ?: JSObject()
val type = object: TypeToken<HashMap<String, String>>(){}.type
val headersMap: HashMap<String, String> = Gson().fromJson(headersObject.toString(), type)

if (url.isNullOrEmpty()) {
call.reject("The value of the 'url' input parameter of the 'openInSystemBrowser' action is missing or is empty.")
return
Expand Down Expand Up @@ -96,7 +106,7 @@ class InAppBrowserPlugin : Plugin() {
}
)

engine?.openCustomTabs(customTabsRouter, url) { success ->
engine?.openCustomTabs(customTabsRouter, url, headersMap) { success ->
if (success) {
activeRouter = customTabsRouter
call.resolve()
Expand All @@ -115,6 +125,10 @@ class InAppBrowserPlugin : Plugin() {
val url = call.getString("url")
val options = call.getObject("options")

val headersObject = call.getObject("headers", JSObject()) ?: JSObject()
val type = object: TypeToken<HashMap<String, String>>(){}.type
val headersMap: HashMap<String, String> = Gson().fromJson(headersObject.toString(), type)

if (url.isNullOrEmpty()) {
call.reject("The value of the 'url' input parameter of the 'openInWebView' action is missing or is empty.")
return
Expand Down Expand Up @@ -148,7 +162,7 @@ class InAppBrowserPlugin : Plugin() {
}
)

engine?.openWebView(webViewRouter, url) { success ->
engine?.openWebView(webViewRouter, url, headersMap) { success ->
if (success) {
activeRouter = webViewRouter
call.resolve()
Expand Down Expand Up @@ -207,7 +221,7 @@ class InAppBrowserPlugin : Plugin() {
val allowZoom = androidOptions?.getBoolean("allowZoom", true) ?: true
val hardwareBack = androidOptions?.getBoolean("hardwareBack", true) ?: true
val pauseMedia = androidOptions?.getBoolean("pauseMedia", true) ?: true

OSIABWebViewOptions(
showURL,
showToolbar,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.capacitorjs.osinappbrowser

import com.google.gson.annotations.SerializedName
import com.outsystems.plugins.inappbrowser.osinappbrowserlib.models.OSIABToolbarPosition
import com.tradingpoint.plugins.inappbrowser.osinappbrowserlib.models.OSIABToolbarPosition

data class OSInAppBrowserWebViewInputArguments(
@SerializedName("showURL") val showURL: Boolean?,
Expand Down
3 changes: 3 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ export interface AndroidSystemBrowserOptions {
export interface OpenInDefaultParameterModel {
/** The URL to be opened. It must contain either 'http' or 'https' as the protocol prefix. */
url: string;

/** The headers for the http request */
headers?: Record<string, string>;
}

/**
Expand Down
Loading