Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Enumerations | Functions | Variables
LegacyPlugin.cpp File Reference
#include "stdafx.h"
#include "jni.h"
#include "npapi.h"
#include "nsISupports.h"
#include "LegacyPlugin.h"

Go to the source code of this file.

Classes

class  CInstallControlProgress

Defines

#define MIME_OLEOBJECT1   "application/x-oleobject"
#define MIME_OLEOBJECT2   "application/oleobject"

Enumerations

enum  MozAxPluginErrors { MozAxErrorControlIsNotSafeForScripting, MozAxErrorCouldNotCreateControl }

Functions

NPError NPP_Initialize (void)
void NPP_Shutdown (void)
jref NPP_GetJavaClass (void)
static void ShowError (MozAxPluginErrors errorCode, const CLSID &clsid)
static BOOL WillHandleCLSID (const CLSID &clsid, PluginInstanceData *pData)
static NPError CreateControl (const CLSID &clsid, PluginInstanceData *pData, PropertyList &pl, LPCOLESTR szCodebase)
static NPError NewControl (const char *pluginType, PluginInstanceData *pData, uint16 mode, int16 argc, char *argn[], char *argv[])
NPError NP_LOADDS NPP_New (NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char *argn[], char *argv[], NPSavedData *saved)
NPError NP_LOADDS NPP_Destroy (NPP instance, NPSavedData **save)
NPError NP_LOADDS NPP_SetWindow (NPP instance, NPWindow *window)
NPError NP_LOADDS NPP_NewStream (NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, uint16 *stype)
void NP_LOADDS NPP_StreamAsFile (NPP instance, NPStream *stream, const char *fname)
int32 NP_LOADDS NPP_WriteReady (NPP instance, NPStream *stream)
int32 NP_LOADDS NPP_Write (NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
NPError NP_LOADDS NPP_DestroyStream (NPP instance, NPStream *stream, NPError reason)
void NP_LOADDS NPP_Print (NPP instance, NPPrint *printInfo)
void NPP_URLNotify (NPP instance, const char *url, NPReason reason, void *notifyData)
NPError NP_LOADDS NPP_GetValue (NPP instance, NPPVariable variable, void *value)
NPError NP_LOADDS NPP_SetValue (NPP instance, NPNVariable variable, void *value)

Variables

const BOOL kHostSafeControlsOnly = FALSE
const BOOL kDownloadControlsIfMissing = FALSE
const BOOL kDisplayErrorMessages = FALSE
int32 STREAMBUFSIZE = 0X0FFFFFFF

Define Documentation

#define MIME_OLEOBJECT1   "application/x-oleobject"

Definition at line 267 of file LegacyPlugin.cpp.

#define MIME_OLEOBJECT2   "application/oleobject"

Definition at line 268 of file LegacyPlugin.cpp.


Enumeration Type Documentation

Enumerator:
MozAxErrorControlIsNotSafeForScripting 
MozAxErrorCouldNotCreateControl 

Definition at line 270 of file LegacyPlugin.cpp.


Function Documentation

static NPError CreateControl ( const CLSID &  clsid,
PluginInstanceData pData,
PropertyList pl,
LPCOLESTR  szCodebase 
) [static]

Definition at line 567 of file LegacyPlugin.cpp.

{
    // Make sure we got a CLSID we can handle
    if (!WillHandleCLSID(clsid, pData))
    {
        return NPERR_GENERIC_ERROR;
    }

    pData->clsid = clsid;

    // Set flags to specify if it is allowed to host safe or unsafe controls
    // and download them.
    PRBool hostSafeControlsOnly;
    PRBool downloadControlsIfMissing;
#if defined(MOZ_ACTIVEX_PLUGIN_XPCONNECT) && defined(XPC_IDISPATCH_SUPPORT)
    PRUint32 hostingFlags = MozAxPlugin::PrefGetHostingFlags();
    if (hostingFlags & nsIActiveXSecurityPolicy::HOSTING_FLAGS_HOST_SAFE_OBJECTS &&
        !(hostingFlags & nsIActiveXSecurityPolicy::HOSTING_FLAGS_HOST_ALL_OBJECTS))
    {
        hostSafeControlsOnly = TRUE;
    }
    else if (hostingFlags & nsIActiveXSecurityPolicy::HOSTING_FLAGS_HOST_ALL_OBJECTS)
    {
        hostSafeControlsOnly = FALSE;
    }
    else
    {
        // Plugin can host neither safe nor unsafe controls, so just return
        // without creating anything.
        return NPERR_GENERIC_ERROR;
    }
    if (hostingFlags & nsIActiveXSecurityPolicy::HOSTING_FLAGS_DOWNLOAD_CONTROLS)
    {
        downloadControlsIfMissing = PR_TRUE;
    }
    else
    {
        downloadControlsIfMissing = PR_FALSE;
    }
    // Ensure we can obtain the nsIDispatchSupport service
    nsCOMPtr<nsIDispatchSupport> dispSupport = do_GetService(NS_IDISPATCH_SUPPORT_CONTRACTID);
    if (!dispSupport)
    {
        return NPERR_GENERIC_ERROR;
    }
    // Now test if the CLSID is safe for scripting
    PRBool classIsMarkedSafeForScripting = PR_FALSE;
    if (hostSafeControlsOnly)
    {
        PRBool classExists = PR_FALSE;
        PRBool isClassSafeForScripting = PR_FALSE;
        nsCID cid;
        memcpy(&cid, &clsid, sizeof(cid));
        if (NS_SUCCEEDED(dispSupport->IsClassMarkedSafeForScripting(cid, &classExists, &isClassSafeForScripting)) &&
            classExists && isClassSafeForScripting)
        {
            classIsMarkedSafeForScripting = PR_TRUE;
        }
    }
#else
    hostSafeControlsOnly = kHostSafeControlsOnly;
    downloadControlsIfMissing = kDownloadControlsIfMissing;
#endif

    // Create the control site
    CControlSiteInstance *pSite = NULL;
    CControlSiteInstance::CreateInstance(&pSite);
    if (pSite == NULL)
    {
        return NPERR_GENERIC_ERROR;
    }

    pSite->m_bSupportWindowlessActivation = FALSE;
#if defined(MOZ_ACTIVEX_PLUGIN_XPCONNECT) && defined(XPC_IDISPATCH_SUPPORT)
    // We handle our own security further down
    pSite->SetSecurityPolicy(NULL);
    pSite->m_bSafeForScriptingObjectsOnly = FALSE;
#else
    pSite->m_bSafeForScriptingObjectsOnly = hostSafeControlsOnly;
#endif

    pSite->AddRef();

#ifdef MOZ_ACTIVEX_PLUGIN_XPCONNECT
    // Set up the service provider and container so the control can get hold
    // of the IE DOM and other interfaces
    CComPtr<IServiceProvider> sp;
    MozAxPlugin::GetServiceProvider(pData, &sp);
    if (sp)
        pSite->SetServiceProvider(sp);
    CComQIPtr<IOleContainer> container  = sp;
    if (container)
        pSite->SetContainer(container);
#endif

    // TODO check the object is installed and at least as recent as
    //      that specified in szCodebase

    // Create the object
    HRESULT hr;
    if (!downloadControlsIfMissing || !szCodebase)
    {
        hr = pSite->Create(clsid, pl);
    }
    else if (szCodebase)
    {
        CComObject<CInstallControlProgress> *pProgress = NULL;
        CComPtr<IBindCtx> spBindCtx;
        CComPtr<IBindStatusCallback> spOldBSC;
        CComObject<CInstallControlProgress>::CreateInstance(&pProgress);
        pProgress->AddRef();
        CreateBindCtx(0, &spBindCtx);
        RegisterBindStatusCallback(spBindCtx, dynamic_cast<IBindStatusCallback *>(pProgress), &spOldBSC, 0);

        hr = pSite->Create(clsid, pl, szCodebase, spBindCtx);
        if (hr == MK_S_ASYNCHRONOUS)
        {
            pProgress->mNPP = pData->pPluginInstance;
            pProgress->mBindingInProgress = TRUE;
            pProgress->mResult = E_FAIL;

            // Spin around waiting for binding to complete
            HANDLE hFakeEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
            while (pProgress->mBindingInProgress)
            {
                MSG msg;
                // Process pending messages
                while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
                {
                    if (!::GetMessage(&msg, NULL, 0, 0))
                    {
                        pProgress->mBindingInProgress = FALSE;
                        break;
                    }
                    ::TranslateMessage(&msg);
                    ::DispatchMessage(&msg);
                }
                if (!pProgress->mBindingInProgress)
                    break;
                // Sleep for a bit or the next msg to appear
                ::MsgWaitForMultipleObjects(1, &hFakeEvent, FALSE, 500, QS_ALLEVENTS);
            }
            ::CloseHandle(hFakeEvent);

            hr = pProgress->mResult;
            if (SUCCEEDED(hr))
            {
                hr = pSite->Create(clsid, pl);
            }
        }
        if (pProgress)
        {
            RevokeBindStatusCallback(spBindCtx, dynamic_cast<IBindStatusCallback *>(pProgress));
            pProgress->Release();
        }
    }
    if (FAILED(hr))
    {
        ShowError(MozAxErrorCouldNotCreateControl, clsid);
    }
#if defined(MOZ_ACTIVEX_PLUGIN_XPCONNECT) && defined(XPC_IDISPATCH_SUPPORT)
    if (SUCCEEDED(hr) && hostSafeControlsOnly && !classIsMarkedSafeForScripting)
    {
        CComPtr<IUnknown> cpUnk;
        pSite->GetControlUnknown(&cpUnk);
        nsIID iidDispatch;
        memcpy(&iidDispatch, &__uuidof(IDispatch), sizeof(nsIID));
        PRBool isObjectSafe = PR_FALSE;
        if (!cpUnk ||
            NS_FAILED(dispSupport->IsObjectSafeForScripting(
                reinterpret_cast<void *>(cpUnk.p), iidDispatch, &isObjectSafe)) ||
            !isObjectSafe)
        {
            pSite->Detach();
            hr = E_FAIL;
            ShowError(MozAxErrorControlIsNotSafeForScripting, clsid);
            // DROP THROUGH
        }
    }
#endif

    // Clean up if the control could not be created
    if (FAILED(hr))
    {
        pSite->Release();
        return NPERR_GENERIC_ERROR;
    }
    
#if defined(MOZ_ACTIVEX_PLUGIN_XPCONNECT) && defined(XPC_IDISPATCH_SUPPORT)
    // Hook up the event sink
    nsEventSinkInstance *pSink = NULL;
    nsEventSinkInstance::CreateInstance(&pSink);
    if (pSink)
    {
        pSink->AddRef();
        pSink->mPlugin = pData;
        CComPtr<IUnknown> control;
        pSite->GetControlUnknown(&control);
        pSink->SubscribeToEvents(control);
    }
    pData->pControlEventSink = pSink;
#endif
    pData->nType = itControl;
    pData->pControlSite = pSite;

    return NPERR_NO_ERROR;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static NPError NewControl ( const char *  pluginType,
PluginInstanceData pData,
uint16  mode,
int16  argc,
char *  argn[],
char *  argv[] 
) [static]

Definition at line 776 of file LegacyPlugin.cpp.

{
    // Read the parameters
    CLSID clsid = CLSID_NULL;
    CComBSTR codebase;
    PropertyList pl;

    if (strcmp(pluginType, MIME_OLEOBJECT1) != 0 &&
        strcmp(pluginType, MIME_OLEOBJECT2) != 0)
    {
        clsid = MozAxPlugin::GetCLSIDForType(pluginType);
    }

    for (int16 i = 0; i < argc; i++)
    {
        if (stricmp(argn[i], "CLSID") == 0 ||
            stricmp(argn[i], "CLASSID") == 0)
        {
            // Accept CLSIDs specified in various ways
            // e.g:
            //   "CLSID:C16DF970-D1BA-11d2-A252-000000000000"
            //   "C16DF970-D1BA-11d2-A252-000000000000"
            //   "{C16DF970-D1BA-11d2-A252-000000000000}"
            //
            // The first example is the proper way

            const int kCLSIDLen = 256;
            char szCLSID[kCLSIDLen];
            if (strlen(argv[i]) < sizeof(szCLSID))
            {
                if (strnicmp(argv[i], "CLSID:", 6) == 0)
                {
                    _snprintf(szCLSID, kCLSIDLen - 1, "{%s}", argv[i]+6);
                }
                else if(argv[i][0] != '{')
                {
                    _snprintf(szCLSID, kCLSIDLen - 1, "{%s}", argv[i]);
                }
                else
                {
                    strncpy(szCLSID, argv[i], kCLSIDLen - 1);
                }
                szCLSID[kCLSIDLen - 1] = '\0';
                USES_CONVERSION;
                CLSIDFromString(A2OLE(szCLSID), &clsid);
            }
        }
        else if (stricmp(argn[i], "CODEBASE") == 0)
        {
            codebase = argv[i];

#ifdef XPC_IDISPATCH_SUPPORT
            // resolve relative URLs on CODEBASE
            if (argv[i])
            {
                nsCOMPtr<nsIDOMElement> element;
                NPN_GetValue(pData->pPluginInstance, NPNVDOMElement, 
                             NS_STATIC_CAST(nsIDOMElement **, getter_AddRefs(element)));
                if (element)
                {
                    nsCOMPtr<nsIDOMNode> tagAsNode (do_QueryInterface(element));
                    if (tagAsNode)
                    {
                        nsCOMPtr<nsIDOMDocument> DOMdocument;
                        tagAsNode->GetOwnerDocument(getter_AddRefs(DOMdocument));
                        // XXX nsIDocument is not frozen!!!
                        nsCOMPtr<nsIDocument> doc(do_QueryInterface(DOMdocument));
                        if (doc)
                        {
                            nsIURI *baseURI = doc->GetBaseURI();
                            if (baseURI)
                            {
                                nsCAutoString newURL;
                                if (NS_SUCCEEDED(baseURI->Resolve(nsDependentCString(argv[i]), newURL)))
                                {
                                    codebase = newURL.get();
                                }
                            }
                        }
                    }
                }
            }
#endif

        }
        else 
        {
            CComBSTR paramName;
            if (strnicmp(argn[i], "PARAM_", 6) == 0)
            {
                paramName = argn[i] + 6;
            }
            else if (stricmp(argn[i], "PARAM") == 0)
            {
                // The next argn and argv values after this symbol
                // will be <param> tag names and values
                continue;
            }
            else
            {
                paramName = argn[i];
            }

            // Empty parameters are ignored
            if (!paramName.m_str || paramName.Length() == 0)
            {
                continue;
            }

            USES_CONVERSION;
            CComBSTR paramValue(A2W(argv[i]));

            // Check for existing params with the same name
            BOOL bFound = FALSE;
            for (unsigned long j = 0; j < pl.GetSize(); j++)
            {
                if (wcscmp(pl.GetNameOf(j), (BSTR) paramName) == 0)
                {
                    bFound = TRUE;
                    break;
                }
            }
            // If the parameter already exists, don't add it to the
            // list again.
            if (bFound)
            {
                continue;
            }

            // Add named parameter to list
            CComVariant v(paramValue);
            pl.AddNamedProperty(paramName, v);
        }
    }

    return CreateControl(clsid, pData, pl, codebase.m_str);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NPError NP_LOADDS NPP_Destroy ( NPP  instance,
NPSavedData **  save 
)

Definition at line 990 of file LegacyPlugin.cpp.

{
    ATLTRACE(_T("NPP_Destroy()\n"));

    PluginInstanceData *pData = (PluginInstanceData *) instance->pdata;
    if (pData == NULL)
    {
        return NPERR_INVALID_INSTANCE_ERROR;
    }

    if (pData->nType == itControl)
    {
        // Destroy the site
        CControlSiteInstance *pSite = pData->pControlSite;
        if (pSite)
        {
            pSite->Detach();
            pSite->Release();
        }
#if defined(MOZ_ACTIVEX_PLUGIN_XPCONNECT) && defined(XPC_IDISPATCH_SUPPORT)
        if (pData->pControlEventSink)
        {
            pData->pControlEventSink->UnsubscribeFromEvents();
            pData->pControlEventSink->Release();
        }
#endif
#ifdef MOZ_ACTIVEX_PLUGIN_XPCONNECT
        if (pData->pScriptingPeer)
        {
            pData->pScriptingPeer->Release();
        }
#endif
    }
    else if (pData->nType == itScript)
    {
        // TODO
    }

    if (pData->szUrl)
        free(pData->szUrl);
    if (pData->szContentType)
        free(pData->szContentType);
    delete pData;
#ifdef MOZ_ACTIVEX_PLUGIN_XPCONNECT
    MozAxPlugin::Release();
#endif

    instance->pdata = 0;

    return NPERR_NO_ERROR;

}

Here is the caller graph for this function:

NPError NP_LOADDS NPP_DestroyStream ( NPP  instance,
NPStream stream,
NPError  reason 
)

Definition at line 1212 of file LegacyPlugin.cpp.

{
    // because I am handling the stream as a file, I don't do anything here...
    // If I was streaming, I would know that I was done and do anything appropriate
    // to the end of the stream...   
    return NPERR_NO_ERROR;
}

Here is the caller graph for this function:

Definition at line 258 of file LegacyPlugin.cpp.

{
    ATLTRACE(_T("NPP_GetJavaClass()\n"));
#ifdef MOZ_ACTIVEX_PLUGIN_LIVECONNECT
    return liveconnect_GetJavaClass();
#endif
    return NULL;
}

Here is the caller graph for this function:

NPError NP_LOADDS NPP_GetValue ( NPP  instance,
NPPVariable  variable,
void value 
)

Definition at line 1271 of file LegacyPlugin.cpp.

{
    NPError rv = NPERR_GENERIC_ERROR;
#ifdef MOZ_ACTIVEX_PLUGIN_XPCONNECT
    rv = MozAxPlugin::GetValue(instance, variable, value);
#endif
    return rv;
}

Here is the caller graph for this function:

Definition at line 232 of file LegacyPlugin.cpp.

{
    ATLTRACE(_T("NPP_Initialize()\n"));
    _Module.Lock();
    return NPERR_NO_ERROR;
}

Here is the caller graph for this function:

NPError NP_LOADDS NPP_New ( NPMIMEType  pluginType,
NPP  instance,
uint16  mode,
int16  argc,
char *  argn[],
char *  argv[],
NPSavedData saved 
)

Definition at line 925 of file LegacyPlugin.cpp.

{
    ATLTRACE(_T("NPP_New()\n"));

    // trap duff args
    if (instance == NULL)
    {
        return NPERR_INVALID_INSTANCE_ERROR;
    }

    PluginInstanceData *pData = new PluginInstanceData;
    if (pData == NULL)
    {
        return NPERR_GENERIC_ERROR;
    }
    pData->pPluginInstance = instance;
    pData->szUrl = NULL;
    pData->szContentType = (pluginType) ? strdup(pluginType) : NULL;
#ifdef MOZ_ACTIVEX_PLUGIN_XPCONNECT
    pData->pScriptingPeer = NULL;
#endif

    // Create a plugin according to the mime type
#ifdef MOZ_ACTIVEX_PLUGIN_XPCONNECT
    MozAxPlugin::AddRef();
#endif

    NPError rv = NPERR_GENERIC_ERROR;
    /* if (strcmp(pluginType, MIME_OLEOBJECT1) == 0 ||
           strcmp(pluginType, MIME_OLEOBJECT2) == 0) */
    {
        rv = NewControl(pluginType, pData, mode, argc, argn, argv);
    }

    // Test if plugin creation has succeeded and cleanup if it hasn't
    if (rv != NPERR_NO_ERROR)
    {
        if (pData->szContentType)
            free(pData->szContentType);
        if (pData->szUrl)
            free(pData->szUrl);
        delete pData;
#ifdef MOZ_ACTIVEX_PLUGIN_XPCONNECT
        MozAxPlugin::Release();
#endif
        return rv;
    }

    instance->pdata = pData;

    return NPERR_NO_ERROR;
}

Here is the caller graph for this function:

NPError NP_LOADDS NPP_NewStream ( NPP  instance,
NPMIMEType  type,
NPStream stream,
NPBool  seekable,
uint16 stype 
)

Definition at line 1128 of file LegacyPlugin.cpp.

{
    ATLTRACE(_T("NPP_NewStream()\n"));

    if(!instance)
    {
        return NPERR_INVALID_INSTANCE_ERROR;
    }

    // save the plugin instance object in the stream instance
    stream->pdata = instance->pdata;
    *stype = NP_ASFILE;
    return NPERR_NO_ERROR;
}

Here is the caller graph for this function:

void NP_LOADDS NPP_Print ( NPP  instance,
NPPrint printInfo 
)

Definition at line 1226 of file LegacyPlugin.cpp.

{
    if(printInfo == NULL)   // trap invalid parm
    {
        return;
    }

//    if (instance != NULL) {
//        CPluginWindow* pluginData = (CPluginWindow*) instance->pdata;
//        pluginData->Print(printInfo);
//    }
}

Here is the caller graph for this function:

NPError NP_LOADDS NPP_SetValue ( NPP  instance,
NPNVariable  variable,
void value 
)

Definition at line 1281 of file LegacyPlugin.cpp.

{
    return NPERR_GENERIC_ERROR;
}

Here is the caller graph for this function:

NPError NP_LOADDS NPP_SetWindow ( NPP  instance,
NPWindow window 
)

Definition at line 1061 of file LegacyPlugin.cpp.

{
    ATLTRACE(_T("NPP_SetWindow()\n"));

    // Reject silly parameters
    if (!window)
    {
        return NPERR_GENERIC_ERROR;
    }

    PluginInstanceData *pData = (PluginInstanceData *) instance->pdata;
    if (pData == NULL)
    {
        return  NPERR_INVALID_INSTANCE_ERROR;
    }

    if (pData->nType == itControl)
    {
        CControlSiteInstance *pSite = pData->pControlSite;
        if (pSite == NULL)
        {
            return NPERR_GENERIC_ERROR;
        }

        HWND hwndParent = (HWND) window->window;
        if (hwndParent)
        {
            RECT rcPos;
            GetClientRect(hwndParent, &rcPos);

            if (pSite->GetParentWindow() == NULL)
            {
                pSite->Attach(hwndParent, rcPos, NULL);
            }
            else
            {
                pSite->SetPosition(rcPos);
            }

            // Ensure clipping on parent to keep child controls happy
            ::SetWindowLong(hwndParent, GWL_STYLE,
                ::GetWindowLong(hwndParent, GWL_STYLE) | WS_CLIPCHILDREN);
        }
    }

    return NPERR_NO_ERROR;
}

Here is the caller graph for this function:

Definition at line 244 of file LegacyPlugin.cpp.

{
    ATLTRACE(_T("NPP_Shutdown()\n"));
#ifdef MOZ_ACTIVEX_PLUGIN_LIVECONNECT
    liveconnect_Shutdown();
#endif
    _Module.Unlock();
}

Here is the caller graph for this function:

void NP_LOADDS NPP_StreamAsFile ( NPP  instance,
NPStream stream,
const char *  fname 
)

Definition at line 1154 of file LegacyPlugin.cpp.

{
    ATLTRACE(_T("NPP_StreamAsFile()\n"));

    if(fname == NULL || fname[0] == NULL)
    {
        return;
    }
}

Here is the caller graph for this function:

void NPP_URLNotify ( NPP  instance,
const char *  url,
NPReason  reason,
void notifyData 
)

Definition at line 1259 of file LegacyPlugin.cpp.

{
    PluginInstanceData *pData = (PluginInstanceData *) instance->pdata;
    if (pData)
    {
        if (pData->szUrl)
            free(pData->szUrl);
        pData->szUrl = strdup(url);
    }
}

Here is the caller graph for this function:

int32 NP_LOADDS NPP_Write ( NPP  instance,
NPStream stream,
int32  offset,
int32  len,
void buffer 
)

Definition at line 1198 of file LegacyPlugin.cpp.

{   
    return len;
}

Here is the caller graph for this function:

int32 NP_LOADDS NPP_WriteReady ( NPP  instance,
NPStream stream 
)

Definition at line 1187 of file LegacyPlugin.cpp.

{
    return STREAMBUFSIZE;  
}

Here is the caller graph for this function:

static void ShowError ( MozAxPluginErrors  errorCode,
const CLSID &  clsid 
) [static]

Definition at line 277 of file LegacyPlugin.cpp.

{
    if (!kDisplayErrorMessages)
        return;

    const TCHAR *szMsg = NULL;
    const unsigned long kBufSize = 256;
    TCHAR szBuffer[kBufSize];

    // TODO errors are hardcoded for now
    switch (errorCode)
    {
    case MozAxErrorControlIsNotSafeForScripting:
        {
            USES_CONVERSION;
            LPOLESTR szClsid;
            StringFromCLSID(clsid, &szClsid);
            _sntprintf(szBuffer, kBufSize - 1,
                _T("Could not create the control %s because it is not marked safe for scripting."), OLE2T(szClsid));
            CoTaskMemFree(szClsid);
            szMsg = szBuffer;
        }
        break;
    case MozAxErrorCouldNotCreateControl:
        {
            USES_CONVERSION;
            LPOLESTR szClsid;
            StringFromCLSID(clsid, &szClsid);
            _sntprintf(szBuffer, kBufSize - 1,
                _T("Could not create the control %s. Check that it has been installed on your computer "
                   "and that this page correctly references it."), OLE2T(szClsid));
            CoTaskMemFree(szClsid);
            szMsg = szBuffer;
        }
        break;
    }
    szBuffer[kBufSize - 1] = TCHAR('\0');
    if (szMsg)
        MessageBox(NULL, szMsg, _T("ActiveX Error"), MB_OK | MB_ICONWARNING);
}

Here is the caller graph for this function:

static BOOL WillHandleCLSID ( const CLSID &  clsid,
PluginInstanceData pData 
) [static]

Definition at line 452 of file LegacyPlugin.cpp.

{
#if defined(MOZ_ACTIVEX_PLUGIN_XPCONNECT) && defined(XPC_IDISPATCH_SUPPORT)
    // Ensure the control is safe for scripting
    nsCOMPtr<nsIDispatchSupport> dispSupport = do_GetService(NS_IDISPATCH_SUPPORT_CONTRACTID);
    if (!dispSupport)
        return FALSE;
    JSContext * cx = GetPluginsContext(pData);
    if (!cx)
        return FALSE;
    nsCID cid;
    memcpy(&cid, &clsid, sizeof(nsCID));
    PRBool isSafe = PR_FALSE;
    PRBool classExists = PR_FALSE;
    nsCOMPtr<nsIURI> uri;
    MozAxPlugin::GetCurrentLocation(pData->pPluginInstance, getter_AddRefs(uri));
    MozAxAutoPushJSContext autoContext(cx, uri);
    dispSupport->IsClassSafeToHost(cx, cid, PR_TRUE, &classExists, &isSafe);
    if (classExists && !isSafe)
        return FALSE;
    return TRUE;
#else
    if (::IsEqualCLSID(clsid, CLSID_NULL))
    {
        return FALSE;
    }

    // Check the Internet Explorer list of vulnerable controls
    CRegKey keyExplorer;
    if (keyExplorer.Open(HKEY_LOCAL_MACHINE,
        _T("SOFTWARE\\Microsoft\\Internet Explorer\\ActiveX Compatibility"), KEY_READ) == ERROR_SUCCESS)
    {
        LPOLESTR szCLSID = NULL;
        ::StringFromCLSID(clsid, &szCLSID);
        if (szCLSID)
        {
            CRegKey keyCLSID;
            USES_CONVERSION;
            if (keyCLSID.Open(keyExplorer, W2T(szCLSID), KEY_READ) == ERROR_SUCCESS)
            {
                DWORD dwType = REG_DWORD;
                DWORD dwFlags = 0;
                DWORD dwBufSize = sizeof(dwFlags);
                if (::RegQueryValueEx(keyCLSID, _T("Compatibility Flags"),
                    NULL, &dwType, (LPBYTE) &dwFlags, &dwBufSize) == ERROR_SUCCESS)
                {
                    // Flags for this reg key
                    const DWORD kKillBit = 0x00000400;
                    if (dwFlags & kKillBit)
                    {
                        ::CoTaskMemFree(szCLSID);
                        return FALSE;
                    }
                }
            }
            ::CoTaskMemFree(szCLSID);
        }
    }

    // Check if the CLSID belongs to a list that the plugin does not support
    CRegKey keyDeny;
    if (keyDeny.Open(HKEY_LOCAL_MACHINE, kControlsToDenyKey, KEY_READ) == ERROR_SUCCESS)
    {
        // Enumerate CLSIDs looking for this one
        int i = 0;
        do {
            USES_CONVERSION;
            TCHAR szCLSID[64];
            const DWORD nLength = sizeof(szCLSID) / sizeof(szCLSID[0]);
            if (::RegEnumKey(keyDeny, i++, szCLSID, nLength) != ERROR_SUCCESS)
            {
                break;
            }
            szCLSID[nLength - 1] = TCHAR('\0');
            CLSID clsidToCompare = GUID_NULL;
            if (SUCCEEDED(::CLSIDFromString(T2OLE(szCLSID), &clsidToCompare)) &&
                ::IsEqualCLSID(clsid, clsidToCompare))
            {
                return FALSE;
            }
        } while (1);
        keyDeny.Close();
    }

    // Check if the CLSID belongs to a list that the plugin only supports
    CRegKey keyAllow;
    if (keyAllow.Open(HKEY_LOCAL_MACHINE, kControlsToAllowKey, KEY_READ) == ERROR_SUCCESS)
    {
        // Enumerate CLSIDs looking for this one
        int i = 0;
        do {
            USES_CONVERSION;
            TCHAR szCLSID[64];
            const DWORD nLength = sizeof(szCLSID) / sizeof(szCLSID[0]);
            if (::RegEnumKey(keyAllow, i, szCLSID, nLength) != ERROR_SUCCESS)
            {
                // An empty list means all controls are allowed.
                return (i == 0) ? TRUE : FALSE;
            }
            ++i;
            szCLSID[nLength - 1] = TCHAR('\0');
            CLSID clsidToCompare = GUID_NULL;
            if (SUCCEEDED(::CLSIDFromString(T2OLE(szCLSID), &clsidToCompare)) &&
                ::IsEqualCLSID(clsid, clsidToCompare))
            {
                return TRUE;
            }
        } while (1);
    }

    return TRUE;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 85 of file LegacyPlugin.cpp.

Definition at line 80 of file LegacyPlugin.cpp.

Definition at line 77 of file LegacyPlugin.cpp.

int32 STREAMBUFSIZE = 0X0FFFFFFF

Definition at line 1176 of file LegacyPlugin.cpp.