initial import
[vuplus_webkit] / Source / WebKit2 / WebProcess / InjectedBundle / InjectedBundle.h
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)
43 typedef struct _GModule GModule;
44 #endif
45
46 namespace CoreIPC {
47     class ArgumentDecoder;
48     class Connection;
49     class MessageID;
50 }
51
52 namespace WebKit {
53
54 #if PLATFORM(MAC)
55 typedef CFBundleRef PlatformBundle;
56 #elif PLATFORM(WIN)
57 typedef HMODULE PlatformBundle;
58 #elif PLATFORM(QT)
59 typedef QLibrary PlatformBundle;
60 #elif PLATFORM(GTK)
61 typedef ::GModule* PlatformBundle;
62 #endif
63
64 class ImmutableArray;
65 class InjectedBundleScriptWorld;
66 class WebCertificateInfo;
67 class WebFrame;
68 class WebPage;
69 class WebPageGroupProxy;
70
71 class InjectedBundle : public APIObject {
72 public:
73     static const Type APIType = TypeBundle;
74
75     static PassRefPtr<InjectedBundle> create(const String& path)
76     {
77         return adoptRef(new InjectedBundle(path));
78     }
79     ~InjectedBundle();
80
81     bool load(APIObject* initializationUserData);
82     void setSandboxExtension(PassRefPtr<SandboxExtension> sandboxExtension) { m_sandboxExtension = sandboxExtension; }
83
84     // API
85     void initializeClient(WKBundleClient*);
86     void postMessage(const String&, APIObject*);
87     void postSynchronousMessage(const String&, APIObject*, RefPtr<APIObject>& returnData);
88 #if PLATFORM(WIN)
89     void setHostAllowsAnyHTTPSCertificate(const String&);
90     void setClientCertificate(const String& host, const String& certificateSystemStoreName, const WebCertificateInfo*);
91 #endif
92
93     // TestRunner only SPI
94     void setShouldTrackVisitedLinks(bool);
95     void removeAllVisitedLinks();
96     void activateMacFontAscentHack();
97     void overrideXSSAuditorEnabledForTestRunner(WebPageGroupProxy* pageGroup, bool enabled);
98     void setAllowUniversalAccessFromFileURLs(WebPageGroupProxy*, bool);
99     void setAllowFileAccessFromFileURLs(WebPageGroupProxy*, bool);
100     void setFrameFlatteningEnabled(WebPageGroupProxy*, bool);
101     void setJavaScriptCanAccessClipboard(WebPageGroupProxy*, bool);
102     void setPrivateBrowsingEnabled(WebPageGroupProxy*, bool);
103     void switchNetworkLoaderToNewTestingSession();
104     void setAuthorAndUserStylesEnabled(WebPageGroupProxy*, bool);
105     void addOriginAccessWhitelistEntry(const String&, const String&, const String&, bool);
106     void removeOriginAccessWhitelistEntry(const String&, const String&, const String&, bool);
107     void resetOriginAccessWhitelists();
108     int numberOfPages(WebFrame*, double, double);
109     int pageNumberForElementById(WebFrame*, const String&, double, double);
110     String pageSizeAndMarginsInPixels(WebFrame*, int, int, int, int, int, int, int);
111     bool isPageBoxVisible(WebFrame*, int);
112
113     // UserContent API
114     void addUserScript(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& source, const String& url, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserScriptInjectionTime, WebCore::UserContentInjectedFrames);
115     void addUserStyleSheet(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& source, const String& url, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserContentInjectedFrames);
116     void removeUserScript(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& url);
117     void removeUserStyleSheet(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& url);
118     void removeUserScripts(WebPageGroupProxy*, InjectedBundleScriptWorld*);
119     void removeUserStyleSheets(WebPageGroupProxy*, InjectedBundleScriptWorld*);
120     void removeAllUserContent(WebPageGroupProxy*);
121
122     // Local storage API
123     void clearAllDatabases();
124     void setDatabaseQuota(uint64_t);
125
126     // Garbage collection API
127     void garbageCollectJavaScriptObjects();
128     void garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging(bool waitUntilDone);
129     size_t javaScriptObjectsCount();
130
131     // Callback hooks
132     void didCreatePage(WebPage*);
133     void willDestroyPage(WebPage*);
134     void didInitializePageGroup(WebPageGroupProxy*);
135     void didReceiveMessage(const String&, APIObject*);
136
137     void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
138
139     static void reportException(JSContextRef, JSValueRef exception);
140
141     static bool isProcessingUserGesture();
142
143 private:
144     InjectedBundle(const String&);
145
146     virtual Type type() const { return APIType; }
147
148     String m_path;
149     PlatformBundle m_platformBundle; // This is leaked right now, since we never unload the bundle/module.
150
151     RefPtr<SandboxExtension> m_sandboxExtension;
152
153     InjectedBundleClient m_client;
154 };
155
156 } // namespace WebKit
157
158 #endif // InjectedBundle_h