コード例 #1
0
ファイル: history.py プロジェクト: tikservices/qutebrowser
 def add_from_tab(self, url, requested_url, title):
     """Add a new history entry as slot, called from a BrowserTab."""
     no_formatting = QUrl.UrlFormattingOption(0)
     if (requested_url.isValid()
             and not requested_url.matches(url, no_formatting)):
         # If the url of the page is different than the url of the link
         # originally clicked, save them both.
         self.add_url(requested_url, title, redirect=True)
     self.add_url(url, title)
コード例 #2
0
 def on_initial_layout_completed(self):
     """Add url to history now that we have displayed something."""
     history = objreg.get('web-history')
     no_formatting = QUrl.UrlFormattingOption(0)
     orig_url = self.page().mainFrame().requestedUrl()
     if (orig_url.isValid() and
             not orig_url.matches(self.cur_url, no_formatting)):
         # If the url of the page is different than the url of the link
         # originally clicked, save them both.
         history.add_url(orig_url, self.title(), redirect=True)
     history.add_url(self.cur_url, self.title())
コード例 #3
0
    def on_initial_layout_completed(self):
        """Add url to history now that we have displayed something."""
        history = objreg.get('web-history')
        if not self._orig_url.matches(self.cur_url,
                                      QUrl.UrlFormattingOption(0)):
            # If the url of the page is different than the url of the link
            # originally clicked, save them both.
            url = self._orig_url.toString(QUrl.FullyEncoded
                                          | QUrl.RemovePassword)
            history.add_url(url, self.title(), hidden=True)
        url = self.cur_url.toString(QUrl.FullyEncoded | QUrl.RemovePassword)

        history.add_url(url, self.title())
コード例 #4
0
    def add_from_tab(self, url, requested_url, title):
        """Add a new history entry as slot, called from a BrowserTab."""
        if any(url.scheme() in ('data', 'view-source') or (
                url.scheme(), url.host()) == ('qute', 'back')
               for url in (url, requested_url)):
            return
        if url.isEmpty():
            # things set via setHtml
            return

        no_formatting = QUrl.UrlFormattingOption(0)
        if (requested_url.isValid()
                and not requested_url.matches(url, no_formatting)):
            # If the url of the page is different than the url of the link
            # originally clicked, save them both.
            self.add_url(requested_url, title, redirect=True)
        self.add_url(url, title)
コード例 #5
0
ファイル: history.py プロジェクト: xp4ck/qutebrowser
    def add_from_tab(self, url, requested_url, title):
        """Add a new history entry as slot, called from a BrowserTab."""
        if self._is_excluded_entirely(url) or self._is_excluded_entirely(requested_url):
            return
        if url.isEmpty():
            # things set via setHtml
            return

        no_formatting = QUrl.UrlFormattingOption(0)
        if (requested_url.isValid() and
                not requested_url.matches(url, no_formatting)):
            # If the url of the page is different than the url of the link
            # originally clicked, save them both.
            self.add_url(requested_url, title, redirect=True)
        if url != self._last_url:
            self.add_url(url, title)
            self._last_url = url
コード例 #6
0
    def _on_history_trigger(self, force_entry: bool = True) -> None:
        """Add or update a history entry when required."""
        try:
            self._widget.page()
        except RuntimeError:
            # Looks like this slot can be triggered on destroyed tabs:
            # https://crashes.qutebrowser.org/view/3abffbed (Qt 5.9.1)
            # wrapped C/C++ object of type WebEngineView has been deleted
            log.misc.debug("Ignoring history trigger for destroyed tab")
            return

        url = self.url()
        requested_url = self.url(requested=True)

        # Don't save the title if it's generated from the URL
        title = self.title()
        title_url = QUrl(url)
        title_url.setScheme('')
        title_url_str = title_url.toDisplayString(
            QUrl.RemoveScheme)  # type: ignore[arg-type]
        if title == title_url_str.strip('/'):
            title = ""

        # Don't add history entry if the URL is invalid anyways
        if not url.isValid():
            log.misc.debug("Ignoring invalid URL being added to history")
            return

        if url == self._last_history_url:
            # Same page, but title might have changed
            if title != self._last_history_title:
                atime = self._last_history_atime
                # redirect=False, update=True
                self.history_item_triggered.emit(url, title, atime, False,
                                                 True)
                self._last_history_title = title

            # Update this in case it changed.
            self._last_history_requested_url = requested_url
        elif force_entry or title != self._last_history_title:
            # Don't add an entry if only the url has changed.
            # This hopefully filters out unimportant url changes

            atime = int(time.time())

            no_formatting = cast(QUrl.FormattingOptions,
                                 QUrl.UrlFormattingOption(0))
            if any(u is not None and requested_url.matches(u, no_formatting)
                   for u in (self._last_history_requested_url,
                             self._last_history_url)):
                # This isn't a new request, so get old atime and mark
                # previous url as a redirect
                atime = self._last_history_atime
                # redirect=True, update=True
                self.history_item_triggered.emit(self._last_history_url, title,
                                                 atime, True, True)
            elif requested_url.isValid() \
                    and not requested_url.matches(url, no_formatting) \
                    and not url.scheme() == 'view-source':
                # If the url of the page is different than the url of the link
                # originally clicked, save them both.
                # Check for 'view-source' here because WebEngine sets
                # requested_url to the url of the original page.
                # redirect=True, update=False
                self.history_item_triggered.emit(requested_url, title, atime,
                                                 True, False)

            # redirect=False, update=False
            self.history_item_triggered.emit(url, title, atime, False, False)

            self._last_history_atime = atime
            self._last_history_requested_url = requested_url
            self._last_history_url = url
            self._last_history_title = title