Changeset 69808 in webkit


Ignore:
Timestamp:
Oct 14, 2010 3:16:34 PM (14 years ago)
Author:
commit-queue@webkit.org
Message:

2010-10-14 Dawit Alemayehu <adawit@kde.org>

Reviewed by Andreas Kling

Implemented NPN_GetValueForURL and NPN_SetValueForURL and NPN_GetAuthenticationInfo.
https://bugs.webkit.org/show_bug.cgi?id=34539

These missing NPN functions cause Java applets to crash in ports such
as QtWebkit that rely on webkit for Java applet support.

  • plugins/PluginDebug.cpp: (WebCore::prettyNameForNPNURLVariable):
  • plugins/PluginDebug.h:
  • plugins/PluginPackage.cpp: (WebCore::PluginPackage::initializeBrowserFuncs):
  • plugins/PluginView.cpp: (WebCore::PluginView::getValueForURL): (WebCore::PluginView::setValueForURL): (WebCore::PluginView::getAuthenticationInfo):
  • plugins/PluginView.h:
  • plugins/npapi.cpp: (NPN_GetValueForURL): (NPN_SetValueForURL): (NPN_GetAuthenticationInfo):
  • platform/network/ProxyServer.h:
  • platform/network/cf/ProxyServerCFNet.cpp: (WebCore::proxyServersForURL):
  • platform/network/qt/ProxyServerQt.cpp: (WebCore::proxyServersForURL):
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r69807 r69808  
     12010-10-14  Dawit Alemayehu  <adawit@kde.org>
     2
     3        Reviewed by Andreas Kling
     4
     5        Implemented NPN_GetValueForURL and NPN_SetValueForURL and NPN_GetAuthenticationInfo.
     6        https://bugs.webkit.org/show_bug.cgi?id=34539
     7
     8        These missing NPN functions cause Java applets to crash in ports such
     9        as QtWebkit that rely on webkit for Java applet support.
     10
     11        * plugins/PluginDebug.cpp:
     12        (WebCore::prettyNameForNPNURLVariable):
     13        * plugins/PluginDebug.h:
     14        * plugins/PluginPackage.cpp:
     15        (WebCore::PluginPackage::initializeBrowserFuncs):
     16        * plugins/PluginView.cpp:
     17        (WebCore::PluginView::getValueForURL):
     18        (WebCore::PluginView::setValueForURL):
     19        (WebCore::PluginView::getAuthenticationInfo):
     20        * plugins/PluginView.h:
     21        * plugins/npapi.cpp:
     22        (NPN_GetValueForURL):
     23        (NPN_SetValueForURL):
     24        (NPN_GetAuthenticationInfo):
     25        * platform/network/ProxyServer.h:
     26        * platform/network/cf/ProxyServerCFNet.cpp:
     27        (WebCore::proxyServersForURL):
     28        * platform/network/qt/ProxyServerQt.cpp:
     29        (WebCore::proxyServersForURL):
     30 
    1312010-10-14  Gavin Barraclough  <barraclough@apple.com>
    232
  • trunk/WebCore/platform/network/ProxyServer.h

    r68951 r69808  
    3333
    3434class KURL;
     35class NetworkingContext;
    3536
    3637// Represents a single proxy server.
     
    6869
    6970// Return a vector of proxy servers for the given URL.
    70 Vector<ProxyServer> proxyServersForURL(const KURL&);
     71Vector<ProxyServer> proxyServersForURL(const KURL&, const NetworkingContext*);
    7172
    7273// Converts the given vector of proxy servers to a PAC string, as described in
  • trunk/WebCore/platform/network/cf/ProxyServerCFNet.cpp

    r68951 r69808  
    8080}
    8181
    82 Vector<ProxyServer> proxyServersForURL(const KURL& url)
     82Vector<ProxyServer> proxyServersForURL(const KURL& url, const NetworkingContext*)
    8383{
    8484    Vector<ProxyServer> proxyServers;
  • trunk/WebCore/platform/network/qt/ProxyServerQt.cpp

    r68954 r69808  
    2727#include "ProxyServer.h"
    2828
    29 #include "NotImplemented.h"
    3029#include "KURL.h"
     30#include "NetworkingContext.h"
     31
     32#include <QNetworkAccessManager>
     33#include <QNetworkProxy>
     34#include <QNetworkProxyFactory>
     35#include <QNetworkProxyQuery>
     36#include <QUrl>
    3137
    3238namespace WebCore {
    3339
    34 Vector<ProxyServer> proxyServersForURL(const KURL&)
     40Vector<ProxyServer> proxyServersForURL(const KURL& url, const NetworkingContext* context)
    3541{
    36     notImplemented();
    37     return Vector<ProxyServer>();
     42    Vector<ProxyServer> servers;
     43   
     44    const QNetworkAccessManager* accessManager = context ? context->networkAccessManager() : 0;
     45    QNetworkProxyFactory* proxyFactory = accessManager ? accessManager->proxyFactory() : 0;
     46
     47    if (proxyFactory) {
     48        const QList<QNetworkProxy> proxies = proxyFactory->queryProxy(QNetworkProxyQuery(url));
     49        Q_FOREACH(const QNetworkProxy& proxy, proxies) {
     50            ProxyServer::Type proxyType;
     51            switch (proxy.type()) {
     52            case QNetworkProxy::Socks5Proxy:
     53                proxyType = ProxyServer::SOCKS;
     54                break;
     55            case QNetworkProxy::HttpProxy:
     56            case QNetworkProxy::HttpCachingProxy:
     57            case QNetworkProxy::FtpCachingProxy:
     58                proxyType = ProxyServer::HTTP;
     59                break;
     60            case QNetworkProxy::DefaultProxy:
     61            case QNetworkProxy::NoProxy:
     62            default:
     63                proxyType = ProxyServer::Direct;
     64                break;
     65            }
     66            servers.append(ProxyServer(proxyType, proxy.hostName(), proxy.port()));
     67        }
     68    }
     69
     70    return servers;
    3871}
    3972
  • trunk/WebCore/plugins/PluginDebug.cpp

    r46024 r69808  
    164164}
    165165
     166CString prettyNameForNPNURLVariable(NPNURLVariable variable)
     167{
     168    switch (variable) {
     169    case NPNURLVCookie: return "NPNURLVCookie";
     170    case NPNURLVProxy: return "NPNURLVProxy";
     171    default: return "Unknown variable";
     172    }
     173}
    166174} // namespace WebCore
    167175
  • trunk/WebCore/plugins/PluginDebug.h

    r56825 r69808  
    4242CString prettyNameForNPNVariable(NPNVariable variable);
    4343CString prettyNameForNPPVariable(NPPVariable variable, void* value);
     44CString prettyNameForNPNURLVariable(NPNURLVariable variable);
    4445
    4546#ifdef XP_MACOSX
  • trunk/WebCore/plugins/PluginPackage.cpp

    r69602 r69808  
    335335    m_browserFuncs.enumerate = _NPN_Enumerate;
    336336    m_browserFuncs.construct = _NPN_Construct;
     337    m_browserFuncs.getvalueforurl = NPN_GetValueForURL;
     338    m_browserFuncs.setvalueforurl = NPN_SetValueForURL;
     339    m_browserFuncs.getauthenticationinfo = NPN_GetAuthenticationInfo;
    337340}
    338341#endif
  • trunk/WebCore/plugins/PluginView.cpp

    r68970 r69808  
    3333#endif
    3434#include "Chrome.h"
     35#include "CookieJar.h"
    3536#include "Document.h"
    3637#include "DocumentLoader.h"
     
    5657#include "PluginMainThreadScheduler.h"
    5758#include "PluginPackage.h"
     59#include "ProxyServer.h"
    5860#include "RenderBox.h"
    5961#include "RenderObject.h"
     
    13931395    }
    13941396}
     1397
     1398static Frame* getFrame(Frame* parentFrame, Element* element)
     1399{
     1400    if (parentFrame)
     1401        return parentFrame;
     1402   
     1403    Document* document = element->document();
     1404    if (!document)
     1405        document = element->ownerDocument();
     1406    if (document)
     1407        return document->frame();
     1408   
     1409    return 0;
     1410}
     1411
     1412NPError PluginView::getValueForURL(NPNURLVariable variable, const char* url, char** value, uint32_t* len)
     1413{
     1414    LOG(Plugins, "PluginView::getValueForURL(%s)", prettyNameForNPNURLVariable(variable).data());
     1415
     1416    NPError result = NPERR_NO_ERROR;
     1417
     1418    switch (variable) {
     1419    case NPNURLVCookie: {
     1420        KURL u(m_baseURL, url);
     1421        if (u.isValid()) {
     1422            Frame* frame = getFrame(parentFrame(), m_element);
     1423            if (frame) {
     1424                const CString cookieStr = cookies(frame->document(), u).utf8();
     1425                if (!cookieStr.isNull()) {
     1426                    const int size = cookieStr.length();
     1427                    *value = static_cast<char*>(NPN_MemAlloc(size+1));
     1428                    if (*value) {
     1429                        memset(*value, 0, size+1);
     1430                        memcpy(*value, cookieStr.data(), size+1);
     1431                        if (len)
     1432                            *len = size;
     1433                    } else
     1434                        result = NPERR_OUT_OF_MEMORY_ERROR;
     1435                }
     1436            }
     1437        } else
     1438            result = NPERR_INVALID_URL;
     1439        break;
     1440    }
     1441    case NPNURLVProxy: {
     1442        KURL u(m_baseURL, url);
     1443        if (u.isValid()) {
     1444            Frame* frame = getFrame(parentFrame(), m_element);
     1445            const FrameLoader* frameLoader = frame ? frame->loader() : 0;
     1446            const NetworkingContext* context = frameLoader ? frameLoader->networkingContext() : 0;
     1447            const CString proxyStr = toString(proxyServersForURL(u, context)).utf8();
     1448            if (!proxyStr.isNull()) {
     1449                const int size = proxyStr.length();
     1450                *value = static_cast<char*>(NPN_MemAlloc(size+1));
     1451                if (*value) {
     1452                    memset(*value, 0, size+1);
     1453                    memcpy(*value, proxyStr.data(), size+1);
     1454                    if (len)
     1455                        *len = size;
     1456                } else
     1457                    result = NPERR_OUT_OF_MEMORY_ERROR;
     1458            }
     1459        } else
     1460            result = NPERR_INVALID_URL;
     1461        break;
     1462    }
     1463    default:
     1464        result = NPERR_GENERIC_ERROR;
     1465        LOG(Plugins, "PluginView::getValueForURL: %s", prettyNameForNPNURLVariable(variable).data());
     1466        break;
     1467    }
     1468
     1469    return result;
     1470}
     1471
     1472
     1473NPError PluginView::setValueForURL(NPNURLVariable variable, const char* url, const char* value, uint32_t len)
     1474{
     1475    LOG(Plugins, "PluginView::setValueForURL(%s)", prettyNameForNPNURLVariable(variable).data());
     1476
     1477    NPError result = NPERR_NO_ERROR;
     1478
     1479    switch (variable) {
     1480    case NPNURLVCookie: {
     1481        KURL u(m_baseURL, url);
     1482        if (u.isValid()) {
     1483            const String cookieStr = String::fromUTF8(value, len);
     1484            Frame* frame = getFrame(parentFrame(), m_element);
     1485            if (frame && !cookieStr.isEmpty())
     1486                setCookies(frame->document(), u, cookieStr);
     1487        } else
     1488            result = NPERR_INVALID_URL;
     1489        break;
     1490    }
     1491    case NPNURLVProxy:
     1492        LOG(Plugins, "PluginView::setValueForURL(%s): Plugins are NOT allowed to set proxy information.", prettyNameForNPNURLVariable(variable).data());
     1493        result = NPERR_GENERIC_ERROR;
     1494        break;
     1495    default:
     1496        LOG(Plugins, "PluginView::setValueForURL: %s", prettyNameForNPNURLVariable(variable).data());
     1497        result = NPERR_GENERIC_ERROR;
     1498        break;
     1499    }
     1500
     1501    return result;
     1502}
     1503
     1504NPError PluginView::getAuthenticationInfo(const char* protocol, const char* host, int32_t port, const char* scheme, const char* realm, char** username, uint32_t* ulen, char** password, uint32_t* plen)
     1505{
     1506    LOG(Plugins, "PluginView::getAuthenticationInfo: protocol=%s, host=%s, port=%d", protocol, host, port);
     1507    notImplemented();
     1508    return NPERR_GENERIC_ERROR;
     1509}
    13951510#endif
    13961511
  • trunk/WebCore/plugins/PluginView.h

    r69635 r69808  
    169169        static NPError getValueStatic(NPNVariable variable, void* value);
    170170        NPError setValue(NPPVariable variable, void* value);
     171        NPError getValueForURL(NPNURLVariable variable, const char* url, char** value, uint32_t* len);
     172        NPError setValueForURL(NPNURLVariable variable, const char* url, const char* value, uint32_t len);
     173        NPError getAuthenticationInfo(const char* protocol, const char* host, int32_t port, const char* scheme, const char* realm, char** username, uint32_t* ulen, char** password, uint32_t* plen);
    171174        void invalidateRect(NPRect*);
    172175        void invalidateRegion(NPRegion);
  • trunk/WebCore/plugins/npapi.cpp

    r60077 r69808  
    176176    PluginMainThreadScheduler::scheduler().scheduleCall(instance, func, userData);
    177177}
     178
     179NPError NPN_GetValueForURL(NPP instance, NPNURLVariable variable, const char* url, char** value, uint32_t* len)
     180{
     181    return pluginViewForInstance(instance)->getValueForURL(variable, url, value, len);
     182}
     183
     184NPError NPN_SetValueForURL(NPP instance, NPNURLVariable variable, const char* url, const char* value, uint32_t len)
     185{
     186    return pluginViewForInstance(instance)->setValueForURL(variable, url, value, len);
     187}
     188
     189NPError NPN_GetAuthenticationInfo(NPP instance, const char* protocol, const char* host, int32_t port, const char* scheme, const char* realm, char** username, uint32_t* ulen, char** password, uint32_t* plen)
     190{
     191    return pluginViewForInstance(instance)->getAuthenticationInfo(protocol, host, port, scheme, realm, username, ulen, password, plen);
     192}
  • trunk/WebKit/mac/Plugins/Hosted/NetscapePluginInstanceProxy.mm

    r68956 r69808  
    15591559        return false;
    15601560
    1561     Vector<ProxyServer> proxyServers = proxyServersForURL(url);
     1561    Vector<ProxyServer> proxyServers = proxyServersForURL(url, 0);
    15621562    WTF::CString proxyStringUTF8 = toString(proxyServers).utf8();
    15631563
  • trunk/WebKit/mac/Plugins/WebNetscapePluginView.mm

    r68951 r69808  
    22412241                break;
    22422242
    2243             Vector<ProxyServer> proxyServers = proxyServersForURL(URL);
     2243            Vector<ProxyServer> proxyServers = proxyServersForURL(URL, 0);
    22442244            CString proxiesUTF8 = toString(proxyServers).utf8();
    22452245           
  • trunk/WebKit2/WebProcess/Plugins/PluginView.cpp

    r68988 r69808  
    4242#include <WebCore/HostWindow.h>
    4343#include <WebCore/NetscapePlugInStreamLoader.h>
     44#include <WebCore/NetworkingContext.h>
    4445#include <WebCore/ProxyServer.h>
    4546#include <WebCore/RenderEmbeddedObject.h>
     
    842843String PluginView::proxiesForURL(const String& urlString)
    843844{
    844     Vector<ProxyServer> proxyServers = proxyServersForURL(KURL(KURL(), urlString));
     845    const FrameLoader* frameLoader = frame() ? frame()->loader() : 0;
     846    const NetworkingContext* context = frameLoader ? frameLoader->networkingContext() : 0;
     847    Vector<ProxyServer> proxyServers = proxyServersForURL(KURL(KURL(), urlString), context);
    845848    return toString(proxyServers);
    846849}
Note: See TracChangeset for help on using the changeset viewer.