<rdar://problem/8613727> and https://bugs.webkit.org/show_bug.cgi?id=49836
[WebKit-https.git] / WebKit2 / WebProcess / InjectedBundle / API / c / WKBundlePage.cpp
1 /*
2  * Copyright (C) 2010 Apple Inc. 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 "WKBundlePage.h"
27 #include "WKBundlePagePrivate.h"
28
29 #include "InjectedBundleBackForwardList.h"
30 #include "WebPage.h"
31 #include "WebURL.h"
32 #include "WebURLRequest.h"
33 #include "WKAPICast.h"
34 #include "WKBundleAPICast.h"
35
36 #include <WebCore/KURL.h>
37
38 using namespace WebKit;
39
40 WKTypeID WKBundlePageGetTypeID()
41 {
42     return toAPI(WebPage::APIType);
43 }
44
45 void WKBundlePageSetContextMenuClient(WKBundlePageRef pageRef, WKBundlePageContextMenuClient* wkClient)
46 {
47     if (wkClient && wkClient->version)
48         return;
49     toImpl(pageRef)->initializeInjectedBundleContextMenuClient(wkClient);
50 }
51
52 void WKBundlePageSetEditorClient(WKBundlePageRef pageRef, WKBundlePageEditorClient* wkClient)
53 {
54     if (wkClient && wkClient->version)
55         return;
56     toImpl(pageRef)->initializeInjectedBundleEditorClient(wkClient);
57 }
58
59 void WKBundlePageSetFormClient(WKBundlePageRef pageRef, WKBundlePageFormClient* wkClient)
60 {
61     if (wkClient && wkClient->version)
62         return;
63     toImpl(pageRef)->initializeInjectedBundleFormClient(wkClient);
64 }
65
66 void WKBundlePageSetLoaderClient(WKBundlePageRef pageRef, WKBundlePageLoaderClient* wkClient)
67 {
68     if (wkClient && wkClient->version)
69         return;
70     toImpl(pageRef)->initializeInjectedBundleLoaderClient(wkClient);
71 }
72
73 void WKBundlePageSetUIClient(WKBundlePageRef pageRef, WKBundlePageUIClient* wkClient)
74 {
75     if (wkClient && wkClient->version)
76         return;
77     toImpl(pageRef)->initializeInjectedBundleUIClient(wkClient);
78 }
79
80 WKBundleFrameRef WKBundlePageGetMainFrame(WKBundlePageRef pageRef)
81 {
82     return toAPI(toImpl(pageRef)->mainFrame());
83 }
84
85 void WKBundlePageStopLoading(WKBundlePageRef pageRef)
86 {
87     toImpl(pageRef)->stopLoading();
88 }
89
90 WKStringRef WKBundlePageCopyRenderTreeExternalRepresentation(WKBundlePageRef pageRef)
91 {
92     return toCopiedAPI(toImpl(pageRef)->renderTreeExternalRepresentation());
93 }
94
95 void WKBundlePageExecuteEditingCommand(WKBundlePageRef pageRef, WKStringRef name, WKStringRef argument)
96 {
97     toImpl(pageRef)->executeEditingCommand(toImpl(name)->string(), toImpl(argument)->string());
98 }
99
100 bool WKBundlePageIsEditingCommandEnabled(WKBundlePageRef pageRef, WKStringRef name)
101 {
102     return toImpl(pageRef)->isEditingCommandEnabled(toImpl(name)->string());
103 }
104
105 void WKBundlePageClearMainFrameName(WKBundlePageRef pageRef)
106 {
107     toImpl(pageRef)->clearMainFrameName();
108 }
109
110 void WKBundlePageClose(WKBundlePageRef pageRef)
111 {
112     toImpl(pageRef)->sendClose();
113 }
114
115 double WKBundlePageGetTextZoomFactor(WKBundlePageRef pageRef)
116 {
117     return toImpl(pageRef)->textZoomFactor();
118 }
119
120 void WKBundlePageSetTextZoomFactor(WKBundlePageRef pageRef, double zoomFactor)
121 {
122     toImpl(pageRef)->setTextZoomFactor(zoomFactor);
123 }
124
125 double WKBundlePageGetPageZoomFactor(WKBundlePageRef pageRef)
126 {
127     return toImpl(pageRef)->pageZoomFactor();
128 }
129
130 void WKBundlePageSetPageZoomFactor(WKBundlePageRef pageRef, double zoomFactor)
131 {
132     toImpl(pageRef)->setPageZoomFactor(zoomFactor);
133 }
134
135 WKBundleBackForwardListRef WKBundlePageGetBackForwardList(WKBundlePageRef pageRef)
136 {
137     return toAPI(toImpl(pageRef)->backForwardList());
138 }
139
140 void WKBundlePageInstallPageOverlay(WKBundlePageRef pageRef, WKBundlePageOverlayRef pageOverlayRef)
141 {
142     toImpl(pageRef)->installPageOverlay(toImpl(pageOverlayRef));
143 }
144
145 void WKBundlePageUninstallPageOverlay(WKBundlePageRef pageRef, WKBundlePageOverlayRef pageOverlayRef)
146 {
147     toImpl(pageRef)->uninstallPageOverlay(toImpl(pageOverlayRef));
148 }
149
150 bool WKBundlePageHasLocalDataForURL(WKBundlePageRef pageRef, WKURLRef urlRef)
151 {
152     return toImpl(pageRef)->hasLocalDataForURL(WebCore::KURL(WebCore::KURL(), toImpl(urlRef)->string()));
153 }
154
155 bool WKBundlePageCanHandleRequest(WKURLRequestRef requestRef)
156 {
157     return WebPage::canHandleRequest(toImpl(requestRef)->resourceRequest());
158 }