From 89cf3eb46cf15f41ab2806e42efbeccbcfb6dba3 Mon Sep 17 00:00:00 2001 From: bridiver Date: Mon, 12 Jun 2017 18:12:09 -0700 Subject: [PATCH] =?UTF-8?q?dont=E2=80=99t=20call=20to=20get=20site=20setti?= =?UTF-8?q?ngs=20outside=20of=20mergeProps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/state/tabState.js | 7 ++ app/renderer/components/frame/frame.js | 105 +++++++++++-------------- 2 files changed, 51 insertions(+), 61 deletions(-) diff --git a/app/common/state/tabState.js b/app/common/state/tabState.js index 823f8d956cf..bb54171b2d1 100644 --- a/app/common/state/tabState.js +++ b/app/common/state/tabState.js @@ -630,6 +630,13 @@ const tabState = { return entry ? entry.get('url') : '' }, + getVisibleOrigin: (state, tabId) => { + const entry = tabState.getVisibleEntry(state, tabId) + const origin = entry ? entry.get('origin') : '' + // TODO(bridiver) - all origins in browser-laptop should be changed to have a trailing slash to match chromium + return (origin || '').replace(/\/$/, '') + }, + getVisibleVirtualURL: (state, tabId) => { const entry = tabState.getVisibleEntry(state, tabId) return entry ? entry.get('virtualURL') : '' diff --git a/app/renderer/components/frame/frame.js b/app/renderer/components/frame/frame.js index 4c2c4cbb480..d9abc19fed6 100644 --- a/app/renderer/components/frame/frame.js +++ b/app/renderer/components/frame/frame.js @@ -91,15 +91,6 @@ class Frame extends React.Component { windowActions.closeFrame(this.props.frameKey) } - getFrameBraverySettings (props) { - props = props || this.props - const frameSiteSettings = - siteSettings.getSiteSettingsForURL(props.allSiteSettings, props.location) - return Immutable.fromJS(siteSettings.activeSettings(frameSiteSettings, - appStoreRenderer.state, - appConfig)) - } - isAboutPage () { return aboutUrls.get(getBaseUrl(this.props.location)) } @@ -112,58 +103,44 @@ class Frame extends React.Component { return !this.webview } - runInsecureContent () { - const activeSiteSettings = siteSettings.getSiteSettingsForHostPattern(this.props.allSiteSettings, this.origin) - return activeSiteSettings === undefined - ? false : activeSiteSettings.get('runInsecureContent') - } - allowRunningWidevinePlugin (url) { if (!this.props.isWidevineEnabled) { return false } - const origin = url ? siteUtil.getOrigin(url) : this.origin - if (!origin) { + if (!this.props.origin) { return false } // Check for at least one CtP allowed on this origin if (!this.props.allSiteSettings) { return false } - const activeSiteSettings = siteSettings.getSiteSettingsForHostPattern(this.props.allSiteSettings, origin) - if (activeSiteSettings && typeof activeSiteSettings.get('widevine') === 'number') { + if (typeof this.props.widevine === 'number') { return true } return false } - expireContentSettings (origin) { + expireContentSettings (props) { // Expired Flash settings should be deleted when the webview is // navigated or closed. Same for NoScript's allow-once option. - const activeSiteSettings = siteSettings.getSiteSettingsForHostPattern(this.props.allSiteSettings, origin) - if (!activeSiteSettings) { - return - } - if (typeof activeSiteSettings.get('flash') === 'number') { - if (activeSiteSettings.get('flash') < Date.now()) { - appActions.removeSiteSetting(origin, 'flash', this.props.isPrivate) + if (typeof props.flash === 'number') { + if (props.flash < Date.now()) { + appActions.removeSiteSetting(props.origin, 'flash', props.isPrivate) } } - if (activeSiteSettings.get('widevine') === 0) { - appActions.removeSiteSetting(origin, 'widevine', this.props.isPrivate) + if (props.widevine === 0) { + appActions.removeSiteSetting(props.origin, 'widevine', props.isPrivate) } - if (activeSiteSettings.get('noScript') === 0) { - appActions.removeSiteSetting(origin, 'noScript', this.props.isPrivate) + if (props.noScript === 0) { + appActions.removeSiteSetting(props.origin, 'noScript', props.isPrivate) } - const noScriptExceptions = activeSiteSettings.get('noScriptExceptions') - if (noScriptExceptions) { - appActions.noScriptExceptionsAdded(origin, - noScriptExceptions.map(value => value === 0 ? false : value)) + if (props.noScriptExceptions) { + appActions.noScriptExceptionsAdded(props.origin, props.noScriptExceptions.filter((value, host) => value === 0 ? false : value)) } } componentWillUnmount () { - this.expireContentSettings(this.origin) + this.expireContentSettings(this.props) } updateWebview (cb, prevProps = {}) { @@ -218,7 +195,7 @@ class Frame extends React.Component { get zoomLevel () { const zoom = this.props.siteZoomLevel - appActions.removeSiteSetting(this.origin, 'zoomLevel', this.props.isPrivate) + appActions.removeSiteSetting(this.props.origin, 'zoomLevel', this.props.isPrivate) return zoom } @@ -288,9 +265,8 @@ class Frame extends React.Component { } // For cross-origin navigation, clear temp approvals - const prevOrigin = siteUtil.getOrigin(prevProps.location) - if (this.origin !== prevOrigin) { - this.expireContentSettings(prevOrigin) + if (this.props.origin !== prevProps.origin) { + this.expireContentSettings(prevProps) } this.updateWebview(cb, prevProps) @@ -388,13 +364,15 @@ class Frame extends React.Component { * @param {function=} widevineCallback - Optional callback to run if Widevine is * accepted */ - showWidevineNotification (location, origin, noWidevineCallback, widevineCallback) { + showWidevineNotification (noWidevineCallback, widevineCallback) { // https://www.nfl.com is said to be a widevine site but it actually uses Flash for me Oct 10, 2016 const widevineSites = ['https://www.netflix.com', 'http://bitmovin.com', 'https://www.primevideo.com', 'https://www.spotify.com', 'https://shaka-player-demo.appspot.com'] + const origin = this.props.origin + const location = this.props.location const isForWidevineTest = process.env.NODE_ENV === 'test' && location.endsWith('/drm.html') if (!isForWidevineTest && (!origin || !widevineSites.includes(origin))) { noWidevineCallback() @@ -406,7 +384,7 @@ class Frame extends React.Component { const nonce = Math.random().toString() if (this.props.isWidevineEnabled) { - const message = locale.translation('allowWidevine').replace(/{{\s*origin\s*}}/, this.origin) + const message = locale.translation('allowWidevine').replace(/{{\s*origin\s*}}/, origin) // Show Widevine notification bar appActions.showNotification({ buttons: [ @@ -414,7 +392,7 @@ class Frame extends React.Component { {text: locale.translation('allow')} ], message, - frameOrigin: this.origin, + frameOrigin: origin, options: { nonce, persist: true @@ -423,16 +401,16 @@ class Frame extends React.Component { this.notificationCallbacks[message] = (buttonIndex, persist) => { if (buttonIndex === 1) { if (persist) { - appActions.changeSiteSetting(this.origin, 'widevine', 1) + appActions.changeSiteSetting(origin, 'widevine', 1) } else { - appActions.changeSiteSetting(this.origin, 'widevine', 0) + appActions.changeSiteSetting(origin, 'widevine', 0) } if (widevineCallback) { widevineCallback() } } else { if (persist) { - appActions.changeSiteSetting(this.origin, 'widevine', false) + appActions.changeSiteSetting(origin, 'widevine', false) } } appActions.hideNotification(message) @@ -611,7 +589,7 @@ class Frame extends React.Component { } if (e.isMainFrame && !e.isErrorPage && !e.isFrameSrcDoc) { if (e.url && e.url.startsWith(appConfig.noScript.twitterRedirectUrl) && - this.getFrameBraverySettings(this.props).get('noScript') === true) { + this.props.noScript === true) { // This result will be canceled immediately by sitehacks, so don't // update the load state; otherwise it will not show the security // icon. @@ -628,7 +606,7 @@ class Frame extends React.Component { windowActions.onWebviewLoadEnd(this.frame, url) const parsedUrl = urlParse(url) if (!this.allowRunningWidevinePlugin()) { - this.showWidevineNotification(this.props.location, this.origin, () => { + this.showWidevineNotification(() => { }, () => { appActions.loadURLRequested(this.props.tabId, this.props.provisionalLocation) }) @@ -698,7 +676,7 @@ class Frame extends React.Component { return } let isSecure = null - let runInsecureContent = this.runInsecureContent() + let runInsecureContent = this.props.runInsecureContent if (e.securityState === 'secure') { isSecure = true } else if (e.securityState === 'insecure') { @@ -766,8 +744,8 @@ class Frame extends React.Component { }) this.webview.addEventListener('did-finish-load', (e) => { loadEnd(true, e.validatedURL) - if (this.runInsecureContent()) { - appActions.removeSiteSetting(this.origin, 'runInsecureContent', this.props.isPrivate) + if (this.props.runInsecureContent) { + appActions.removeSiteSetting(this.props.origin, 'runInsecureContent', this.props.isPrivate) } }) this.webview.addEventListener('did-navigate-in-page', (e) => { @@ -839,10 +817,6 @@ class Frame extends React.Component { this.webview.addEventListener('mousewheel', this.onMouseWheel.bind(this)) } - get origin () { - return siteUtil.getOrigin(this.props.location) - } - onFocus () { if (!this.frame.isEmpty()) { windowActions.setTabPageIndexByFrame(this.frame) @@ -885,13 +859,16 @@ class Frame extends React.Component { mergeProps (state, ownProps) { const currentWindow = state.get('currentWindow') const frame = frameStateUtil.getFrameByKey(currentWindow, ownProps.frameKey) || Immutable.Map() + const tabId = frame.get('tabId') + const location = frame.get('location') - const allSiteSettings = siteSettingsState.getAllSiteSettings(state, frame.get('isPrivate')) - const frameSiteSettings = frame.get('location') - ? siteSettings.getSiteSettingsForURL(allSiteSettings, frame.get('location')) - : undefined + const origin = tabState.getVisibleOrigin(state, tabId) + const isPrivate = frame.get('isPrivate', false) + + const allSiteSettings = siteSettingsState.getAllSiteSettings(state, isPrivate) + const frameSiteSettings = siteSettings.getSiteSettingsForURL(allSiteSettings, location) || Immutable.Map() + const contextMenu = currentWindow.get('contextMenuDetail') - const tabId = frame.get('tabId') const tab = tabId && tabId > -1 && tabState.getByTabId(state, tabId) const props = {} @@ -909,6 +886,12 @@ class Frame extends React.Component { // used in other functions props.frameKey = ownProps.frameKey + props.origin = origin + props.runInsecureContent = frameSiteSettings.get('runInsecureContent') + props.noScript = frameSiteSettings.get('noScript') + props.noScriptExceptions = frameSiteSettings.get('noScriptExceptions') + props.widevine = frameSiteSettings.get('widevine') + props.flash = frameSiteSettings.get('flash') props.urlBarFocused = frame && frame.getIn(['navbar', 'urlbar', 'focused']) props.isAutFillContextMenu = contextMenu && contextMenu.get('type') === 'autofill' props.isSecure = frame.getIn(['security', 'isSecure']) @@ -930,7 +913,7 @@ class Frame extends React.Component { props.aboutDetailsErrorCode = frame.getIn(['aboutDetails', 'errorCode']) props.unloaded = frame.get('unloaded') props.isWidevineEnabled = state.get('widevine') && state.getIn(['widevine', 'enabled']) - props.siteZoomLevel = frameSiteSettings && frameSiteSettings.get('zoomLevel') + props.siteZoomLevel = frameSiteSettings.get('zoomLevel') props.allSiteSettings = allSiteSettings // TODO (nejc) can be improved even more props.tabUrl = tab && tab.get('url') props.partitionNumber = frame.get('partitionNumber')