summaryrefslogtreecommitdiffstats
path: root/src/core/profile_adapter_client.cpp
blob: b6a16c21a4b78e4b28387874c2e5164e7e1fd9f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "profile_adapter_client.h"
#include "components/download/public/common/download_item.h"
#include "content/public/browser/save_page_type.h"

#include <QCoreApplication>
#include <QString>

namespace QtWebEngineCore {

ASSERT_ENUMS_MATCH(download::DownloadItem::IN_PROGRESS, ProfileAdapterClient::DownloadInProgress)
ASSERT_ENUMS_MATCH(download::DownloadItem::COMPLETE, ProfileAdapterClient::DownloadCompleted)
ASSERT_ENUMS_MATCH(download::DownloadItem::CANCELLED, ProfileAdapterClient::DownloadCancelled)
ASSERT_ENUMS_MATCH(download::DownloadItem::INTERRUPTED, ProfileAdapterClient::DownloadInterrupted)

ASSERT_ENUMS_MATCH(content::SAVE_PAGE_TYPE_UNKNOWN, ProfileAdapterClient::UnknownSavePageFormat)
ASSERT_ENUMS_MATCH(content::SAVE_PAGE_TYPE_AS_ONLY_HTML, ProfileAdapterClient::SingleHtmlSaveFormat)
ASSERT_ENUMS_MATCH(content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, ProfileAdapterClient::CompleteHtmlSaveFormat)
ASSERT_ENUMS_MATCH(content::SAVE_PAGE_TYPE_AS_MHTML, ProfileAdapterClient::MimeHtmlSaveFormat)

ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_NONE, ProfileAdapterClient::NoReason)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, ProfileAdapterClient::FileFailed)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED, ProfileAdapterClient::FileAccessDenied)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, ProfileAdapterClient::FileNoSpace)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG, ProfileAdapterClient::FileNameTooLong)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_FILE_TOO_LARGE, ProfileAdapterClient::FileTooLarge)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED, ProfileAdapterClient::FileVirusInfected)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR, ProfileAdapterClient::FileTransientError)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED, ProfileAdapterClient::FileBlocked)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_FILE_SECURITY_CHECK_FAILED, ProfileAdapterClient::FileSecurityCheckFailed)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_FILE_TOO_SHORT, ProfileAdapterClient::FileTooShort)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_FILE_HASH_MISMATCH, ProfileAdapterClient::FileHashMismatch)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, ProfileAdapterClient::NetworkFailed)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT, ProfileAdapterClient::NetworkTimeout)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED, ProfileAdapterClient::NetworkDisconnected)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_NETWORK_SERVER_DOWN, ProfileAdapterClient::NetworkServerDown)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST, ProfileAdapterClient::NetworkInvalidRequest)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, ProfileAdapterClient::ServerFailed)
//ASSERT_ENUMS_MATCH(content::DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE, ProfileAdapterClient::ServerNoRange)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, ProfileAdapterClient::ServerBadContent)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED, ProfileAdapterClient::ServerUnauthorized)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM, ProfileAdapterClient::ServerCertProblem)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_SERVER_FORBIDDEN, ProfileAdapterClient::ServerForbidden)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_SERVER_UNREACHABLE, ProfileAdapterClient::ServerUnreachable)
ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED, ProfileAdapterClient::UserCanceled)
//ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN, ProfileAdapterClient::UserShutdown)
//ASSERT_ENUMS_MATCH(download::DOWNLOAD_INTERRUPT_REASON_CRASH, ProfileAdapterClient::Crash)

QString ProfileAdapterClient::downloadInterruptReasonToString(DownloadInterruptReason reason)
{
    switch (reason) {
    default:
        // Yield an error in debug mode, but fall through to some defined behavior
        Q_UNREACHABLE();
    case NoReason:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "Unknown reason or not interrupted");
    case FileFailed:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "General file operation failure");
    case FileAccessDenied:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "The file cannot be written locally, due to access restrictions");
    case FileNoSpace:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "Insufficient space on the target drive");
    case FileNameTooLong:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "The directory or file name is too long");
    case FileTooLarge:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "The file size exceeds the file system limitation");
    case FileVirusInfected:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "The file is infected with a virus");
    case FileTransientError:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "Temporary problem (for example file in use, or too many open files)");
    case FileBlocked:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "The file was blocked due to local policy");
    case FileSecurityCheckFailed:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "Checking the safety of the download failed due to unexpected reasons");
    case FileTooShort:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "File seek past the end of a file (resuming previously interrupted download)");
    case FileHashMismatch:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "The partial file did not match the expected hash");
    case NetworkFailed:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "General network failure");
    case NetworkTimeout:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "The network operation has timed out");
    case NetworkDisconnected:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "The network connection has been terminated");
    case NetworkServerDown:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "The server has gone down");
    case NetworkInvalidRequest:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "The network request was invalid (for example, the URL or scheme is invalid)");
    case ServerFailed:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "General server failure");
    //case ServerNoRange:
    //    return QCoreApplication::translate("DownloadInterruptReason",
    //                                       "Server does not support range requests");
    case ServerBadContent:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "The server does not have the requested data");
    case ServerUnauthorized:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "The server did not authorize access to the resource");
    case ServerCertProblem:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "A problem with the server certificate occurred");
    case ServerForbidden:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "Access forbidden by the server");
    case ServerUnreachable:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "Unexpected server response");
    case UserCanceled:
        return QCoreApplication::translate("DownloadInterruptReason",
                                           "Download canceled by the user");
    //case UserShutdown:
    //    return QCoreApplication::translate("DownloadInterruptReason",
    //                                       "The user shut down the browser");
    //case Crash:
    //    return QCoreApplication::translate("DownloadInterruptReason",
    //                                       "The browser crashed");
    }
}

} // namespace QtWebEngineCore