[Release] wrt_0.8.225
[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 class ViewmodesSupport;
44 }
45
46 class Bundle
47 {
48   public:
49     Bundle(WKBundleRef bundle);
50     ~Bundle();
51
52     Bundle(const Bundle&) = delete;
53     Bundle& operator=(const Bundle&) = delete;
54
55     // WKBundleClient callback
56     static void didCreatePageCallback(
57         WKBundleRef bundle,
58         WKBundlePageRef page,
59         const void* clientInfo);
60     static void willDestroyPageCallback(
61         WKBundleRef bundle,
62         WKBundlePageRef page,
63         const void* clientInfo);
64     static void didReceiveMessageCallback(
65         WKBundleRef,
66         WKStringRef messageName,
67         WKTypeRef messageBody,
68         const void *clientInfo);
69
70   private:
71     WKBundleRef m_bundle;
72
73     typedef std::list<WKBundlePageRef> PagesList;
74     PagesList m_pagesList;
75     typedef std::set<JSGlobalContextRef> ContextSet;
76     typedef std::map<WKBundlePageRef, ContextSet> PageContextList;
77     PageContextList m_pageContext;
78     PageGlobalContextContainer m_pageGlobalContext;
79     DPL::String m_widgetTizenId;
80     double m_scale;
81     std::string m_encodedBundle;
82     std::string m_theme;
83     std::set<JSGlobalContextRef> m_loadedContext;
84     JSGlobalContextRef m_willRemoveContext;
85     WrtDB::WidgetType m_widgetType;
86     WrtDB::WidgetSecurityModelVersion m_securityModelVersion;
87     bool m_initialized;
88
89     std::unique_ptr<InjectedBundle::DecryptionSupport> m_decryptionSupport;
90     std::unique_ptr<InjectedBundle::ViewmodesSupport> m_viewmodesSupport;
91
92     // WKBundlePageResourceLoadClient callback
93     static WKURLRequestRef willSendRequestForFrameCallback(
94         WKBundlePageRef,
95         WKBundleFrameRef,
96         uint64_t resourceIdentifier,
97         WKURLRequestRef request,
98         WKURLResponseRef,
99         const void *clientInfo);
100     static void didFinishLoadForResourceCallback(
101         WKBundlePageRef page,
102         WKBundleFrameRef frame,
103         uint64_t resourceIdentifier,
104         const void* clientInfo);
105
106     // WKBundlePageDidStartProvisionalLoadForFrame callback
107     static void didStartProvisionalLoadForFrameCallback(
108         WKBundlePageRef page,
109         WKBundleFrameRef frame,
110         WKTypeRef* userData,
111         const void *clientInfo);
112
113     // WKBundlePageDidRemoveFrameFromHierarchy callback
114     static void didRemoveFrameFromHierarchyCallback(
115         WKBundlePageRef page,
116         WKBundleFrameRef frame,
117         WKTypeRef* userData,
118         const void *clientInfo);
119
120     // WKBundlePageLoaderClient callback
121     static void didCommitLoadForFrameCallback(
122         WKBundlePageRef page,
123         WKBundleFrameRef frame,
124         WKTypeRef*,
125         const void *clientInfo);
126
127     // WKBundlePageDecidePolicyForNavigationActionCallback
128     static WKBundlePagePolicyAction decidePolicyForNavigationActionCallback(
129         WKBundlePageRef page,
130         WKBundleFrameRef frame,
131         WKBundleNavigationActionRef navigationAction,
132         WKURLRequestRef request,
133         WKTypeRef* userData,
134         const void* clientInfo);
135
136     // WKBundlePageDecidePolicyForNewWindowActionCallback
137     static WKBundlePagePolicyAction decidePolicyForNewWindowActionCallback(
138         WKBundlePageRef page,
139         WKBundleFrameRef frame,
140         WKBundleNavigationActionRef navigationAction,
141         WKURLRequestRef request,
142         WKStringRef frameName,
143         WKTypeRef* userData,
144         const void* clientInfo);
145
146     // WKBundlePageDecidePolicyForResponseCallback
147     static WKBundlePagePolicyAction decidePolicyForResponseCallback(
148         WKBundlePageRef page,
149         WKBundleFrameRef frame,
150         WKURLResponseRef response,
151         WKURLRequestRef request,
152         WKTypeRef* userData,
153         const void* clientInfo);
154
155     // WKBundleClient
156     void didCreatePage(WKBundlePageRef page);
157     void willDestroyPage(WKBundlePageRef page);
158     void didReceiveMessage(
159         WKStringRef messageName,
160         WKTypeRef messageBody);
161
162     // WKBundlePageResourceLoadClient
163     WKURLRequestRef willSendRequestForFrame(WKURLRequestRef request);
164     WKBundlePagePolicyAction decidePolicyForAction(
165         bool isNewWindow,
166         WKBundlePageRef page,
167         WKBundleFrameRef frame,
168         WKBundleNavigationActionRef navigationAction,
169         WKURLRequestRef request,
170         WKTypeRef* userData);
171
172     // basic
173     inline static std::string toString(WKStringRef str);
174     inline static std::string toString(WKURLRef url);
175     inline static std::string toString(WKURLRequestRef req);
176     inline static std::string toString(WKErrorRef err);
177     static std::string getScheme(std::string uri);
178
179     bool isEncryptedResource(std::string Url, int &size);
180     std::string DecryptResource(std::string resource, int size);
181
182     void fixWKMessageArgs(std::string & argScale,
183                           std::string & argEncodedBundle,
184                           std::string & argTheme);
185
186
187 #ifdef MULTIPROCESS_SERVICE_SUPPORT_INLINE
188     void sendWebProcessPid();
189 #endif
190 #ifdef CORS_WHITELISTING_ENABLED
191     void bypassCORSforWARPAccessList(WrtDB::WidgetDAOReadOnly &dao);
192 #endif
193 };
194
195 #endif // WRT_SRC_VIEW_WEBKIT_WRT_INJECTED_BUNDLE_H_