Fix after certificate popup
[framework/osp/web.git] / src / FWeb_BookmarkItemImpl.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 <favorites.h>
25 #include <unique_ptr.h>
26 #include <FBaseBoolean.h>
27 #include <FBaseInteger.h>
28 #include <FBaseSysLog.h>
29 #include <FGrpBitmap.h>
30 #include <FGrpDimension.h>
31 #include <FWebBookmarkItem.h>
32 #include "FWeb_BookmarkItemImpl.h"
33 #include "FWebCtrl_Utility.h"
34
35
36 using namespace Tizen::Base;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Web::Controls;
39
40
41 namespace Tizen { namespace Web
42 {
43
44
45 _BookmarkItemImpl::_BookmarkItemImpl(void)
46         : __isFolder(false)
47         , __id(0)
48         , __parentId(0)
49         , __url(L"")
50         , __title(L"")
51
52 {
53 }
54
55
56 _BookmarkItemImpl::~_BookmarkItemImpl(void)
57 {
58 }
59
60
61 void
62 _BookmarkItemImpl::SetBookmarkItem(RecordId id, const String& url, const String& title, RecordId parentId, bool isFolder)
63 {
64         __id = id;
65         __url = url;
66         __title = title;
67         __parentId = parentId;
68         __isFolder = isFolder;
69 }
70
71
72 String
73 _BookmarkItemImpl::GetTitle(void) const
74 {
75         return __title;
76 }
77
78
79 String
80 _BookmarkItemImpl::GetUrl(void) const
81 {
82         return __url;
83 }
84
85
86 Bitmap*
87 _BookmarkItemImpl::GetFaviconN(void) const
88 {
89         result r = E_SUCCESS;
90
91         Evas* pEvas = _Utility::GetEvasFromUiApp();
92         SysTryReturn(NID_WEB, pEvas, null, E_SYSTEM, "[E_SYSTEM] Propagating.");
93
94         Evas_Object* pIcon = null;
95         int ret = favorites_bookmark_get_favicon(__id, pEvas, &pIcon);
96         SysTryReturn(NID_WEB, ret == FAVORITES_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] Propagating.");
97
98         if (!pIcon)
99         {
100                 return null;
101         }
102
103         BufferInfo bufferInfo;
104         r = _Utility::GetPixelBufferFromEvasObject(pIcon,  bufferInfo);
105         SysTryReturn(NID_WEB, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
106
107         const Dimension dimension(bufferInfo.width, bufferInfo.height);
108
109         ByteBuffer byteBuffer;
110         r = byteBuffer.Construct(reinterpret_cast < byte* >(bufferInfo.pPixels), 0, dimension.height * dimension.width * 32, dimension.height * dimension.width * 32 );
111         SysTryReturn(NID_WEB, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
112
113         std::unique_ptr<Bitmap> pImage(new (std::nothrow) Bitmap());
114         SysTryReturn(NID_WEB, pImage.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
115
116         r = pImage->Construct(byteBuffer, dimension, BITMAP_PIXEL_FORMAT_ARGB8888);
117         SysTryReturn(NID_WEB, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
118
119         return pImage.release();
120 }
121
122
123 RecordId
124 _BookmarkItemImpl::GetParentFolderId(void) const
125 {
126         return __parentId;
127 }
128
129
130 bool
131 _BookmarkItemImpl::IsFolder(void) const
132 {
133         return __isFolder;
134 }
135
136
137 bool
138 _BookmarkItemImpl::Equals(const Object& obj) const
139 {
140         const _BookmarkItemImpl* pRhs = dynamic_cast< const _BookmarkItemImpl* >(&obj);
141         if (pRhs == null)
142         {
143                 return false;
144         }
145
146         return __id == pRhs->__id && __url == pRhs->__url && __title == pRhs->__title && __parentId == pRhs->__parentId
147                    && __isFolder == pRhs->__isFolder;
148 }
149
150
151 int
152 _BookmarkItemImpl::GetHashCode(void) const
153 {
154         return Integer(__id).GetHashCode() + __url.GetHashCode() + __title.GetHashCode()
155                 + Integer(__parentId).GetHashCode() + Boolean(__isFolder).GetHashCode();
156 }
157
158
159 _BookmarkItemImpl*
160 _BookmarkItemImpl::GetInstance(BookmarkItem* pBookmarkItem)
161 {
162         return pBookmarkItem->__pBookmarkItemImpl;
163 }
164
165
166 const _BookmarkItemImpl*
167 _BookmarkItemImpl::GetInstance(const BookmarkItem* pBookmarkItem)
168 {
169         return pBookmarkItem->__pBookmarkItemImpl;
170 }
171
172
173 }} // Tizen::Web