From 8b966423807c6af839800adcffb8914bbe3c3489 Mon Sep 17 00:00:00 2001 From: Chris Bobbe Date: Mon, 21 Sep 2020 14:53:29 -0700 Subject: [PATCH] webview: Prepare to "revive" realm in `handleInitialLoad`. In an upcoming commit, we'll change the `Auth` type to have a URL object for the realm. We call `JSON.stringify` on the arguments passed to `handleInitialLoad`. For the `realm` property, this means it'll be a string URL, not a URL object. Here, we pick it out in preparation for "reviving" it back into its URL form in the body of `handleInitialLoad`. --- src/webview/js/generatedEs3.js | 55 +++++++++++++++++++++++++++++++++- src/webview/js/js.js | 5 +++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/webview/js/generatedEs3.js b/src/webview/js/generatedEs3.js index bcd5acfe35a..3404fec6839 100644 --- a/src/webview/js/generatedEs3.js +++ b/src/webview/js/generatedEs3.js @@ -36,6 +36,55 @@ var compiledWebviewJs = (function (exports) { return Constructor; } + function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; + } + + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + if (enumerableOnly) symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + }); + keys.push.apply(keys, symbols); + } + + return keys; + } + + function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i] != null ? arguments[i] : {}; + + if (i % 2) { + ownKeys(Object(source), true).forEach(function (key) { + _defineProperty(target, key, source[key]); + }); + } else if (Object.getOwnPropertyDescriptors) { + Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + } else { + ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + } + + return target; + } + var sendMessage = (function (msg) { window.ReactNativeWebView.postMessage(JSON.stringify(msg)); }); @@ -610,7 +659,11 @@ var compiledWebviewJs = (function (exports) { sendScrollMessageIfListShort(); }; - var handleInitialLoad = function handleInitialLoad(platformOS, scrollMessageId, auth) { + var handleInitialLoad = function handleInitialLoad(platformOS, scrollMessageId, rawAuth) { + var auth = _objectSpread2(_objectSpread2({}, rawAuth), {}, { + realm: rawAuth.realm + }); + if (platformOS === 'ios') { window.addEventListener('message', handleMessageEvent); } else { diff --git a/src/webview/js/js.js b/src/webview/js/js.js index 30621d659f9..f31adfaeea2 100644 --- a/src/webview/js/js.js +++ b/src/webview/js/js.js @@ -544,8 +544,11 @@ const handleUpdateEventContent = (uevent: WebViewUpdateEventContent) => { export const handleInitialLoad = ( platformOS: string, scrollMessageId: number | null, - auth: Auth, + // In an upcoming commit, the `realm` part of an `Auth` object will + // be a URL object. It'll be passed here in its stringified form. + rawAuth: {| ...$Diff, realm: string |}, ) => { + const auth: Auth = { ...rawAuth, realm: rawAuth.realm }; // Since its version 5.x, the `react-native-webview` library dispatches our // `message` events at `window` on iOS but `document` on Android. if (platformOS === 'ios') {