49dbb41fb4a6e777f7833d35bcbaad37d20df275
[platform/framework/web/wrt.git] / src / view / webkit / view_logic_utils.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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  * @file    view_logic_utils.cpp
18  * @author  Lukasz Marek (l.marek@samsung.com)
19  * @brief   Implementation file of utils API used by ViewLogic
20  */
21
22 #include "view_logic_utils.h"
23
24 namespace ViewModule {
25 namespace Utils {
26
27 DPL::OptionalString toString(WKStringRef str)
28 {
29     if (WKStringIsEmpty(str)) {
30         return DPL::OptionalString::Null;
31     }
32     size_t size = WKStringGetMaximumUTF8CStringSize(str);
33     char buffer[size + 1];
34     WKStringGetUTF8CString(str, buffer, size + 1);
35     return DPL::FromUTF8String(buffer);
36 }
37
38 DPL::OptionalString toString(WKURLRef url)
39 {
40     WKStringRef urlStr = WKURLCopyString(url);
41     DPL::OptionalString str = toString(urlStr);
42     WKRelease(urlStr);
43     return str;
44 }
45
46 DPL::OptionalString toString(WKURLRequestRef req)
47 {
48     WKURLRef reqUrl = WKURLRequestCopyURL(req);
49     DPL::OptionalString str = toString(reqUrl);
50     WKRelease(reqUrl);
51     return str;
52 }
53
54 DPL::OptionalString toString(WKFrameRef req)
55 {
56     WKURLRef reqUrl = WKFrameCopyURL(req);
57     DPL::OptionalString str = toString(reqUrl);
58     WKRelease(reqUrl);
59     return str;
60 }
61
62 DPL::OptionalString toString(WKErrorRef err)
63 {
64     WKStringRef domErr = WKErrorCopyDomain(err);
65     WKStringRef desc = WKErrorCopyLocalizedDescription(err);
66     DPL::String str =
67         (WKStringIsEmpty(domErr) ? L"null" : *toString(domErr)) +
68         L"\n" +
69         (WKStringIsEmpty(desc) ? L"null" : *toString(desc));
70     WKRelease(domErr);
71     WKRelease(desc);
72     return str;
73 }
74
75 } // namespace Utils
76 } // namespace ViewModule