Home | History | Annotate | Download | only in WebProcess
      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 WebProcess_h
     27 #define WebProcess_h
     28 
     29 #include "CacheModel.h"
     30 #include "ChildProcess.h"
     31 #include "DrawingArea.h"
     32 #include "ResourceCachesToClear.h"
     33 #include "SandboxExtension.h"
     34 #include "SharedMemory.h"
     35 #include "TextCheckerState.h"
     36 #include "VisitedLinkTable.h"
     37 #include "WebGeolocationManager.h"
     38 #include "WebIconDatabaseProxy.h"
     39 #include "WebPageGroupProxy.h"
     40 #include <WebCore/LinkHash.h>
     41 #include <wtf/Forward.h>
     42 #include <wtf/HashMap.h>
     43 #include <wtf/HashSet.h>
     44 
     45 #if PLATFORM(MAC)
     46 #include "MachPort.h"
     47 #endif
     48 
     49 #if PLATFORM(QT)
     50 class QNetworkAccessManager;
     51 #endif
     52 
     53 namespace WebCore {
     54     class IntSize;
     55     class PageGroup;
     56     class ResourceRequest;
     57 }
     58 
     59 namespace WebKit {
     60 
     61 class InjectedBundle;
     62 class WebFrame;
     63 class WebPage;
     64 struct WebPageCreationParameters;
     65 struct WebPageGroupData;
     66 struct WebPreferencesStore;
     67 struct WebProcessCreationParameters;
     68 
     69 class WebProcess : public ChildProcess {
     70 public:
     71     static WebProcess& shared();
     72 
     73     void initialize(CoreIPC::Connection::Identifier, RunLoop*);
     74 
     75     CoreIPC::Connection* connection() const { return m_connection.get(); }
     76     RunLoop* runLoop() const { return m_runLoop; }
     77 
     78     WebPage* webPage(uint64_t pageID) const;
     79     void createWebPage(uint64_t pageID, const WebPageCreationParameters&);
     80     void removeWebPage(uint64_t pageID);
     81     WebPage* focusedWebPage() const;
     82 
     83     InjectedBundle* injectedBundle() const { return m_injectedBundle.get(); }
     84 
     85     bool isSeparateProcess() const;
     86 
     87 #if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC)
     88     mach_port_t compositingRenderServerPort() const { return m_compositingRenderServerPort; }
     89 #endif
     90 
     91     void addVisitedLink(WebCore::LinkHash);
     92     bool isLinkVisited(WebCore::LinkHash) const;
     93 
     94     bool fullKeyboardAccessEnabled();
     95 
     96     WebFrame* webFrame(uint64_t) const;
     97     void addWebFrame(uint64_t, WebFrame*);
     98     void removeWebFrame(uint64_t);
     99 
    100     WebPageGroupProxy* webPageGroup(uint64_t pageGroupID);
    101     WebPageGroupProxy* webPageGroup(const WebPageGroupData&);
    102 #if PLATFORM(MAC)
    103     pid_t presenterApplicationPid() const { return m_presenterApplicationPid; }
    104 #endif
    105 
    106 #if PLATFORM(QT)
    107     QNetworkAccessManager* networkAccessManager() { return m_networkAccessManager; }
    108 #endif
    109 
    110     bool shouldUseCustomRepresentationForMIMEType(const String& mimeType) const { return m_mimeTypesWithCustomRepresentations.contains(mimeType); }
    111 
    112     // Text Checking
    113     const TextCheckerState& textCheckerState() const { return m_textCheckerState; }
    114 
    115     // Geolocation
    116     WebGeolocationManager& geolocationManager() { return m_geolocationManager; }
    117 
    118     void clearResourceCaches(ResourceCachesToClear = AllResourceCaches);
    119 
    120     const String& localStorageDirectory() const { return m_localStorageDirectory; }
    121 
    122 private:
    123     WebProcess();
    124 
    125     void initializeWebProcess(const WebProcessCreationParameters&, CoreIPC::ArgumentDecoder*);
    126     void platformInitializeWebProcess(const WebProcessCreationParameters&, CoreIPC::ArgumentDecoder*);
    127     void platformTerminate();
    128     void setShouldTrackVisitedLinks(bool);
    129     void registerURLSchemeAsEmptyDocument(const String&);
    130     void registerURLSchemeAsSecure(const String&) const;
    131     void setDomainRelaxationForbiddenForURLScheme(const String&) const;
    132     void setDefaultRequestTimeoutInterval(double);
    133     void setAlwaysUsesComplexTextCodePath(bool);
    134     void languageChanged(const String&) const;
    135 #if PLATFORM(WIN)
    136     void setShouldPaintNativeControls(bool);
    137 #endif
    138 
    139     void setVisitedLinkTable(const SharedMemory::Handle&);
    140     void visitedLinkStateChanged(const Vector<WebCore::LinkHash>& linkHashes);
    141     void allVisitedLinkStateChanged();
    142 
    143     void setCacheModel(uint32_t);
    144     void platformSetCacheModel(CacheModel);
    145     static void calculateCacheSizes(CacheModel cacheModel, uint64_t memorySize, uint64_t diskFreeSize,
    146         unsigned& cacheTotalCapacity, unsigned& cacheMinDeadCapacity, unsigned& cacheMaxDeadCapacity, double& deadDecodedDataDeletionInterval,
    147         unsigned& pageCacheCapacity, unsigned long& urlCacheMemoryCapacity, unsigned long& urlCacheDiskCapacity);
    148     void platformClearResourceCaches(ResourceCachesToClear);
    149     void clearApplicationCache();
    150 
    151     void setEnhancedAccessibility(bool);
    152 
    153 #if !ENABLE(PLUGIN_PROCESS)
    154     void getSitesWithPluginData(const Vector<String>& pluginPaths, uint64_t callbackID);
    155     void clearPluginSiteData(const Vector<String>& pluginPaths, const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID);
    156 #endif
    157 
    158     void startMemorySampler(const SandboxExtension::Handle&, const String&, const double);
    159     void stopMemorySampler();
    160 
    161     void downloadRequest(uint64_t downloadID, uint64_t initiatingPageID, const WebCore::ResourceRequest&);
    162     void cancelDownload(uint64_t downloadID);
    163 
    164     void setTextCheckerState(const TextCheckerState&);
    165 
    166     // ChildProcess
    167     virtual bool shouldTerminate();
    168     virtual void terminate();
    169 
    170     // CoreIPC::Connection::Client
    171     virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
    172     virtual CoreIPC::SyncReplyMode didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
    173     virtual void didClose(CoreIPC::Connection*);
    174     virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID);
    175     virtual void syncMessageSendTimedOut(CoreIPC::Connection*);
    176 
    177 #if PLATFORM(WIN)
    178     Vector<HWND> windowsToReceiveSentMessagesWhileWaitingForSyncReply();
    179 #endif
    180 
    181     // Implemented in generated WebProcessMessageReceiver.cpp
    182     void didReceiveWebProcessMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
    183 
    184     RefPtr<CoreIPC::Connection> m_connection;
    185     HashMap<uint64_t, RefPtr<WebPage> > m_pageMap;
    186     HashMap<uint64_t, RefPtr<WebPageGroupProxy> > m_pageGroupMap;
    187     RefPtr<InjectedBundle> m_injectedBundle;
    188 
    189     bool m_inDidClose;
    190 
    191     RunLoop* m_runLoop;
    192 
    193     // FIXME: The visited link table should not be per process.
    194     VisitedLinkTable m_visitedLinkTable;
    195 
    196     bool m_hasSetCacheModel;
    197     CacheModel m_cacheModel;
    198 
    199 #if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC)
    200     mach_port_t m_compositingRenderServerPort;
    201 #endif
    202 #if PLATFORM(MAC)
    203     pid_t m_presenterApplicationPid;
    204 #endif
    205 
    206 #if PLATFORM(QT)
    207     QNetworkAccessManager* m_networkAccessManager;
    208 #endif
    209 
    210     HashMap<uint64_t, WebFrame*> m_frameMap;
    211 
    212     HashSet<String, CaseFoldingHash> m_mimeTypesWithCustomRepresentations;
    213 
    214     TextCheckerState m_textCheckerState;
    215     WebGeolocationManager m_geolocationManager;
    216     WebIconDatabaseProxy m_iconDatabaseProxy;
    217 
    218     String m_localStorageDirectory;
    219 };
    220 
    221 } // namespace WebKit
    222 
    223 #endif // WebProcess_h
    224