223815c815d5983c8c1ecb2e8d3860c0a90b9685
[platform/framework/web/wrt.git] / src / view / webkit / injected-bundle / wrt-injected-bundle.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file wrt-injected-bundle.h
18  * @author Jihoon Chung (jihoon.chung@samsung.com)
19  * @brief declare injected bundle
20  */
21 #ifndef WRT_SRC_VIEW_WEBKIT_WRT_INJECTED_BUNDLE_H_
22 #define WRT_SRC_VIEW_WEBKIT_WRT_INJECTED_BUNDLE_H_
23
24 #include <map>
25 #include <memory>
26 #include <set>
27 #include <list>
28 #include <string>
29 #include <WKBundle.h>
30 #include <WKPageLoadTypes.h>
31 #include <WKBundlePage.h>
32 #include <dpl/string.h>
33 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
34 #include <dpl/wrt-dao-ro/common_dao_types.h>
35 #include "page_global_context_container.h"
36
37 extern "C" {
38 WK_EXPORT void WKBundleInitialize(WKBundleRef bundle, WKTypeRef);
39 }
40
41 namespace InjectedBundle {
42 class DecryptionSupport;
43 }
44
45 class Bundle
46 {
47   public:
48     Bundle(WKBundleRef bundle);
49     ~Bundle();
50
51     Bundle(const Bundle&) = delete;
52     Bundle& operator=(const Bundle&) = delete;
53
54     // WKBundleClient callback
55     static void didCreatePageCallback(
56         WKBundleRef bundle,
57         WKBundlePageRef page,
58         const void* clientInfo);
59     static void willDestroyPageCallback(
60         WKBundleRef bundle,
61         WKBundlePageRef page,
62         const void* clientInfo);
63     static void didReceiveMessageCallback(
64         WKBundleRef,
65         WKStringRef messageName,
66         WKTypeRef messageBody,
67         const void *clientInfo);
68
69   private:
70     WKBundleRef m_bundle;
71
72     typedef std::list<WKBundlePageRef> PagesList;
73     PagesList m_pagesList;
74     typedef std::set<JSGlobalContextRef> ContextSet;
75     typedef std::map<WKBundlePageRef, ContextSet> PageContextList;
76     PageContextList m_pageContext;
77     PageGlobalContextContainer m_pageGlobalContext;
78     DPL::String m_widgetTizenId;
79     double m_scale;
80     std::string m_encodedBundle;
81     std::string m_theme;
82     std::set<JSGlobalContextRef> m_loadedContext;
83     JSGlobalContextRef m_willRemoveContext;
84     WrtDB::WidgetType m_widgetType;
85     WrtDB::WidgetSecurityModelVersion m_securityModelVersion;
86     bool m_initialized;
87
88     std::unique_ptr<InjectedBundle::DecryptionSupport> m_decryptionSupport;
89
90     // WKBundlePageResourceLoadClient callback
91     static WKURLRequestRef willSendRequestForFrameCallback(
92         WKBundlePageRef,
93         WKBundleFrameRef,
94         uint64_t resourceIdentifier,
95         WKURLRequestRef request,
96         WKURLResponseRef,
97         const void *clientInfo);
98     static void didFinishLoadForResourceCallback(
99         WKBundlePageRef page,
100         WKBundleFrameRef frame,
101         uint64_t resourceIdentifier,
102         const void* clientInfo);
103
104     // WKBundlePageDidStartProvisionalLoadForFrame callback
105     static void didStartProvisionalLoadForFrameCallback(
106         WKBundlePageRef page,
107         WKBundleFrameRef frame,
108         WKTypeRef* userData,
109         const void *clientInfo);
110
111     // WKBundlePageDidRemoveFrameFromHierarchy callback
112     static void didRemoveFrameFromHierarchyCallback(
113         WKBundlePageRef page,
114         WKBundleFrameRef frame,
115         WKTypeRef* userData,
116         const void *clientInfo);
117
118     // WKBundlePageLoaderClient callback
119     static void didCommitLoadForFrameCallback(
120         WKBundlePageRef page,
121         WKBundleFrameRef frame,
122         WKTypeRef*,
123         const void *clientInfo);
124
125     // WKBundlePageDecidePolicyForNavigationActionCallback
126     static WKBundlePagePolicyAction decidePolicyForNavigationActionCallback(
127         WKBundlePageRef page,
128         WKBundleFrameRef frame,
129         WKBundleNavigationActionRef navigationAction,
130         WKURLRequestRef request,
131         WKTypeRef* userData,
132         const void* clientInfo);
133
134     // WKBundlePageDecidePolicyForNewWindowActionCallback
135     static WKBundlePagePolicyAction decidePolicyForNewWindowActionCallback(
136         WKBundlePageRef page,
137         WKBundleFrameRef frame,
138         WKBundleNavigationActionRef navigationAction,
139         WKURLRequestRef request,
140         WKStringRef frameName,
141         WKTypeRef* userData,
142         const void* clientInfo);
143
144     // WKBundlePageDecidePolicyForResponseCallback
145     static WKBundlePagePolicyAction decidePolicyForResponseCallback(
146         WKBundlePageRef page,
147         WKBundleFrameRef frame,
148         WKURLResponseRef response,
149         WKURLRequestRef request,
150         WKTypeRef* userData,
151         const void* clientInfo);
152
153     // WKBundleClient
154     void didCreatePage(WKBundlePageRef page);
155     void willDestroyPage(WKBundlePageRef page);
156     void didReceiveMessage(
157         WKStringRef messageName,
158         WKTypeRef messageBody);
159
160     // WKBundlePageResourceLoadClient
161     WKURLRequestRef willSendRequestForFrame(WKURLRequestRef request);
162     WKBundlePagePolicyAction decidePolicyForAction(
163         bool isNewWindow,
164         WKBundlePageRef page,
165         WKBundleFrameRef frame,
166         WKBundleNavigationActionRef navigationAction,
167         WKURLRequestRef request,
168         WKTypeRef* userData);
169
170     // basic
171     inline static std::string toString(WKStringRef str);
172     inline static std::string toString(WKURLRef url);
173     inline static std::string toString(WKURLRequestRef req);
174     inline static std::string toString(WKErrorRef err);
175     static std::string getScheme(std::string uri);
176
177     bool isEncryptedResource(std::string Url, int &size);
178     std::string DecryptResource(std::string resource, int size);
179
180     void fixWKMessageArgs(std::string & argScale,
181                           std::string & argEncodedBundle,
182                           std::string & argTheme);
183
184
185 #ifdef MULTIPROCESS_SERVICE_SUPPORT_INLINE
186     void sendWebProcessPid();
187 #endif
188
189 #ifdef CORS_WHITELISTING_ENABLED
190     void bypassCORSforWARPAccessList(WrtDB::WidgetDAOReadOnly &dao);
191 #endif
192 };
193
194 #endif // WRT_SRC_VIEW_WEBKIT_WRT_INJECTED_BUNDLE_H_