Home | History | Annotate | Download | only in Plugins
      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 #ifndef PluginProcessProxy_h
     27 #define PluginProcessProxy_h
     28 
     29 #if ENABLE(PLUGIN_PROCESS)
     30 
     31 #include "Connection.h"
     32 #include "PluginInfoStore.h"
     33 #include "ProcessLauncher.h"
     34 #include "WebProcessProxyMessages.h"
     35 #include <wtf/Deque.h>
     36 
     37 #if PLATFORM(MAC)
     38 #include <wtf/RetainPtr.h>
     39 OBJC_CLASS NSObject;
     40 OBJC_CLASS WKPlaceholderModalWindow;
     41 #endif
     42 
     43 // FIXME: This is platform specific.
     44 namespace CoreIPC {
     45     class MachPort;
     46 }
     47 
     48 namespace WebKit {
     49 
     50 class PluginProcessManager;
     51 class WebPluginSiteDataManager;
     52 class WebProcessProxy;
     53 struct PluginProcessCreationParameters;
     54 
     55 class PluginProcessProxy : CoreIPC::Connection::Client, ProcessLauncher::Client {
     56 public:
     57 #if PLATFORM(MAC)
     58     static bool pluginNeedsExecutableHeap(const PluginInfoStore::Plugin&);
     59 #endif
     60     static PassOwnPtr<PluginProcessProxy> create(PluginProcessManager*, const PluginInfoStore::Plugin&);
     61     ~PluginProcessProxy();
     62 
     63     const PluginInfoStore::Plugin& pluginInfo() const { return m_pluginInfo; }
     64 
     65     // Asks the plug-in process to create a new connection to a web process. The connection identifier will be
     66     // encoded in the given argument encoder and sent back to the connection of the given web process.
     67     void getPluginProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply>);
     68 
     69     // Asks the plug-in process to get a list of domains for which the plug-in has data stored.
     70     void getSitesWithData(WebPluginSiteDataManager*, uint64_t callbackID);
     71 
     72     // Asks the plug-in process to clear the data for the given sites.
     73     void clearSiteData(WebPluginSiteDataManager*, const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID);
     74 
     75     // Terminates the plug-in process.
     76     void terminate();
     77 
     78 private:
     79     PluginProcessProxy(PluginProcessManager*, const PluginInfoStore::Plugin&);
     80 
     81     void pluginProcessCrashedOrFailedToLaunch();
     82 
     83     // CoreIPC::Connection::Client
     84     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
     85     virtual void didClose(CoreIPC::Connection*);
     86     virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID);
     87     virtual void syncMessageSendTimedOut(CoreIPC::Connection*);
     88 
     89     // ProcessLauncher::Client
     90     virtual void didFinishLaunching(ProcessLauncher*, CoreIPC::Connection::Identifier);
     91 
     92     // Message handlers
     93     void didReceivePluginProcessProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
     94 #if PLATFORM(MAC)
     95     void didCreateWebProcessConnection(const CoreIPC::MachPort&);
     96 #endif
     97     void didGetSitesWithData(const Vector<String>& sites, uint64_t callbackID);
     98     void didClearSiteData(uint64_t callbackID);
     99 
    100 #if PLATFORM(MAC)
    101     bool getPluginProcessSerialNumber(ProcessSerialNumber&);
    102     void makePluginProcessTheFrontProcess();
    103     void makeUIProcessTheFrontProcess();
    104 
    105     void setFullscreenWindowIsShowing(bool);
    106     void enterFullscreen();
    107     void exitFullscreen();
    108 
    109     void setModalWindowIsShowing(bool);
    110     void beginModal();
    111     void endModal();
    112 
    113     void applicationDidBecomeActive();
    114 #endif
    115 
    116     void platformInitializePluginProcess(PluginProcessCreationParameters& parameters);
    117 
    118     // The plug-in host process manager.
    119     PluginProcessManager* m_pluginProcessManager;
    120 
    121     // Information about the plug-in.
    122     PluginInfoStore::Plugin m_pluginInfo;
    123 
    124     // The connection to the plug-in host process.
    125     RefPtr<CoreIPC::Connection> m_connection;
    126 
    127     // The process launcher for the plug-in host process.
    128     RefPtr<ProcessLauncher> m_processLauncher;
    129 
    130     Deque<RefPtr<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply> > m_pendingConnectionReplies;
    131 
    132     Vector<uint64_t> m_pendingGetSitesRequests;
    133     HashMap<uint64_t, RefPtr<WebPluginSiteDataManager> > m_pendingGetSitesReplies;
    134 
    135     struct ClearSiteDataRequest {
    136         Vector<String> sites;
    137         uint64_t flags;
    138         uint64_t maxAgeInSeconds;
    139         uint64_t callbackID;
    140     };
    141     Vector<ClearSiteDataRequest> m_pendingClearSiteDataRequests;
    142     HashMap<uint64_t, RefPtr<WebPluginSiteDataManager> > m_pendingClearSiteDataReplies;
    143 
    144     // If createPluginConnection is called while the process is still launching we'll keep count of it and send a bunch of requests
    145     // when the process finishes launching.
    146     unsigned m_numPendingConnectionRequests;
    147 
    148 #if PLATFORM(MAC)
    149     RetainPtr<NSObject> m_activationObserver;
    150     RetainPtr<WKPlaceholderModalWindow *> m_placeholderWindow;
    151     bool m_modalWindowIsShowing;
    152     bool m_fullscreenWindowIsShowing;
    153     unsigned m_preFullscreenAppPresentationOptions;
    154 #endif
    155 };
    156 
    157 } // namespace WebKit
    158 
    159 #endif // ENABLE(PLUGIN_PROCESS)
    160 
    161 #endif // PluginProcessProxy_h
    162