Fix for lockup
[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 <FWebHistoryItem.h>
34 #include "FWeb_HistoryItemImpl.h"
35 #include "FWebCtrl_Utility.h"
36
37
38 using namespace Tizen::Base;
39 using namespace Tizen::Graphics;
40 using namespace Tizen::Web::Controls;
41
42
43 namespace Tizen { namespace Web
44 {
45
46
47 _HistoryItemImpl::_HistoryItemImpl(void)
48         : __id(-1)
49         , __url(L"")
50         , __title(L"")
51 {
52 }
53
54
55 _HistoryItemImpl::~_HistoryItemImpl(void)
56 {
57 }
58
59
60 void
61 _HistoryItemImpl::SetHistoryItem(const String& url, const String& title, int id)
62 {
63         __id = id;
64         __url = url;
65         __title = title;
66 }
67
68
69 String
70 _HistoryItemImpl::GetTitle(void) const
71 {
72         return __title;
73 }
74
75
76 String
77 _HistoryItemImpl::GetUrl(void) const
78 {
79         return __url;
80 }
81
82
83 Bitmap*
84 _HistoryItemImpl::GetFaviconN(void) const
85 {
86         result r = E_SUCCESS;
87
88         Evas* pEvas = _Utility::GetEvasFromUiApp();
89         SysTryReturn(NID_WEB_CTRL, pEvas, null, E_SYSTEM, "[E_SYSTEM] Propagating.");
90
91         Evas_Object* pIcon = null;
92         if( __id == -1)
93         {
94                 Ewk_Context* pDefaultContext = ewk_context_default_get();
95
96                 const std::unique_ptr<char[]> pUrl(_StringConverter::CopyToCharArrayN(__url));
97                 pIcon = ewk_context_icon_database_icon_object_add(pDefaultContext, pUrl.get(), pEvas);
98         }
99         else
100         {
101                 int ret = favorites_history_get_favicon(__id, pEvas, &pIcon);
102                 SysTryReturn(NID_WEB_CTRL, ret == FAVORITES_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] Propagating.");
103         }
104
105         if (!pIcon)
106         {
107                 return null;
108         }
109
110         BufferInfo bufferInfo;
111         r = _Utility::GetPixelBufferFromEvasObject(pIcon,  bufferInfo);
112         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
113
114         const Dimension dimension(bufferInfo.width, bufferInfo.height);
115
116         ByteBuffer byteBuffer;
117         r = byteBuffer.Construct(reinterpret_cast < byte* >(bufferInfo.pPixels), 0, dimension.height * dimension.width * 32, dimension.height * dimension.width * 32 );
118         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
119
120         std::unique_ptr<Bitmap> pBitmapImage(new (std::nothrow) Bitmap());
121         SysTryReturn(NID_WEB_CTRL, pBitmapImage.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
122
123         r = pBitmapImage->Construct(byteBuffer, dimension, BITMAP_PIXEL_FORMAT_ARGB8888);
124         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
125
126         return pBitmapImage.release();
127 }
128
129
130 _HistoryItemImpl*
131 _HistoryItemImpl::GetInstance(HistoryItem* pHistoryItem)
132 {
133         return pHistoryItem->__pHistoryItemImpl;
134 }
135
136
137 const _HistoryItemImpl*
138 _HistoryItemImpl::GetInstance(const HistoryItem* pHistoryItem)
139 {
140         return pHistoryItem->__pHistoryItemImpl;
141 }
142
143
144 }} // Tizen::Web