@@ -215,16 +215,17 @@ public WebViewClient createWebViewClient(InAppBrowserDelegate inAppBrowserDelega
215
215
}
216
216
217
217
boolean isChromiumWebView = "com.android.webview" .equals (packageInfo .packageName ) ||
218
- "com.google.android.webview" .equals (packageInfo .packageName ) ||
219
- "com.android.chrome" .equals (packageInfo .packageName );
218
+ "com.google.android.webview" .equals (packageInfo .packageName ) ||
219
+ "com.android.chrome" .equals (packageInfo .packageName );
220
220
boolean isChromiumWebViewBugFixed = false ;
221
221
if (isChromiumWebView ) {
222
222
String versionName = packageInfo .versionName != null ? packageInfo .versionName : "" ;
223
223
try {
224
224
int majorVersion = versionName .contains ("." ) ?
225
225
Integer .parseInt (versionName .split ("\\ ." )[0 ]) : 0 ;
226
226
isChromiumWebViewBugFixed = majorVersion >= 73 ;
227
- } catch (NumberFormatException ignored ) {}
227
+ } catch (NumberFormatException ignored ) {
228
+ }
228
229
}
229
230
230
231
if (isChromiumWebViewBugFixed || !isChromiumWebView ) {
@@ -704,36 +705,21 @@ public void takeScreenshot(final @Nullable Map<String, Object> screenshotConfigu
704
705
@ Override
705
706
public void run () {
706
707
try {
707
- Bitmap screenshotBitmap = Bitmap . createBitmap ( getMeasuredWidth (), getMeasuredHeight (), Bitmap . Config . ARGB_8888 );
708
- Canvas c = new Canvas ( screenshotBitmap );
709
- c . translate (- getScrollX (), - getScrollY () );
710
- draw ( c );
708
+ int bitmapWidth = getMeasuredWidth ();
709
+ int bitmapHeight = getMeasuredHeight ( );
710
+ int bitmapScrollX = getScrollX ();
711
+ int bitmapScrollY = getScrollY ( );
711
712
712
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ();
713
713
Bitmap .CompressFormat compressFormat = Bitmap .CompressFormat .PNG ;
714
714
int quality = 100 ;
715
715
716
716
if (screenshotConfiguration != null ) {
717
717
Map <String , Double > rect = (Map <String , Double >) screenshotConfiguration .get ("rect" );
718
718
if (rect != null ) {
719
- int rectX = (int ) Math .floor (rect .get ("x" ) * pixelDensity + 0.5 );
720
- int rectY = (int ) Math .floor (rect .get ("y" ) * pixelDensity + 0.5 );
721
- int rectWidth = Math .min (screenshotBitmap .getWidth (), (int ) Math .floor (rect .get ("width" ) * pixelDensity + 0.5 ));
722
- int rectHeight = Math .min (screenshotBitmap .getHeight (), (int ) Math .floor (rect .get ("height" ) * pixelDensity + 0.5 ));
723
- screenshotBitmap = Bitmap .createBitmap (
724
- screenshotBitmap ,
725
- rectX ,
726
- rectY ,
727
- rectWidth ,
728
- rectHeight );
729
- }
730
-
731
- Double snapshotWidth = (Double ) screenshotConfiguration .get ("snapshotWidth" );
732
- if (snapshotWidth != null ) {
733
- int dstWidth = (int ) Math .floor (snapshotWidth * pixelDensity + 0.5 );
734
- float ratioBitmap = (float ) screenshotBitmap .getWidth () / (float ) screenshotBitmap .getHeight ();
735
- int dstHeight = (int ) ((float ) dstWidth / ratioBitmap );
736
- screenshotBitmap = Bitmap .createScaledBitmap (screenshotBitmap , dstWidth , dstHeight , true );
719
+ bitmapScrollX = (int ) Math .floor (rect .get ("x" ) * pixelDensity + 0.5 );
720
+ bitmapScrollY = (int ) Math .floor (rect .get ("y" ) * pixelDensity + 0.5 );
721
+ bitmapWidth = (int ) Math .floor (rect .get ("width" ) * pixelDensity + 0.5 );
722
+ bitmapHeight = (int ) Math .floor (rect .get ("height" ) * pixelDensity + 0.5 );
737
723
}
738
724
739
725
try {
@@ -745,10 +731,31 @@ public void run() {
745
731
quality = (Integer ) screenshotConfiguration .get ("quality" );
746
732
}
747
733
748
- screenshotBitmap .compress (
734
+ Bitmap screenshotBitmap = Bitmap .createBitmap (bitmapWidth , bitmapHeight , Bitmap .Config .ARGB_8888 );
735
+ Canvas c = new Canvas (screenshotBitmap );
736
+ c .translate (-bitmapScrollX , -bitmapScrollY );
737
+ draw (c );
738
+
739
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ();
740
+
741
+ if (screenshotConfiguration != null ) {
742
+ Double snapshotWidth = (Double ) screenshotConfiguration .get ("snapshotWidth" );
743
+ if (snapshotWidth != null ) {
744
+ int dstWidth = (int ) Math .floor (snapshotWidth * pixelDensity + 0.5 );
745
+ float ratioBitmap = (float ) screenshotBitmap .getWidth () / (float ) screenshotBitmap .getHeight ();
746
+ int dstHeight = (int ) ((float ) dstWidth / ratioBitmap );
747
+ screenshotBitmap = Bitmap .createScaledBitmap (screenshotBitmap , dstWidth , dstHeight , true );
748
+ }
749
+ }
750
+
751
+ final boolean compressed = screenshotBitmap .compress (
749
752
compressFormat ,
750
753
quality ,
751
754
byteArrayOutputStream );
755
+ if (!compressed ) {
756
+ Log .e (LOG_TAG , "Screenshot cannot be compressed using compressFormat " +
757
+ compressFormat .name () + " with quality " + quality , null );
758
+ }
752
759
753
760
try {
754
761
byteArrayOutputStream .close ();
@@ -932,7 +939,7 @@ else if (newSettingsMap.get("clearSessionCache") != null && newCustomSettings.cl
932
939
933
940
if (newSettingsMap .get ("disabledActionModeMenuItems" ) != null &&
934
941
(customSettings .disabledActionModeMenuItems == null ||
935
- !customSettings .disabledActionModeMenuItems .equals (newCustomSettings .disabledActionModeMenuItems ))) {
942
+ !customSettings .disabledActionModeMenuItems .equals (newCustomSettings .disabledActionModeMenuItems ))) {
936
943
if (WebViewFeature .isFeatureSupported (WebViewFeature .DISABLED_ACTION_MODE_MENU_ITEMS ))
937
944
WebSettingsCompat .setDisabledActionModeMenuItems (settings , newCustomSettings .disabledActionModeMenuItems );
938
945
else if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N )
@@ -1164,7 +1171,7 @@ public void injectDeferredObject(String source, @Nullable final ContentWorld con
1164
1171
if (resultUuid != null && resultCallback != null ) {
1165
1172
evaluateJavaScriptContentWorldCallbacks .put (resultUuid , resultCallback );
1166
1173
scriptToInject = Util .replaceAll (PluginScriptsUtil .EVALUATE_JAVASCRIPT_WITH_CONTENT_WORLD_WRAPPER_JS_SOURCE ,
1167
- PluginScriptsUtil .VAR_RANDOM_NAME , "_" + JavaScriptBridgeJS .JAVASCRIPT_BRIDGE_NAME + "_" + Math .round (Math .random () * 1000000 ))
1174
+ PluginScriptsUtil .VAR_RANDOM_NAME , "_" + JavaScriptBridgeJS .JAVASCRIPT_BRIDGE_NAME + "_" + Math .round (Math .random () * 1000000 ))
1168
1175
.replace (PluginScriptsUtil .VAR_PLACEHOLDER_VALUE , UserContentController .escapeCode (source ))
1169
1176
.replace (PluginScriptsUtil .VAR_RESULT_UUID , resultUuid );
1170
1177
}
@@ -1209,15 +1216,15 @@ public void injectJavascriptFileFromUrl(String urlFile, @Nullable Map<String, Ob
1209
1216
String scriptIdEscaped = idAttr .replaceAll ("'" , "\\ \\ '" );
1210
1217
scriptAttributes += " script.id = '" + scriptIdEscaped + "'; " ;
1211
1218
scriptAttributes += " script.onload = function() {" +
1212
- " if (window." + JavaScriptBridgeJS .JAVASCRIPT_BRIDGE_NAME + " != null) {" +
1213
- " window." + JavaScriptBridgeJS .JAVASCRIPT_BRIDGE_NAME + ".callHandler('onInjectedScriptLoaded', '" + scriptIdEscaped + "');" +
1214
- " }" +
1215
- "};" ;
1219
+ " if (window." + JavaScriptBridgeJS .JAVASCRIPT_BRIDGE_NAME + " != null) {" +
1220
+ " window." + JavaScriptBridgeJS .JAVASCRIPT_BRIDGE_NAME + ".callHandler('onInjectedScriptLoaded', '" + scriptIdEscaped + "');" +
1221
+ " }" +
1222
+ "};" ;
1216
1223
scriptAttributes += " script.onerror = function() {" +
1217
- " if (window." + JavaScriptBridgeJS .JAVASCRIPT_BRIDGE_NAME + " != null) {" +
1218
- " window." + JavaScriptBridgeJS .JAVASCRIPT_BRIDGE_NAME + ".callHandler('onInjectedScriptError', '" + scriptIdEscaped + "');" +
1219
- " }" +
1220
- "};" ;
1224
+ " if (window." + JavaScriptBridgeJS .JAVASCRIPT_BRIDGE_NAME + " != null) {" +
1225
+ " window." + JavaScriptBridgeJS .JAVASCRIPT_BRIDGE_NAME + ".callHandler('onInjectedScriptError', '" + scriptIdEscaped + "');" +
1226
+ " }" +
1227
+ "};" ;
1221
1228
}
1222
1229
Boolean asyncAttr = (Boolean ) scriptHtmlTagAttributes .get ("async" );
1223
1230
if (asyncAttr != null && asyncAttr ) {
@@ -1368,13 +1375,13 @@ class DownloadStartListener implements DownloadListener {
1368
1375
@ Override
1369
1376
public void onDownloadStart (String url , String userAgent , String contentDisposition , String mimeType , long contentLength ) {
1370
1377
DownloadStartRequest downloadStartRequest = new DownloadStartRequest (
1371
- url ,
1372
- userAgent ,
1373
- contentDisposition ,
1374
- mimeType ,
1375
- contentLength ,
1376
- URLUtil .guessFileName (url , contentDisposition , mimeType ),
1377
- null
1378
+ url ,
1379
+ userAgent ,
1380
+ contentDisposition ,
1381
+ mimeType ,
1382
+ contentLength ,
1383
+ URLUtil .guessFileName (url , contentDisposition , mimeType ),
1384
+ null
1378
1385
);
1379
1386
if (channelDelegate != null ) channelDelegate .onDownloadStartRequest (downloadStartRequest );
1380
1387
}
@@ -1516,7 +1523,8 @@ protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolea
1516
1523
}
1517
1524
1518
1525
if (overScrolledHorizontally || overScrolledVertically ) {
1519
- if (channelDelegate != null ) channelDelegate .onOverScrolled (scrollX , scrollY , overScrolledHorizontally , overScrolledVertically );
1526
+ if (channelDelegate != null )
1527
+ channelDelegate .onOverScrolled (scrollX , scrollY , overScrolledHorizontally , overScrolledVertically );
1520
1528
}
1521
1529
}
1522
1530
@@ -1639,7 +1647,8 @@ public void onClick(View v) {
1639
1647
hideContextMenu ();
1640
1648
callback .onActionItemClicked (actionMode , menuItem );
1641
1649
1642
- if (channelDelegate != null ) channelDelegate .onContextMenuActionItemClicked (itemId , itemTitle );
1650
+ if (channelDelegate != null )
1651
+ channelDelegate .onContextMenuActionItemClicked (itemId , itemTitle );
1643
1652
}
1644
1653
});
1645
1654
if (floatingContextMenu != null ) {
@@ -1659,7 +1668,8 @@ public void onClick(View v) {
1659
1668
public void onClick (View v ) {
1660
1669
hideContextMenu ();
1661
1670
1662
- if (channelDelegate != null ) channelDelegate .onContextMenuActionItemClicked (itemId , itemTitle );
1671
+ if (channelDelegate != null )
1672
+ channelDelegate .onContextMenuActionItemClicked (itemId , itemTitle );
1663
1673
}
1664
1674
});
1665
1675
if (floatingContextMenu != null ) {
0 commit comments