Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLucian Branescu Mihaila <lucian.branescu@gmail.com>2009-07-29 16:46:26 (GMT)
committer Lucian Branescu Mihaila <lucian.branescu@gmail.com>2009-07-29 16:46:44 (GMT)
commita8c8fd55008d38e8a46430d833bb71ae366bd1ca (patch)
tree0acbff2a7b9d5e63dd53b25332224070b6618ea7
parentf3208fad41a7dbbb027d696b8c0a1db6d3bb0800 (diff)
Replace data URI download hack with another, smaller hack. trac #1029
-rw-r--r--downloadmanager.py59
-rw-r--r--palettes.py2
-rw-r--r--usercode.py6
3 files changed, 9 insertions, 58 deletions
diff --git a/downloadmanager.py b/downloadmanager.py
index d580d55..d55b2c4 100644
--- a/downloadmanager.py
+++ b/downloadmanager.py
@@ -295,16 +295,11 @@ components.registrar.registerFactory('{23c51569-e9a1-4a92-adeb-3723db82ef7c}',
def save_link(url, text, owner_document):
# Inspired on Firefox' browser/base/content/nsContextMenu.js:saveLink()
- # HACK, workaround for ticket #1029
- if url.startswith('data:'):
- save_data_uri(url, text, owner_document)
- return
-
cls = components.classes["@mozilla.org/network/io-service;1"]
io_service = cls.getService(interfaces.nsIIOService)
uri = io_service.newURI(url, None, None)
channel = io_service.newChannelFromURI(uri)
-
+
auth_prompt_callback = xpcom.server.WrapObject(
_AuthPromptCallback(owner_document.defaultView),
interfaces.nsIInterfaceRequestor)
@@ -314,58 +309,18 @@ def save_link(url, text, owner_document):
interfaces.nsIRequest.LOAD_BYPASS_CACHE | \
interfaces.nsIChannel.LOAD_CALL_CONTENT_SNIFFERS
- if _implements_interface(channel, interfaces.nsIHttpChannel):
- channel.referrer = io_service.newURI(owner_document.documentURI, None,
- None)
+ if uri.scheme == 'http':
+ if _implements_interface(channel, interfaces.nsIHttpChannel):
+ channel.referrer = io_service.newURI(owner_document.documentURI,
+ None, None)
# kick off the channel with our proxy object as the listener
listener = xpcom.server.WrapObject(
_SaveLinkProgressListener(owner_document),
interfaces.nsIStreamListener)
+
channel.asyncOpen(listener, None)
-def save_data_uri(url, text, owner_document):
- '''Special case, workaround for ticket #1029'''
- import base64
- import re
-
- pattern = re.compile(r'''
- ^data:
- (\w+/\w+)? # mimetype
- (?:;charset="(\w+)")? # charset
- (?:;(base64))? # encoding
- ,(.+) # actual data
- $
- ''', re.VERBOSE)
- result = re.search(pattern, url).groups()
- logging.debug('^^^^^ %s' % str(result))
-
- mime = result[0] or 'text/plain'
- charset = result[1] or 'US-ASCII'
- encoding = result[2] or 'base64'
- data = base64.decodestring(result[3])
-
- temp_path = os.path.join(activity.get_activity_root(), 'instance')
- if not os.path.exists(temp_path):
- os.makedirs(temp_path)
- fd, file_path = tempfile.mkstemp(dir=temp_path, prefix='datauri',
- suffix='')
- os.close(fd)
- os.chmod(file_path, 0644)
-
- # write data to file
- open(file_path, 'w').write(data)
-
- jobject = datastore.create()
- jobject.metadata['title'] = 'datauri'
- jobject.metadata['mime_type'] = mime
- jobject.metadata['icon-color'] = profile.get_color().to_string()
- jobject.file_path = file_path
-
- datastore.write(jobject)
- activity.show_object_in_journal(jobject.object_id)
-
-
def _implements_interface(obj, interface):
try:
obj.QueryInterface(interface)
@@ -412,7 +367,7 @@ class _SaveLinkProgressListener(object):
external_helper = cls.getService(
interfaces.nsIExternalHelperAppService)
- channel = request.QueryInterface(interfaces.nsIHttpChannel)
+ channel = request.QueryInterface(interfaces.nsIChannel)
self._external_listener = \
external_helper.doContent(channel.contentType, request,
diff --git a/palettes.py b/palettes.py
index c86d8dd..79c27ca 100644
--- a/palettes.py
+++ b/palettes.py
@@ -108,7 +108,7 @@ class LinkPalette(Palette):
menu_item.show()
if url.startswith('javascript:'):
- # only show in an ssb, if the link is a bookmarklet
+ # only show if the link is a bookmarklet
menu_item = MenuItem(_('Save bookmarklet'))
menu_item.connect('activate', self.__bookmarklet_activate_cb)
self.menu.append(menu_item)
diff --git a/usercode.py b/usercode.py
index e62b339..7a77b40 100644
--- a/usercode.py
+++ b/usercode.py
@@ -255,16 +255,13 @@ class Injector():
interfaces.nsIDOMEventListener)
def handleEvent(self, event):
- logging.debug('***** finish inject')
- logging.debug('***** %s' % self.head.innerHTML)
self.head.appendChild(self.script)
def attach_to(self, window):
- logging.debug('***** starting inject')
# set up the script element to be injected
self.script = window.document.createElement('script')
self.script.type = 'text/javascript'
- #self.script.src = 'file://' + self.script_path # XSS security fail
+ # working around XSS security
text = open(self.script_path,'r').read()
self.script.appendChild( window.document.createTextNode(text) )
@@ -273,7 +270,6 @@ class Injector():
# actual attaching
window.addEventListener('load', self._wrapped, False)
- logging.debug('***** injecting ...')
class ScriptListener(gobject.GObject):