• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KDEWebKit

kwebpluginfactory.cpp
Go to the documentation of this file.
00001 /*
00002  * This file is part of the KDE project.
00003  *
00004  * Copyright (C) 2008 Michael Howell <mhowell123@gmail.com>
00005  * Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
00006  * Copyright (C) 2009 Dawit Alemayehu <adawit @ kde.org>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Library General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Library General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Library General Public License
00019  * along with this library; see the file COPYING.LIB.  If not, write to
00020  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021  * Boston, MA 02110-1301, USA.
00022  *
00023  */
00024 
00025 #include "kwebpluginfactory.h"
00026 #include "kwebpage.h"
00027 #include "kwebview.h"
00028 
00029 #include <kmimetypetrader.h>
00030 #include <kservicetypetrader.h>
00031 #include <kmimetype.h>
00032 #include <kdebug.h>
00033 
00034 #include <kio/job.h>
00035 #include <kio/scheduler.h>
00036 #include <kparts/part.h>
00037 
00038 #include <QtCore/QListIterator>
00039 #include <QtCore/QStringList>
00040 #include <QtCore/QList>
00041 
00042 #include <QtWebKit/QWebPluginFactory>
00043 #include <QtWebKit/QWebFrame>
00044 #include <QtWebKit/QWebView>
00045 
00046 #define QL1S(x)  QLatin1String(x)
00047 #define QL1C(x)  QLatin1Char(x)
00048 
00049 static bool excludedMimeType(const QString &type)
00050 {
00051     if (type.startsWith(QL1S("inode/"), Qt::CaseInsensitive))
00052         return true;
00053 
00054     if (type.startsWith(QL1S("application/x-java"), Qt::CaseInsensitive))
00055         return true;
00056 
00057     if (type == QL1S("application/x-shockwave-flash") ||
00058         type == QL1S("application/futuresplash"))
00059       return true;
00060 
00061     return false;
00062 }
00063 
00064 KWebPluginFactory::KWebPluginFactory(QObject *parent)
00065                   :QWebPluginFactory(parent),d(0)
00066 {
00067 }
00068 
00069 KWebPluginFactory::~KWebPluginFactory()
00070 {
00071 }
00072 
00073 QObject* KWebPluginFactory::create(const QString& _mimeType, const QUrl& url, const QStringList& argumentNames, const QStringList& argumentValues) const
00074 {
00075     // Only attempt to find a KPart for the supported mime types...
00076     QVariantList arguments;
00077     const int count = argumentNames.count();
00078 
00079     for (int i = 0; i < count; ++i) {
00080         arguments << QString(argumentNames.at(i) + QL1S("=\"") + argumentValues.at(i) + QL1C('\"'));
00081     }
00082 
00083     QString mimeType (_mimeType.trimmed());
00084     // If no mimetype is provided, we do our best to correctly determine it here...
00085     if (mimeType.isEmpty()) {
00086       kDebug(800) << "Looking up missing mimetype for plugin resource:" << url;
00087       const KUrl reqUrl (url);
00088       KMimeType::Ptr ptr = KMimeType::findByUrl(reqUrl, 0, reqUrl.isLocalFile());
00089       if (ptr->isDefault())
00090           mimeType = ptr->name();
00091 
00092        // Disregard inode/* mime-types...
00093        if (mimeType.startsWith(QLatin1String("inode/"), Qt::CaseInsensitive))
00094           mimeType.clear();
00095        kDebug(800) << "Updated mimetype to" << mimeType;
00096     }
00097 
00098     KParts::ReadOnlyPart* part = 0;
00099 
00100     // Defer handling of flash content to QtWebKit's builtin viewer.
00101     // If you want to use/test KDE's nspluginviewer, comment out the
00102     // if statement below.
00103     if (!mimeType.isEmpty() && !excludedMimeType(mimeType))
00104         part = KMimeTypeTrader::createPartInstanceFromQuery<KParts::ReadOnlyPart>(mimeType, 0, parent(), QString(), arguments);
00105 
00106     kDebug(800) << "Asked for" << mimeType << "plugin, got" << part;
00107 
00108     if (part) {
00109         QMap<QString, QString> metaData = part->arguments().metaData();
00110         QString urlStr = url.toString(QUrl::RemovePath | QUrl::RemoveQuery | QUrl::RemoveFragment);
00111         metaData.insert("PropagateHttpHeader", "true");
00112         metaData.insert("referrer", urlStr);
00113         metaData.insert("cross-domain", urlStr);
00114         metaData.insert("main_frame_request", "TRUE");
00115         metaData.insert("ssl_activate_warnings", "TRUE");
00116 
00117         KWebPage *page = qobject_cast<KWebPage *>(parent());
00118 
00119         if (page) {
00120             const QString scheme = page->mainFrame()->url().scheme();
00121             if (page && (QString::compare(scheme, QL1S("https"), Qt::CaseInsensitive) == 0 ||
00122                          QString::compare(scheme, QL1S("webdavs"), Qt::CaseInsensitive) == 0))
00123               metaData.insert("ssl_was_in_use", "TRUE");
00124             else
00125               metaData.insert("ssl_was_in_use", "FALSE");
00126         }
00127 
00128         KParts::OpenUrlArguments openUrlArgs = part->arguments();
00129         openUrlArgs.metaData() = metaData;
00130         openUrlArgs.setMimeType(mimeType);
00131         part->setArguments(openUrlArgs);
00132         part->openUrl(url);
00133         return part->widget();
00134     }
00135 
00136     return 0;
00137 }
00138 
00139 QList<KWebPluginFactory::Plugin> KWebPluginFactory::plugins() const
00140 {
00141     QList<Plugin> plugins;
00142     return plugins;
00143 }
00144 
00145 #include "kwebpluginfactory.moc"

KDEWebKit

Skip menu "KDEWebKit"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal