diff --git a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java index 56a058620..e7ff8b6dd 100644 --- a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +++ b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java @@ -76,6 +76,7 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.lang.IllegalArgumentException; import javax.annotation.Nullable; @@ -196,36 +197,40 @@ protected WebView createViewInstance(ThemedReactContext reactContext) { public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { RNCWebViewModule module = getModule(reactContext); - DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); - - String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype); - String downloadMessage = "Downloading " + fileName; - - //Attempt to add cookie, if it exists - URL urlObj = null; try { - urlObj = new URL(url); - String baseUrl = urlObj.getProtocol() + "://" + urlObj.getHost(); - String cookie = CookieManager.getInstance().getCookie(baseUrl); - request.addRequestHeader("Cookie", cookie); - System.out.println("Got cookie for DownloadManager: " + cookie); - } catch (MalformedURLException e) { - System.out.println("Error getting cookie for DownloadManager: " + e.toString()); - e.printStackTrace(); - } + DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); + + String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype); + String downloadMessage = "Downloading " + fileName; + + //Attempt to add cookie, if it exists + URL urlObj = null; + try { + urlObj = new URL(url); + String baseUrl = urlObj.getProtocol() + "://" + urlObj.getHost(); + String cookie = CookieManager.getInstance().getCookie(baseUrl); + request.addRequestHeader("Cookie", cookie); + System.out.println("Got cookie for DownloadManager: " + cookie); + } catch (MalformedURLException e) { + System.out.println("Error getting cookie for DownloadManager: " + e.toString()); + e.printStackTrace(); + } - //Finish setting up request - request.addRequestHeader("User-Agent", userAgent); - request.setTitle(fileName); - request.setDescription(downloadMessage); - request.allowScanningByMediaScanner(); - request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); - request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName); + //Finish setting up request + request.addRequestHeader("User-Agent", userAgent); + request.setTitle(fileName); + request.setDescription(downloadMessage); + request.allowScanningByMediaScanner(); + request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); + request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName); - module.setDownloadRequest(request); + module.setDownloadRequest(request); - if (module.grantFileDownloaderPermissions()) { - module.downloadFile(); + if (module.grantFileDownloaderPermissions()) { + module.downloadFile(); + } + } catch (IllegalArgumentException e) { + System.out.println("IllegalArgumentException: " + e.toString()); } } }); @@ -396,7 +401,7 @@ public void setInjectedJavaScript(WebView view, @Nullable String injectedJavaScr public void setMessagingEnabled(WebView view, boolean enabled) { ((RNCWebView) view).setMessagingEnabled(enabled); } - + @ReactProp(name = "incognito") public void setIncognito(WebView view, boolean enabled) { // Remove all previous cookies @@ -646,7 +651,7 @@ protected void setupWebChromeClient(ReactContext reactContext, WebView webView) public Bitmap getDefaultVideoPoster() { return Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888); } - + @Override public void onShowCustomView(View view, CustomViewCallback callback) { if (mVideoView != null) { diff --git a/package.json b/package.json index c61933cc4..967cb1ef8 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "react-native-webview", + "name": "@pandadoc/react-native-webview", "description": "React Native WebView component for iOS, Android, and macOS", "main": "index.js", "typings": "index.d.ts", @@ -8,8 +8,8 @@ "Thibault Malbranche " ], "license": "MIT", - "version": "8.1.0", - "homepage": "https://github.com/react-native-community/react-native-webview#readme", + "version": "8.1.5", + "homepage": "https://github.com/pandadoc/react-native-webview#readme", "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "start:android": "react-native run-android --root example/", @@ -37,8 +37,8 @@ "devDependencies": { "@babel/core": "7.4.5", "@babel/runtime": "7.4.5", - "@react-native-community/cli-platform-ios": "^3.0.0", "@react-native-community/cli-platform-android": "^3.0.0", + "@react-native-community/cli-platform-ios": "^3.0.0", "@semantic-release/git": "7.0.16", "@types/invariant": "^2.2.30", "@types/jest": "24.0.18", @@ -66,7 +66,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/react-native-community/react-native-webview.git" + "url": "https://github.com/pandadoc/react-native-webview.git" }, "files": [ "android", diff --git a/react-native-webview.podspec b/react-native-webview.podspec index 4140ecfc0..72af5df06 100644 --- a/react-native-webview.podspec +++ b/react-native-webview.podspec @@ -3,7 +3,7 @@ require 'json' package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) Pod::Spec.new do |s| - s.name = package['name'] + s.name = "react-native-webview" s.version = package['version'] s.summary = package['description'] s.license = package['license'] @@ -12,7 +12,7 @@ Pod::Spec.new do |s| s.homepage = package['homepage'] s.platform = :ios, "9.0" - s.source = { :git => "https://github.com/react-native-community/react-native-webview.git", :tag => "v#{s.version}" } + s.source = { :git => "https://github.com/pandadoc/react-native-webview.git", :tag => "v#{s.version}" } s.source_files = "ios/**/*.{h,m}" s.dependency 'React'