Task TT-75 Implement "Main page loading UI" view
[profile/tv/apps/web/browser.git] / services / BookmarkService / BookmarkService.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /*
18  *
19  * Created on: Apr, 2014
20  *     Author: k.dobkowski
21  */
22
23 #include "browser_config.h"
24 #include "BookmarkService.h"
25 #include <Elementary.h>
26
27 #include <boost/any.hpp>
28 #include <BrowserAssert.h>
29
30 #include "ServiceManager.h"
31 #include "service_macros.h"
32 #include "BrowserLogger.h"
33 #include "AbstractWebEngine.h"
34 #include "AbstractMainWindow.h"
35 #include "EflTools.h"
36 #include "GeneralTools.h"
37
38 #include <web/web_bookmark.h>
39
40
41
42 namespace tizen_browser{
43 namespace services{
44
45 EXPORT_SERVICE(BookmarkService, "org.tizen.browser.favoriteservice")
46
47 BookmarkService::BookmarkService()
48 {
49     int ret = bp_bookmark_adaptor_initialize();
50     if (ret<0){
51         BROWSER_LOGE("Error! Could not initialize bookmark service!");
52         return;
53     }
54 }
55
56 BookmarkService::~BookmarkService()
57 {
58     bp_bookmark_adaptor_deinitialize();
59     free_path_history();
60 }
61
62 /*private*/ std::shared_ptr<tizen_browser::services::StorageService> BookmarkService::getStorageManager() {
63     return m_storageManager;
64 }
65
66 void BookmarkService::synchronizeBookmarks()
67 {
68     m_bookmarks.clear();
69 }
70
71 std::shared_ptr<BookmarkItem> BookmarkService::addToBookmarks(
72                                                 const std::string & address,
73                                                 const std::string & tittle,
74                                                 const std::string & note,
75                                                 std::shared_ptr<tizen_browser::tools::BrowserImage> thumbnail,
76                                                 std::shared_ptr<tizen_browser::tools::BrowserImage> favicon,
77                                                 unsigned int dirId)
78 {
79     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
80     bp_bookmark_property_cond_fmt properties;
81     properties.parent = -1;
82     properties.type = 0;
83     properties.is_operator = -1;
84     properties.is_editable = -1;
85     //conditions for querying
86     bp_bookmark_rows_cond_fmt conds;
87     conds.limit = 1;
88     conds.offset = 0;
89     conds.order_offset = BP_BOOKMARK_O_SEQUENCE;
90     conds.ordering = 0;
91     conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
92     conds.period_type = BP_BOOKMARK_DATE_ALL;
93
94     int id = -1;
95     int *ids = nullptr;
96     int ids_count = -1;
97     int ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_URL, address.c_str(), 0);
98     free(ids);
99     if (ret < 0){
100         BROWSER_LOGE("Error! Could not get ids!");
101         return std::make_shared<BookmarkItem>();
102     }
103
104     bp_bookmark_info_fmt info;
105     info.type = 0;
106     info.parent = dirId;
107     info.sequence = -1;
108     info.access_count = -1;
109     info.editable = 1;
110
111     if (!address.empty()) {
112         info.url = (char*) address.c_str();
113     }
114     if (!tittle.empty())
115         info.title = (char*) tittle.c_str();
116
117     ret = bp_bookmark_adaptor_easy_create(&id, &info);
118     if (ret < 0){
119         BROWSER_LOGE("Error! Could not create new bookmark!");
120         return std::make_shared<BookmarkItem>();
121     }
122
123     // max sequence
124     ret = bp_bookmark_adaptor_set_sequence(id, -1);
125
126     if(thumbnail)
127     {
128         std::unique_ptr<tizen_browser::tools::Blob> thumb_blob = tizen_browser::tools::EflTools::getBlobPNG(thumbnail);
129         unsigned char * thumb = std::move((unsigned char*)thumb_blob->getData());
130         bp_bookmark_adaptor_set_snapshot(id, thumbnail->width, thumbnail->height, thumb, thumb_blob->getLength());
131     }
132     if(favicon)
133     {
134         std::unique_ptr<tizen_browser::tools::Blob> favicon_blob = tizen_browser::tools::EflTools::getBlobPNG(favicon);
135         unsigned char * fav = std::move((unsigned char*)favicon_blob->getData());
136         bp_bookmark_adaptor_set_icon(id, favicon->width, favicon->height, fav, favicon_blob->getLength());
137     }
138     std::shared_ptr<BookmarkItem> bookmark = std::make_shared<BookmarkItem>(address, tittle, note, dirId, id);
139     bookmark->setThumbnail(thumbnail);
140     bookmark->setFavicon(favicon);
141     m_bookmarks.push_back(bookmark);
142     bookmarkAdded(bookmark);
143     return bookmark;
144 }
145
146 bool BookmarkService::deleteBookmark(const std::string & url)
147 {
148     int id = getBookmarkId(url);
149     if (id!=0)
150         bp_bookmark_adaptor_delete(id);
151     bookmarkDeleted(url);
152     return true;
153 }
154
155 int BookmarkService::countBookmarksAndSubFolders()
156 {
157     return m_bookmarks.size();
158 }
159
160 bool BookmarkService::bookmarkExists(const std::string & url)
161 {
162     return 0 != getBookmarkId(url);
163 }
164
165 int BookmarkService::getBookmarkId(const std::string & url)
166 {
167     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
168     bp_bookmark_property_cond_fmt properties;
169     properties.parent = -1;
170     properties.type = 0;
171     properties.is_operator = 0;
172     properties.is_editable = -1;
173     bp_bookmark_rows_cond_fmt conds;
174     conds.limit = -1;
175     conds.offset = 0;
176     conds.order_offset = BP_BOOKMARK_O_DATE_CREATED;
177     conds.ordering = 0;
178     conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
179     conds.period_type = BP_BOOKMARK_DATE_ALL;
180     int *ids = nullptr;
181     int ids_count = 0;
182     int i = 0;
183     int ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_URL, url.c_str(), 0);
184     if (ids_count > 0){
185         i = *ids;
186     }
187     free(ids);
188     return i;
189 }
190
191 std::vector<std::shared_ptr<BookmarkItem> > BookmarkService::getBookmarks(int folder_id)
192 {
193     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
194     int *ids = nullptr;
195     int ids_count = 0;
196     int ret = bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, folder_id, 0, -1, -1, BP_BOOKMARK_O_SEQUENCE, 0);
197     if (ret<0){
198         BROWSER_LOGE("Error! Could not get ids!");
199         return std::vector<std::shared_ptr<BookmarkItem>>();
200     }
201
202     m_bookmarks.clear();
203
204     BROWSER_LOGD("Bookmark items: %d", ids_count);
205
206     for(int i = 0; i<ids_count; i++)
207     {
208         bp_bookmark_info_fmt bookmark_info;
209         bp_bookmark_adaptor_get_easy_all(ids[i], &bookmark_info);
210
211         std::shared_ptr<BookmarkItem> bookmark = std::make_shared<BookmarkItem>(std::string(bookmark_info.url),std::string(bookmark_info.title), std::string(""),(int) bookmark_info.parent, ids[i]);
212
213         std::shared_ptr<tizen_browser::tools::BrowserImage> bi = std::make_shared<tizen_browser::tools::BrowserImage>();
214         bi->imageType = tizen_browser::tools::BrowserImage::ImageType::ImageTypePNG;
215         bi->width = bookmark_info.thumbnail_width;
216         bi->height = bookmark_info.thumbnail_height;
217         bi->dataSize = bookmark_info.thumbnail_length;
218         bi->imageData = (void*)malloc(bookmark_info.thumbnail_length);
219         memcpy(bi->imageData, (void*)bookmark_info.thumbnail, bookmark_info.thumbnail_length);
220         bookmark->setThumbnail(bi);
221
222         std::shared_ptr<tizen_browser::tools::BrowserImage> fav = std::make_shared<tizen_browser::tools::BrowserImage>();
223         unsigned char *image_bytes;
224         bp_bookmark_adaptor_get_icon(ids[i], &fav->width, &fav->height, &image_bytes, &fav->dataSize);
225         fav->imageType = tizen_browser::tools::BrowserImage::ImageType::ImageTypePNG;
226
227         fav->imageData = (void*)malloc(bookmark_info.favicon_length);
228         memcpy(fav->imageData, (void*)image_bytes, bookmark_info.favicon_length);
229         bookmark->setFavicon(fav);
230
231         m_bookmarks.push_back(bookmark);
232     }
233     free(ids);
234     return m_bookmarks;
235 }
236
237 std::vector<std::shared_ptr<BookmarkItem> > BookmarkService::getBookmarkFolders()
238 {
239     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
240     int *ids = nullptr;
241     int ids_count = 0;
242     int ret = bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, -1, 1, -1, -1, BP_BOOKMARK_O_SEQUENCE, 0);
243     if (ret<0){
244         BROWSER_LOGE("Error! Could not get ids!");
245         return std::vector<std::shared_ptr<BookmarkItem>>();
246     }
247
248     m_bookmarks.clear();
249
250     BROWSER_LOGD("Bookmark items: %d", ids_count);
251
252     for(int i = 0; i<ids_count; i++)
253     {
254         bp_bookmark_info_fmt bookmark_info;
255         bp_bookmark_adaptor_get_easy_all(ids[i], &bookmark_info);
256
257         std::shared_ptr<BookmarkItem> bookmark = std::make_shared<BookmarkItem>(std::string(bookmark_info.url ? bookmark_info.url : ""),std::string(bookmark_info.title ? bookmark_info.title : ""), std::string(""),(int) bookmark_info.parent, ids[i]);
258         std::shared_ptr<tizen_browser::tools::BrowserImage> bi = std::make_shared<tizen_browser::tools::BrowserImage>();
259         bi->imageType = tizen_browser::tools::BrowserImage::ImageType::ImageTypePNG;
260         bi->width = bookmark_info.thumbnail_width;
261         bi->height = bookmark_info.thumbnail_height;
262         bi->dataSize = bookmark_info.thumbnail_length;
263         bi->imageData = (void*)malloc(bookmark_info.thumbnail_length);
264         memcpy(bi->imageData, (void*)bookmark_info.thumbnail, bookmark_info.thumbnail_length);
265         bookmark->setThumbnail(bi);
266
267         std::shared_ptr<tizen_browser::tools::BrowserImage> fav = std::make_shared<tizen_browser::tools::BrowserImage>();
268         unsigned char *image_bytes;
269         bp_bookmark_adaptor_get_icon(ids[i], &fav->width, &fav->height, &image_bytes, &fav->dataSize);
270         fav->imageType = tizen_browser::tools::BrowserImage::ImageType::ImageTypePNG;
271
272         fav->imageData = (void*)malloc(bookmark_info.favicon_length);
273         memcpy(fav->imageData, (void*)image_bytes, bookmark_info.favicon_length);
274         bookmark->setFavicon(fav);
275         if(!bookmark_info.is_operator)
276            m_bookmarks.push_back(bookmark);
277         else
278            m_bookmarks.insert(m_bookmarks.begin(),bookmark);
279     }
280     free(ids);
281     return m_bookmarks;
282 }
283
284
285 bool BookmarkService::deleteAllBookmarks()
286 {
287     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
288     bp_bookmark_adaptor_reset();
289     m_bookmarks.clear();
290     bookmarksDeleted();
291     return true;
292 }
293
294 int BookmarkService::get_root_folder_id(void)
295 {
296     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
297     int root_id = 0;
298     bp_bookmark_adaptor_get_root(&root_id);
299     return root_id;
300 }
301
302 int BookmarkService::save_folder(const char *title, int *saved_folder_id, int parent_id, int by_operator)
303 {
304     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
305
306     bp_bookmark_property_cond_fmt properties;
307     properties.parent = parent_id;
308     properties.type = 1;
309     properties.is_operator = -1;
310     properties.is_editable = -1;
311     //conditions for querying
312     bp_bookmark_rows_cond_fmt conds;
313     conds.limit = 1;
314     conds.offset = 0;
315     conds.order_offset = BP_BOOKMARK_O_SEQUENCE;
316     conds.ordering = 0;
317     conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
318     conds.period_type = BP_BOOKMARK_DATE_ALL;
319     int id = -1;
320     int *ids = nullptr;
321     int ids_count = -1;
322     int ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_TITLE, title, 0);
323     free(ids);
324
325     if (ret < 0)
326         return -1;
327
328     if (ids_count > 0) {
329         return 0;
330     }
331
332     bp_bookmark_info_fmt info;
333     info.type = 1;
334     info.parent = parent_id;
335     info.sequence = -1;
336     info.is_operator = by_operator;
337     info.access_count = -1;
338     info.editable = 1;
339     if (title != nullptr && strlen(title) > 0)
340     {
341         info.title = (char *)title;
342     }
343     ret = bp_bookmark_adaptor_easy_create(&id, &info);
344
345     if (ret == 0) {
346         ret = bp_bookmark_adaptor_set_sequence(id, -1); // max sequence
347         if (ret == 0) {
348            *saved_folder_id = id;
349            BROWSER_LOGD("bmsvc_add_bookmark is success(id:%d)", *saved_folder_id);
350            bp_bookmark_adaptor_publish_notification();
351            return id;
352         }
353     }
354     BROWSER_LOGD("bmsvc_add_bookmark is failed");
355     return -1;
356 }
357
358 bool BookmarkService::delete_by_id(int id)
359 {
360     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
361     BROWSER_LOGD("id[%d]", id);
362     if (bp_bookmark_adaptor_delete(id) < 0)
363         return false;
364     else {
365         bp_bookmark_adaptor_publish_notification();
366         return true;
367     }
368 }
369
370 bool BookmarkService::delete_by_id_notify(int id)
371 {
372     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
373     BROWSER_LOGD("id[%d]", id);
374
375     BookmarkItem item;
376     get_item_by_id(id, &item);
377     return delete_by_id(id);
378 }
379
380 bool BookmarkService::delete_by_uri(const char *uri)
381 {
382     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
383     BROWSER_LOGD("uri[%s]", uri);
384     bp_bookmark_property_cond_fmt properties;
385     properties.parent = -1;
386     properties.type = 0;
387     properties.is_operator = -1;
388     properties.is_editable = -1;
389     //conditions for querying
390     bp_bookmark_rows_cond_fmt conds;
391     conds.limit = 1;
392     conds.offset = 0;
393     conds.order_offset = BP_BOOKMARK_O_SEQUENCE;
394     conds.ordering = 0;
395     conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
396     conds.period_type = BP_BOOKMARK_DATE_ALL;
397
398     int *ids = nullptr;
399     int ids_count = -1;
400     int ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_URL, uri, 0);
401     bool result = false;
402     if (ret >= 0 && ids_count > 0)
403     {
404         delete_by_id_notify(ids[0]);
405         free(ids);
406     }
407
408     return result;
409 }
410
411 int BookmarkService::update_bookmark(int id, const char *title, const char *uri, int parent_id, int order,
412                                      bool is_duplicate_check_needed, bool is_URI_check_needed)
413 {
414     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
415
416     bool is_URI_exist = (uri != nullptr && strlen(uri) > 0);
417     bool is_title_exist = (title != nullptr && strlen(title) > 0);
418     int ret = -1;
419     if (is_duplicate_check_needed) {
420         bp_bookmark_property_cond_fmt properties;
421         properties.parent = -1;
422         properties.type = 0;
423         properties.is_operator = -1;
424         properties.is_editable = -1;
425         //conditions for querying
426         bp_bookmark_rows_cond_fmt conds;
427         conds.limit = 1;
428         conds.offset = 0;
429         conds.order_offset = BP_BOOKMARK_O_SEQUENCE;
430         conds.ordering = 0;
431         conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
432         conds.period_type = BP_BOOKMARK_DATE_ALL;
433         int *ids = nullptr;
434         int ids_count = -1;
435         //This is a bookmark item so check for any such URL already exists
436         if (is_URI_exist && is_URI_check_needed) {
437             ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_URL, uri, 0);
438             free(ids);
439             if (ret < 0)
440                 return -1;
441         }
442         //This is a bookmark folder so check for any such folder with same title already exists
443         else if (is_title_exist) {
444             ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_TITLE, title, 0);
445             free(ids);
446             if (ret < 0)
447                 return -1;
448         }
449
450         if (ids_count > 0) {
451             BROWSER_LOGD("same bookmark already exist");
452             return 0;
453         }
454     }
455     bp_bookmark_info_fmt info;
456     info.type = -1;
457     info.parent = parent_id;
458     info.sequence = order;
459     info.editable = -1;
460     if (is_URI_exist)
461         info.url = (char *)uri;
462     if (is_title_exist)
463         info.title = (char *)title;
464
465     ret = bp_bookmark_adaptor_easy_create(&id, &info);
466     if (ret == 0) {
467         BROWSER_LOGD("bp_bookmark_adaptor_easy_create is success");
468         bp_bookmark_adaptor_publish_notification();
469         return 1;
470     }
471     int errcode = bp_bookmark_adaptor_get_errorcode();
472     BROWSER_LOGD("bp_bookmark_adaptor_easy_create is failed[%d]", errcode);
473     return -1;
474 }
475
476 int BookmarkService::update_bookmark_notify(int id, const char *title, const char *uri, int parent_id, int order,
477                                             bool is_duplicate_check_needed, bool is_URI_check_needed)
478 {
479     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
480     BROWSER_LOGD("");
481     int ret = update_bookmark(id, title, uri, parent_id, order, is_duplicate_check_needed, is_URI_check_needed);
482     return ret;
483 }
484
485 bool BookmarkService::is_in_bookmark(const char *uri)
486 {
487     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
488     BROWSER_LOGD("uri[%s]", uri);
489
490     int id = 0;
491     return get_id(uri, &id);
492 }
493
494 bool BookmarkService::is_in_folder(int parent_folder, const char *title)
495 {
496     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
497     BROWSER_LOGD("");
498
499     bp_bookmark_property_cond_fmt properties;
500     properties.parent = parent_folder;
501     properties.type = 1;
502     properties.is_operator = -1;
503     properties.is_editable = -1;
504     //conditions for querying
505     bp_bookmark_rows_cond_fmt conds;
506     conds.limit = 1;
507     conds.offset = 0;
508     conds.order_offset = BP_BOOKMARK_O_SEQUENCE;
509     conds.ordering = 0;
510     conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
511     conds.period_type = BP_BOOKMARK_DATE_ALL;
512
513     int *ids = nullptr;
514     int ids_count = -1;
515     int ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_TITLE, title, 0);
516     free(ids);
517     return ((ret >= 0) && (ids_count > 0));
518 }
519
520 bool BookmarkService::get_id(const char *uri, int *bookmark_id)
521 {
522     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
523     bp_bookmark_property_cond_fmt properties;
524     properties.parent = -1;
525     properties.type = 0;
526     properties.is_operator = -1;
527     properties.is_editable = -1;
528     //conditions for querying
529     bp_bookmark_rows_cond_fmt conds;
530     conds.limit = 1;
531     conds.offset = 0;
532     conds.order_offset = BP_BOOKMARK_O_SEQUENCE;
533     conds.ordering = 0;
534     conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
535     conds.period_type = BP_BOOKMARK_DATE_ALL;
536
537     int *ids = nullptr;
538     int ids_count = -1;
539     int ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_URL, uri, 0);
540     free(ids);
541     bool result = ((ret >= 0) && (ids_count > 0));
542     if (result) {
543         *bookmark_id = ids[0];
544     }
545     return result;
546 }
547
548 bool BookmarkService::get_folder_id(const char *title, int parent_id, int *folder_id)
549 {
550     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
551
552     bp_bookmark_property_cond_fmt properties;
553     properties.parent = parent_id;
554     properties.type = 1;
555     properties.is_operator = -1;
556     properties.is_editable = -1;
557     //conditions for querying
558     bp_bookmark_rows_cond_fmt conds;
559     conds.limit = 1;
560     conds.offset = 0;
561     conds.order_offset = BP_BOOKMARK_O_SEQUENCE;
562     conds.ordering = 0;
563     conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
564     conds.period_type = BP_BOOKMARK_DATE_ALL;
565
566     int *ids = nullptr;
567     int ids_count = -1;
568     int ret = bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds, BP_BOOKMARK_O_TITLE, title, 0);
569     free(ids);
570     bool result = ((ret >= 0) && (ids_count > 0));
571     if (result) {
572         *folder_id = ids[0];
573     }
574     return false;
575 }
576
577 bool BookmarkService::get_item_by_id(int id, BookmarkItem *item)
578 {
579     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
580     BROWSER_LOGD("ID: %d", id);
581     if (!item) {
582         BROWSER_LOGE("item is nullptr");
583         return false;
584     }
585
586     if (id == get_root_folder_id()) {
587         item->setTittle("Bookmarks");
588         item->setAddress("");
589         item->setId(id);
590         item->set_folder_flag(1);
591         item->set_editable_flag(1);
592         item->setDir(-1);
593         return true;
594     }
595     bp_bookmark_info_fmt info;
596     if (bp_bookmark_adaptor_get_info(id, (BP_BOOKMARK_O_TYPE | BP_BOOKMARK_O_PARENT | BP_BOOKMARK_O_SEQUENCE |
597                                      BP_BOOKMARK_O_IS_EDITABLE | BP_BOOKMARK_O_URL |BP_BOOKMARK_O_TITLE), &info) == 0) {
598         item->setId(id);
599         item->set_folder_flag(static_cast<bool>(info.type));
600         item->setDir(info.parent);
601         item->set_editable_flag(static_cast<bool>(info.editable));
602
603         if (info.url != nullptr && strlen(info.url) > 0)
604             item->setAddress(info.url);
605
606         if (info.title != nullptr && strlen(info.title) > 0)
607             item->setTittle(info.title);
608
609         bp_bookmark_adaptor_easy_free(&info);
610         return true;
611     }
612     BROWSER_LOGD("bp_bookmark_adaptor_get_easy_all is failed");
613     return false;
614 }
615
616 std::vector<BookmarkItem *>  BookmarkService::get_list_by_folder(const int folder_id)
617 {
618     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
619     std::vector<BookmarkItem *> list;
620     BROWSER_LOGD("folder ID: %d", folder_id);
621     int *ids = nullptr;
622     int ids_count = -1;
623
624     if (bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, folder_id, -1, -1, -1, BP_BOOKMARK_O_SEQUENCE, 1) < 0) {
625         BROWSER_LOGD("bp_bookmark_adaptor_get_sequence_child_ids_p is failed");
626         return list;
627     }
628
629     if (ids_count <= 0) {
630         BROWSER_LOGD("bookmark list is empty");
631         free(ids);
632         return list;
633     }
634
635     bp_bookmark_info_fmt info;
636     for(int i = 0; i < ids_count; i++) {
637         if (bp_bookmark_adaptor_get_info(ids[i], (BP_BOOKMARK_O_TYPE |
638                 BP_BOOKMARK_O_SEQUENCE |
639                 BP_BOOKMARK_O_IS_EDITABLE | BP_BOOKMARK_O_URL |
640                 BP_BOOKMARK_O_TITLE | BP_BOOKMARK_O_IS_OPERATOR), &info) == 0) {
641             BookmarkItem *item = new BookmarkItem();
642             item->setId(ids[i]);
643
644             item->set_folder_flag(static_cast<bool>(info.type));
645             item->setDir(folder_id);
646             item->set_editable_flag(static_cast<bool>(info.editable));
647
648             if (info.url != nullptr && strlen(info.url) > 0)
649                 item->setAddress(info.url);
650
651             if (info.title != nullptr && strlen(info.title) > 0)
652                 item->setTittle(info.title);
653
654             list.push_back(item);
655             bp_bookmark_adaptor_easy_free(&info);
656         }
657     }
658     free(ids);
659     return list;
660 }
661
662 bool BookmarkService::get_list_users_by_folder(const int folder_id, std::vector<BookmarkItem *> &list)
663 {
664     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
665     BROWSER_LOGD("folder ID: %d", folder_id);
666     int *ids = nullptr;
667     int ids_count = -1;
668     if (bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, folder_id, -1, 0, -1, BP_BOOKMARK_O_SEQUENCE, 1) < 0) {
669         BROWSER_LOGD("bp_bookmark_adaptor_get_ids_p is failed");
670         return false;
671     }
672
673     if (ids_count <= 0) {
674         BROWSER_LOGD("bookmark list is empty");
675         free(ids);
676         return false;
677     }
678
679     bp_bookmark_info_fmt info;
680     for(int i = 0; i < ids_count; i++) {
681         if (bp_bookmark_adaptor_get_info(ids[i], (BP_BOOKMARK_O_TYPE |
682                 BP_BOOKMARK_O_SEQUENCE |
683                 BP_BOOKMARK_O_IS_EDITABLE | BP_BOOKMARK_O_URL |
684                 BP_BOOKMARK_O_TITLE |
685                 BP_BOOKMARK_O_IS_OPERATOR), &info) == 0) {
686             BookmarkItem *item = new BookmarkItem();
687             item->setId(ids[i]);
688             item->set_folder_flag(static_cast<bool>(info.type));
689             item->setDir(folder_id);
690             item->set_editable_flag(static_cast<bool>(info.editable));
691
692             if (info.url != nullptr && strlen(info.url) > 0)
693                 item->setAddress(info.url);
694
695             if (info.title != nullptr && strlen(info.title) > 0)
696                 item->setTittle(info.title);
697
698             if (info.is_operator > 0) {
699                 delete item;
700             } else {
701                 list.push_back(item);
702             }
703             bp_bookmark_adaptor_easy_free(&info);
704         }
705     }
706     free(ids);
707     return (list.empty() == false);
708 }
709
710 bool BookmarkService::get_list_by_dividing(const int folder_id, std::vector<BookmarkItem *> &list, int *list_item_count, int genlist_block_size)
711 {
712     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
713     BROWSER_LOGD("folder ID: %d", folder_id);
714
715     int *ids = nullptr;
716     int ids_count = -1;
717     if (bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, genlist_block_size, *list_item_count, folder_id, -1, -1, -1,
718                                       BP_BOOKMARK_O_SEQUENCE, 1) < 0) {
719         BROWSER_LOGD("bp_bookmark_adaptor_get_ids_p is failed");
720         return false;
721     }
722
723     if (ids_count <= 0) {
724         BROWSER_LOGD("bookmark list is empty");
725         free(ids);
726         return false;
727     }
728
729     bp_bookmark_info_fmt info;
730     for(int i = 0; i < ids_count; i++) {
731         if (bp_bookmark_adaptor_get_info(ids[i], (BP_BOOKMARK_O_TYPE |
732                 BP_BOOKMARK_O_SEQUENCE |
733                 BP_BOOKMARK_O_IS_EDITABLE | BP_BOOKMARK_O_URL |
734                 BP_BOOKMARK_O_TITLE | BP_BOOKMARK_O_IS_OPERATOR), &info) == 0) {
735             BookmarkItem *item = new BookmarkItem();
736             item->setId(ids[i]);
737             item->set_folder_flag(static_cast<bool>(info.type));
738             item->setDir(folder_id);
739             item->set_editable_flag(static_cast<bool>(info.editable));
740
741             if (info.url != nullptr && strlen(info.url) > 0)
742                 item->setAddress(info.url);
743
744             if (info.title != nullptr && strlen(info.title) > 0)
745                 item->setTittle(info.title);
746
747             list.push_back(item);
748             bp_bookmark_adaptor_easy_free(&info);
749         }
750     }
751     free(ids);
752     return true;
753 }
754
755 bool BookmarkService::get_list_users_by_dividing(const int folder_id, std::vector<BookmarkItem *> &list, int *list_item_count, int genlist_block_size)
756 {
757     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
758     BROWSER_LOGD("folder ID: %d", folder_id);
759     int *ids = nullptr;
760     int ids_count = -1;
761     if (bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, genlist_block_size, *list_item_count, folder_id, -1, 0, 1,
762                                       BP_BOOKMARK_O_SEQUENCE, 1) < 0) {
763         BROWSER_LOGD("bp_bookmark_adaptor_get_ids_p is failed");
764         return false;
765     }
766
767     if (ids_count <= 0) {
768         BROWSER_LOGD("bookmark list is empty");
769         free(ids);
770         return false;
771     }
772
773     bp_bookmark_info_fmt info;
774     BROWSER_LOGD("list.size() before : %d", list.size());
775     BROWSER_LOGD("ids_count: %d", ids_count);
776     for(int i = 0; i < ids_count; i++) {
777         BROWSER_LOGD("list.size(): %d", list.size());
778         BROWSER_LOGD("index : %d", i);
779         if (bp_bookmark_adaptor_get_info(ids[i], (BP_BOOKMARK_O_TYPE |
780                 BP_BOOKMARK_O_SEQUENCE |
781                 BP_BOOKMARK_O_IS_EDITABLE | BP_BOOKMARK_O_URL |
782                 BP_BOOKMARK_O_TITLE |
783                 BP_BOOKMARK_O_IS_OPERATOR), &info) == 0) {
784             BookmarkItem *item = new BookmarkItem();
785             item->setId(ids[i]);
786             item->set_folder_flag(static_cast<bool>(info.type));
787             item->setDir(folder_id);
788             item->set_editable_flag(static_cast<bool>(info.editable));
789
790             if (info.url != nullptr && strlen(info.url) > 0)
791                 item->setAddress(info.url);
792
793             if (info.title != nullptr && strlen(info.title) > 0)
794                 item->setTittle(info.title);
795
796             if (info.is_operator > 0) {
797                 BROWSER_LOGD("this is operator bookmark");
798                 delete item;
799             } else {
800                 BROWSER_LOGD("item is pushed");
801                 list.push_back(item);
802             }
803             bp_bookmark_adaptor_easy_free(&info);
804         }
805     }
806     BROWSER_LOGD("list.size() after: %d", list.size());
807     free(ids);
808     return (list.empty() == false);
809 }
810
811 int BookmarkService::_get_folder_count(const int folder_id)
812 {
813     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
814     BROWSER_LOGD("folder ID: %d", folder_id);
815
816     int *ids = nullptr;
817     int ids_count = -1;
818     bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, folder_id, 1, -1, -1, BP_BOOKMARK_O_SEQUENCE, 0);
819     free(ids);
820     return ids_count;
821 }
822
823
824 int BookmarkService::_get_bookmarks_count(const int folder_id)
825 {
826     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
827     BROWSER_LOGD("folder ID: %d", folder_id);
828
829     int *ids = nullptr;
830     int ids_count = -1;
831     bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, folder_id, 0, -1, -1, BP_BOOKMARK_O_SEQUENCE, 0);
832     free(ids);
833     return ids_count;
834 }
835
836
837 int BookmarkService::_get_total_contents_count(const int folder_id)
838 {
839     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
840     BROWSER_LOGD("folder ID: %d", folder_id);
841
842     int *ids = nullptr;
843     int ids_count = -1;
844     bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, folder_id, 0, -1, -1, BP_BOOKMARK_O_SEQUENCE, 0);
845     free(ids);
846     return ids_count;
847 }
848
849 bool BookmarkService::get_list_operators(const int folder_id, std::vector<BookmarkItem *> &list)
850 {
851     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
852     BROWSER_LOGD("folder ID: %d", folder_id);
853     int *ids = nullptr;
854     int ids_count = -1;
855
856     if (bp_bookmark_adaptor_get_ids_p(&ids, &ids_count, -1, 0, folder_id, -1, 1, -1, BP_BOOKMARK_O_SEQUENCE, 1) < 0) {
857         BROWSER_LOGD("bp_bookmark_adaptor_get_ids_p is failed");
858         return false;
859     }
860
861     if (ids_count <= 0) {
862         BROWSER_LOGD("bookmark list is empty");
863         free(ids);
864         return false;
865     }
866
867     bp_bookmark_info_fmt info;
868     for(int i = 0; i < ids_count; i++) {
869         if (bp_bookmark_adaptor_get_info(ids[i], (BP_BOOKMARK_O_TYPE |
870                 BP_BOOKMARK_O_SEQUENCE |
871                 BP_BOOKMARK_O_IS_EDITABLE | BP_BOOKMARK_O_URL |
872                 BP_BOOKMARK_O_TITLE), &info) == 0) {
873             BookmarkItem *item = new BookmarkItem();
874             item->setId(ids[i]);
875             item->set_folder_flag(static_cast<bool>(info.type));
876             item->setDir(folder_id);
877             item->set_editable_flag(static_cast<bool>(info.editable));
878
879             if (info.url != nullptr && strlen(info.url) > 0)
880                 item->setAddress(info.url);
881
882             if (info.title != nullptr && strlen(info.title) > 0)
883                 item->setTittle(info.title);
884
885             list.push_back(item);
886             bp_bookmark_adaptor_easy_free(&info);
887         }
888     }
889     free(ids);
890     return (list.empty() == false);
891 }
892
893 bool BookmarkService::get_list_by_keyword(const char *keyword, std::vector<BookmarkItem *> &list)
894 {
895     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
896     BROWSER_LOGD("");
897
898     if (!keyword || (strlen(keyword) == 0)) {
899         BROWSER_LOGD("keyword is nullptr");
900         return false;
901     }
902
903     std::string buf_str(keyword);
904     buf_str = "%" + buf_str + "%";
905
906     bp_bookmark_property_cond_fmt properties;
907     properties.parent = -1;
908     properties.type = 0;
909     properties.is_operator = -1;
910     properties.is_editable = -1;
911     //conditions for querying
912     bp_bookmark_rows_cond_fmt conds;
913     conds.limit = -1;
914     conds.offset = 0;
915     conds.order_offset = BP_BOOKMARK_O_TITLE;
916     conds.ordering = -1;
917     conds.period_offset = BP_BOOKMARK_O_DATE_CREATED;
918     conds.period_type = BP_BOOKMARK_DATE_ALL;
919
920     int *ids = nullptr;
921     int ids_count = -1;
922     if (bp_bookmark_adaptor_get_cond_ids_p(&ids, &ids_count, &properties, &conds,
923         (BP_BOOKMARK_O_TITLE | BP_BOOKMARK_O_URL), buf_str.c_str(), 1) < 0) {
924         BROWSER_LOGE("bp_bookmark_adaptor_get_cond_ids_p is failed");
925         return false;
926     }
927
928     if (ids_count <= 0) {
929         BROWSER_LOGD("bookmark list is empty");
930         free(ids);
931         return false;
932     }
933
934     bp_bookmark_info_fmt info;
935     for(int i = 0; i < ids_count; i++) {
936         if (bp_bookmark_adaptor_get_info(ids[i], (BP_BOOKMARK_O_TYPE |
937                 BP_BOOKMARK_O_PARENT | BP_BOOKMARK_O_SEQUENCE |
938                 BP_BOOKMARK_O_IS_EDITABLE | BP_BOOKMARK_O_URL |
939                 BP_BOOKMARK_O_TITLE), &info) == 0) {
940             BookmarkItem *item = new BookmarkItem();
941             item->setId(ids[i]);
942             item->set_folder_flag(static_cast<bool>(info.type));
943             item->setDir(info.parent);
944             item->set_editable_flag(static_cast<bool>(info.editable));
945
946             if (info.url != nullptr && strlen(info.url) > 0)
947                 item->setAddress(info.url);
948
949             if (info.title != nullptr && strlen(info.title) > 0)
950                 item->setTittle(info.title);
951
952             list.push_back(item);
953             bp_bookmark_adaptor_easy_free(&info);
954         }
955     }
956     free(ids);
957     return true;
958 }
959
960 void BookmarkService::destroy_list(std::vector<BookmarkItem *> &list)
961 {
962     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
963     BROWSER_LOGD("");
964
965     for(unsigned int i = 0 ; i < list.size() ; i++) {
966         delete list[i];
967     }
968     list.clear();
969 }
970
971 bool BookmarkService::get_folder_depth_count(int *depth_count)
972 {
973     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
974     BROWSER_LOGD("depth_count: %d", *depth_count);
975     return _get_depth_count_recursive(get_root_folder_id(), 0, depth_count);
976 }
977
978 bool BookmarkService::_get_depth_count_recursive(int folder_id, int cur_depth, int *depth_count)
979 {
980     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
981     BROWSER_LOGD("current_depth: %d, depth_count:%d", cur_depth, *depth_count);
982
983     std::vector<BookmarkItem *> bookmark_list = get_list_by_folder(folder_id);
984     if (!bookmark_list.empty()) {
985         BROWSER_LOGE("get_list_by_folder is failed(folder id:%d)",folder_id);
986         return false;
987     }
988
989     for(unsigned int j = 0 ; j < bookmark_list.size() ; j++) {
990         if (bookmark_list[j]->is_folder()) {
991             /* Folder item is found. get sub list */
992             if ((cur_depth+1) > *depth_count)
993                 *depth_count = cur_depth+1;
994
995             _get_depth_count_recursive(bookmark_list[j]->getId(), cur_depth+1, depth_count);
996         }
997     }
998     destroy_list(bookmark_list);
999     return true;
1000 }
1001
1002 bool BookmarkService::set_thumbnail(int id, Evas_Object *thumbnail)
1003 {
1004     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1005     BROWSER_LOGD("id : %d", id);
1006
1007     int w = 0;
1008     int h = 0;
1009     int stride = 0;
1010     int len = 0;
1011
1012     //platform_Service ps.
1013     //ps.evas_image_size_get(thumbnail, &w, &h, &stride);
1014     len = stride * h;
1015     BROWSER_LOGD("thumbnail w=[%d], h=[%d], stride=[%d], len=[%d]", w, h, stride, len);
1016
1017     if (len == 0)
1018         return false;
1019
1020     void *thumbnail_data = evas_object_image_data_get(thumbnail, true);
1021     int ret = bp_bookmark_adaptor_set_snapshot(id, w, h, (const unsigned char *)thumbnail_data, len);
1022     if (ret < 0) {
1023         BROWSER_LOGE("bp_bookmark_adaptor_set_thumbnail is failed");
1024         return false;
1025     }
1026     return true;
1027 }
1028
1029 Evas_Object *BookmarkService::get_thumbnail(int id, Evas_Object *parent)
1030 {
1031     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1032     BROWSER_LOGD("id : %d", id);
1033     void *thumbnail_data = nullptr;
1034     int w = 0;
1035     int h = 0;
1036     int len = 0;
1037     Evas_Object *icon = nullptr;
1038
1039     int ret = bp_bookmark_adaptor_get_snapshot(id, &w, &h, (unsigned char **)&thumbnail_data, &len);
1040     BROWSER_LOGE("len: %d, w:%d, h:%d", len, w, h);
1041     if (len > 0){
1042         /* gengrid event area has scaled with original image if it is evas image.
1043             therefore use elm_image*/
1044         icon = elm_image_add(parent);
1045         Evas_Object *icon_object = elm_image_object_get(icon);
1046         evas_object_image_colorspace_set(icon_object, EVAS_COLORSPACE_ARGB8888);
1047         evas_object_image_size_set(icon_object, w, h);
1048         evas_object_image_fill_set(icon_object, 0, 0, w, h);
1049         evas_object_image_filled_set(icon_object, true);
1050         evas_object_image_alpha_set(icon_object,true);
1051
1052         void *target_image_data = evas_object_image_data_get(icon_object, true);
1053         memcpy(target_image_data, thumbnail_data, len);
1054         evas_object_image_data_set(icon_object, target_image_data);
1055     }
1056
1057     return icon;
1058 }
1059
1060 bool BookmarkService::set_favicon(int id, Evas_Object *favicon)
1061 {
1062     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1063     BROWSER_LOGD("id : %d", id);
1064
1065     int w = 0;
1066     int h = 0;
1067     int stride = 0;
1068     int len = 0;
1069
1070     //platform_Service ps.
1071     //ps.evas_image_size_get(favicon, &w, &h, &stride);
1072     len = stride * h;
1073     BROWSER_LOGD("favicon w=[%d], h=[%d], stride=[%d], len=[%d]", w, h, stride, len);
1074
1075     if (len == 0)
1076         return false;
1077
1078     void *favicon_data = evas_object_image_data_get(favicon, true);
1079     int ret = bp_bookmark_adaptor_set_icon(id, w, h, (const unsigned char *)favicon_data, len);
1080     if (ret < 0) {
1081         BROWSER_LOGE("bp_bookmark_adaptor_set_favicon is failed");
1082         return false;
1083     }
1084     return true;
1085 }
1086
1087 Evas_Object *BookmarkService::get_favicon(int id, Evas_Object *parent)
1088 {
1089     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1090     BROWSER_LOGD("id : %d", id);
1091     void *favicon_data = nullptr;
1092     int w = 0;
1093     int h = 0;
1094     int len = 0;
1095
1096     Evas *e = nullptr;
1097     e = evas_object_evas_get(parent);
1098     if (!e) {
1099         BROWSER_LOGE("canvas is nullptr");
1100         return nullptr;
1101     }
1102     int ret = bp_bookmark_adaptor_get_icon(id, &w, &h, (unsigned char **)&favicon_data, &len);
1103     if (ret < 0) {
1104         BROWSER_LOGE("bp_bookmark_adaptor_set_favicon is failed");
1105         return nullptr;
1106     }
1107
1108     Evas_Object *icon = nullptr;
1109     BROWSER_LOGE("len: %d, w:%d, h:%d", len, w, h);
1110     if (len > 0){
1111         icon = evas_object_image_filled_add(e);
1112         if (w == 0 || h == 0) {
1113             // Android bookmark.
1114             evas_object_image_memfile_set(icon, favicon_data, len, nullptr, nullptr);
1115         } else {
1116             // Tizen bookmark.
1117             evas_object_image_colorspace_set(icon, EVAS_COLORSPACE_ARGB8888);
1118             evas_object_image_size_set(icon, w, h);
1119             evas_object_image_fill_set(icon, 0, 0, w, h);
1120             evas_object_image_filled_set(icon, true);
1121             evas_object_image_alpha_set(icon,true);
1122
1123             void *target_image_data = evas_object_image_data_get(icon, true);
1124             memcpy(target_image_data, favicon_data, len);
1125             evas_object_image_data_set(icon, target_image_data);
1126         }
1127     }
1128     return icon;
1129 }
1130
1131 bool BookmarkService::set_webicon(int id, Evas_Object *webicon)
1132 {
1133     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1134     BROWSER_LOGD("id : %d", id);
1135
1136     int w = 0;
1137     int h = 0;
1138     int stride = 0;
1139     int len = 0;
1140
1141     //platform_Service ps;
1142     //ps.evas_image_size_get(webicon, &w, &h, &stride);
1143     len = stride * h;
1144     BROWSER_LOGD("webicon w=[%d], h=[%d], stride=[%d], len=[%d]", w, h, stride, len);
1145
1146     if (len == 0)
1147         return false;
1148
1149     void *webicon_data = evas_object_image_data_get(webicon, true);
1150     int ret = bp_bookmark_adaptor_set_webicon(id, w, h, (const unsigned char *)webicon_data, len);
1151     if (ret != 0)
1152         BROWSER_LOGE("set webicon is failed");
1153     return false;
1154 }
1155
1156 Evas_Object *BookmarkService::get_webicon(int id, Evas_Object *parent)
1157 {
1158     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1159     BROWSER_LOGD("id : %d", id);
1160     void *webicon_data = nullptr;
1161     int w = 0;
1162     int h = 0;
1163     int len = 0;
1164
1165     int ret = bp_bookmark_adaptor_get_webicon(id, &w, &h, (unsigned char **)&webicon_data, &len);
1166     if (ret != 0) {
1167         BROWSER_LOGE("bp_bookmark_adaptor_set_webicon is failed");
1168         return nullptr;
1169     }
1170
1171     Evas_Object *icon = nullptr;
1172     BROWSER_LOGE("len: %d, w:%d, h:%d", len, w, h);
1173     if (len > 0){
1174         Evas *e = evas_object_evas_get(parent);
1175         icon = evas_object_image_filled_add(e);
1176
1177         evas_object_image_colorspace_set(icon, EVAS_COLORSPACE_ARGB8888);
1178         evas_object_image_size_set(icon, w, h);
1179         evas_object_image_fill_set(icon, 0, 0, w, h);
1180         evas_object_image_filled_set(icon, true);
1181         evas_object_image_alpha_set(icon,true);
1182
1183         void *target_image_data = evas_object_image_data_get(icon, true);
1184         memcpy(target_image_data, webicon_data, len);
1185         evas_object_image_data_set(icon, target_image_data);
1186     }
1187
1188     return icon;
1189 }
1190
1191 bool BookmarkService::set_access_count(int id, int count)
1192 {
1193     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1194     BROWSER_LOGD("");
1195     return !bp_bookmark_adaptor_set_access_count(id, count);
1196 }
1197
1198 bool BookmarkService::get_access_count(int id, int *count)
1199 {
1200     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1201     BROWSER_LOGD("");
1202     return !bp_bookmark_adaptor_get_access_count(id, count);
1203 }
1204
1205 bool BookmarkService::increase_access_count(int id)
1206 {
1207     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1208     BROWSER_LOGD("");
1209     int count;
1210     if(get_access_count(id, &count) == false) {
1211         BROWSER_LOGD("get_access_count is failed");
1212         return false;
1213     }
1214
1215     if(set_access_count(id, count + 1) == false) {
1216         BROWSER_LOGD("set_access_count is failed");
1217         return false;
1218     }
1219
1220     return true;
1221 }
1222
1223 bool BookmarkService::set_last_sequence(int id)
1224 {
1225     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1226     BROWSER_LOGD("");
1227     return (bp_bookmark_adaptor_set_sequence(id, -1) == -1);
1228 }
1229
1230 const char* BookmarkService::get_path_info(void)
1231 {
1232     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1233     BROWSER_LOGD("%s", m_path_string.c_str());
1234     return m_path_string.c_str();
1235 }
1236
1237 BookmarkService::folder_info *BookmarkService::get_path_by_index(unsigned int index)
1238 {
1239     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1240     BROWSER_LOGD("%s", m_path_history[index]->folder_name);
1241     return m_path_history[index];
1242 }
1243
1244 int BookmarkService::get_path_size(void)
1245 {
1246     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1247     BROWSER_LOGD("%d", m_path_history.size());
1248     return m_path_history.size();
1249 }
1250
1251 void BookmarkService::push_back_path(folder_info *item)
1252 {
1253     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1254     BROWSER_LOGD("path size before push: %d", m_path_history.size());
1255     m_path_history.push_back(item);
1256 }
1257
1258 void BookmarkService::pop_back_path(void)
1259 {
1260     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1261     BROWSER_LOGD("path size before pop: %d", m_path_history.size());
1262     m_path_history.pop_back();
1263 }
1264
1265 void BookmarkService::clear_path_history(void)
1266 {
1267     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1268     BROWSER_LOGD("");
1269     free_path_history();
1270     m_path_history.clear();
1271 }
1272
1273 void BookmarkService::free_path_history(void)
1274 {
1275     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1276     BROWSER_LOGD("");
1277     for(unsigned int i = 0 ; i < m_path_history.size() ; i++) {
1278         if (m_path_history[i]) {
1279             if (m_path_history[i]->folder_name)
1280                 free(m_path_history[i]->folder_name);
1281
1282             free(m_path_history[i]);
1283         }
1284     }
1285 }
1286
1287 void BookmarkService::change_path_lang(void)
1288 {
1289     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1290     BROWSER_LOGD("");
1291     m_path_string.clear();
1292
1293     char *old_str = m_path_history[0]->folder_name;
1294     m_path_history[0]->folder_name = strdup("Bookmarks");
1295     free(old_str);
1296
1297     for(int i = 0 ; i < get_path_size(); i++) {
1298         if (get_path_by_index(i)) {
1299             if (m_path_string.empty()) {
1300                 m_path_string = m_path_history[0]->folder_name;
1301             } else {
1302                 m_path_string += "/";
1303                 m_path_string += get_path_by_index(i)->folder_name;
1304             }
1305         }
1306     }
1307     BROWSER_LOGD("str: %s", m_path_string.c_str());
1308 }
1309
1310 void BookmarkService::path_into_sub_folder(int folder_id, const char *folder_name)
1311 {
1312     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1313     BROWSER_LOGD("");
1314
1315     folder_info *item = (folder_info *)calloc(1, sizeof(folder_info));
1316
1317     item->folder_id = folder_id;
1318     if (folder_id == get_root_folder_id()) {
1319         item->folder_name = strdup("Bookmarks");
1320     } else
1321         item->folder_name = strdup(folder_name);
1322     push_back_path(item);
1323
1324     m_path_string.clear();
1325     for(int i = 0 ; i < get_path_size() ; i++) {
1326         if (get_path_by_index(i)) {
1327             if (m_path_string.empty()) {
1328                 m_path_string = get_path_by_index(i)->folder_name;
1329             } else {
1330                 m_path_string += "/";
1331                 m_path_string += get_path_by_index(i)->folder_name;
1332             }
1333         }
1334     }
1335     char *path_string = (elm_entry_utf8_to_markup(m_path_string.c_str()));
1336     m_path_string = path_string;
1337     free(path_string);
1338     BROWSER_LOGD("m_path_string: %s", m_path_string.c_str());
1339
1340     m_curr_folder = folder_id;
1341 }
1342
1343 bool BookmarkService::path_to_upper_folder(int *curr_folder)
1344 {
1345     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
1346     BROWSER_LOGD("");
1347
1348     int current_depth = get_path_size();
1349     BROWSER_LOGD("current_depth: %d", current_depth);
1350
1351     if (current_depth <= 0) {
1352         BROWSER_LOGE("[ERROR] top folder is not valid");
1353         return true;
1354     }
1355
1356     int curr_depth = current_depth - 1;
1357     if (curr_depth > 0) {
1358         *curr_folder = get_path_by_index(curr_depth - 1)->folder_id;
1359         if (get_path_by_index(curr_depth) && get_path_by_index(curr_depth)->folder_name) {
1360             free(get_path_by_index(curr_depth)->folder_name);
1361             free(get_path_by_index(curr_depth));
1362         }
1363         pop_back_path();
1364     } else {
1365         /* Current folder is root folder */
1366         if (*curr_folder != get_root_folder_id()) {
1367             BROWSER_LOGE("[ERROR] top folder is not root folder");
1368             return true;
1369         }
1370         if (get_path_by_index(curr_depth) && get_path_by_index(curr_depth)->folder_name) {
1371             free(get_path_by_index(curr_depth)->folder_name);
1372             free(get_path_by_index(curr_depth));
1373         }
1374         pop_back_path();
1375         m_path_string.clear();
1376         return false;
1377     }
1378
1379     m_path_string.clear();
1380     for(int i = 0 ; i < get_path_size() ; i++) {
1381         if (get_path_by_index(i)) {
1382             if (m_path_string.empty()) {
1383                 m_path_string = get_path_by_index(i)->folder_name;
1384             } else {
1385                 m_path_string += "/";
1386                 m_path_string += get_path_by_index(i)->folder_name;
1387             }
1388         }
1389     }
1390     BROWSER_LOGD("m_path_string: %s", m_path_string.c_str());
1391
1392     m_curr_folder = *curr_folder;
1393     return true;
1394 }
1395
1396 } /* end of namespace services*/
1397 } /* end of namespace tizen_browser */