Skip to content

Commit

Permalink
Check that the jsobject has not been added already
Browse files Browse the repository at this point in the history
  • Loading branch information
zwarm committed Jun 17, 2024
1 parent 9e26ec5 commit cfd8b51
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 cfd8b51

Please sign in to comment.