Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
47f19feb
Commit
47f19feb
authored
Apr 21, 2016
by
Robert Knight
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3233 from hypothesis/work-on-file-urls
Fix Hypothesis on local HTML documents
parents
f38c7bbe
1a956785
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
discovery.coffee
h/static/scripts/discovery.coffee
+9
-0
discovery-test.coffee
h/static/scripts/test/discovery-test.coffee
+12
-0
No files found.
h/static/scripts/discovery.coffee
View file @
47f19feb
...
@@ -86,6 +86,15 @@ module.exports = class Discovery
...
@@ -86,6 +86,15 @@ module.exports = class Discovery
_onMessage
:
(
event
)
=>
_onMessage
:
(
event
)
=>
{
source
,
origin
,
data
}
=
event
{
source
,
origin
,
data
}
=
event
# If `origin` is 'null' the source frame is a file URL or loaded over some
# other scheme for which the `origin` is undefined. In this case, the only
# way to ensure the message arrives is to use the wildcard origin. See:
#
# https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
#
if
origin
is
'null'
origin
=
'*'
# Check if the message is at all related to our discovery mechanism
# Check if the message is at all related to our discovery mechanism
match
=
data
.
match
?
/^__cross_frame_dhcp_(discovery|offer|request|ack)(?::(\d+))?$/
match
=
data
.
match
?
/^__cross_frame_dhcp_(discovery|offer|request|ack)(?::(\d+))?$/
return
unless
match
return
unless
match
...
...
h/static/scripts/test/discovery-test.coffee
View file @
47f19feb
...
@@ -74,6 +74,18 @@ describe 'Discovery', ->
...
@@ -74,6 +74,18 @@ describe 'Discovery', ->
matcher
=
sinon
.
match
(
/__cross_frame_dhcp_ack:\d+/
)
matcher
=
sinon
.
match
(
/__cross_frame_dhcp_ack:\d+/
)
assert
.
calledWith
(
fakeTopWindow
.
postMessage
,
matcher
,
'top'
)
assert
.
calledWith
(
fakeTopWindow
.
postMessage
,
matcher
,
'top'
)
it
'sends an "ack" to the wildcard origin if a request comes from a frame with null origin'
,
->
fakeFrameWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_request'
source
:
fakeTopWindow
origin
:
'null'
})
server
.
startDiscovery
(
->
)
assert
.
called
(
fakeTopWindow
.
postMessage
)
matcher
=
sinon
.
match
(
/__cross_frame_dhcp_ack:\d+/
)
assert
.
calledWith
(
fakeTopWindow
.
postMessage
,
matcher
,
'*'
)
it
'calls the discovery callback on receiving "request"'
,
->
it
'calls the discovery callback on receiving "request"'
,
->
fakeFrameWindow
.
addEventListener
.
yields
({
fakeFrameWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_request'
data
:
'__cross_frame_dhcp_request'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment