aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
authorStephen Blott2014-12-29 17:28:37 +0000
committerStephen Blott2014-12-29 17:28:37 +0000
commitf7541ed966859ae893600f5cfd17a1965efd0822 (patch)
tree386ac078c3d08c2dba9c6b0a11b49cf0063ed382 /content_scripts
parent6c1bbf0ab5781951364464c5fa68ad22f74c9fee (diff)
parent7499675455941251eaa69c93e7c66bfb1c6ae35c (diff)
downloadvimium-f7541ed966859ae893600f5cfd17a1965efd0822.tar.bz2
Merge branch 'smblott-uicomponent-iframe' into post-1.46-with-uicomponent-iframe
Conflicts: content_scripts/vimium_frontend.coffee manifest.json
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/ui_component.coffee52
-rw-r--r--content_scripts/vimium_frontend.coffee1
2 files changed, 52 insertions, 1 deletions
diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee
new file mode 100644
index 00000000..d89f0cc8
--- /dev/null
+++ b/content_scripts/ui_component.coffee
@@ -0,0 +1,52 @@
+class UIComponent
+ iframeElement: null
+ iframePort: null
+ showing: null
+ showStyle: "display: block;"
+ hideStyle: "display: none;"
+
+ constructor: (iframeUrl, className, @handleMessage) ->
+ @iframeElement = document.createElement "iframe"
+ @iframeElement.className = className
+ @iframeElement.seamless = "seamless"
+ @iframeElement.src = chrome.runtime.getURL iframeUrl
+ @iframeElement.addEventListener "load", => @openPort()
+ document.documentElement.appendChild @iframeElement
+ @showing = true # The iframe is visible now.
+ # Hide the iframe, but don't interfere with the focus.
+ @hide false
+
+ # Open a port and pass it to the iframe via window.postMessage.
+ openPort: ->
+ messageChannel = new MessageChannel()
+ @iframePort = messageChannel.port1
+ @iframePort.onmessage = (event) => @handleMessage event
+
+ # Get vimiumSecret so the iframe can determine that our message isn't the page impersonating us.
+ chrome.storage.local.get "vimiumSecret", ({vimiumSecret: secret}) =>
+ @iframeElement.contentWindow.postMessage secret, chrome.runtime.getURL(""), [messageChannel.port2]
+
+ postMessage: (message) ->
+ @iframePort.postMessage message
+
+ activate: (message) ->
+ @postMessage message if message?
+ if @showing
+ # NOTE(smblott) Experimental. Not sure this is a great idea. If the iframe was already showing, then
+ # the user gets no visual feedback when it is re-focused. So flash its border.
+ borderWas = @iframeElement.style.border
+ @iframeElement.style.border = '5px solid yellow'
+ setTimeout((=> @iframeElement.style.border = borderWas), 200)
+ else
+ @iframeElement.setAttribute "style", @showStyle
+ @showing = true
+ @iframeElement.focus()
+
+ hide: (focusWindow=true)->
+ if @showing
+ @iframeElement.setAttribute "style", @hideStyle
+ window.focus() if focusWindow
+ @showing = false
+
+root = exports ? window
+root.UIComponent = UIComponent
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 2de08c39..114786e8 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -198,7 +198,6 @@ window.addEventListener "focus", ->
#
initializeOnDomReady = ->
enterInsertModeIfElementIsFocused() if isEnabledForUrl
-
# Tell the background page we're in the dom ready state.
chrome.runtime.connect({ name: "domReady" })
CursorHider.init()