diff options
| author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-01-06 14:44:00 +0100 |
|---|---|---|
| committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-01-06 14:44:00 +0100 |
| commit | 40736c5763bf61337c8c14e16d8587db021a87d4 (patch) | |
| tree | b17a9c00042ad89cb1308e2484491799aa14e9f8 /Source/WebKit2/WebProcess/InjectedBundle | |
| download | qtwebkit-40736c5763bf61337c8c14e16d8587db021a87d4.tar.gz | |
Imported WebKit commit 2ea9d364d0f6efa8fa64acf19f451504c59be0e4 (http://svn.webkit.org/repository/webkit/trunk@104285)
Diffstat (limited to 'Source/WebKit2/WebProcess/InjectedBundle')
74 files changed, 7069 insertions, 0 deletions
diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.cpp new file mode 100644 index 000000000..d88281e1b --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.cpp @@ -0,0 +1,232 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKBundle.h" +#include "WKBundlePrivate.h" + +#include "InjectedBundle.h" +#include "WKAPICast.h" +#include "WKBundleAPICast.h" + +using namespace WebKit; + +WKTypeID WKBundleGetTypeID() +{ + return toAPI(InjectedBundle::APIType); +} + +void WKBundleSetClient(WKBundleRef bundleRef, WKBundleClient * wkClient) +{ + toImpl(bundleRef)->initializeClient(wkClient); +} + +void WKBundlePostMessage(WKBundleRef bundleRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef) +{ + toImpl(bundleRef)->postMessage(toImpl(messageNameRef)->string(), toImpl(messageBodyRef)); +} + +void WKBundlePostSynchronousMessage(WKBundleRef bundleRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef, WKTypeRef* returnDataRef) +{ + RefPtr<APIObject> returnData; + toImpl(bundleRef)->postSynchronousMessage(toImpl(messageNameRef)->string(), toImpl(messageBodyRef), returnData); + if (returnDataRef) + *returnDataRef = toAPI(returnData.release().leakRef()); +} + +WKConnectionRef WKBundleGetApplicationConnection(WKBundleRef bundleRef) +{ + return toAPI(toImpl(bundleRef)->webConnectionToUIProcess()); +} + +void WKBundleSetShouldTrackVisitedLinks(WKBundleRef bundleRef, bool shouldTrackVisitedLinks) +{ + toImpl(bundleRef)->setShouldTrackVisitedLinks(shouldTrackVisitedLinks); +} + +void WKBundleRemoveAllVisitedLinks(WKBundleRef bundleRef) +{ + toImpl(bundleRef)->removeAllVisitedLinks(); +} + +void WKBundleActivateMacFontAscentHack(WKBundleRef bundleRef) +{ + toImpl(bundleRef)->activateMacFontAscentHack(); +} + +void WKBundleGarbageCollectJavaScriptObjects(WKBundleRef bundleRef) +{ + toImpl(bundleRef)->garbageCollectJavaScriptObjects(); +} + +void WKBundleGarbageCollectJavaScriptObjectsOnAlternateThreadForDebugging(WKBundleRef bundleRef, bool waitUntilDone) +{ + toImpl(bundleRef)->garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging(waitUntilDone); +} + +size_t WKBundleGetJavaScriptObjectsCount(WKBundleRef bundleRef) +{ + return toImpl(bundleRef)->javaScriptObjectsCount(); +} + +void WKBundleAddUserScript(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, WKBundleScriptWorldRef scriptWorldRef, WKStringRef sourceRef, WKURLRef urlRef, WKArrayRef whitelistRef, WKArrayRef blacklistRef, WKUserScriptInjectionTime injectionTimeRef, WKUserContentInjectedFrames injectedFramesRef) +{ + toImpl(bundleRef)->addUserScript(toImpl(pageGroupRef), toImpl(scriptWorldRef), toWTFString(sourceRef), toWTFString(urlRef), toImpl(whitelistRef), toImpl(blacklistRef), toUserScriptInjectionTime(injectionTimeRef), toUserContentInjectedFrames(injectedFramesRef)); +} + +void WKBundleAddUserStyleSheet(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, WKBundleScriptWorldRef scriptWorldRef, WKStringRef sourceRef, WKURLRef urlRef, WKArrayRef whitelistRef, WKArrayRef blacklistRef, WKUserContentInjectedFrames injectedFramesRef) +{ + toImpl(bundleRef)->addUserStyleSheet(toImpl(pageGroupRef), toImpl(scriptWorldRef), toWTFString(sourceRef), toWTFString(urlRef), toImpl(whitelistRef), toImpl(blacklistRef), toUserContentInjectedFrames(injectedFramesRef)); +} + +void WKBundleRemoveUserScript(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, WKBundleScriptWorldRef scriptWorldRef, WKURLRef urlRef) +{ + toImpl(bundleRef)->removeUserScript(toImpl(pageGroupRef), toImpl(scriptWorldRef), toWTFString(urlRef)); +} + +void WKBundleRemoveUserStyleSheet(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, WKBundleScriptWorldRef scriptWorldRef, WKURLRef urlRef) +{ + toImpl(bundleRef)->removeUserStyleSheet(toImpl(pageGroupRef), toImpl(scriptWorldRef), toWTFString(urlRef)); +} + +void WKBundleRemoveUserScripts(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, WKBundleScriptWorldRef scriptWorldRef) +{ + toImpl(bundleRef)->removeUserScripts(toImpl(pageGroupRef), toImpl(scriptWorldRef)); +} + +void WKBundleRemoveUserStyleSheets(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, WKBundleScriptWorldRef scriptWorldRef) +{ + toImpl(bundleRef)->removeUserStyleSheets(toImpl(pageGroupRef), toImpl(scriptWorldRef)); +} + +void WKBundleRemoveAllUserContent(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef) +{ + toImpl(bundleRef)->removeAllUserContent(toImpl(pageGroupRef)); +} + +void WKBundleOverrideXSSAuditorEnabledForTestRunner(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, bool enabled) +{ + toImpl(bundleRef)->overrideXSSAuditorEnabledForTestRunner(toImpl(pageGroupRef), enabled); +} + +void WKBundleSetAllowUniversalAccessFromFileURLs(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, bool enabled) +{ + toImpl(bundleRef)->setAllowUniversalAccessFromFileURLs(toImpl(pageGroupRef), enabled); +} + +void WKBundleSetAllowFileAccessFromFileURLs(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, bool enabled) +{ + toImpl(bundleRef)->setAllowFileAccessFromFileURLs(toImpl(pageGroupRef), enabled); +} + +void WKBundleSetFrameFlatteningEnabled(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, bool enabled) +{ + toImpl(bundleRef)->setFrameFlatteningEnabled(toImpl(pageGroupRef), enabled); +} + +void WKBundleSetJavaScriptCanAccessClipboard(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, bool enabled) +{ + toImpl(bundleRef)->setJavaScriptCanAccessClipboard(toImpl(pageGroupRef), enabled); +} + +void WKBundleSetPrivateBrowsingEnabled(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, bool enabled) +{ + toImpl(bundleRef)->setPrivateBrowsingEnabled(toImpl(pageGroupRef), enabled); +} + +void WKBundleSwitchNetworkLoaderToNewTestingSession(WKBundleRef bundleRef) +{ + toImpl(bundleRef)->switchNetworkLoaderToNewTestingSession(); +} + +void WKBundleSetAuthorAndUserStylesEnabled(WKBundleRef bundleRef, WKBundlePageGroupRef pageGroupRef, bool enabled) +{ + toImpl(bundleRef)->setAuthorAndUserStylesEnabled(toImpl(pageGroupRef), enabled); +} + +void WKBundleAddOriginAccessWhitelistEntry(WKBundleRef bundleRef, WKStringRef sourceOrigin, WKStringRef destinationProtocol, WKStringRef destinationHost, bool allowDestinationSubdomains) +{ + toImpl(bundleRef)->addOriginAccessWhitelistEntry(toImpl(sourceOrigin)->string(), toImpl(destinationProtocol)->string(), toImpl(destinationHost)->string(), allowDestinationSubdomains); +} + +void WKBundleRemoveOriginAccessWhitelistEntry(WKBundleRef bundleRef, WKStringRef sourceOrigin, WKStringRef destinationProtocol, WKStringRef destinationHost, bool allowDestinationSubdomains) +{ + toImpl(bundleRef)->removeOriginAccessWhitelistEntry(toImpl(sourceOrigin)->string(), toImpl(destinationProtocol)->string(), toImpl(destinationHost)->string(), allowDestinationSubdomains); +} + +void WKBundleResetOriginAccessWhitelists(WKBundleRef bundleRef) +{ + toImpl(bundleRef)->resetOriginAccessWhitelists(); +} + +void WKBundleReportException(JSContextRef context, JSValueRef exception) +{ + InjectedBundle::reportException(context, exception); +} + +void WKBundleClearAllDatabases(WKBundleRef bundleRef) +{ + toImpl(bundleRef)->clearAllDatabases(); +} + +void WKBundleSetDatabaseQuota(WKBundleRef bundleRef, uint64_t quota) +{ + toImpl(bundleRef)->setDatabaseQuota(quota); +} + +void WKBundleClearApplicationCache(WKBundleRef bundleRef) +{ + toImpl(bundleRef)->clearApplicationCache(); +} + +void WKBundleSetAppCacheMaximumSize(WKBundleRef bundleRef, uint64_t size) +{ + toImpl(bundleRef)->setAppCacheMaximumSize(size); +} + +int WKBundleNumberOfPages(WKBundleRef bundleRef, WKBundleFrameRef frameRef, double pageWidthInPixels, double pageHeightInPixels) +{ + return toImpl(bundleRef)->numberOfPages(toImpl(frameRef), pageWidthInPixels, pageHeightInPixels); +} + +int WKBundlePageNumberForElementById(WKBundleRef bundleRef, WKBundleFrameRef frameRef, WKStringRef idRef, double pageWidthInPixels, double pageHeightInPixels) +{ + return toImpl(bundleRef)->pageNumberForElementById(toImpl(frameRef), toImpl(idRef)->string(), pageWidthInPixels, pageHeightInPixels); +} + +WKStringRef WKBundlePageSizeAndMarginsInPixels(WKBundleRef bundleRef, WKBundleFrameRef frameRef, int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) +{ + return toCopiedAPI(toImpl(bundleRef)->pageSizeAndMarginsInPixels(toImpl(frameRef), pageIndex, width, height, marginTop, marginRight, marginBottom, marginLeft)); +} + +bool WKBundleIsPageBoxVisible(WKBundleRef bundleRef, WKBundleFrameRef frameRef, int pageIndex) +{ + return toImpl(bundleRef)->isPageBoxVisible(toImpl(frameRef), pageIndex); +} + +bool WKBundleIsProcessingUserGesture(WKBundleRef) +{ + return InjectedBundle::isProcessingUserGesture(); +} diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.h new file mode 100644 index 000000000..9e273bae3 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundle_h +#define WKBundle_h + +#include <JavaScriptCore/JavaScript.h> +#include <WebKit2/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +// Client +typedef void (*WKBundleDidCreatePageCallback)(WKBundleRef bundle, WKBundlePageRef page, const void* clientInfo); +typedef void (*WKBundleWillDestroyPageCallback)(WKBundleRef bundle, WKBundlePageRef page, const void* clientInfo); +typedef void (*WKBundleDidInitializePageGroupCallback)(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, const void* clientInfo); +typedef void (*WKBundleDidReceiveMessageCallback)(WKBundleRef bundle, WKStringRef name, WKTypeRef messageBody, const void* clientInfo); + +struct WKBundleClient { + int version; + const void * clientInfo; + WKBundleDidCreatePageCallback didCreatePage; + WKBundleWillDestroyPageCallback willDestroyPage; + WKBundleDidInitializePageGroupCallback didInitializePageGroup; + WKBundleDidReceiveMessageCallback didReceiveMessage; +}; +typedef struct WKBundleClient WKBundleClient; + +enum { kWKBundleClientCurrentVersion = 0 }; + +WK_EXPORT WKTypeID WKBundleGetTypeID(); + +WK_EXPORT void WKBundleSetClient(WKBundleRef bundle, WKBundleClient * client); + +WK_EXPORT void WKBundlePostMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef messageBody); +WK_EXPORT void WKBundlePostSynchronousMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData); + +WK_EXPORT WKConnectionRef WKBundleGetApplicationConnection(WKBundleRef bundle); + +WK_EXPORT void WKBundleReportException(JSContextRef, JSValueRef exception); + +#ifdef __cplusplus +} +#endif + +#endif /* WKBundle_h */ diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleAPICast.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleAPICast.h new file mode 100644 index 000000000..db32716c1 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleAPICast.h @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundleAPICast_h +#define WKBundleAPICast_h + +#include "WKSharedAPICast.h" +#include "WKBundlePage.h" +#include "WKBundlePagePrivate.h" +#include "WKBundlePrivate.h" +#include <WebCore/EditorInsertAction.h> +#include <WebCore/TextAffinity.h> +#include <WebCore/UserContentTypes.h> +#include <WebCore/UserScriptTypes.h> + +namespace WebCore { + class CSSStyleDeclaration; +} + +namespace WebKit { + +class InjectedBundle; +class InjectedBundleBackForwardList; +class InjectedBundleBackForwardListItem; +class InjectedBundleHitTestResult; +class InjectedBundleNavigationAction; +class InjectedBundleNodeHandle; +class InjectedBundleRangeHandle; +class InjectedBundleScriptWorld; +class PageOverlay; +class WebFrame; +class WebInspector; +class WebPage; +class WebPageGroupProxy; + +WK_ADD_API_MAPPING(WKBundleBackForwardListItemRef, InjectedBundleBackForwardListItem) +WK_ADD_API_MAPPING(WKBundleBackForwardListRef, InjectedBundleBackForwardList) +WK_ADD_API_MAPPING(WKBundleCSSStyleDeclarationRef, WebCore::CSSStyleDeclaration) +WK_ADD_API_MAPPING(WKBundleFrameRef, WebFrame) +WK_ADD_API_MAPPING(WKBundleHitTestResultRef, InjectedBundleHitTestResult) +WK_ADD_API_MAPPING(WKBundleInspectorRef, WebInspector) +WK_ADD_API_MAPPING(WKBundleNavigationActionRef, InjectedBundleNavigationAction) +WK_ADD_API_MAPPING(WKBundleNodeHandleRef, InjectedBundleNodeHandle) +WK_ADD_API_MAPPING(WKBundlePageGroupRef, WebPageGroupProxy) +WK_ADD_API_MAPPING(WKBundlePageOverlayRef, PageOverlay) +WK_ADD_API_MAPPING(WKBundlePageRef, WebPage) +WK_ADD_API_MAPPING(WKBundleRangeHandleRef, InjectedBundleRangeHandle) +WK_ADD_API_MAPPING(WKBundleRef, InjectedBundle) +WK_ADD_API_MAPPING(WKBundleScriptWorldRef, InjectedBundleScriptWorld) + +inline WKInsertActionType toAPI(WebCore::EditorInsertAction action) +{ + switch (action) { + case WebCore::EditorInsertActionTyped: + return kWKInsertActionTyped; + break; + case WebCore::EditorInsertActionPasted: + return kWKInsertActionPasted; + break; + case WebCore::EditorInsertActionDropped: + return kWKInsertActionDropped; + break; + } + ASSERT_NOT_REACHED(); + return kWKInsertActionTyped; +} + +inline WKAffinityType toAPI(WebCore::EAffinity affinity) +{ + switch (affinity) { + case WebCore::UPSTREAM: + return kWKAffinityUpstream; + break; + case WebCore::DOWNSTREAM: + return kWKAffinityDownstream; + break; + } + ASSERT_NOT_REACHED(); + return kWKAffinityUpstream; +} + +inline WebCore::UserScriptInjectionTime toUserScriptInjectionTime(WKUserScriptInjectionTime wkInjectedTime) +{ + switch (wkInjectedTime) { + case kWKInjectAtDocumentStart: + return WebCore::InjectAtDocumentStart; + case kWKInjectAtDocumentEnd: + return WebCore::InjectAtDocumentEnd; + } + + ASSERT_NOT_REACHED(); + return WebCore::InjectAtDocumentStart; +} + +inline WebCore::UserContentInjectedFrames toUserContentInjectedFrames(WKUserContentInjectedFrames wkInjectedFrames) +{ + switch (wkInjectedFrames) { + case kWKInjectInAllFrames: + return WebCore::InjectInAllFrames; + case kWKInjectInTopFrameOnly: + return WebCore::InjectInTopFrameOnly; + } + + ASSERT_NOT_REACHED(); + return WebCore::InjectInAllFrames; +} + +} // namespace WebKit + +#endif // WKBundleAPICast_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleBackForwardList.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleBackForwardList.cpp new file mode 100644 index 000000000..7ffa3ce1c --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleBackForwardList.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKBundleBackForwardList.h" + +#include "InjectedBundleBackForwardList.h" +#include "InjectedBundleBackForwardListItem.h" +#include "WKBundleAPICast.h" + +using namespace WebKit; + +WKTypeID WKBundleBackForwardListGetTypeID() +{ + return toAPI(InjectedBundleBackForwardList::APIType); +} + +WKBundleBackForwardListItemRef WKBundleBackForwardListCopyItemAtIndex(WKBundleBackForwardListRef listRef, int index) +{ + return toAPI(toImpl(listRef)->itemAtIndex(index).leakRef()); +} + +unsigned WKBundleBackForwardListGetBackListCount(WKBundleBackForwardListRef listRef) +{ + return toImpl(listRef)->backListCount(); +} + +unsigned WKBundleBackForwardListGetForwardListCount(WKBundleBackForwardListRef listRef) +{ + return toImpl(listRef)->forwardListCount(); +} + +void WKBundleBackForwardListClear(WKBundleBackForwardListRef listRef) +{ + return toImpl(listRef)->clear(); +} diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleBackForwardList.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleBackForwardList.h new file mode 100644 index 000000000..7aa573aa6 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleBackForwardList.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundleBackForwardList_h +#define WKBundleBackForwardList_h + +#include <WebKit2/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKBundleBackForwardListGetTypeID(); + +WK_EXPORT WKBundleBackForwardListItemRef WKBundleBackForwardListCopyItemAtIndex(WKBundleBackForwardListRef list, int index); + +WK_EXPORT unsigned WKBundleBackForwardListGetBackListCount(WKBundleBackForwardListRef list); +WK_EXPORT unsigned WKBundleBackForwardListGetForwardListCount(WKBundleBackForwardListRef list); + +WK_EXPORT void WKBundleBackForwardListClear(WKBundleBackForwardListRef list); + +#ifdef __cplusplus +} +#endif + +#endif // WKBundleBackForwardList_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.cpp new file mode 100644 index 000000000..e9845e355 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKBundleBackForwardListItem.h" + +#include "ImmutableArray.h" +#include "InjectedBundleBackForwardListItem.h" +#include "WKBundleAPICast.h" + +using namespace WebKit; + +WKTypeID WKBundleBackForwardListItemGetTypeID() +{ + return toAPI(InjectedBundleBackForwardListItem::APIType); +} + +bool WKBundleBackForwardListItemIsSame(WKBundleBackForwardListItemRef itemRef1, WKBundleBackForwardListItemRef itemRef2) +{ + return toImpl(itemRef1)->item() == toImpl(itemRef2)->item(); +} + +WKURLRef WKBundleBackForwardListItemCopyOriginalURL(WKBundleBackForwardListItemRef itemRef) +{ + return toCopiedURLAPI(toImpl(itemRef)->originalURL()); +} + +WKURLRef WKBundleBackForwardListItemCopyURL(WKBundleBackForwardListItemRef itemRef) +{ + return toCopiedURLAPI(toImpl(itemRef)->url()); +} + +WKStringRef WKBundleBackForwardListItemCopyTitle(WKBundleBackForwardListItemRef itemRef) +{ + return toCopiedAPI(toImpl(itemRef)->title()); +} + +WKStringRef WKBundleBackForwardListItemCopyTarget(WKBundleBackForwardListItemRef itemRef) +{ + return toCopiedAPI(toImpl(itemRef)->target()); +} + +bool WKBundleBackForwardListItemIsTargetItem(WKBundleBackForwardListItemRef itemRef) +{ + return toImpl(itemRef)->isTargetItem(); +} + +WKArrayRef WKBundleBackForwardListItemCopyChildren(WKBundleBackForwardListItemRef itemRef) +{ + return toAPI(toImpl(itemRef)->children().leakRef()); +} + diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.h new file mode 100644 index 000000000..f256464e6 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundleBackForwardListItem_h +#define WKBundleBackForwardListItem_h + +#include <WebKit2/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKBundleBackForwardListItemGetTypeID(); + +WK_EXPORT bool WKBundleBackForwardListItemIsSame(WKBundleBackForwardListItemRef item1, WKBundleBackForwardListItemRef item2); + +WK_EXPORT WKURLRef WKBundleBackForwardListItemCopyOriginalURL(WKBundleBackForwardListItemRef item); +WK_EXPORT WKURLRef WKBundleBackForwardListItemCopyURL(WKBundleBackForwardListItemRef item); +WK_EXPORT WKStringRef WKBundleBackForwardListItemCopyTitle(WKBundleBackForwardListItemRef item); + +WK_EXPORT WKStringRef WKBundleBackForwardListItemCopyTarget(WKBundleBackForwardListItemRef item); +WK_EXPORT bool WKBundleBackForwardListItemIsTargetItem(WKBundleBackForwardListItemRef item); + +WK_EXPORT WKArrayRef WKBundleBackForwardListItemCopyChildren(WKBundleBackForwardListItemRef item); + +#ifdef __cplusplus +} +#endif + +#endif /* WKBundleBackForwardListItem_h */ diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp new file mode 100644 index 000000000..df729bff5 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp @@ -0,0 +1,254 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKBundleFrame.h" +#include "WKBundleFramePrivate.h" + +#include "WKAPICast.h" +#include "WKBundleAPICast.h" +#include "WKData.h" +#include "WebFrame.h" +#include <WebCore/Frame.h> +#include <WebCore/FrameView.h> + +using namespace WebCore; +using namespace WebKit; + +WKTypeID WKBundleFrameGetTypeID() +{ + return toAPI(WebFrame::APIType); +} + +bool WKBundleFrameIsMainFrame(WKBundleFrameRef frameRef) +{ + return toImpl(frameRef)->isMainFrame(); +} + +WKURLRef WKBundleFrameCopyURL(WKBundleFrameRef frameRef) +{ + return toCopiedURLAPI(toImpl(frameRef)->url()); +} + +WKURLRef WKBundleFrameCopyProvisionalURL(WKBundleFrameRef frameRef) +{ + return toCopiedURLAPI(toImpl(frameRef)->provisionalURL()); +} + +WKFrameLoadState WKBundleFrameGetFrameLoadState(WKBundleFrameRef frameRef) +{ + Frame* coreFrame = toImpl(frameRef)->coreFrame(); + if (!coreFrame) + return kWKFrameLoadStateFinished; + + FrameLoader* loader = coreFrame->loader(); + if (!loader) + return kWKFrameLoadStateFinished; + + switch (loader->state()) { + case FrameStateProvisional: + return kWKFrameLoadStateProvisional; + case FrameStateCommittedPage: + return kWKFrameLoadStateCommitted; + case FrameStateComplete: + return kWKFrameLoadStateFinished; + } + + ASSERT_NOT_REACHED(); + return kWKFrameLoadStateFinished; +} + +WKArrayRef WKBundleFrameCopyChildFrames(WKBundleFrameRef frameRef) +{ + return toAPI(toImpl(frameRef)->childFrames().leakRef()); +} + +unsigned WKBundleFrameGetNumberOfActiveAnimations(WKBundleFrameRef frameRef) +{ + return toImpl(frameRef)->numberOfActiveAnimations(); +} + +bool WKBundleFramePauseAnimationOnElementWithId(WKBundleFrameRef frameRef, WKStringRef animationName, WKStringRef elementID, double time) +{ + return toImpl(frameRef)->pauseAnimationOnElementWithId(toImpl(animationName)->string(), toImpl(elementID)->string(), time); +} + +bool WKBundleFramePauseTransitionOnElementWithId(WKBundleFrameRef frameRef, WKStringRef propertyName, WKStringRef elementID, double time) +{ + return toImpl(frameRef)->pauseTransitionOnElementWithId(toImpl(propertyName)->string(), toImpl(elementID)->string(), time); +} + +void WKBundleFrameSuspendAnimations(WKBundleFrameRef frameRef) +{ + toImpl(frameRef)->suspendAnimations(); +} + +void WKBundleFrameResumeAnimations(WKBundleFrameRef frameRef) +{ + toImpl(frameRef)->resumeAnimations(); +} + +JSGlobalContextRef WKBundleFrameGetJavaScriptContext(WKBundleFrameRef frameRef) +{ + return toImpl(frameRef)->jsContext(); +} + +WKBundleFrameRef WKBundleFrameForJavaScriptContext(JSContextRef context) +{ + return toAPI(WebFrame::frameForContext(context)); +} + +JSGlobalContextRef WKBundleFrameGetJavaScriptContextForWorld(WKBundleFrameRef frameRef, WKBundleScriptWorldRef worldRef) +{ + return toImpl(frameRef)->jsContextForWorld(toImpl(worldRef)); +} + +JSValueRef WKBundleFrameGetJavaScriptWrapperForNodeForWorld(WKBundleFrameRef frameRef, WKBundleNodeHandleRef nodeHandleRef, WKBundleScriptWorldRef worldRef) +{ + return toImpl(frameRef)->jsWrapperForWorld(toImpl(nodeHandleRef), toImpl(worldRef)); +} + +JSValueRef WKBundleFrameGetJavaScriptWrapperForRangeForWorld(WKBundleFrameRef frameRef, WKBundleRangeHandleRef rangeHandleRef, WKBundleScriptWorldRef worldRef) +{ + return toImpl(frameRef)->jsWrapperForWorld(toImpl(rangeHandleRef), toImpl(worldRef)); +} + +WKStringRef WKBundleFrameCopyName(WKBundleFrameRef frameRef) +{ + return toCopiedAPI(toImpl(frameRef)->name()); +} + +JSValueRef WKBundleFrameGetComputedStyleIncludingVisitedInfo(WKBundleFrameRef frameRef, JSObjectRef element) +{ + return toImpl(frameRef)->computedStyleIncludingVisitedInfo(element); +} + +WKStringRef WKBundleFrameCopyCounterValue(WKBundleFrameRef frameRef, JSObjectRef element) +{ + return toCopiedAPI(toImpl(frameRef)->counterValue(element)); +} + +WKStringRef WKBundleFrameCopyMarkerText(WKBundleFrameRef frameRef, JSObjectRef element) +{ + return toCopiedAPI(toImpl(frameRef)->markerText(element)); +} + +WKStringRef WKBundleFrameCopyInnerText(WKBundleFrameRef frameRef) +{ + return toCopiedAPI(toImpl(frameRef)->innerText()); +} + +unsigned WKBundleFrameGetPendingUnloadCount(WKBundleFrameRef frameRef) +{ + return toImpl(frameRef)->pendingUnloadCount(); +} + +WKBundlePageRef WKBundleFrameGetPage(WKBundleFrameRef frameRef) +{ + return toAPI(toImpl(frameRef)->page()); +} + +void WKBundleFrameClearOpener(WKBundleFrameRef frameRef) +{ + Frame* coreFrame = toImpl(frameRef)->coreFrame(); + if (coreFrame) + coreFrame->loader()->setOpener(0); +} + +WKStringRef WKBundleFrameCopyLayerTreeAsText(WKBundleFrameRef frameRef) +{ + return toCopiedAPI(toImpl(frameRef)->layerTreeAsText()); +} + +bool WKBundleFrameAllowsFollowingLink(WKBundleFrameRef frameRef, WKURLRef urlRef) +{ + return toImpl(frameRef)->allowsFollowingLink(WebCore::KURL(WebCore::KURL(), toImpl(urlRef)->string())); +} + +WKRect WKBundleFrameGetContentBounds(WKBundleFrameRef frameRef) +{ + return toAPI(toImpl(frameRef)->contentBounds()); +} + +WKRect WKBundleFrameGetVisibleContentBounds(WKBundleFrameRef frameRef) +{ + return toAPI(toImpl(frameRef)->visibleContentBounds()); +} + +WKRect WKBundleFrameGetVisibleContentBoundsExcludingScrollbars(WKBundleFrameRef frameRef) +{ + return toAPI(toImpl(frameRef)->visibleContentBoundsExcludingScrollbars()); +} + +WKSize WKBundleFrameGetScrollOffset(WKBundleFrameRef frameRef) +{ + return toAPI(toImpl(frameRef)->scrollOffset()); +} + +bool WKBundleFrameHasHorizontalScrollbar(WKBundleFrameRef frameRef) +{ + return toImpl(frameRef)->hasHorizontalScrollbar(); +} + +bool WKBundleFrameHasVerticalScrollbar(WKBundleFrameRef frameRef) +{ + return toImpl(frameRef)->hasVerticalScrollbar(); +} + +bool WKBundleFrameGetDocumentBackgroundColor(WKBundleFrameRef frameRef, double* red, double* green, double* blue, double* alpha) +{ + return toImpl(frameRef)->getDocumentBackgroundColor(red, green, blue, alpha); +} + +WKStringRef WKBundleFrameCopySuggestedFilenameForResourceWithURL(WKBundleFrameRef frameRef, WKURLRef urlRef) +{ + return toCopiedAPI(toImpl(frameRef)->suggestedFilenameForResourceWithURL(WebCore::KURL(WebCore::KURL(), toImpl(urlRef)->string()))); +} + +WKStringRef WKBundleFrameCopyMIMETypeForResourceWithURL(WKBundleFrameRef frameRef, WKURLRef urlRef) +{ + return toCopiedAPI(toImpl(frameRef)->mimeTypeForResourceWithURL(WebCore::KURL(WebCore::KURL(), toImpl(urlRef)->string()))); +} + +bool WKBundleFrameContainsAnyFormElements(WKBundleFrameRef frameRef) +{ + return toImpl(frameRef)->containsAnyFormElements(); +} + +void WKBundleFrameSetTextDirection(WKBundleFrameRef frameRef, WKStringRef directionRef) +{ + toImpl(frameRef)->setTextDirection(toImpl(directionRef)->string()); +} + +WKDataRef WKBundleFrameCopyWebArchive(WKBundleFrameRef frameRef) +{ +#if PLATFORM(MAC) || PLATFORM(WIN) + RetainPtr<CFDataRef> data = toImpl(frameRef)->webArchiveData(); + if (data) + return WKDataCreate(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get())); +#endif + + return 0; +} diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.h new file mode 100644 index 000000000..ce94badcb --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.h @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundleFrame_h +#define WKBundleFrame_h + +#include <JavaScriptCore/JavaScript.h> +#include <WebKit2/WKBase.h> +#include <WebKit2/WKFrame.h> +#include <WebKit2/WKGeometry.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKBundleFrameGetTypeID(); + +WK_EXPORT bool WKBundleFrameIsMainFrame(WKBundleFrameRef frame); +WK_EXPORT WKArrayRef WKBundleFrameCopyChildFrames(WKBundleFrameRef frame); + +WK_EXPORT WKStringRef WKBundleFrameCopyName(WKBundleFrameRef frame); +WK_EXPORT WKURLRef WKBundleFrameCopyURL(WKBundleFrameRef frame); +WK_EXPORT WKURLRef WKBundleFrameCopyProvisionalURL(WKBundleFrameRef frame); + +WK_EXPORT WKFrameLoadState WKBundleFrameGetFrameLoadState(WKBundleFrameRef frame); + +WK_EXPORT JSGlobalContextRef WKBundleFrameGetJavaScriptContext(WKBundleFrameRef frame); +WK_EXPORT JSGlobalContextRef WKBundleFrameGetJavaScriptContextForWorld(WKBundleFrameRef frame, WKBundleScriptWorldRef world); + +WK_EXPORT WKBundleFrameRef WKBundleFrameForJavaScriptContext(JSContextRef context); + +WK_EXPORT JSValueRef WKBundleFrameGetJavaScriptWrapperForNodeForWorld(WKBundleFrameRef frame, WKBundleNodeHandleRef nodeHandle, WKBundleScriptWorldRef world); +WK_EXPORT JSValueRef WKBundleFrameGetJavaScriptWrapperForRangeForWorld(WKBundleFrameRef frame, WKBundleRangeHandleRef rangeHandle, WKBundleScriptWorldRef world); + +WK_EXPORT WKBundlePageRef WKBundleFrameGetPage(WKBundleFrameRef frame); + +WK_EXPORT bool WKBundleFrameAllowsFollowingLink(WKBundleFrameRef frame, WKURLRef url); + +WK_EXPORT WKRect WKBundleFrameGetContentBounds(WKBundleFrameRef frame); +WK_EXPORT WKRect WKBundleFrameGetVisibleContentBounds(WKBundleFrameRef frame); +WK_EXPORT WKRect WKBundleFrameGetVisibleContentBoundsExcludingScrollbars(WKBundleFrameRef frame); +WK_EXPORT WKSize WKBundleFrameGetScrollOffset(WKBundleFrameRef frame); + +WK_EXPORT bool WKBundleFrameHasHorizontalScrollbar(WKBundleFrameRef frame); +WK_EXPORT bool WKBundleFrameHasVerticalScrollbar(WKBundleFrameRef frame); + +WK_EXPORT bool WKBundleFrameGetDocumentBackgroundColor(WKBundleFrameRef frame, double* red, double* green, double* blue, double* alpha); + +WK_EXPORT WKStringRef WKBundleFrameCopySuggestedFilenameForResourceWithURL(WKBundleFrameRef frame, WKURLRef url); +WK_EXPORT WKStringRef WKBundleFrameCopyMIMETypeForResourceWithURL(WKBundleFrameRef frame, WKURLRef url); + +WK_EXPORT WKDataRef WKBundleFrameCopyWebArchive(WKBundleFrameRef frame); + +#ifdef __cplusplus +} +#endif + +#endif /* WKBundleFrame_h */ diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFramePrivate.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFramePrivate.h new file mode 100644 index 000000000..a786b2557 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFramePrivate.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundleFramePrivate_h +#define WKBundleFramePrivate_h + +#include <JavaScriptCore/JavaScript.h> +#include <WebKit2/WKBase.h> + +#ifndef __cplusplus +#include <stdbool.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKStringRef WKBundleFrameCopyInnerText(WKBundleFrameRef frame); +WK_EXPORT WKStringRef WKBundleFrameCopyCounterValue(WKBundleFrameRef frame, JSObjectRef element); +WK_EXPORT WKStringRef WKBundleFrameCopyMarkerText(WKBundleFrameRef frame, JSObjectRef element); +WK_EXPORT JSValueRef WKBundleFrameGetComputedStyleIncludingVisitedInfo(WKBundleFrameRef frame, JSObjectRef element); +WK_EXPORT unsigned WKBundleFrameGetNumberOfActiveAnimations(WKBundleFrameRef frame); +WK_EXPORT bool WKBundleFramePauseAnimationOnElementWithId(WKBundleFrameRef frame, WKStringRef animationName, WKStringRef elementID, double time); +WK_EXPORT bool WKBundleFramePauseTransitionOnElementWithId(WKBundleFrameRef frame, WKStringRef propertyName, WKStringRef elementID, double time); +WK_EXPORT void WKBundleFrameSuspendAnimations(WKBundleFrameRef frame); +WK_EXPORT void WKBundleFrameResumeAnimations(WKBundleFrameRef frame); +WK_EXPORT unsigned WKBundleFrameGetPendingUnloadCount(WKBundleFrameRef frame); +WK_EXPORT WKStringRef WKBundleFrameCopyLayerTreeAsText(WKBundleFrameRef frame); +WK_EXPORT void WKBundleFrameClearOpener(WKBundleFrameRef frame); + +WK_EXPORT bool WKBundleFrameContainsAnyFormElements(WKBundleFrameRef frame); +WK_EXPORT void WKBundleFrameSetTextDirection(WKBundleFrameRef frame, WKStringRef); + +#ifdef __cplusplus +} +#endif + +#endif /* WKBundleFramePrivate_h */ diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp new file mode 100644 index 000000000..9cb225033 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKBundleHitTestResult.h" + +#include "InjectedBundleHitTestResult.h" +#include "InjectedBundleNodeHandle.h" +#include "WKAPICast.h" +#include "WKBundleAPICast.h" + +using namespace WebKit; + +WKTypeID WKBundleHitTestResultGetTypeID() +{ + return toAPI(InjectedBundleHitTestResult::APIType); +} + +WKBundleNodeHandleRef WKBundleHitTestResultCopyNodeHandle(WKBundleHitTestResultRef hitTestResultRef) +{ + RefPtr<InjectedBundleNodeHandle> nodeHandle = toImpl(hitTestResultRef)->nodeHandle(); + return toAPI(nodeHandle.release().leakRef()); +} + +WKBundleFrameRef WKBundleHitTestResultGetFrame(WKBundleHitTestResultRef hitTestResultRef) +{ + return toAPI(toImpl(hitTestResultRef)->frame()); +} + +WKBundleFrameRef WKBundleHitTestResultGetTargetFrame(WKBundleHitTestResultRef hitTestResultRef) +{ + return toAPI(toImpl(hitTestResultRef)->targetFrame()); +} + +WKURLRef WKBundleHitTestResultCopyAbsoluteImageURL(WKBundleHitTestResultRef hitTestResultRef) +{ + return toCopiedURLAPI(toImpl(hitTestResultRef)->absoluteImageURL()); +} + +WKURLRef WKBundleHitTestResultCopyAbsolutePDFURL(WKBundleHitTestResultRef hitTestResultRef) +{ + return toCopiedURLAPI(toImpl(hitTestResultRef)->absolutePDFURL()); +} + +WKURLRef WKBundleHitTestResultCopyAbsoluteLinkURL(WKBundleHitTestResultRef hitTestResultRef) +{ + return toCopiedURLAPI(toImpl(hitTestResultRef)->absoluteLinkURL()); +} + +WKURLRef WKBundleHitTestResultCopyAbsoluteMediaURL(WKBundleHitTestResultRef hitTestResultRef) +{ + return toCopiedURLAPI(toImpl(hitTestResultRef)->absoluteMediaURL()); +} + +WKRect WKBundleHitTestResultGetImageRect(WKBundleHitTestResultRef hitTestResultRef) +{ + return toAPI(toImpl(hitTestResultRef)->imageRect()); +} + +bool WKBundleHitTestResultGetIsSelected(WKBundleHitTestResultRef hitTestResultRef) +{ + return toImpl(hitTestResultRef)->isSelected(); +} + +WKStringRef WKBundleHitTestResultCopyLinkLabel(WKBundleHitTestResultRef hitTestResultRef) +{ + return toCopiedAPI(toImpl(hitTestResultRef)->linkLabel()); +} + +WKStringRef WKBundleHitTestResultCopyLinkTitle(WKBundleHitTestResultRef hitTestResultRef) +{ + return toCopiedAPI(toImpl(hitTestResultRef)->linkTitle()); +} diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h new file mode 100644 index 000000000..37c5019da --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundleHitTestResult_h +#define WKBundleHitTestResult_h + +#include <WebKit2/WKBase.h> +#include <WebKit2/WKGeometry.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKBundleHitTestResultGetTypeID(); + +WK_EXPORT WKBundleNodeHandleRef WKBundleHitTestResultCopyNodeHandle(WKBundleHitTestResultRef hitTestResult); + +WK_EXPORT WKBundleFrameRef WKBundleHitTestResultGetFrame(WKBundleHitTestResultRef hitTestResult); +WK_EXPORT WKBundleFrameRef WKBundleHitTestResultGetTargetFrame(WKBundleHitTestResultRef hitTestResult); + +WK_EXPORT WKURLRef WKBundleHitTestResultCopyAbsoluteImageURL(WKBundleHitTestResultRef hitTestResult); +WK_EXPORT WKURLRef WKBundleHitTestResultCopyAbsolutePDFURL(WKBundleHitTestResultRef hitTestResult); +WK_EXPORT WKURLRef WKBundleHitTestResultCopyAbsoluteLinkURL(WKBundleHitTestResultRef hitTestResult); +WK_EXPORT WKURLRef WKBundleHitTestResultCopyAbsoluteMediaURL(WKBundleHitTestResultRef hitTestResult); + +WK_EXPORT WKRect WKBundleHitTestResultGetImageRect(WKBundleHitTestResultRef hitTestResult); +WK_EXPORT bool WKBundleHitTestResultGetIsSelected(WKBundleHitTestResultRef hitTestResult); + +WK_EXPORT WKStringRef WKBundleHitTestResultCopyLinkLabel(WKBundleHitTestResultRef hitTestResult); +WK_EXPORT WKStringRef WKBundleHitTestResultCopyLinkTitle(WKBundleHitTestResultRef hitTestResult); + +#ifdef __cplusplus +} +#endif + +#endif /* WKBundleHitTestResult_h */ diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleInitialize.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleInitialize.h new file mode 100644 index 000000000..f10b7b400 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleInitialize.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundleInitialize_h +#define WKBundleInitialize_h + +#include <WebKit2/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +// NOTE: Must be implemented by InjectedBundle's as a function named "WKBundleInitialize". +typedef void (*WKBundleInitializeFunctionPtr)(WKBundleRef, WKTypeRef); + +#ifdef __cplusplus +} +#endif + +#endif /* WKBundleInitialize_h */ diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleInspector.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleInspector.cpp new file mode 100644 index 000000000..a699eabaa --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleInspector.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKBundleInspector.h" + +#if ENABLE(INSPECTOR) + +#include "WKAPICast.h" +#include "WKBundleAPICast.h" +#include "WebInspector.h" + +using namespace WebCore; +using namespace WebKit; + +WKTypeID WKBundleInspectorGetTypeID() +{ + return toAPI(WebInspector::APIType); +} + +void WKBundleInspectorShow(WKBundleInspectorRef inspectorRef) +{ + return toImpl(inspectorRef)->show(); +} + +void WKBundleInspectorClose(WKBundleInspectorRef inspectorRef) +{ + return toImpl(inspectorRef)->close(); +} + +void WKBundleInspectorEvaluateScriptForTest(WKBundleInspectorRef inspectorRef, long callID, WKStringRef script) +{ + return toImpl(inspectorRef)->evaluateScriptForTest(callID, toImpl(script)->string()); +} + +void WKBundleInspectorSetJavaScriptProfilingEnabled(WKBundleInspectorRef inspectorRef, bool enabled) +{ + toImpl(inspectorRef)->setJavaScriptProfilingEnabled(enabled); +} + +void WKBundleInspectorSetPageProfilingEnabled(WKBundleInspectorRef inspectorRef, bool enabled) +{ + if (enabled) + toImpl(inspectorRef)->startPageProfiling(); + else + toImpl(inspectorRef)->stopPageProfiling(); +} + +#endif // ENABLE(INSPECTOR) diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleInspector.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleInspector.h new file mode 100644 index 000000000..593d90aa5 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleInspector.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundleInspector_h +#define WKBundleInspector_h + +#include <WebKit2/WKBase.h> + +#if ENABLE(INSPECTOR) + +#ifndef __cplusplus +#include <stdbool.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKBundleInspectorGetTypeID(); + +WK_EXPORT void WKBundleInspectorShow(WKBundleInspectorRef inspector); +WK_EXPORT void WKBundleInspectorClose(WKBundleInspectorRef inspector); + +WK_EXPORT void WKBundleInspectorEvaluateScriptForTest(WKBundleInspectorRef inspector, long callID, WKStringRef script); +WK_EXPORT void WKBundleInspectorSetJavaScriptProfilingEnabled(WKBundleInspectorRef inspector, bool enabled); +WK_EXPORT void WKBundleInspectorSetPageProfilingEnabled(WKBundleInspectorRef inspector, bool enabled); + +#ifdef __cplusplus +} +#endif + +#endif // ENABLE(INSPECTOR) + +#endif // WKBundleInspector_h + diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNavigationAction.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNavigationAction.cpp new file mode 100644 index 000000000..c26ec3ecf --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNavigationAction.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKBundleNavigationAction.h" + +#include "InjectedBundleHitTestResult.h" +#include "InjectedBundleNavigationAction.h" +#include "InjectedBundleNodeHandle.h" +#include "WKAPICast.h" +#include "WKBundleAPICast.h" + +using namespace WebKit; + +WKTypeID WKBundleNavigationActionGetTypeID() +{ + return toAPI(InjectedBundleNavigationAction::APIType); +} + +WKFrameNavigationType WKBundleNavigationActionGetNavigationType(WKBundleNavigationActionRef navigationActionRef) +{ + return toAPI(toImpl(navigationActionRef)->navigationType()); +} + +WKEventModifiers WKBundleNavigationActionGetEventModifiers(WKBundleNavigationActionRef navigationActionRef) +{ + return toAPI(toImpl(navigationActionRef)->modifiers()); +} + +WKEventMouseButton WKBundleNavigationActionGetEventMouseButton(WKBundleNavigationActionRef navigationActionRef) +{ + return toAPI(toImpl(navigationActionRef)->mouseButton()); +} + +WKBundleHitTestResultRef WKBundleNavigationActionCopyHitTestResult(WKBundleNavigationActionRef navigationActionRef) +{ + RefPtr<InjectedBundleHitTestResult> hitTestResult = toImpl(navigationActionRef)->hitTestResult(); + return toAPI(hitTestResult.release().leakRef()); +} + +WKBundleNodeHandleRef WKBundleNavigationActionCopyFormElement(WKBundleNavigationActionRef navigationActionRef) +{ + RefPtr<InjectedBundleNodeHandle> formElement = toImpl(navigationActionRef)->formElement(); + return toAPI(formElement.release().leakRef()); +} diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNavigationAction.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNavigationAction.h new file mode 100644 index 000000000..03f083a29 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNavigationAction.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundleNavigationAction_h +#define WKBundleNavigationAction_h + +#include <WebKit2/WKBase.h> +#include <WebKit2/WKEvent.h> +#include <WebKit2/WKPageLoadTypes.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKBundleNavigationActionGetTypeID(); + +WK_EXPORT WKFrameNavigationType WKBundleNavigationActionGetNavigationType(WKBundleNavigationActionRef navigationAction); +WK_EXPORT WKEventModifiers WKBundleNavigationActionGetEventModifiers(WKBundleNavigationActionRef navigationAction); +WK_EXPORT WKEventMouseButton WKBundleNavigationActionGetEventMouseButton(WKBundleNavigationActionRef navigationAction); +WK_EXPORT WKBundleHitTestResultRef WKBundleNavigationActionCopyHitTestResult(WKBundleNavigationActionRef navigationAction); +WK_EXPORT WKBundleNodeHandleRef WKBundleNavigationActionCopyFormElement(WKBundleNavigationActionRef navigationAction); + +#ifdef __cplusplus +} +#endif + +#endif /* WKBundleNavigationAction_h */ diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp new file mode 100644 index 000000000..77b87c90d --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKBundleNodeHandle.h" +#include "WKBundleNodeHandlePrivate.h" + +#include "InjectedBundleNodeHandle.h" +#include "WKAPICast.h" +#include "WKBundleAPICast.h" +#include "WebFrame.h" + +using namespace WebKit; + +WKTypeID WKBundleNodeHandleGetTypeID() +{ + return toAPI(InjectedBundleNodeHandle::APIType); +} + +WKBundleNodeHandleRef WKBundleNodeHandleCreate(JSContextRef contextRef, JSObjectRef objectRef) +{ + RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(contextRef, objectRef); + return toAPI(nodeHandle.release().leakRef()); +} + +WKBundleNodeHandleRef WKBundleNodeHandleCopyDocument(WKBundleNodeHandleRef nodeHandleRef) +{ + RefPtr<InjectedBundleNodeHandle> nodeHandle = toImpl(nodeHandleRef)->document(); + return toAPI(nodeHandle.release().leakRef()); +} + +WKRect WKBundleNodeHandleGetRenderRect(WKBundleNodeHandleRef nodeHandleRef, bool* isReplaced) +{ + return toAPI(toImpl(nodeHandleRef)->renderRect(isReplaced)); +} + +WKRect WKBundleNodeHandleGetElementBounds(WKBundleNodeHandleRef elementHandleRef) +{ + return toAPI(toImpl(elementHandleRef)->elementBounds()); +} + +void WKBundleNodeHandleSetHTMLInputElementValueForUser(WKBundleNodeHandleRef htmlInputElementHandleRef, WKStringRef valueRef) +{ + toImpl(htmlInputElementHandleRef)->setHTMLInputElementValueForUser(toWTFString(valueRef)); +} + +bool WKBundleNodeHandleGetHTMLInputElementAutofilled(WKBundleNodeHandleRef htmlInputElementHandleRef) +{ + return toImpl(htmlInputElementHandleRef)->isHTMLInputElementAutofilled(); +} + +void WKBundleNodeHandleSetHTMLInputElementAutofilled(WKBundleNodeHandleRef htmlInputElementHandleRef, bool filled) +{ + toImpl(htmlInputElementHandleRef)->setHTMLInputElementAutofilled(filled); +} + +bool WKBundleNodeHandleGetHTMLInputElementLastChangeWasUserEdit(WKBundleNodeHandleRef htmlInputElementHandleRef) +{ + return toImpl(htmlInputElementHandleRef)->htmlInputElementLastChangeWasUserEdit(); +} + +bool WKBundleNodeHandleGetHTMLTextAreaElementLastChangeWasUserEdit(WKBundleNodeHandleRef htmlTextAreaElementHandleRef) +{ + return toImpl(htmlTextAreaElementHandleRef)->htmlTextAreaElementLastChangeWasUserEdit(); +} + +WKBundleNodeHandleRef WKBundleNodeHandleCopyHTMLTableCellElementCellAbove(WKBundleNodeHandleRef htmlTableCellElementHandleRef) +{ + RefPtr<InjectedBundleNodeHandle> nodeHandle = toImpl(htmlTableCellElementHandleRef)->htmlTableCellElementCellAbove(); + return toAPI(nodeHandle.release().leakRef()); +} + +WKBundleFrameRef WKBundleNodeHandleCopyDocumentFrame(WKBundleNodeHandleRef documentHandleRef) +{ + RefPtr<WebFrame> frame = toImpl(documentHandleRef)->documentFrame(); + return toAPI(frame.release().leakRef()); +} + +WKBundleFrameRef WKBundleNodeHandleCopyHTMLFrameElementContentFrame(WKBundleNodeHandleRef htmlFrameElementHandleRef) +{ + RefPtr<WebFrame> frame = toImpl(htmlFrameElementHandleRef)->htmlFrameElementContentFrame(); + return toAPI(frame.release().leakRef()); +} + +WKBundleFrameRef WKBundleNodeHandleCopyHTMLIFrameElementContentFrame(WKBundleNodeHandleRef htmlIFrameElementHandleRef) +{ + RefPtr<WebFrame> frame = toImpl(htmlIFrameElementHandleRef)->htmlIFrameElementContentFrame(); + return toAPI(frame.release().leakRef()); +} diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.h new file mode 100644 index 000000000..3cdad1761 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundleNodeHandle_h +#define WKBundleNodeHandle_h + +#include <WebKit2/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKBundleNodeHandleGetTypeID(); + +#ifdef __cplusplus +} +#endif + +#endif /* WKBundleNodeHandle_h */ diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandlePrivate.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandlePrivate.h new file mode 100644 index 000000000..245c56555 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandlePrivate.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundleNodeHandlePrivate_h +#define WKBundleNodeHandlePrivate_h + +#include <JavaScriptCore/JavaScript.h> +#include <WebKit2/WKBase.h> +#include <WebKit2/WKGeometry.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKBundleNodeHandleRef WKBundleNodeHandleCreate(JSContextRef context, JSObjectRef object); + +/* Convenience Operations */ +WK_EXPORT WKBundleNodeHandleRef WKBundleNodeHandleCopyDocument(WKBundleNodeHandleRef nodeHandle); + + +/* Additional DOM Operations */ + +WK_EXPORT WKRect WKBundleNodeHandleGetRenderRect(WKBundleNodeHandleRef nodeHandle, bool* isReplaced); + +/* Element Specific Operations */ +WK_EXPORT WKRect WKBundleNodeHandleGetElementBounds(WKBundleNodeHandleRef elementHandle); + +/* HTMLInputElement Specific Operations */ +WK_EXPORT void WKBundleNodeHandleSetHTMLInputElementValueForUser(WKBundleNodeHandleRef htmlInputElementHandle, WKStringRef value); +WK_EXPORT bool WKBundleNodeHandleGetHTMLInputElementAutofilled(WKBundleNodeHandleRef htmlInputElementHandle); +WK_EXPORT void WKBundleNodeHandleSetHTMLInputElementAutofilled(WKBundleNodeHandleRef htmlInputElementHandle, bool filled); +WK_EXPORT bool WKBundleNodeHandleGetHTMLInputElementLastChangeWasUserEdit(WKBundleNodeHandleRef htmlInputElementHandle); + +/* HTMLTextAreaElement Specific Operations */ +WK_EXPORT bool WKBundleNodeHandleGetHTMLTextAreaElementLastChangeWasUserEdit(WKBundleNodeHandleRef htmlTextAreaElementHandle); + +/* HTMLTableCellElement Specific Operations */ +WK_EXPORT WKBundleNodeHandleRef WKBundleNodeHandleCopyHTMLTableCellElementCellAbove(WKBundleNodeHandleRef htmlTableCellElementHandle); + +/* Document Specific Operations */ +WK_EXPORT WKBundleFrameRef WKBundleNodeHandleCopyDocumentFrame(WKBundleNodeHandleRef documentHandle); + +/* HTMLFrameElement Specific Operations */ +WK_EXPORT WKBundleFrameRef WKBundleNodeHandleCopyHTMLFrameElementContentFrame(WKBundleNodeHandleRef htmlFrameElementHandle); + +/* HTMLIFrameElement Specific Operations */ +WK_EXPORT WKBundleFrameRef WKBundleNodeHandleCopyHTMLIFrameElementContentFrame(WKBundleNodeHandleRef htmlIFrameElementHandle); + +#ifdef __cplusplus +} +#endif + +#endif /* WKBundleNodeHandlePrivate_h */ diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp new file mode 100644 index 000000000..97347f2f9 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.cpp @@ -0,0 +1,374 @@ +/* + * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKBundlePage.h" +#include "WKBundlePagePrivate.h" + +#include "InjectedBundleBackForwardList.h" +#include "InjectedBundleNodeHandle.h" +#include "WKAPICast.h" +#include "WKBundleAPICast.h" +#include "WebFullScreenManager.h" +#include "WebImage.h" +#include "WebPage.h" +#include "WebURL.h" +#include "WebURLRequest.h" + +#include <WebCore/AXObjectCache.h> +#include <WebCore/AccessibilityObject.h> +#include <WebCore/Frame.h> +#include <WebCore/KURL.h> +#include <WebCore/Page.h> + +using namespace WebKit; + +WKTypeID WKBundlePageGetTypeID() +{ + return toAPI(WebPage::APIType); +} + +void WKBundlePageSetContextMenuClient(WKBundlePageRef pageRef, WKBundlePageContextMenuClient* wkClient) +{ + toImpl(pageRef)->initializeInjectedBundleContextMenuClient(wkClient); +} + +void WKBundlePageSetEditorClient(WKBundlePageRef pageRef, WKBundlePageEditorClient* wkClient) +{ + toImpl(pageRef)->initializeInjectedBundleEditorClient(wkClient); +} + +void WKBundlePageSetFormClient(WKBundlePageRef pageRef, WKBundlePageFormClient* wkClient) +{ + toImpl(pageRef)->initializeInjectedBundleFormClient(wkClient); +} + +void WKBundlePageSetPageLoaderClient(WKBundlePageRef pageRef, WKBundlePageLoaderClient* wkClient) +{ + toImpl(pageRef)->initializeInjectedBundleLoaderClient(wkClient); +} + +void WKBundlePageSetResourceLoadClient(WKBundlePageRef pageRef, WKBundlePageResourceLoadClient* wkClient) +{ + toImpl(pageRef)->initializeInjectedBundleResourceLoadClient(wkClient); +} + +void WKBundlePageSetPolicyClient(WKBundlePageRef pageRef, WKBundlePagePolicyClient* wkClient) +{ + toImpl(pageRef)->initializeInjectedBundlePolicyClient(wkClient); +} + +void WKBundlePageSetUIClient(WKBundlePageRef pageRef, WKBundlePageUIClient* wkClient) +{ + toImpl(pageRef)->initializeInjectedBundleUIClient(wkClient); +} + +void WKBundlePageSetFullScreenClient(WKBundlePageRef pageRef, WKBundlePageFullScreenClient* wkClient) +{ +#if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API + toImpl(pageRef)->initializeInjectedBundleFullScreenClient(wkClient); +#endif +} + +void WKBundlePageWillEnterFullScreen(WKBundlePageRef pageRef) +{ +#if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API + toImpl(pageRef)->fullScreenManager()->willEnterFullScreen(); +#endif +} + +void WKBundlePageDidEnterFullScreen(WKBundlePageRef pageRef) +{ +#if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API + toImpl(pageRef)->fullScreenManager()->didEnterFullScreen(); +#endif +} + +void WKBundlePageWillExitFullScreen(WKBundlePageRef pageRef) +{ +#if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API + toImpl(pageRef)->fullScreenManager()->willExitFullScreen(); +#endif +} + +void WKBundlePageDidExitFullScreen(WKBundlePageRef pageRef) +{ +#if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API + toImpl(pageRef)->fullScreenManager()->didExitFullScreen(); +#endif +} + +WKBundlePageGroupRef WKBundlePageGetPageGroup(WKBundlePageRef pageRef) +{ + return toAPI(toImpl(pageRef)->pageGroup()); +} + +WKBundleFrameRef WKBundlePageGetMainFrame(WKBundlePageRef pageRef) +{ + return toAPI(toImpl(pageRef)->mainWebFrame()); +} + +void* WKAccessibilityRootObject(WKBundlePageRef pageRef) +{ +#if HAVE(ACCESSIBILITY) + if (!pageRef) + return 0; + + WebCore::Page* page = toImpl(pageRef)->corePage(); + if (!page) + return 0; + + WebCore::Frame* core = page->mainFrame(); + if (!core || !core->document()) + return 0; + + WebCore::AXObjectCache::enableAccessibility(); + + WebCore::AccessibilityObject* root = core->document()->axObjectCache()->rootObject(); + if (!root) + return 0; + + return root->wrapper(); +#else + return 0; +#endif +} + +void* WKAccessibilityFocusedObject(WKBundlePageRef pageRef) +{ +#if HAVE(ACCESSIBILITY) + if (!pageRef) + return 0; + + WebCore::Page* page = toImpl(pageRef)->corePage(); + if (!page) + return 0; + + WebCore::AXObjectCache::enableAccessibility(); + + WebCore::AccessibilityObject* focusedObject = WebCore::AXObjectCache::focusedUIElementForPage(page); + if (!focusedObject) + return 0; + + return focusedObject->wrapper(); +#else + return 0; +#endif +} + +void WKBundlePageStopLoading(WKBundlePageRef pageRef) +{ + toImpl(pageRef)->stopLoading(); +} + +void WKBundlePageSetDefersLoading(WKBundlePageRef pageRef, bool defersLoading) +{ + toImpl(pageRef)->setDefersLoading(defersLoading); +} + +WKStringRef WKBundlePageCopyRenderTreeExternalRepresentation(WKBundlePageRef pageRef) +{ + return toCopiedAPI(toImpl(pageRef)->renderTreeExternalRepresentation()); +} + +void WKBundlePageExecuteEditingCommand(WKBundlePageRef pageRef, WKStringRef name, WKStringRef argument) +{ + toImpl(pageRef)->executeEditingCommand(toImpl(name)->string(), toImpl(argument)->string()); +} + +bool WKBundlePageIsEditingCommandEnabled(WKBundlePageRef pageRef, WKStringRef name) +{ + return toImpl(pageRef)->isEditingCommandEnabled(toImpl(name)->string()); +} + +void WKBundlePageClearMainFrameName(WKBundlePageRef pageRef) +{ + toImpl(pageRef)->clearMainFrameName(); +} + +void WKBundlePageClose(WKBundlePageRef pageRef) +{ + toImpl(pageRef)->sendClose(); +} + +double WKBundlePageGetTextZoomFactor(WKBundlePageRef pageRef) +{ + return toImpl(pageRef)->textZoomFactor(); +} + +void WKBundlePageSetTextZoomFactor(WKBundlePageRef pageRef, double zoomFactor) +{ + toImpl(pageRef)->setTextZoomFactor(zoomFactor); +} + +double WKBundlePageGetPageZoomFactor(WKBundlePageRef pageRef) +{ + return toImpl(pageRef)->pageZoomFactor(); +} + +void WKBundlePageSetPageZoomFactor(WKBundlePageRef pageRef, double zoomFactor) +{ + toImpl(pageRef)->setPageZoomFactor(zoomFactor); +} + +void WKBundlePageSetScaleAtOrigin(WKBundlePageRef pageRef, double scale, WKPoint origin) +{ + toImpl(pageRef)->scalePage(scale, toIntPoint(origin)); +} + +WKBundleBackForwardListRef WKBundlePageGetBackForwardList(WKBundlePageRef pageRef) +{ + return toAPI(toImpl(pageRef)->backForwardList()); +} + +void WKBundlePageSetUnderlayPage(WKBundlePageRef pageRef, WKBundlePageRef pageUnderlayRef) +{ + toImpl(pageRef)->setUnderlayPage(toImpl(pageUnderlayRef)); +} + +void WKBundlePageInstallPageOverlay(WKBundlePageRef pageRef, WKBundlePageOverlayRef pageOverlayRef) +{ + toImpl(pageRef)->installPageOverlay(toImpl(pageOverlayRef)); +} + +void WKBundlePageUninstallPageOverlay(WKBundlePageRef pageRef, WKBundlePageOverlayRef pageOverlayRef) +{ + toImpl(pageRef)->uninstallPageOverlay(toImpl(pageOverlayRef), false); +} + +bool WKBundlePageHasLocalDataForURL(WKBundlePageRef pageRef, WKURLRef urlRef) +{ + return toImpl(pageRef)->hasLocalDataForURL(WebCore::KURL(WebCore::KURL(), toImpl(urlRef)->string())); +} + +bool WKBundlePageCanHandleRequest(WKURLRequestRef requestRef) +{ + return WebPage::canHandleRequest(toImpl(requestRef)->resourceRequest()); +} + +bool WKBundlePageFindString(WKBundlePageRef pageRef, WKStringRef target, WKFindOptions findOptions) +{ + return toImpl(pageRef)->findStringFromInjectedBundle(toImpl(target)->string(), toFindOptions(findOptions)); +} + +WKImageRef WKBundlePageCreateSnapshotInViewCoordinates(WKBundlePageRef pageRef, WKRect rect, WKImageOptions options) +{ + RefPtr<WebImage> webImage = toImpl(pageRef)->snapshotInViewCoordinates(toIntRect(rect), toImageOptions(options)); + return toAPI(webImage.release().leakRef()); +} + +WKImageRef WKBundlePageCreateSnapshotInDocumentCoordinates(WKBundlePageRef pageRef, WKRect rect, WKImageOptions options) +{ + RefPtr<WebImage> webImage = toImpl(pageRef)->snapshotInDocumentCoordinates(toIntRect(rect), toImageOptions(options)); + return toAPI(webImage.release().leakRef()); +} + +WKImageRef WKBundlePageCreateScaledSnapshotInDocumentCoordinates(WKBundlePageRef pageRef, WKRect rect, double scaleFactor, WKImageOptions options) +{ + RefPtr<WebImage> webImage = toImpl(pageRef)->scaledSnapshotInDocumentCoordinates(toIntRect(rect), scaleFactor, toImageOptions(options)); + return toAPI(webImage.release().leakRef()); +} + +double WKBundlePageGetBackingScaleFactor(WKBundlePageRef pageRef) +{ + return toImpl(pageRef)->deviceScaleFactor(); +} + +#if defined(ENABLE_INSPECTOR) && ENABLE_INSPECTOR +WKBundleInspectorRef WKBundlePageGetInspector(WKBundlePageRef pageRef) +{ + return toAPI(toImpl(pageRef)->inspector()); +} +#endif + +void WKBundlePageForceRepaint(WKBundlePageRef page) +{ + toImpl(page)->forceRepaintWithoutCallback(); +} + +void WKBundlePageSimulateMouseDown(WKBundlePageRef page, int button, WKPoint position, int clickCount, WKEventModifiers modifiers, double time) +{ + toImpl(page)->simulateMouseDown(button, toIntPoint(position), clickCount, modifiers, time); +} + +void WKBundlePageSimulateMouseUp(WKBundlePageRef page, int button, WKPoint position, int clickCount, WKEventModifiers modifiers, double time) +{ + toImpl(page)->simulateMouseUp(button, toIntPoint(position), clickCount, modifiers, time); +} + +void WKBundlePageSimulateMouseMotion(WKBundlePageRef page, WKPoint position, double time) +{ + toImpl(page)->simulateMouseMotion(toIntPoint(position), time); +} + +uint64_t WKBundlePageGetRenderTreeSize(WKBundlePageRef pageRef) +{ + return toImpl(pageRef)->renderTreeSize(); +} + +void WKBundlePageSetTracksRepaints(WKBundlePageRef pageRef, bool trackRepaints) +{ + toImpl(pageRef)->setTracksRepaints(trackRepaints); +} + +bool WKBundlePageIsTrackingRepaints(WKBundlePageRef pageRef) +{ + return toImpl(pageRef)->isTrackingRepaints(); +} + +void WKBundlePageResetTrackedRepaints(WKBundlePageRef pageRef) +{ + toImpl(pageRef)->resetTrackedRepaints(); +} + +WKArrayRef WKBundlePageCopyTrackedRepaintRects(WKBundlePageRef pageRef) +{ + return toAPI(toImpl(pageRef)->trackedRepaintRects().leakRef()); +} + +WKStringRef WKBundlePageViewportConfigurationAsText(WKBundlePageRef pageRef, int deviceDPI, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight) +{ + return toCopiedAPI(toImpl(pageRef)->viewportConfigurationAsText(deviceDPI, deviceWidth, deviceHeight, availableWidth, availableHeight)); +} + +void WKBundlePageSetComposition(WKBundlePageRef pageRef, WKStringRef text, int from, int length) +{ + toImpl(pageRef)->setCompositionForTesting(toImpl(text)->string(), from, length); +} + +bool WKBundlePageHasComposition(WKBundlePageRef pageRef) +{ + return toImpl(pageRef)->hasCompositionForTesting(); +} + +void WKBundlePageConfirmComposition(WKBundlePageRef pageRef) +{ + toImpl(pageRef)->confirmCompositionForTesting(String()); +} + +void WKBundlePageConfirmCompositionWithText(WKBundlePageRef pageRef, WKStringRef text) +{ + toImpl(pageRef)->confirmCompositionForTesting(toImpl(text)->string()); +} diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.h new file mode 100644 index 000000000..7da8d0a3d --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePage.h @@ -0,0 +1,354 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundlePage_h +#define WKBundlePage_h + +#include <WebKit2/WKBase.h> +#include <WebKit2/WKEvent.h> +#include <WebKit2/WKFindOptions.h> +#include <WebKit2/WKImage.h> +#include <WebKit2/WKPageLoadTypes.h> + +#ifndef __cplusplus +#include <stdbool.h> +#endif + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + kWKInsertActionTyped = 0, + kWKInsertActionPasted = 1, + kWKInsertActionDropped = 2 +}; +typedef uint32_t WKInsertActionType; + +enum { + kWKAffinityUpstream, + kWKAffinityDownstream +}; +typedef uint32_t WKAffinityType; + +enum { + WKInputFieldActionTypeMoveUp, + WKInputFieldActionTypeMoveDown, + WKInputFieldActionTypeCancel, + WKInputFieldActionTypeInsertTab, + WKInputFieldActionTypeInsertBacktab, + WKInputFieldActionTypeInsertNewline, + WKInputFieldActionTypeInsertDelete +}; +typedef uint32_t WKInputFieldActionType; + +enum { + WKFullScreenNoKeyboard, + WKFullScreenKeyboard, +}; +typedef uint32_t WKFullScreenKeyboardRequestType; + +enum { + WKScrollDirectionLeft, + WKScrollDirectionRight +}; +typedef uint32_t WKScrollDirection; + +// Loader Client +typedef void (*WKBundlePageDidStartProvisionalLoadForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidReceiveServerRedirectForProvisionalLoadForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidFailProvisionalLoadWithErrorForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKErrorRef error, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidCommitLoadForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidDocumentFinishLoadForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidFinishLoadForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidFinishDocumentLoadForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidFailLoadWithErrorForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKErrorRef error, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidSameDocumentNavigationForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKSameDocumentNavigationType type, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidReceiveTitleForFrameCallback)(WKBundlePageRef page, WKStringRef title, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidRemoveFrameFromHierarchyCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidDisplayInsecureContentForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidRunInsecureContentForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidDetectXSSForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidFirstLayoutForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidFirstVisuallyNonEmptyLayoutForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidLayoutForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, const void* clientInfo); +typedef void (*WKBundlePageDidClearWindowObjectForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKBundleScriptWorldRef world, const void *clientInfo); +typedef void (*WKBundlePageDidCancelClientRedirectForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo); +typedef void (*WKBundlePageWillPerformClientRedirectForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKURLRef url, double delay, double date, const void *clientInfo); +typedef void (*WKBundlePageDidHandleOnloadEventsForFrameCallback)(WKBundlePageRef page, WKBundleFrameRef frame, const void *clientInfo); + +struct WKBundlePageLoaderClient { + int version; + const void * clientInfo; + + // Version 0. + WKBundlePageDidStartProvisionalLoadForFrameCallback didStartProvisionalLoadForFrame; + WKBundlePageDidReceiveServerRedirectForProvisionalLoadForFrameCallback didReceiveServerRedirectForProvisionalLoadForFrame; + WKBundlePageDidFailProvisionalLoadWithErrorForFrameCallback didFailProvisionalLoadWithErrorForFrame; + WKBundlePageDidCommitLoadForFrameCallback didCommitLoadForFrame; + WKBundlePageDidFinishDocumentLoadForFrameCallback didFinishDocumentLoadForFrame; + WKBundlePageDidFinishLoadForFrameCallback didFinishLoadForFrame; + WKBundlePageDidFailLoadWithErrorForFrameCallback didFailLoadWithErrorForFrame; + WKBundlePageDidSameDocumentNavigationForFrameCallback didSameDocumentNavigationForFrame; + WKBundlePageDidReceiveTitleForFrameCallback didReceiveTitleForFrame; + WKBundlePageDidFirstLayoutForFrameCallback didFirstLayoutForFrame; + WKBundlePageDidFirstVisuallyNonEmptyLayoutForFrameCallback didFirstVisuallyNonEmptyLayoutForFrame; + WKBundlePageDidRemoveFrameFromHierarchyCallback didRemoveFrameFromHierarchy; + WKBundlePageDidDisplayInsecureContentForFrameCallback didDisplayInsecureContentForFrame; + WKBundlePageDidRunInsecureContentForFrameCallback didRunInsecureContentForFrame; + WKBundlePageDidClearWindowObjectForFrameCallback didClearWindowObjectForFrame; + WKBundlePageDidCancelClientRedirectForFrameCallback didCancelClientRedirectForFrame; + WKBundlePageWillPerformClientRedirectForFrameCallback willPerformClientRedirectForFrame; + WKBundlePageDidHandleOnloadEventsForFrameCallback didHandleOnloadEventsForFrame; + + // Version 1. + WKBundlePageDidLayoutForFrameCallback didLayoutForFrame; + WKBundlePageDidDetectXSSForFrameCallback didDetectXSSForFrame; +}; +typedef struct WKBundlePageLoaderClient WKBundlePageLoaderClient; + +enum { kWKBundlePageLoaderClientCurrentVersion = 1 }; + +enum { + WKBundlePagePolicyActionPassThrough, + WKBundlePagePolicyActionUse +}; +typedef uint32_t WKBundlePagePolicyAction; + +// Policy Client +typedef WKBundlePagePolicyAction (*WKBundlePageDecidePolicyForNavigationActionCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKBundleNavigationActionRef navigationAction, WKURLRequestRef request, WKTypeRef* userData, const void* clientInfo); +typedef WKBundlePagePolicyAction (*WKBundlePageDecidePolicyForNewWindowActionCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKBundleNavigationActionRef navigationAction, WKURLRequestRef request, WKStringRef frameName, WKTypeRef* userData, const void* clientInfo); +typedef WKBundlePagePolicyAction (*WKBundlePageDecidePolicyForResponseCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKURLResponseRef response, WKURLRequestRef request, WKTypeRef* userData, const void* clientInfo); +typedef void (*WKBundlePageUnableToImplementPolicyCallback)(WKBundlePageRef page, WKBundleFrameRef frame, WKErrorRef error, WKTypeRef* userData, const void* clientInfo); + +struct WKBundlePagePolicyClient { + int version; + const void * clientInfo; + WKBundlePageDecidePolicyForNavigationActionCallback decidePolicyForNavigationAction; + WKBundlePageDecidePolicyForNewWindowActionCallback decidePolicyForNewWindowAction; + WKBundlePageDecidePolicyForResponseCallback decidePolicyForResponse; + WKBundlePageUnableToImplementPolicyCallback unableToImplementPolicy; +}; +typedef struct WKBundlePagePolicyClient WKBundlePagePolicyClient; + +enum { kWKBundlePagePolicyClientCurrentVersion = 0 }; + +// Resource Load Client +typedef void (*WKBundlePageDidInitiateLoadForResourceCallback)(WKBundlePageRef, WKBundleFrameRef, uint64_t resourceIdentifier, WKURLRequestRef, bool pageIsProvisionallyLoading, const void* clientInfo); +typedef WKURLRequestRef (*WKBundlePageWillSendRequestForFrameCallback)(WKBundlePageRef, WKBundleFrameRef, uint64_t resourceIdentifier, WKURLRequestRef, WKURLResponseRef redirectResponse, const void *clientInfo); +typedef void (*WKBundlePageDidReceiveResponseForResourceCallback)(WKBundlePageRef, WKBundleFrameRef, uint64_t resourceIdentifier, WKURLResponseRef, const void* clientInfo); +typedef void (*WKBundlePageDidReceiveContentLengthForResourceCallback)(WKBundlePageRef, WKBundleFrameRef, uint64_t resourceIdentifier, uint64_t contentLength, const void* clientInfo); +typedef void (*WKBundlePageDidFinishLoadForResourceCallback)(WKBundlePageRef, WKBundleFrameRef, uint64_t resourceIdentifier, const void* clientInfo); +typedef void (*WKBundlePageDidFailLoadForResourceCallback)(WKBundlePageRef, WKBundleFrameRef, uint64_t resourceIdentifier, WKErrorRef, const void* clientInfo); + +struct WKBundlePageResourceLoadClient { + int version; + const void * clientInfo; + WKBundlePageDidInitiateLoadForResourceCallback didInitiateLoadForResource; + + // willSendRequestForFrame is supposed to return a retained reference to the URL request. + WKBundlePageWillSendRequestForFrameCallback willSendRequestForFrame; + + WKBundlePageDidReceiveResponseForResourceCallback didReceiveResponseForResource; + WKBundlePageDidReceiveContentLengthForResourceCallback didReceiveContentLengthForResource; + WKBundlePageDidFinishLoadForResourceCallback didFinishLoadForResource; + WKBundlePageDidFailLoadForResourceCallback didFailLoadForResource; +}; +typedef struct WKBundlePageResourceLoadClient WKBundlePageResourceLoadClient; + +enum { kWKBundlePageResourceLoadClientCurrentVersion = 0 }; + +enum { + WKBundlePageUIElementVisibilityUnknown, + WKBundlePageUIElementVisible, + WKBundlePageUIElementHidden +}; +typedef uint32_t WKBundlePageUIElementVisibility; + +// UI Client +typedef void (*WKBundlePageWillAddMessageToConsoleCallback)(WKBundlePageRef page, WKStringRef message, uint32_t lineNumber, const void *clientInfo); +typedef void (*WKBundlePageWillSetStatusbarTextCallback)(WKBundlePageRef page, WKStringRef statusbarText, const void *clientInfo); +typedef void (*WKBundlePageWillRunJavaScriptAlertCallback)(WKBundlePageRef page, WKStringRef alertText, WKBundleFrameRef frame, const void *clientInfo); +typedef void (*WKBundlePageWillRunJavaScriptConfirmCallback)(WKBundlePageRef page, WKStringRef message, WKBundleFrameRef frame, const void *clientInfo); +typedef void (*WKBundlePageWillRunJavaScriptPromptCallback)(WKBundlePageRef page, WKStringRef message, WKStringRef defaultValue, WKBundleFrameRef frame, const void *clientInfo); +typedef void (*WKBundlePageMouseDidMoveOverElementCallback)(WKBundlePageRef page, WKBundleHitTestResultRef hitTestResult, WKEventModifiers modifiers, WKTypeRef* userData, const void *clientInfo); +typedef void (*WKBundlePageDidScrollCallback)(WKBundlePageRef page, const void *clientInfo); +typedef void (*WKBundlePagePaintCustomOverhangAreaCallback)(WKBundlePageRef page, WKGraphicsContextRef graphicsContext, WKRect horizontalOverhang, WKRect verticalOverhang, WKRect dirtyRect, const void* clientInfo); +typedef WKStringRef (*WKBundlePageGenerateFileForUploadCallback)(WKBundlePageRef page, WKStringRef originalFilePath, const void* clientInfo); +typedef bool (*WKBundlePageShouldRubberBandInDirectionCallback)(WKBundlePageRef page, WKScrollDirection scrollDirection, const void* clientInfo); +typedef WKBundlePageUIElementVisibility (*WKBundlePageStatusBarIsVisibleCallback)(WKBundlePageRef page, const void *clientInfo); +typedef WKBundlePageUIElementVisibility (*WKBundlePageMenuBarIsVisibleCallback)(WKBundlePageRef page, const void *clientInfo); +typedef WKBundlePageUIElementVisibility (*WKBundlePageToolbarsAreVisibleCallback)(WKBundlePageRef page, const void *clientInfo); + +struct WKBundlePageUIClient { + int version; + const void * clientInfo; + WKBundlePageWillAddMessageToConsoleCallback willAddMessageToConsole; + WKBundlePageWillSetStatusbarTextCallback willSetStatusbarText; + WKBundlePageWillRunJavaScriptAlertCallback willRunJavaScriptAlert; + WKBundlePageWillRunJavaScriptConfirmCallback willRunJavaScriptConfirm; + WKBundlePageWillRunJavaScriptPromptCallback willRunJavaScriptPrompt; + WKBundlePageMouseDidMoveOverElementCallback mouseDidMoveOverElement; + WKBundlePageDidScrollCallback pageDidScroll; + WKBundlePagePaintCustomOverhangAreaCallback paintCustomOverhangArea; + WKBundlePageGenerateFileForUploadCallback shouldGenerateFileForUpload; + WKBundlePageGenerateFileForUploadCallback generateFileForUpload; + WKBundlePageShouldRubberBandInDirectionCallback shouldRubberBandInDirection; + WKBundlePageStatusBarIsVisibleCallback statusBarIsVisible; + WKBundlePageMenuBarIsVisibleCallback menuBarIsVisible; + WKBundlePageToolbarsAreVisibleCallback toolbarsAreVisible; +}; +typedef struct WKBundlePageUIClient WKBundlePageUIClient; + +enum { kWKBundlePageUIClientCurrentVersion = 0 }; + +// Editor client +typedef bool (*WKBundlePageShouldBeginEditingCallback)(WKBundlePageRef page, WKBundleRangeHandleRef range, const void* clientInfo); +typedef bool (*WKBundlePageShouldEndEditingCallback)(WKBundlePageRef page, WKBundleRangeHandleRef range, const void* clientInfo); +typedef bool (*WKBundlePageShouldInsertNodeCallback)(WKBundlePageRef page, WKBundleNodeHandleRef node, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType action, const void* clientInfo); +typedef bool (*WKBundlePageShouldInsertTextCallback)(WKBundlePageRef page, WKStringRef string, WKBundleRangeHandleRef rangeToReplace, WKInsertActionType action, const void* clientInfo); +typedef bool (*WKBundlePageShouldDeleteRangeCallback)(WKBundlePageRef page, WKBundleRangeHandleRef range, const void* clientInfo); +typedef bool (*WKBundlePageShouldChangeSelectedRange)(WKBundlePageRef page, WKBundleRangeHandleRef fromRange, WKBundleRangeHandleRef toRange, WKAffinityType affinity, bool stillSelecting, const void* clientInfo); +typedef bool (*WKBundlePageShouldApplyStyle)(WKBundlePageRef page, WKBundleCSSStyleDeclarationRef style, WKBundleRangeHandleRef range, const void* clientInfo); +typedef void (*WKBundlePageEditingNotification)(WKBundlePageRef page, WKStringRef notificationName, const void* clientInfo); + +struct WKBundlePageEditorClient { + int version; + const void * clientInfo; + WKBundlePageShouldBeginEditingCallback shouldBeginEditing; + WKBundlePageShouldEndEditingCallback shouldEndEditing; + WKBundlePageShouldInsertNodeCallback shouldInsertNode; + WKBundlePageShouldInsertTextCallback shouldInsertText; + WKBundlePageShouldDeleteRangeCallback shouldDeleteRange; + WKBundlePageShouldChangeSelectedRange shouldChangeSelectedRange; + WKBundlePageShouldApplyStyle shouldApplyStyle; + WKBundlePageEditingNotification didBeginEditing; + WKBundlePageEditingNotification didEndEditing; + WKBundlePageEditingNotification didChange; + WKBundlePageEditingNotification didChangeSelection; +}; +typedef struct WKBundlePageEditorClient WKBundlePageEditorClient; + +enum { kWKBundlePageEditorClientCurrentVersion = 0 }; + +// Form client +typedef void (*WKBundlePageTextFieldDidBeginEditingCallback)(WKBundlePageRef page, WKBundleNodeHandleRef htmlInputElementHandle, WKBundleFrameRef frame, const void* clientInfo); +typedef void (*WKBundlePageTextFieldDidEndEditingCallback)(WKBundlePageRef page, WKBundleNodeHandleRef htmlInputElementHandle, WKBundleFrameRef frame, const void* clientInfo); +typedef void (*WKBundlePageTextDidChangeInTextFieldCallback)(WKBundlePageRef page, WKBundleNodeHandleRef htmlInputElementHandle, WKBundleFrameRef frame, const void* clientInfo); +typedef void (*WKBundlePageTextDidChangeInTextAreaCallback)(WKBundlePageRef page, WKBundleNodeHandleRef htmlTextAreaElementHandle, WKBundleFrameRef frame, const void* clientInfo); +typedef bool (*WKBundlePageShouldPerformActionInTextFieldCallback)(WKBundlePageRef page, WKBundleNodeHandleRef htmlInputElementHandle, WKInputFieldActionType actionType, WKBundleFrameRef frame, const void* clientInfo); +typedef void (*WKBundlePageWillSubmitFormCallback)(WKBundlePageRef page, WKBundleNodeHandleRef htmlFormElementHandle, WKBundleFrameRef frame, WKBundleFrameRef sourceFrame, WKDictionaryRef values, WKTypeRef* userData, const void* clientInfo); + +struct WKBundlePageFormClient { + int version; + const void * clientInfo; + WKBundlePageTextFieldDidBeginEditingCallback textFieldDidBeginEditing; + WKBundlePageTextFieldDidEndEditingCallback textFieldDidEndEditing; + WKBundlePageTextDidChangeInTextFieldCallback textDidChangeInTextField; + WKBundlePageTextDidChangeInTextAreaCallback textDidChangeInTextArea; + WKBundlePageShouldPerformActionInTextFieldCallback shouldPerformActionInTextField; + WKBundlePageWillSubmitFormCallback willSubmitForm; +}; +typedef struct WKBundlePageFormClient WKBundlePageFormClient; + +enum { kWKBundlePageFormClientCurrentVersion = 0 }; + +// ContextMenu client +typedef void (*WKBundlePageGetContextMenuFromDefaultContextMenuCallback)(WKBundlePageRef page, WKBundleHitTestResultRef hitTestResult, WKArrayRef defaultMenu, WKArrayRef* newMenu, WKTypeRef* userData, const void* clientInfo); + +struct WKBundlePageContextMenuClient { + int version; + const void * clientInfo; + WKBundlePageGetContextMenuFromDefaultContextMenuCallback getContextMenuFromDefaultMenu; +}; +typedef struct WKBundlePageContextMenuClient WKBundlePageContextMenuClient; + +enum { kWKBundlePageContextMenuClientCurrentVersion = 0 }; + +// Full Screen client +typedef bool (*WKBundlePageSupportsFullScreen)(WKBundlePageRef page, WKFullScreenKeyboardRequestType requestType); +typedef void (*WKBundlePageEnterFullScreenForElement)(WKBundlePageRef page, WKBundleNodeHandleRef element); +typedef void (*WKBundlePageExitFullScreenForElement)(WKBundlePageRef page, WKBundleNodeHandleRef element); + +struct WKBundlePageFullScreenClient { + int version; + const void * clientInfo; + WKBundlePageSupportsFullScreen supportsFullScreen; + WKBundlePageEnterFullScreenForElement enterFullScreenForElement; + WKBundlePageExitFullScreenForElement exitFullScreenForElement; +}; +typedef struct WKBundlePageFullScreenClient WKBundlePageFullScreenClient; + +enum { kWKBundlePageFullScreenClientCurrentVersion = 0 }; + +WK_EXPORT void WKBundlePageWillEnterFullScreen(WKBundlePageRef page); +WK_EXPORT void WKBundlePageDidEnterFullScreen(WKBundlePageRef page); +WK_EXPORT void WKBundlePageWillExitFullScreen(WKBundlePageRef page); +WK_EXPORT void WKBundlePageDidExitFullScreen(WKBundlePageRef page); + +WK_EXPORT WKTypeID WKBundlePageGetTypeID(); + +WK_EXPORT void WKBundlePageSetContextMenuClient(WKBundlePageRef page, WKBundlePageContextMenuClient* client); +WK_EXPORT void WKBundlePageSetEditorClient(WKBundlePageRef page, WKBundlePageEditorClient* client); +WK_EXPORT void WKBundlePageSetFormClient(WKBundlePageRef page, WKBundlePageFormClient* client); +WK_EXPORT void WKBundlePageSetPageLoaderClient(WKBundlePageRef page, WKBundlePageLoaderClient* client); +WK_EXPORT void WKBundlePageSetResourceLoadClient(WKBundlePageRef page, WKBundlePageResourceLoadClient* client); +WK_EXPORT void WKBundlePageSetPolicyClient(WKBundlePageRef page, WKBundlePagePolicyClient* client); +WK_EXPORT void WKBundlePageSetUIClient(WKBundlePageRef page, WKBundlePageUIClient* client); + +WK_EXPORT void WKBundlePageSetFullScreenClient(WKBundlePageRef page, WKBundlePageFullScreenClient* client); + +WK_EXPORT WKBundlePageGroupRef WKBundlePageGetPageGroup(WKBundlePageRef page); +WK_EXPORT WKBundleFrameRef WKBundlePageGetMainFrame(WKBundlePageRef page); + +WK_EXPORT WKBundleBackForwardListRef WKBundlePageGetBackForwardList(WKBundlePageRef page); + +WK_EXPORT void WKBundlePageSetUnderlayPage(WKBundlePageRef page, WKBundlePageRef pageUnderlay); + +WK_EXPORT void WKBundlePageInstallPageOverlay(WKBundlePageRef page, WKBundlePageOverlayRef pageOverlay); +WK_EXPORT void WKBundlePageUninstallPageOverlay(WKBundlePageRef page, WKBundlePageOverlayRef pageOverlay); + +WK_EXPORT bool WKBundlePageHasLocalDataForURL(WKBundlePageRef page, WKURLRef url); +WK_EXPORT bool WKBundlePageCanHandleRequest(WKURLRequestRef request); + +WK_EXPORT bool WKBundlePageFindString(WKBundlePageRef page, WKStringRef target, WKFindOptions findOptions); + +WK_EXPORT WKImageRef WKBundlePageCreateSnapshotInViewCoordinates(WKBundlePageRef page, WKRect rect, WKImageOptions options); +WK_EXPORT WKImageRef WKBundlePageCreateSnapshotInDocumentCoordinates(WKBundlePageRef page, WKRect rect, WKImageOptions options); +WK_EXPORT WKImageRef WKBundlePageCreateScaledSnapshotInDocumentCoordinates(WKBundlePageRef page, WKRect rect, double scaleFactor, WKImageOptions options); + +WK_EXPORT double WKBundlePageGetBackingScaleFactor(WKBundlePageRef page); + +#if defined(ENABLE_INSPECTOR) && ENABLE_INSPECTOR +WK_EXPORT WKBundleInspectorRef WKBundlePageGetInspector(WKBundlePageRef page); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* WKBundlePage_h */ diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageGroup.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageGroup.cpp new file mode 100644 index 000000000..e076cb97f --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageGroup.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKBundlePageGroup.h" + +#include "WKAPICast.h" +#include "WKBundleAPICast.h" +#include "WebPageGroupProxy.h" + +using namespace WebKit; + +WKTypeID WKBundlePageGroupGetTypeID() +{ + return toAPI(WebPageGroupProxy::APIType); +} + +WKStringRef WKBundlePageGroupCopyIdentifier(WKBundlePageGroupRef bundlePageGroup) +{ + return toCopiedAPI(toImpl(bundlePageGroup)->identifier()); +} diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageGroup.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageGroup.h new file mode 100644 index 000000000..e0bf64525 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageGroup.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundlePageGroup_h +#define WKBundlePageGroup_h + +#include <WebKit2/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKBundlePageGroupGetTypeID(); + +WK_EXPORT WKStringRef WKBundlePageGroupCopyIdentifier(WKBundlePageGroupRef bundlePageGroup); + +#ifdef __cplusplus +} +#endif + +#endif /* WKBundlePageGroup_h */ diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageOverlay.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageOverlay.cpp new file mode 100644 index 000000000..4364ce97c --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageOverlay.cpp @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKBundlePageOverlay.h" + +#include "PageOverlay.h" +#include "WKAPICast.h" +#include "WKBundleAPICast.h" +#include <WebCore/GraphicsContext.h> +#include <wtf/PassOwnPtr.h> + +using namespace WebCore; +using namespace WebKit; + +class PageOverlayClientImpl : public PageOverlay::Client { +public: + static PassOwnPtr<PageOverlayClientImpl> create(WKBundlePageOverlayClient* client) + { + return adoptPtr(new PageOverlayClientImpl(client)); + } + +private: + explicit PageOverlayClientImpl(WKBundlePageOverlayClient* client) + : m_client() + { + if (client) + m_client = *client; + } + + // PageOverlay::Client. + virtual void pageOverlayDestroyed(PageOverlay*) + { + delete this; + } + + virtual void willMoveToWebPage(PageOverlay* pageOverlay, WebPage* page) + { + if (!m_client.willMoveToPage) + return; + + m_client.willMoveToPage(toAPI(pageOverlay), toAPI(page), m_client.clientInfo); + } + + virtual void didMoveToWebPage(PageOverlay* pageOverlay, WebPage* page) + { + if (!m_client.didMoveToPage) + return; + + m_client.didMoveToPage(toAPI(pageOverlay), toAPI(page), m_client.clientInfo); + } + + virtual void drawRect(PageOverlay* pageOverlay, GraphicsContext& graphicsContext, const IntRect& dirtyRect) + { + if (!m_client.drawRect) + return; + + m_client.drawRect(toAPI(pageOverlay), graphicsContext.platformContext(), toAPI(dirtyRect), m_client.clientInfo); + } + + virtual bool mouseEvent(PageOverlay* pageOverlay, const WebMouseEvent& event) + { + switch (event.type()) { + case WebEvent::MouseDown: { + if (!m_client.mouseDown) + return false; + + return m_client.mouseDown(toAPI(pageOverlay), toAPI(event.position()), toAPI(event.button()), m_client.clientInfo); + } + case WebEvent::MouseUp: { + if (!m_client.mouseUp) + return false; + + return m_client.mouseUp(toAPI(pageOverlay), toAPI(event.position()), toAPI(event.button()), m_client.clientInfo); + } + case WebEvent::MouseMove: { + if (event.button() == WebMouseEvent::NoButton) { + if (!m_client.mouseMoved) + return false; + + return m_client.mouseMoved(toAPI(pageOverlay), toAPI(event.position()), m_client.clientInfo); + } + + // This is a MouseMove event with a mouse button pressed. Call mouseDragged. + if (!m_client.mouseDragged) + return false; + + return m_client.mouseDragged(toAPI(pageOverlay), toAPI(event.position()), toAPI(event.button()), m_client.clientInfo); + } + + default: + return false; + } + } + + WKBundlePageOverlayClient m_client; +}; + +WKTypeID WKBundlePageOverlayGetTypeID() +{ + return toAPI(PageOverlay::APIType); +} + +WKBundlePageOverlayRef WKBundlePageOverlayCreate(WKBundlePageOverlayClient* wkClient) +{ + if (wkClient && wkClient->version) + return 0; + + OwnPtr<PageOverlayClientImpl> clientImpl = PageOverlayClientImpl::create(wkClient); + + return toAPI(PageOverlay::create(clientImpl.leakPtr()).leakRef()); +} + +void WKBundlePageOverlaySetNeedsDisplay(WKBundlePageOverlayRef bundlePageOverlayRef, WKRect rect) +{ + toImpl(bundlePageOverlayRef)->setNeedsDisplay(enclosingIntRect(toFloatRect(rect))); +} + +float WKBundlePageOverlayFractionFadedIn(WKBundlePageOverlayRef bundlePageOverlayRef) +{ + return toImpl(bundlePageOverlayRef)->fractionFadedIn(); +} diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageOverlay.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageOverlay.h new file mode 100644 index 000000000..eeb20c902 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePageOverlay.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundlePageOverlay_h +#define WKBundlePageOverlay_h + +#include <WebKit2/WKBase.h> +#include <WebKit2/WKEvent.h> +#include <WebKit2/WKGeometry.h> + +#ifndef __cplusplus +#include <stdbool.h> +#endif + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +// Page overlay client. +typedef void (*WKBundlePageOverlayWillMoveToPageCallback)(WKBundlePageOverlayRef pageOverlay, WKBundlePageRef page, const void* clientInfo); +typedef void (*WKBundlePageOverlayDidMoveToPageCallback)(WKBundlePageOverlayRef pageOverlay, WKBundlePageRef page, const void* clientInfo); +typedef void (*WKBundlePageOverlayDrawRectCallback)(WKBundlePageOverlayRef pageOverlay, void* graphicsContext, WKRect dirtyRect, const void* clientInfo); +typedef bool (*WKBundlePageOverlayMouseDownCallback)(WKBundlePageOverlayRef pageOverlay, WKPoint position, WKEventMouseButton mouseButton, const void* clientInfo); +typedef bool (*WKBundlePageOverlayMouseUpCallback)(WKBundlePageOverlayRef pageOverlay, WKPoint position, WKEventMouseButton mouseButton, const void* clientInfo); +typedef bool (*WKBundlePageOverlayMouseMovedCallback)(WKBundlePageOverlayRef pageOverlay, WKPoint position, const void* clientInfo); +typedef bool (*WKBundlePageOverlayMouseDraggedCallback)(WKBundlePageOverlayRef pageOverlay, WKPoint position, WKEventMouseButton mouseButton, const void* clientInfo); + +struct WKBundlePageOverlayClient { + int version; + const void * clientInfo; + WKBundlePageOverlayWillMoveToPageCallback willMoveToPage; + WKBundlePageOverlayDidMoveToPageCallback didMoveToPage; + WKBundlePageOverlayDrawRectCallback drawRect; + WKBundlePageOverlayMouseDownCallback mouseDown; + WKBundlePageOverlayMouseUpCallback mouseUp; + WKBundlePageOverlayMouseMovedCallback mouseMoved; + WKBundlePageOverlayMouseDraggedCallback mouseDragged; +}; +typedef struct WKBundlePageOverlayClient WKBundlePageOverlayClient; + +enum { kWKBundlePageOverlayClientCurrentVersion = 0 }; + +WK_EXPORT WKTypeID WKBundlePageOverlayGetTypeID(); + +WK_EXPORT WKBundlePageOverlayRef WKBundlePageOverlayCreate(WKBundlePageOverlayClient* client); +WK_EXPORT void WKBundlePageOverlaySetNeedsDisplay(WKBundlePageOverlayRef bundlePageOverlay, WKRect rect); +WK_EXPORT float WKBundlePageOverlayFractionFadedIn(WKBundlePageOverlayRef bundlePageOverlay); + +#ifdef __cplusplus +} +#endif + +#endif // WKBundlePageOverlay_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h new file mode 100644 index 000000000..73351b9fe --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePagePrivate.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundlePagePrivate_h +#define WKBundlePagePrivate_h + +#include <WebKit2/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT void WKBundlePageStopLoading(WKBundlePageRef page); +WK_EXPORT void WKBundlePageSetDefersLoading(WKBundlePageRef page, bool defersLoading); +WK_EXPORT bool WKBundlePageIsEditingCommandEnabled(WKBundlePageRef page, WKStringRef commandName); +WK_EXPORT void WKBundlePageClearMainFrameName(WKBundlePageRef page); +WK_EXPORT void WKBundlePageClose(WKBundlePageRef page); +WK_EXPORT WKStringRef WKBundlePageCopyRenderTreeExternalRepresentation(WKBundlePageRef page); +WK_EXPORT void WKBundlePageExecuteEditingCommand(WKBundlePageRef page, WKStringRef commandName, WKStringRef argument); + +WK_EXPORT double WKBundlePageGetTextZoomFactor(WKBundlePageRef page); +WK_EXPORT void WKBundlePageSetTextZoomFactor(WKBundlePageRef page, double zoomFactor); +WK_EXPORT double WKBundlePageGetPageZoomFactor(WKBundlePageRef page); +WK_EXPORT void WKBundlePageSetPageZoomFactor(WKBundlePageRef page, double zoomFactor); + +WK_EXPORT void WKBundlePageSetScaleAtOrigin(WKBundlePageRef page, double scale, WKPoint origin); + +WK_EXPORT void WKBundlePageForceRepaint(WKBundlePageRef page); + +WK_EXPORT void WKBundlePageSimulateMouseDown(WKBundlePageRef page, int button, WKPoint position, int clickCount, WKEventModifiers modifiers, double time); +WK_EXPORT void WKBundlePageSimulateMouseUp(WKBundlePageRef page, int button, WKPoint position, int clickCount, WKEventModifiers modifiers, double time); +WK_EXPORT void WKBundlePageSimulateMouseMotion(WKBundlePageRef page, WKPoint position, double time); + +WK_EXPORT uint64_t WKBundlePageGetRenderTreeSize(WKBundlePageRef page); + +WK_EXPORT void WKBundlePageSetTracksRepaints(WKBundlePageRef page, bool trackRepaints); +WK_EXPORT bool WKBundlePageIsTrackingRepaints(WKBundlePageRef page); +WK_EXPORT void WKBundlePageResetTrackedRepaints(WKBundlePageRef page); +WK_EXPORT WKArrayRef WKBundlePageCopyTrackedRepaintRects(WKBundlePageRef page); + +WK_EXPORT WKStringRef WKBundlePageViewportConfigurationAsText(WKBundlePageRef, int deviceDPI, int deviceWidth, int deviceHeight, int availableWidth, int availableHeight); + +WK_EXPORT void WKBundlePageSetComposition(WKBundlePageRef page, WKStringRef text, int from, int length); +WK_EXPORT bool WKBundlePageHasComposition(WKBundlePageRef page); +WK_EXPORT void WKBundlePageConfirmComposition(WKBundlePageRef page); +WK_EXPORT void WKBundlePageConfirmCompositionWithText(WKBundlePageRef page, WKStringRef text); + +WK_EXPORT void* WKAccessibilityRootObject(WKBundlePageRef); +WK_EXPORT void* WKAccessibilityFocusedObject(WKBundlePageRef); + +#ifdef __cplusplus +} +#endif + +#endif /* WKBundlePagePrivate_h */ diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h new file mode 100644 index 000000000..95ca7ce7e --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundlePrivate.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundlePrivate_h +#define WKBundlePrivate_h + +#include <WebKit2/WKBase.h> + +#ifndef __cplusplus +#include <stdbool.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT void WKBundleSetShouldTrackVisitedLinks(WKBundleRef bundle, bool shouldTrackVisitedLinks); +WK_EXPORT void WKBundleRemoveAllVisitedLinks(WKBundleRef bundle); +WK_EXPORT void WKBundleActivateMacFontAscentHack(WKBundleRef bundle); +WK_EXPORT void WKBundleGarbageCollectJavaScriptObjects(WKBundleRef bundle); +WK_EXPORT void WKBundleGarbageCollectJavaScriptObjectsOnAlternateThreadForDebugging(WKBundleRef bundle, bool waitUntilDone); +WK_EXPORT size_t WKBundleGetJavaScriptObjectsCount(WKBundleRef bundle); + +enum WKUserScriptInjectionTime { + kWKInjectAtDocumentStart, + kWKInjectAtDocumentEnd +}; +typedef enum WKUserScriptInjectionTime WKUserScriptInjectionTime; + +enum WKUserContentInjectedFrames { + kWKInjectInAllFrames, + kWKInjectInTopFrameOnly +}; +typedef enum WKUserContentInjectedFrames WKUserContentInjectedFrames; + +WK_EXPORT void WKBundleAddUserScript(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, WKBundleScriptWorldRef scriptWorld, WKStringRef source, WKURLRef url, WKArrayRef whitelist, WKArrayRef blacklist, WKUserScriptInjectionTime injectionTime, WKUserContentInjectedFrames injectedFrames); +WK_EXPORT void WKBundleAddUserStyleSheet(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, WKBundleScriptWorldRef scriptWorld, WKStringRef source, WKURLRef url, WKArrayRef whitelist, WKArrayRef blacklist, WKUserContentInjectedFrames injectedFrames); +WK_EXPORT void WKBundleRemoveUserScript(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, WKBundleScriptWorldRef scriptWorld, WKURLRef url); +WK_EXPORT void WKBundleRemoveUserStyleSheet(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, WKBundleScriptWorldRef scriptWorld, WKURLRef url); +WK_EXPORT void WKBundleRemoveUserScripts(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, WKBundleScriptWorldRef scriptWorld); +WK_EXPORT void WKBundleRemoveUserStyleSheets(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, WKBundleScriptWorldRef scriptWorld); +WK_EXPORT void WKBundleRemoveAllUserContent(WKBundleRef bundle, WKBundlePageGroupRef pageGroup); + +// Will make WebProcess ignore this preference until a preferences change notification, only for WebKitTestRunner use. +WK_EXPORT void WKBundleOverrideXSSAuditorEnabledForTestRunner(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled); +WK_EXPORT void WKBundleSetAllowUniversalAccessFromFileURLs(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled); +WK_EXPORT void WKBundleSetAllowFileAccessFromFileURLs(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled); +WK_EXPORT void WKBundleSetFrameFlatteningEnabled(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled); +WK_EXPORT void WKBundleSetJavaScriptCanAccessClipboard(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled); +WK_EXPORT void WKBundleSetPrivateBrowsingEnabled(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled); +WK_EXPORT void WKBundleSetAuthorAndUserStylesEnabled(WKBundleRef bundle, WKBundlePageGroupRef pageGroup, bool enabled); +WK_EXPORT void WKBundleClearAllDatabases(WKBundleRef bundle); +WK_EXPORT void WKBundleSetDatabaseQuota(WKBundleRef bundle, uint64_t); +WK_EXPORT void WKBundleClearApplicationCache(WKBundleRef bundle); +WK_EXPORT void WKBundleSetAppCacheMaximumSize(WKBundleRef bundle, uint64_t size); +WK_EXPORT int WKBundleNumberOfPages(WKBundleRef bundle, WKBundleFrameRef frameRef, double pageWidthInPixels, double pageHeightInPixels); +WK_EXPORT int WKBundlePageNumberForElementById(WKBundleRef bundle, WKBundleFrameRef frameRef, WKStringRef idRef, double pageWidthInPixels, double pageHeightInPixels); +WK_EXPORT WKStringRef WKBundlePageSizeAndMarginsInPixels(WKBundleRef bundle, WKBundleFrameRef frameRef, int, int, int, int, int, int, int); +WK_EXPORT bool WKBundleIsPageBoxVisible(WKBundleRef bundle, WKBundleFrameRef frameRef, int); +WK_EXPORT void WKBundleAddOriginAccessWhitelistEntry(WKBundleRef bundle, WKStringRef, WKStringRef, WKStringRef, bool); +WK_EXPORT void WKBundleRemoveOriginAccessWhitelistEntry(WKBundleRef bundle, WKStringRef, WKStringRef, WKStringRef, bool); +WK_EXPORT void WKBundleResetOriginAccessWhitelists(WKBundleRef bundle); + +WK_EXPORT bool WKBundleIsProcessingUserGesture(WKBundleRef bundle); + +WK_EXPORT void WKBundleSwitchNetworkLoaderToNewTestingSession(WKBundleRef bundle); + +#ifdef __cplusplus +} +#endif + +#endif /* WKBundlePrivate_h */ diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandle.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandle.cpp new file mode 100644 index 000000000..c868fab77 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandle.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKBundleRangeHandle.h" + +#include "InjectedBundleRangeHandle.h" +#include "WKAPICast.h" +#include "WKBundleAPICast.h" + +using namespace WebKit; + +WKTypeID WKBundleRangeHandleGetTypeID() +{ + return toAPI(InjectedBundleRangeHandle::APIType); +} diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandle.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandle.h new file mode 100644 index 000000000..8d1d35928 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandle.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundleRangeHandle_h +#define WKBundleRangeHandle_h + +#include <WebKit2/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKBundleRangeHandleGetTypeID(); + +#ifdef __cplusplus +} +#endif + +#endif /* WKBundleRangeHandle_h */ diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.cpp new file mode 100644 index 000000000..87ccf11e9 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKBundleScriptWorld.h" + +#include "InjectedBundleScriptWorld.h" +#include "WKAPICast.h" +#include "WKBundleAPICast.h" + +using namespace WebKit; + +WKTypeID WKBundleScriptWorldGetTypeID() +{ + return toAPI(InjectedBundleScriptWorld::APIType); +} + +WKBundleScriptWorldRef WKBundleScriptWorldCreateWorld() +{ + RefPtr<InjectedBundleScriptWorld> world = InjectedBundleScriptWorld::create(); + return toAPI(world.release().leakRef()); +} + +WKBundleScriptWorldRef WKBundleScriptWorldNormalWorld() +{ + return toAPI(InjectedBundleScriptWorld::normalWorld()); +} + +void WKBundleScriptWorldClearWrappers(WKBundleScriptWorldRef scriptWorldRef) +{ + toImpl(scriptWorldRef)->clearWrappers(); +} diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.h new file mode 100644 index 000000000..013cdc9a3 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleScriptWorld.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundleScriptWorld_h +#define WKBundleScriptWorld_h + +#include <WebKit2/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT WKTypeID WKBundleScriptWorldGetTypeID(); + +WK_EXPORT WKBundleScriptWorldRef WKBundleScriptWorldCreateWorld(); +WK_EXPORT WKBundleScriptWorldRef WKBundleScriptWorldNormalWorld(); +WK_EXPORT void WKBundleScriptWorldClearWrappers(WKBundleScriptWorldRef scriptWorld); + +#ifdef __cplusplus +} +#endif + +#endif /* WKBundleScriptWorld_h */ diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/win/WKBundlePrivateWin.cpp b/Source/WebKit2/WebProcess/InjectedBundle/API/c/win/WKBundlePrivateWin.cpp new file mode 100644 index 000000000..463a21155 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/win/WKBundlePrivateWin.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "WKBundlePrivateWin.h" + +#include "InjectedBundle.h" +#include "WKAPICast.h" +#include "WKBundleAPICast.h" + +using namespace WebKit; + +void WKBundleSetHostAllowsAnyHTTPSCertificate(WKBundleRef bundleRef, WKStringRef host) +{ + toImpl(bundleRef)->setHostAllowsAnyHTTPSCertificate(toWTFString(host)); +} + +void WKBundleSetClientCertificate(WKBundleRef bundleRef, WKStringRef host, WKStringRef certificateSystemStoreName, WKCertificateInfoRef certificateInfoRef) +{ + toImpl(bundleRef)->setClientCertificate(toWTFString(host), toWTFString(certificateSystemStoreName), toImpl(certificateInfoRef)); +} diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/c/win/WKBundlePrivateWin.h b/Source/WebKit2/WebProcess/InjectedBundle/API/c/win/WKBundlePrivateWin.h new file mode 100644 index 000000000..03006dc11 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/API/c/win/WKBundlePrivateWin.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef WKBundlePrivateWin_h +#define WKBundlePrivateWin_h + +#include <WebKit2/WKBase.h> + +#ifdef __cplusplus +extern "C" { +#endif + +WK_EXPORT void WKBundleSetHostAllowsAnyHTTPSCertificate(WKBundleRef bundle, WKStringRef host); +WK_EXPORT void WKBundleSetClientCertificate(WKBundleRef bundle, WKStringRef host, WKStringRef certificateSystemStoreName, WKCertificateInfoRef certificateInfo); + +#ifdef __cplusplus +} +#endif + +#endif /* WKBundlePrivateWin_h */ diff --git a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp new file mode 100644 index 000000000..cebbb30c1 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp @@ -0,0 +1,204 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundleNodeHandle.h" + +#include "WebFrame.h" +#include "WebFrameLoaderClient.h" +#include <JavaScriptCore/APICast.h> +#include <WebCore/Document.h> +#include <WebCore/Frame.h> +#include <WebCore/HTMLFrameElement.h> +#include <WebCore/HTMLIFrameElement.h> +#include <WebCore/HTMLInputElement.h> +#include <WebCore/HTMLNames.h> +#include <WebCore/HTMLTableCellElement.h> +#include <WebCore/HTMLTextAreaElement.h> +#include <WebCore/IntRect.h> +#include <WebCore/JSNode.h> +#include <WebCore/Node.h> +#include <wtf/HashMap.h> +#include <wtf/text/WTFString.h> + +using namespace WebCore; +using namespace HTMLNames; + +namespace WebKit { + +typedef HashMap<Node*, InjectedBundleNodeHandle*> DOMHandleCache; + +static DOMHandleCache& domHandleCache() +{ + DEFINE_STATIC_LOCAL(DOMHandleCache, cache, ()); + return cache; +} + +PassRefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::getOrCreate(JSContextRef, JSObjectRef object) +{ + Node* node = toNode(toJS(object)); + return getOrCreate(node); +} + +PassRefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::getOrCreate(Node* node) +{ + if (!node) + return 0; + + std::pair<DOMHandleCache::iterator, bool> result = domHandleCache().add(node, 0); + if (!result.second) + return PassRefPtr<InjectedBundleNodeHandle>(result.first->second); + + RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::create(node); + result.first->second = nodeHandle.get(); + return nodeHandle.release(); +} + +PassRefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::create(Node* node) +{ + return adoptRef(new InjectedBundleNodeHandle(node)); +} + +InjectedBundleNodeHandle::InjectedBundleNodeHandle(Node* node) + : m_node(node) +{ +} + +InjectedBundleNodeHandle::~InjectedBundleNodeHandle() +{ + domHandleCache().remove(m_node.get()); +} + +Node* InjectedBundleNodeHandle::coreNode() const +{ + return m_node.get(); +} + +PassRefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::document() +{ + return getOrCreate(m_node->document()); +} + +// Additional DOM Operations +// Note: These should only be operations that are not exposed to JavaScript. + +IntRect InjectedBundleNodeHandle::elementBounds() const +{ + if (!m_node->isElementNode()) + return IntRect(); + + return static_cast<Element*>(m_node.get())->boundsInRootViewSpace(); +} + +IntRect InjectedBundleNodeHandle::renderRect(bool* isReplaced) const +{ + return m_node.get()->renderRect(isReplaced); +} + +void InjectedBundleNodeHandle::setHTMLInputElementValueForUser(const String& value) +{ + if (!m_node->hasTagName(inputTag)) + return; + + static_cast<HTMLInputElement*>(m_node.get())->setValueForUser(value); +} + +bool InjectedBundleNodeHandle::isHTMLInputElementAutofilled() const +{ + if (!m_node->hasTagName(inputTag)) + return false; + + return static_cast<HTMLInputElement*>(m_node.get())->isAutofilled(); +} + +void InjectedBundleNodeHandle::setHTMLInputElementAutofilled(bool filled) +{ + if (!m_node->hasTagName(inputTag)) + return; + + static_cast<HTMLInputElement*>(m_node.get())->setAutofilled(filled); +} + +bool InjectedBundleNodeHandle::htmlInputElementLastChangeWasUserEdit() +{ + if (!m_node->hasTagName(inputTag)) + return false; + + return static_cast<HTMLInputElement*>(m_node.get())->lastChangeWasUserEdit(); +} + +bool InjectedBundleNodeHandle::htmlTextAreaElementLastChangeWasUserEdit() +{ + if (!m_node->hasTagName(textareaTag)) + return false; + + return static_cast<HTMLTextAreaElement*>(m_node.get())->lastChangeWasUserEdit(); +} + +PassRefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::htmlTableCellElementCellAbove() +{ + if (!m_node->hasTagName(tdTag)) + return 0; + + return getOrCreate(static_cast<HTMLTableCellElement*>(m_node.get())->cellAbove()); +} + +PassRefPtr<WebFrame> InjectedBundleNodeHandle::documentFrame() +{ + if (!m_node->isDocumentNode()) + return 0; + + Frame* frame = static_cast<Document*>(m_node.get())->frame(); + if (!frame) + return 0; + + return static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame(); +} + +PassRefPtr<WebFrame> InjectedBundleNodeHandle::htmlFrameElementContentFrame() +{ + if (!m_node->hasTagName(frameTag)) + return 0; + + Frame* frame = static_cast<HTMLFrameElement*>(m_node.get())->contentFrame(); + if (!frame) + return 0; + + return static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame(); +} + +PassRefPtr<WebFrame> InjectedBundleNodeHandle::htmlIFrameElementContentFrame() +{ + if (!m_node->hasTagName(iframeTag)) + return 0; + + Frame* frame = static_cast<HTMLIFrameElement*>(m_node.get())->contentFrame(); + if (!frame) + return 0; + + return static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame(); +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h new file mode 100644 index 000000000..e4a5ab91e --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundleNodeHandle_h +#define InjectedBundleNodeHandle_h + +#include "APIObject.h" +#include <JavaScriptCore/JSBase.h> +#include <wtf/Forward.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> + +namespace WebCore { + class IntRect; + class Node; +} + +namespace WebKit { + +class InjectedBundleScriptWorld; +class WebFrame; + +class InjectedBundleNodeHandle : public APIObject { +public: + static const Type APIType = TypeBundleNodeHandle; + + static PassRefPtr<InjectedBundleNodeHandle> getOrCreate(JSContextRef, JSObjectRef); + static PassRefPtr<InjectedBundleNodeHandle> getOrCreate(WebCore::Node*); + + virtual ~InjectedBundleNodeHandle(); + + WebCore::Node* coreNode() const; + + // Convenience DOM Operations + PassRefPtr<InjectedBundleNodeHandle> document(); + + // Additional DOM Operations + // Note: These should only be operations that are not exposed to JavaScript. + WebCore::IntRect elementBounds() const; + WebCore::IntRect renderRect(bool*) const; + void setHTMLInputElementValueForUser(const String&); + bool isHTMLInputElementAutofilled() const; + void setHTMLInputElementAutofilled(bool); + bool htmlInputElementLastChangeWasUserEdit(); + bool htmlTextAreaElementLastChangeWasUserEdit(); + + PassRefPtr<InjectedBundleNodeHandle> htmlTableCellElementCellAbove(); + + PassRefPtr<WebFrame> documentFrame(); + PassRefPtr<WebFrame> htmlFrameElementContentFrame(); + PassRefPtr<WebFrame> htmlIFrameElementContentFrame(); + +private: + static PassRefPtr<InjectedBundleNodeHandle> create(WebCore::Node*); + InjectedBundleNodeHandle(WebCore::Node*); + + virtual Type type() const { return APIType; } + + RefPtr<WebCore::Node> m_node; +}; + +} // namespace WebKit + +#endif // InjectedBundleNodeHandle_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp new file mode 100644 index 000000000..e94edfd34 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundleRangeHandle.h" + +#include <WebCore/Range.h> +#include <wtf/HashMap.h> + +using namespace WebCore; + +namespace WebKit { + +typedef HashMap<Range*, InjectedBundleRangeHandle*> DOMHandleCache; + +static DOMHandleCache& domHandleCache() +{ + DEFINE_STATIC_LOCAL(DOMHandleCache, cache, ()); + return cache; +} + +PassRefPtr<InjectedBundleRangeHandle> InjectedBundleRangeHandle::getOrCreate(Range* range) +{ + if (!range) + return 0; + + std::pair<DOMHandleCache::iterator, bool> result = domHandleCache().add(range, 0); + if (!result.second) + return PassRefPtr<InjectedBundleRangeHandle>(result.first->second); + + RefPtr<InjectedBundleRangeHandle> rangeHandle = InjectedBundleRangeHandle::create(range); + result.first->second = rangeHandle.get(); + return rangeHandle.release(); +} + +PassRefPtr<InjectedBundleRangeHandle> InjectedBundleRangeHandle::create(Range* range) +{ + return adoptRef(new InjectedBundleRangeHandle(range)); +} + +InjectedBundleRangeHandle::InjectedBundleRangeHandle(Range* range) + : m_range(range) +{ +} + +InjectedBundleRangeHandle::~InjectedBundleRangeHandle() +{ + domHandleCache().remove(m_range.get()); +} + +Range* InjectedBundleRangeHandle::coreRange() const +{ + return m_range.get(); +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h new file mode 100644 index 000000000..4d6789a88 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundleRangeHandle_h +#define InjectedBundleRangeHandle_h + +#include "APIObject.h" +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> + +namespace WebCore { + class Range; +} + +namespace WebKit { + +class InjectedBundleScriptWorld; + +class InjectedBundleRangeHandle : public APIObject { +public: + static const Type APIType = TypeBundleRangeHandle; + + static PassRefPtr<InjectedBundleRangeHandle> getOrCreate(WebCore::Range*); + + virtual ~InjectedBundleRangeHandle(); + + WebCore::Range* coreRange() const; + +private: + static PassRefPtr<InjectedBundleRangeHandle> create(WebCore::Range*); + InjectedBundleRangeHandle(WebCore::Range*); + + virtual Type type() const { return APIType; } + + RefPtr<WebCore::Range> m_range; +}; + +} // namespace WebKit + +#endif // InjectedBundleRangeHandle_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp new file mode 100644 index 000000000..b87151e42 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp @@ -0,0 +1,394 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundle.h" + +#include "Arguments.h" +#include "ImmutableArray.h" +#include "InjectedBundleMessageKinds.h" +#include "InjectedBundleScriptWorld.h" +#include "InjectedBundleUserMessageCoders.h" +#include "WKAPICast.h" +#include "WKBundleAPICast.h" +#include "WebApplicationCacheManager.h" +#include "WebContextMessageKinds.h" +#include "WebCoreArgumentCoders.h" +#include "WebDatabaseManager.h" +#include "WebFrame.h" +#include "WebPage.h" +#include "WebPreferencesStore.h" +#include "WebProcess.h" +#include <JavaScriptCore/APICast.h> +#include <JavaScriptCore/JSLock.h> +#include <WebCore/Frame.h> +#include <WebCore/FrameView.h> +#include <WebCore/GCController.h> +#include <WebCore/JSDOMWindow.h> +#include <WebCore/Page.h> +#include <WebCore/PageGroup.h> +#include <WebCore/PrintContext.h> +#include <WebCore/ResourceHandle.h> +#include <WebCore/ScriptController.h> +#include <WebCore/SecurityOrigin.h> +#include <WebCore/SecurityPolicy.h> +#include <WebCore/Settings.h> +#include <WebCore/UserGestureIndicator.h> +#include <wtf/OwnArrayPtr.h> +#include <wtf/PassOwnArrayPtr.h> + +using namespace WebCore; +using namespace JSC; + +namespace WebKit { + +InjectedBundle::InjectedBundle(const String& path) + : m_path(path) + , m_platformBundle(0) +{ + initializeClient(0); +} + +InjectedBundle::~InjectedBundle() +{ +} + +void InjectedBundle::initializeClient(WKBundleClient* client) +{ + m_client.initialize(client); +} + +void InjectedBundle::postMessage(const String& messageName, APIObject* messageBody) +{ + WebProcess::shared().connection()->deprecatedSend(WebContextLegacyMessage::PostMessage, 0, CoreIPC::In(messageName, InjectedBundleUserMessageEncoder(messageBody))); +} + +void InjectedBundle::postSynchronousMessage(const String& messageName, APIObject* messageBody, RefPtr<APIObject>& returnData) +{ + RefPtr<APIObject> returnDataTmp; + InjectedBundleUserMessageDecoder messageDecoder(returnDataTmp); + + bool succeeded = WebProcess::shared().connection()->deprecatedSendSync(WebContextLegacyMessage::PostSynchronousMessage, 0, CoreIPC::In(messageName, InjectedBundleUserMessageEncoder(messageBody)), CoreIPC::Out(messageDecoder)); + + if (!succeeded) + return; + + returnData = returnDataTmp; +} + +WebConnection* InjectedBundle::webConnectionToUIProcess() const +{ + return WebProcess::shared().webConnectionToUIProcess(); +} + +void InjectedBundle::setShouldTrackVisitedLinks(bool shouldTrackVisitedLinks) +{ + PageGroup::setShouldTrackVisitedLinks(shouldTrackVisitedLinks); +} + +void InjectedBundle::removeAllVisitedLinks() +{ + PageGroup::removeAllVisitedLinks(); +} + +void InjectedBundle::overrideXSSAuditorEnabledForTestRunner(WebPageGroupProxy* pageGroup, bool enabled) +{ + // Override the preference for all future pages. + WebPreferencesStore::overrideXSSAuditorEnabledForTestRunner(enabled); + + // Change the setting for existing ones. + const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages(); + for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter) + (*iter)->settings()->setXSSAuditorEnabled(enabled); +} + +void InjectedBundle::setAllowUniversalAccessFromFileURLs(WebPageGroupProxy* pageGroup, bool enabled) +{ + const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages(); + for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter) + (*iter)->settings()->setAllowUniversalAccessFromFileURLs(enabled); +} + +void InjectedBundle::setAllowFileAccessFromFileURLs(WebPageGroupProxy* pageGroup, bool enabled) +{ + const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages(); + for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter) + (*iter)->settings()->setAllowFileAccessFromFileURLs(enabled); +} + +void InjectedBundle::setFrameFlatteningEnabled(WebPageGroupProxy* pageGroup, bool enabled) +{ + const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages(); + for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter) + (*iter)->settings()->setFrameFlatteningEnabled(enabled); +} + +void InjectedBundle::setJavaScriptCanAccessClipboard(WebPageGroupProxy* pageGroup, bool enabled) +{ + const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages(); + for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter) + (*iter)->settings()->setJavaScriptCanAccessClipboard(enabled); +} + +void InjectedBundle::setPrivateBrowsingEnabled(WebPageGroupProxy* pageGroup, bool enabled) +{ + const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages(); + for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter) + (*iter)->settings()->setPrivateBrowsingEnabled(enabled); +} + +void InjectedBundle::switchNetworkLoaderToNewTestingSession() +{ +#if USE(CFURLSTORAGESESSIONS) + // Set a private session for testing to avoid interfering with global cookies. This should be different from private browsing session. + RetainPtr<CFURLStorageSessionRef> session = ResourceHandle::createPrivateBrowsingStorageSession(CFSTR("Private WebKit Session")); + ResourceHandle::setDefaultStorageSession(session.get()); +#endif +} + +void InjectedBundle::setAuthorAndUserStylesEnabled(WebPageGroupProxy* pageGroup, bool enabled) +{ + const HashSet<Page*>& pages = PageGroup::pageGroup(pageGroup->identifier())->pages(); + for (HashSet<Page*>::iterator iter = pages.begin(); iter != pages.end(); ++iter) + (*iter)->settings()->setAuthorAndUserStylesEnabled(enabled); +} + +void InjectedBundle::addOriginAccessWhitelistEntry(const String& sourceOrigin, const String& destinationProtocol, const String& destinationHost, bool allowDestinationSubdomains) +{ + SecurityPolicy::addOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains); +} + +void InjectedBundle::removeOriginAccessWhitelistEntry(const String& sourceOrigin, const String& destinationProtocol, const String& destinationHost, bool allowDestinationSubdomains) +{ + SecurityPolicy::removeOriginAccessWhitelistEntry(*SecurityOrigin::createFromString(sourceOrigin), destinationProtocol, destinationHost, allowDestinationSubdomains); +} + +void InjectedBundle::resetOriginAccessWhitelists() +{ + SecurityPolicy::resetOriginAccessWhitelists(); +} + +void InjectedBundle::clearAllDatabases() +{ + WebDatabaseManager::shared().deleteAllDatabases(); +} + +void InjectedBundle::setDatabaseQuota(uint64_t quota) +{ + WebDatabaseManager::shared().setQuotaForOrigin("file:///", quota); +} + +void InjectedBundle::clearApplicationCache() +{ + WebApplicationCacheManager::shared().deleteAllEntries(); +} + +void InjectedBundle::setAppCacheMaximumSize(uint64_t size) +{ + WebApplicationCacheManager::shared().setAppCacheMaximumSize(size); +} + +int InjectedBundle::numberOfPages(WebFrame* frame, double pageWidthInPixels, double pageHeightInPixels) +{ + Frame* coreFrame = frame ? frame->coreFrame() : 0; + if (!coreFrame) + return -1; + if (!pageWidthInPixels) + pageWidthInPixels = coreFrame->view()->width(); + if (!pageHeightInPixels) + pageHeightInPixels = coreFrame->view()->height(); + + return PrintContext::numberOfPages(coreFrame, FloatSize(pageWidthInPixels, pageHeightInPixels)); +} + +int InjectedBundle::pageNumberForElementById(WebFrame* frame, const String& id, double pageWidthInPixels, double pageHeightInPixels) +{ + Frame* coreFrame = frame ? frame->coreFrame() : 0; + if (!coreFrame) + return -1; + + Element* element = coreFrame->document()->getElementById(AtomicString(id)); + if (!element) + return -1; + + if (!pageWidthInPixels) + pageWidthInPixels = coreFrame->view()->width(); + if (!pageHeightInPixels) + pageHeightInPixels = coreFrame->view()->height(); + + return PrintContext::pageNumberForElement(element, FloatSize(pageWidthInPixels, pageHeightInPixels)); +} + +String InjectedBundle::pageSizeAndMarginsInPixels(WebFrame* frame, int pageIndex, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft) +{ + Frame* coreFrame = frame ? frame->coreFrame() : 0; + if (!coreFrame) + return String(); + + return PrintContext::pageSizeAndMarginsInPixels(coreFrame, pageIndex, width, height, marginTop, marginRight, marginBottom, marginLeft); +} + +bool InjectedBundle::isPageBoxVisible(WebFrame* frame, int pageIndex) +{ + Frame* coreFrame = frame ? frame->coreFrame() : 0; + if (!coreFrame) + return false; + + return PrintContext::isPageBoxVisible(coreFrame, pageIndex); +} + +bool InjectedBundle::isProcessingUserGesture() +{ + return ScriptController::processingUserGesture(); +} + +static PassOwnPtr<Vector<String> > toStringVector(ImmutableArray* patterns) +{ + if (!patterns) + return nullptr; + + size_t size = patterns->size(); + if (!size) + return nullptr; + + OwnPtr<Vector<String> > patternsVector = adoptPtr(new Vector<String>); + patternsVector->reserveInitialCapacity(size); + for (size_t i = 0; i < size; ++i) { + WebString* entry = patterns->at<WebString>(i); + if (entry) + patternsVector->uncheckedAppend(entry->string()); + } + return patternsVector.release(); +} + +void InjectedBundle::addUserScript(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld, const String& source, const String& url, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserScriptInjectionTime injectionTime, WebCore::UserContentInjectedFrames injectedFrames) +{ + // url is not from KURL::string(), i.e. it has not already been parsed by KURL, so we have to use the relative URL constructor for KURL instead of the ParsedURLStringTag version. + PageGroup::pageGroup(pageGroup->identifier())->addUserScriptToWorld(scriptWorld->coreWorld(), source, KURL(KURL(), url), toStringVector(whitelist), toStringVector(blacklist), injectionTime, injectedFrames); +} + +void InjectedBundle::addUserStyleSheet(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld, const String& source, const String& url, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserContentInjectedFrames injectedFrames) +{ + // url is not from KURL::string(), i.e. it has not already been parsed by KURL, so we have to use the relative URL constructor for KURL instead of the ParsedURLStringTag version. + PageGroup::pageGroup(pageGroup->identifier())->addUserStyleSheetToWorld(scriptWorld->coreWorld(), source, KURL(KURL(), url), toStringVector(whitelist), toStringVector(blacklist), injectedFrames); +} + +void InjectedBundle::removeUserScript(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld, const String& url) +{ + // url is not from KURL::string(), i.e. it has not already been parsed by KURL, so we have to use the relative URL constructor for KURL instead of the ParsedURLStringTag version. + PageGroup::pageGroup(pageGroup->identifier())->removeUserScriptFromWorld(scriptWorld->coreWorld(), KURL(KURL(), url)); +} + +void InjectedBundle::removeUserStyleSheet(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld, const String& url) +{ + // url is not from KURL::string(), i.e. it has not already been parsed by KURL, so we have to use the relative URL constructor for KURL instead of the ParsedURLStringTag version. + PageGroup::pageGroup(pageGroup->identifier())->removeUserStyleSheetFromWorld(scriptWorld->coreWorld(), KURL(KURL(), url)); +} + +void InjectedBundle::removeUserScripts(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld) +{ + PageGroup::pageGroup(pageGroup->identifier())->removeUserScriptsFromWorld(scriptWorld->coreWorld()); +} + +void InjectedBundle::removeUserStyleSheets(WebPageGroupProxy* pageGroup, InjectedBundleScriptWorld* scriptWorld) +{ + PageGroup::pageGroup(pageGroup->identifier())->removeUserStyleSheetsFromWorld(scriptWorld->coreWorld()); +} + +void InjectedBundle::removeAllUserContent(WebPageGroupProxy* pageGroup) +{ + PageGroup::pageGroup(pageGroup->identifier())->removeAllUserContent(); +} + +void InjectedBundle::garbageCollectJavaScriptObjects() +{ + gcController().garbageCollectNow(); +} + +void InjectedBundle::garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging(bool waitUntilDone) +{ + gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone); +} + +size_t InjectedBundle::javaScriptObjectsCount() +{ + JSLock lock(SilenceAssertionsOnly); + return JSDOMWindow::commonJSGlobalData()->heap.objectCount(); +} + +void InjectedBundle::reportException(JSContextRef context, JSValueRef exception) +{ + if (!context || !exception) + return; + + JSLock lock(JSC::SilenceAssertionsOnly); + JSC::ExecState* execState = toJS(context); + + // Make sure the context has a DOMWindow global object, otherwise this context didn't originate from a Page. + if (!toJSDOMWindow(execState->lexicalGlobalObject())) + return; + + WebCore::reportException(execState, toJS(execState, exception)); +} + +void InjectedBundle::didCreatePage(WebPage* page) +{ + m_client.didCreatePage(this, page); +} + +void InjectedBundle::willDestroyPage(WebPage* page) +{ + m_client.willDestroyPage(this, page); +} + +void InjectedBundle::didInitializePageGroup(WebPageGroupProxy* pageGroup) +{ + m_client.didInitializePageGroup(this, pageGroup); +} + +void InjectedBundle::didReceiveMessage(const String& messageName, APIObject* messageBody) +{ + m_client.didReceiveMessage(this, messageName, messageBody); +} + +void InjectedBundle::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments) +{ + switch (messageID.get<InjectedBundleMessage::Kind>()) { + case InjectedBundleMessage::PostMessage: { + String messageName; + RefPtr<APIObject> messageBody; + InjectedBundleUserMessageDecoder messageDecoder(messageBody); + if (!arguments->decode(CoreIPC::Out(messageName, messageDecoder))) + return; + + didReceiveMessage(messageName, messageBody.get()); + return; + } + } + + ASSERT_NOT_REACHED(); +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h new file mode 100644 index 000000000..6ff2cfa8e --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h @@ -0,0 +1,165 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundle_h +#define InjectedBundle_h + +#include "APIObject.h" +#include "InjectedBundleClient.h" +#include "SandboxExtension.h" +#include "WKBundle.h" +#include <WebCore/UserContentTypes.h> +#include <WebCore/UserScriptTypes.h> +#include <wtf/PassRefPtr.h> +#include <wtf/text/WTFString.h> + +#if PLATFORM(QT) +#include <QLibrary> +#endif + +#if PLATFORM(GTK) +typedef struct _GModule GModule; +#endif + +namespace CoreIPC { + class ArgumentDecoder; + class Connection; + class MessageID; +} + +namespace WebKit { + +#if PLATFORM(MAC) +typedef CFBundleRef PlatformBundle; +#elif PLATFORM(WIN) +typedef HMODULE PlatformBundle; +#elif PLATFORM(QT) +typedef QLibrary PlatformBundle; +#elif PLATFORM(GTK) +typedef ::GModule* PlatformBundle; +#endif + +class ImmutableArray; +class InjectedBundleScriptWorld; +class WebCertificateInfo; +class WebConnection; +class WebFrame; +class WebPage; +class WebPageGroupProxy; + +class InjectedBundle : public APIObject { +public: + static const Type APIType = TypeBundle; + + static PassRefPtr<InjectedBundle> create(const String& path) + { + return adoptRef(new InjectedBundle(path)); + } + ~InjectedBundle(); + + bool load(APIObject* initializationUserData); + void setSandboxExtension(PassRefPtr<SandboxExtension> sandboxExtension) { m_sandboxExtension = sandboxExtension; } + + // API + void initializeClient(WKBundleClient*); + void postMessage(const String&, APIObject*); + void postSynchronousMessage(const String&, APIObject*, RefPtr<APIObject>& returnData); +#if PLATFORM(WIN) + void setHostAllowsAnyHTTPSCertificate(const String&); + void setClientCertificate(const String& host, const String& certificateSystemStoreName, const WebCertificateInfo*); +#endif + + WebConnection* webConnectionToUIProcess() const; + + // TestRunner only SPI + void setShouldTrackVisitedLinks(bool); + void removeAllVisitedLinks(); + void activateMacFontAscentHack(); + void overrideXSSAuditorEnabledForTestRunner(WebPageGroupProxy* pageGroup, bool enabled); + void setAllowUniversalAccessFromFileURLs(WebPageGroupProxy*, bool); + void setAllowFileAccessFromFileURLs(WebPageGroupProxy*, bool); + void setFrameFlatteningEnabled(WebPageGroupProxy*, bool); + void setJavaScriptCanAccessClipboard(WebPageGroupProxy*, bool); + void setPrivateBrowsingEnabled(WebPageGroupProxy*, bool); + void switchNetworkLoaderToNewTestingSession(); + void setAuthorAndUserStylesEnabled(WebPageGroupProxy*, bool); + void addOriginAccessWhitelistEntry(const String&, const String&, const String&, bool); + void removeOriginAccessWhitelistEntry(const String&, const String&, const String&, bool); + void resetOriginAccessWhitelists(); + int numberOfPages(WebFrame*, double, double); + int pageNumberForElementById(WebFrame*, const String&, double, double); + String pageSizeAndMarginsInPixels(WebFrame*, int, int, int, int, int, int, int); + bool isPageBoxVisible(WebFrame*, int); + + // UserContent API + void addUserScript(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& source, const String& url, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserScriptInjectionTime, WebCore::UserContentInjectedFrames); + void addUserStyleSheet(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& source, const String& url, ImmutableArray* whitelist, ImmutableArray* blacklist, WebCore::UserContentInjectedFrames); + void removeUserScript(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& url); + void removeUserStyleSheet(WebPageGroupProxy*, InjectedBundleScriptWorld*, const String& url); + void removeUserScripts(WebPageGroupProxy*, InjectedBundleScriptWorld*); + void removeUserStyleSheets(WebPageGroupProxy*, InjectedBundleScriptWorld*); + void removeAllUserContent(WebPageGroupProxy*); + + // Local storage API + void clearAllDatabases(); + void setDatabaseQuota(uint64_t); + + // Application Cache API + void clearApplicationCache(); + void setAppCacheMaximumSize(uint64_t); + + // Garbage collection API + void garbageCollectJavaScriptObjects(); + void garbageCollectJavaScriptObjectsOnAlternateThreadForDebugging(bool waitUntilDone); + size_t javaScriptObjectsCount(); + + // Callback hooks + void didCreatePage(WebPage*); + void willDestroyPage(WebPage*); + void didInitializePageGroup(WebPageGroupProxy*); + void didReceiveMessage(const String&, APIObject*); + + void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*); + + static void reportException(JSContextRef, JSValueRef exception); + + static bool isProcessingUserGesture(); + +private: + InjectedBundle(const String&); + + virtual Type type() const { return APIType; } + + String m_path; + PlatformBundle m_platformBundle; // This is leaked right now, since we never unload the bundle/module. + + RefPtr<SandboxExtension> m_sandboxExtension; + + InjectedBundleClient m_client; +}; + +} // namespace WebKit + +#endif // InjectedBundle_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleBackForwardList.cpp b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleBackForwardList.cpp new file mode 100644 index 000000000..d7fb9ec01 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleBackForwardList.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundleBackForwardList.h" + +#include "InjectedBundleBackForwardListItem.h" +#include "WebBackForwardListProxy.h" +#include "WebPage.h" +#include <WebCore/BackForwardController.h> +#include <WebCore/Page.h> + +using namespace WebCore; + +namespace WebKit { + +PassRefPtr<InjectedBundleBackForwardListItem> InjectedBundleBackForwardList::itemAtIndex(int index) const +{ + if (!m_page) + return 0; + Page* page = m_page->corePage(); + if (!page) + return 0; + return InjectedBundleBackForwardListItem::create(page->backForward()->itemAtIndex(index)); +} + +int InjectedBundleBackForwardList::backListCount() const +{ + if (!m_page) + return 0; + Page* page = m_page->corePage(); + if (!page) + return 0; + return page->backForward()->backCount(); +} + +int InjectedBundleBackForwardList::forwardListCount() const +{ + if (!m_page) + return 0; + Page* page = m_page->corePage(); + if (!page) + return 0; + return page->backForward()->forwardCount(); +} + +void InjectedBundleBackForwardList::clear() +{ + if (!m_page) + return; + Page* page = m_page->corePage(); + if (!page) + return; + static_cast<WebBackForwardListProxy*>(page->backForward()->client())->clear(); +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleBackForwardList.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleBackForwardList.h new file mode 100644 index 000000000..952bdb6bc --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleBackForwardList.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundleBackForwardList_h +#define InjectedBundleBackForwardList_h + +#include "APIObject.h" +#include <wtf/PassRefPtr.h> + +namespace WebKit { + +class WebPage; + +class InjectedBundleBackForwardListItem; + +class InjectedBundleBackForwardList : public APIObject { +public: + static const Type APIType = TypeBundleBackForwardList; + + static PassRefPtr<InjectedBundleBackForwardList> create(WebPage* page) + { + return adoptRef(new InjectedBundleBackForwardList(page)); + } + + void detach() { m_page = 0; } + + void clear(); + + PassRefPtr<InjectedBundleBackForwardListItem> itemAtIndex(int) const; + int backListCount() const; + int forwardListCount() const; + +private: + InjectedBundleBackForwardList(WebPage* page) : m_page(page) { } + + virtual Type type() const { return APIType; } + + WebPage* m_page; +}; + +} // namespace WebKit + +#endif // InjectedBundleBackForwardList_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleBackForwardListItem.cpp b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleBackForwardListItem.cpp new file mode 100644 index 000000000..92a7e695e --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleBackForwardListItem.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundleBackForwardListItem.h" + +#include "ImmutableArray.h" + +using namespace WebCore; + +namespace WebKit { + +PassRefPtr<ImmutableArray> InjectedBundleBackForwardListItem::children() const +{ + const HistoryItemVector& children = m_item->children(); + size_t size = children.size(); + Vector<RefPtr<APIObject> > vector(size); + for (size_t i = 0; i < size; ++i) + vector[i] = InjectedBundleBackForwardListItem::create(children[i]); + return ImmutableArray::adopt(vector); +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleBackForwardListItem.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleBackForwardListItem.h new file mode 100644 index 000000000..6cd9ec682 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleBackForwardListItem.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundleBackForwardListItem_h +#define InjectedBundleBackForwardListItem_h + +#include "APIObject.h" +#include <WebCore/HistoryItem.h> + +namespace WebKit { + +class ImmutableArray; +class WebPageProxy; + +class InjectedBundleBackForwardListItem : public APIObject { +public: + static const Type APIType = TypeBundleBackForwardListItem; + + static PassRefPtr<InjectedBundleBackForwardListItem> create(PassRefPtr<WebCore::HistoryItem> item) + { + if (!item) + return 0; + return adoptRef(new InjectedBundleBackForwardListItem(item)); + } + + WebCore::HistoryItem* item() const { return m_item.get(); } + + const String& originalURL() const { return m_item->originalURLString(); } + const String& url() const { return m_item->urlString(); } + const String& title() const { return m_item->title(); } + + const String& target() const { return m_item->target(); } + bool isTargetItem() const { return m_item->isTargetItem(); } + + PassRefPtr<ImmutableArray> children() const; + +private: + InjectedBundleBackForwardListItem(PassRefPtr<WebCore::HistoryItem> item) : m_item(item) { } + + virtual Type type() const { return APIType; } + + RefPtr<WebCore::HistoryItem> m_item; +}; + +} // namespace WebKit + +#endif // InjectedBundleBackForwardListItem_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleClient.cpp b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleClient.cpp new file mode 100644 index 000000000..f2e4f2b9f --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleClient.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundleClient.h" + +#include "WKBundleAPICast.h" + +namespace WebKit { + +void InjectedBundleClient::didCreatePage(InjectedBundle* bundle, WebPage* page) +{ + if (!m_client.didCreatePage) + return; + + m_client.didCreatePage(toAPI(bundle), toAPI(page), m_client.clientInfo); +} + +void InjectedBundleClient::willDestroyPage(InjectedBundle* bundle, WebPage* page) +{ + if (!m_client.willDestroyPage) + return; + + m_client.willDestroyPage(toAPI(bundle), toAPI(page), m_client.clientInfo); +} + +void InjectedBundleClient::didInitializePageGroup(InjectedBundle* bundle, WebPageGroupProxy* pageGroup) +{ + if (!m_client.didInitializePageGroup) + return; + + m_client.didInitializePageGroup(toAPI(bundle), toAPI(pageGroup), m_client.clientInfo); +} + +void InjectedBundleClient::didReceiveMessage(InjectedBundle* bundle, const String& messageName, APIObject* messageBody) +{ + if (!m_client.didReceiveMessage) + return; + + m_client.didReceiveMessage(toAPI(bundle), toAPI(messageName.impl()), toAPI(messageBody), m_client.clientInfo); +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleClient.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleClient.h new file mode 100644 index 000000000..32be290c9 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleClient.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundleClient_h +#define InjectedBundleClient_h + +#include "APIClient.h" +#include "WKBundle.h" +#include <wtf/Forward.h> + +namespace WebKit { + +class APIObject; +class InjectedBundle; +class WebPage; +class WebPageGroupProxy; + +class InjectedBundleClient : public APIClient<WKBundleClient, kWKBundleClientCurrentVersion> { +public: + void didCreatePage(InjectedBundle*, WebPage*); + void willDestroyPage(InjectedBundle*, WebPage*); + void didInitializePageGroup(InjectedBundle*, WebPageGroupProxy*); + void didReceiveMessage(InjectedBundle*, const String& messageName, APIObject* messageBody); +}; + +} // namespace WebKit + + +#endif // InjectedBundleClient_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp new file mode 100644 index 000000000..8c91cb875 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundleHitTestResult.h" + +#include "InjectedBundleNodeHandle.h" +#include "WebFrame.h" +#include "WebFrameLoaderClient.h" +#include <WebCore/Document.h> +#include <WebCore/Frame.h> +#include <WebCore/FrameLoader.h> +#include <WebCore/FrameView.h> +#include <WebCore/KURL.h> +#include <wtf/text/WTFString.h> + +using namespace WebCore; + +namespace WebKit { + +PassRefPtr<InjectedBundleHitTestResult> InjectedBundleHitTestResult::create(const WebCore::HitTestResult& hitTestResult) +{ + return adoptRef(new InjectedBundleHitTestResult(hitTestResult)); +} + +PassRefPtr<InjectedBundleNodeHandle> InjectedBundleHitTestResult::nodeHandle() const +{ + return InjectedBundleNodeHandle::getOrCreate(m_hitTestResult.innerNonSharedNode()); +} + +WebFrame* InjectedBundleHitTestResult::frame() const +{ + Node* node = m_hitTestResult.innerNonSharedNode(); + if (!node) + return 0; + + Document* document = node->document(); + if (!document) + return 0; + + Frame* frame = document->frame(); + if (!frame) + return 0; + + return static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame(); +} + +WebFrame* InjectedBundleHitTestResult::targetFrame() const +{ + Frame* frame = m_hitTestResult.targetFrame(); + if (!frame) + return 0; + + return static_cast<WebFrameLoaderClient*>(frame->loader()->client())->webFrame(); +} + +String InjectedBundleHitTestResult::absoluteImageURL() const +{ + return m_hitTestResult.absoluteImageURL().string(); +} + +String InjectedBundleHitTestResult::absolutePDFURL() const +{ + return m_hitTestResult.absolutePDFURL().string(); +} + +String InjectedBundleHitTestResult::absoluteLinkURL() const +{ + return m_hitTestResult.absoluteLinkURL().string(); +} + +String InjectedBundleHitTestResult::absoluteMediaURL() const +{ + return m_hitTestResult.absoluteMediaURL().string(); +} + +String InjectedBundleHitTestResult::linkLabel() const +{ + return m_hitTestResult.textContent(); +} + +String InjectedBundleHitTestResult::linkTitle() const +{ + return m_hitTestResult.titleDisplayString(); +} + +WebCore::IntRect InjectedBundleHitTestResult::imageRect() const +{ + WebCore::IntRect imageRect = m_hitTestResult.imageRect(); + if (imageRect.isEmpty()) + return imageRect; + + // The image rect in WebCore::HitTestResult is in frame coordinates, but we need it in WKView + // coordinates since WebKit2 clients don't have enough context to do the conversion themselves. + WebFrame* webFrame = frame(); + if (!webFrame) + return imageRect; + + WebCore::Frame* coreFrame = webFrame->coreFrame(); + if (!coreFrame) + return imageRect; + + WebCore::FrameView* view = coreFrame->view(); + if (!view) + return imageRect; + + return view->contentsToRootView(imageRect); +} + +bool InjectedBundleHitTestResult::isSelected() const +{ + return m_hitTestResult.isSelected(); +} + +} // WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h new file mode 100644 index 000000000..292fce1ba --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundleHitTestResult_h +#define InjectedBundleHitTestResult_h + +#include "APIObject.h" +#include <WebCore/HitTestResult.h> +#include <wtf/Forward.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> + +namespace WebKit { + +class InjectedBundleNodeHandle; +class WebFrame; + +class InjectedBundleHitTestResult : public APIObject { +public: + static const Type APIType = TypeBundleHitTestResult; + + static PassRefPtr<InjectedBundleHitTestResult> create(const WebCore::HitTestResult&); + + const WebCore::HitTestResult& coreHitTestResult() const { return m_hitTestResult; } + + PassRefPtr<InjectedBundleNodeHandle> nodeHandle() const; + WebFrame* frame() const; + WebFrame* targetFrame() const; + + String absoluteImageURL() const; + String absolutePDFURL() const; + String absoluteLinkURL() const; + String absoluteMediaURL() const; + + String linkLabel() const; + String linkTitle() const; + + WebCore::IntRect imageRect() const; + + bool isSelected() const; + +private: + explicit InjectedBundleHitTestResult(const WebCore::HitTestResult& hitTestResult) + : m_hitTestResult(hitTestResult) + { + } + + virtual Type type() const { return APIType; } + + WebCore::HitTestResult m_hitTestResult; +}; + +} // namespace WebKit + +#endif // InjectedBundleHitTestResult_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleNavigationAction.cpp b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleNavigationAction.cpp new file mode 100644 index 000000000..7a40ee6fb --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleNavigationAction.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundleNavigationAction.h" + +#include "WebFrame.h" +#include <WebCore/Frame.h> +#include <WebCore/HTMLFormElement.h> +#include <WebCore/MouseEvent.h> +#include <WebCore/NavigationAction.h> +#include <WebCore/UIEventWithKeyState.h> + +using namespace WebCore; + +namespace WebKit { + +static const MouseEvent* mouseEventForNavigationAction(const NavigationAction& navigationAction) +{ + for (const Event* e = navigationAction.event(); e; e = e->underlyingEvent()) { + if (e->isMouseEvent()) + return static_cast<const MouseEvent*>(e); + } + return 0; +} + +static WebMouseEvent::Button mouseButtonForMouseEvent(const MouseEvent* mouseEvent) +{ + if (!mouseEvent) + return WebMouseEvent::NoButton; + + if (!mouseEvent->buttonDown()) + return WebMouseEvent::NoButton; + + return static_cast<WebMouseEvent::Button>(mouseEvent->button()); +} + +WebEvent::Modifiers InjectedBundleNavigationAction::modifiersForNavigationAction(const NavigationAction& navigationAction) +{ + uint32_t modifiers = 0; + if (const UIEventWithKeyState* keyStateEvent = findEventWithKeyState(const_cast<Event*>(navigationAction.event()))) { + if (keyStateEvent->shiftKey()) + modifiers |= WebEvent::ShiftKey; + if (keyStateEvent->ctrlKey()) + modifiers |= WebEvent::ControlKey; + if (keyStateEvent->altKey()) + modifiers |= WebEvent::AltKey; + if (keyStateEvent->metaKey()) + modifiers |= WebEvent::MetaKey; + } + + return static_cast<WebEvent::Modifiers>(modifiers); +} + +WebMouseEvent::Button InjectedBundleNavigationAction::mouseButtonForNavigationAction(const NavigationAction& navigationAction) +{ + return mouseButtonForMouseEvent(mouseEventForNavigationAction(navigationAction)); +} + + +PassRefPtr<InjectedBundleNavigationAction> InjectedBundleNavigationAction::create(WebFrame* frame, const NavigationAction& action, PassRefPtr<FormState> formState) +{ + return adoptRef(new InjectedBundleNavigationAction(frame, action, formState)); +} + +InjectedBundleNavigationAction::InjectedBundleNavigationAction(WebFrame* frame, const NavigationAction& navigationAction, PassRefPtr<FormState> prpFormState) +{ + m_navigationType = navigationAction.type(); + m_modifiers = modifiersForNavigationAction(navigationAction); + + if (const MouseEvent* mouseEvent = mouseEventForNavigationAction(navigationAction)) { + m_hitTestResult = InjectedBundleHitTestResult::create(frame->coreFrame()->eventHandler()->hitTestResultAtPoint(mouseEvent->absoluteLocation(), false)); + m_mouseButton = mouseButtonForMouseEvent(mouseEvent); + } + + RefPtr<FormState> formState = prpFormState; + if (formState) { + ASSERT(formState->form()); + m_formElement = InjectedBundleNodeHandle::getOrCreate(formState->form()); + } +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleNavigationAction.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleNavigationAction.h new file mode 100644 index 000000000..128c9fbd0 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleNavigationAction.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundleNavigationAction_h +#define InjectedBundleNavigationAction_h + +#include "APIObject.h" +#include "InjectedBundleHitTestResult.h" +#include "InjectedBundleNodeHandle.h" +#include "WebEvent.h" +#include <WebCore/FrameLoaderTypes.h> +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> + +namespace WebCore { + class FormState; + class NavigationAction; +} + +namespace WebKit { + +class WebFrame; + +class InjectedBundleNavigationAction : public APIObject { +public: + static const Type APIType = TypeBundleNavigationAction; + + static PassRefPtr<InjectedBundleNavigationAction> create(WebFrame*, const WebCore::NavigationAction&, PassRefPtr<WebCore::FormState>); + + static WebEvent::Modifiers modifiersForNavigationAction(const WebCore::NavigationAction&); + static WebMouseEvent::Button mouseButtonForNavigationAction(const WebCore::NavigationAction&); + + WebCore::NavigationType navigationType() const { return m_navigationType; } + WebEvent::Modifiers modifiers() const { return m_modifiers; } + WebMouseEvent::Button mouseButton() const { return m_mouseButton; } + InjectedBundleHitTestResult* hitTestResult() const { return m_hitTestResult.get(); } + InjectedBundleNodeHandle* formElement() const { return m_formElement.get(); } + +private: + InjectedBundleNavigationAction(WebFrame*, const WebCore::NavigationAction&, PassRefPtr<WebCore::FormState>); + + virtual Type type() const { return APIType; } + + WebCore::NavigationType m_navigationType; + WebEvent::Modifiers m_modifiers; + WebMouseEvent::Button m_mouseButton; + RefPtr<InjectedBundleHitTestResult> m_hitTestResult; + RefPtr<InjectedBundleNodeHandle> m_formElement; +}; + +} // namespace WebKit + +#endif // InjectedBundleNavigationAction_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageContextMenuClient.cpp b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageContextMenuClient.cpp new file mode 100644 index 000000000..9df00819d --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageContextMenuClient.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundlePageContextMenuClient.h" + +#include "ImmutableArray.h" +#include "InjectedBundleHitTestResult.h" +#include "Logging.h" +#include "MutableArray.h" +#include "WebContextMenuItem.h" +#include "WKAPICast.h" +#include "WKBundleAPICast.h" +#include <WebCore/ContextMenu.h> + +using namespace WebCore; + +namespace WebKit { + +bool InjectedBundlePageContextMenuClient::getCustomMenuFromDefaultItems(WebPage* page, InjectedBundleHitTestResult* hitTestResult, const Vector<WebContextMenuItemData>& defaultMenu, Vector<WebContextMenuItemData>& newMenu, RefPtr<APIObject>& userData) +{ + if (!m_client.getContextMenuFromDefaultMenu) + return false; + + RefPtr<MutableArray> defaultMenuArray = MutableArray::create(); + defaultMenuArray->reserveCapacity(defaultMenu.size()); + for (unsigned i = 0; i < defaultMenu.size(); ++i) + defaultMenuArray->append(WebContextMenuItem::create(defaultMenu[i]).get()); + + WKArrayRef newMenuWK = 0; + WKTypeRef userDataToPass = 0; + m_client.getContextMenuFromDefaultMenu(toAPI(page), toAPI(hitTestResult), toAPI(defaultMenuArray.get()), &newMenuWK, &userDataToPass, m_client.clientInfo); + RefPtr<ImmutableArray> array = adoptRef(toImpl(newMenuWK)); + userData = adoptRef(toImpl(userDataToPass)); + + newMenu.clear(); + + if (!array || !array->size()) + return true; + + size_t size = array->size(); + for (size_t i = 0; i < size; ++i) { + WebContextMenuItem* item = array->at<WebContextMenuItem>(i); + if (!item) { + LOG(ContextMenu, "New menu entry at index %i is not a WebContextMenuItem", (int)i); + continue; + } + + newMenu.append(*item->data()); + } + + return true; +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageContextMenuClient.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageContextMenuClient.h new file mode 100644 index 000000000..0d8ea5f83 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageContextMenuClient.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundlePageContextMenuClient_h +#define InjectedBundlePageContextMenuClient_h + +#include "APIClient.h" +#include "WKBundlePage.h" +#include <wtf/Vector.h> + +namespace WebCore { + class ContextMenu; +} + +namespace WebKit { + +class APIObject; +class InjectedBundleHitTestResult; +class WebContextMenuItemData; +class WebPage; + +class InjectedBundlePageContextMenuClient : public APIClient<WKBundlePageContextMenuClient, kWKBundlePageContextMenuClientCurrentVersion> { +public: + bool getCustomMenuFromDefaultItems(WebPage*, InjectedBundleHitTestResult*, const Vector<WebContextMenuItemData>& defaultMenu, Vector<WebContextMenuItemData>& newMenu, RefPtr<APIObject>& userData); +}; + +} // namespace WebKit + +#endif // InjectedBundlePageEditorClient_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageEditorClient.cpp b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageEditorClient.cpp new file mode 100644 index 000000000..633936be1 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageEditorClient.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundlePageEditorClient.h" + +#include "InjectedBundleNodeHandle.h" +#include "InjectedBundleRangeHandle.h" +#include "WKAPICast.h" +#include "WKBundleAPICast.h" +#include <wtf/text/WTFString.h> + +using namespace WebCore; + +namespace WebKit { + +bool InjectedBundlePageEditorClient::shouldBeginEditing(WebPage* page, Range* range) +{ + if (m_client.shouldBeginEditing) { + RefPtr<InjectedBundleRangeHandle> rangeHandle = InjectedBundleRangeHandle::getOrCreate(range); + return m_client.shouldBeginEditing(toAPI(page), toAPI(rangeHandle.get()), m_client.clientInfo); + } + return true; +} + +bool InjectedBundlePageEditorClient::shouldEndEditing(WebPage* page, Range* range) +{ + if (m_client.shouldEndEditing) { + RefPtr<InjectedBundleRangeHandle> rangeHandle = InjectedBundleRangeHandle::getOrCreate(range); + return m_client.shouldEndEditing(toAPI(page), toAPI(rangeHandle.get()), m_client.clientInfo); + } + return true; +} + +bool InjectedBundlePageEditorClient::shouldInsertNode(WebPage* page, Node* node, Range* rangeToReplace, EditorInsertAction action) +{ + if (m_client.shouldInsertNode) { + RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(node); + RefPtr<InjectedBundleRangeHandle> rangeToReplaceHandle = InjectedBundleRangeHandle::getOrCreate(rangeToReplace); + return m_client.shouldInsertNode(toAPI(page), toAPI(nodeHandle.get()), toAPI(rangeToReplaceHandle.get()), toAPI(action), m_client.clientInfo); + } + return true; +} + +bool InjectedBundlePageEditorClient::shouldInsertText(WebPage* page, StringImpl* text, Range* rangeToReplace, EditorInsertAction action) +{ + if (m_client.shouldInsertText) { + RefPtr<InjectedBundleRangeHandle> rangeToReplaceHandle = InjectedBundleRangeHandle::getOrCreate(rangeToReplace); + return m_client.shouldInsertText(toAPI(page), toAPI(text), toAPI(rangeToReplaceHandle.get()), toAPI(action), m_client.clientInfo); + } + return true; +} + +bool InjectedBundlePageEditorClient::shouldDeleteRange(WebPage* page, Range* range) +{ + if (m_client.shouldDeleteRange) { + RefPtr<InjectedBundleRangeHandle> rangeHandle = InjectedBundleRangeHandle::getOrCreate(range); + return m_client.shouldDeleteRange(toAPI(page), toAPI(rangeHandle.get()), m_client.clientInfo); + } + return true; +} + +bool InjectedBundlePageEditorClient::shouldChangeSelectedRange(WebPage* page, Range* fromRange, Range* toRange, EAffinity affinity, bool stillSelecting) +{ + if (m_client.shouldChangeSelectedRange) { + RefPtr<InjectedBundleRangeHandle> fromRangeHandle = InjectedBundleRangeHandle::getOrCreate(fromRange); + RefPtr<InjectedBundleRangeHandle> toRangeHandle = InjectedBundleRangeHandle::getOrCreate(toRange); + return m_client.shouldChangeSelectedRange(toAPI(page), toAPI(fromRangeHandle.get()), toAPI(toRangeHandle.get()), toAPI(affinity), stillSelecting, m_client.clientInfo); + } + return true; +} + +bool InjectedBundlePageEditorClient::shouldApplyStyle(WebPage* page, CSSStyleDeclaration* style, Range* range) +{ + if (m_client.shouldApplyStyle) { + RefPtr<InjectedBundleRangeHandle> rangeHandle = InjectedBundleRangeHandle::getOrCreate(range); + return m_client.shouldApplyStyle(toAPI(page), toAPI(style), toAPI(rangeHandle.get()), m_client.clientInfo); + } + return true; +} + +void InjectedBundlePageEditorClient::didBeginEditing(WebPage* page, StringImpl* notificationName) +{ + if (m_client.didBeginEditing) + m_client.didBeginEditing(toAPI(page), toAPI(notificationName), m_client.clientInfo); +} + +void InjectedBundlePageEditorClient::didEndEditing(WebPage* page, StringImpl* notificationName) +{ + if (m_client.didEndEditing) + m_client.didEndEditing(toAPI(page), toAPI(notificationName), m_client.clientInfo); +} + +void InjectedBundlePageEditorClient::didChange(WebPage* page, StringImpl* notificationName) +{ + if (m_client.didChange) + m_client.didChange(toAPI(page), toAPI(notificationName), m_client.clientInfo); +} + +void InjectedBundlePageEditorClient::didChangeSelection(WebPage* page, StringImpl* notificationName) +{ + if (m_client.didChangeSelection) + m_client.didChangeSelection(toAPI(page), toAPI(notificationName), m_client.clientInfo); +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageEditorClient.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageEditorClient.h new file mode 100644 index 000000000..3bb782233 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageEditorClient.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundlePageEditorClient_h +#define InjectedBundlePageEditorClient_h + +#include "APIClient.h" +#include "WKBundlePage.h" +#include <WebCore/EditorInsertAction.h> +#include <WebCore/TextAffinity.h> +#include <wtf/Forward.h> + +namespace WebCore { + class CSSStyleDeclaration; + class Node; + class Range; +} + +namespace WebKit { + +class WebFrame; +class WebPage; + +class InjectedBundlePageEditorClient : public APIClient<WKBundlePageEditorClient, kWKBundlePageEditorClientCurrentVersion> { +public: + bool shouldBeginEditing(WebPage*, WebCore::Range*); + bool shouldEndEditing(WebPage*, WebCore::Range*); + bool shouldInsertNode(WebPage*, WebCore::Node*, WebCore::Range* rangeToReplace, WebCore::EditorInsertAction); + bool shouldInsertText(WebPage*, StringImpl*, WebCore::Range* rangeToReplace, WebCore::EditorInsertAction); + bool shouldDeleteRange(WebPage*, WebCore::Range*); + bool shouldChangeSelectedRange(WebPage*, WebCore::Range* fromRange, WebCore::Range* toRange, WebCore::EAffinity affinity, bool stillSelecting); + bool shouldApplyStyle(WebPage*, WebCore::CSSStyleDeclaration*, WebCore::Range*); + void didBeginEditing(WebPage*, StringImpl* notificationName); + void didEndEditing(WebPage*, StringImpl* notificationName); + void didChange(WebPage*, StringImpl* notificationName); + void didChangeSelection(WebPage*, StringImpl* notificationName); +}; + +} // namespace WebKit + +#endif // InjectedBundlePageEditorClient_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageFormClient.cpp b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageFormClient.cpp new file mode 100644 index 000000000..39924ec16 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageFormClient.cpp @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundlePageFormClient.h" + +#include "ImmutableDictionary.h" +#include "InjectedBundleNodeHandle.h" +#include "WKAPICast.h" +#include "WKBundleAPICast.h" +#include <WebCore/HTMLFormElement.h> +#include <WebCore/HTMLInputElement.h> +#include <WebCore/HTMLTextAreaElement.h> + +using namespace WebCore; + +namespace WebKit { + +void InjectedBundlePageFormClient::textFieldDidBeginEditing(WebPage* page, HTMLInputElement* inputElement, WebFrame* frame) +{ + if (!m_client.textFieldDidBeginEditing) + return; + + RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(inputElement); + m_client.textFieldDidBeginEditing(toAPI(page), toAPI(nodeHandle.get()), toAPI(frame), m_client.clientInfo); +} + +void InjectedBundlePageFormClient::textFieldDidEndEditing(WebPage* page, HTMLInputElement* inputElement, WebFrame* frame) +{ + if (!m_client.textFieldDidEndEditing) + return; + + RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(inputElement); + m_client.textFieldDidEndEditing(toAPI(page), toAPI(nodeHandle.get()), toAPI(frame), m_client.clientInfo); +} + +void InjectedBundlePageFormClient::textDidChangeInTextField(WebPage* page, HTMLInputElement* inputElement, WebFrame* frame) +{ + if (!m_client.textDidChangeInTextField) + return; + + RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(inputElement); + m_client.textDidChangeInTextField(toAPI(page), toAPI(nodeHandle.get()), toAPI(frame), m_client.clientInfo); +} + +void InjectedBundlePageFormClient::textDidChangeInTextArea(WebPage* page, HTMLTextAreaElement* textAreaElement, WebFrame* frame) +{ + if (!m_client.textDidChangeInTextArea) + return; + + RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(textAreaElement); + m_client.textDidChangeInTextArea(toAPI(page), toAPI(nodeHandle.get()), toAPI(frame), m_client.clientInfo); +} + +bool InjectedBundlePageFormClient::shouldPerformActionInTextField(WebPage* page, HTMLInputElement* inputElement, WKInputFieldActionType actionType, WebFrame* frame) +{ + if (!m_client.shouldPerformActionInTextField) + return false; + + RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(inputElement); + return m_client.shouldPerformActionInTextField(toAPI(page), toAPI(nodeHandle.get()), actionType, toAPI(frame), m_client.clientInfo); +} + +void InjectedBundlePageFormClient::willSubmitForm(WebPage* page, HTMLFormElement* formElement, WebFrame* frame, WebFrame* sourceFrame, const Vector<std::pair<String, String> >& values, RefPtr<APIObject>& userData) +{ + if (!m_client.willSubmitForm) + return; + + RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(formElement); + + ImmutableDictionary::MapType map; + for (size_t i = 0; i < values.size(); ++i) + map.set(values[i].first, WebString::create(values[i].second)); + RefPtr<ImmutableDictionary> textFieldsMap = ImmutableDictionary::adopt(map); + + WKTypeRef userDataToPass = 0; + m_client.willSubmitForm(toAPI(page), toAPI(nodeHandle.get()), toAPI(frame), toAPI(sourceFrame), toAPI(textFieldsMap.get()), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageFormClient.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageFormClient.h new file mode 100644 index 000000000..89369dfb2 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageFormClient.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundlePageFormClient_h +#define InjectedBundlePageFormClient_h + +#include "APIClient.h" +#include "WKBundlePage.h" +#include <algorithm> +#include <wtf/Forward.h> +#include <wtf/Vector.h> + +namespace WebCore { + class HTMLFormElement; + class HTMLInputElement; + class HTMLTextAreaElement; +} + +namespace WebKit { + +class APIObject; +class ImmutableDictionary; +class WebFrame; +class WebPage; + +class InjectedBundlePageFormClient : public APIClient<WKBundlePageFormClient, kWKBundlePageFormClientCurrentVersion> { +public: + void textFieldDidBeginEditing(WebPage*, WebCore::HTMLInputElement*, WebFrame*); + void textFieldDidEndEditing(WebPage*, WebCore::HTMLInputElement*, WebFrame*); + void textDidChangeInTextField(WebPage*, WebCore::HTMLInputElement*, WebFrame*); + void textDidChangeInTextArea(WebPage*, WebCore::HTMLTextAreaElement*, WebFrame*); + bool shouldPerformActionInTextField(WebPage*, WebCore::HTMLInputElement*, WKInputFieldActionType, WebFrame*); + void willSubmitForm(WebPage*, WebCore::HTMLFormElement*, WebFrame*, WebFrame* sourceFrame, const Vector<std::pair<String, String> >&, RefPtr<APIObject>& userData); +}; + +} // namespace WebKit + +#endif // InjectedBundlePageFormClient_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageFullScreenClient.cpp b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageFullScreenClient.cpp new file mode 100644 index 000000000..d8e986f7d --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageFullScreenClient.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#if ENABLE(FULLSCREEN_API) + +#include "InjectedBundlePageFullScreenClient.h" + +#include "InjectedBundleNodeHandle.h" +#include "WKAPICast.h" +#include "WKBundleAPICast.h" +#include "WebFullScreenManagerProxyMessages.h" +#include "WebPage.h" +#include <WebCore/Element.h> + +using namespace WebCore; + +namespace WebKit { + +bool InjectedBundlePageFullScreenClient::supportsFullScreen(WebPage *page, bool withKeyboard) +{ + if (m_client.supportsFullScreen) + return m_client.supportsFullScreen(toAPI(page), withKeyboard); + + bool supports = true; + page->sendSync(Messages::WebFullScreenManagerProxy::SupportsFullScreen(withKeyboard), supports); + return supports; +} + +void InjectedBundlePageFullScreenClient::enterFullScreenForElement(WebPage *page, WebCore::Element *element) +{ + if (m_client.enterFullScreenForElement) { + RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(element); + m_client.enterFullScreenForElement(toAPI(page), toAPI(nodeHandle.get())); + } else + page->send(Messages::WebFullScreenManagerProxy::EnterFullScreen()); +} + +void InjectedBundlePageFullScreenClient::exitFullScreenForElement(WebPage *page, WebCore::Element *element) +{ + if (m_client.exitFullScreenForElement) { + RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(element); + m_client.exitFullScreenForElement(toAPI(page), toAPI(nodeHandle.get())); + } else + page->send(Messages::WebFullScreenManagerProxy::ExitFullScreen()); +} + +} // namespace WebKit + +#endif // ENABLE(FULLSCREEN_API) diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageFullScreenClient.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageFullScreenClient.h new file mode 100644 index 000000000..c45b21780 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageFullScreenClient.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundlePageFullScreenClient_h +#define InjectedBundlePageFullScreenClient_h + +#if ENABLE(FULLSCREEN_API) + +#include "APIClient.h" +#include "WKBundlePage.h" +#include "WebEvent.h" +#include <wtf/Forward.h> + +namespace WebCore { +class Element; +} + +namespace WebKit { + +class WebPage; + +class InjectedBundlePageFullScreenClient : public APIClient<WKBundlePageFullScreenClient, kWKBundlePageFullScreenClientCurrentVersion> { +public: + bool supportsFullScreen(WebPage*, bool withKeyboard); + void enterFullScreenForElement(WebPage*, WebCore::Element*); + void exitFullScreenForElement(WebPage*, WebCore::Element*); +}; + +} // namespace WebKit + +#endif // ENABLE(FULLSCREEN_API) + +#endif // InjectedBundlePageFullScreenClient_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp new file mode 100644 index 000000000..69e357ebe --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp @@ -0,0 +1,230 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundlePageLoaderClient.h" + +#include "InjectedBundleScriptWorld.h" +#include "WKAPICast.h" +#include "WKBundleAPICast.h" +#include "WebError.h" +#include <wtf/text/WTFString.h> + +using namespace WebCore; + +namespace WebKit { + +void InjectedBundlePageLoaderClient::didStartProvisionalLoadForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData) +{ + if (!m_client.didStartProvisionalLoadForFrame) + return; + + WKTypeRef userDataToPass = 0; + m_client.didStartProvisionalLoadForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +void InjectedBundlePageLoaderClient::didReceiveServerRedirectForProvisionalLoadForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData) +{ + if (!m_client.didReceiveServerRedirectForProvisionalLoadForFrame) + return; + + WKTypeRef userDataToPass = 0; + m_client.didReceiveServerRedirectForProvisionalLoadForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +void InjectedBundlePageLoaderClient::didFailProvisionalLoadWithErrorForFrame(WebPage* page, WebFrame* frame, const ResourceError& error, RefPtr<APIObject>& userData) +{ + if (!m_client.didFailProvisionalLoadWithErrorForFrame) + return; + + WKTypeRef userDataToPass = 0; + m_client.didFailProvisionalLoadWithErrorForFrame(toAPI(page), toAPI(frame), toAPI(error), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +void InjectedBundlePageLoaderClient::didCommitLoadForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData) +{ + if (!m_client.didCommitLoadForFrame) + return; + + WKTypeRef userDataToPass = 0; + m_client.didCommitLoadForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +void InjectedBundlePageLoaderClient::didFinishDocumentLoadForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData) +{ + if (!m_client.didFinishDocumentLoadForFrame) + return; + + WKTypeRef userDataToPass = 0; + m_client.didFinishDocumentLoadForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +void InjectedBundlePageLoaderClient::didFinishLoadForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData) +{ + if (!m_client.didFinishLoadForFrame) + return; + + WKTypeRef userDataToPass = 0; + m_client.didFinishLoadForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +void InjectedBundlePageLoaderClient::didFailLoadWithErrorForFrame(WebPage* page, WebFrame* frame, const ResourceError& error, RefPtr<APIObject>& userData) +{ + if (!m_client.didFailLoadWithErrorForFrame) + return; + + WKTypeRef userDataToPass = 0; + m_client.didFailLoadWithErrorForFrame(toAPI(page), toAPI(frame), toAPI(error), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +void InjectedBundlePageLoaderClient::didSameDocumentNavigationForFrame(WebPage* page, WebFrame* frame, SameDocumentNavigationType type, RefPtr<APIObject>& userData) +{ + if (!m_client.didSameDocumentNavigationForFrame) + return; + + WKTypeRef userDataToPass = 0; + m_client.didSameDocumentNavigationForFrame(toAPI(page), toAPI(frame), toAPI(type), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +void InjectedBundlePageLoaderClient::didReceiveTitleForFrame(WebPage* page, const String& title, WebFrame* frame, RefPtr<APIObject>& userData) +{ + if (!m_client.didReceiveTitleForFrame) + return; + + WKTypeRef userDataToPass = 0; + m_client.didReceiveTitleForFrame(toAPI(page), toAPI(title.impl()), toAPI(frame), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +void InjectedBundlePageLoaderClient::didRemoveFrameFromHierarchy(WebPage* page , WebFrame* frame, RefPtr<APIObject>& userData) +{ + if (!m_client.didRemoveFrameFromHierarchy) + return; + + WKTypeRef userDataToPass = 0; + m_client.didRemoveFrameFromHierarchy(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +void InjectedBundlePageLoaderClient::didDisplayInsecureContentForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData) +{ + if (!m_client.didDisplayInsecureContentForFrame) + return; + + WKTypeRef userDataToPass = 0; + m_client.didDisplayInsecureContentForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +void InjectedBundlePageLoaderClient::didRunInsecureContentForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData) +{ + if (!m_client.didRunInsecureContentForFrame) + return; + + WKTypeRef userDataToPass = 0; + m_client.didRunInsecureContentForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +void InjectedBundlePageLoaderClient::didDetectXSSForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData) +{ + if (!m_client.didDetectXSSForFrame) + return; + + WKTypeRef userDataToPass = 0; + m_client.didDetectXSSForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +void InjectedBundlePageLoaderClient::didFirstLayoutForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData) +{ + if (!m_client.didFirstLayoutForFrame) + return; + + WKTypeRef userDataToPass = 0; + m_client.didFirstLayoutForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +void InjectedBundlePageLoaderClient::didFirstVisuallyNonEmptyLayoutForFrame(WebPage* page, WebFrame* frame, RefPtr<APIObject>& userData) +{ + if (!m_client.didFirstVisuallyNonEmptyLayoutForFrame) + return; + + WKTypeRef userDataToPass = 0; + m_client.didFirstVisuallyNonEmptyLayoutForFrame(toAPI(page), toAPI(frame), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + + +void InjectedBundlePageLoaderClient::didLayoutForFrame(WebPage* page, WebFrame* frame) +{ + if (!m_client.didLayoutForFrame) + return; + + m_client.didLayoutForFrame(toAPI(page), toAPI(frame), m_client.clientInfo); +} + +void InjectedBundlePageLoaderClient::didClearWindowObjectForFrame(WebPage* page, WebFrame* frame, DOMWrapperWorld* world) +{ + if (!m_client.didClearWindowObjectForFrame) + return; + + m_client.didClearWindowObjectForFrame(toAPI(page), toAPI(frame), toAPI(InjectedBundleScriptWorld::getOrCreate(world).get()), m_client.clientInfo); +} + +void InjectedBundlePageLoaderClient::didCancelClientRedirectForFrame(WebPage* page, WebFrame* frame) +{ + if (!m_client.didCancelClientRedirectForFrame) + return; + + m_client.didCancelClientRedirectForFrame(toAPI(page), toAPI(frame), m_client.clientInfo); +} + +void InjectedBundlePageLoaderClient::willPerformClientRedirectForFrame(WebPage* page, WebFrame* frame, const String& url, double delay, double date) +{ + if (!m_client.willPerformClientRedirectForFrame) + return; + + m_client.willPerformClientRedirectForFrame(toAPI(page), toAPI(frame), toURLRef(url.impl()), delay, date, m_client.clientInfo); +} + +void InjectedBundlePageLoaderClient::didHandleOnloadEventsForFrame(WebPage* page, WebFrame* frame) +{ + if (!m_client.didHandleOnloadEventsForFrame) + return; + + m_client.didHandleOnloadEventsForFrame(toAPI(page), toAPI(frame), m_client.clientInfo); +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h new file mode 100644 index 000000000..c366c6d00 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundlePageLoaderClient_h +#define InjectedBundlePageLoaderClient_h + +#include "APIClient.h" +#include "SameDocumentNavigationType.h" +#include "WKBundlePage.h" +#include <JavaScriptCore/JSBase.h> +#include <wtf/Forward.h> + +namespace WebCore { +class DOMWrapperWorld; +class ResourceError; +class ResourceRequest; +class ResourceResponse; +} + +namespace WebKit { + +class APIObject; +class WebPage; +class WebFrame; + +class InjectedBundlePageLoaderClient : public APIClient<WKBundlePageLoaderClient, kWKBundlePageLoaderClientCurrentVersion> { +public: + void didStartProvisionalLoadForFrame(WebPage*, WebFrame*, RefPtr<APIObject>& userData); + void didReceiveServerRedirectForProvisionalLoadForFrame(WebPage*, WebFrame*, RefPtr<APIObject>& userData); + void didFailProvisionalLoadWithErrorForFrame(WebPage*, WebFrame*, const WebCore::ResourceError&, RefPtr<APIObject>& userData); + void didCommitLoadForFrame(WebPage*, WebFrame*, RefPtr<APIObject>& userData); + void didFinishDocumentLoadForFrame(WebPage*, WebFrame*, RefPtr<APIObject>& userData); + void didFinishLoadForFrame(WebPage*, WebFrame*, RefPtr<APIObject>& userData); + void didFailLoadWithErrorForFrame(WebPage*, WebFrame*, const WebCore::ResourceError&, RefPtr<APIObject>& userData); + void didSameDocumentNavigationForFrame(WebPage*, WebFrame*, SameDocumentNavigationType, RefPtr<APIObject>& userData); + void didReceiveTitleForFrame(WebPage*, const String&, WebFrame*, RefPtr<APIObject>& userData); + void didRemoveFrameFromHierarchy(WebPage*, WebFrame*, RefPtr<APIObject>& userData); + void didDisplayInsecureContentForFrame(WebPage*, WebFrame*, RefPtr<APIObject>& userData); + void didRunInsecureContentForFrame(WebPage*, WebFrame*, RefPtr<APIObject>& userData); + void didDetectXSSForFrame(WebPage*, WebFrame*, RefPtr<APIObject>& userData); + + void didFirstLayoutForFrame(WebPage*, WebFrame*, RefPtr<APIObject>& userData); + void didFirstVisuallyNonEmptyLayoutForFrame(WebPage*, WebFrame*, RefPtr<APIObject>& userData); + void didLayoutForFrame(WebPage*, WebFrame*); + + void didClearWindowObjectForFrame(WebPage*, WebFrame*, WebCore::DOMWrapperWorld*); + void didCancelClientRedirectForFrame(WebPage*, WebFrame*); + void willPerformClientRedirectForFrame(WebPage*, WebFrame*, const String& url, double delay, double date); + void didHandleOnloadEventsForFrame(WebPage*, WebFrame*); +}; + +} // namespace WebKit + +#endif // InjectedBundlePageLoaderClient_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePagePolicyClient.cpp b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePagePolicyClient.cpp new file mode 100644 index 000000000..b90cf1f9e --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePagePolicyClient.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundlePagePolicyClient.h" + +#include "WKBundleAPICast.h" +#include "WebError.h" +#include "WebURLRequest.h" + +using namespace WebCore; + +namespace WebKit { + +WKBundlePagePolicyAction InjectedBundlePagePolicyClient::decidePolicyForNavigationAction(WebPage* page, WebFrame* frame, InjectedBundleNavigationAction* action, const ResourceRequest& resourceRequest, RefPtr<APIObject>& userData) +{ + if (!m_client.decidePolicyForNavigationAction) + return WKBundlePagePolicyActionPassThrough; + + RefPtr<WebURLRequest> request = WebURLRequest::create(resourceRequest); + + WKTypeRef userDataToPass = 0; + WKBundlePagePolicyAction policy = m_client.decidePolicyForNavigationAction(toAPI(page), toAPI(frame), toAPI(action), toAPI(request.get()), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); + return policy; +} + +WKBundlePagePolicyAction InjectedBundlePagePolicyClient::decidePolicyForNewWindowAction(WebPage* page, WebFrame* frame, InjectedBundleNavigationAction* action, const ResourceRequest& resourceRequest, const String& frameName, RefPtr<APIObject>& userData) +{ + if (!m_client.decidePolicyForNewWindowAction) + return WKBundlePagePolicyActionPassThrough; + + RefPtr<WebURLRequest> request = WebURLRequest::create(resourceRequest); + + WKTypeRef userDataToPass = 0; + WKBundlePagePolicyAction policy = m_client.decidePolicyForNewWindowAction(toAPI(page), toAPI(frame), toAPI(action), toAPI(request.get()), toAPI(frameName.impl()), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); + return policy; +} + +WKBundlePagePolicyAction InjectedBundlePagePolicyClient::decidePolicyForResponse(WebPage* page, WebFrame* frame, const ResourceResponse& resourceResponse, const ResourceRequest& resourceRequest, RefPtr<APIObject>& userData) +{ + if (!m_client.decidePolicyForResponse) + return WKBundlePagePolicyActionPassThrough; + + RefPtr<WebURLResponse> response = WebURLResponse::create(resourceResponse); + RefPtr<WebURLRequest> request = WebURLRequest::create(resourceRequest); + + WKTypeRef userDataToPass = 0; + WKBundlePagePolicyAction policy = m_client.decidePolicyForResponse(toAPI(page), toAPI(frame), toAPI(response.get()), toAPI(request.get()), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); + return policy; +} + +void InjectedBundlePagePolicyClient::unableToImplementPolicy(WebPage* page, WebFrame* frame, const WebCore::ResourceError& error, RefPtr<APIObject>& userData) +{ + if (!m_client.unableToImplementPolicy) + return; + + WKTypeRef userDataToPass = 0; + m_client.unableToImplementPolicy(toAPI(page), toAPI(frame), toAPI(error), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePagePolicyClient.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePagePolicyClient.h new file mode 100644 index 000000000..3cdbebe60 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePagePolicyClient.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundlePagePolicyClient_h +#define InjectedBundlePagePolicyClient_h + +#include "APIClient.h" +#include "APIObject.h" +#include "WKBundlePage.h" +#include <wtf/Forward.h> + +namespace WebCore { + class ResourceError; + class ResourceRequest; + class ResourceResponse; +} + +namespace WebKit { + +class InjectedBundleNavigationAction; +class WebFrame; +class WebPage; + +class InjectedBundlePagePolicyClient : public APIClient<WKBundlePagePolicyClient, kWKBundlePagePolicyClientCurrentVersion> { +public: + WKBundlePagePolicyAction decidePolicyForNavigationAction(WebPage*, WebFrame*, InjectedBundleNavigationAction*, const WebCore::ResourceRequest&, RefPtr<APIObject>& userData); + WKBundlePagePolicyAction decidePolicyForNewWindowAction(WebPage*, WebFrame*, InjectedBundleNavigationAction*, const WebCore::ResourceRequest&, const String& frameName, RefPtr<APIObject>& userData); + WKBundlePagePolicyAction decidePolicyForResponse(WebPage*, WebFrame*, const WebCore::ResourceResponse&, const WebCore::ResourceRequest&, RefPtr<APIObject>& userData); + void unableToImplementPolicy(WebPage*, WebFrame*, const WebCore::ResourceError&, RefPtr<APIObject>& userData); +}; + +} // namespace WebKit + +#endif // InjectedBundlePagePolicyClient_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageResourceLoadClient.cpp b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageResourceLoadClient.cpp new file mode 100644 index 000000000..49dcac6cc --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageResourceLoadClient.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundlePageResourceLoadClient.h" + +#include "WKAPICast.h" +#include "WKBundleAPICast.h" + +using namespace WebCore; + +namespace WebKit { + +void InjectedBundlePageResourceLoadClient::didInitiateLoadForResource(WebPage* page, WebFrame* frame, uint64_t identifier, const WebCore::ResourceRequest& request, bool pageIsProvisionallyLoading) +{ + if (!m_client.didInitiateLoadForResource) + return; + + m_client.didInitiateLoadForResource(toAPI(page), toAPI(frame), identifier, toAPI(request), pageIsProvisionallyLoading, m_client.clientInfo); +} + +void InjectedBundlePageResourceLoadClient::willSendRequestForFrame(WebPage* page, WebFrame* frame, uint64_t identifier, ResourceRequest& request, const ResourceResponse& redirectResponse) +{ + if (!m_client.willSendRequestForFrame) + return; + + RefPtr<WebURLRequest> returnedRequest = adoptRef(toImpl(m_client.willSendRequestForFrame(toAPI(page), toAPI(frame), identifier, toAPI(request), toAPI(redirectResponse), m_client.clientInfo))); + if (returnedRequest) + request = returnedRequest->resourceRequest(); + else + request = ResourceRequest(); +} + +void InjectedBundlePageResourceLoadClient::didReceiveResponseForResource(WebPage* page, WebFrame* frame, uint64_t identifier, const WebCore::ResourceResponse& response) +{ + if (!m_client.didReceiveResponseForResource) + return; + + m_client.didReceiveResponseForResource(toAPI(page), toAPI(frame), identifier, toAPI(response), m_client.clientInfo); +} + +void InjectedBundlePageResourceLoadClient::didReceiveContentLengthForResource(WebPage* page, WebFrame* frame, uint64_t identifier, uint64_t contentLength) +{ + if (!m_client.didReceiveContentLengthForResource) + return; + + m_client.didReceiveContentLengthForResource(toAPI(page), toAPI(frame), identifier, contentLength, m_client.clientInfo); +} + +void InjectedBundlePageResourceLoadClient::didFinishLoadForResource(WebPage* page, WebFrame* frame, uint64_t identifier) +{ + if (!m_client.didFinishLoadForResource) + return; + + m_client.didFinishLoadForResource(toAPI(page), toAPI(frame), identifier, m_client.clientInfo); +} + +void InjectedBundlePageResourceLoadClient::didFailLoadForResource(WebPage* page, WebFrame* frame, uint64_t identifier, const WebCore::ResourceError& error) +{ + if (!m_client.didFailLoadForResource) + return; + + m_client.didFailLoadForResource(toAPI(page), toAPI(frame), identifier, toAPI(error), m_client.clientInfo); +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageResourceLoadClient.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageResourceLoadClient.h new file mode 100644 index 000000000..68c68205c --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageResourceLoadClient.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundlePageResourceLoadClient_h +#define InjectedBundlePageResourceLoadClient_h + +#include "APIClient.h" +#include "SameDocumentNavigationType.h" +#include "WKBundlePage.h" +#include <JavaScriptCore/JSBase.h> +#include <wtf/Forward.h> + +namespace WebCore { +class ResourceError; +class ResourceRequest; +class ResourceResponse; +} + +namespace WebKit { + +class APIObject; +class WebPage; +class WebFrame; + +class InjectedBundlePageResourceLoadClient : public APIClient<WKBundlePageResourceLoadClient, kWKBundlePageResourceLoadClientCurrentVersion> { +public: + void didInitiateLoadForResource(WebPage*, WebFrame*, uint64_t identifier, const WebCore::ResourceRequest&, bool pageIsProvisionallyLoading); + void willSendRequestForFrame(WebPage*, WebFrame*, uint64_t identifier, WebCore::ResourceRequest&, const WebCore::ResourceResponse&); + void didReceiveResponseForResource(WebPage*, WebFrame*, uint64_t identifier, const WebCore::ResourceResponse&); + void didReceiveContentLengthForResource(WebPage*, WebFrame*, uint64_t identifier, uint64_t contentLength); + void didFinishLoadForResource(WebPage*, WebFrame*, uint64_t identifier); + void didFailLoadForResource(WebPage*, WebFrame*, uint64_t identifier, const WebCore::ResourceError&); +}; + +} // namespace WebKit + +#endif // InjectedBundlePageResourceLoadClient_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp new file mode 100644 index 000000000..b8c9c6206 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundlePageUIClient.h" + +#include "InjectedBundleHitTestResult.h" +#include "WKAPICast.h" +#include "WebGraphicsContext.h" +#include "WKBundleAPICast.h" +#include <wtf/text/WTFString.h> + +using namespace WebCore; + +namespace WebKit { + +void InjectedBundlePageUIClient::willAddMessageToConsole(WebPage* page, const String& message, int32_t lineNumber) +{ + if (m_client.willAddMessageToConsole) + m_client.willAddMessageToConsole(toAPI(page), toAPI(message.impl()), lineNumber, m_client.clientInfo); +} + +void InjectedBundlePageUIClient::willSetStatusbarText(WebPage* page, const String& statusbarText) +{ + if (m_client.willSetStatusbarText) + m_client.willSetStatusbarText(toAPI(page), toAPI(statusbarText.impl()), m_client.clientInfo); +} + +void InjectedBundlePageUIClient::willRunJavaScriptAlert(WebPage* page, const String& alertText, WebFrame* frame) +{ + if (m_client.willRunJavaScriptAlert) + m_client.willRunJavaScriptAlert(toAPI(page), toAPI(alertText.impl()), toAPI(frame), m_client.clientInfo); +} + +void InjectedBundlePageUIClient::willRunJavaScriptConfirm(WebPage* page, const String& message, WebFrame* frame) +{ + if (m_client.willRunJavaScriptConfirm) + m_client.willRunJavaScriptConfirm(toAPI(page), toAPI(message.impl()), toAPI(frame), m_client.clientInfo); +} + +void InjectedBundlePageUIClient::willRunJavaScriptPrompt(WebPage* page, const String& message, const String& defaultValue, WebFrame* frame) +{ + if (m_client.willRunJavaScriptPrompt) + m_client.willRunJavaScriptPrompt(toAPI(page), toAPI(message.impl()), toAPI(defaultValue.impl()), toAPI(frame), m_client.clientInfo); +} + +void InjectedBundlePageUIClient::mouseDidMoveOverElement(WebPage* page, const HitTestResult& coreHitTestResult, WebEvent::Modifiers modifiers, RefPtr<APIObject>& userData) +{ + if (!m_client.mouseDidMoveOverElement) + return; + + RefPtr<InjectedBundleHitTestResult> hitTestResult = InjectedBundleHitTestResult::create(coreHitTestResult); + + WKTypeRef userDataToPass = 0; + m_client.mouseDidMoveOverElement(toAPI(page), toAPI(hitTestResult.get()), toAPI(modifiers), &userDataToPass, m_client.clientInfo); + userData = adoptRef(toImpl(userDataToPass)); +} + +void InjectedBundlePageUIClient::pageDidScroll(WebPage* page) +{ + if (!m_client.pageDidScroll) + return; + + m_client.pageDidScroll(toAPI(page), m_client.clientInfo); +} + +bool InjectedBundlePageUIClient::shouldPaintCustomOverhangArea() +{ + return m_client.paintCustomOverhangArea; +} + +void InjectedBundlePageUIClient::paintCustomOverhangArea(WebPage* page, GraphicsContext* graphicsContext, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect) +{ + ASSERT(shouldPaintCustomOverhangArea()); + + RefPtr<WebGraphicsContext> context = WebGraphicsContext::create(graphicsContext); + m_client.paintCustomOverhangArea(toAPI(page), toAPI(context.get()), toAPI(horizontalOverhangArea), toAPI(verticalOverhangArea), toAPI(dirtyRect), m_client.clientInfo); +} + +String InjectedBundlePageUIClient::shouldGenerateFileForUpload(WebPage* page, const String& originalFilePath) +{ + if (!m_client.shouldGenerateFileForUpload) + return String(); + RefPtr<WebString> generatedFilePath = adoptRef(toImpl(m_client.shouldGenerateFileForUpload(toAPI(page), toAPI(originalFilePath.impl()), m_client.clientInfo))); + return generatedFilePath ? generatedFilePath->string() : String(); +} + +String InjectedBundlePageUIClient::generateFileForUpload(WebPage* page, const String& originalFilePath) +{ + if (!m_client.shouldGenerateFileForUpload) + return String(); + RefPtr<WebString> generatedFilePath = adoptRef(toImpl(m_client.generateFileForUpload(toAPI(page), toAPI(originalFilePath.impl()), m_client.clientInfo))); + return generatedFilePath ? generatedFilePath->string() : String(); +} + +bool InjectedBundlePageUIClient::shouldRubberBandInDirection(WebPage* page, WKScrollDirection direction) const +{ + if (!m_client.shouldRubberBandInDirection) + return true; + return m_client.shouldRubberBandInDirection(toAPI(page), direction, m_client.clientInfo); +} + +WKBundlePageUIElementVisibility InjectedBundlePageUIClient::statusBarIsVisible(WebPage* page) +{ + if (!m_client.statusBarIsVisible) + return WKBundlePageUIElementVisibilityUnknown; + + return m_client.statusBarIsVisible(toAPI(page), m_client.clientInfo); +} + +WKBundlePageUIElementVisibility InjectedBundlePageUIClient::menuBarIsVisible(WebPage* page) +{ + if (!m_client.menuBarIsVisible) + return WKBundlePageUIElementVisibilityUnknown; + + return m_client.menuBarIsVisible(toAPI(page), m_client.clientInfo); +} + +WKBundlePageUIElementVisibility InjectedBundlePageUIClient::toolbarsAreVisible(WebPage* page) +{ + if (!m_client.toolbarsAreVisible) + return WKBundlePageUIElementVisibilityUnknown; + + return m_client.toolbarsAreVisible(toAPI(page), m_client.clientInfo); +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageUIClient.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageUIClient.h new file mode 100644 index 000000000..de2928aa5 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageUIClient.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundlePageUIClient_h +#define InjectedBundlePageUIClient_h + +#include "APIClient.h" +#include "WKBundlePage.h" +#include "WebEvent.h" +#include <wtf/Forward.h> + +namespace WebCore { + class GraphicsContext; + class HitTestResult; + class IntRect; +} + +namespace WebKit { + +class APIObject; +class WebFrame; +class WebPage; + +class InjectedBundlePageUIClient : public APIClient<WKBundlePageUIClient, kWKBundlePageUIClientCurrentVersion> { +public: + void willAddMessageToConsole(WebPage*, const String& message, int32_t lineNumber); + void willSetStatusbarText(WebPage*, const String&); + void willRunJavaScriptAlert(WebPage*, const String&, WebFrame*); + void willRunJavaScriptConfirm(WebPage*, const String&, WebFrame*); + void willRunJavaScriptPrompt(WebPage*, const String&, const String&, WebFrame*); + void mouseDidMoveOverElement(WebPage*, const WebCore::HitTestResult&, WebEvent::Modifiers, RefPtr<APIObject>& userData); + void pageDidScroll(WebPage*); + + bool shouldPaintCustomOverhangArea(); + void paintCustomOverhangArea(WebPage*, WebCore::GraphicsContext*, const WebCore::IntRect&, const WebCore::IntRect&, const WebCore::IntRect&); + + String shouldGenerateFileForUpload(WebPage*, const String& originalFilePath); + String generateFileForUpload(WebPage*, const String& originalFilePath); + + bool shouldRubberBandInDirection(WebPage*, WKScrollDirection) const; + + WKBundlePageUIElementVisibility statusBarIsVisible(WebPage*); + WKBundlePageUIElementVisibility menuBarIsVisible(WebPage*); + WKBundlePageUIElementVisibility toolbarsAreVisible(WebPage*); +}; + +} // namespace WebKit + +#endif // InjectedBundlePageUIClient_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp new file mode 100644 index 000000000..2f40fd305 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleScriptWorld.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundleScriptWorld.h" + +#include <WebCore/DOMWrapperWorld.h> +#include <WebCore/ScriptController.h> +#include <wtf/HashMap.h> + +using namespace WebCore; + +namespace WebKit { + +typedef HashMap<DOMWrapperWorld*, InjectedBundleScriptWorld*> WorldMap; + +static WorldMap& allWorlds() +{ + DEFINE_STATIC_LOCAL(WorldMap, map, ()); + return map; +} + +PassRefPtr<InjectedBundleScriptWorld> InjectedBundleScriptWorld::create() +{ + return adoptRef(new InjectedBundleScriptWorld(ScriptController::createWorld())); +} + +PassRefPtr<InjectedBundleScriptWorld> InjectedBundleScriptWorld::getOrCreate(DOMWrapperWorld* world) +{ + if (world == mainThreadNormalWorld()) + return normalWorld(); + + if (InjectedBundleScriptWorld* existingWorld = allWorlds().get(world)) + return existingWorld; + + return adoptRef(new InjectedBundleScriptWorld(world)); +} + +InjectedBundleScriptWorld* InjectedBundleScriptWorld::normalWorld() +{ + static InjectedBundleScriptWorld* world = adoptRef(new InjectedBundleScriptWorld(mainThreadNormalWorld())).leakRef(); + return world; +} + +InjectedBundleScriptWorld::InjectedBundleScriptWorld(PassRefPtr<DOMWrapperWorld> world) + : m_world(world) +{ + ASSERT(!allWorlds().contains(m_world.get())); + allWorlds().add(m_world.get(), this); +} + +InjectedBundleScriptWorld::~InjectedBundleScriptWorld() +{ + ASSERT(allWorlds().contains(m_world.get())); + allWorlds().remove(m_world.get()); +} + +DOMWrapperWorld* InjectedBundleScriptWorld::coreWorld() const +{ + return m_world.get(); +} + +void InjectedBundleScriptWorld::clearWrappers() +{ + m_world->clearWrappers(); +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleScriptWorld.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleScriptWorld.h new file mode 100644 index 000000000..7562a6f8f --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleScriptWorld.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundleScriptWorld_h +#define InjectedBundleScriptWorld_h + +#include "APIObject.h" +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> + +namespace WebCore { + class DOMWrapperWorld; +} + +namespace WebKit { + +class InjectedBundleScriptWorld : public APIObject { +public: + static const Type APIType = TypeBundleScriptWorld; + + static PassRefPtr<InjectedBundleScriptWorld> create(); + static PassRefPtr<InjectedBundleScriptWorld> getOrCreate(WebCore::DOMWrapperWorld*); + static InjectedBundleScriptWorld* normalWorld(); + + virtual ~InjectedBundleScriptWorld(); + + WebCore::DOMWrapperWorld* coreWorld() const; + + void clearWrappers(); + +private: + InjectedBundleScriptWorld(PassRefPtr<WebCore::DOMWrapperWorld>); + + virtual Type type() const { return APIType; } + + RefPtr<WebCore::DOMWrapperWorld> m_world; +}; + +} // namespace WebKit + +#endif // InjectedBundleScriptWorld_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleUserMessageCoders.h b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleUserMessageCoders.h new file mode 100644 index 000000000..49d66966a --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleUserMessageCoders.h @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef InjectedBundleUserMessageCoders_h +#define InjectedBundleUserMessageCoders_h + +#include "UserMessageCoders.h" +#include "WebFrame.h" +#include "WebPage.h" +#include "WebPageGroupData.h" +#include "WebPageGroupProxy.h" +#include "WebProcess.h" + +namespace WebKit { + +// Adds +// - BundlePage -> Page +// - BundleFrame -> Frame +// - BundlePageGroup -> PageGroup + +class InjectedBundleUserMessageEncoder : public UserMessageEncoder<InjectedBundleUserMessageEncoder> { +public: + typedef UserMessageEncoder<InjectedBundleUserMessageEncoder> Base; + + InjectedBundleUserMessageEncoder(APIObject* root) + : Base(root) + { + } + + void encode(CoreIPC::ArgumentEncoder* encoder) const + { + APIObject::Type type = APIObject::TypeNull; + if (baseEncode(encoder, type)) + return; + + switch (type) { + case APIObject::TypeBundlePage: { + WebPage* page = static_cast<WebPage*>(m_root); + encoder->encode(page->pageID()); + break; + } + case APIObject::TypeBundleFrame: { + WebFrame* frame = static_cast<WebFrame*>(m_root); + encoder->encode(frame->frameID()); + break; + } + case APIObject::TypeBundlePageGroup: { + WebPageGroupProxy* pageGroup = static_cast<WebPageGroupProxy*>(m_root); + encoder->encode(pageGroup->pageGroupID()); + break; + } + default: + ASSERT_NOT_REACHED(); + break; + } + } +}; + +// Adds +// - Page -> BundlePage +// - Frame -> BundleFrame +// - PageGroup -> BundlePageGroup + +class InjectedBundleUserMessageDecoder : public UserMessageDecoder<InjectedBundleUserMessageDecoder> { +public: + typedef UserMessageDecoder<InjectedBundleUserMessageDecoder> Base; + + InjectedBundleUserMessageDecoder(RefPtr<APIObject>& root) + : Base(root) + { + } + + InjectedBundleUserMessageDecoder(InjectedBundleUserMessageDecoder&, RefPtr<APIObject>& root) + : Base(root) + { + } + + static bool decode(CoreIPC::ArgumentDecoder* decoder, InjectedBundleUserMessageDecoder& coder) + { + APIObject::Type type = APIObject::TypeNull; + if (!Base::baseDecode(decoder, coder, type)) + return false; + + if (coder.m_root || type == APIObject::TypeNull) + return true; + + switch (type) { + case APIObject::TypePage: { + uint64_t pageID; + if (!decoder->decode(pageID)) + return false; + coder.m_root = WebProcess::shared().webPage(pageID); + break; + } + case APIObject::TypeFrame: { + uint64_t frameID; + if (!decoder->decode(frameID)) + return false; + coder.m_root = WebProcess::shared().webFrame(frameID); + break; + } + case APIObject::TypePageGroup: { + WebPageGroupData pageGroupData; + if (!decoder->decode(pageGroupData)) + return false; + coder.m_root = WebProcess::shared().webPageGroup(pageGroupData); + break; + } + default: + return false; + } + + return true; + } +}; + +} // namespace WebKit + +#endif // InjectedBundleUserMessageCoders_h diff --git a/Source/WebKit2/WebProcess/InjectedBundle/efl/InjectedBundleEfl.cpp b/Source/WebKit2/WebProcess/InjectedBundle/efl/InjectedBundleEfl.cpp new file mode 100644 index 000000000..294ca06a6 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/efl/InjectedBundleEfl.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2011 Samsung Electronics + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundle.h" + +#include "WKBundleAPICast.h" +#include "WKBundleInitialize.h" +#include <WebCore/NotImplemented.h> + +using namespace WebCore; + +namespace WebKit { + +bool InjectedBundle::load(APIObject*) +{ + return false; +} + +void InjectedBundle::activateMacFontAscentHack() +{ + notImplemented(); +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/gtk/InjectedBundleGtk.cpp b/Source/WebKit2/WebProcess/InjectedBundle/gtk/InjectedBundleGtk.cpp new file mode 100644 index 000000000..ca1a43f8c --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/gtk/InjectedBundleGtk.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundle.h" + +#include "WKBundleAPICast.h" +#include "WKBundleInitialize.h" +#include <WebCore/FileSystem.h> +#include <wtf/text/CString.h> + +using namespace WebCore; + +namespace WebKit { + +bool InjectedBundle::load(APIObject* initializationUserData) +{ + m_platformBundle = g_module_open(fileSystemRepresentation(m_path).data(), G_MODULE_BIND_LOCAL); + if (!m_platformBundle) { + g_warning("Error loading the injected bundle (%s): %s", m_path.utf8().data(), g_module_error()); + return false; + } + + WKBundleInitializeFunctionPtr initializeFunction = 0; + if (!g_module_symbol(m_platformBundle, "WKBundleInitialize", reinterpret_cast<void**>(&initializeFunction)) || !initializeFunction) { + g_warning("Error loading WKBundleInitialize symbol from injected bundle."); + return false; + } + + initializeFunction(toAPI(this), toAPI(initializationUserData)); + return true; +} + +void InjectedBundle::activateMacFontAscentHack() +{ +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/mac/InjectedBundleMac.cpp b/Source/WebKit2/WebProcess/InjectedBundle/mac/InjectedBundleMac.cpp new file mode 100644 index 000000000..b9973ad17 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/mac/InjectedBundleMac.cpp @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundle.h" + +#include "WKBundleAPICast.h" +#include "WKBundleInitialize.h" +#include <stdio.h> +#include <wtf/RetainPtr.h> +#include <wtf/text/CString.h> +#include <wtf/text/WTFString.h> + +using namespace WebCore; + +namespace WebKit { + +bool InjectedBundle::load(APIObject* initializationUserData) +{ + if (m_sandboxExtension) { + if (!m_sandboxExtension->consume()) { + fprintf(stderr, "InjectedBundle::load failed - Could not consume bundle sandbox extension for [%s].\n", m_path.utf8().data()); + return false; + } + + m_sandboxExtension = 0; + } + + RetainPtr<CFStringRef> injectedBundlePathStr(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(m_path.characters()), m_path.length())); + if (!injectedBundlePathStr) { + fprintf(stderr, "InjectedBundle::load failed - Could not create the path string.\n"); + return false; + } + + RetainPtr<CFURLRef> bundleURL(AdoptCF, CFURLCreateWithFileSystemPath(0, injectedBundlePathStr.get(), kCFURLPOSIXPathStyle, false)); + if (!bundleURL) { + fprintf(stderr, "InjectedBundle::load failed - Could not create the url from the path string.\n"); + return false; + } + + m_platformBundle = CFBundleCreate(0, bundleURL.get()); + if (!m_platformBundle) { + fprintf(stderr, "InjectedBundle::load failed - Could not create the bundle.\n"); + return false; + } + + if (!CFBundleLoadExecutable(m_platformBundle)) { + fprintf(stderr, "InjectedBundle::load failed - Could not load the executable from the bundle.\n"); + return false; + } + + WKBundleInitializeFunctionPtr initializeFunction = reinterpret_cast<WKBundleInitializeFunctionPtr>(CFBundleGetFunctionPointerForName(m_platformBundle, CFSTR("WKBundleInitialize"))); + if (!initializeFunction) { + fprintf(stderr, "InjectedBundle::load failed - Could not find the initialize function in the bundle executable.\n"); + return false; + } + + initializeFunction(toAPI(this), toAPI(initializationUserData)); + return true; +} + +void InjectedBundle::activateMacFontAscentHack() +{ +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/qt/InjectedBundleQt.cpp b/Source/WebKit2/WebProcess/InjectedBundle/qt/InjectedBundleQt.cpp new file mode 100644 index 000000000..a5183b135 --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/qt/InjectedBundleQt.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010 University of Szeged. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundle.h" + +#include "WKBundleAPICast.h" +#include "WKBundleInitialize.h" + +using namespace WebCore; + +namespace WebKit { + +bool InjectedBundle::load(APIObject* initializationUserData) +{ + m_platformBundle.setFileName(static_cast<QString>(m_path)); + if (!m_platformBundle.load()) { + qWarning("Error loading the injected bundle: %s", qPrintable(m_platformBundle.errorString())); + return false; + } + + WKBundleInitializeFunctionPtr initializeFunction = + reinterpret_cast<WKBundleInitializeFunctionPtr>(m_platformBundle.resolve("WKBundleInitialize")); + + if (!initializeFunction) { + qWarning("Error resolving WKBundleInitialize: %s", qPrintable(m_platformBundle.errorString())); + return false; + } + + initializeFunction(toAPI(this), toAPI(initializationUserData)); + return true; +} + +void InjectedBundle::activateMacFontAscentHack() +{ +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/InjectedBundle/win/InjectedBundleWin.cpp b/Source/WebKit2/WebProcess/InjectedBundle/win/InjectedBundleWin.cpp new file mode 100644 index 000000000..08c9a937b --- /dev/null +++ b/Source/WebKit2/WebProcess/InjectedBundle/win/InjectedBundleWin.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "InjectedBundle.h" + +#include "WKBundleAPICast.h" +#include "WKBundleInitialize.h" +#include "WebCertificateInfo.h" +#include <WebCore/ResourceHandle.h> +#include <WebCore/SimpleFontData.h> +#include <wtf/text/CString.h> + +#include <windows.h> +#include <winbase.h> +#include <shlobj.h> +#include <shlwapi.h> + +#if USE(CFNETWORK) +#include <WebCore/CertificateCFWin.h> +#endif + +using namespace WebCore; + +namespace WebKit { + +// FIXME: This should try and use <WebCore/FileSystem.h>. + +static String pathGetFileName(const String& path) +{ + return String(::PathFindFileName(String(path).charactersWithNullTermination())); +} + +static String directoryName(const String& path) +{ + String fileName = pathGetFileName(path); + String dirName = String(path); + dirName.truncate(dirName.length() - pathGetFileName(path).length()); + return dirName; +} + +bool InjectedBundle::load(APIObject* initializationUserData) +{ + WCHAR currentPath[MAX_PATH]; + if (!::GetCurrentDirectoryW(MAX_PATH, currentPath)) + return false; + + String directorBundleResidesIn = directoryName(m_path); + if (!::SetCurrentDirectoryW(directorBundleResidesIn.charactersWithNullTermination())) + return false; + + m_platformBundle = ::LoadLibraryExW(m_path.charactersWithNullTermination(), 0, LOAD_WITH_ALTERED_SEARCH_PATH); + if (!m_platformBundle) + return false; + + // Reset the current directory. + if (!::SetCurrentDirectoryW(currentPath)) { + return false; + } + + WKBundleInitializeFunctionPtr initializeFunction = reinterpret_cast<WKBundleInitializeFunctionPtr>(::GetProcAddress(m_platformBundle, "WKBundleInitialize")); + if (!initializeFunction) + return false; + + initializeFunction(toAPI(this), toAPI(initializationUserData)); + return true; +} + +void InjectedBundle::activateMacFontAscentHack() +{ + SimpleFontData::setShouldApplyMacAscentHack(true); +} + +void InjectedBundle::setHostAllowsAnyHTTPSCertificate(const String& host) +{ +#if USE(CFNETWORK) + ResourceHandle::setHostAllowsAnyHTTPSCertificate(host); +#endif +} + +void InjectedBundle::setClientCertificate(const String& host, const String& certificateSystemStoreName, const WebCertificateInfo* certificateInfo) +{ +#if USE(CFNETWORK) + ASSERT_ARG(certificateInfo, certificateInfo); + if (!certificateInfo) + return; + + const Vector<PCCERT_CONTEXT> certificateChain = certificateInfo->platformCertificateInfo().certificateChain(); + ASSERT(certificateChain.size() == 1); + if (certificateChain.size() != 1) + return; + + ASSERT_ARG(certificateSystemStoreName, !certificateSystemStoreName.isEmpty()); + if (certificateSystemStoreName.isEmpty()) + return; + + // The PCCERT_CONTEXT in the WebCertificateInfo we created using the message from the UI process doesn't contain enough information + // to actually use it in a request, we need to get the real certificate from the certificate store (which is typically the "MY" store). + String mutableCertificateSystemStoreName = certificateSystemStoreName; + HCERTSTORE certStore = ::CertOpenSystemStore(0, mutableCertificateSystemStoreName.charactersWithNullTermination()); + if (!certStore) { + LOG_ERROR("Could not open system certificate store %s", certificateSystemStoreName.ascii().data()); + return; + } + + PCCERT_CONTEXT realCert = ::CertFindCertificateInStore(certStore, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0, CERT_FIND_EXISTING, certificateChain.first(), 0); + if (!realCert) { + LOG_ERROR("Could not find certificate in system certificate store"); + return; + } + + ResourceHandle::setClientCertificate(host, WebCore::copyCertificateToData(realCert).get()); + CertFreeCertificateContext(realCert); + + // We can't close certStore here, since the certificate is still in use. +#endif +} + +} // namespace WebKit |
