~michael-sheldon/webbrowser-app/implement-download-folder

« back to all changes in this revision

Viewing changes to src/app/WebProcessMonitor.qml

  • Committer: Michael Sheldon
  • Date: 2015-09-07 15:28:12 UTC
  • mfrom: (1106.1.64 webbrowser-app)
  • Revision ID: michael.sheldon@canonical.com-20150907152812-c7koycws1bfx836d
Merge from trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2015 Canonical Ltd.
 
3
 *
 
4
 * This file is part of webbrowser-app.
 
5
 *
 
6
 * webbrowser-app is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * webbrowser-app is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 */
 
18
 
 
19
import QtQuick 2.4
 
20
import com.canonical.Oxide 1.8 as Oxide
 
21
 
 
22
Item {
 
23
    id: monitor
 
24
 
 
25
    visible: false
 
26
 
 
27
    property var webview: null
 
28
 
 
29
    readonly property bool killed: webview &&
 
30
                                   (webview.webProcessStatus == Oxide.WebView.WebProcessKilled)
 
31
    readonly property bool crashed: webview &&
 
32
                                    (webview.webProcessStatus == Oxide.WebView.WebProcessCrashed)
 
33
 
 
34
    // When the renderer process is killed (most likely by the system’s
 
35
    // OOM killer), try to reload the page once, and if this results in
 
36
    // the process being killed again within one minute, then display
 
37
    // the sad tab.
 
38
 
 
39
    readonly property int killedRetries: internal.killedRetries
 
40
 
 
41
    QtObject {
 
42
        id: internal
 
43
        property int killedRetries: 0
 
44
    }
 
45
 
 
46
    Connections {
 
47
        target: webview
 
48
        onWebProcessStatusChanged: {
 
49
            if (webview.webProcessStatus == Oxide.WebView.WebProcessKilled) {
 
50
                if (internal.killedRetries == 0) {
 
51
                    // Do not attempt reloading right away, this would result in a crash
 
52
                    delayedReload.restart()
 
53
                }
 
54
            }
 
55
        }
 
56
    }
 
57
 
 
58
    Timer {
 
59
        id: delayedReload
 
60
        interval: 100
 
61
        onTriggered: {
 
62
            monitorTimer.restart()
 
63
            monitor.webview.reload()
 
64
            internal.killedRetries++
 
65
        }
 
66
    }
 
67
 
 
68
    Timer {
 
69
        id: monitorTimer
 
70
        interval: 60000 // 1 minute
 
71
        onTriggered: internal.killedRetries = 0
 
72
    }
 
73
 
 
74
    onWebviewChanged: {
 
75
        internal.killedRetries = 0
 
76
        delayedReload.stop()
 
77
        monitorTimer.stop()
 
78
    }
 
79
}