aboutsummaryrefslogtreecommitdiffstats
path: root/pages/ui_component_server.coffee
diff options
context:
space:
mode:
authorStephen Blott2016-04-15 16:51:18 +0100
committerStephen Blott2016-04-16 14:15:33 +0100
commit5bfe6dc5d1e0aeb1ab3e372821997d83ba5c9164 (patch)
tree174c58b552cc0b869764d2dd28f14bb3f010ef2c /pages/ui_component_server.coffee
parent014f53fb091ac8672d3efbeca13a494c15d8afcb (diff)
downloadvimium-5bfe6dc5d1e0aeb1ab3e372821997d83ba5c9164.tar.bz2
Rework UI component focus handling.
The code to handle the focus for UI components has been tweaked and adapted over time, and has become quite complicated (and brittle). This reworks it from scratch, and co-locates similar code which does related things. Fixes #2099.
Diffstat (limited to 'pages/ui_component_server.coffee')
-rw-r--r--pages/ui_component_server.coffee13
1 files changed, 9 insertions, 4 deletions
diff --git a/pages/ui_component_server.coffee b/pages/ui_component_server.coffee
index 4210a60e..9f72dd92 100644
--- a/pages/ui_component_server.coffee
+++ b/pages/ui_component_server.coffee
@@ -2,14 +2,12 @@
# Fetch the Vimium secret, register the port received from the parent window, and stop listening for messages
# on the window object. vimiumSecret is accessible only within the current instance of Vimium. So a
# malicious host page trying to register its own port can do no better than guessing.
-registerPort = (event) ->
+window.addEventListener "message", registerPort = (event) ->
chrome.storage.local.get "vimiumSecret", ({vimiumSecret: secret}) ->
return unless event.source == window.parent and event.data == secret
UIComponentServer.portOpen event.ports[0]
window.removeEventListener "message", registerPort
-window.addEventListener "message", registerPort
-
UIComponentServer =
ownerPagePort: null
handleMessage: null
@@ -23,6 +21,9 @@ UIComponentServer =
postMessage: (message) ->
@ownerPagePort?.postMessage message
+ hide: ->
+ @postMessage "hide"
+
# We require both that the DOM is ready and that the port has been opened before the UI component is ready.
# These events can happen in either order. We count them, and notify the content script when we've seen
# both.
@@ -34,7 +35,11 @@ UIComponentServer =
else
1
- -> @postMessage "uiComponentIsReady" if ++uiComponentIsReadyCount == 2
+ ->
+ if ++uiComponentIsReadyCount == 2
+ @postMessage {name: "setIframeFrameId", iframeFrameId: window.frameId} if window.frameId?
+ @postMessage "uiComponentIsReady"
root = exports ? window
root.UIComponentServer = UIComponentServer
+root.isVimiumUIComponent = true