summaryrefslogtreecommitdiff
path: root/dev-qt/qtwebengine/files/qtwebengine-5.15.2_p20210224-fix-crash-w-app-locales.patch
blob: 3a372381ebd8696186cbf899434c188893619057 (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
From 199ea00a9eea13315a652c62778738629185b059 Mon Sep 17 00:00:00 2001
From: Allan Sandfeld Jensen <allan.jensen@qt.io>
Date: Wed, 10 Mar 2021 17:14:27 +0100
Subject: Fix normalization of app locales
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Use the internal Chromium routine to get the app locale Chromium
expects.

Fixes: QTBUG-91715
Change-Id: I5042eb066cb6879ad69628959912f2841867b4e8
Reviewed-by: Michael Brüning <michael.bruning@qt.io>
---
 src/core/content_browser_client_qt.cpp             |  7 ++++++-
 src/core/content_browser_client_qt.h               |  2 ++
 src/core/web_engine_library_info.cpp               | 18 ++++++++--------
 .../widgets/qwebengineview/tst_qwebengineview.cpp  | 24 ++++++++++++++++++++++
 4 files changed, 40 insertions(+), 11 deletions(-)

diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp
index e13ecd8d1..c2c78ff8b 100644
--- a/src/core/content_browser_client_qt.cpp
+++ b/src/core/content_browser_client_qt.cpp
@@ -471,7 +471,12 @@ std::unique_ptr<net::ClientCertStore> ContentBrowserClientQt::CreateClientCertSt
 
 std::string ContentBrowserClientQt::GetApplicationLocale()
 {
-    return WebEngineLibraryInfo::getApplicationLocale();
+    std::string bcp47Name = QLocale().bcp47Name().toStdString();
+    if (m_cachedQtLocale != bcp47Name) {
+        m_cachedQtLocale = bcp47Name;
+        m_appLocale = WebEngineLibraryInfo::getApplicationLocale();
+    }
+    return m_appLocale;
 }
 
 std::string ContentBrowserClientQt::GetAcceptLangs(content::BrowserContext *context)
diff --git a/src/core/content_browser_client_qt.h b/src/core/content_browser_client_qt.h
index 7c8aa3ac9..1ccd2926d 100644
--- a/src/core/content_browser_client_qt.h
+++ b/src/core/content_browser_client_qt.h
@@ -269,6 +269,8 @@ public:
 
 private:
     scoped_refptr<ShareGroupQtQuick> m_shareGroupQtQuick;
+    std::string m_appLocale;
+    std::string m_cachedQtLocale;
 };
 
 } // namespace QtWebEngineCore
diff --git a/src/core/web_engine_library_info.cpp b/src/core/web_engine_library_info.cpp
index 2ad5b7565..09a4141b0 100644
--- a/src/core/web_engine_library_info.cpp
+++ b/src/core/web_engine_library_info.cpp
@@ -46,6 +46,7 @@
 #include "components/spellcheck/spellcheck_buildflags.h"
 #include "content/public/common/content_paths.h"
 #include "sandbox/policy/switches.h"
+#include "ui/base/l10n/l10n_util.h"
 #include "ui/base/ui_base_paths.h"
 #include "ui/base/ui_base_switches.h"
 
@@ -353,18 +354,15 @@ base::string16 WebEngineLibraryInfo::getApplicationName()
 std::string WebEngineLibraryInfo::getApplicationLocale()
 {
     base::CommandLine *parsedCommandLine = base::CommandLine::ForCurrentProcess();
-    if (!parsedCommandLine->HasSwitch(switches::kLang)) {
+    if (parsedCommandLine->HasSwitch(switches::kLang)) {
+        return parsedCommandLine->GetSwitchValueASCII(switches::kLang);
+    } else {
         const QString &locale = QLocale().bcp47Name();
-
-        // QLocale::bcp47Name returns "en" for American English locale. Chromium requires the "US" suffix
-        // to clarify the dialect and ignores the shorter version.
-        if (locale == "en")
-            return "en-US";
-
-        return locale.toStdString();
+        std::string resolvedLocale;
+        if (l10n_util::CheckAndResolveLocale(locale.toStdString(), &resolvedLocale))
+            return resolvedLocale;
     }
-
-    return parsedCommandLine->GetSwitchValueASCII(switches::kLang);
+    return "en-US";
 }
 
 #if defined(OS_WIN)
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
index 021986381..bf2c28ae6 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
@@ -123,6 +123,7 @@ private Q_SLOTS:
     void doNotBreakLayout();
 
     void changeLocale();
+    void mixLangLocale();
     void inputMethodsTextFormat_data();
     void inputMethodsTextFormat();
     void keyboardEvents();
@@ -1210,6 +1211,29 @@ void tst_QWebEngineView::changeLocale()
     QCOMPARE(errorLines.first().toUtf8(), QByteArrayLiteral("Die Website ist nicht erreichbar"));
 }
 
+void tst_QWebEngineView::mixLangLocale()
+{
+    for (QString locale : { "en_DK", "de_CH", "eu_ES" }) {
+        QLocale::setDefault(locale);
+        QWebEngineView view;
+        QSignalSpy loadSpy(&view, &QWebEngineView::loadFinished);
+
+        bool terminated = false;
+        auto sc = connect(view.page(), &QWebEnginePage::renderProcessTerminated, [&] () { terminated = true; });
+
+        view.load(QUrl("qrc:///resources/dummy.html"));
+        QTRY_VERIFY(terminated || loadSpy.count() == 1);
+
+        QVERIFY2(!terminated,
+            qPrintable(QString("Locale [%1] terminated: %2, loaded: %3").arg(locale).arg(terminated).arg(loadSpy.count())));
+        QVERIFY(loadSpy.first().first().toBool());
+
+        QString content = toPlainTextSync(view.page());
+        QVERIFY2(!content.isEmpty() && content.contains("test content"), qPrintable(content));
+    }
+    QLocale::setDefault(QLocale("en"));
+}
+
 void tst_QWebEngineView::inputMethodsTextFormat_data()
 {
     QTest::addColumn<QString>("string");
-- 
cgit v1.2.1