2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "InjectedBundlePageUIClient.h"
29 #include "InjectedBundleHitTestResult.h"
30 #include "WKAPICast.h"
31 #include "WebGraphicsContext.h"
32 #include "WKBundleAPICast.h"
33 #include <wtf/text/WTFString.h>
35 using namespace WebCore;
39 void InjectedBundlePageUIClient::willAddMessageToConsole(WebPage* page, const String& message, int32_t lineNumber)
41 if (m_client.willAddMessageToConsole)
42 m_client.willAddMessageToConsole(toAPI(page), toAPI(message.impl()), lineNumber, m_client.clientInfo);
45 void InjectedBundlePageUIClient::willSetStatusbarText(WebPage* page, const String& statusbarText)
47 if (m_client.willSetStatusbarText)
48 m_client.willSetStatusbarText(toAPI(page), toAPI(statusbarText.impl()), m_client.clientInfo);
51 void InjectedBundlePageUIClient::willRunJavaScriptAlert(WebPage* page, const String& alertText, WebFrame* frame)
53 if (m_client.willRunJavaScriptAlert)
54 m_client.willRunJavaScriptAlert(toAPI(page), toAPI(alertText.impl()), toAPI(frame), m_client.clientInfo);
57 void InjectedBundlePageUIClient::willRunJavaScriptConfirm(WebPage* page, const String& message, WebFrame* frame)
59 if (m_client.willRunJavaScriptConfirm)
60 m_client.willRunJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.clientInfo);
63 void InjectedBundlePageUIClient::willRunJavaScriptPrompt(WebPage* page, const String& message, const String& defaultValue, WebFrame* frame)
65 if (m_client.willRunJavaScriptPrompt)
66 m_client.willRunJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.clientInfo);
69 void InjectedBundlePageUIClient::mouseDidMoveOverElement(WebPage* page, const HitTestResult& coreHitTestResult, WebEvent::Modifiers modifiers, RefPtr<APIObject>& userData)
71 if (!m_client.mouseDidMoveOverElement)
74 RefPtr<InjectedBundleHitTestResult> hitTestResult = InjectedBundleHitTestResult::create(coreHitTestResult);
76 WKTypeRef userDataToPass = 0;
77 m_client.mouseDidMoveOverElement(toAPI(page), toAPI(hitTestResult.get()), toAPI(modifiers), &userDataToPass, m_client.clientInfo);
78 userData = adoptRef(toImpl(userDataToPass));
81 void InjectedBundlePageUIClient::pageDidScroll(WebPage* page)
83 if (!m_client.pageDidScroll)
86 m_client.pageDidScroll(toAPI(page), m_client.clientInfo);
89 bool InjectedBundlePageUIClient::shouldPaintCustomOverhangArea()
91 return m_client.paintCustomOverhangArea;
94 void InjectedBundlePageUIClient::paintCustomOverhangArea(WebPage* page, GraphicsContext* graphicsContext, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect)
96 ASSERT(shouldPaintCustomOverhangArea());
98 RefPtr<WebGraphicsContext> context = WebGraphicsContext::create(graphicsContext);
99 m_client.paintCustomOverhangArea(toAPI(page), toAPI(context.get()), toAPI(horizontalOverhangArea), toAPI(verticalOverhangArea), toAPI(dirtyRect), m_client.clientInfo);
102 String InjectedBundlePageUIClient::shouldGenerateFileForUpload(WebPage* page, const String& originalFilePath)
104 if (!m_client.shouldGenerateFileForUpload)
106 RefPtr<WebString> generatedFilePath = adoptRef(toImpl(m_client.shouldGenerateFileForUpload(toAPI(page), toAPI(originalFilePath.impl()), m_client.clientInfo)));
107 return generatedFilePath ? generatedFilePath->string() : String();
110 String InjectedBundlePageUIClient::generateFileForUpload(WebPage* page, const String& originalFilePath)
112 if (!m_client.shouldGenerateFileForUpload)
114 RefPtr<WebString> generatedFilePath = adoptRef(toImpl(m_client.generateFileForUpload(toAPI(page), toAPI(originalFilePath.impl()), m_client.clientInfo)));
115 return generatedFilePath ? generatedFilePath->string() : String();
118 bool InjectedBundlePageUIClient::shouldRubberBandInDirection(WebPage* page, WKScrollDirection direction) const
120 if (!m_client.shouldRubberBandInDirection)
122 return m_client.shouldRubberBandInDirection(toAPI(page), direction, m_client.clientInfo);
125 WKBundlePageUIElementVisibility InjectedBundlePageUIClient::statusBarIsVisible(WebPage* page)
127 if (!m_client.statusBarIsVisible)
128 return WKBundlePageUIElementVisibilityUnknown;
130 return m_client.statusBarIsVisible(toAPI(page), m_client.clientInfo);
133 WKBundlePageUIElementVisibility InjectedBundlePageUIClient::menuBarIsVisible(WebPage* page)
135 if (!m_client.menuBarIsVisible)
136 return WKBundlePageUIElementVisibilityUnknown;
138 return m_client.menuBarIsVisible(toAPI(page), m_client.clientInfo);
141 WKBundlePageUIElementVisibility InjectedBundlePageUIClient::toolbarsAreVisible(WebPage* page)
143 if (!m_client.toolbarsAreVisible)
144 return WKBundlePageUIElementVisibilityUnknown;
146 return m_client.toolbarsAreVisible(toAPI(page), m_client.clientInfo);
149 } // namespace WebKit