Create string tightly when retrive string from cbhm callback event
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / ewk_url_scheme_request.cpp
1 /*
2  * Copyright (C) 2012 Intel Corporation. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "ewk_url_scheme_request.h"
28
29 #include "GOwnPtrSoup.h"
30 #include "WKData.h"
31 #include "WKString.h"
32 #include "ewk_url_scheme_request_private.h"
33
34 using namespace WebKit;
35
36 Ewk_Url_Scheme_Request::Ewk_Url_Scheme_Request(WKSoupRequestManagerRef manager, WKURLRef url, uint64_t requestID)
37     : m_wkRequestManager(manager)
38     , m_url(url)
39     , m_requestID(requestID)
40 {
41     GOwnPtr<SoupURI> soupURI(soup_uri_new(m_url));
42     m_scheme = soupURI->scheme;
43     m_path = soupURI->path;
44 }
45
46 uint64_t Ewk_Url_Scheme_Request::id() const
47 {
48     return m_requestID;
49 }
50
51 const char* Ewk_Url_Scheme_Request::url() const
52 {
53     return m_url;
54 }
55
56 const char* Ewk_Url_Scheme_Request::scheme() const
57 {
58     return m_scheme;
59 }
60
61 const char* Ewk_Url_Scheme_Request::path() const
62 {
63     return m_path;
64 }
65
66 void Ewk_Url_Scheme_Request::finish(const void* contentData, uint64_t contentLength, const char* mimeType)
67 {
68     WKRetainPtr<WKDataRef> wkData(AdoptWK, WKDataCreate(contentLength ? reinterpret_cast<const unsigned char*>(contentData) : 0, contentLength));
69     WKRetainPtr<WKStringRef> wkMimeType = mimeType ? adoptWK(WKStringCreateWithUTF8CString(mimeType)) : 0;
70
71     // In case of empty reply an empty WKDataRef is sent to the WebProcess.
72     WKSoupRequestManagerDidHandleURIRequest(m_wkRequestManager.get(), wkData.get(), contentLength, wkMimeType.get(), m_requestID);
73 }
74
75 Ewk_Url_Scheme_Request* ewk_url_scheme_request_ref(Ewk_Url_Scheme_Request* request)
76 {
77     EINA_SAFETY_ON_NULL_RETURN_VAL(request, 0);
78     request->ref();
79
80     return request;
81 }
82
83 void ewk_url_scheme_request_unref(Ewk_Url_Scheme_Request* request)
84 {
85     EINA_SAFETY_ON_NULL_RETURN(request);
86
87     request->deref();
88 }
89
90 const char* ewk_url_scheme_request_scheme_get(const Ewk_Url_Scheme_Request* request)
91 {
92     EINA_SAFETY_ON_NULL_RETURN_VAL(request, 0);
93
94     return request->scheme();
95 }
96
97 const char* ewk_url_scheme_request_url_get(const Ewk_Url_Scheme_Request* request)
98 {
99     EINA_SAFETY_ON_NULL_RETURN_VAL(request, 0);
100
101     return request->url();
102 }
103
104 const char* ewk_url_scheme_request_path_get(const Ewk_Url_Scheme_Request* request)
105 {
106     EINA_SAFETY_ON_NULL_RETURN_VAL(request, 0);
107
108     return request->path();
109 }
110
111 Eina_Bool ewk_url_scheme_request_finish(Ewk_Url_Scheme_Request* request, const void* contentData, uint64_t contentLength, const char* mimeType)
112 {
113     EINA_SAFETY_ON_NULL_RETURN_VAL(request, false);
114
115     request->finish(contentData, contentLength, mimeType);
116
117     return true;
118 }