createWindow function doesn't load flashplayer content

168 views Asked by At

I am currently trying to develop a basic browser web in order to surf on a specific internet site using qt framework. I created a MyWindow class which inherits QWebView and reimplements createWindow function, this in order to handle the opening of potential pop-ups in a new browser window. It works well during "normal" navigation, but when I encounter links such as:

<a class="lien_default" href="javascript:popupChat2('foo.php?id=42250')">bar</a>

If linked page has a flash content, a new window is created but it is empty. Here is the code of popupChat2:

function popupChat2(page)
{fenetre=window.open(page,'chat','top=0, left=0, width=800, height=500, resizable=no, toolbar=no, scrollbars=no, status=no, menubar=no, titlebar=no, dependent=yes');}

I also tried to save locally linked page, and if I open it with a very simple qt browser web like this:

main.cpp

#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
   QApplication a(argc, argv);
   MainWindow w;
   w.show();

   return a.exec();
}

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
   QMainWindow(parent),
   ui(new Ui::MainWindow)
{
   QUrl url("file:///[url of the page locally saved with flash player content]");
   ui->setupUi(this);
   QWebSettings *settings = ui->webView->settings();
   settings->setAttribute(QWebSettings::JavascriptEnabled, true);
   settings->setAttribute(QWebSettings::PluginsEnabled, true);
   settings->setAttribute(QWebSettings::AutoLoadImages, true);
   settings->setAttribute(QWebSettings::JavaEnabled, false);
   settings->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
   settings->setAttribute(QWebSettings::LocalContentCanAccessFileUrls,true);

   ui->webView->load(url);
   ui->webView->show();
}

MainWindow::~MainWindow()
{
   delete ui;
}

It is correctly loaded. The following is the code of my createWindow function and the code of linked page with flash content:

MyWindow *MyWindow::createWindow(QWebPage::WebWindowType type)
      {
        Q_UNUSED(type);
        MyWindow *webView = new MyWindow;

        webView->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
        webView->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
        webView->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
        webView->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);

        webView->setAttribute(Qt::WA_DeleteOnClose, true);

        QWebPage *newWeb = new QWebPage(webView);
        newWeb->setNetworkAccessManager(page()->networkAccessManager());

        webView->setPage(newWeb);
        webView->show();

        return webView;
    }

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Taverna dei d'Alcontres</title></head>

<script language="Javascript">
function popUpPerso(page)
{
        fenetre = window.open(page, 'perso', 'top=0, left=0, width=650, height=638, resizable=0, toolbar=0, scrollbars=0, status=0, menubar=0, titlebar=0, location=0, dependent=yes');
}

function popUpMains()
{
   fenetre = window.open('/EcranPrincipal.php?l=34&action=14', 'main');
}

function closeWindow()
{
   window.close();
}

function flashTheWindow()
{
   window.GetAttention();
}
</script>

<body bgcolor="#ffffff" style="margin:0;">
<script type="text/javascript">
<!--
function format(val) {
   sign = val < 0 ? "-":"";
   rval = Math.abs(Math.round(val*100));
   str = rval.toString();
   if(rval < 10) str = "0.0"+str;
   else if(rval < 100) str = "0."+str;
   else str = str.substring(0, str.length-2)
     + "." + str.substring(str.length-2, str.length);
   return sign+str;
}

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.

function Taverne_DoFSCommand(command, args) {
   var TaverneObj = isInternetExplorer ? document.all.Taverne : document.Taverne;
   if (command == "closeWindow") {
       closeWindow();
   }
   if (command == "flashWindow") {
       flashTheWindow();
   }
}
// Hook for Internet Explorer.
   if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
    document.write('<script language="VBScript">\n');
    document.write('On Error Resume Next\n');
    document.write('Sub Taverne_FSCommand(ByVal command, ByVal args)\n');
    document.write('    Call Taverne_DoFSCommand(command, args)\n');
    document.write('End Sub\n');
    document.write('</script\>\n');
}
//-->
</script>

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"     codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="1200" height="700" id="Taverne" align="middle">
<param name="allowScriptAccess" value="always" />
<param name="movie" value="http://d2wb3jk3zoe588.cloudfront.net/divers/taverne5.swf?myTaverne=41785&myLogin=sir_marcus&myPassword=a5c358a794d018f6737ecf76cab2c31f&estNoble=0&estTavernier=0&SonEnTaverne=1&html_address=ns36946.ovh.net&html_port=8080&codeLangue=it&nbPlacesTiersEtat=8&nbPlacesNoblesse=1&NomTaverne=Taverna+dei+d%27Alcontres&nbPlacesPersonnelTaverne=1&doitParlerDansTaverne=0&doitOffrirABoireDansTaverne=0&doitMangerDansTaverne=0&typeEtablissement=0&mainsRestantes=10&version=3.0" />
<param name="quality" value="high" />
<param name="bgcolor" value="#000000" />
<param name="menu" value="false" />
<embed src="http://d2wb3jk3zoe588.cloudfront.net/divers/taverne5.swf?myTaverne=41785&myLogin=sir_marcus&myPassword=a5c358a794d018f6737ecf76cab2c31f&estNoble=0&estTavernier=0&SonEnTaverne=1&html_address=ns36946.ovh.net&html_port=8080&codeLangue=it&nbPlacesTiersEtat=8&nbPlacesNoblesse=1&NomTaverne=Taverna+dei+d%27Alcontres&nbPlacesPersonnelTaverne=1&doitParlerDansTaverne=0&doitOffrirABoireDansTaverne=0&doitMangerDansTaverne=0&typeEtablissement=0&mainsRestantes=10&version=3.0" quality="high" bgcolor="#000000" menu="false" width="1200" height="700" name="Taverne" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>

Thank you

Hicarus

1

There are 1 answers

0
jturcotte On BEST ANSWER

You apply your QWebSettings on webView, but they are effectively stored in webView->page().

So when you do webView->setPage(newWeb); you revert to default QWebSettings, including the needed QWebSettings::PluginsEnabled.

In fact, you don't seem to need an extra QWebPage, just set your QNAM on the default one:

webView->page()->setNetworkAccessManager(page()->networkAccessManager());