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 InjectedBundle_h
27#define InjectedBundle_h
28
29#include "APIObject.h"
30#include "InjectedBundleClient.h"
31#include "SandboxExtension.h"
32#include "WKBundle.h"
33#include <WebCore/UserContentTypes.h>
34#include <WebCore/UserScriptTypes.h>
35#include <wtf/PassRefPtr.h>
36#include <wtf/text/WTFString.h>
37
38#if PLATFORM(QT)
39#include <QLibrary>
40#endif
41
42#if PLATFORM(GTK)
43typedef struct _GModule GModule;
44#endif
45
46#if PLATFORM(EFL)
47#include <Eina.h>
48#endif
49
50#if PLATFORM(MAC)
51OBJC_CLASS NSBundle;
52#endif
53
54namespace CoreIPC {
55    class ArgumentDecoder;
56    class Connection;
57}
58
59namespace WebKit {
60
61#if PLATFORM(MAC)
62typedef NSBundle *PlatformBundle;
63#elif PLATFORM(QT)
64typedef QLibrary PlatformBundle;
65#elif PLATFORM(GTK)
66typedef ::GModule* PlatformBundle;
67#elif PLATFORM(EFL)
68typedef Eina_Module* PlatformBundle;
69#endif
70
71class ImmutableArray;
72class InjectedBundleScriptWorld;
73class WebCertificateInfo;
74class WebConnection;
75class WebData;
76class WebFrame;
77class WebPage;
78class WebPageGroupProxy;
79
80class InjectedBundle : public TypedAPIObject<APIObject::TypeBundle> {
81public:
82    static PassRefPtr<InjectedBundle> create(const String& path)
83    {
84        return adoptRef(new InjectedBundle(path));
85    }
86    ~InjectedBundle();
87
88    bool load(APIObject* initializationUserData);
89    void setSandboxExtension(PassRefPtr<SandboxExtension> sandboxExtension) { m_sandboxExtension = sandboxExtension; }
90
91    // API
92    void initializeClient(WKBundleClient*);
93    void postMessage(const String&, APIObject*);
94    void postSynchronousMessage(const String&, APIObject*, RefPtr<APIObject>& returnData);
95
96    WebConnection* webConnectionToUIProcess() const;
97
98    // TestRunner only SPI
99    void setShouldTrackVisitedLinks(bool);
100    void setAlwaysAcceptCookies(bool);
101    void removeAllVisitedLinks();
102    void setCacheModel(uint32_t);
103    void activateMacFontAscentHack();
104    void overrideBoolPreferenceForTestRunner(WebPageGroupProxy*, const String& preference, bool enabled);
105    void overrideXSSAuditorEnabledForTestRunner(WebPageGroupProxy* pageGroup, bool enabled);
106    void setAllowUniversalAccessFromFileURLs(WebPageGroupProxy*, bool);
107    void setAllowFileAccessFromFileURLs(WebPageGroupProxy*, bool);
108    void setMinimumLogicalFontSize(WebPageGroupProxy*, int size);
109    void setFrameFlatteningEnabled(WebPageGroupProxy*, bool);
110    void setPluginsEnabled(WebPageGroupProxy*, bool);
111    void setJavaScriptCanAccessClipboard(WebPageGroupProxy*, bool);
112    void setPrivateBrowsingEnabled(WebPageGroupProxy*, bool);
113    void setPopupBlockingEnabled(WebPageGroupProxy*, bool);
114    void switchNetworkLoaderToNewTestingSession();
115    void setAuthorAndUserStylesEnabled(WebPageGroupProxy*, bool);
116    void setSpatialNavigationEnabled(WebPageGroupProxy*, bool);
117    void addOriginAccessWhitelistEntry(const String&, const String&, const String&, bool);
118    void removeOriginAccessWhitelistEntry(const String&, const String&, const String&, bool);
119    void resetOriginAccessWhitelists();
120    void setAsynchronousSpellCheckingEnabled(WebPageGroupProxy*, bool);
121    int numberOfPages(WebFrame*, double, double);
122    int pageNumberForElementById(WebFrame*, const String&, double, double);
123    String pageSizeAndMarginsInPixels(WebFrame*, int, int, int, int, int, int, int);
124    bool isPageBoxVisible(WebFrame*, int);
125    void setUserStyleSheetLocation(WebPageGroupProxy*, const String&);
126    void setWebNotificationPermission(WebPage*, const String& originString, bool allowed);
127    void removeAllWebNotificationPermissions(WebPage*);
128    uint64_t webNotificationID(JSContextRef, JSValueRef);
129    PassRefPtr<WebData> createWebDataFromUint8Array(JSContextRef, JSValueRef);
130
131    // UserContent API
132    void addUserScript(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& source, const String& url, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserScriptInjectionTime, WebCore::UserContentInjectedFrames);
133    void addUserStyleSheet(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& source, const String& url, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserContentInjectedFrames);
134    void removeUserScript(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& url);
135    void removeUserStyleSheet(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& url);
136    void removeUserScripts(WebPageGroupProxy*, InjectedBundleScriptWorld*);
137    void removeUserStyleSheets(WebPageGroupProxy*, InjectedBundleScriptWorld*);
138    void removeAllUserContent(WebPageGroupProxy*);
139
140    // Local storage API
141    void clearAllDatabases();
142    void setDatabaseQuota(uint64_t);
143
144    // Application Cache API
145    void clearApplicationCache();
146    void clearApplicationCacheForOrigin(const String& origin);
147    void setAppCacheMaximumSize(uint64_t);
148    uint64_t appCacheUsageForOrigin(const String& origin);
149    void setApplicationCacheOriginQuota(const String& origin, uint64_t);
150    void resetApplicationCacheOriginQuota(const String& origin);
151    PassRefPtr<ImmutableArray> originsWithApplicationCache();
152
153    // Garbage collection API
154    void garbageCollectJavaScriptObjects();
155    void garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging(bool waitUntilDone);
156    size_t javaScriptObjectsCount();
157
158    // Callback hooks
159    void didCreatePage(WebPage*);
160    void willDestroyPage(WebPage*);
161    void didInitializePageGroup(WebPageGroupProxy*);
162    void didReceiveMessage(const String&, APIObject*);
163    void didReceiveMessageToPage(WebPage*, const String&, APIObject*);
164
165    static void reportException(JSContextRef, JSValueRef exception);
166
167    static bool isProcessingUserGesture();
168
169    void setTabKeyCyclesThroughElements(WebPage*, bool enabled);
170    void setSerialLoadingEnabled(bool);
171    void setShadowDOMEnabled(bool);
172    void setCSSRegionsEnabled(bool);
173    void setCSSCompositingEnabled(bool);
174    void setSeamlessIFramesEnabled(bool);
175    void dispatchPendingLoadRequests();
176
177private:
178    explicit InjectedBundle(const String&);
179
180    String m_path;
181    PlatformBundle m_platformBundle; // This is leaked right now, since we never unload the bundle/module.
182
183    RefPtr<SandboxExtension> m_sandboxExtension;
184
185    InjectedBundleClient m_client;
186};
187
188} // namespace WebKit
189
190#endif // InjectedBundle_h
191