From 95bf16aa07c00d67732164c716e194d7077c3b8f Mon Sep 17 00:00:00 2001 From: root <root@dedalo.nexlab.thc> Date: Tue, 5 Mar 2013 21:10:11 +0100 Subject: [PATCH] Forced referer header on requests to youtube to avoid the UMG messages --- src/mainwin.cpp | 12 ++++++++++-- src/mainwin.h | 19 +++++++++++++++++++ src/webwin.cpp | 9 +++++++++ src/webwin.h | 1 - 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/mainwin.cpp b/src/mainwin.cpp index 3b8a3a5..a3fa07e 100644 --- a/src/mainwin.cpp +++ b/src/mainwin.cpp @@ -184,8 +184,6 @@ void MainWin::handle_youtubevideo(SKMessage &msg) if(msg.parameters.contains("url")) { std::cout << "OPEN URL " << msg.parameters["url"].toStdString() << std::endl; - //if(msg.parameters.contains("width") - //if(msg.parameters.contains("height); if(!yt_is_open) { yt = new WebWin(); @@ -194,12 +192,22 @@ void MainWin::handle_youtubevideo(SKMessage &msg) //QWebPageForMac *newWeb = new QWebPageForMac(yt); //#else QWebPage *newWeb = new QWebPage(yt); + //ReferredNetworkAccessManager nam; + ReferredNetworkAccessManager *nam = new ReferredNetworkAccessManager(); + newWeb->setNetworkAccessManager(nam); //#endif yt->setPage(newWeb); yt->setAttribute(Qt::WA_DeleteOnClose, true); yt->settings()->setAttribute(QWebSettings::PluginsEnabled, true); yt->settings()->setAttribute(QWebSettings::JavascriptEnabled, true); + if(msg.parameters.contains("width") && msg.parameters.contains("height")) + yt->resize(msg.parameters["width"].toInt(), msg.parameters["height"].toInt()); + else if(msg.parameters.contains("width")) + yt->resize(msg.parameters["width"].toInt(), yt->height()); + else if(msg.parameters.contains("height")) + yt->resize(yt->width(), msg.parameters["height"].toInt()); + yt->setUrl(QUrl(msg.parameters["url"])); connect(yt, SIGNAL(closingWindow()), this, SLOT(ytclosesignal())); yt->show(); diff --git a/src/mainwin.h b/src/mainwin.h index 5282dd5..41cf180 100644 --- a/src/mainwin.h +++ b/src/mainwin.h @@ -42,6 +42,9 @@ #include <QHash> #include <QString> #include <QObject> +#include <QNetworkAccessManager> +#include <QNetworkRequest> +#include <QIODevice> #include <ipcmsg.h> #include "webwin.h" #include "jsbridge.h" @@ -77,4 +80,20 @@ class MainWin : public SkylivexWin }; +class ReferredNetworkAccessManager : public QNetworkAccessManager { + + Q_OBJECT + + protected: + virtual QNetworkReply * createRequest(Operation op, + const QNetworkRequest & req, + QIODevice * outgoingData = 0) + { + QNetworkRequest newReq(req); + newReq.setRawHeader("Referer", "http://www.skylive.it"); + return QNetworkAccessManager::createRequest(op, newReq, outgoingData); + } +}; + + #endif diff --git a/src/webwin.cpp b/src/webwin.cpp index 8489647..c86ef92 100644 --- a/src/webwin.cpp +++ b/src/webwin.cpp @@ -131,6 +131,10 @@ QWebView* WebWin::createWindow(QWebPage::WebWindowType type) if (type == QWebPage::WebModalDialog) wv->setWindowModality(Qt::ApplicationModal); + // Assure plugin and js support also for this window. + wv->settings()->setAttribute(QWebSettings::PluginsEnabled, true); + wv->settings()->setAttribute(QWebSettings::JavascriptEnabled, true); + SKMessage msg("newwindow", qobject_cast<SkylivexWin *>(wv)); sendMessage(msg); @@ -290,6 +294,11 @@ SkylivexWin* SkylivexWin::createSkyliveWindow(QString url, QWebPage::WebWindowTy connect(newWeb->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), wv, SLOT(refreshJsObject())); + // Assure plugin and js support also for this window. + wv->settings()->setAttribute(QWebSettings::PluginsEnabled, true); + wv->settings()->setAttribute(QWebSettings::JavascriptEnabled, true); + + wv->setPage(newWeb); wv->setAttribute(Qt::WA_DeleteOnClose, true); if (type == QWebPage::WebModalDialog) diff --git a/src/webwin.h b/src/webwin.h index 444c855..7767c83 100644 --- a/src/webwin.h +++ b/src/webwin.h @@ -52,7 +52,6 @@ typedef void (WebWin::*SKHandlerFunction)(SKMessage&); //typedef int (WebWin::*SKHandlerFunction)(SKMessage&); -//#if defined(Q_OS_MAC) /* * For some reason youtube think that the default user agent * on OSX doesn't support HTML5 videos, -- 2.18.1