Title: [118354] trunk/Source/WebKit/qt
Revision
118354
Author
[email protected]
Date
2012-05-24 05:49:02 -0700 (Thu, 24 May 2012)

Log Message

https://bugs.webkit.org/show_bug.cgi?id=67093
[Qt] Default window.alert shows HTML entities in certain cases

Instead of HTML escaping the text of JS alerts (which does not work
consistently because of Qt's automatisms), build message boxes
explicitly to be able set the text format to plain text.
QInputDialog is a bit hacky, because there is no way to access or
control the contained QLabel.

Patch by Steffen Imhof <[email protected]> on 2012-05-24
Reviewed by Simon Hausmann.

* Api/qwebpage.cpp:
(QWebPage::_javascript_Alert):
(QWebPage::_javascript_Confirm):
(QWebPage::_javascript_Prompt):

Modified Paths

Diff

Modified: trunk/Source/WebKit/qt/Api/qwebpage.cpp (118353 => 118354)


--- trunk/Source/WebKit/qt/Api/qwebpage.cpp	2012-05-24 12:21:50 UTC (rev 118353)
+++ trunk/Source/WebKit/qt/Api/qwebpage.cpp	2012-05-24 12:49:02 UTC (rev 118354)
@@ -130,6 +130,7 @@
 #include <QDropEvent>
 #include <QFileDialog>
 #include <QInputDialog>
+#include <QLabel>
 #include <QMenu>
 #include <QMessageBox>
 #include <QNetworkProxy>
@@ -2082,7 +2083,12 @@
     Q_UNUSED(frame)
 #ifndef QT_NO_MESSAGEBOX
     QWidget* parent = (d->client) ? d->client->ownerWidget() : 0;
-    QMessageBox::information(parent, tr("_javascript_ Alert - %1").arg(mainFrame()->url().host()), escapeHtml(msg), QMessageBox::Ok);
+    QMessageBox box(parent);
+    box.setWindowTitle(tr("_javascript_ Alert - %1").arg(mainFrame()->url().host()));
+    box.setTextFormat(Qt::PlainText);
+    box.setText(msg);
+    box.setStandardButtons(QMessageBox::Ok);
+    box.exec();
 #endif
 }
 
@@ -2099,7 +2105,12 @@
     return true;
 #else
     QWidget* parent = (d->client) ? d->client->ownerWidget() : 0;
-    return QMessageBox::Yes == QMessageBox::information(parent, tr("_javascript_ Confirm - %1").arg(mainFrame()->url().host()), escapeHtml(msg), QMessageBox::Yes, QMessageBox::No);
+    QMessageBox box(parent);
+    box.setWindowTitle(tr("_javascript_ Confirm - %1").arg(mainFrame()->url().host()));
+    box.setTextFormat(Qt::PlainText);
+    box.setText(msg);
+    box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+    return QMessageBox::Yes == box.exec();
 #endif
 }
 
@@ -2118,10 +2129,30 @@
     Q_UNUSED(frame)
     bool ok = false;
 #ifndef QT_NO_INPUTDIALOG
+
     QWidget* parent = (d->client) ? d->client->ownerWidget() : 0;
-    QString x = QInputDialog::getText(parent, tr("_javascript_ Prompt - %1").arg(mainFrame()->url().host()), escapeHtml(msg), QLineEdit::Normal, defaultValue, &ok);
+    QInputDialog dlg(parent);
+    dlg.setWindowTitle(tr("_javascript_ Prompt - %1").arg(mainFrame()->url().host()));
+
+    // Hack to force the dialog's QLabel into plain text mode
+    // prevents https://bugs.webkit.org/show_bug.cgi?id=34429
+    QLabel* label = dlg.findChild<QLabel*>();
+    if (label)
+        label->setTextFormat(Qt::PlainText);
+
+    // double the &'s because single & will underline the following character
+    // (Accelerator mnemonics)
+    QString escMsg(msg);
+    escMsg.replace(QChar::fromAscii('&'), QString::fromAscii("&&"));
+    dlg.setLabelText(escMsg);
+
+    dlg.setTextEchoMode(QLineEdit::Normal);
+    dlg.setTextValue(defaultValue);
+
+    ok = !!dlg.exec();
+
     if (ok && result)
-        *result = x;
+        *result = dlg.textValue();
 #endif
     return ok;
 }

Modified: trunk/Source/WebKit/qt/ChangeLog (118353 => 118354)


--- trunk/Source/WebKit/qt/ChangeLog	2012-05-24 12:21:50 UTC (rev 118353)
+++ trunk/Source/WebKit/qt/ChangeLog	2012-05-24 12:49:02 UTC (rev 118354)
@@ -1,3 +1,21 @@
+2012-05-24  Steffen Imhof  <[email protected]>
+
+        https://bugs.webkit.org/show_bug.cgi?id=67093
+        [Qt] Default window.alert shows HTML entities in certain cases
+
+        Instead of HTML escaping the text of JS alerts (which does not work
+        consistently because of Qt's automatisms), build message boxes
+        explicitly to be able set the text format to plain text.
+        QInputDialog is a bit hacky, because there is no way to access or
+        control the contained QLabel.
+
+        Reviewed by Simon Hausmann.
+
+        * Api/qwebpage.cpp:
+        (QWebPage::_javascript_Alert):
+        (QWebPage::_javascript_Confirm):
+        (QWebPage::_javascript_Prompt):
+
 2012-05-21  Caio Marcelo de Oliveira Filho  <[email protected]>
 
         Move setEditingBehavior() from layoutTestController to window.internals
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to