From ca4ae1c7374304c872a4f38f670aa590e45150ff Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Thu, 12 Jan 2012 20:55:39 +0000 Subject: Bring back download functionality using WebKit This brings back the download functionality to Browse using WebKit, it handles the cases when you click on a link and the Browser is not setup to view this file. Requesting a download through Palettes is still to come. The code is inspired by the download code in Surf. Signed-off-by: Simon Schampijer --- (limited to 'browser.py') diff --git a/browser.py b/browser.py index 2d65237..83cc7ea 100644 --- a/browser.py +++ b/browser.py @@ -35,6 +35,7 @@ from sugar3.graphics.icon import Icon from widgets import BrowserNotebook import globalhistory +import downloadmanager _ZOOM_AMOUNT = 0.1 _LIBRARY_PATH = '/usr/share/library-common/index.html' @@ -389,6 +390,9 @@ class Browser(WebKit.WebView): self._global_history = globalhistory.get_global_history() self.connect('notify::load-status', self.__load_status_changed_cb) self.connect('notify::title', self.__title_changed_cb) + self.connect('download-requested', self.__download_requested_cb) + self.connect('mime-type-policy-decision-requested', + self.__mime_type_policy_cb) def get_history(self): """Return the browsing history of this browser.""" @@ -478,6 +482,16 @@ class Browser(WebKit.WebView): title = unicode(title, 'utf-8') self._global_history.set_page_title(uri, title) + def __mime_type_policy_cb(self, webview, frame, request, mimetype, + policy_decision): + if not self.can_show_mime_type(mimetype): + policy_decision.download() + return True + + def __download_requested_cb(self, browser, download): + downloadmanager.add_download(download, browser) + return True + class PopupDialog(Gtk.Window): def __init__(self): -- cgit v0.9.1