diff options
| author | Stephen Blott | 2015-06-05 07:07:02 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-06-05 07:07:04 +0100 | 
| commit | 8eda31fb236b9506d577a25908d4e5334d3289d5 (patch) | |
| tree | 85cfc27b6156d3833c9fd21f7177097a7f6d054e | |
| parent | a143d2c81a9faaf383a05b0dae2f232db85959a2 (diff) | |
| download | vimium-8eda31fb236b9506d577a25908d4e5334d3289d5.tar.bz2 | |
Global marks; global marks are always recorded for the top frame only.
With global marks, we may later create a new tab when the mark is used.
When doing so, we should always be using the URL and scroll position of
the top frame within the tab.  For example, if a global mark is created
from within the Hangouts frame of Google's Inbox and the mark is later
used, then we should create a new tab for Inbox's URL and scroll
position, not for the Hangout's URL and scroll position.
| -rw-r--r-- | background_scripts/marks.coffee | 18 | ||||
| -rw-r--r-- | content_scripts/marks.coffee | 7 | 
2 files changed, 20 insertions, 5 deletions
| diff --git a/background_scripts/marks.coffee b/background_scripts/marks.coffee index 3a5af130..6e5f08ba 100644 --- a/background_scripts/marks.coffee +++ b/background_scripts/marks.coffee @@ -11,15 +11,27 @@ Marks =    # tabId can be considered valid.    create: (req, sender) ->      chrome.storage.local.get "vimiumSecret", (items) => -      item = {} -      item[@getLocationKey req.markName] = +      markInfo =          vimiumSecret: items.vimiumSecret          markName: req.markName          url: @getBaseUrl sender.tab.url          tabId: sender.tab.id          scrollX: req.scrollX          scrollY: req.scrollY -      chrome.storage.sync.set item + +      if markInfo.scrollX? and markInfo.scrollY? +        @saveMark markInfo +      else +        # The front-end frame hasn't provided the scroll position (because it's not the top frame within its +        # tab).  We need to ask the top frame what its scroll position is. (With the frame Id set to 0, below, +        # the request will only be handled by the top frame within the tab.) +        chrome.tabs.sendMessage sender.tab.id, name: "getScrollPosition", frameId: 0, (response) => +          @saveMark extend markInfo, scrollX: response.scrollX, scrollY: response.scrollY + +  saveMark: (markInfo) -> +    item = {} +    item[@getLocationKey markInfo.markName] = markInfo +    chrome.storage.sync.set item    # Goto a global mark.  We try to find the original tab.  If we can't find that, then we try to find another    # tab with the original URL, and use that.  And if we can't find such an existing tab, then we create a new diff --git a/content_scripts/marks.coffee b/content_scripts/marks.coffee index 3b5814da..f569e1ea 100644 --- a/content_scripts/marks.coffee +++ b/content_scripts/marks.coffee @@ -36,11 +36,14 @@ Marks =          # characters.          @exit =>            if event.shiftKey +            # We record the current scroll position, but only if this is the top frame within the tab. +            # Otherwise, we'll fetch the scroll position of the top frame from the background page later. +            [ scrollX, scrollY ] = [ window.scrollX, window.scrollY ] if DomUtils.isTopFrame()              chrome.runtime.sendMessage                handler: 'createMark'                markName: keyChar -              scrollX: window.scrollX -              scrollY: window.scrollY +              scrollX: scrollX +              scrollY: scrollY              , => @showMessage "Created global mark", keyChar            else              localStorage[@getLocationKey keyChar] = @getMarkString() | 
