Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Commit

Permalink
fix typo in attach.js, add onLoad, onUnmount, onMount lifecycle metho…
Browse files Browse the repository at this point in the history
…ds (#1)

* fix typo in attach.js, add onLoad, onUnmount, onMount lifecycle methods

* remove additional whitespace
  • Loading branch information
hanford authored and fouad committed May 15, 2017
1 parent ed8bbe4 commit afa99f0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/attach.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export function attachHeadersListener({
webRequest,
hosts,
iframeHosts,
dangerouslyOverrideFrameOptions
overrideFrameOptions
}) {
if (typeof hosts !== 'string') {
if (hosts) {
Expand All @@ -23,7 +23,7 @@ export function attachHeadersListener({

const types = ['main_frame']

if (dangerouslyOverrideFrameOptions) {
if (overrideFrameOptions) {
types.push('sub_frame')
}

Expand All @@ -40,12 +40,12 @@ export function attachHeadersListener({
csp = csp.replace('frame-src', `frame-src ${iframeHosts}`)
csp = csp.replace('child-src', `child-src ${hosts}`)

if (dangerouslyOverrideFrameOptions) {
if (overrideFrameOptions) {
csp = csp.replace(/frame-ancestors (.*?);/ig, '')
}

header.value = csp
} else if (isFrameHeader && dangerouslyOverrideFrameOptions) {
} else if (isFrameHeader && overrideFrameOptions) {
header.value = 'ALLOWALL'
}

Expand Down
38 changes: 34 additions & 4 deletions src/frame.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from 'react'
import cx from 'classnames'
import { css } from 'glamor'
import { node, object, string, number } from 'prop-types'
import { node, object, string, number, func } from 'prop-types'

const iframeClass = css({
border: 'none',
Expand Down Expand Up @@ -84,6 +84,7 @@ export class Frame extends Component {
})}
style={maskStyle}
onClick={this.onMaskClick}
ref={mask => this.mask = mask}
/>

<div
Expand All @@ -103,6 +104,8 @@ export class Frame extends Component {
})}
style={iframeStyle}
src={url}
ref={frame => this.frame = frame}
onLoad={this.onLoad}
/>

{containerChildren}
Expand All @@ -126,7 +129,10 @@ export class Frame extends Component {
containerClassName: '',
containerStyle: {},
iframeClassName: '',
iframeStyle: {}
iframeStyle: {},
onMount: () => {},
onUnmount: () => {},
onLoad: () => {}
}

static propTypes = {
Expand All @@ -139,14 +145,22 @@ export class Frame extends Component {
iframeClassName: string,
iframeStyle: object,
children: node,
containerChildren: node
containerChildren: node,
onMount: func,
onUnmount: func,
onLoad: func
}

componentDidMount() {
const { delay } = this.props
const { delay, onMount } = this.props

window[FRAME_TOGGLE_FUNCTION] = this.toggleFrame

onMount({
mask: this.mask,
frame: this.frame
})

this._visibleRenderTimeout = setTimeout(() => {
this.setState({
isVisible: true
Expand All @@ -155,10 +169,26 @@ export class Frame extends Component {
}

componentWillUnmount() {
const { onUnmount } = this.props

onUnmount({
mask: this.mask,
frame: this.frame
})

delete window[FRAME_TOGGLE_FUNCTION]
clearTimeout(this._visibleRenderTimeout)
}

onLoad = () => {
const { onLoad } = this.props

onLoad({
mask: this.mask,
frame: this.frame
})
}

onMaskClick = () => {
this.setState({
isMinimized: true
Expand Down

0 comments on commit afa99f0

Please sign in to comment.