Skip to content

Commit

Permalink
Merge pull request #20997 from wordpress-mobile/issue/20996-iae-jsobj…
Browse files Browse the repository at this point in the history
…ectname

[Fix] IllegalArgumentException: in ReaderPostRenderer
  • Loading branch information
irfano committed Jun 18, 2024
2 parents 9e26ec5 + cfd8b51 commit 42fee84
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
*/
public class ReaderPostRenderer {
private static final String JAVASCRIPT_MESSAGE_HANDLER = "wvHandler";
private static final String JS_OBJECT_ADDED_TAG = "jsObjectAdded";
private final ReaderResourceVars mResourceVars;
private final ReaderPost mPost;
private final int mMinFullSizeWidthDp;
Expand Down Expand Up @@ -645,6 +646,11 @@ private String getContentTextProperties() {
}

private void setWebViewMessageHandler(@NonNull WebView webView) {
Object tag = webView.getTag(JS_OBJECT_ADDED_TAG.hashCode());
if (tag != null && (boolean) tag) {
return; // Exit if the object has already been added
}

Set<String> allowedOrigins = new HashSet<>();
allowedOrigins.add("*");

Expand All @@ -665,6 +671,9 @@ private void setWebViewMessageHandler(@NonNull WebView webView) {
}
return null;
});

// Set the tag that the JS object has been added, so we can check before adding it again
webView.setTag(JS_OBJECT_ADDED_TAG.hashCode(), true);
}

void setPostMessageListener(@Nullable ReaderPostMessageListener listener) {
Expand Down

0 comments on commit 42fee84

Please sign in to comment.