Merge "fix: use EINA_* booleans instread of TRUE/FALSE" into tizen
[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::WidgetSecurityModelVersion m_securityModelVersion;
86     bool m_initialized;
87
88     std::unique_ptr<InjectedBundle::DecryptionSupport> m_decryptionSupport;
89     std::unique_ptr<InjectedBundle::ViewmodesSupport> m_viewmodesSupport;
90
91     // WKBundlePageResourceLoadClient callback
92     static WKURLRequestRef willSendRequestForFrameCallback(
93         WKBundlePageRef,
94         WKBundleFrameRef,
95         uint64_t resourceIdentifier,
96         WKURLRequestRef request,
97         WKURLResponseRef,
98         const void *clientInfo);
99     static void didFinishLoadForResourceCallback(
100         WKBundlePageRef page,
101         WKBundleFrameRef frame,
102         uint64_t resourceIdentifier,
103         const void* clientInfo);
104
105     // WKBundlePageDidStartProvisionalLoadForFrame callback
106     static void didStartProvisionalLoadForFrameCallback(
107         WKBundlePageRef page,
108         WKBundleFrameRef frame,
109         WKTypeRef* userData,
110         const void *clientInfo);
111
112     // WKBundlePageDidRemoveFrameFromHierarchy callback
113     static void didRemoveFrameFromHierarchyCallback(
114         WKBundlePageRef page,
115         WKBundleFrameRef frame,
116         WKTypeRef* userData,
117         const void *clientInfo);
118
119     // WKBundlePageLoaderClient callback
120     static void didCommitLoadForFrameCallback(
121         WKBundlePageRef page,
122         WKBundleFrameRef frame,
123         WKTypeRef*,
124         const void *clientInfo);
125
126     // WKBundlePageDecidePolicyForNavigationActionCallback
127     static WKBundlePagePolicyAction decidePolicyForNavigationActionCallback(
128         WKBundlePageRef page,
129         WKBundleFrameRef frame,
130         WKBundleNavigationActionRef navigationAction,
131         WKURLRequestRef request,
132         WKTypeRef* userData,
133         const void* clientInfo);
134
135     // WKBundlePageDecidePolicyForNewWindowActionCallback
136     static WKBundlePagePolicyAction decidePolicyForNewWindowActionCallback(
137         WKBundlePageRef page,
138         WKBundleFrameRef frame,
139         WKBundleNavigationActionRef navigationAction,
140         WKURLRequestRef request,
141         WKStringRef frameName,
142         WKTypeRef* userData,
143         const void* clientInfo);
144
145     // WKBundlePageDecidePolicyForResponseCallback
146     static WKBundlePagePolicyAction decidePolicyForResponseCallback(
147         WKBundlePageRef page,
148         WKBundleFrameRef frame,
149         WKURLResponseRef response,
150         WKURLRequestRef request,
151         WKTypeRef* userData,
152         const void* clientInfo);
153
154     // WKBundleClient
155     void didCreatePage(WKBundlePageRef page);
156     void willDestroyPage(WKBundlePageRef page);
157     void didReceiveMessage(
158         WKStringRef messageName,
159         WKTypeRef messageBody);
160
161     // WKBundlePageResourceLoadClient
162     WKURLRequestRef willSendRequestForFrame(WKURLRequestRef request);
163     WKBundlePagePolicyAction decidePolicyForAction(
164         bool isNewWindow,
165         WKBundlePageRef page,
166         WKBundleFrameRef frame,
167         WKBundleNavigationActionRef navigationAction,
168         WKURLRequestRef request,
169         WKTypeRef* userData);
170
171     // basic
172     inline static std::string toString(WKStringRef str);
173     inline static std::string toString(WKURLRef url);
174     inline static std::string toString(WKURLRequestRef req);
175     inline static std::string toString(WKErrorRef err);
176     static std::string getScheme(std::string uri);
177
178     bool isEncryptedResource(std::string Url, int &size);
179     std::string DecryptResource(std::string resource, int size);
180
181     void fixWKMessageArgs(std::string & argScale,
182                           std::string & argEncodedBundle,
183                           std::string & argTheme);
184
185 #ifdef CORS_WHITELISTING_ENABLED
186     void bypassCORSforWARPAccessList(WrtDB::WidgetDAOReadOnly &dao);
187 #endif
188 };
189
190 #endif // WRT_SRC_VIEW_WEBKIT_WRT_INJECTED_BUNDLE_H_