WebKit2/WebProcess/Plugins/Netscape/NetscapePluginModule.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2010 Apple Inc. All rights reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions
       
     6  * are met:
       
     7  * 1. Redistributions of source code must retain the above copyright
       
     8  *    notice, this list of conditions and the following disclaimer.
       
     9  * 2. Redistributions in binary form must reproduce the above copyright
       
    10  *    notice, this list of conditions and the following disclaimer in the
       
    11  *    documentation and/or other materials provided with the distribution.
       
    12  *
       
    13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
       
    14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
       
    15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
       
    16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
       
    17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
       
    18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
       
    19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
       
    20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
       
    21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
       
    22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
       
    23  * THE POSSIBILITY OF SUCH DAMAGE.
       
    24  */
       
    25 
       
    26 #include "NetscapePluginModule.h"
       
    27 
       
    28 using namespace WebCore;
       
    29 
       
    30 namespace WebKit {
       
    31 
       
    32 static Vector<NetscapePluginModule*>& initializedNetscapePluginModules()
       
    33 {
       
    34     DEFINE_STATIC_LOCAL(Vector<NetscapePluginModule*>, initializedNetscapePluginModules, ());
       
    35     return initializedNetscapePluginModules;
       
    36 }
       
    37 
       
    38 NetscapePluginModule::NetscapePluginModule(const String& pluginPath)
       
    39     : m_pluginPath(pluginPath)
       
    40     , m_isInitialized(false)
       
    41     , m_pluginCount(0)
       
    42     , m_shutdownProcPtr(0)
       
    43     , m_pluginFuncs()
       
    44 {
       
    45 }
       
    46 
       
    47 NetscapePluginModule::~NetscapePluginModule()
       
    48 {
       
    49     ASSERT(initializedNetscapePluginModules().find(this) == notFound);
       
    50 }
       
    51 
       
    52 void NetscapePluginModule::pluginCreated()
       
    53 {
       
    54     m_pluginCount++;
       
    55 }
       
    56 
       
    57 void NetscapePluginModule::pluginDestroyed()
       
    58 {
       
    59     ASSERT(m_pluginCount > 0);
       
    60     m_pluginCount--;
       
    61     
       
    62     if (!m_pluginCount)
       
    63         shutdown();
       
    64 }
       
    65 
       
    66 void NetscapePluginModule::shutdown()
       
    67 {
       
    68     ASSERT(m_isInitialized);
       
    69 
       
    70     m_shutdownProcPtr();
       
    71 
       
    72     size_t pluginModuleIndex = initializedNetscapePluginModules().find(this);
       
    73     ASSERT(pluginModuleIndex != notFound);
       
    74     
       
    75     initializedNetscapePluginModules().remove(pluginModuleIndex);
       
    76 }
       
    77 
       
    78 PassRefPtr<NetscapePluginModule> NetscapePluginModule::getOrCreate(const String& pluginPath)
       
    79 {
       
    80     // First, see if we already have a module with this plug-in path.
       
    81     for (size_t i = 0; i < initializedNetscapePluginModules().size(); ++i) {
       
    82         NetscapePluginModule* pluginModule = initializedNetscapePluginModules()[i];
       
    83 
       
    84         if (pluginModule->m_pluginPath == pluginPath)
       
    85             return pluginModule;
       
    86     }
       
    87 
       
    88     RefPtr<NetscapePluginModule> pluginModule(adoptRef(new NetscapePluginModule(pluginPath)));
       
    89     
       
    90     // Try to load and initialize the plug-in module.
       
    91     if (!pluginModule->load())
       
    92         return 0;
       
    93     
       
    94     return pluginModule.release();
       
    95 }
       
    96 
       
    97 bool NetscapePluginModule::load()
       
    98 {
       
    99     if (!tryLoad()) {
       
   100         unload();
       
   101         return false;
       
   102     }
       
   103     
       
   104     m_isInitialized = true;
       
   105 
       
   106     ASSERT(initializedNetscapePluginModules().find(this) == notFound);
       
   107     initializedNetscapePluginModules().append(this);
       
   108 
       
   109     return true;
       
   110 }
       
   111 
       
   112 } // namespace WebKit
       
   113