Changeset 86578 in webkit


Ignore:
Timestamp:
May 16, 2011 9:34:09 AM (13 years ago)
Author:
andersca@apple.com
Message:

2011-05-16 Anders Carlsson <andersca@apple.com>

Reviewed by Oliver Hunt.

Short-circuit NPRuntime calls made by Flash during plug-in instantiation
https://bugs.webkit.org/show_bug.cgi?id=60894
<rdar://problem/8804681>

During plug-in instantiation, Flash makes a couple of NPRuntime calls to get the
URL of the current document as well as the URL of the toplevel document. This leads to
a bunch of IPC traffic that slows down instantiation.

Since we know what calls Flash is making and what results are expected, we can handle the
NPRuntime calls directly in the plug-in process and avoid extra IPC overhead.

  • PluginProcess/PluginControllerProxy.cpp: (WebKit::PluginControllerProxy::PluginControllerProxy): Initialize m_pluginCreationParameters.

(WebKit::PluginControllerProxy::initialize):
Set m_pluginCreationParameters to point to the creation parameters right before
calling Plugin::initialize and restore it back afterwards.

(WebKit::PluginControllerProxy::tryToShortCircuitInvoke):
If the plug-in calling NPN_Invoke has the CanShortCircuitSomeNPRuntimeCallsDuringInitialization
quirk, and we're being initialized, check for the flash_getWindowLocation and
flash_getTopLocation function calls and return the correct values.

(WebKit::PluginControllerProxy::tryToShortCircuitEvaluate):
Check if the script string has the definitions of flash_getWindowLocation or flash_getTopLocation
and just ignore them. Note that ignoring them has the effect of not adding them to the window object,
which could in theory be a backwards compatibility problem if web pages were to assume that these
functions existed on a page with plug-ins. In practice this is probably not a problem, especially since
these functions are only used on Mac WebKit.

  • PluginProcess/PluginControllerProxy.h: (WebKit::PluginControllerProxy::inInitialize): Add helper function.
  • Shared/Plugins/Netscape/mac/NetscapePluginModuleMac.mm: (WebKit::NetscapePluginModule::determineQuirks): Add the CanShortCircuitSomeNPRuntimeCallsDuringInitialization quirk for Flash on Mac.
  • Shared/Plugins/PluginQuirks.h: Add Mac specific CanShortCircuitSomeNPRuntimeCallsDuringInitialization quirk.
Location:
trunk/Source/WebKit2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r86577 r86578  
     12011-05-16  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Short-circuit NPRuntime calls made by Flash during plug-in instantiation
     6        https://bugs.webkit.org/show_bug.cgi?id=60894
     7        <rdar://problem/8804681>
     8
     9        During plug-in instantiation, Flash makes a couple of NPRuntime calls to get the
     10        URL of the current document as well as the URL of the toplevel document. This leads to
     11        a bunch of IPC traffic that slows down instantiation.
     12
     13        Since we know what calls Flash is making and what results are expected, we can handle the
     14        NPRuntime calls directly in the plug-in process and avoid extra IPC overhead.
     15
     16        * PluginProcess/PluginControllerProxy.cpp:
     17        (WebKit::PluginControllerProxy::PluginControllerProxy):
     18        Initialize m_pluginCreationParameters.
     19
     20        (WebKit::PluginControllerProxy::initialize):
     21        Set m_pluginCreationParameters to point to the creation parameters right before
     22        calling Plugin::initialize and restore it back afterwards.
     23
     24        (WebKit::PluginControllerProxy::tryToShortCircuitInvoke):
     25        If the plug-in calling NPN_Invoke has the CanShortCircuitSomeNPRuntimeCallsDuringInitialization
     26        quirk, and we're being initialized, check for the __flash_getWindowLocation and
     27        __flash_getTopLocation function calls and return the correct values.
     28
     29        (WebKit::PluginControllerProxy::tryToShortCircuitEvaluate):
     30        Check if the script string has the definitions of __flash_getWindowLocation or __flash_getTopLocation
     31        and just ignore them. Note that ignoring them has the effect of not adding them to the window object,
     32        which could in theory be a backwards compatibility problem if web pages were to assume that these
     33        functions existed on a page with plug-ins. In practice this is probably not a problem, especially since
     34        these functions are only used on Mac WebKit.
     35
     36        * PluginProcess/PluginControllerProxy.h:
     37        (WebKit::PluginControllerProxy::inInitialize):
     38        Add helper function.
     39
     40        * Shared/Plugins/Netscape/mac/NetscapePluginModuleMac.mm:
     41        (WebKit::NetscapePluginModule::determineQuirks):
     42        Add the CanShortCircuitSomeNPRuntimeCallsDuringInitialization quirk for Flash on Mac.
     43
     44        * Shared/Plugins/PluginQuirks.h:
     45        Add Mac specific CanShortCircuitSomeNPRuntimeCallsDuringInitialization quirk.
     46
    1472011-05-16  Anders Carlsson  <andersca@apple.com>
    248
  • trunk/Source/WebKit2/PluginProcess/PluginControllerProxy.cpp

    r86577 r86578  
    4242#include "WebProcessConnection.h"
    4343#include <WebCore/GraphicsContext.h>
     44#include <WebCore/IdentifierRep.h>
    4445#include <WebCore/NotImplemented.h>
    4546#include <wtf/text/WTFString.h>
     
    6566    , m_pluginDestructionProtectCount(0)
    6667    , m_pluginDestroyTimer(RunLoop::main(), this, &PluginControllerProxy::destroy)
     68    , m_pluginCreationParameters(0)
    6769    , m_waitingForDidUpdate(false)
    6870    , m_pluginCanceledManualStreamLoad(false)
     
    100102    ASSERT(m_windowNPObject);
    101103
    102     if (!m_plugin->initialize(this, creationParameters.parameters)) {
     104    m_pluginCreationParameters = &creationParameters;
     105    bool returnValue = m_plugin->initialize(this, creationParameters.parameters);
     106    m_pluginCreationParameters = 0;
     107
     108    if (!returnValue) {
    103109        // Get the plug-in so we can pass it to removePluginControllerProxy. The pointer is only
    104110        // used as an identifier so it's OK to just get a weak reference.
     
    282288}
    283289
    284 bool PluginControllerProxy::tryToShortCircuitInvoke(NPObject*, NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, bool& returnValue, NPVariant& result)
    285 {
     290bool PluginControllerProxy::tryToShortCircuitInvoke(NPObject* npObject, NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, bool& returnValue, NPVariant& result)
     291{
     292    // Only try to short circuit evaluate for plug-ins that have the quirk specified.
     293    if (!PluginProcess::shared().netscapePluginModule()->pluginQuirks().contains(PluginQuirks::CanShortCircuitSomeNPRuntimeCallsDuringInitialization))
     294        return false;
     295   
     296    // And only when we're in initialize.
     297    if (!inInitialize())
     298        return false;
     299   
     300    // And only when the NPObject is the window NPObject.
     301    if (npObject != m_windowNPObject)
     302        return false;
     303
     304    // And only when we don't have any arguments.
     305    if (argumentCount)
     306        return false;
     307
     308    IdentifierRep* methodNameRep = static_cast<IdentifierRep*>(methodName);
     309    if (!methodNameRep->isString())
     310        return false;
     311
     312    if (!strcmp(methodNameRep->string(), "__flash_getWindowLocation")) {
     313        result.type = NPVariantType_String;
     314        result.value.stringValue = createNPString(m_pluginCreationParameters->parameters.documentURL.utf8());
     315        returnValue = true;
     316        return true;
     317    }
     318   
     319    if (!strcmp(methodNameRep->string(), "__flash_getTopLocation")) {
     320        if (m_pluginCreationParameters->parameters.toplevelDocumentURL.isNull()) {
     321            // If the toplevel document is URL it means that the frame that the plug-in is in doesn't have access to the toplevel document.
     322            returnValue = false;
     323            return true;
     324        }
     325
     326        result.type = NPVariantType_String;
     327        result.value.stringValue = createNPString(m_pluginCreationParameters->parameters.toplevelDocumentURL.utf8());
     328        returnValue = true;
     329        return true;
     330    }
     331
    286332    return false;
    287333}
     
    543589bool PluginControllerProxy::tryToShortCircuitEvaluate(NPObject* npObject, const String& scriptString, NPVariant* result)
    544590{
    545     return false;
     591    // Only try to short circuit evaluate for plug-ins that have the quirk specified.
     592    if (!PluginProcess::shared().netscapePluginModule()->pluginQuirks().contains(PluginQuirks::CanShortCircuitSomeNPRuntimeCallsDuringInitialization))
     593        return false;
     594
     595    // And only when we're in initialize.
     596    if (!inInitialize())
     597        return false;
     598
     599    // And only when the NPObject is the window NPObject.
     600    if (npObject != m_windowNPObject)
     601        return false;
     602
     603    // Now, check for the right strings.
     604    if (scriptString != "function __flash_getWindowLocation() { return window.location; }"
     605        && scriptString != "function __flash_getTopLocation() { return top.location; }")
     606        return false;
     607
     608    VOID_TO_NPVARIANT(*result);
     609    return true;
    546610}
    547611
  • trunk/Source/WebKit2/PluginProcess/PluginControllerProxy.h

    r86577 r86578  
    144144    bool tryToShortCircuitEvaluate(NPObject*, const String& scriptString, NPVariant* result);
    145145
     146    bool inInitialize() const { return m_pluginCreationParameters; }
     147
    146148    void platformInitialize();
    147149    void platformDestroy();
     
    174176    RunLoop::Timer<PluginControllerProxy> m_pluginDestroyTimer;
    175177
     178    // Will point to the plug-in creation parameters of the plug-in we're currently initializing and will be null when we're done initializing.
     179    const PluginCreationParameters* m_pluginCreationParameters;
     180
    176181    // Whether we're waiting for the plug-in proxy in the web process to draw the contents of its
    177182    // backing store into the web process backing store.
  • trunk/Source/WebKit2/Shared/Plugins/Netscape/mac/NetscapePluginModuleMac.mm

    r86097 r86578  
    416416        // Flash supports snapshotting.
    417417        m_pluginQuirks.add(PluginQuirks::SupportsSnapshotting);
     418
     419        // We can short circuit some NPRuntime calls during initialization.
     420        m_pluginQuirks.add(PluginQuirks::CanShortCircuitSomeNPRuntimeCallsDuringInitialization);
    418421    }
    419422
  • trunk/Source/WebKit2/Shared/Plugins/PluginQuirks.h

    r86494 r86578  
    4848        // transparent.
    4949        MakeTransparentIfBackgroundAttributeExists,
     50
     51        // Whether we can short circuit some NPRuntime calls during plug-in initialization.
     52        // The Flash plug-in uses NPRuntime to figure out the URL of the frame it is in, as well
     53        // as the URL of the main frame. Since we know the exact NPRuntime calls the plug-in makes,
     54        // we can return the right values without having to do sync IPC back into the web process.
     55        CanShortCircuitSomeNPRuntimeCallsDuringInitialization,
    5056
    5157#ifndef NP_NO_QUICKDRAW
Note: See TracChangeset for help on using the changeset viewer.