diff options
-rw-r--r-- | bookmarklets.py | 3 | ||||
-rw-r--r-- | downloadmanager.py | 5 | ||||
-rw-r--r-- | ssb.py | 2 | ||||
-rw-r--r-- | usercode.py | 44 |
4 files changed, 30 insertions, 24 deletions
diff --git a/bookmarklets.py b/bookmarklets.py index e4178f4..006272f 100644 --- a/bookmarklets.py +++ b/bookmarklets.py @@ -72,7 +72,8 @@ class BookmarkletStore(gobject.GObject): def get(self, name): return self._config.get(name, 'url') - def add(self, name, url): + def add(self, name, url): + logging.debug('web-activity: Adding bookmarklet') if not self._config.has_section(name): self._config.add_section(name) self._config.set(name, 'url', url) diff --git a/downloadmanager.py b/downloadmanager.py index d55b2c4..5e5c325 100644 --- a/downloadmanager.py +++ b/downloadmanager.py @@ -250,6 +250,8 @@ class Download: def _get_file_name(self): if self._display_name: return self._display_name + elif self._source.scheme == 'data': + return 'data URI' else: path = urlparse.urlparse(self._source.spec).path location, file_name = os.path.split(path) @@ -309,6 +311,8 @@ def save_link(url, text, owner_document): interfaces.nsIRequest.LOAD_BYPASS_CACHE | \ interfaces.nsIChannel.LOAD_CALL_CONTENT_SNIFFERS + # HACK: when we QI for nsIHttpChannel on objects that implement + # just nsIChannel, pyxpcom gets confused. see trac #1029 if uri.scheme == 'http': if _implements_interface(channel, interfaces.nsIHttpChannel): channel.referrer = io_service.newURI(owner_document.documentURI, @@ -318,7 +322,6 @@ def save_link(url, text, owner_document): listener = xpcom.server.WrapObject( _SaveLinkProgressListener(owner_document), interfaces.nsIStreamListener) - channel.asyncOpen(listener, None) def _implements_interface(obj, interface): @@ -148,7 +148,7 @@ class SSBCreator(object): shutil.copytree(self.data_path, ssb_data_path) # delete undesirable things from the profile - remove_paths(['Cache', 'cookies.sqlite'], + remove_paths(['Cache', 'cookies.sqlite', 'Google Gears for Firefox'], root=os.path.join(ssb_data_path, 'gecko')) # create MANIFEST diff --git a/usercode.py b/usercode.py index 7a77b40..80cf7f7 100644 --- a/usercode.py +++ b/usercode.py @@ -197,36 +197,37 @@ class ScriptEditor(Dialog): self._editor.file_path = self._fileview.get_selected_file() def add_script(location): - cls = components.classes["@mozilla.org/network/io-service;1"] - io_service = cls.getService(interfaces.nsIIOService) - + '''Inspired by https://developer.mozilla.org/en/nsIWebBrowserPersist''' + cls = components.classes[ \ '@mozilla.org/embedding/browser/nsWebBrowserPersist;1'] - browser_persist = cls.getService(interfaces.nsIWebBrowserPersist) - + browser_persist = cls.createInstance(interfaces.nsIWebBrowserPersist) + browser_persist.persistFlags = interfaces.nsIWebBrowserPersist \ + .PERSIST_FLAGS_REPLACE_EXISTING_FILES + cls = components.classes["@mozilla.org/network/io-service;1"] + io_service = cls.getService(interfaces.nsIIOService) location_uri = io_service.newURI(location, None, None) - + + cls = components.classes["@mozilla.org/file/local;1"] + local_file = cls.createInstance(interfaces.nsILocalFile) + file_name = os.path.basename(location_uri.path) file_path = os.path.join(SCRIPTS_PATH, file_name) - file_uri = io_service.newURI('file://'+file_path, None, None) + local_file.initWithPath(file_path) + if not local_file.exists(): + local_file.create(0x00, 0644) - logging.debug('##### %s -> %s' % (location_uri.spec, file_uri.spec)) - - # make sure the file doesn't already exist - try: os.remove(file_path) - except OSError: pass + logging.debug('Saving userscript %s -> %s' % \ + (location_uri.spec, file_path)) - browser_persist.saveURI(location_uri, None, None, None, None, file_uri) + browser_persist.saveURI(location_uri, None, None, None, None, local_file) def script_exists(location): script_name = os.path.basename(urlparse(location).path) - - if os.path.isfile(os.path.join(SCRIPTS_PATH, script_name)): - return True - else: - return False - + + return os.path.isfile(os.path.join(SCRIPTS_PATH, script_name)) + def save_document(browser): cls = components.classes["@mozilla.org/network/io-service;1"] io_service = cls.getService(interfaces.nsIIOService) @@ -261,8 +262,9 @@ class Injector(): # set up the script element to be injected self.script = window.document.createElement('script') self.script.type = 'text/javascript' - # working around XSS security - text = open(self.script_path,'r').read() + + # work around XSS security + text = str(open(self.script_path,'r').read()) self.script.appendChild( window.document.createTextNode(text) ) # reference to head |