def __init__(self, activity, window_xid): self.parent_window_xid = window_xid url, title = get_help_url_and_title(activity) has_local_help = url is not None self._mode = _MODE_HELP if has_local_help else _MODE_SOCIAL_HELP Gtk.Window.__init__(self) box = Gtk.Box() box.set_orientation(Gtk.Orientation.VERTICAL) self.add(box) box.show() self.set_decorated(False) self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) self.set_border_width(style.LINE_WIDTH) self.set_has_resize_grip(False) width = Gdk.Screen.width() - style.GRID_CELL_SIZE * 2 height = Gdk.Screen.height() - style.GRID_CELL_SIZE * 2 self.set_size_request(width, height) self.connect('realize', self.__realize_cb) self.connect('hide', self.__hide_cb) self.connect('key-press-event', self.__key_press_event_cb) toolbar = Toolbar(title, has_local_help) box.pack_start(toolbar, False, False, 0) toolbar.show() toolbar.connect('stop-clicked', self.__stop_clicked_cb) toolbar.connect('mode-changed', self.__mode_changed_cb) session = WebKit.get_default_session() cookie_jar = SoupGNOME.CookieJarSqlite(filename=os.path.join( env.get_profile_path(), 'social-help.cookies'), read_only=False) session.add_feature(cookie_jar) self._webview = WebKit.WebView() self._webview.set_full_content_zoom(True) self._webview.connect('resource-request-starting', self._resource_request_starting_cb) scrolled_window = Gtk.ScrolledWindow() scrolled_window.add(self._webview) scrolled_window.show() box.pack_start(scrolled_window, True, True, 0) self._webview.show() language = self._get_current_language() if has_local_help: self._help_url = 'file://' + self._get_help_file(language, url) self._social_help_url = '{}/goto/{}'.format(get_social_help_server(), activity.get_bundle_id()) self._webview.connect('notify::load-status', self.__load_status_changed_cb) self._load_mode(self._mode)
def __init__(self, *args, **kwargs): """Initialize this instance.""" super(WebClient, self).__init__(*args, **kwargs) # pylint: disable=E0611,F0401 from gi.repository import Soup, SoupGNOME self.soup = Soup self.session = Soup.SessionAsync() self.session.add_feature(SoupGNOME.ProxyResolverGNOME()) self.session.connect("authenticate", self._on_authenticate)
def __init__(self, toolbar): self._toolbar = toolbar session = WebKit.get_default_session() cookie_jar = SoupGNOME.CookieJarSqlite(filename=os.path.join( env.get_profile_path(), 'social-help.cookies'), read_only=False) session.add_feature(cookie_jar) self._webview = WebKit.WebView() self._webview.set_full_content_zoom(True) self._webview.connect('resource-request-starting', self.__resource_request_starting_cb) self._webview.connect('notify::uri', self.__load_changed_cb) toolbar.update_back_forward(False, False) toolbar.connect('back-clicked', self.__back_cb) toolbar.connect('forward-clicked', self.__forward_cb) self._webview.show()
def __init__(self, handle): activity.Activity.__init__(self, handle) _logger.debug('Starting the web activity') session = WebKit.get_default_session() session.set_property('accept-language-auto', True) session.set_property('ssl-use-system-ca-file', True) session.set_property('ssl-strict', False) # By default, cookies are not stored persistently, we have to # add a cookie jar so that they get saved to disk. We use one # with a SQlite database: cookie_jar = SoupGNOME.CookieJarSqlite(filename=_cookies_db_path, read_only=False) session.add_feature(cookie_jar) _seed_xs_cookie(cookie_jar) # FIXME # downloadmanager.remove_old_parts() self._force_close = False self._tabbed_view = TabbedView() self._tabbed_view.connect('focus-url-entry', self._on_focus_url_entry) self._tabbed_view.connect('switch-page', self.__switch_page_cb) self._tray = HTray() self.set_tray(self._tray, Gtk.PositionType.BOTTOM) self._primary_toolbar = PrimaryToolbar(self._tabbed_view, self) self._edit_toolbar = EditToolbar(self) self._view_toolbar = ViewToolbar(self) self._primary_toolbar.connect('add-link', self._link_add_button_cb) self._primary_toolbar.connect('go-home', self._go_home_button_cb) self._primary_toolbar.connect('go-library', self._go_library_button_cb) self._primary_toolbar.connect('set-home', self._set_home_button_cb) self._primary_toolbar.connect('reset-home', self._reset_home_button_cb) self._edit_toolbar_button = ToolbarButton( page=self._edit_toolbar, icon_name='toolbar-edit') self._primary_toolbar.toolbar.insert( self._edit_toolbar_button, 1) view_toolbar_button = ToolbarButton( page=self._view_toolbar, icon_name='toolbar-view') self._primary_toolbar.toolbar.insert( view_toolbar_button, 2) self._primary_toolbar.show_all() self.set_toolbar_box(self._primary_toolbar) self.set_canvas(self._tabbed_view) self._tabbed_view.show() self.model = Model() self.model.connect('add_link', self._add_link_model_cb) self.connect('key-press-event', self._key_press_cb) if handle.uri: self._tabbed_view.current_browser.load_uri(handle.uri) elif not self._jobject.file_path: # TODO: we need this hack until we extend the activity API for # opening URIs and default docs. self._tabbed_view.load_homepage() self.messenger = None self.connect('shared', self._shared_cb) # Get the Presence Service self.pservice = presenceservice.get_instance() try: name, path = self.pservice.get_preferred_connection() self.tp_conn_name = name self.tp_conn_path = path self.conn = telepathy.client.Connection(name, path) except TypeError: _logger.debug('Offline') self.initiating = None if self.get_shared_activity() is not None: _logger.debug('shared: %s', self.get_shared()) # We are joining the activity _logger.debug('Joined activity') self.connect('joined', self._joined_cb) if self.get_shared(): # We've already joined self._joined_cb() else: _logger.debug('Created activity') # README: this is a workaround to remove old temp file # http://bugs.sugarlabs.org/ticket/3973 self._cleanup_temp_files()
def __init__(self, handle): activity.Activity.__init__(self, handle) self._force_close = False if incompatible: return self._incompatible() self._collab = CollabWrapper(self) self._collab.message.connect(self.__message_cb) _logger.debug('Starting the web activity') # TODO PORT # session = WebKit2.get_default_session() # session.set_property('accept-language-auto', True) # session.set_property('ssl-use-system-ca-file', True) # session.set_property('ssl-strict', False) # But of a hack, but webkit doesn't let us change the cookie jar # contents, we we can just pre-seed it cookie_jar = SoupGNOME.CookieJarSqlite(filename=_cookies_db_path, read_only=False) _seed_xs_cookie(cookie_jar) del cookie_jar context = WebKit2.WebContext.get_default() cookie_manager = context.get_cookie_manager() cookie_manager.set_persistent_storage( _cookies_db_path, WebKit2.CookiePersistentStorage.SQLITE) # FIXME # downloadmanager.remove_old_parts() context.connect('download-started', self.__download_requested_cb) self._tabbed_view = TabbedView(self) self._tabbed_view.connect('focus-url-entry', self._on_focus_url_entry) self._tabbed_view.connect('switch-page', self.__switch_page_cb) self._titled_tray = TitledTray(_('Bookmarks')) self._tray = self._titled_tray.tray self.set_tray(self._titled_tray, Gtk.PositionType.BOTTOM) self._tray_links = {} self.model = Model() self.model.add_link_signal.connect(self._add_link_model_cb) self._primary_toolbar = PrimaryToolbar(self._tabbed_view, self) self._edit_toolbar = EditToolbar(self) self._view_toolbar = ViewToolbar(self) self._primary_toolbar.connect('add-link', self.__link_add_button_cb) self._primary_toolbar.connect('remove-link', self.__link_remove_button_cb) self._primary_toolbar.connect('go-home', self._go_home_button_cb) self._primary_toolbar.connect('go-library', self._go_library_button_cb) self._primary_toolbar.connect('set-home', self._set_home_button_cb) self._primary_toolbar.connect('reset-home', self._reset_home_button_cb) self._edit_toolbar_button = ToolbarButton(page=self._edit_toolbar, icon_name='toolbar-edit') self._primary_toolbar.toolbar.insert(self._edit_toolbar_button, 1) view_toolbar_button = ToolbarButton(page=self._view_toolbar, icon_name='toolbar-view') self._primary_toolbar.toolbar.insert(view_toolbar_button, 2) self._primary_toolbar.show_all() self.set_toolbar_box(self._primary_toolbar) self.set_canvas(self._tabbed_view) self._tabbed_view.show() self.connect('key-press-event', self._key_press_cb) if handle.uri: self._tabbed_view.current_browser.load_uri(handle.uri) elif not self._jobject.file_path: # TODO: we need this hack until we extend the activity API for # opening URIs and default docs. self._tabbed_view.load_homepage() # README: this is a workaround to remove old temp file # http://bugs.sugarlabs.org/ticket/3973 self._cleanup_temp_files() self._collab.setup()
import gi from contextlib import contextmanager gi.require_version('SoupGNOME', '2.4') from gi.repository import Gio, Soup, SoupGNOME from urllib.parse import urlencode from friends.errors import FriendsError log = logging.getLogger(__name__) # Global libsoup session instance. _soup = Soup.SessionSync() # Enable this for full requests and responses dumped to STDOUT. #_soup.add_feature(Soup.Logger.new(Soup.LoggerLogLevel.BODY, -1)) _soup.add_feature(SoupGNOME.ProxyResolverGNOME()) def _get_charset(message): """Extract charset from Content-Type header in a Soup Message.""" type_header = message.response_headers.get_content_type()[1] if not type_header: return None return type_header.get('charset') class BaseRateLimiter: """Base class for the rate limiting API. By default, this class does no rate limiting. Subclass from this and override the `wait()` and `update()` methods for protocol specific