From acb0c7010d345a3e4918c4aa33eb1d2bf72cf8da Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Wed, 3 Feb 2016 15:23:02 +0000 Subject: Move help dialog into an iframe --- lib/settings.coffee | 4 +++- lib/utils.coffee | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/settings.coffee b/lib/settings.coffee index dd1aa377..c127343d 100644 --- a/lib/settings.coffee +++ b/lib/settings.coffee @@ -18,8 +18,10 @@ Settings = onLoadedCallbacks: [] init: -> - if Utils.isExtensionPage() + if Utils.isExtensionPage() and (try localStorage) # On extension pages, we use localStorage (or a copy of it) as the cache. + # For UIComponents (or other content of ours in an iframe within a regular page), we can't access + # localStorage, so we check for this too. @cache = if Utils.isBackgroundPage() then localStorage else extend {}, localStorage @onLoaded() diff --git a/lib/utils.coffee b/lib/utils.coffee index c255102e..4726739b 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -7,7 +7,7 @@ Utils = isExtensionPage: -> document.location?.origin + "/" == chrome.extension.getURL "" # Returns true whenever the current page is the extension's background page. - isBackgroundPage: -> @isExtensionPage() and chrome.extension.getBackgroundPage() == window + isBackgroundPage: -> @isExtensionPage() and try chrome.extension.getBackgroundPage() == window # Takes a dot-notation object string and call the function # that it points to with the correct value for 'this'. -- cgit v1.2.3 From 2f73ad6c7357c9a7105e99a929991df735efc96e Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Thu, 11 Feb 2016 04:49:13 +0000 Subject: Tidy up detection for the current page and context belonging to us --- lib/settings.coffee | 4 ++-- lib/utils.coffee | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/settings.coffee b/lib/settings.coffee index c127343d..8b7f6062 100644 --- a/lib/settings.coffee +++ b/lib/settings.coffee @@ -18,10 +18,10 @@ Settings = onLoadedCallbacks: [] init: -> - if Utils.isExtensionPage() and (try localStorage) + if Utils.isExtensionPage() and Utils.isExtensionPage window.top # On extension pages, we use localStorage (or a copy of it) as the cache. # For UIComponents (or other content of ours in an iframe within a regular page), we can't access - # localStorage, so we check for this too. + # localStorage, so we check that the top level frame is also an extension page. @cache = if Utils.isBackgroundPage() then localStorage else extend {}, localStorage @onLoaded() diff --git a/lib/utils.coffee b/lib/utils.coffee index 4726739b..50d8c7dd 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -2,12 +2,12 @@ Utils = getCurrentVersion: -> chrome.runtime.getManifest().version - # Returns true whenever the current page is from the extension's origin (and thus can access the - # extension's localStorage). - isExtensionPage: -> document.location?.origin + "/" == chrome.extension.getURL "" + # Returns true whenever the current page (or the page supplied as an argument) is from the extension's + # origin (and thus can access the extension's localStorage). + isExtensionPage: (win = window) -> try win.document.location?.origin + "/" == chrome.extension.getURL "" # Returns true whenever the current page is the extension's background page. - isBackgroundPage: -> @isExtensionPage() and try chrome.extension.getBackgroundPage() == window + isBackgroundPage: -> @isExtensionPage() and chrome.extension.getBackgroundPage?() == window # Takes a dot-notation object string and call the function # that it points to with the correct value for 'this'. -- cgit v1.2.3