fix certificate popup crash issue
[framework/osp/web.git] / src / FWeb_HistoryItemImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FWeb_HistoryItemImplcpp
20  * @brief               The file contains the definition of _HistoryItemImpl class.
21  *
22  * This file contains the definition of _HistoryItemImpl class.
23  */
24 #include <Ecore_Evas.h>
25 //#include <elm_config.h>
26 #include <EWebKit2.h>
27 #include <favorites.h>
28 #include <unique_ptr.h>
29 #include <FBaseSysLog.h>
30 #include <FGrpBitmap.h>
31 #include <FGrpDimension.h>
32 #include <FBase_StringConverter.h>
33 #include <FUiCtrlFrame.h>
34 #include <FWebHistoryItem.h>
35 #include "FWeb_HistoryItemImpl.h"
36 #include "FWebCtrl_Utility.h"
37
38
39 using namespace Tizen::Base;
40 using namespace Tizen::Graphics;
41 using namespace Tizen::Ui::Controls;
42 using namespace Tizen::Web::Controls;
43
44
45 namespace Tizen { namespace Web
46 {
47
48
49 _HistoryItemImpl::_HistoryItemImpl(void)
50         : __id(-1)
51         , __url(L"")
52         , __title(L"")
53 {
54 }
55
56
57 _HistoryItemImpl::~_HistoryItemImpl(void)
58 {
59 }
60
61
62 void
63 _HistoryItemImpl::SetHistoryItem(const String& url, const String& title, int id)
64 {
65         __id = id;
66         __url = url;
67         __title = title;
68 }
69
70
71 String
72 _HistoryItemImpl::GetTitle(void) const
73 {
74         return __title;
75 }
76
77
78 String
79 _HistoryItemImpl::GetUrl(void) const
80 {
81         return __url;
82 }
83
84
85 Bitmap*
86 _HistoryItemImpl::GetFaviconN(void) const
87 {
88         result r = E_SUCCESS;
89         Frame* pFrame = null;
90
91         Evas_Object* pIcon = null;
92
93         Ewk_Context* pDefaultContext = null;
94         std::unique_ptr<char[]> pUrl;
95         std::unique_ptr<Bitmap> pBitmapImage;
96
97         int ret = 0;
98         Dimension dimension;
99         BufferInfo bufferInfo;
100         ByteBuffer byteBuffer;
101
102         Evas* pEvas = _Utility::GetEvasFromUiApp(pFrame);
103         SysTryCatch(NID_WEB_CTRL, pEvas, , E_SYSTEM, "[E_SYSTEM] Propagating.");
104
105         if( __id == -1)
106         {
107                 pDefaultContext = ewk_context_default_get();
108
109                 pUrl = std::unique_ptr<char[]>(_StringConverter::CopyToCharArrayN(__url));
110                 pIcon = ewk_context_icon_database_icon_object_add(pDefaultContext, pUrl.get(), pEvas);
111         }
112         else
113         {
114                 ret = favorites_history_get_favicon(__id, pEvas, &pIcon);
115                 SysTryCatch(NID_WEB_CTRL, ret == FAVORITES_ERROR_NONE, , E_SYSTEM, "[E_SYSTEM] Propagating.");
116         }
117
118         if (!pIcon)
119         {
120                 return null;
121         }
122
123         r = _Utility::GetPixelBufferFromEvasObject(pIcon,  bufferInfo);
124         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
125
126         dimension.width = bufferInfo.width;
127         dimension.height = bufferInfo.height;
128
129         r = byteBuffer.Construct(reinterpret_cast < byte* >(bufferInfo.pPixels), 0, dimension.height * dimension.width * 32, dimension.height * dimension.width * 32 );
130         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
131
132         pBitmapImage = std::unique_ptr<Bitmap>(new (std::nothrow) Bitmap());
133         SysTryCatch(NID_WEB_CTRL, pBitmapImage.get(), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
134
135         r = pBitmapImage->Construct(byteBuffer, dimension, BITMAP_PIXEL_FORMAT_ARGB8888);
136         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
137
138
139         delete pFrame;
140
141         return pBitmapImage.release();
142
143 CATCH:
144         delete pFrame;
145
146         return null;
147 }
148
149
150 _HistoryItemImpl*
151 _HistoryItemImpl::GetInstance(HistoryItem* pHistoryItem)
152 {
153         return pHistoryItem->__pHistoryItemImpl;
154 }
155
156
157 const _HistoryItemImpl*
158 _HistoryItemImpl::GetInstance(const HistoryItem* pHistoryItem)
159 {
160         return pHistoryItem->__pHistoryItemImpl;
161 }
162
163
164 }} // Tizen::Web