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 "config.h" |
27 | #include "InjectedBundlePageUIClient.h" |
28 | |
29 | #include "APISecurityOrigin.h" |
30 | #include "InjectedBundleHitTestResult.h" |
31 | #include "InjectedBundleNodeHandle.h" |
32 | #include "WKAPICast.h" |
33 | #include "WKBundleAPICast.h" |
34 | #include "WebFrame.h" |
35 | #include "WebPage.h" |
36 | #include <wtf/text/WTFString.h> |
37 | |
38 | namespace WebKit { |
39 | using namespace WebCore; |
40 | |
41 | InjectedBundlePageUIClient::InjectedBundlePageUIClient(const WKBundlePageUIClientBase* client) |
42 | { |
43 | initialize(client); |
44 | } |
45 | |
46 | void InjectedBundlePageUIClient::willAddMessageToConsole(WebPage* page, MessageSource, MessageLevel, const String& message, unsigned lineNumber, unsigned /*columnNumber*/, const String& /*sourceID*/) |
47 | { |
48 | if (m_client.willAddMessageToConsole) |
49 | m_client.willAddMessageToConsole(toAPI(page), toAPI(message.impl()), lineNumber, m_client.base.clientInfo); |
50 | } |
51 | |
52 | void InjectedBundlePageUIClient::willSetStatusbarText(WebPage* page, const String& statusbarText) |
53 | { |
54 | if (m_client.willSetStatusbarText) |
55 | m_client.willSetStatusbarText(toAPI(page), toAPI(statusbarText.impl()), m_client.base.clientInfo); |
56 | } |
57 | |
58 | void InjectedBundlePageUIClient::willRunJavaScriptAlert(WebPage* page, const String& alertText, WebFrame* frame) |
59 | { |
60 | if (m_client.willRunJavaScriptAlert) |
61 | m_client.willRunJavaScriptAlert(toAPI(page), toAPI(alertText.impl()), toAPI(frame), m_client.base.clientInfo); |
62 | } |
63 | |
64 | void InjectedBundlePageUIClient::willRunJavaScriptConfirm(WebPage* page, const String& message, WebFrame* frame) |
65 | { |
66 | if (m_client.willRunJavaScriptConfirm) |
67 | m_client.willRunJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.base.clientInfo); |
68 | } |
69 | |
70 | void InjectedBundlePageUIClient::willRunJavaScriptPrompt(WebPage* page, const String& message, const String& defaultValue, WebFrame* frame) |
71 | { |
72 | if (m_client.willRunJavaScriptPrompt) |
73 | m_client.willRunJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.base.clientInfo); |
74 | } |
75 | |
76 | void InjectedBundlePageUIClient::mouseDidMoveOverElement(WebPage* page, const HitTestResult& coreHitTestResult, OptionSet<WebEvent::Modifier> modifiers, RefPtr<API::Object>& userData) |
77 | { |
78 | if (!m_client.mouseDidMoveOverElement) |
79 | return; |
80 | |
81 | auto hitTestResult = InjectedBundleHitTestResult::create(coreHitTestResult); |
82 | |
83 | WKTypeRef userDataToPass = 0; |
84 | m_client.mouseDidMoveOverElement(toAPI(page), toAPI(hitTestResult.ptr()), toAPI(modifiers), &userDataToPass, m_client.base.clientInfo); |
85 | userData = adoptRef(toImpl(userDataToPass)); |
86 | } |
87 | |
88 | void InjectedBundlePageUIClient::pageDidScroll(WebPage* page) |
89 | { |
90 | if (!m_client.pageDidScroll) |
91 | return; |
92 | |
93 | m_client.pageDidScroll(toAPI(page), m_client.base.clientInfo); |
94 | } |
95 | |
96 | String InjectedBundlePageUIClient::shouldGenerateFileForUpload(WebPage* page, const String& originalFilePath) |
97 | { |
98 | if (!m_client.shouldGenerateFileForUpload) |
99 | return String(); |
100 | RefPtr<API::String> generatedFilePath = adoptRef(toImpl(m_client.shouldGenerateFileForUpload(toAPI(page), toAPI(originalFilePath.impl()), m_client.base.clientInfo))); |
101 | return generatedFilePath ? generatedFilePath->string() : String(); |
102 | } |
103 | |
104 | String InjectedBundlePageUIClient::generateFileForUpload(WebPage* page, const String& originalFilePath) |
105 | { |
106 | if (!m_client.generateFileForUpload) |
107 | return String(); |
108 | RefPtr<API::String> generatedFilePath = adoptRef(toImpl(m_client.generateFileForUpload(toAPI(page), toAPI(originalFilePath.impl()), m_client.base.clientInfo))); |
109 | return generatedFilePath ? generatedFilePath->string() : String(); |
110 | } |
111 | |
112 | static API::InjectedBundle::PageUIClient::UIElementVisibility toUIElementVisibility(WKBundlePageUIElementVisibility visibility) |
113 | { |
114 | switch (visibility) { |
115 | case WKBundlePageUIElementVisibilityUnknown: |
116 | return API::InjectedBundle::PageUIClient::UIElementVisibility::Unknown; |
117 | case WKBundlePageUIElementVisible: |
118 | return API::InjectedBundle::PageUIClient::UIElementVisibility::Visible; |
119 | case WKBundlePageUIElementHidden: |
120 | return API::InjectedBundle::PageUIClient::UIElementVisibility::Hidden; |
121 | } |
122 | |
123 | ASSERT_NOT_REACHED(); |
124 | return API::InjectedBundle::PageUIClient::UIElementVisibility::Unknown; |
125 | } |
126 | |
127 | API::InjectedBundle::PageUIClient::UIElementVisibility InjectedBundlePageUIClient::statusBarIsVisible(WebPage* page) |
128 | { |
129 | if (!m_client.statusBarIsVisible) |
130 | return API::InjectedBundle::PageUIClient::UIElementVisibility::Unknown; |
131 | |
132 | return toUIElementVisibility(m_client.statusBarIsVisible(toAPI(page), m_client.base.clientInfo)); |
133 | } |
134 | |
135 | API::InjectedBundle::PageUIClient::UIElementVisibility InjectedBundlePageUIClient::(WebPage* page) |
136 | { |
137 | if (!m_client.menuBarIsVisible) |
138 | return API::InjectedBundle::PageUIClient::UIElementVisibility::Unknown; |
139 | |
140 | return toUIElementVisibility(m_client.menuBarIsVisible(toAPI(page), m_client.base.clientInfo)); |
141 | } |
142 | |
143 | API::InjectedBundle::PageUIClient::UIElementVisibility InjectedBundlePageUIClient::toolbarsAreVisible(WebPage* page) |
144 | { |
145 | if (!m_client.toolbarsAreVisible) |
146 | return API::InjectedBundle::PageUIClient::UIElementVisibility::Unknown; |
147 | |
148 | return toUIElementVisibility(m_client.toolbarsAreVisible(toAPI(page), m_client.base.clientInfo)); |
149 | } |
150 | |
151 | bool InjectedBundlePageUIClient::didReachApplicationCacheOriginQuota(WebPage* page, API::SecurityOrigin* origin, int64_t totalBytesNeeded) |
152 | { |
153 | if (!m_client.didReachApplicationCacheOriginQuota) |
154 | return false; |
155 | |
156 | m_client.didReachApplicationCacheOriginQuota(toAPI(page), toAPI(origin), totalBytesNeeded, m_client.base.clientInfo); |
157 | return true; |
158 | } |
159 | |
160 | uint64_t InjectedBundlePageUIClient::didExceedDatabaseQuota(WebPage* page, API::SecurityOrigin* origin, const String& databaseName, const String& databaseDisplayName, uint64_t currentQuotaBytes, uint64_t currentOriginUsageBytes, uint64_t currentDatabaseUsageBytes, uint64_t expectedUsageBytes) |
161 | { |
162 | if (!m_client.didExceedDatabaseQuota) |
163 | return 0; |
164 | |
165 | return m_client.didExceedDatabaseQuota(toAPI(page), toAPI(origin), toAPI(databaseName.impl()), toAPI(databaseDisplayName.impl()), currentQuotaBytes, currentOriginUsageBytes, currentDatabaseUsageBytes, expectedUsageBytes, m_client.base.clientInfo); |
166 | } |
167 | |
168 | String InjectedBundlePageUIClient::plugInStartLabelTitle(const String& mimeType) const |
169 | { |
170 | if (!m_client.createPlugInStartLabelTitle) |
171 | return String(); |
172 | |
173 | RefPtr<API::String> title = adoptRef(toImpl(m_client.createPlugInStartLabelTitle(toAPI(mimeType.impl()), m_client.base.clientInfo))); |
174 | return title ? title->string() : String(); |
175 | } |
176 | |
177 | String InjectedBundlePageUIClient::plugInStartLabelSubtitle(const String& mimeType) const |
178 | { |
179 | if (!m_client.createPlugInStartLabelSubtitle) |
180 | return String(); |
181 | |
182 | RefPtr<API::String> subtitle = adoptRef(toImpl(m_client.createPlugInStartLabelSubtitle(toAPI(mimeType.impl()), m_client.base.clientInfo))); |
183 | return subtitle ? subtitle->string() : String(); |
184 | } |
185 | |
186 | String InjectedBundlePageUIClient::() const |
187 | { |
188 | if (!m_client.createPlugInExtraStyleSheet) |
189 | return String(); |
190 | |
191 | RefPtr<API::String> styleSheet = adoptRef(toImpl(m_client.createPlugInExtraStyleSheet(m_client.base.clientInfo))); |
192 | return styleSheet ? styleSheet->string() : String(); |
193 | } |
194 | |
195 | String InjectedBundlePageUIClient::() const |
196 | { |
197 | if (!m_client.createPlugInExtraScript) |
198 | return String(); |
199 | |
200 | RefPtr<API::String> script = adoptRef(toImpl(m_client.createPlugInExtraScript(m_client.base.clientInfo))); |
201 | return script ? script->string() : String(); |
202 | } |
203 | |
204 | void InjectedBundlePageUIClient::didClickAutoFillButton(WebPage& page, InjectedBundleNodeHandle& nodeHandle, RefPtr<API::Object>& userData) |
205 | { |
206 | if (!m_client.didClickAutoFillButton) |
207 | return; |
208 | |
209 | WKTypeRef userDataToPass = nullptr; |
210 | m_client.didClickAutoFillButton(toAPI(&page), toAPI(&nodeHandle), &userDataToPass, m_client.base.clientInfo); |
211 | userData = adoptRef(toImpl(userDataToPass)); |
212 | } |
213 | |
214 | void InjectedBundlePageUIClient::didResignInputElementStrongPasswordAppearance(WebPage& page, InjectedBundleNodeHandle& nodeHandle, RefPtr<API::Object>& userData) |
215 | { |
216 | if (!m_client.didResignInputElementStrongPasswordAppearance) |
217 | return; |
218 | |
219 | WKTypeRef userDataToPass = nullptr; |
220 | m_client.didResignInputElementStrongPasswordAppearance(toAPI(&page), toAPI(&nodeHandle), &userDataToPass, m_client.base.clientInfo); |
221 | userData = adoptRef(toImpl(userDataToPass)); |
222 | } |
223 | |
224 | } // namespace WebKit |
225 | |