WebBrowser/WebBrowserView.py

branch
QtWebEngine
changeset 4903
10910764454a
parent 4900
32f940762654
child 4905
09f38f85a3af
diff -r 7a49807e493c -r 10910764454a WebBrowser/WebBrowserView.py
--- a/WebBrowser/WebBrowserView.py	Mon Mar 28 15:31:47 2016 +0200
+++ b/WebBrowser/WebBrowserView.py	Mon Mar 28 16:06:39 2016 +0200
@@ -36,6 +36,7 @@
 from .Network.LoadRequest import LoadRequest, LoadRequestOperations
 
 from . import WebInspector
+from .Tools.WebBrowserTools import readAllFileContents, pixmapToDataUrl
 
 import Preferences
 import UI.PixmapCache
@@ -120,8 +121,7 @@
         self.loadStarted.connect(self.__loadStarted)
         self.loadProgress.connect(self.__loadProgress)
         self.loadFinished.connect(self.__loadFinished)
-        # TODO: renderProcessTerminated
-##        self.page().renderProcessTerminated.connect(self.__renderProcessTerminated)
+        self.renderProcessTerminated.connect(self.__renderProcessTerminated)
         
 ##        self.page().setForwardUnsupportedContent(True)
 ##        self.page().unsupportedContent.connect(self.__unsupportedContent)
@@ -1500,10 +1500,45 @@
     ## Signal handlers below
     ###########################################################################
     
-    # TODO: renderProcessTerminated
-##    def __renderProcessTerminated(self, status, exitCode):
-##        print(status, exitCode)
-##    
+    def __renderProcessTerminated(self, status, exitCode):
+        """
+        Private slot handling a crash of the web page render process.
+        
+        @param status termination status
+        @type QWebEnginePage.RenderProcessTerminationStatus
+        @param exitCode exit code of the process
+        @type int
+        """
+        if status == QWebEnginePage.NormalTerminationStatus:
+            return
+        
+        QTimer.singleShot(0, self.__showTabCrashPage)
+    
+    def __showTabCrashPage(self):
+        """
+        Private slot to show the tab crash page.
+        """
+        html = readAllFileContents(":/html/tabCrashPage.html")
+        html = html.replace("@IMAGE@", pixmapToDataUrl(
+            qApp.style().standardIcon(QStyle.SP_MessageBoxWarning).pixmap(
+                48, 48)).toString())
+        html = html.replace("@FAVICON@", pixmapToDataUrl(
+            qApp.style() .standardIcon(QStyle.SP_MessageBoxWarning).pixmap(
+                16, 16)).toString())
+        html = html.replace("@TITLE@", self.tr("Failed loading page"))
+        html = html.replace("@H1@", self.tr("Failed loading page"))
+        html = html.replace(
+            "@LI-1@",
+            self.tr("Something went wrong while loading this page."))
+        html = html.replace(
+            "@LI-2@",
+            self.tr(
+                "Try reloading the page or closing some tabs to make more"
+                " memory available."))
+        html = html.replace(
+            "@BUTTON@", self.tr("Reload Page"))
+        self.page().setHtml(html, self.url())
+    
     def __loadStarted(self):
         """
         Private method to handle the loadStarted signal.

eric ide

mercurial