Source code formating unification
[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 DPL::OptionalString toString(WKStringRef str)
27 {
28     if (WKStringIsEmpty(str)) {
29         return DPL::OptionalString::Null;
30     }
31     size_t size = WKStringGetMaximumUTF8CStringSize(str);
32     char buffer[size + 1];
33     WKStringGetUTF8CString(str, buffer, size + 1);
34     return DPL::FromUTF8String(buffer);
35 }
36
37 DPL::OptionalString toString(WKURLRef url)
38 {
39     WKStringRef urlStr = WKURLCopyString(url);
40     DPL::OptionalString str = toString(urlStr);
41     WKRelease(urlStr);
42     return str;
43 }
44
45 DPL::OptionalString toString(WKURLRequestRef req)
46 {
47     WKURLRef reqUrl = WKURLRequestCopyURL(req);
48     DPL::OptionalString str = toString(reqUrl);
49     WKRelease(reqUrl);
50     return str;
51 }
52
53 DPL::OptionalString toString(WKFrameRef req)
54 {
55     WKURLRef reqUrl = WKFrameCopyURL(req);
56     DPL::OptionalString str = toString(reqUrl);
57     WKRelease(reqUrl);
58     return str;
59 }
60
61 DPL::OptionalString toString(WKErrorRef err)
62 {
63     WKStringRef domErr = WKErrorCopyDomain(err);
64     WKStringRef desc = WKErrorCopyLocalizedDescription(err);
65     DPL::String str =
66         (WKStringIsEmpty(domErr) ? L"null" : *toString(domErr)) +
67         L"\n" +
68         (WKStringIsEmpty(desc) ? L"null" : *toString(desc));
69     WKRelease(domErr);
70     WKRelease(desc);
71     return str;
72 }
73 } // namespace Utils
74 } // namespace ViewModule