2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FWebWebHistory.cpp
20 * @brief The file contains the definition of WebHistory class.
22 * This file contains the definition of WebHistory class.
25 #include <favorites.h>
26 #include <unique_ptr.h>
27 #include <FBaseSysLog.h>
28 #include <FGrpBitmap.h>
29 #include <FWebBookmarkItem.h>
30 #include <FWebWebBookmark.h>
31 #include <FBase_StringConverter.h>
32 #include "FWeb_BookmarkItemImpl.h"
33 #include "FWeb_WebBookmarkImpl.h"
34 #include "FWebCtrl_Utility.h"
37 using namespace Tizen::Base;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Web::Controls;
42 namespace Tizen { namespace Web
47 _BookmarkForEachCb(favorites_bookmark_entry_s* pItem, void* pUserData)
49 SysAssertf(pItem && pUserData, "Failed to request");
53 _WebBookmarkImpl* pImpl = reinterpret_cast< _WebBookmarkImpl* >(pUserData);
55 String url(pItem->address);
56 String title(pItem->title);
58 r = pImpl->AddItem(pItem->id, url, title, pItem->folder_id, pItem->is_folder);
59 SysTryReturn(NID_WEB, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
65 _WebBookmarkImpl::_WebBookmarkImpl(void)
66 : __rootFolderId(ROOT_FOLDER_ID)
71 _WebBookmarkImpl::~_WebBookmarkImpl(void)
77 _WebBookmarkImpl::Construct(void)
81 int ret = favorites_bookmark_get_root_folder_id(&__rootFolderId);
82 SysTryReturnResult(NID_WEB, ret == FAVORITES_ERROR_NONE, E_SYSTEM, "Failed to get root folder id.");
84 r = __bookmarkList.Construct();
85 SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
87 ret = favorites_bookmark_foreach(_BookmarkForEachCb, this);
88 SysTryCatch(NID_WEB, ret == FAVORITES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to set bookmark callback.");
93 __bookmarkList.RemoveAll(true);
100 _WebBookmarkImpl::AddFolder(const String& title, RecordId parentId, RecordId& folderId)
102 result r = E_SUCCESS;
104 std::unique_ptr<char[]> pTitle(_StringConverter::CopyToCharArrayN(title));
105 SysTryReturn(NID_WEB, pTitle.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
107 int realParentId = parentId;
109 if (parentId == ROOT_FOLDER_ID)
111 realParentId = __rootFolderId;
114 int ret = favorites_bookmark_add(pTitle.get(), null, realParentId, 1, &folderId);
115 SysTryReturn(NID_WEB, ret == FAVORITES_ERROR_NONE, ConvertErrorCode(ret), ConvertErrorCode(ret), "[%s] Propagating.", ConvertErrorCode(ret));
122 _WebBookmarkImpl::AddBookmark(const String& title, const String& url, RecordId parentId, RecordId& bookmarkId)
124 std::unique_ptr<char[]> pTitle(_StringConverter::CopyToCharArrayN(title));
125 SysTryReturn(NID_WEB, pTitle.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
126 std::unique_ptr<char[]> pUrl(_StringConverter::CopyToCharArrayN(url));
127 SysTryReturn(NID_WEB, pUrl.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
129 int realParentId = parentId;
131 if (parentId == ROOT_FOLDER_ID)
133 realParentId = __rootFolderId;
136 int ret = favorites_bookmark_add(pTitle.get(), pUrl.get(), realParentId, 0, &bookmarkId);
137 SysTryReturn(NID_WEB, ret == FAVORITES_ERROR_NONE, ConvertErrorCode(ret), ConvertErrorCode(ret), "[%s] Propagating.", ConvertErrorCode(ret));
144 _WebBookmarkImpl::SetFavicon(RecordId bookmarkId, const Bitmap& favicon)
146 SysTryReturnResult(NID_WEB, favicon.GetWidth() == 16 && favicon.GetHeight() == 16, E_INVALID_DATA, "The size of a favicon must be 16 X 16");
147 SysTryReturnResult(NID_WEB, favicon.GetPixelColorFormat() == BITMAP_PIXEL_FORMAT_ARGB8888, E_INVALID_DATA, "The pixel format of a favicon must be ARGB8888");
149 result r = E_SUCCESS;
151 Evas* pEvas = _Utility::GetEvasFromUiApp();
152 SysTryReturn(NID_WEB, pEvas, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
154 Evas_Object* pIcon = evas_object_image_filled_add(pEvas);
155 evas_object_image_colorspace_set(pIcon, EVAS_COLORSPACE_ARGB8888);
156 evas_object_image_filled_set(pIcon, EINA_TRUE);
157 evas_object_image_alpha_set(pIcon,EINA_TRUE);
159 Bitmap& temp = const_cast< Bitmap& >(favicon);
161 BufferInfo bufferInfo;
162 r = temp.Lock(bufferInfo);
163 SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", r);
165 evas_object_image_size_set(pIcon, bufferInfo.width, bufferInfo.height);
166 evas_object_image_fill_set(pIcon, 0, 0, bufferInfo.width, bufferInfo.height);
167 evas_object_image_data_set(pIcon, bufferInfo.pPixels);
170 SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", r);
172 int ret = favorites_bookmark_set_favicon(bookmarkId, pIcon);
173 SysTryReturn(NID_WEB, ret == FAVORITES_ERROR_NONE, ConvertErrorCode(ret), ConvertErrorCode(ret), "[%s] Propagating.", ConvertErrorCode(ret));
180 _WebBookmarkImpl::GetItemAt(int index) const
182 SysTryReturn(NID_WEB,
183 (index >= 0 && index < GetItemCount()), null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] The index is out of range.");
185 return dynamic_cast < const BookmarkItem* >(__bookmarkList.GetAt(index));
190 _WebBookmarkImpl::GetItemCount(void) const
192 return __bookmarkList.GetCount();
197 _WebBookmarkImpl::GetRootFolderId(void) const
200 int ret = favorites_bookmark_get_root_folder_id(&folderId);
201 SysTryReturn(NID_WEB, ret == FAVORITES_ERROR_NONE, -1, ConvertErrorCode(ret), "[%s] Propagating.", ConvertErrorCode(ret));
208 _WebBookmarkImpl::AddItem(RecordId id, const String& url, const String& title, RecordId parentId, bool isFolder)
210 result r = E_SUCCESS;
212 std::unique_ptr<BookmarkItem> pBookmarkItem(new (std::nothrow) BookmarkItem());
213 SysTryReturnResult(NID_WEB, pBookmarkItem.get(), E_OUT_OF_MEMORY, "Memory allocation failed");
215 _BookmarkItemImpl* pBookmarkItemImpl = _BookmarkItemImpl::GetInstance(pBookmarkItem.get());
216 SysTryReturn(NID_WEB, pBookmarkItemImpl, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
218 int realParentId = parentId;
220 if (parentId == __rootFolderId)
222 realParentId = ROOT_FOLDER_ID;
225 pBookmarkItemImpl->SetBookmarkItem(id, url, title, realParentId, isFolder);
227 r = __bookmarkList.Add(*pBookmarkItem.get());
228 SysTryReturn(NID_WEB, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
229 pBookmarkItem.release();
236 _WebBookmarkImpl::RemoveAll(void)
238 int ret = favorites_bookmark_delete_all_bookmarks();
239 SysTryReturn(NID_WEB, ret == FAVORITES_ERROR_NONE, ConvertErrorCode(ret), ConvertErrorCode(ret), "[%s] Propagating.", ConvertErrorCode(ret));
246 _WebBookmarkImpl::ConvertErrorCode(int err) const
248 result r = E_SUCCESS;
252 case FAVORITES_ERROR_INVALID_PARAMETER:
256 case FAVORITES_ERROR_ITEM_ALREADY_EXIST:
257 r = E_OBJ_ALREADY_EXIST;
260 case FAVORITES_ERROR_DB_FAILED:
271 _WebBookmarkImpl::GetInstance(WebBookmark* pWebBookmark)
273 return pWebBookmark->__pWebBookmarkImpl;
277 const _WebBookmarkImpl*
278 _WebBookmarkImpl::GetInstance(const WebBookmark* pWebBookmark)
280 return pWebBookmark->__pWebBookmarkImpl;