Apply to remove download listener before deleting _WebImpl
[framework/osp/web.git] / src / controls / FWebCtrl_Utility.cpp
1 //\r
2 // Open Service Platform\r
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
4 //\r
5 // Licensed under the Apache License, Version 2.0 (the License);\r
6 // you may not use this file except in compliance with the License.\r
7 // You may obtain a copy of the License at\r
8 //\r
9 //     http://www.apache.org/licenses/LICENSE-2.0\r
10 //\r
11 // Unless required by applicable law or agreed to in writing, software\r
12 // distributed under the License is distributed on an "AS IS" BASIS,\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 // See the License for the specific language governing permissions and\r
15 // limitations under the License.\r
16 //\r
17 \r
18 /**\r
19  * @file                FWebCtrl_Utility.cpp\r
20  * @brief               The file contains the definition of _Utility class.\r
21  *\r
22  * The file contains the definition of _Utility class.\r
23  */\r
24 \r
25 #include <Ecore.h>\r
26 #include <FAppUiApp.h>
27 #include <FAppIAppFrame.h>
28 #include <FBaseSysLog.h>\r
29 #include <FUiAnim_EflNode.h>\r
30 #include <FUiAnim_VisualElementImpl.h>
31 #include <FUiCtrlFrame.h>
32 #include <FUi_ControlImpl.h>\r
33 #include "FWebCtrl_Utility.h"\r
34 \r
35 using namespace Tizen::App;\r
36 using namespace Tizen::Base;\r
37 using namespace Tizen::Graphics;\r
38 using namespace Tizen::Ui;
39 using namespace Tizen::Ui::Controls;\r
40 using namespace Tizen::Ui::Animations;\r
41 \r
42 namespace Tizen { namespace Web { namespace Controls\r
43 {\r
44 \r
45 \r
46 _Utility::_Utility(void)\r
47 {\r
48 }\r
49 \r
50 _Utility::~_Utility(void)\r
51 {\r
52 }\r
53 \r
54 \r
55 Evas*\r
56 _Utility::GetEvasFromUiApp()\r
57 {\r
58         IAppFrame* pAppFrame = Application::GetInstance()->GetAppFrame();
59         SysTryReturn(NID_WEB_CTRL, pAppFrame, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
60
61         Frame* pFrame = pAppFrame->GetFrame();
62         SysTryReturn(NID_WEB_CTRL, pFrame, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
63
64         _ControlImpl* pControlimpl = _ControlImpl::GetInstance(*pFrame);
65         SysTryReturn(NID_WEB_CTRL, pControlimpl, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
66
67         VisualElement* pVisual = pControlimpl->GetCore().GetVisualElement();
68         SysTryReturn(NID_WEB_CTRL, pVisual, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
69
70         _VisualElementImpl* pWebVisualElementImpl = _VisualElementImpl::GetInstance(*pVisual);
71         SysTryReturn(NID_WEB_CTRL,pWebVisualElementImpl, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
72
73         _EflNode* pEflNode = dynamic_cast< _EflNode* >(pWebVisualElementImpl->GetNativeNode());
74         SysTryReturn(NID_WEB_CTRL, pEflNode, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
75
76         Evas* pEvas = pEflNode->GetEvas();
77         SysTryReturn(NID_WEB_CTRL, pEvas, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));\r
78 \r
79         return pEvas;\r
80 }\r
81 \r
82 \r
83 result\r
84 _Utility::GetPixelBufferFromEvasObject(const Evas_Object* source, Tizen::Graphics::BufferInfo& bufferInfo)\r
85 {\r
86         bufferInfo.pPixels = evas_object_image_data_get(source, EINA_FALSE);\r
87         SysTryReturnResult(NID_WEB_CTRL, bufferInfo.pPixels, E_INVALID_DATA, "Failed to get pixel data from evas object.");\r
88 \r
89         evas_object_image_size_get(source, &bufferInfo.width, &bufferInfo.height);\r
90 \r
91         Evas_Colorspace colorSpace = evas_object_image_colorspace_get(source);\r
92 \r
93         switch (colorSpace)\r
94         {\r
95         case EVAS_COLORSPACE_ARGB8888:\r
96                 bufferInfo.bitsPerPixel = 32;\r
97                 bufferInfo.pixelFormat = PIXEL_FORMAT_ARGB8888;\r
98                 break;\r
99 \r
100         case EVAS_COLORSPACE_YCBCR422P601_PL:\r
101                 bufferInfo.bitsPerPixel = 0;\r
102                 bufferInfo.pixelFormat = PIXEL_FORMAT_MIN;\r
103                 break;\r
104 \r
105         case EVAS_COLORSPACE_YCBCR422P709_PL:\r
106                 bufferInfo.bitsPerPixel = 0;\r
107                 bufferInfo.pixelFormat = PIXEL_FORMAT_MIN;\r
108                 break;\r
109 \r
110         case EVAS_COLORSPACE_RGB565_A5P:\r
111                 bufferInfo.bitsPerPixel = 0;\r
112                 bufferInfo.pixelFormat = PIXEL_FORMAT_MIN;\r
113                 break;\r
114 \r
115         case EVAS_COLORSPACE_GRY8:\r
116                 bufferInfo.bitsPerPixel = 0;\r
117                 bufferInfo.pixelFormat = PIXEL_FORMAT_MIN;\r
118                 break;\r
119 \r
120         case EVAS_COLORSPACE_YCBCR422601_PL:\r
121                 bufferInfo.bitsPerPixel = 0;\r
122                 bufferInfo.pixelFormat = PIXEL_FORMAT_MIN;\r
123                 break;\r
124 \r
125         case EVAS_COLORSPACE_YCBCR420NV12601_PL:\r
126                 bufferInfo.bitsPerPixel = 0;\r
127                 bufferInfo.pixelFormat = PIXEL_FORMAT_MIN;\r
128                 break;\r
129 \r
130         case EVAS_COLORSPACE_YCBCR420TM12601_PL:\r
131                 bufferInfo.bitsPerPixel = 0;\r
132                 bufferInfo.pixelFormat = PIXEL_FORMAT_MIN;\r
133                 break;\r
134 \r
135         default:\r
136                 bufferInfo.bitsPerPixel = 0;\r
137                 bufferInfo.pixelFormat = PIXEL_FORMAT_MIN;\r
138                 break;\r
139         }\r
140 \r
141         bufferInfo.pitch = bufferInfo.width * bufferInfo.bitsPerPixel / 8;\r
142 \r
143         SysLog(NID_WEB_CTRL, "color space : %d, pitch (%d), w-h (%d, %d)", colorSpace, bufferInfo.pitch, bufferInfo.width, bufferInfo.height);\r
144 \r
145         return E_SUCCESS;\r
146 }\r
147 \r
148 \r
149 String
150 _Utility::CreateOrigin(const Ewk_Security_Origin* pSecurityOrigin)\r
151 {
152         String protocol(ewk_security_origin_protocol_get(pSecurityOrigin));\r
153         String host(ewk_security_origin_host_get(pSecurityOrigin));\r
154         int port = ewk_security_origin_port_get(pSecurityOrigin);\r
155
156         String origin = protocol + L"://" + host;
157
158         if (port)
159         {
160                 origin.Append(L":");
161                 origin.Append(port);
162         }
163
164         SysLog(NID_WEB_CTRL, "The current value of origin is %ls", origin.GetPointer());
165
166         return origin;
167 }
168 \r
169 \r
170 }}}\r