5b91ce46c9ff4f5ee0d420ed8f4c50707258f83a
[platform/framework/web/wrt.git] / src / view / webkit / bundles / wrt-wk2-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-wk2-bundle.h
18  * @author Jihoon Chung (jihoon.chung@samsung.com)
19  * @brief declare bundle for WK2
20  */
21 #ifndef WRT_SRC_VIEW_WEBKIT2_WRT_WK2_BUNDLE_H_
22 #define WRT_SRC_VIEW_WEBKIT2_WRT_WK2_BUNDLE_H_
23
24 #include <set>
25 #include <map>
26 #include <list>
27 #include <string>
28 #include <WKBundle.h>
29 #include <WKPageLoadTypes.h>
30 #include <WKBundlePage.h>
31 #include <dpl/string.h>
32 #include <dpl/encryption/resource_decryption.h>
33 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
34
35 extern "C" {
36     WK_EXPORT void WKBundleInitialize(WKBundleRef bundle, WKTypeRef);
37 }
38
39 class Bundle {
40   public:
41     Bundle(WKBundleRef bundle);
42     ~Bundle();
43
44     // WKBundleClient callback
45     static void didCreatePageCallback(
46             WKBundleRef bundle,
47             WKBundlePageRef page,
48             const void* clientInfo);
49     static void willDestroyPageCallback(
50             WKBundleRef bundle,
51             WKBundlePageRef page,
52             const void* clientInfo);
53     static void didReceiveMessageCallback(
54             WKBundleRef,
55             WKStringRef messageName,
56             WKTypeRef messageBody,
57             const void *clientInfo);
58
59   private:
60     WKStringRef m_uriChangedMessage;
61     WKBundleRef m_bundle;
62
63     typedef std::list<WKBundlePageRef> PagesList;
64     PagesList m_pagesList;
65     typedef std::set<JSGlobalContextRef> ContextSet;
66     typedef std::map<WKBundlePageRef, ContextSet> PageContextList;
67     typedef std::map<WKBundlePageRef, JSGlobalContextRef> PageGlobalContext;
68     PageContextList m_pageContext;
69     PageGlobalContext m_pageGlobalContext;
70     DPL::String m_widgetTizenId;
71     double m_scale;
72     std::string m_encodedBundle;
73     std::string m_theme;
74     std::set<JSGlobalContextRef> m_loadedContext;
75     bool m_encrypted;
76     WRTDecryptor::ResourceDecryptor *m_resDec;
77     WrtDB::EncryptedFileList m_encryptedFiles;
78     WrtDB::WidgetType m_widgetType;
79
80     // WKBundlePageResourceLoadClient callback
81     static WKURLRequestRef willSendRequestForFrameCallback(
82             WKBundlePageRef,
83             WKBundleFrameRef,
84             uint64_t resourceIdentifier,
85             WKURLRequestRef request,
86             WKURLResponseRef,
87             const void *clientInfo);
88     static void didFinishLoadForResourceCallback(
89             WKBundlePageRef page,
90             WKBundleFrameRef frame,
91             uint64_t resourceIdentifier,
92             const void* clientInfo);
93
94     // WKBundlePageDidStartProvisionalLoadForFrame callback
95     static void didStartProvisionalLoadForFrameCallback(
96             WKBundlePageRef page,
97             WKBundleFrameRef frame,
98             WKTypeRef* userData,
99             const void *clientInfo);
100
101     // WKBundlePageDidRemoveFrameFromHierarchy callback
102     static void didRemoveFrameFromHierarchyCallback(
103             WKBundlePageRef page,
104             WKBundleFrameRef frame,
105             WKTypeRef* userData,
106             const void *clientInfo);
107
108     // WKBundlePageLoaderClient callback
109     static void didCommitLoadForFrameCallback(
110             WKBundlePageRef page,
111             WKBundleFrameRef frame,
112             WKTypeRef*,
113             const void *clientInfo);
114
115     // WKBundlePageDecidePolicyForNavigationActionCallback
116     static WKBundlePagePolicyAction pageDecidePolicyForNavigationActionCallback(
117             WKBundlePageRef page,
118             WKBundleFrameRef frame,
119             WKBundleNavigationActionRef navigationAction,
120             WKURLRequestRef request,
121             WKTypeRef* userData,
122             const void* clientInfo);
123
124     // WKBundlePageDecidePolicyForResponseCallback
125     static WKBundlePagePolicyAction pageDecidePolicyForResponseCallback(
126         WKBundlePageRef page,
127         WKBundleFrameRef frame,
128         WKURLResponseRef response,
129         WKURLRequestRef request,
130         WKTypeRef* userData,
131         const void* clientInfo);
132
133     // WKBundleClient
134     void didCreatePage(WKBundlePageRef page);
135     void willDestroyPage(WKBundlePageRef page);
136     void didReceiveMessage(
137             WKStringRef messageName,
138             WKTypeRef messageBody);
139
140     // WKBundlePageResourceLoadClient
141     WKURLRequestRef willSendRequestForFrame(WKURLRequestRef request);
142     WKBundlePagePolicyAction pageDecidePolicyForNavigationAction(
143         WKBundlePageRef             page,
144         WKBundleFrameRef            frame,
145         WKBundleNavigationActionRef navigationAction,
146         WKURLRequestRef             request,
147         WKTypeRef*                  userData);
148
149     // basic
150     static std::string toString(WKStringRef str);
151     static std::string toString(WKURLRef url);
152     static std::string toString(WKURLRequestRef req);
153     static std::string toString(WKErrorRef err);
154     static std::string getScheme(std::string uri);
155
156     bool isEncryptedResource(std::string Url, int &size);
157     std::string DecryptResource(std::string resource, int size);
158
159     void fixWKMessageArgs(std::string & argScale,
160         std::string & argEncodedBundle, std::string & argTheme);
161
162     void requestSuspend();
163     void requestResume();
164
165     void connectLoaderClientCallbacksToPage(WKBundlePageRef page);
166
167
168 };
169
170 #endif /* WRT_SRC_VIEW_WEBKIT2_WRT_WK2_BUNDLE_H_ */