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

KDEWebKit

  • sources
  • kde-4.14
  • kdelibs
  • kdewebkit
kwebpluginfactory.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the KDE project.
3  *
4  * Copyright (C) 2008 Michael Howell <mhowell123@gmail.com>
5  * Copyright (C) 2008 Urs Wolfer <uwolfer @ kde.org>
6  * Copyright (C) 2009 Dawit Alemayehu <adawit @ kde.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB. If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24 
25 #include "kwebpluginfactory.h"
26 #include "kwebpage.h"
27 #include "kwebview.h"
28 
29 #include <kmimetypetrader.h>
30 #include <kservicetypetrader.h>
31 #include <kmimetype.h>
32 #include <kdebug.h>
33 
34 #include <kio/job.h>
35 #include <kparts/part.h>
36 
37 #include <QtCore/QListIterator>
38 #include <QtCore/QStringList>
39 #include <QtCore/QList>
40 
41 #include <QtWebKit/QWebPluginFactory>
42 #include <QtWebKit/QWebFrame>
43 #include <QtWebKit/QWebView>
44 
45 #define QL1S(x) QLatin1String(x)
46 #define QL1C(x) QLatin1Char(x)
47 
48 
49 KWebPluginFactory::KWebPluginFactory(QObject *parent)
50  :QWebPluginFactory(parent),d(0)
51 {
52 }
53 
54 KWebPluginFactory::~KWebPluginFactory()
55 {
56 }
57 
58 QObject* KWebPluginFactory::create(const QString& _mimeType, const QUrl& url, const QStringList& argumentNames, const QStringList& argumentValues) const
59 {
60  QString mimeType (_mimeType.trimmed());
61  // If no mimetype is provided, we do our best to correctly determine it here...
62  if (mimeType.isEmpty()) {
63  kDebug(800) << "Looking up missing mimetype for plugin resource:" << url;
64  extractGuessedMimeType(url, &mimeType);
65  kDebug(800) << "Updated mimetype to" << mimeType;
66  }
67 
68  // Defer handling of flash content to QtWebKit's builtin viewer.
69  // If you want to use/test KDE's nspluginviewer, comment out the
70  // if statement below.
71  KParts::ReadOnlyPart* part = (excludedMimeType(mimeType) ? 0 : createPartInstanceFrom(mimeType, argumentNames, argumentValues, 0, parent()));
72 
73  kDebug(800) << "Asked for" << mimeType << "plugin, got" << part;
74 
75  if (part) {
76  QMap<QString, QString> metaData = part->arguments().metaData();
77  QString urlStr = url.toString(QUrl::RemovePath | QUrl::RemoveQuery | QUrl::RemoveFragment);
78  metaData.insert("PropagateHttpHeader", "true");
79  metaData.insert("referrer", urlStr);
80  metaData.insert("cross-domain", urlStr);
81  metaData.insert("main_frame_request", "TRUE");
82  metaData.insert("ssl_activate_warnings", "TRUE");
83 
84  KWebPage *page = qobject_cast<KWebPage *>(parent());
85 
86  if (page) {
87  const QString scheme = page->currentFrame()->url().scheme();
88  if (page && (QString::compare(scheme, QL1S("https"), Qt::CaseInsensitive) == 0 ||
89  QString::compare(scheme, QL1S("webdavs"), Qt::CaseInsensitive) == 0))
90  metaData.insert("ssl_was_in_use", "TRUE");
91  else
92  metaData.insert("ssl_was_in_use", "FALSE");
93  }
94 
95  KParts::OpenUrlArguments openUrlArgs = part->arguments();
96  openUrlArgs.metaData() = metaData;
97  openUrlArgs.setMimeType(mimeType);
98  part->setArguments(openUrlArgs);
99  part->openUrl(url);
100  return part->widget();
101  }
102 
103  return 0;
104 }
105 
106 QList<KWebPluginFactory::Plugin> KWebPluginFactory::plugins() const
107 {
108  QList<Plugin> plugins;
109  return plugins;
110 }
111 
112 static bool isHttpProtocol(const QUrl& url)
113 {
114  const QString scheme (url.scheme());
115  return (scheme.startsWith(QL1S("http"), Qt::CaseInsensitive)
116  || scheme.startsWith(QL1S("webdav"), Qt::CaseInsensitive));
117 }
118 
119 void KWebPluginFactory::extractGuessedMimeType (const QUrl& url, QString* mimeType) const
120 {
121  if (mimeType) {
122  const KUrl reqUrl ((isHttpProtocol(url) ? url.path() : url));
123  KMimeType::Ptr ptr = KMimeType::findByUrl(reqUrl, 0, reqUrl.isLocalFile(), true);
124  if (!ptr->isDefault() && !ptr->name().startsWith(QL1S("inode/"), Qt::CaseInsensitive)) {
125  *mimeType = ptr->name();
126  }
127  }
128 }
129 
130 KParts::ReadOnlyPart* KWebPluginFactory::createPartInstanceFrom(const QString& mimeType,
131  const QStringList& argumentNames,
132  const QStringList& argumentValues,
133  QWidget* parentWidget,
134  QObject* parentObj) const
135 {
136  KParts::ReadOnlyPart* part = 0;
137 
138  if (!mimeType.isEmpty()) {
139  // Only attempt to find a KPart for the supported mime types...
140  QVariantList arguments;
141  const int count = argumentNames.count();
142 
143  for (int i = 0; i < count; ++i) {
144  arguments << QString(argumentNames.at(i) + QL1S("=\"") + argumentValues.at(i) + QL1C('\"'));
145  }
146  part = KMimeTypeTrader::createPartInstanceFromQuery<KParts::ReadOnlyPart>(mimeType, parentWidget, parentObj, QString(), arguments);
147  }
148 
149  return part;
150 }
151 
152 bool KWebPluginFactory::excludedMimeType (const QString& mimeType) const
153 {
154  if (mimeType.startsWith(QL1S("inode/"), Qt::CaseInsensitive))
155  return true;
156 
157  if (mimeType.startsWith(QL1S("application/x-java"), Qt::CaseInsensitive))
158  return true;
159 
160  if (mimeType == QL1S("application/x-shockwave-flash") ||
161  mimeType == QL1S("application/futuresplash"))
162  return true;
163 
164  return false;
165 }
166 
167 #include "kwebpluginfactory.moc"
QWidget
kwebpage.h
kdebug.h
kmimetype.h
KWebPluginFactory::create
virtual QObject * create(const QString &mimeType, const QUrl &url, const QStringList &argumentNames, const QStringList &argumentValues) const
Definition: kwebpluginfactory.cpp:58
KWebPluginFactory::~KWebPluginFactory
~KWebPluginFactory()
Destroys the KWebPage.
Definition: kwebpluginfactory.cpp:54
QList::at
const T & at(int i) const
QMap< QString, QString >
kwebview.h
QL1S
#define QL1S(x)
Definition: kwebpluginfactory.cpp:45
KWebPluginFactory::extractGuessedMimeType
void extractGuessedMimeType(const QUrl &url, QString *mimeType) const
Sets mimeType to the content type guessed from url.
Definition: kwebpluginfactory.cpp:119
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
QUrl::toString
QString toString(QFlags< QUrl::FormattingOption > options) const
KWebPluginFactory::createPartInstanceFrom
KParts::ReadOnlyPart * createPartInstanceFrom(const QString &mimeType, const QStringList &argumentNames, const QStringList &argumentValues, QWidget *parentWidget=0, QObject *parent=0) const
Returns an instance of the service associated with mimeType.
Definition: kwebpluginfactory.cpp:130
KUrl
kservicetypetrader.h
QL1C
#define QL1C(x)
Definition: kwebpluginfactory.cpp:46
QList::count
int count(const T &value) const
QWebFrame::url
url
KWebPluginFactory::KWebPluginFactory
KWebPluginFactory(QObject *parent)
Constructs a KWebPluginFactory with parent parent.
Definition: kwebpluginfactory.cpp:49
QObject
QString::isEmpty
bool isEmpty() const
QString::trimmed
QString trimmed() const
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
kmimetypetrader.h
QUrl::path
QString path() const
QString
QList
QUrl::scheme
QString scheme() const
QStringList
QUrl
KWebPluginFactory::excludedMimeType
bool excludedMimeType(const QString &mimeType) const
Returns true if the given mime-type is excluded from being used to create a web plugin using KDE's tr...
Definition: kwebpluginfactory.cpp:152
job.h
QWebPluginFactory
kwebpluginfactory.h
isHttpProtocol
static bool isHttpProtocol(const QUrl &url)
Definition: kwebpluginfactory.cpp:112
KWebPage
An enhanced QWebPage that provides integration into the KDE environment.
Definition: kwebpage.h:75
QMap::insert
iterator insert(const Key &key, const T &value)
QWebPage::currentFrame
QWebFrame * currentFrame() const
KUrl::isLocalFile
bool isLocalFile() const
QObject::parent
QObject * parent() const
QString::compare
int compare(const QString &other) const
KWebPluginFactory::plugins
virtual QList< Plugin > plugins() const
Definition: kwebpluginfactory.cpp:106
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:26:06 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEWebKit

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • 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

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal