From 0ff1e082e284104aa0d18c97ee464a9d9197b3e2 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Wed, 1 Mar 2017 19:48:14 +0100 Subject: [PATCH 1/2] Fixed wallet preference page refresh Resolves #6770 Auditors: @alexwykoff @bsclifton @mrose17 Test Plan: - described in #6770 --- app/filtering.js | 15 ++++++++++++++- app/ledger.js | 14 +++++--------- docs/appActions.md | 16 ++++++++++++++++ js/actions/appActions.js | 17 +++++++++++++++++ js/components/frame.js | 3 --- js/constants/appConstants.js | 3 ++- 6 files changed, 54 insertions(+), 14 deletions(-) diff --git a/app/filtering.js b/app/filtering.js index b0f6bb47f98..a09918b14b7 100644 --- a/app/filtering.js +++ b/app/filtering.js @@ -561,11 +561,24 @@ function initForPartition (partition) { registerForDownloadListener, registerForMagnetHandler] let options = {} + if (isSessionPartition(partition)) { options.parent_partition = '' } + let ses = session.fromPartition(partition, options) - fns.forEach((fn) => { fn(ses, partition, module.exports.isPrivate(partition)) }) + fns.forEach((fn) => { + fn(ses, partition, module.exports.isPrivate(partition)) + }) + ses.on('register-navigator-handler', (e, protocol, location) => { + appActions.navigatorHandler(ses.partition, protocol, location, true) + }) + ses.on('unregister-navigator-handler', (e, protocol, location) => { + appActions.navigatorHandler(ses.partition, protocol, location, false) + }) + ses.protocol.getNavigatorHandlers().forEach((handler) => { + appActions.navigatorHandler(ses.partition, handler.protocol, handler.location, true) + }) } const filterableProtocols = ['http:', 'https:', 'ws:', 'wss:'] diff --git a/app/ledger.js b/app/ledger.js index 0a118027551..b4c0691c5b3 100644 --- a/app/ledger.js +++ b/app/ledger.js @@ -232,6 +232,11 @@ const doAction = (action) => { setTimeout(networkConnected, 1 * msecs.second) break + case appConstants.APP_NAVIGATOR_HANDLER_UPDATE: + ledgerInfo.hasBitcoinHandler = (action.register && action.protocol === 'bitcoin') + appActions.updateLedgerInfo(underscore.omit(ledgerInfo, [ '_internal' ])) + break + default: break } @@ -466,15 +471,6 @@ if (ipc) { } }) - ipc.on(messages.CHECK_BITCOIN_HANDLER, (event, partition) => { - const protocolHandler = session.fromPartition(partition).protocol - // TODO: https://github.com/brave/browser-laptop/issues/3625 - if (typeof protocolHandler.isNavigatorProtocolHandled === 'function') { - ledgerInfo.hasBitcoinHandler = protocolHandler.isNavigatorProtocolHandled('bitcoin') - appActions.updateLedgerInfo(underscore.omit(ledgerInfo, [ '_internal' ])) - } - }) - ipc.on(messages.LEDGER_PUBLISHER, (event, location) => { var ctx diff --git a/docs/appActions.md b/docs/appActions.md index 1439537a735..1484e3b0c05 100644 --- a/docs/appActions.md +++ b/docs/appActions.md @@ -754,6 +754,22 @@ Update the detail object for the open alert/confirm/prompt (triggers re-render) +### navigatorHandler(partition, protocol, location, register) + +Action triggered by navigation handler + +**Parameters** + +**partition**: `string`, session partition + +**protocol**: `string`, navigator protocol + +**location**: `string`, location where handler was triggered + +**register**: `boolean`, true if event was registered or false if unregistered + + + * * * diff --git a/js/actions/appActions.js b/js/actions/appActions.js index 555d960f5a4..5257a0dbc50 100644 --- a/js/actions/appActions.js +++ b/js/actions/appActions.js @@ -929,6 +929,23 @@ const appActions = { tabId, detail }) + }, + + /** + * Action triggered by navigation handler + * @param partition {string} session partition + * @param protocol {string} navigator protocol + * @param location {string} location where handler was triggered + * @param register {boolean} true if event was registered or false if unregistered + */ + navigatorHandler: function (partition, protocol, location, register) { + AppDispatcher.dispatch({ + actionType: appConstants.APP_NAVIGATOR_HANDLER_UPDATE, + partition, + protocol, + location, + register + }) } } diff --git a/js/components/frame.js b/js/components/frame.js index 24cbc87c249..79320fee802 100644 --- a/js/components/frame.js +++ b/js/components/frame.js @@ -91,9 +91,6 @@ class Frame extends ImmutableComponent { updateAboutDetails (prevProps) { let location = getBaseUrl(this.props.location) if (location === 'about:preferences' || location === 'about:contributions' || location === aboutUrls.get('about:contributions')) { - if (prevProps.partition !== this.props.partition) { - ipc.send(messages.CHECK_BITCOIN_HANDLER, this.props.partition) - } if (!Immutable.is(prevProps.ledgerInfo, this.props.ledgerInfo) || !Immutable.is(prevProps.publisherInfo, this.props.publisherInfo) || !Immutable.is(prevProps.preferencesData, this.props.preferencesData)) { diff --git a/js/constants/appConstants.js b/js/constants/appConstants.js index 713dd534b5a..fddeae95efc 100644 --- a/js/constants/appConstants.js +++ b/js/constants/appConstants.js @@ -94,7 +94,8 @@ const appConstants = { APP_ADD_NOSCRIPT_EXCEPTIONS: _, APP_TAB_MESSAGE_BOX_SHOWN: _, APP_TAB_MESSAGE_BOX_DISMISSED: _, - APP_TAB_MESSAGE_BOX_UPDATED: _ + APP_TAB_MESSAGE_BOX_UPDATED: _, + APP_NAVIGATOR_HANDLER_UPDATE: _ } module.exports = mapValuesByKeys(appConstants) From 24273c26c9d17e53a140430a94e358b12a22225d Mon Sep 17 00:00:00 2001 From: Brian Clifton Date: Thu, 2 Mar 2017 14:36:12 -0700 Subject: [PATCH 2/2] Fix for unit test; I unintentionally had broke this after localizing alert buttons --- test/unit/app/renderer/components/messageBoxTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/app/renderer/components/messageBoxTest.js b/test/unit/app/renderer/components/messageBoxTest.js index b14091bd4dc..2d071626755 100644 --- a/test/unit/app/renderer/components/messageBoxTest.js +++ b/test/unit/app/renderer/components/messageBoxTest.js @@ -150,7 +150,7 @@ describe('MessageBox component unit tests', function () { /> ) const instance = wrapper.instance() - assert.deepEqual(instance.buttons.toJS(), ['OK']) + assert.deepEqual(instance.buttons.toJS(), ['ok']) }) })