it's 3.31.3 release day, upload a tarball and show that our software is more stable than this table 彡┻━┻

Commit 161d49d1 authored by Cédric Bellegarde's avatar Cédric Bellegarde

Rework per URI settings since profiles are not needed anymore

parent ca3d8319
Pipeline #37651 passed with stage
in 10 minutes and 43 seconds
......@@ -55,10 +55,6 @@ class ToolbarActions(Gtk.Bin):
Click next
"""
webview = self.__window.container.current.webview
back_list = webview.get_back_forward_list().get_back_list()
if back_list:
uri = back_list[0].get_uri()
webview.update_settings_for_uri(uri)
webview.go_back()
def forward(self):
......@@ -66,10 +62,6 @@ class ToolbarActions(Gtk.Bin):
Click previous
"""
webview = self.__window.container.current.webview
forward_list = webview.get_back_forward_list().get_forward_list()
if forward_list:
uri = forward_list[0].get_uri()
webview.update_settings_for_uri(uri)
webview.go_forward()
@property
......
......@@ -460,6 +460,7 @@ class WebView(WebKit2.WebView):
self.__selection = ""
self._readable = False
self.__uri = None
self._initial_uri = None
self._title = None
self.__related_view = related_view
self._shown = False
......
......@@ -32,7 +32,6 @@ class WebViewArtwork:
self.__cancellable = Gio.Cancellable()
self.__snapshot_id = None
self.__cancellable = Gio.Cancellable()
self.__initial_uri = None
self.__favicon_db = self.context.get_favicon_database()
self.__favicon_db.connect("favicon-changed", self.__on_favicon_changed)
self.connect("notify::uri", self.__on_uri_changed)
......@@ -50,7 +49,7 @@ class WebViewArtwork:
self.__cancellable,
self.__on_get_favicon,
self.uri,
self.__initial_uri)
self._initial_uri)
def set_current_favicon(self):
"""
......@@ -78,16 +77,11 @@ class WebViewArtwork:
@param event as WebKit2.LoadEvent
"""
if event == WebKit2.LoadEvent.STARTED:
parsed = urlparse(self.uri)
self.__cancellable.cancel()
self.__cancellable.reset()
if self.__snapshot_id is not None:
GLib.source_remove(self.__snapshot_id)
self.__snapshot_id = None
if parsed.scheme in ["http", "https"]:
self.__initial_uri = self.uri.rstrip('/')
else:
self.__initial_uri = None
elif event == WebKit2.LoadEvent.FINISHED:
if self.__snapshot_id is not None:
GLib.source_remove(self.__snapshot_id)
......@@ -107,7 +101,7 @@ class WebViewArtwork:
parsed = urlparse(self.uri)
save = parsed.scheme in ["http", "https"]
bookmark_id = App().bookmarks.get_id(self.uri)
ibookmark_id = App().bookmarks.get_id(self.__initial_uri)
ibookmark_id = App().bookmarks.get_id(self._initial_uri)
if bookmark_id is None and ibookmark_id is None:
save = False
self.get_snapshot(WebKit2.SnapshotRegion.FULL_DOCUMENT,
......@@ -173,7 +167,6 @@ class WebViewArtwork:
@param param as GObject.ParamSpec
"""
if not webview.is_loading() and not webview.ephemeral:
self.__initial_uri = None
if self.__snapshot_id is not None:
GLib.source_remove(self.__snapshot_id)
self.__snapshot_id = GLib.timeout_add(2500,
......@@ -205,7 +198,7 @@ class WebViewArtwork:
None,
self.__on_get_favicon,
uri,
self.__initial_uri,
self._initial_uri,
False)
def __on_favicon_changed(self, favicon_db, uri, *ignore):
......@@ -220,7 +213,7 @@ class WebViewArtwork:
None,
self.__on_get_favicon,
uri,
self.__initial_uri)
self._initial_uri)
def __on_snapshot(self, surface, save, first_pass):
"""
......@@ -249,9 +242,9 @@ class WebViewArtwork:
uri = self.uri
# We also cache initial URI
uris = [uri.rstrip("/")]
if self.__initial_uri is not None and\
self.__initial_uri not in uris:
uris.append(self.__initial_uri)
if self._initial_uri is not None and\
self._initial_uri not in uris:
uris.append(self._initial_uri)
for uri in uris:
exists = App().art.exists(uri, "start")
if not exists:
......
......@@ -95,45 +95,6 @@ class WebViewNavigation:
self.stop_loading()
GLib.idle_add(WebKit2.WebView.load_uri, self, uri)
def update_settings_for_uri(self, uri):
"""
Update internal settings for URI
@param uri as str
"""
parsed = urlparse(uri)
http_scheme = parsed.scheme in ["http", "https"]
App().history.set_page_state(uri)
# self.__switch_profile(uri)
self.__update_bookmark_metadata(uri)
self.content_manager.remove_all_style_sheets()
# Can't find a way to block content for ephemeral views
if App().settings.get_value("adblock") and\
not App().adblock_exceptions.find_parsed(parsed) and\
http_scheme and\
self.content_manager is not None:
self.content_manager.add_style_sheet(
App().default_style_sheet)
rules = App().adblock.get_css_rules(uri)
user_style_sheet = WebKit2.UserStyleSheet(
rules,
WebKit2.UserContentInjectedFrames.ALL_FRAMES,
WebKit2.UserStyleLevel.USER,
None,
None)
self.content_manager.add_style_sheet(user_style_sheet)
user_agent = App().websettings.get_user_agent(uri)
settings = self.get_settings()
if user_agent:
settings.set_user_agent(user_agent)
else:
settings.set_user_agent_with_application_details("Eolie",
None)
# Setup image blocker
block_image = http_scheme and\
App().settings.get_value("imageblock") and\
not App().image_exceptions.find_parsed(parsed)
self.set_setting("auto-load-images", not block_image)
@property
def profile(self):
"""
......@@ -154,8 +115,14 @@ class WebViewNavigation:
parsed = urlparse(self.uri)
if event == WebKit2.LoadEvent.STARTED:
self.emit("uri-changed", self.uri)
if parsed.scheme in ["http", "https"]:
self._initial_uri = self.uri.rstrip('/')
else:
self._initial_uri = None
self.__update_bookmark_metadata(self.uri)
elif event == WebKit2.LoadEvent.REDIRECTED:
# Block ads
self.__update_bookmark_metadata(self.uri)
# Block ads, useful for some site
if App().settings.get_value("adblock") and\
webview.__related_view is not None and\
parsed.scheme in ["http", "https"] and\
......@@ -170,6 +137,11 @@ class WebViewNavigation:
return
elif event == WebKit2.LoadEvent.COMMITTED:
self.emit("uri-changed", self.uri)
App().history.set_page_state(self.uri)
if self._initial_uri != self.uri:
self.__update_bookmark_metadata(self.uri)
self.__set_imgblock(self.uri)
self.__set_adblock(self.uri)
self.update_zoom_level()
elif event == WebKit2.LoadEvent.FINISHED:
self.update_spell_checking(self.uri)
......@@ -232,6 +204,56 @@ class WebViewNavigation:
path,
WebKit2.CookiePersistentStorage.SQLITE)
def __set_adblock(self, uri):
"""
Set adblocker
@param uri as str
"""
parsed = urlparse(uri)
http_scheme = parsed.scheme in ["http", "https"]
self.content_manager.remove_all_style_sheets()
# Can't find a way to block content for ephemeral views
if App().settings.get_value("adblock") and\
not App().adblock_exceptions.find_parsed(parsed) and\
http_scheme and\
self.content_manager is not None:
self.content_manager.add_style_sheet(
App().default_style_sheet)
rules = App().adblock.get_css_rules(uri)
user_style_sheet = WebKit2.UserStyleSheet(
rules,
WebKit2.UserContentInjectedFrames.ALL_FRAMES,
WebKit2.UserStyleLevel.USER,
None,
None)
self.content_manager.add_style_sheet(user_style_sheet)
def __set_user_agent(self, uri):
"""
Set user agent for uri
@param uri as str
"""
user_agent = App().websettings.get_user_agent(uri)
settings = self.get_settings()
if user_agent:
settings.set_user_agent(user_agent)
else:
settings.set_user_agent_with_application_details("Eolie",
None)
def __set_imgblock(self, uri):
"""
Set image blocker for uri
@param uri as str
"""
parsed = urlparse(uri)
http_scheme = parsed.scheme in ["http", "https"]
# Setup image blocker
block_image = http_scheme and\
App().settings.get_value("imageblock") and\
not App().image_exceptions.find_parsed(parsed)
self.set_setting("auto-load-images", not block_image)
def __on_run_as_modal(self, webview):
Logger.info("WebView::__on_run_as_modal(): TODO")
......@@ -267,6 +289,7 @@ class WebViewNavigation:
"""
# Js update
if not self.is_loading():
self._initial_uri = None
uri = webview.get_property(param.name)
# JS bookmark (Bookmarklet)
if not uri.startswith("javascript:") and not self.error:
......@@ -354,7 +377,7 @@ class WebViewNavigation:
return True
else:
self.discard_error()
self.update_settings_for_uri(navigation_uri)
self.__set_user_agent(navigation_uri)
decision.use()
return False
elif mouse_button == 1:
......@@ -379,7 +402,7 @@ class WebViewNavigation:
decision.ignore()
return True
else:
self.update_settings_for_uri(navigation_uri)
self.__set_user_agent(navigation_uri)
self.discard_error()
decision.use()
return False
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment