Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Re-create webview when contentScripts change
Browse files Browse the repository at this point in the history
Fix #666

Auditors: @diracdeltas
  • Loading branch information
bbondy committed Feb 9, 2016
1 parent 545c7a6 commit 446dfe8
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,27 @@ class Frame extends ImmutableComponent {
if (isAboutURL) {
src = getTargetAboutUrl(src)
}
let contentScripts = ['content/webviewPreload.js']
if (this.props.frame.get('location') === 'about:preferences') {
contentScripts.push('content/aboutPreload.js')
}
contentScripts = contentScripts.join(',')

const contentScriptsChanged =
this.webview && contentScripts !== this.webview.getAttribute('contentScripts')

// Create the webview dynamically because React doesn't whitelist all
// of the attributes we need.
this.webview = this.webview || document.createElement('webview')
// of the attributes we need. Clear out old webviews if the contentScripts
// change because they cannot change after being added to the DOM.
if (contentScriptsChanged) {
while (this.webviewContainer.firstChild) {
this.webviewContainer.removeChild(this.webviewContainer.firstChild)
}
}
this.webview = !contentScriptsChanged && this.webview || document.createElement('webview')
this.webview.setAttribute('allowDisplayingInsecureContent', true)
this.webview.setAttribute('data-frame-key', this.props.frame.get('key'))
const preloadScripts = ['content/webviewPreload.js']
if (this.props.frame.get('location') === 'about:preferences') {
preloadScripts.push('content/aboutPreload.js')
}
this.webview.setAttribute('contentScripts', preloadScripts.join(','))
this.webview.setAttribute('contentScripts', contentScripts)
if (this.props.frame.get('isPrivate')) {
this.webview.setAttribute('partition', 'private-1')
} else if (this.props.frame.get('partitionNumber')) {
Expand All @@ -48,7 +58,6 @@ class Frame extends ImmutableComponent {
if (this.props.frame.get('guestInstanceId')) {
this.webview.setAttribute('data-guest-instance-id', this.props.frame.get('guestInstanceId'))
}

this.webview.setAttribute('src', src)
if (!this.webviewContainer.firstChild) {
this.webviewContainer.appendChild(this.webview)
Expand Down Expand Up @@ -269,10 +278,6 @@ class Frame extends ImmutableComponent {
this.webview.send(messages.SET_AD_DIV_CANDIDATES, adDivCandidates, Config.vault.replacementUrl)
}

get isPrivileged () {
return isSourceAboutUrl(this.props.frame.get('src'))
}

goBack () {
this.webview.goBack()
}
Expand Down

1 comment on commit 446dfe8

@diracdeltas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Please sign in to comment.