diff options
Diffstat (limited to 'Source/WebKit2/UIProcess/API')
148 files changed, 4014 insertions, 1007 deletions
diff --git a/Source/WebKit2/UIProcess/API/C/WKContext.cpp b/Source/WebKit2/UIProcess/API/C/WKContext.cpp index 28a70821b..a41a762d1 100644 --- a/Source/WebKit2/UIProcess/API/C/WKContext.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKContext.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2011, 2012 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -300,6 +300,12 @@ void WKContextSetJavaScriptGarbageCollectorTimerEnabled(WKContextRef contextRef, { toImpl(contextRef)->setJavaScriptGarbageCollectorTimerEnabled(enable); } + +void WKContextSetUsesNetworkProcess(WKContextRef contextRef, bool usesNetworkProcess) +{ + toImpl(contextRef)->setUsesNetworkProcess(usesNetworkProcess); +} + // Deprecated functions. void _WKContextSetAdditionalPluginsDirectory(WKContextRef context, WKStringRef pluginsDirectory) { diff --git a/Source/WebKit2/UIProcess/API/C/WKContextPrivate.h b/Source/WebKit2/UIProcess/API/C/WKContextPrivate.h index 49aec7f53..8aa9c0b0c 100644 --- a/Source/WebKit2/UIProcess/API/C/WKContextPrivate.h +++ b/Source/WebKit2/UIProcess/API/C/WKContextPrivate.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2012 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -70,6 +70,10 @@ WK_EXPORT void WKContextSetHTTPPipeliningEnabled(WKContextRef context, bool enab WK_EXPORT void WKContextWarmInitialProcess(WKContextRef context); +// FIXME: This function is temporary and useful during the development of the NetworkProcess feature. +// At some point it should be removed. +WK_EXPORT void WKContextSetUsesNetworkProcess(WKContextRef context, bool usesNetworkProcess); + #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.cpp b/Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.cpp index 99195c79c..5d94f3e86 100644 --- a/Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 Apple Inc. All rights reserved. + * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,6 +38,11 @@ WKTypeID WKGeolocationPositionGetTypeID() WKGeolocationPositionRef WKGeolocationPositionCreate(double timestamp, double latitude, double longitude, double accuracy) { - RefPtr<WebGeolocationPosition> position = WebGeolocationPosition::create(timestamp, latitude, longitude, accuracy); + return WKGeolocationPositionCreate_b(timestamp, latitude, longitude, accuracy, false, 0., false, 0., false, 0., false, 0.); +} + +WKGeolocationPositionRef WKGeolocationPositionCreate_b(double timestamp, double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed) +{ + RefPtr<WebGeolocationPosition> position = WebGeolocationPosition::create(timestamp, latitude, longitude, accuracy, providesAltitude, altitude, providesAltitudeAccuracy, altitudeAccuracy, providesHeading, heading, providesSpeed, speed); return toAPI(position.release().leakRef()); } diff --git a/Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.h b/Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.h index 85183fd60..4727e9763 100644 --- a/Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.h +++ b/Source/WebKit2/UIProcess/API/C/WKGeolocationPosition.h @@ -35,6 +35,7 @@ extern "C" { WK_EXPORT WKTypeID WKGeolocationPositionGetTypeID(); WK_EXPORT WKGeolocationPositionRef WKGeolocationPositionCreate(double timestamp, double latitude, double longitude, double accuracy); +WK_EXPORT WKGeolocationPositionRef WKGeolocationPositionCreate_b(double timestamp, double latitude, double longitude, double accuracy, bool providesAltitude, double altitude, bool providesAltitudeAccuracy, double altitudeAccuracy, bool providesHeading, double heading, bool providesSpeed, double speed); #ifdef __cplusplus } diff --git a/Source/WebKit2/UIProcess/API/C/WKIconDatabase.h b/Source/WebKit2/UIProcess/API/C/WKIconDatabase.h index 45ceec765..eec4ab3af 100644 --- a/Source/WebKit2/UIProcess/API/C/WKIconDatabase.h +++ b/Source/WebKit2/UIProcess/API/C/WKIconDatabase.h @@ -35,16 +35,22 @@ extern "C" { // IconDatabase Client. typedef void (*WKIconDatabaseDidChangeIconForPageURLCallback)(WKIconDatabaseRef iconDatabase, WKURLRef pageURL, const void* clientInfo); typedef void (*WKIconDatabaseDidRemoveAllIconsCallback)(WKIconDatabaseRef iconDatabase, const void* clientInfo); +typedef void (*WKIconDatabaseIconDataReadyForPageURLCallback)(WKIconDatabaseRef iconDatabase, WKURLRef pageURL, const void* clientInfo); struct WKIconDatabaseClient { int version; const void * clientInfo; + + // Version 0 WKIconDatabaseDidChangeIconForPageURLCallback didChangeIconForPageURL; WKIconDatabaseDidRemoveAllIconsCallback didRemoveAllIcons; + + // Version 1 + WKIconDatabaseIconDataReadyForPageURLCallback iconDataReadyForPageURL; }; typedef struct WKIconDatabaseClient WKIconDatabaseClient; -enum { kWKIconDatabaseClientCurrentVersion = 0 }; +enum { kWKIconDatabaseClientCurrentVersion = 1 }; WK_EXPORT WKTypeID WKIconDatabaseGetTypeID(); diff --git a/Source/WebKit2/UIProcess/API/C/WKPage.cpp b/Source/WebKit2/UIProcess/API/C/WKPage.cpp index 94fda474a..52e1cebf8 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPage.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKPage.cpp @@ -365,6 +365,16 @@ bool WKPageIsPinnedToRightSide(WKPageRef pageRef) return toImpl(pageRef)->isPinnedToRightSide(); } +bool WKPageIsPinnedToTopSide(WKPageRef pageRef) +{ + return toImpl(pageRef)->isPinnedToTopSide(); +} + +bool WKPageIsPinnedToBottomSide(WKPageRef pageRef) +{ + return toImpl(pageRef)->isPinnedToBottomSide(); +} + void WKPageSetPaginationMode(WKPageRef pageRef, WKPaginationMode paginationMode) { Pagination::Mode mode; @@ -738,3 +748,7 @@ void WKPagePostMessageToInjectedBundle(WKPageRef pageRef, WKStringRef messageNam toImpl(pageRef)->postMessageToInjectedBundle(toImpl(messageNameRef)->string(), toImpl(messageBodyRef)); } +WKArrayRef WKPageCopyRelatedPages(WKPageRef pageRef) +{ + return toAPI(toImpl(pageRef)->relatedPages().leakRef()); +} diff --git a/Source/WebKit2/UIProcess/API/C/WKPage.h b/Source/WebKit2/UIProcess/API/C/WKPage.h index 62db9174c..9dfd52e3c 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPage.h +++ b/Source/WebKit2/UIProcess/API/C/WKPage.h @@ -439,6 +439,8 @@ WK_EXPORT bool WKPageAreScrollbarAnimationsSuppressed(WKPageRef page); WK_EXPORT bool WKPageIsPinnedToLeftSide(WKPageRef page); WK_EXPORT bool WKPageIsPinnedToRightSide(WKPageRef page); +WK_EXPORT bool WKPageIsPinnedToTopSide(WKPageRef page); +WK_EXPORT bool WKPageIsPinnedToBottomSide(WKPageRef page); WK_EXPORT bool WKPageCanDelete(WKPageRef page); WK_EXPORT bool WKPageHasSelectedRange(WKPageRef page); diff --git a/Source/WebKit2/UIProcess/API/C/WKPageGroup.cpp b/Source/WebKit2/UIProcess/API/C/WKPageGroup.cpp index 8a4d86a05..5559d0180 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPageGroup.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKPageGroup.cpp @@ -57,3 +57,13 @@ WKPreferencesRef WKPageGroupGetPreferences(WKPageGroupRef pageGroupRef) { return toAPI(toImpl(pageGroupRef)->preferences()); } + +void WKPageGroupAddUserStyleSheet(WKPageGroupRef pageGroupRef, WKStringRef sourceRef, WKURLRef baseURL, WKArrayRef whitelist, WKArrayRef blacklist, WKUserContentInjectedFrames injectedFrames) +{ + toImpl(pageGroupRef)->addUserStyleSheet(toWTFString(sourceRef), toWTFString(baseURL), toImpl(whitelist), toImpl(blacklist), toUserContentInjectedFrames(injectedFrames), WebCore::UserStyleUserLevel); +} + +void WKPageGroupRemoveAllUserStyleSheets(WKPageGroupRef pageGroupRef) +{ + toImpl(pageGroupRef)->removeAllUserStyleSheets(); +} diff --git a/Source/WebKit2/UIProcess/API/C/WKPageGroup.h b/Source/WebKit2/UIProcess/API/C/WKPageGroup.h index 705df083e..1280241c8 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPageGroup.h +++ b/Source/WebKit2/UIProcess/API/C/WKPageGroup.h @@ -40,6 +40,9 @@ WK_EXPORT WKStringRef WKPageGroupCopyIdentifier(WKPageGroupRef pageGroup); WK_EXPORT void WKPageGroupSetPreferences(WKPageGroupRef pageGroup, WKPreferencesRef preferences); WK_EXPORT WKPreferencesRef WKPageGroupGetPreferences(WKPageGroupRef pageGroup); + +WK_EXPORT void WKPageGroupAddUserStyleSheet(WKPageGroupRef pageGroup, WKStringRef source, WKURLRef baseURL, WKArrayRef whitelist, WKArrayRef blacklist, WKUserContentInjectedFrames); +WK_EXPORT void WKPageGroupRemoveAllUserStyleSheets(WKPageGroupRef pageGroup); #ifdef __cplusplus } diff --git a/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h b/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h index 4a13ae7a2..3a9de69af 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h +++ b/Source/WebKit2/UIProcess/API/C/WKPagePrivate.h @@ -94,6 +94,8 @@ WK_EXPORT void WKPageSetShouldSendEventsSynchronously(WKPageRef page, bool sync) WK_EXPORT void WKPageSetMediaVolume(WKPageRef page, float volume); +WK_EXPORT WKArrayRef WKPageCopyRelatedPages(WKPageRef page); + #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp b/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp index 657b1b730..532d82caf 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKPreferences.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2012 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -298,6 +298,16 @@ bool WKPreferencesGetScreenFontSubstitutionEnabled(WKPreferencesRef preferencesR return toImpl(preferencesRef)->screenFontSubstitutionEnabled(); } +void WKPreferencesSetCookieEnabled(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setCookieEnabled(enabled); +} + +bool WKPreferencesGetCookieEnabled(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->cookieEnabled(); +} + void WKPreferencesSetEditableLinkBehavior(WKPreferencesRef preferencesRef, WKEditableLinkBehavior wkBehavior) { toImpl(preferencesRef)->setEditableLinkBehavior(toEditableLinkBehavior(wkBehavior)); @@ -913,3 +923,23 @@ bool WKPreferencesGetScrollingPerformanceLoggingEnabled(WKPreferencesRef prefere { return toImpl(preferencesRef)->scrollingPerformanceLoggingEnabled(); } + +void WKPreferencesSetPlugInSnapshottingEnabled(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setPlugInSnapshottingEnabled(enabled); +} + +bool WKPreferencesGetPlugInSnapshottingEnabled(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->plugInSnapshottingEnabled(); +} + +void WKPreferencesSetPDFPluginEnabled(WKPreferencesRef preferencesRef, bool enabled) +{ + toImpl(preferencesRef)->setPDFPluginEnabled(enabled); +} + +bool WKPreferencesGetPDFPluginEnabled(WKPreferencesRef preferencesRef) +{ + return toImpl(preferencesRef)->pdfPluginEnabled(); +} diff --git a/Source/WebKit2/UIProcess/API/C/WKPreferences.h b/Source/WebKit2/UIProcess/API/C/WKPreferences.h index c0fde67fd..d91b82d83 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPreferences.h +++ b/Source/WebKit2/UIProcess/API/C/WKPreferences.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2010, 2012 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -216,6 +216,10 @@ WK_EXPORT bool WKPreferencesGetShouldRespectImageOrientation(WKPreferencesRef pr WK_EXPORT void WKPreferencesSetStorageBlockingPolicy(WKPreferencesRef preferencesRef, WKStorageBlockingPolicy policy); WK_EXPORT WKStorageBlockingPolicy WKPreferencesGetStorageBlockingPolicy(WKPreferencesRef preferencesRef); +// Defaults to false +WK_EXPORT void WKPreferencesSetPlugInSnapshottingEnabled(WKPreferencesRef preferencesRef, bool enabled); +WK_EXPORT bool WKPreferencesGetPlugInSnapshottingEnabled(WKPreferencesRef preferencesRef); + #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/C/WKPreferencesPrivate.h b/Source/WebKit2/UIProcess/API/C/WKPreferencesPrivate.h index 11311704d..af5f73b34 100644 --- a/Source/WebKit2/UIProcess/API/C/WKPreferencesPrivate.h +++ b/Source/WebKit2/UIProcess/API/C/WKPreferencesPrivate.h @@ -219,6 +219,14 @@ WK_EXPORT bool WKPreferencesGetScrollingPerformanceLoggingEnabled(WKPreferencesR WK_EXPORT void WKPreferencesSetScreenFontSubstitutionEnabled(WKPreferencesRef preferences, bool enabled); WK_EXPORT bool WKPreferencesGetScreenFontSubstitutionEnabled(WKPreferencesRef preferences); +// Defaults to true +WK_EXPORT void WKPreferencesSetCookieEnabled(WKPreferencesRef preferences, bool enabled); +WK_EXPORT bool WKPreferencesGetCookieEnabled(WKPreferencesRef preferences); + +// Defaults to false +WK_EXPORT void WKPreferencesSetPDFPluginEnabled(WKPreferencesRef preferences, bool enabled); +WK_EXPORT bool WKPreferencesGetPDFPluginEnabled(WKPreferencesRef preferences); + WK_EXPORT void WKPreferencesResetTestRunnerOverrides(WKPreferencesRef preferencesRef); #ifdef __cplusplus diff --git a/Source/WebKit2/UIProcess/API/C/soup/WKSoupRequestManager.h b/Source/WebKit2/UIProcess/API/C/soup/WKSoupRequestManager.h index 1c9c001f2..4dba13908 100644 --- a/Source/WebKit2/UIProcess/API/C/soup/WKSoupRequestManager.h +++ b/Source/WebKit2/UIProcess/API/C/soup/WKSoupRequestManager.h @@ -33,7 +33,7 @@ extern "C" { #endif -typedef void (*WKSoupRequestManagerDidReceiveURIRequestCallback)(WKSoupRequestManagerRef soupRequestManagerRef, WKURLRef urlRef, uint64_t requestID, const void* clientInfo); +typedef void (*WKSoupRequestManagerDidReceiveURIRequestCallback)(WKSoupRequestManagerRef soupRequestManagerRef, WKURLRef urlRef, WKPageRef pageRef, uint64_t requestID, const void* clientInfo); typedef void (*WKSoupRequestManagerDidFailToLoadURIRequestCallback)(WKSoupRequestManagerRef soupRequestManagerRef, uint64_t requestID, const void* clientInfo); struct WKSoupRequestManagerClient { diff --git a/Source/WebKit2/UIProcess/API/efl/BatteryProvider.cpp b/Source/WebKit2/UIProcess/API/efl/BatteryProvider.cpp index 83cc37119..810711597 100644 --- a/Source/WebKit2/UIProcess/API/efl/BatteryProvider.cpp +++ b/Source/WebKit2/UIProcess/API/efl/BatteryProvider.cpp @@ -31,6 +31,7 @@ #include "WKAPICast.h" #include "WKBatteryManager.h" #include "WKBatteryStatus.h" +#include "WKContext.h" using namespace WebCore; using namespace WebKit; @@ -53,17 +54,25 @@ static void stopUpdatingCallback(WKBatteryManagerRef, const void* clientInfo) BatteryProvider::~BatteryProvider() { m_provider.stopUpdating(); + + WKBatteryManagerRef wkBatteryManager = WKContextGetBatteryManager(m_wkContext.get()); + ASSERT(wkBatteryManager); + + WKBatteryManagerSetProvider(wkBatteryManager, 0); } -PassRefPtr<BatteryProvider> BatteryProvider::create(WKBatteryManagerRef wkBatteryManager) +PassRefPtr<BatteryProvider> BatteryProvider::create(WKContextRef wkContext) { - return adoptRef(new BatteryProvider(wkBatteryManager)); + return adoptRef(new BatteryProvider(wkContext)); } -BatteryProvider::BatteryProvider(WKBatteryManagerRef wkBatteryManager) - : m_wkBatteryManager(wkBatteryManager) +BatteryProvider::BatteryProvider(WKContextRef wkContext) + : m_wkContext(wkContext) , m_provider(this) { + ASSERT(m_wkContext); + + WKBatteryManagerRef wkBatteryManager = WKContextGetBatteryManager(m_wkContext.get()); ASSERT(wkBatteryManager); WKBatteryProvider wkBatteryProvider = { @@ -72,7 +81,7 @@ BatteryProvider::BatteryProvider(WKBatteryManagerRef wkBatteryManager) startUpdatingCallback, stopUpdatingCallback }; - WKBatteryManagerSetProvider(m_wkBatteryManager.get(), &wkBatteryProvider); + WKBatteryManagerSetProvider(wkBatteryManager, &wkBatteryProvider); } void BatteryProvider::startUpdating() @@ -87,8 +96,11 @@ void BatteryProvider::stopUpdating() void BatteryProvider::didChangeBatteryStatus(const AtomicString& eventType, PassRefPtr<BatteryStatus> status) { + WKBatteryManagerRef wkBatteryManager = WKContextGetBatteryManager(m_wkContext.get()); + ASSERT(wkBatteryManager); + WKRetainPtr<WKBatteryStatusRef> wkBatteryStatus(AdoptWK, WKBatteryStatusCreate(status->charging(), status->chargingTime(), status->dischargingTime(), status->level())); - WKBatteryManagerProviderDidChangeBatteryStatus(m_wkBatteryManager.get(), toAPI(eventType.impl()), wkBatteryStatus.get()); + WKBatteryManagerProviderDidChangeBatteryStatus(wkBatteryManager, toAPI(eventType.impl()), wkBatteryStatus.get()); } #endif // ENABLE(BATTERY_STATUS) diff --git a/Source/WebKit2/UIProcess/API/efl/BatteryProvider.h b/Source/WebKit2/UIProcess/API/efl/BatteryProvider.h index e9e4cf5f0..c54414e68 100644 --- a/Source/WebKit2/UIProcess/API/efl/BatteryProvider.h +++ b/Source/WebKit2/UIProcess/API/efl/BatteryProvider.h @@ -38,18 +38,18 @@ class BatteryProvider : public RefCounted<BatteryProvider>, public WebCore::BatteryProviderEflClient { public: virtual ~BatteryProvider(); - static PassRefPtr<BatteryProvider> create(WKBatteryManagerRef); + static PassRefPtr<BatteryProvider> create(WKContextRef); void startUpdating(); void stopUpdating(); private: - BatteryProvider(WKBatteryManagerRef); + BatteryProvider(WKContextRef); // BatteryProviderEflClient interface. virtual void didChangeBatteryStatus(const AtomicString& eventType, PassRefPtr<WebCore::BatteryStatus>); - WKRetainPtr<WKBatteryManagerRef> m_wkBatteryManager; + WKRetainPtr<WKContextRef> m_wkContext; WebCore::BatteryProviderEfl m_provider; }; diff --git a/Source/WebKit2/UIProcess/API/efl/EWebKit2.h b/Source/WebKit2/UIProcess/API/efl/EWebKit2.h index 13efab13a..00dd811a4 100644 --- a/Source/WebKit2/UIProcess/API/efl/EWebKit2.h +++ b/Source/WebKit2/UIProcess/API/efl/EWebKit2.h @@ -33,19 +33,20 @@ #include "ewk_context.h" #include "ewk_cookie_manager.h" #include "ewk_download_job.h" +#include "ewk_error.h" #include "ewk_form_submission_request.h" #include "ewk_intent.h" #include "ewk_intent_service.h" #include "ewk_main.h" +#include "ewk_navigation_data.h" #include "ewk_navigation_policy_decision.h" #include "ewk_popup_menu_item.h" +#include "ewk_resource.h" #include "ewk_settings.h" #include "ewk_touch.h" #include "ewk_url_request.h" #include "ewk_url_response.h" #include "ewk_url_scheme_request.h" #include "ewk_view.h" -#include "ewk_web_error.h" -#include "ewk_web_resource.h" #endif // EWebKit2_h diff --git a/Source/WebKit2/UIProcess/API/efl/EflViewportHandler.cpp b/Source/WebKit2/UIProcess/API/efl/EflViewportHandler.cpp index eb3d007fe..05be4cadf 100644 --- a/Source/WebKit2/UIProcess/API/efl/EflViewportHandler.cpp +++ b/Source/WebKit2/UIProcess/API/efl/EflViewportHandler.cpp @@ -53,6 +53,11 @@ DrawingAreaProxy* EflViewportHandler::drawingArea() const return ewk_view_page_get(m_viewWidget)->drawingArea(); } +void EflViewportHandler::setRendererActive(bool active) +{ + drawingArea()->layerTreeCoordinatorProxy()->layerTreeRenderer()->setActive(active); +} + void EflViewportHandler::display(const IntRect& rect) { WebCore::TransformationMatrix matrix; diff --git a/Source/WebKit2/UIProcess/API/efl/EflViewportHandler.h b/Source/WebKit2/UIProcess/API/efl/EflViewportHandler.h index a23f4e147..f4d0e66de 100644 --- a/Source/WebKit2/UIProcess/API/efl/EflViewportHandler.h +++ b/Source/WebKit2/UIProcess/API/efl/EflViewportHandler.h @@ -48,7 +48,7 @@ public: void updateViewportSize(const WebCore::IntSize& viewportSize); void setVisibleContentsRect(const WebCore::IntPoint&, float, const WebCore::FloatPoint&); void didChangeContentsSize(const WebCore::IntSize& size); - + void setRendererActive(bool); private: explicit EflViewportHandler(Evas_Object*); diff --git a/Source/WebKit2/UIProcess/API/efl/NetworkInfoProvider.cpp b/Source/WebKit2/UIProcess/API/efl/NetworkInfoProvider.cpp index 54a6921da..1431c83a7 100644 --- a/Source/WebKit2/UIProcess/API/efl/NetworkInfoProvider.cpp +++ b/Source/WebKit2/UIProcess/API/efl/NetworkInfoProvider.cpp @@ -28,6 +28,7 @@ #if ENABLE(NETWORK_INFO) +#include "WKContext.h" #include "WKNetworkInfoManager.h" #include <NotImplemented.h> @@ -56,15 +57,18 @@ static bool isMeteredCallback(WKNetworkInfoManagerRef, const void* clientInfo) return toNetworkInfoProvider(clientInfo)->metered(); } -PassRefPtr<NetworkInfoProvider> NetworkInfoProvider::create(WKNetworkInfoManagerRef wkManager) +PassRefPtr<NetworkInfoProvider> NetworkInfoProvider::create(WKContextRef wkContext) { - return adoptRef(new NetworkInfoProvider(wkManager)); + return adoptRef(new NetworkInfoProvider(wkContext)); } -NetworkInfoProvider::NetworkInfoProvider(WKNetworkInfoManagerRef wkManager) - : m_wkNetworkInfoManager(wkManager) +NetworkInfoProvider::NetworkInfoProvider(WKContextRef wkContext) + : m_wkContext(wkContext) { - ASSERT(wkManager); + ASSERT(wkContext); + + WKNetworkInfoManagerRef wkNetworkInfoManager = WKContextGetNetworkInfoManager(m_wkContext.get()); + ASSERT(wkNetworkInfoManager); WKNetworkInfoProvider wkNetworkInfoProvider = { kWKNetworkInfoProviderCurrentVersion, @@ -74,11 +78,15 @@ NetworkInfoProvider::NetworkInfoProvider(WKNetworkInfoManagerRef wkManager) getBandwidthCallback, isMeteredCallback }; - WKNetworkInfoManagerSetProvider(m_wkNetworkInfoManager.get(), &wkNetworkInfoProvider); + WKNetworkInfoManagerSetProvider(wkNetworkInfoManager, &wkNetworkInfoProvider); } NetworkInfoProvider::~NetworkInfoProvider() { + WKNetworkInfoManagerRef wkNetworkInfoManager = WKContextGetNetworkInfoManager(m_wkContext.get()); + ASSERT(wkNetworkInfoManager); + + WKNetworkInfoManagerSetProvider(wkNetworkInfoManager, 0); } double NetworkInfoProvider::bandwidth() const diff --git a/Source/WebKit2/UIProcess/API/efl/NetworkInfoProvider.h b/Source/WebKit2/UIProcess/API/efl/NetworkInfoProvider.h index b9f86e6e5..0a5d60e4f 100644 --- a/Source/WebKit2/UIProcess/API/efl/NetworkInfoProvider.h +++ b/Source/WebKit2/UIProcess/API/efl/NetworkInfoProvider.h @@ -37,7 +37,7 @@ class NetworkInfoProvider : public RefCounted<NetworkInfoProvider>, public WebCore::NetworkInfoClient { public: virtual ~NetworkInfoProvider(); - static PassRefPtr<NetworkInfoProvider> create(WKNetworkInfoManagerRef); + static PassRefPtr<NetworkInfoProvider> create(WKContextRef); // NetworkInfoClient interface. virtual double bandwidth() const; @@ -47,9 +47,9 @@ public: virtual void stopUpdating(); private: - NetworkInfoProvider(WKNetworkInfoManagerRef); + NetworkInfoProvider(WKContextRef); - WKRetainPtr<WKNetworkInfoManagerRef> m_wkNetworkInfoManager; + WKRetainPtr<WKContextRef> m_wkContext; WebCore::NetworkInfoProviderEfl m_provider; }; diff --git a/Source/WebKit2/UIProcess/API/efl/PageClientImpl.cpp b/Source/WebKit2/UIProcess/API/efl/PageClientImpl.cpp index ef2ce603f..3bf194f57 100644 --- a/Source/WebKit2/UIProcess/API/efl/PageClientImpl.cpp +++ b/Source/WebKit2/UIProcess/API/efl/PageClientImpl.cpp @@ -94,8 +94,7 @@ bool PageClientImpl::isViewFocused() bool PageClientImpl::isViewVisible() { - notImplemented(); - return true; + return evas_object_visible_get(m_viewWidget); } bool PageClientImpl::isViewInWindow() diff --git a/Source/WebKit2/UIProcess/API/efl/VibrationProvider.cpp b/Source/WebKit2/UIProcess/API/efl/VibrationProvider.cpp index 29fb6a4fc..13d4de6d6 100644 --- a/Source/WebKit2/UIProcess/API/efl/VibrationProvider.cpp +++ b/Source/WebKit2/UIProcess/API/efl/VibrationProvider.cpp @@ -29,6 +29,7 @@ #if ENABLE(VIBRATION) #include "WKAPICast.h" +#include "WKContext.h" #include "WKVibration.h" #include <Evas.h> @@ -65,15 +66,18 @@ static void cancelVibrationCallback(WKVibrationRef, const void* clientInfo) toVibrationProvider(clientInfo)->cancelVibration(); } -PassRefPtr<VibrationProvider> VibrationProvider::create(WKVibrationRef wkVibrationRef) +PassRefPtr<VibrationProvider> VibrationProvider::create(WKContextRef wkContext) { - return adoptRef(new VibrationProvider(wkVibrationRef)); + return adoptRef(new VibrationProvider(wkContext)); } -VibrationProvider::VibrationProvider(WKVibrationRef wkVibrationRef) - : m_wkVibrationRef(wkVibrationRef) +VibrationProvider::VibrationProvider(WKContextRef wkContext) + : m_wkContext(wkContext) { - ASSERT(wkVibrationRef); + ASSERT(m_wkContext.get()); + + WKVibrationRef wkVibration = WKContextGetVibration(m_wkContext.get()); + ASSERT(wkVibration); WKVibrationProvider wkVibrationProvider = { kWKVibrationProviderCurrentVersion, @@ -81,11 +85,15 @@ VibrationProvider::VibrationProvider(WKVibrationRef wkVibrationRef) vibrateCallback, cancelVibrationCallback }; - WKVibrationSetProvider(m_wkVibrationRef.get(), &wkVibrationProvider); + WKVibrationSetProvider(wkVibration, &wkVibrationProvider); } VibrationProvider::~VibrationProvider() { + WKVibrationRef wkVibration = WKContextGetVibration(m_wkContext.get()); + ASSERT(wkVibration); + + WKVibrationSetProvider(wkVibration, 0); } void VibrationProvider::vibrate(uint64_t vibrationTime) diff --git a/Source/WebKit2/UIProcess/API/efl/VibrationProvider.h b/Source/WebKit2/UIProcess/API/efl/VibrationProvider.h index c2643b638..6b2db4eec 100644 --- a/Source/WebKit2/UIProcess/API/efl/VibrationProvider.h +++ b/Source/WebKit2/UIProcess/API/efl/VibrationProvider.h @@ -37,7 +37,7 @@ typedef struct _Ewk_Vibration_Client Ewk_Vibration_Client; class VibrationProvider : public RefCounted<VibrationProvider> { public: - static PassRefPtr<VibrationProvider> create(WKVibrationRef); + static PassRefPtr<VibrationProvider> create(WKContextRef); virtual ~VibrationProvider(); void vibrate(uint64_t vibrationTime); @@ -45,9 +45,9 @@ public: void setVibrationClientCallbacks(Ewk_Vibration_Client_Vibrate_Cb, Ewk_Vibration_Client_Vibration_Cancel_Cb, void*); private: - explicit VibrationProvider(WKVibrationRef); + explicit VibrationProvider(WKContextRef); - WKRetainPtr<WKVibrationRef> m_wkVibrationRef; + WKRetainPtr<WKContextRef> m_wkContext; OwnPtr<Ewk_Vibration_Client> m_vibrationClient; }; diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list.cpp index be866fa0a..94d0300c1 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list.cpp @@ -54,7 +54,7 @@ struct _Ewk_Back_Forward_List { ItemsMap::iterator it = wrapperCache.begin(); ItemsMap::iterator end = wrapperCache.end(); for (; it != end; ++it) - ewk_back_forward_list_item_unref(it->second); + ewk_back_forward_list_item_unref(it->value); } }; diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list_item.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list_item.cpp index 5679773a0..704545a0b 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list_item.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list_item.cpp @@ -39,9 +39,9 @@ using namespace WebKit; struct _Ewk_Back_Forward_List_Item { unsigned int __ref; /**< the reference count of the object */ WKRetainPtr<WKBackForwardListItemRef> wkItem; - mutable WKEinaSharedString uri; + mutable WKEinaSharedString url; mutable WKEinaSharedString title; - mutable WKEinaSharedString originalUri; + mutable WKEinaSharedString originalURL; _Ewk_Back_Forward_List_Item(WKBackForwardListItemRef itemRef) : __ref(1) @@ -83,13 +83,13 @@ void ewk_back_forward_list_item_unref(Ewk_Back_Forward_List_Item* item) delete item; } -const char* ewk_back_forward_list_item_uri_get(const Ewk_Back_Forward_List_Item* item) +const char* ewk_back_forward_list_item_url_get(const Ewk_Back_Forward_List_Item* item) { EWK_BACK_FORWARD_LIST_ITEM_WK_GET_OR_RETURN(item, wkItem, 0); - item->uri = WKEinaSharedString(AdoptWK, WKBackForwardListItemCopyURL(wkItem)); + item->url = WKEinaSharedString(AdoptWK, WKBackForwardListItemCopyURL(wkItem)); - return item->uri; + return item->url; } const char* ewk_back_forward_list_item_title_get(const Ewk_Back_Forward_List_Item* item) @@ -101,13 +101,13 @@ const char* ewk_back_forward_list_item_title_get(const Ewk_Back_Forward_List_Ite return item->title; } -const char* ewk_back_forward_list_item_original_uri_get(const Ewk_Back_Forward_List_Item* item) +const char* ewk_back_forward_list_item_original_url_get(const Ewk_Back_Forward_List_Item* item) { EWK_BACK_FORWARD_LIST_ITEM_WK_GET_OR_RETURN(item, wkItem, 0); - item->originalUri = WKEinaSharedString(AdoptWK, WKBackForwardListItemCopyOriginalURL(wkItem)); + item->originalURL = WKEinaSharedString(AdoptWK, WKBackForwardListItemCopyOriginalURL(wkItem)); - return item->originalUri; + return item->originalURL; } Ewk_Back_Forward_List_Item* ewk_back_forward_list_item_new(WKBackForwardListItemRef backForwardListItemData) diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list_item.h b/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list_item.h index a1227dfc0..3c544f3ef 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list_item.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list_item.h @@ -59,21 +59,21 @@ EAPI Ewk_Back_Forward_List_Item *ewk_back_forward_list_item_ref(Ewk_Back_Forward EAPI void ewk_back_forward_list_item_unref(Ewk_Back_Forward_List_Item *item); /** - * Returns URI of the item. + * Returns URL of the item. * - * The returned URI may differ from the original URI (For example if the page was redirected). + * The returned URL may differ from the original URL (For example if the page was redirected). * - * @see ewk_back_forward_list_item_original_uri_get() + * @see ewk_back_forward_list_item_original_url_get() * * @param item the back-forward list item instance * - * @return the URI of the @a item or @c NULL in case of error. This pointer is + * @return the URL of the @a item or @c NULL in case of error. This pointer is * guaranteed to be eina_stringshare, so whenever possible * save yourself some cpu cycles and use * eina_stringshare_ref() instead of eina_stringshare_add() or * strdup() */ -EAPI const char *ewk_back_forward_list_item_uri_get(const Ewk_Back_Forward_List_Item *item); +EAPI const char *ewk_back_forward_list_item_url_get(const Ewk_Back_Forward_List_Item *item); /** * Returns title of the item. @@ -89,19 +89,19 @@ EAPI const char *ewk_back_forward_list_item_uri_get(const Ewk_Back_Forward_List_ EAPI const char *ewk_back_forward_list_item_title_get(const Ewk_Back_Forward_List_Item *item); /** - * Returns original URI of the item. + * Returns original URL of the item. * - * @see ewk_back_forward_list_item_uri_get() + * @see ewk_back_forward_list_item_url_get() * * @param item the back-forward list item instance * - * @return the original URI of the @a item or @c NULL in case of error. This pointer is + * @return the original URL of the @a item or @c NULL in case of error. This pointer is * guaranteed to be eina_stringshare, so whenever possible * save yourself some cpu cycles and use * eina_stringshare_ref() instead of eina_stringshare_add() or * strdup() */ -EAPI const char *ewk_back_forward_list_item_original_uri_get(const Ewk_Back_Forward_List_Item *item); +EAPI const char *ewk_back_forward_list_item_original_url_get(const Ewk_Back_Forward_List_Item *item); #ifdef __cplusplus } diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp index b34ff77df..02eddb42d 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp @@ -22,6 +22,7 @@ #include "ewk_context.h" #include "BatteryProvider.h" +#include "NetworkInfoProvider.h" #include "VibrationProvider.h" #include "WKAPICast.h" #include "WKContextSoup.h" @@ -30,6 +31,7 @@ #include "WKString.h" #include "WebContext.h" #include "ewk_context_download_client_private.h" +#include "ewk_context_history_client_private.h" #include "ewk_context_private.h" #include "ewk_context_request_manager_client_private.h" #include "ewk_cookie_manager_private.h" @@ -67,6 +69,9 @@ struct _Ewk_Context { #if ENABLE(BATTERY_STATUS) RefPtr<BatteryProvider> batteryProvider; #endif +#if ENABLE(NETWORK_INFO) + RefPtr<NetworkInfoProvider> networkInfoProvider; +#endif #if ENABLE(VIBRATION) RefPtr<VibrationProvider> vibrationProvider; #endif @@ -75,20 +80,25 @@ struct _Ewk_Context { WKRetainPtr<WKSoupRequestManagerRef> requestManager; URLSchemeHandlerMap urlSchemeHandlers; + Ewk_Context_History_Client historyClient; + _Ewk_Context(WKRetainPtr<WKContextRef> contextRef) : __ref(1) , context(contextRef) , cookieManager(0) , requestManager(WKContextGetSoupRequestManager(contextRef.get())) + , historyClient() { #if ENABLE(BATTERY_STATUS) - WKBatteryManagerRef wkBatteryManager = WKContextGetBatteryManager(contextRef.get()); - batteryProvider = BatteryProvider::create(wkBatteryManager); + batteryProvider = BatteryProvider::create(context.get()); +#endif + +#if ENABLE(NETWORK_INFO) + networkInfoProvider = NetworkInfoProvider::create(context.get()); #endif #if ENABLE(VIBRATION) - WKVibrationRef wkVibrationRef = WKContextGetVibration(contextRef.get()); - vibrationProvider = VibrationProvider::create(wkVibrationRef); + vibrationProvider = VibrationProvider::create(context.get()); #endif #if ENABLE(MEMORY_SAMPLER) @@ -103,6 +113,7 @@ struct _Ewk_Context { #endif ewk_context_request_manager_client_attach(this); ewk_context_download_client_attach(this); + ewk_context_history_client_attach(this); } ~_Ewk_Context() @@ -113,7 +124,7 @@ struct _Ewk_Context { HashMap<uint64_t, Ewk_Download_Job*>::iterator it = downloadJobs.begin(); HashMap<uint64_t, Ewk_Download_Job*>::iterator end = downloadJobs.end(); for ( ; it != end; ++it) - ewk_download_job_unref(it->second); + ewk_download_job_unref(it->value); } }; @@ -255,7 +266,7 @@ Ewk_Context* ewk_context_new_with_injected_bundle_path(const char* path) return new Ewk_Context(adoptWK(WKContextCreateWithInjectedBundlePath(pathRef.get()))); } -Eina_Bool ewk_context_uri_scheme_register(Ewk_Context* ewkContext, const char* scheme, Ewk_Url_Scheme_Request_Cb callback, void* userData) +Eina_Bool ewk_context_url_scheme_register(Ewk_Context* ewkContext, const char* scheme, Ewk_Url_Scheme_Request_Cb callback, void* userData) { EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, false); EINA_SAFETY_ON_NULL_RETURN_VAL(scheme, false); @@ -276,3 +287,31 @@ void ewk_context_vibration_client_callbacks_set(Ewk_Context* ewkContext, Ewk_Vib ewkContext->vibrationProvider->setVibrationClientCallbacks(vibrate, cancel, data); #endif } + +void ewk_context_history_callbacks_set(Ewk_Context* ewkContext, Ewk_History_Navigation_Cb navigate, Ewk_History_Client_Redirection_Cb clientRedirect, Ewk_History_Server_Redirection_Cb serverRedirect, Ewk_History_Title_Update_Cb titleUpdate, Ewk_History_Populate_Visited_Links_Cb populateVisitedLinks, void* data) +{ + EINA_SAFETY_ON_NULL_RETURN(ewkContext); + + ewkContext->historyClient.navigate_func = navigate; + ewkContext->historyClient.client_redirect_func = clientRedirect; + ewkContext->historyClient.server_redirect_func = serverRedirect; + ewkContext->historyClient.title_update_func = titleUpdate; + ewkContext->historyClient.populate_visited_links_func = populateVisitedLinks; + ewkContext->historyClient.user_data = data; +} + +const Ewk_Context_History_Client* ewk_context_history_client_get(const Ewk_Context* ewkContext) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(ewkContext, 0); + + return &ewkContext->historyClient; +} + +void ewk_context_visited_link_add(Ewk_Context* ewkContext, const char* visitedURL) +{ + EINA_SAFETY_ON_NULL_RETURN(ewkContext); + EINA_SAFETY_ON_NULL_RETURN(visitedURL); + + WKRetainPtr<WKStringRef> wkVisitedURL(AdoptWK, WKStringCreateWithUTF8CString(visitedURL)); + WKContextAddVisitedLink(ewkContext->context.get(), wkVisitedURL.get()); +} diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_context.h b/Source/WebKit2/UIProcess/API/efl/ewk_context.h index e6e9e0c7b..3f46d460e 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_context.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_context.h @@ -38,6 +38,7 @@ #define ewk_context_h #include "ewk_cookie_manager.h" +#include "ewk_navigation_data.h" #include "ewk_url_scheme_request.h" #include <Evas.h> @@ -50,7 +51,7 @@ typedef struct _Ewk_Context Ewk_Context; /** * @typedef Ewk_Url_Scheme_Request_Cb Ewk_Url_Scheme_Request_Cb - * @brief Callback type for use with ewk_context_uri_scheme_register(). + * @brief Callback type for use with ewk_context_url_scheme_register(). */ typedef void (*Ewk_Url_Scheme_Request_Cb) (Ewk_Url_Scheme_Request *request, void *user_data); @@ -69,6 +70,38 @@ typedef void (*Ewk_Vibration_Client_Vibrate_Cb)(uint64_t vibration_time, void *u typedef void (*Ewk_Vibration_Client_Vibration_Cancel_Cb)(void *user_data); /** + * @typedef Ewk_History_Navigation_Cb Ewk_History_Navigation_Cb + * @brief Type definition for a function that will be called back when @a view did navigation (loaded new URL). + */ +typedef void (*Ewk_History_Navigation_Cb)(const Evas_Object *view, Ewk_Navigation_Data *navigation_data, void *user_data); + +/** + * @typedef Ewk_History_Client_Redirection_Cb Ewk_History_Client_Redirection_Cb + * @brief Type definition for a function that will be called back when @a view performed a client redirect. + */ +typedef void (*Ewk_History_Client_Redirection_Cb)(const Evas_Object *view, const char *source_url, const char *destination_url, void *user_data); + +/** + * @typedef Ewk_History_Server_Redirection_Cb Ewk_History_Server_Redirection_Cb + * @brief Type definition for a function that will be called back when @a view performed a server redirect. + */ +typedef void (*Ewk_History_Server_Redirection_Cb)(const Evas_Object *view, const char *source_url, const char *destination_url, void *user_data); + +/** + * @typedef Ewk_History_Title_Update_Cb Ewk_History_Title_Update_Cb + * @brief Type definition for a function that will be called back when history title is updated. + */ +typedef void (*Ewk_History_Title_Update_Cb)(const Evas_Object *view, const char *title, const char *url, void *user_data); + +/** + * @typedef Ewk_Context_History_Client_Visited_Links_Populate_Cb Ewk_Context_History_Client_Visited_Links_Populate_Cb + * @brief Type definition for a function that will be called back when client is asked to provide visited links from a client-managed storage. + * + * @see ewk_context_visited_link_add + */ +typedef void (*Ewk_History_Populate_Visited_Links_Cb)(void *user_data); + +/** * Increases the reference count of the given object. * * @param context context object to increase the reference count @@ -147,7 +180,7 @@ EAPI Ewk_Cookie_Manager *ewk_context_cookie_manager_get(const Ewk_Context *conte * @param user_data data to pass to callback function * * @code - * static void about_uri_scheme_request_cb(Ewk_Url_Scheme_Request *request, void *user_data) + * static void about_url_scheme_request_cb(Ewk_Url_Scheme_Request *request, void *user_data) * { * const char *path; * char *contents_data = NULL; @@ -172,7 +205,7 @@ EAPI Ewk_Cookie_Manager *ewk_context_cookie_manager_get(const Ewk_Context *conte * } * @endcode */ -EAPI Eina_Bool ewk_context_uri_scheme_register(Ewk_Context *context, const char *scheme, Ewk_Url_Scheme_Request_Cb callback, void *user_data); +EAPI Eina_Bool ewk_context_url_scheme_register(Ewk_Context *context, const char *scheme, Ewk_Url_Scheme_Request_Cb callback, void *user_data); /** * Sets vibration client callbacks to handle the tactile feedback in the form of @@ -190,6 +223,41 @@ EAPI Eina_Bool ewk_context_uri_scheme_register(Ewk_Context *context, const char */ EAPI void ewk_context_vibration_client_callbacks_set(Ewk_Context *context, Ewk_Vibration_Client_Vibrate_Cb vibrate, Ewk_Vibration_Client_Vibration_Cancel_Cb cancel, void *data); +/** + * Sets history callbacks for the given @a context. + * + * To stop listening for history events, you may call this function with @c + * NULL for the callbacks. + * + * @param context context object to set history callbacks + * @param navigate_func The function to call when @c ewk_view did navigation (may be @c NULL). + * @param client_redirect_func The function to call when @c ewk_view performed a client redirect (may be @c NULL). + * @param server_redirect_func The function to call when @c ewk_view performed a server redirect (may be @c NULL). + * @param title_update_func The function to call when history title is updated (may be @c NULL). + * @param populate_visited_links_func The function is called when client is asked to provide visited links from a + * client-managed storage (may be @c NULL). + * @param data User data (may be @c NULL). + */ +EAPI void ewk_context_history_callbacks_set(Ewk_Context *context, + Ewk_History_Navigation_Cb navigate_func, + Ewk_History_Client_Redirection_Cb client_redirect_func, + Ewk_History_Server_Redirection_Cb server_redirect_func, + Ewk_History_Title_Update_Cb title_update_func, + Ewk_History_Populate_Visited_Links_Cb populate_visited_links_func, + void *data); + +/** + * Registers the given @a visited_url as visited link in @a context visited link cache. + * + * This function shall be invoked as a response to @c populateVisitedLinks callback of the history cient. + * + * @param context context object to add visited link data + * @param visited_url visited url + * + * @see Ewk_Context_History_Client + */ +EAPI void ewk_context_visited_link_add(Ewk_Context *context, const char *visited_url); + #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_context_download_client.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_context_download_client.cpp index 9d924bff2..2bbb7ef0f 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_context_download_client.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_context_download_client.cpp @@ -33,11 +33,10 @@ #include "ewk_context_private.h" #include "ewk_download_job.h" #include "ewk_download_job_private.h" +#include "ewk_error_private.h" #include "ewk_url_response.h" #include "ewk_url_response_private.h" #include "ewk_view_private.h" -#include "ewk_web_error.h" -#include "ewk_web_error_private.h" #include <string.h> #include <wtf/text/CString.h> @@ -59,7 +58,7 @@ static WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownlo // and the suggested file name. ewk_view_download_job_requested(ewk_download_job_view_get(download), download); - // DownloadSoup expects the destination to be a URI. + // DownloadSoup expects the destination to be a URL. String destination = String("file://") + String::fromUTF8(ewk_download_job_destination_get(download)); return WKStringCreateWithUTF8CString(destination.utf8().data()); @@ -95,10 +94,10 @@ static void didFail(WKContextRef, WKDownloadRef wkDownload, WKErrorRef error, co Ewk_Download_Job* download = ewk_context_download_job_get(toEwkContext(clientInfo), downloadId); ASSERT(download); - Ewk_Web_Error* ewkError = ewk_web_error_new(error); + Ewk_Error* ewkError = ewk_error_new(error); ewk_download_job_state_set(download, EWK_DOWNLOAD_JOB_STATE_FAILED); ewk_view_download_job_failed(ewk_download_job_view_get(download), download, ewkError); - ewk_web_error_free(ewkError); + ewk_error_free(ewkError); ewk_context_download_job_remove(toEwkContext(clientInfo), downloadId); } diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_context_history_client.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_context_history_client.cpp new file mode 100644 index 000000000..fd1b83aae --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/ewk_context_history_client.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2012 Intel Corporation. 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 "ewk_context.h" + +#include "DownloadProxy.h" +#include "WKAPICast.h" +#include "WKContext.h" +#include "WKEinaSharedString.h" +#include "WKString.h" +#include "ewk_context_history_client_private.h" +#include "ewk_context_private.h" +#include "ewk_navigation_data.h" +#include "ewk_navigation_data_private.h" +#include "ewk_url_response.h" +#include "ewk_url_response_private.h" +#include "ewk_view_private.h" + +using namespace WebKit; + +static inline const Ewk_Context_History_Client* getEwkHistoryDelegate(const void* clientInfo) +{ + ASSERT(clientInfo); + return ewk_context_history_client_get(static_cast<const Ewk_Context*>(clientInfo)); +} + +static void didNavigateWithNavigationData(WKContextRef, WKPageRef page, WKNavigationDataRef navigationData, WKFrameRef, const void* clientInfo) +{ + const Ewk_Context_History_Client* historyDelegate = getEwkHistoryDelegate(clientInfo); + ASSERT(historyDelegate); + + if (!historyDelegate->navigate_func) + return; + + RefPtr<Ewk_Navigation_Data> navigationDataEwk = adoptRef(ewk_navigation_data_new(navigationData)); + historyDelegate->navigate_func(ewk_view_from_page_get(toImpl(page)), navigationDataEwk.get(), historyDelegate->user_data); +} + +static void didPerformClientRedirect(WKContextRef, WKPageRef page, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void* clientInfo) +{ + const Ewk_Context_History_Client* historyDelegate = getEwkHistoryDelegate(clientInfo); + ASSERT(historyDelegate); + + if (!historyDelegate->client_redirect_func) + return; + + WKEinaSharedString sourceURLString(sourceURL); + WKEinaSharedString destinationURLString(destinationURL); + + historyDelegate->client_redirect_func(ewk_view_from_page_get(toImpl(page)), sourceURLString, destinationURLString, historyDelegate->user_data); +} + +static void didPerformServerRedirect(WKContextRef, WKPageRef page, WKURLRef sourceURL, WKURLRef destinationURL, WKFrameRef, const void* clientInfo) +{ + const Ewk_Context_History_Client* historyDelegate = getEwkHistoryDelegate(clientInfo); + ASSERT(historyDelegate); + + if (!historyDelegate->server_redirect_func) + return; + + WKEinaSharedString sourceURLString(sourceURL); + WKEinaSharedString destinationURLString(destinationURL); + + historyDelegate->server_redirect_func(ewk_view_from_page_get(toImpl(page)), sourceURLString, destinationURLString, historyDelegate->user_data); +} + +static void didUpdateHistoryTitle(WKContextRef, WKPageRef page, WKStringRef title, WKURLRef URL, WKFrameRef, const void* clientInfo) +{ + const Ewk_Context_History_Client* historyDelegate = getEwkHistoryDelegate(clientInfo); + ASSERT(historyDelegate); + + if (!historyDelegate->title_update_func) + return; + + WKEinaSharedString titleString(title); + WKEinaSharedString stringURL(URL); + + historyDelegate->title_update_func(ewk_view_from_page_get(toImpl(page)), titleString, stringURL, historyDelegate->user_data); +} + +static void populateVisitedLinks(WKContextRef, const void* clientInfo) +{ + const Ewk_Context_History_Client* historyDelegate = getEwkHistoryDelegate(clientInfo); + ASSERT(historyDelegate); + + if (!historyDelegate->populate_visited_links_func) + return; + + historyDelegate->populate_visited_links_func(historyDelegate->user_data); +} + +void ewk_context_history_client_attach(Ewk_Context* ewkContext) +{ + WKContextHistoryClient wkHistoryClient; + memset(&wkHistoryClient, 0, sizeof(WKContextHistoryClient)); + + wkHistoryClient.version = kWKContextHistoryClientCurrentVersion; + wkHistoryClient.clientInfo = ewkContext; + + wkHistoryClient.didNavigateWithNavigationData = didNavigateWithNavigationData; + wkHistoryClient.didPerformClientRedirect = didPerformClientRedirect; + wkHistoryClient.didPerformServerRedirect = didPerformServerRedirect; + wkHistoryClient.didUpdateHistoryTitle = didUpdateHistoryTitle; + wkHistoryClient.populateVisitedLinks = populateVisitedLinks; + + WKContextSetHistoryClient(ewk_context_WKContext_get(ewkContext), &wkHistoryClient); +} diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_context_history_client_private.h b/Source/WebKit2/UIProcess/API/efl/ewk_context_history_client_private.h new file mode 100644 index 000000000..d9518ced9 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/ewk_context_history_client_private.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2012 Intel Corporation. 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 ewk_context_history_client_private_h +#define ewk_context_history_client_private_h + +#include "ewk_context.h" + +struct _Ewk_Context_History_Client { + void* user_data; + Ewk_History_Navigation_Cb navigate_func; + Ewk_History_Client_Redirection_Cb client_redirect_func; + Ewk_History_Server_Redirection_Cb server_redirect_func; + Ewk_History_Title_Update_Cb title_update_func; + Ewk_History_Populate_Visited_Links_Cb populate_visited_links_func; +}; + +typedef struct _Ewk_Context_History_Client Ewk_Context_History_Client; + +void ewk_context_history_client_attach(Ewk_Context*); + +#endif // ewk_context_history_client_private_h diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_context_private.h b/Source/WebKit2/UIProcess/API/efl/ewk_context_private.h index d1b695e0c..f2c322a61 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_context_private.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_context_private.h @@ -25,6 +25,7 @@ typedef struct _Ewk_Context Ewk_Context; typedef struct _Ewk_Download_Job Ewk_Download_Job; typedef struct _Ewk_Url_Scheme_Request Ewk_Url_Scheme_Request; +typedef struct _Ewk_Context_History_Client Ewk_Context_History_Client; WKContextRef ewk_context_WKContext_get(const Ewk_Context*); Ewk_Context* ewk_context_new_from_WKContext(WKContextRef); @@ -35,4 +36,6 @@ void ewk_context_download_job_add(Ewk_Context*, Ewk_Download_Job*); Ewk_Download_Job* ewk_context_download_job_get(const Ewk_Context*, uint64_t downloadId); void ewk_context_download_job_remove(Ewk_Context*, uint64_t downloadId); +const Ewk_Context_History_Client* ewk_context_history_client_get(const Ewk_Context*); + #endif // ewk_context_private_h diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_context_request_manager_client.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_context_request_manager_client.cpp index b22bd36ff..5a7707229 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_context_request_manager_client.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_context_request_manager_client.cpp @@ -37,7 +37,7 @@ static inline Ewk_Context* toEwkContext(const void* clientInfo) return static_cast<Ewk_Context*>(const_cast<void*>(clientInfo)); } -static void didReceiveURIRequest(WKSoupRequestManagerRef soupRequestManagerRef, WKURLRef urlRef, uint64_t requestID, const void* clientInfo) +static void didReceiveURIRequest(WKSoupRequestManagerRef soupRequestManagerRef, WKURLRef urlRef, WKPageRef, uint64_t requestID, const void* clientInfo) { Ewk_Url_Scheme_Request* schemeRequest = ewk_url_scheme_request_new(soupRequestManagerRef, urlRef, requestID); ewk_context_url_scheme_request_received(toEwkContext(clientInfo), schemeRequest); diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_cookie_manager.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_cookie_manager.cpp index 45dd75e63..a52047336 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_cookie_manager.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_cookie_manager.cpp @@ -33,8 +33,8 @@ #include "WKRetainPtr.h" #include "WKString.h" #include "WebCookieManagerProxy.h" +#include "ewk_error_private.h" #include "ewk_private.h" -#include "ewk_web_error_private.h" #include <wtf/text/CString.h> #include <wtf/text/WTFString.h> @@ -142,12 +142,12 @@ struct Get_Policy_Async_Data { static void getAcceptPolicyCallback(WKHTTPCookieAcceptPolicy policy, WKErrorRef wkError, void* data) { Get_Policy_Async_Data* callbackData = static_cast<Get_Policy_Async_Data*>(data); - Ewk_Web_Error* ewkError = wkError ? ewk_web_error_new(wkError) : 0; + Ewk_Error* ewkError = wkError ? ewk_error_new(wkError) : 0; callbackData->callback(static_cast<Ewk_Cookie_Accept_Policy>(policy), ewkError, callbackData->userData); if (ewkError) - ewk_web_error_free(ewkError); + ewk_error_free(ewkError); delete callbackData; } @@ -172,7 +172,7 @@ static void getHostnamesWithCookiesCallback(WKArrayRef wkHostnames, WKErrorRef w { Eina_List* hostnames = 0; Get_Hostnames_Async_Data* callbackData = static_cast<Get_Hostnames_Async_Data*>(context); - Ewk_Web_Error* ewkError = wkError ? ewk_web_error_new(wkError) : 0; + Ewk_Error* ewkError = wkError ? ewk_error_new(wkError) : 0; const size_t hostnameCount = WKArrayGetSize(wkHostnames); for (size_t i = 0; i < hostnameCount; ++i) { @@ -189,7 +189,7 @@ static void getHostnamesWithCookiesCallback(WKArrayRef wkHostnames, WKErrorRef w EINA_LIST_FREE(hostnames, item) eina_stringshare_del(static_cast<Eina_Stringshare*>(item)); if (ewkError) - ewk_web_error_free(ewkError); + ewk_error_free(ewkError); delete callbackData; } diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_cookie_manager.h b/Source/WebKit2/UIProcess/API/efl/ewk_cookie_manager.h index e37780864..c31b90018 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_cookie_manager.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_cookie_manager.h @@ -31,7 +31,7 @@ #ifndef ewk_cookie_manager_h #define ewk_cookie_manager_h -#include "ewk_web_error.h" +#include "ewk_error.h" #include <Eina.h> #ifdef __cplusplus @@ -77,7 +77,7 @@ typedef enum _Ewk_Cookie_Persistent_Storage Ewk_Cookie_Persistent_Storage; * @typedef Ewk_Cookie_Manager_Async_Policy_Get_Cb Ewk_Cookie_Manager_Async_Policy_Get_Cb * @brief Callback type for use with ewk_cookie_manager_async_accept_policy_get */ -typedef void (*Ewk_Cookie_Manager_Async_Policy_Get_Cb)(Ewk_Cookie_Accept_Policy policy, Ewk_Web_Error *error, void *event_info); +typedef void (*Ewk_Cookie_Manager_Async_Policy_Get_Cb)(Ewk_Cookie_Accept_Policy policy, Ewk_Error *error, void *event_info); /** * @typedef Ewk_Cookie_Manager_Async_Hostnames_Get_Cb Ewk_Cookie_Manager_Async_Hostnames_Get_Cb @@ -87,7 +87,7 @@ typedef void (*Ewk_Cookie_Manager_Async_Policy_Get_Cb)(Ewk_Cookie_Accept_Policy * save yourself some cpu cycles and use eina_stringshare_ref() instead of eina_stringshare_add() * or strdup(). */ -typedef void (*Ewk_Cookie_Manager_Async_Hostnames_Get_Cb)(Eina_List* hostnames, Ewk_Web_Error *error, void *event_info); +typedef void (*Ewk_Cookie_Manager_Async_Hostnames_Get_Cb)(Eina_List *hostnames, Ewk_Error *error, void *event_info); /** * @typedef Ewk_Cookie_Manager_Changes_Watch_Cb Ewk_Cookie_Manager_Changes_Watch_Cb diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_download_job.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_download_job.cpp index 61297920b..15a95b05f 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_download_job.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_download_job.cpp @@ -46,7 +46,7 @@ struct _Ewk_Download_Job { DownloadProxy* downloadProxy; Evas_Object* view; Ewk_Download_Job_State state; - Ewk_Url_Request* request; + RefPtr<Ewk_Url_Request> request; Ewk_Url_Response* response; double startTime; double endTime; @@ -59,7 +59,6 @@ struct _Ewk_Download_Job { , downloadProxy(download) , view(ewkView) , state(EWK_DOWNLOAD_JOB_STATE_NOT_STARTED) - , request(0) , response(0) , startTime(-1) , endTime(-1) @@ -69,8 +68,6 @@ struct _Ewk_Download_Job { ~_Ewk_Download_Job() { ASSERT(!__ref); - if (request) - ewk_url_request_unref(request); if (response) ewk_url_response_unref(response); } @@ -133,10 +130,10 @@ Ewk_Url_Request* ewk_download_job_request_get(const Ewk_Download_Job* download) if (!download->request) { EINA_SAFETY_ON_NULL_RETURN_VAL(download->downloadProxy, 0); WKRetainPtr<WKURLRequestRef> wkURLRequest(AdoptWK, toAPI(WebURLRequest::create(download->downloadProxy->request()).leakRef())); - const_cast<Ewk_Download_Job*>(download)->request = ewk_url_request_new(wkURLRequest.get()); + const_cast<Ewk_Download_Job*>(download)->request = adoptRef(ewk_url_request_new(wkURLRequest.get())); } - return download->request; + return download->request.get(); } Ewk_Url_Response* ewk_download_job_response_get(const Ewk_Download_Job* download) diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_download_job.h b/Source/WebKit2/UIProcess/API/efl/ewk_download_job.h index fdcc10e98..388276c9c 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_download_job.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_download_job.h @@ -112,7 +112,7 @@ EAPI Ewk_Url_Request *ewk_download_job_request_get(const Ewk_Download_Job *downl EAPI Ewk_Url_Response *ewk_download_job_response_get(const Ewk_Download_Job *download); /** - * Query the URI to which the downloaded file will be written. + * Query the URL to which the downloaded file will be written. * * @param download a #Ewk_Download_Job to query. * diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_download_job_private.h b/Source/WebKit2/UIProcess/API/efl/ewk_download_job_private.h index d043494c3..81b544bfe 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_download_job_private.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_download_job_private.h @@ -31,7 +31,7 @@ typedef struct _Ewk_Download_Job Ewk_Download_Job; typedef struct _Ewk_Url_Response Ewk_Url_Response; -typedef struct _Ewk_Web_Error Ewk_Web_Error; +typedef struct _Ewk_Error Ewk_Error; namespace WebKit { class DownloadProxy; diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_web_error.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_error.cpp index 70380bdd2..a7d576d0a 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_web_error.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_error.cpp @@ -24,13 +24,13 @@ */ #include "config.h" -#include "ewk_web_error.h" +#include "ewk_error.h" #include "ErrorsEfl.h" #include "WKEinaSharedString.h" #include "WKString.h" #include "WKURL.h" -#include "ewk_web_error_private.h" +#include "ewk_error_private.h" #include <WKAPICast.h> #include <WKError.h> #include <WKRetainPtr.h> @@ -39,24 +39,24 @@ using namespace WebCore; using namespace WebKit; -struct _Ewk_Web_Error { +struct _Ewk_Error { WKRetainPtr<WKErrorRef> wkError; WKEinaSharedString url; WKEinaSharedString description; - _Ewk_Web_Error(WKErrorRef errorRef) + _Ewk_Error(WKErrorRef errorRef) : wkError(errorRef) , url(AdoptWK, WKErrorCopyFailingURL(errorRef)) , description(AdoptWK, WKErrorCopyLocalizedDescription(errorRef)) { } - ~_Ewk_Web_Error() + ~_Ewk_Error() { } }; -#define EWK_WEB_ERROR_WK_GET_OR_RETURN(error, wkError_, ...) \ +#define EWK_ERROR_WK_GET_OR_RETURN(error, wkError_, ...) \ if (!(error)) { \ EINA_LOG_CRIT("error is NULL."); \ return __VA_ARGS__; \ @@ -67,64 +67,68 @@ struct _Ewk_Web_Error { } \ WKErrorRef wkError_ = (error)->wkError.get() -void ewk_web_error_free(Ewk_Web_Error* error) +/** + * @internal + * Frees the given object. + */ +void ewk_error_free(Ewk_Error* error) { EINA_SAFETY_ON_NULL_RETURN(error); delete error; } -Ewk_Web_Error_Type ewk_web_error_type_get(const Ewk_Web_Error* error) +Ewk_Error_Type ewk_error_type_get(const Ewk_Error* error) { - EWK_WEB_ERROR_WK_GET_OR_RETURN(error, wkError, EWK_WEB_ERROR_TYPE_NONE); + EWK_ERROR_WK_GET_OR_RETURN(error, wkError, EWK_ERROR_TYPE_NONE); WKRetainPtr<WKStringRef> wkDomain(AdoptWK, WKErrorCopyDomain(wkError)); WTF::String errorDomain = toWTFString(wkDomain.get()); if (errorDomain == errorDomainNetwork) - return EWK_WEB_ERROR_TYPE_NETWORK; + return EWK_ERROR_TYPE_NETWORK; if (errorDomain == errorDomainPolicy) - return EWK_WEB_ERROR_TYPE_POLICY; + return EWK_ERROR_TYPE_POLICY; if (errorDomain == errorDomainPlugin) - return EWK_WEB_ERROR_TYPE_PLUGIN; + return EWK_ERROR_TYPE_PLUGIN; if (errorDomain == errorDomainDownload) - return EWK_WEB_ERROR_TYPE_DOWNLOAD; + return EWK_ERROR_TYPE_DOWNLOAD; if (errorDomain == errorDomainPrint) - return EWK_WEB_ERROR_TYPE_PRINT; - return EWK_WEB_ERROR_TYPE_INTERNAL; + return EWK_ERROR_TYPE_PRINT; + return EWK_ERROR_TYPE_INTERNAL; } -const char* ewk_web_error_url_get(const Ewk_Web_Error* error) +const char* ewk_error_url_get(const Ewk_Error* error) { EINA_SAFETY_ON_NULL_RETURN_VAL(error, 0); return error->url; } -int ewk_web_error_code_get(const Ewk_Web_Error* error) +int ewk_error_code_get(const Ewk_Error* error) { - EWK_WEB_ERROR_WK_GET_OR_RETURN(error, wkError, 0); + EWK_ERROR_WK_GET_OR_RETURN(error, wkError, 0); return WKErrorGetErrorCode(wkError); } -const char* ewk_web_error_description_get(const Ewk_Web_Error* error) +const char* ewk_error_description_get(const Ewk_Error* error) { EINA_SAFETY_ON_NULL_RETURN_VAL(error, 0); return error->description; } -Eina_Bool ewk_web_error_cancellation_get(const Ewk_Web_Error* error) +Eina_Bool ewk_error_cancellation_get(const Ewk_Error* error) { - EWK_WEB_ERROR_WK_GET_OR_RETURN(error, wkError, false); + EWK_ERROR_WK_GET_OR_RETURN(error, wkError, false); return toImpl(wkError)->platformError().isCancellation(); } -Ewk_Web_Error* ewk_web_error_new(WKErrorRef error) +Ewk_Error* ewk_error_new(WKErrorRef error) { EINA_SAFETY_ON_NULL_RETURN_VAL(error, 0); - return new Ewk_Web_Error(error); + return new Ewk_Error(error); } diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_web_error.h b/Source/WebKit2/UIProcess/API/efl/ewk_error.h index 4ba0c7acd..01214d121 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_web_error.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_error.h @@ -24,12 +24,12 @@ */ /** - * @file ewk_web_error.h + * @file ewk_error.h * @brief Describes the Web Error API. */ -#ifndef ewk_web_error_h -#define ewk_web_error_h +#ifndef ewk_error_h +#define ewk_error_h #include <Eina.h> @@ -37,26 +37,19 @@ extern "C" { #endif -/** Creates a type name for @a Ewk_Web_Error. */ -typedef struct _Ewk_Web_Error Ewk_Web_Error; +/** Creates a type name for @a Ewk_Error. */ +typedef struct _Ewk_Error Ewk_Error; -/// Creates a type name for Ewk_Web_Error_Type. +/// Creates a type name for Ewk_Error_Type. typedef enum { - EWK_WEB_ERROR_TYPE_NONE, - EWK_WEB_ERROR_TYPE_INTERNAL, - EWK_WEB_ERROR_TYPE_NETWORK, - EWK_WEB_ERROR_TYPE_POLICY, - EWK_WEB_ERROR_TYPE_PLUGIN, - EWK_WEB_ERROR_TYPE_DOWNLOAD, - EWK_WEB_ERROR_TYPE_PRINT -} Ewk_Web_Error_Type; - -/** - * Frees the given object. - * - * @param error the error object to free - */ -EAPI void ewk_web_error_free(Ewk_Web_Error *error); + EWK_ERROR_TYPE_NONE, + EWK_ERROR_TYPE_INTERNAL, + EWK_ERROR_TYPE_NETWORK, + EWK_ERROR_TYPE_POLICY, + EWK_ERROR_TYPE_PLUGIN, + EWK_ERROR_TYPE_DOWNLOAD, + EWK_ERROR_TYPE_PRINT +} Ewk_Error_Type; /** * Query type for this error. @@ -69,7 +62,7 @@ EAPI void ewk_web_error_free(Ewk_Web_Error *error); * eina_stringshare_ref() instead of eina_stringshare_add() or * strdup(). */ -EAPI Ewk_Web_Error_Type ewk_web_error_type_get(const Ewk_Web_Error *error); +EAPI Ewk_Error_Type ewk_error_type_get(const Ewk_Error *error); /** * Query failing URL for this error. @@ -84,7 +77,7 @@ EAPI Ewk_Web_Error_Type ewk_web_error_type_get(const Ewk_Web_Error *error); * eina_stringshare_ref() instead of eina_stringshare_add() or * strdup(). */ -EAPI const char *ewk_web_error_url_get(const Ewk_Web_Error *error); +EAPI const char *ewk_error_url_get(const Ewk_Error *error); /** * Query HTTP error code. @@ -93,7 +86,7 @@ EAPI const char *ewk_web_error_url_get(const Ewk_Web_Error *error); * * @return the HTTP error code. */ -EAPI int ewk_web_error_code_get(const Ewk_Web_Error *error); +EAPI int ewk_error_code_get(const Ewk_Error *error); /** * Query description for this error. @@ -106,7 +99,7 @@ EAPI int ewk_web_error_code_get(const Ewk_Web_Error *error); * eina_stringshare_ref() instead of eina_stringshare_add() or * strdup(). */ -EAPI const char *ewk_web_error_description_get(const Ewk_Web_Error *error); +EAPI const char *ewk_error_description_get(const Ewk_Error *error); /** * Query if error should be treated as a cancellation. @@ -115,10 +108,10 @@ EAPI const char *ewk_web_error_description_get(const Ewk_Web_Error *error); * * @return @c EINA_TRUE if this error should be treated as a cancellation, @c EINA_FALSE otherwise */ -EAPI Eina_Bool ewk_web_error_cancellation_get(const Ewk_Web_Error *error); +EAPI Eina_Bool ewk_error_cancellation_get(const Ewk_Error *error); #ifdef __cplusplus } #endif -#endif // ewk_web_error_h +#endif // ewk_error_h diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_web_error_private.h b/Source/WebKit2/UIProcess/API/efl/ewk_error_private.h index c9a31e50a..2f01988c2 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_web_error_private.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_error_private.h @@ -23,13 +23,14 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ewk_web_error_private_h -#define ewk_web_error_private_h +#ifndef ewk_error_private_h +#define ewk_error_private_h #include <WKError.h> -typedef struct _Ewk_Web_Error Ewk_Web_Error; +typedef struct _Ewk_Error Ewk_Error; -Ewk_Web_Error* ewk_web_error_new(WKErrorRef error); +Ewk_Error* ewk_error_new(WKErrorRef error); +void ewk_error_free(Ewk_Error* error); -#endif // ewk_web_error_private_h +#endif // ewk_error_private_h diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_main.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_main.cpp index fcc9faf1a..17e2b1eea 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_main.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_main.cpp @@ -31,6 +31,10 @@ #include <glib-object.h> #include <glib.h> +#ifdef HAVE_ECORE_X +#include <Ecore_X.h> +#endif + static int _ewkInitCount = 0; /** @@ -68,6 +72,13 @@ int ewk_init(void) goto error_ecore_evas; } +#ifdef HAVE_ECORE_X + if (!ecore_x_init(0)) { + CRITICAL("could not init ecore_x."); + goto error_ecore_x; + } +#endif + g_type_init(); if (!ecore_main_loop_glib_integrate()) { @@ -77,6 +88,10 @@ int ewk_init(void) return ++_ewkInitCount; +#ifdef HAVE_ECORE_X +error_ecore_x: + ecore_evas_shutdown(); +#endif error_ecore_evas: ecore_shutdown(); error_ecore: @@ -95,6 +110,9 @@ int ewk_shutdown(void) if (--_ewkInitCount) return _ewkInitCount; +#ifdef HAVE_ECORE_X + ecore_x_shutdown(); +#endif ecore_evas_shutdown(); ecore_shutdown(); evas_shutdown(); diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_navigation_data.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_navigation_data.cpp new file mode 100644 index 000000000..27a51f083 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/ewk_navigation_data.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2012 Intel Corporation. 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 "ewk_navigation_data.h" + +#include "ewk_navigation_data_private.h" + +using namespace WebKit; + +Ewk_Navigation_Data* ewk_navigation_data_ref(Ewk_Navigation_Data* data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0); + + data->ref(); + + return data; +} + +void ewk_navigation_data_unref(Ewk_Navigation_Data* data) +{ + EINA_SAFETY_ON_NULL_RETURN(data); + + data->deref(); +} + +const char* ewk_navigation_data_title_get(const Ewk_Navigation_Data* data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0); + + return data->title; +} + +Ewk_Url_Request* ewk_navigation_data_original_request_get(const Ewk_Navigation_Data* data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0); + + return data->request.get(); +} + +const char* ewk_navigation_data_url_get(const Ewk_Navigation_Data* data) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0); + + return data->url; +} + +Ewk_Navigation_Data* ewk_navigation_data_new(WKNavigationDataRef dataRef) +{ + ASSERT(dataRef); + EINA_SAFETY_ON_NULL_RETURN_VAL(dataRef, 0); + + return new Ewk_Navigation_Data(dataRef); +} diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_navigation_data.h b/Source/WebKit2/UIProcess/API/efl/ewk_navigation_data.h new file mode 100644 index 000000000..1a1e60732 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/ewk_navigation_data.h @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2012 Intel Corporation. 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. + */ + +/** + * @file ewk_navigation_data.h + * @brief Describes the Ewk navigation data API. + */ + +#ifndef ewk_navigation_data_h +#define ewk_navigation_data_h + +#include "ewk_url_request.h" +#include <Eina.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** Creates a type name for _Ewk_Navigation_Data */ +typedef struct _Ewk_Navigation_Data Ewk_Navigation_Data; + +/** + * Increases the reference count of the given object. + * + * @param data the navigation data object to increase the reference count + * + * @return a pointer to the object on success, @c NULL otherwise. + */ +EAPI Ewk_Navigation_Data *ewk_navigation_data_ref(Ewk_Navigation_Data *data); + +/** + * Decreases the reference count of the given object, possibly freeing it. + * + * When the reference count reaches 0, the object is freed. + * + * @param data the navigation data object to decrease the reference count + */ +EAPI void ewk_navigation_data_unref(Ewk_Navigation_Data *data); + +/** + * Returns title for this navigation data. + * + * The title of the navigated page. + * + * @param data navigation data object to query + * + * @return the title or @c NULL in case of error. This pointer is + * guaranteed to be eina_stringshare, so whenever possible + * save yourself some cpu cycles and use + * eina_stringshare_ref() instead of eina_stringshare_add() or + * strdup(). + */ +EAPI const char *ewk_navigation_data_title_get(const Ewk_Navigation_Data *data); + +/** + * Returns the original request for this navigation data. + * + * @param data navigation data object to query + * + * @return The URL request pointer or @c NULL in case of error. + */ +EAPI Ewk_Url_Request *ewk_navigation_data_original_request_get(const Ewk_Navigation_Data *data); + +/** + * Returns URL for this navigation data. + * + * The URL of the navigated page. + * + * @param data navigation data object to query + * + * @return the URL of the @a data or @c NULL in case of error. This pointer is + * guaranteed to be eina_stringshare, so whenever possible + * save yourself some cpu cycles and use + * eina_stringshare_ref() instead of eina_stringshare_add() or + * strdup() + */ +EAPI const char *ewk_navigation_data_url_get(const Ewk_Navigation_Data *data); + +#ifdef __cplusplus +} +#endif + +#endif // ewk_navigation_data_h diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_navigation_data_private.h b/Source/WebKit2/UIProcess/API/efl/ewk_navigation_data_private.h new file mode 100644 index 000000000..6e42dc629 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/ewk_navigation_data_private.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2012 Intel Corporation. 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 ewk_navigation_data_private_h +#define ewk_navigation_data_private_h + +#include "WKAPICast.h" +#include "WKEinaSharedString.h" +#include "WKNavigationData.h" +#include "WKRetainPtr.h" +#include "ewk_private.h" +#include "ewk_url_request_private.h" + +/** + * \struct _Ewk_Navigation_Data + * @brief Contains the navigation data details. + */ +struct _Ewk_Navigation_Data : public RefCounted<_Ewk_Navigation_Data> { + WKEinaSharedString title; + WKEinaSharedString url; + RefPtr<Ewk_Url_Request> request; + + _Ewk_Navigation_Data(WKNavigationDataRef dataRef) + : title(AdoptWK, WKNavigationDataCopyTitle(dataRef)) + , url(AdoptWK, WKNavigationDataCopyURL(dataRef)) + { + WKRetainPtr<WKURLRequestRef> requestWK(AdoptWK, WKNavigationDataCopyOriginalRequest(dataRef)); + request = adoptRef(ewk_url_request_new(requestWK.get())); + } +}; + +typedef struct _Ewk_Navigation_Data Ewk_Navigation_Data; + +Ewk_Navigation_Data* ewk_navigation_data_new(WKNavigationDataRef dataRef); + +#endif // ewk_navigation_data_private_h diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_navigation_policy_decision.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_navigation_policy_decision.cpp index d46805faa..6ebbebb5c 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_navigation_policy_decision.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_navigation_policy_decision.cpp @@ -47,10 +47,10 @@ struct _Ewk_Navigation_Policy_Decision { Ewk_Navigation_Type navigationType; Event_Mouse_Button mouseButton; Event_Modifier_Keys modifiers; - Ewk_Url_Request* request; + RefPtr<Ewk_Url_Request> request; WKEinaSharedString frameName; - _Ewk_Navigation_Policy_Decision(WKFramePolicyListenerRef _listener, Ewk_Navigation_Type _navigationType, Event_Mouse_Button _mouseButton, Event_Modifier_Keys _modifiers, Ewk_Url_Request* _request, const char* _frameName) + _Ewk_Navigation_Policy_Decision(WKFramePolicyListenerRef _listener, Ewk_Navigation_Type _navigationType, Event_Mouse_Button _mouseButton, Event_Modifier_Keys _modifiers, PassRefPtr<Ewk_Url_Request> _request, const char* _frameName) : __ref(1) , listener(_listener) , actedUponByClient(false) @@ -68,8 +68,6 @@ struct _Ewk_Navigation_Policy_Decision { // This is the default choice for all policy decisions in WebPageProxy.cpp. if (!actedUponByClient) WKFramePolicyListenerUse(listener.get()); - - ewk_url_request_unref(request); } }; @@ -124,7 +122,7 @@ Ewk_Url_Request* ewk_navigation_policy_request_get(const Ewk_Navigation_Policy_D { EINA_SAFETY_ON_NULL_RETURN_VAL(decision, 0); - return decision->request; + return decision->request.get(); } void ewk_navigation_policy_decision_accept(Ewk_Navigation_Policy_Decision* decision) @@ -177,6 +175,6 @@ Ewk_Navigation_Policy_Decision* ewk_navigation_policy_decision_new(WKFrameNaviga static_cast<Ewk_Navigation_Type>(navigationType), static_cast<Event_Mouse_Button>(mouseButton), static_cast<Event_Modifier_Keys>(modifiers), - ewk_url_request_new(request), + adoptRef(ewk_url_request_new(request)), frameName); } diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_web_resource.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_resource.cpp index 89879eead..aaa7e98e7 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_web_resource.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_resource.cpp @@ -24,30 +24,30 @@ */ #include "config.h" -#include "ewk_web_resource.h" +#include "ewk_resource.h" #include "WKEinaSharedString.h" -#include "ewk_web_resource_private.h" +#include "ewk_resource_private.h" #include <wtf/text/CString.h> -struct _Ewk_Web_Resource { - unsigned int __ref; /**< the reference count of the object */ +struct _Ewk_Resource { + unsigned __ref; /**< the reference count of the object */ WKEinaSharedString url; bool isMainResource; - _Ewk_Web_Resource(const char* url, bool isMainResource) + _Ewk_Resource(const char* url, bool isMainResource) : __ref(1) , url(url) , isMainResource(isMainResource) { } - ~_Ewk_Web_Resource() + ~_Ewk_Resource() { ASSERT(!__ref); } }; -Ewk_Web_Resource* ewk_web_resource_ref(Ewk_Web_Resource* resource) +Ewk_Resource* ewk_resource_ref(Ewk_Resource* resource) { EINA_SAFETY_ON_NULL_RETURN_VAL(resource, 0); @@ -56,7 +56,7 @@ Ewk_Web_Resource* ewk_web_resource_ref(Ewk_Web_Resource* resource) return resource; } -void ewk_web_resource_unref(Ewk_Web_Resource* resource) +void ewk_resource_unref(Ewk_Resource* resource) { EINA_SAFETY_ON_NULL_RETURN(resource); @@ -66,7 +66,7 @@ void ewk_web_resource_unref(Ewk_Web_Resource* resource) delete resource; } -const char* ewk_web_resource_url_get(const Ewk_Web_Resource* resource) +const char* ewk_resource_url_get(const Ewk_Resource* resource) { EINA_SAFETY_ON_NULL_RETURN_VAL(resource, 0); @@ -75,16 +75,16 @@ const char* ewk_web_resource_url_get(const Ewk_Web_Resource* resource) /** * @internal - * Constructs a Ewk_Web_Resource. + * Constructs a Ewk_Resource. */ -Ewk_Web_Resource* ewk_web_resource_new(const char* url, bool isMainResource) +Ewk_Resource* ewk_resource_new(const char* url, bool isMainResource) { EINA_SAFETY_ON_NULL_RETURN_VAL(url, 0); - return new Ewk_Web_Resource(url, isMainResource); + return new Ewk_Resource(url, isMainResource); } -Eina_Bool ewk_web_resource_main_resource_get(const Ewk_Web_Resource* resource) +Eina_Bool ewk_resource_main_resource_get(const Ewk_Resource* resource) { EINA_SAFETY_ON_NULL_RETURN_VAL(resource, false); diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_web_resource.h b/Source/WebKit2/UIProcess/API/efl/ewk_resource.h index dc2cf087d..a2f4786b8 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_web_resource.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_resource.h @@ -24,12 +24,12 @@ */ /** - * @file ewk_web_resource.h + * @file ewk_resource.h * @brief Describes the Web Resource API. */ -#ifndef ewk_web_resource_h -#define ewk_web_resource_h +#ifndef ewk_resource_h +#define ewk_resource_h #include <Eina.h> @@ -37,8 +37,8 @@ extern "C" { #endif -/** Creates a type name for @a Ewk_Web_Resource. */ -typedef struct _Ewk_Web_Resource Ewk_Web_Resource; +/** Creates a type name for @a Ewk_Resource. */ +typedef struct _Ewk_Resource Ewk_Resource; /** * Increases the reference count of the given object. @@ -47,7 +47,7 @@ typedef struct _Ewk_Web_Resource Ewk_Web_Resource; * * @return a pointer to the object on success, @c NULL otherwise. */ -EAPI Ewk_Web_Resource *ewk_web_resource_ref(Ewk_Web_Resource *resource); +EAPI Ewk_Resource *ewk_resource_ref(Ewk_Resource *resource); /** * Decreases the reference count of the given object, possibly freeing it. @@ -56,7 +56,7 @@ EAPI Ewk_Web_Resource *ewk_web_resource_ref(Ewk_Web_Resource *resource); * * @param resource the resource object to decrease the reference count */ -EAPI void ewk_web_resource_unref(Ewk_Web_Resource *resource); +EAPI void ewk_resource_unref(Ewk_Resource *resource); /** * Query URL for this resource. @@ -69,7 +69,7 @@ EAPI void ewk_web_resource_unref(Ewk_Web_Resource *resource); * eina_stringshare_ref() instead of eina_stringshare_add() or * strdup(). */ -EAPI const char *ewk_web_resource_url_get(const Ewk_Web_Resource *resource); +EAPI const char *ewk_resource_url_get(const Ewk_Resource *resource); /** * Query if this is the main resource. @@ -78,10 +78,10 @@ EAPI const char *ewk_web_resource_url_get(const Ewk_Web_Resource *resource); * * @return @c EINA_TRUE if this is the main resource, @c EINA_FALSE otherwise */ -EAPI Eina_Bool ewk_web_resource_main_resource_get(const Ewk_Web_Resource *resource); +EAPI Eina_Bool ewk_resource_main_resource_get(const Ewk_Resource *resource); #ifdef __cplusplus } #endif -#endif // ewk_web_resource_h +#endif // ewk_resource_h diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_web_resource_private.h b/Source/WebKit2/UIProcess/API/efl/ewk_resource_private.h index 5b44fe19f..4fd4cfd62 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_web_resource_private.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_resource_private.h @@ -23,11 +23,11 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ewk_web_resource_private_h -#define ewk_web_resource_private_h +#ifndef ewk_resource_private_h +#define ewk_resource_private_h -typedef struct _Ewk_Web_Resource Ewk_Web_Resource; +typedef struct _Ewk_Resource Ewk_Resource; -Ewk_Web_Resource* ewk_web_resource_new(const char* uri, bool isMainResource); +Ewk_Resource* ewk_resource_new(const char* url, bool isMainResource); -#endif // ewk_web_resource_private_h +#endif // ewk_resource_private_h diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_settings.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_settings.cpp index a1f51b8bc..a9f6b0932 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_settings.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_settings.cpp @@ -28,6 +28,7 @@ #include "ewk_settings_private.h" #include <WebKit2/WKPreferences.h> +#include <WebKit2/WKPreferencesPrivate.h> using namespace WebKit; @@ -99,3 +100,51 @@ Eina_Bool ewk_settings_developer_extras_enabled_get(const Ewk_Settings* settings return WKPreferencesGetDeveloperExtrasEnabled(settings->preferences.get()); } + +Eina_Bool ewk_settings_file_access_from_file_urls_allowed_set(Ewk_Settings* settings, Eina_Bool enable) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); + + WKPreferencesSetFileAccessFromFileURLsAllowed(settings->preferences.get(), enable); + + return true; +} + +Eina_Bool ewk_settings_file_access_from_file_urls_allowed_get(const Ewk_Settings* settings) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); + + return WKPreferencesGetFileAccessFromFileURLsAllowed(settings->preferences.get()); +} + +Eina_Bool ewk_settings_frame_flattening_enabled_set(Ewk_Settings* settings, Eina_Bool enable) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); + + WKPreferencesSetFrameFlatteningEnabled(settings->preferences.get(), enable); + + return true; +} + +Eina_Bool ewk_settings_frame_flattening_enabled_get(const Ewk_Settings* settings) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); + + return WKPreferencesGetFrameFlatteningEnabled(settings->preferences.get()); +} + +Eina_Bool ewk_settings_dns_prefetching_enabled_set(Ewk_Settings* settings, Eina_Bool enable) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); + + WKPreferencesSetDNSPrefetchingEnabled(settings->preferences.get(), enable); + + return true; +} + +Eina_Bool ewk_settings_dns_prefetching_enabled_get(const Ewk_Settings* settings) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); + + return WKPreferencesGetDNSPrefetchingEnabled(settings->preferences.get()); +} diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_settings.h b/Source/WebKit2/UIProcess/API/efl/ewk_settings.h index 1d8b213d0..8b17d1cbc 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_settings.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_settings.h @@ -71,16 +71,18 @@ EAPI Eina_Bool ewk_settings_fullscreen_enabled_get(const Ewk_Settings *settings) /** * Enables/disables the javascript executing. * + * By default, JavaScript execution is enabled. + * * @param settings settings object to set javascript executing * @param enable @c EINA_TRUE to enable javascript executing - * @c EINA_FALSE to disable + * @c EINA_FALSE to disable * * @return @c EINA_TRUE on success or @c EINA_FALSE on failure */ EAPI Eina_Bool ewk_settings_javascript_enabled_set(Ewk_Settings *settings, Eina_Bool enable); /** - * Returns the javascript can be executable or not. + * Returns whether JavaScript execution is enabled. * * @param settings settings object to query if the javascript can be executed * @@ -92,20 +94,22 @@ EAPI Eina_Bool ewk_settings_javascript_enabled_get(const Ewk_Settings *settings) /** * Enables/disables auto loading of the images. * + * By default, auto loading of the images is enabled. + * * @param settings settings object to set auto loading of the images - * @param automatic @c EINA_TRUE to enable auto loading of the images, - * @c EINA_FALSE to disable + * @param automatic @c EINA_TRUE to enable auto loading of the images + * @c EINA_FALSE to disable * * @return @c EINA_TRUE on success or @c EINA_FALSE on failure */ EAPI Eina_Bool ewk_settings_loads_images_automatically_set(Ewk_Settings *settings, Eina_Bool automatic); /** - * Returns the images can be loaded automatically or not. + * Returns whether the images can be loaded automatically or not. * * @param settings settings object to get auto loading of the images * - * @return @c EINA_TRUE if the images are loaded automatically, + * @return @c EINA_TRUE if the images are loaded automatically * @c EINA_FALSE if not or on failure */ EAPI Eina_Bool ewk_settings_loads_images_automatically_get(const Ewk_Settings *settings); @@ -116,7 +120,8 @@ EAPI Eina_Bool ewk_settings_loads_images_automatically_get(const Ewk_Settings *s * By default, the developer extensions are disabled. * * @param settings settings object to set developer extensions - * @param enable @c EINA_TRUE to enable developer extensions, @c EINA_FALSE to disable + * @param enable @c EINA_TRUE to enable developer extensions + * @c EINA_FALSE to disable * * @return @c EINA_TRUE on success or @EINA_FALSE on failure */ @@ -134,6 +139,86 @@ EAPI Eina_Bool ewk_settings_developer_extras_enabled_set(Ewk_Settings *settings, */ EAPI Eina_Bool ewk_settings_developer_extras_enabled_get(const Ewk_Settings *settings); +/** + * Allow / Disallow file access from file:// URLs. + * + * By default, file access from file:// URLs is not allowed. + * + * @param settings settings object to set file access permission + * @param enable @c EINA_TRUE to enable file access permission + * @c EINA_FALSE to disable + * + * @return @c EINA_TRUE on success or @EINA_FALSE on failure + */ +EAPI Eina_Bool ewk_settings_file_access_from_file_urls_allowed_set(Ewk_Settings *settings, Eina_Bool enable); + +/** + * Queries if file access from file:// URLs is allowed. + * + * By default, file access from file:// URLs is not allowed. + * + * @param settings settings object to query file access permission + * + * @return @c EINA_TRUE if file access from file:// URLs is allowed + * @c EINA_FALSE if not or on failure + */ +EAPI Eina_Bool ewk_settings_file_access_from_file_urls_allowed_get(const Ewk_Settings *settings); + +/** + * Enables/disables frame flattening. + * + * By default, the frame flattening is disabled. + * + * @param settings settings object to set the frame flattening + * @param enable @c EINA_TRUE to enable the frame flattening + * @c EINA_FALSE to disable + * + * @return @c EINA_TRUE on success or @c EINA_FALSE on failure + * + * @see ewk_settings_enable_frame_flattening_get() + */ +EAPI Eina_Bool ewk_settings_frame_flattening_enabled_set(Ewk_Settings *settings, Eina_Bool enable); + +/** + * Returns whether the frame flattening is enabled. + * + * The frame flattening is a feature which expands sub frames until all the frames become + * one scrollable page. + * + * @param settings settings object to get the frame flattening. + * + * @return @c EINA_TRUE if the frame flattening is enabled + * @c EINA_FALSE if not or on failure + */ +EAPI Eina_Bool ewk_settings_frame_flattening_enabled_get(const Ewk_Settings *settings); + +/** + * Enables/disables DNS prefetching. + * + * By default, DNS prefetching is disabled. + * + * @param settings settings object to set DNS prefetching + * @param enable @c EINA_TRUE to enable DNS prefetching or + * @c EINA_FALSE to disable + * + * @return @c EINA_TRUE on success or @c EINA_FALSE on failure + * + * @see ewk_settings_DNS_prefetching_enabled_get() + */ +EAPI Eina_Bool ewk_settings_dns_prefetching_enabled_set(Ewk_Settings *settings, Eina_Bool enable); + +/** + * Returns whether DNS prefetching is enabled or not. + * + * DNS prefetching is an attempt to resolve domain names before a user tries to follow a link. + * + * @param settings settings object to get DNS prefetching + * + * @return @c EINA_TRUE if DNS prefetching is enabled + * @c EINA_FALSE if not or on failure + */ +EAPI Eina_Bool ewk_settings_dns_prefetching_enabled_get(const Ewk_Settings *settings); + #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_url_request.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_url_request.cpp index 9e7c80c40..b1c94ad61 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_url_request.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_url_request.cpp @@ -26,44 +26,14 @@ #include "config.h" #include "ewk_url_request.h" -#include "WKAPICast.h" -#include "WKEinaSharedString.h" -#include "WKURL.h" -#include "WKURLRequest.h" -#include "WebURLRequest.h" #include "ewk_url_request_private.h" -#include <wtf/text/CString.h> using namespace WebKit; -/** - * \struct _Ewk_Url_Request - * @brief Contains the URL request data. - */ -struct _Ewk_Url_Request { - unsigned int __ref; /**< the reference count of the object */ - - WKEinaSharedString url; - WKEinaSharedString first_party; - WKEinaSharedString http_method; - - _Ewk_Url_Request(WKURLRequestRef requestRef) - : __ref(1) - , url(AdoptWK, WKURLRequestCopyURL(requestRef)) - , first_party(AdoptWK, WKURLRequestCopyFirstPartyForCookies(requestRef)) - , http_method(AdoptWK, WKURLRequestCopyHTTPMethod(requestRef)) - { } - - ~_Ewk_Url_Request() - { - ASSERT(!__ref); - } -}; - Ewk_Url_Request* ewk_url_request_ref(Ewk_Url_Request* request) { EINA_SAFETY_ON_NULL_RETURN_VAL(request, 0); - ++request->__ref; + request->ref(); return request; } @@ -72,10 +42,7 @@ void ewk_url_request_unref(Ewk_Url_Request* request) { EINA_SAFETY_ON_NULL_RETURN(request); - if (--request->__ref) - return; - - delete request; + request->deref(); } const char* ewk_url_request_url_get(const Ewk_Url_Request* request) @@ -89,14 +56,14 @@ const char* ewk_request_cookies_first_party_get(const Ewk_Url_Request* request) { EINA_SAFETY_ON_NULL_RETURN_VAL(request, 0); - return request->first_party; + return request->firstParty; } const char* ewk_url_request_http_method_get(const Ewk_Url_Request* request) { EINA_SAFETY_ON_NULL_RETURN_VAL(request, 0); - return request->http_method; + return request->httpMethod; } /** diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_url_request_private.h b/Source/WebKit2/UIProcess/API/efl/ewk_url_request_private.h index 548b6e91e..acbc984e2 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_url_request_private.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_url_request_private.h @@ -26,6 +26,29 @@ #ifndef ewk_url_request_private_h #define ewk_url_request_private_h +#include "WKEinaSharedString.h" +#include "WKURL.h" +#include "WKURLRequest.h" +#include "WebURLRequest.h" + +/** + * \struct _Ewk_Url_Request + * @brief Contains the URL request data. + */ +struct _Ewk_Url_Request : public RefCounted<_Ewk_Url_Request> { + WKEinaSharedString url; + WKEinaSharedString firstParty; + WKEinaSharedString httpMethod; + + _Ewk_Url_Request(WKURLRequestRef requestRef) + : url(AdoptWK, WKURLRequestCopyURL(requestRef)) + , firstParty(AdoptWK, WKURLRequestCopyFirstPartyForCookies(requestRef)) + , httpMethod(AdoptWK, WKURLRequestCopyHTTPMethod(requestRef)) + { } +}; + +typedef struct _Ewk_Url_Request Ewk_Url_Request; + Ewk_Url_Request* ewk_url_request_new(WKURLRequestRef); #endif // ewk_url_request_private_h diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp index 10a68c404..07a942264 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp @@ -44,6 +44,7 @@ #include "ewk_popup_menu_item.h" #include "ewk_popup_menu_item_private.h" #include "ewk_private.h" +#include "ewk_resource.h" #include "ewk_settings_private.h" #include "ewk_view_find_client_private.h" #include "ewk_view_form_client_private.h" @@ -52,7 +53,6 @@ #include "ewk_view_private.h" #include "ewk_view_resource_load_client_private.h" #include "ewk_view_ui_client_private.h" -#include "ewk_web_resource.h" #include <Ecore_Evas.h> #include <Edje.h> #include <WebCore/Cursor.h> @@ -64,6 +64,10 @@ #include "WebFullScreenManagerProxy.h" #endif +#if ENABLE(INSPECTOR) +#include "WebInspectorProxy.h" +#endif + #if USE(ACCELERATED_COMPOSITING) #include <Evas_GL.h> #endif @@ -79,9 +83,33 @@ static const char EWK_VIEW_TYPE_STR[] = "EWK2_View"; static const int defaultCursorSize = 16; -typedef HashMap<uint64_t, Ewk_Web_Resource*> LoadingResourcesMap; +typedef HashMap<uint64_t, Ewk_Resource*> LoadingResourcesMap; static void _ewk_view_priv_loading_resources_clear(LoadingResourcesMap& loadingResourcesMap); +typedef HashMap<const WebPageProxy*, const Evas_Object*> PageViewMap; + +static inline PageViewMap& pageViewMap() +{ + DEFINE_STATIC_LOCAL(PageViewMap, map, ()); + return map; +} + +static inline void addToPageViewMap(const Evas_Object* ewkView) +{ + ASSERT(ewkView); + ASSERT(ewk_view_page_get(ewkView)); + PageViewMap::AddResult result = pageViewMap().add(ewk_view_page_get(ewkView), ewkView); + ASSERT_UNUSED(result, result.isNewEntry); +} + +static inline void removeFromPageViewMap(const Evas_Object* ewkView) +{ + ASSERT(ewkView); + ASSERT(ewk_view_page_get(ewkView)); + ASSERT(pageViewMap().contains(ewk_view_page_get(ewkView))); + pageViewMap().remove(ewk_view_page_get(ewkView)); +} + struct _Ewk_View_Private_Data { OwnPtr<PageClientImpl> pageClient; #if USE(COORDINATED_GRAPHICS) @@ -89,7 +117,7 @@ struct _Ewk_View_Private_Data { #endif RefPtr<WebPageProxy> pageProxy; - WKEinaSharedString uri; + WKEinaSharedString url; WKEinaSharedString title; WKEinaSharedString theme; WKEinaSharedString customEncoding; @@ -101,6 +129,9 @@ struct _Ewk_View_Private_Data { bool areMouseEventsEnabled; WKColorPickerResultListenerRef colorPickerResultListener; Ewk_Context* context; +#if ENABLE(TOUCH_EVENTS) + bool areTouchEventsEnabled; +#endif WebPopupMenuProxyEfl* popupMenuProxy; Eina_List* popupMenuItems; @@ -121,6 +152,9 @@ struct _Ewk_View_Private_Data { , areMouseEventsEnabled(false) , colorPickerResultListener(0) , context(0) +#if ENABLE(TOUCH_EVENTS) + , areTouchEventsEnabled(false) +#endif , popupMenuProxy(0) , popupMenuItems(0) #ifdef HAVE_ECORE_X @@ -356,6 +390,65 @@ static void _ewk_view_on_key_up(void* data, Evas*, Evas_Object*, void* eventInfo smartData->api->key_up(smartData, upEvent); } +static void _ewk_view_on_show(void* data, Evas*, Evas_Object*, void* /*eventInfo*/) +{ + Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data); + EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv); + priv->pageProxy->viewStateDidChange(WebPageProxy::ViewIsVisible); +} + +static void _ewk_view_on_hide(void* data, Evas*, Evas_Object*, void* /*eventInfo*/) +{ + Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(data); + EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv); + + // This call may look wrong, but we really need to pass ViewIsVisible here. + // viewStateDidChange() itself is responsible for actually setting the visibility to Visible or Hidden + // depending on what WebPageProxy::isViewVisible() returns, this simply triggers the process. + priv->pageProxy->viewStateDidChange(WebPageProxy::ViewIsVisible); +} + +#if ENABLE(TOUCH_EVENTS) +static inline void _ewk_view_feed_touch_event_using_touch_point_list_of_evas(Evas_Object* ewkView, Ewk_Touch_Event_Type type) +{ + EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData); + + unsigned count = evas_touch_point_list_count(smartData->base.evas); + if (!count) + return; + + Eina_List* points = 0; + for (unsigned i = 0; i < count; ++i) { + Ewk_Touch_Point* point = new Ewk_Touch_Point; + point->id = evas_touch_point_list_nth_id_get(smartData->base.evas, i); + evas_touch_point_list_nth_xy_get(smartData->base.evas, i, &point->x, &point->y); + point->state = evas_touch_point_list_nth_state_get(smartData->base.evas, i); + points = eina_list_append(points, point); + } + + ewk_view_feed_touch_event(ewkView, type, points, evas_key_modifier_get(smartData->base.evas)); + + void* data; + EINA_LIST_FREE(points, data) + delete static_cast<Ewk_Touch_Point*>(data); +} + +static void _ewk_view_on_touch_down(void* /* data */, Evas* /* canvas */, Evas_Object* ewkView, void* /* eventInfo */) +{ + _ewk_view_feed_touch_event_using_touch_point_list_of_evas(ewkView, EWK_TOUCH_START); +} + +static void _ewk_view_on_touch_up(void* /* data */, Evas* /* canvas */, Evas_Object* ewkView, void* /* eventInfo */) +{ + _ewk_view_feed_touch_event_using_touch_point_list_of_evas(ewkView, EWK_TOUCH_END); +} + +static void _ewk_view_on_touch_move(void* /* data */, Evas* /* canvas */, Evas_Object* ewkView, void* /* eventInfo */) +{ + _ewk_view_feed_touch_event_using_touch_point_list_of_evas(ewkView, EWK_TOUCH_MOVE); +} +#endif + static Evas_Smart_Class g_parentSmartClass = EVAS_SMART_CLASS_INIT_NULL; static Ewk_View_Private_Data* _ewk_view_priv_new(Ewk_View_Smart_Data* smartData) @@ -379,7 +472,7 @@ static void _ewk_view_priv_loading_resources_clear(LoadingResourcesMap& loadingR LoadingResourcesMap::iterator it = loadingResourcesMap.begin(); LoadingResourcesMap::iterator end = loadingResourcesMap.end(); for ( ; it != end; ++it) - ewk_web_resource_unref(it->second); + ewk_resource_unref(it->value); loadingResourcesMap.clear(); } @@ -434,11 +527,14 @@ static void _ewk_view_smart_add(Evas_Object* ewkView) CONNECT(EVAS_CALLBACK_MOUSE_WHEEL, _ewk_view_on_mouse_wheel); CONNECT(EVAS_CALLBACK_KEY_DOWN, _ewk_view_on_key_down); CONNECT(EVAS_CALLBACK_KEY_UP, _ewk_view_on_key_up); + CONNECT(EVAS_CALLBACK_SHOW, _ewk_view_on_show); + CONNECT(EVAS_CALLBACK_HIDE, _ewk_view_on_hide); #undef CONNECT } static void _ewk_view_smart_del(Evas_Object* ewkView) { + removeFromPageViewMap(ewkView); EWK_VIEW_SD_GET(ewkView, smartData); if (smartData && smartData->priv) _ewk_view_priv_del(smartData->priv); @@ -530,6 +626,7 @@ bool ewk_view_accelerated_compositing_mode_enter(const Evas_Object* ewkView) return false; } + priv->viewportHandler->setRendererActive(true); return true; } @@ -708,6 +805,9 @@ static void _ewk_view_initialize(Evas_Object* ewkView, Ewk_Context* context, WKP priv->pageProxy = toImpl(ewk_context_WKContext_get(context))->createWebPage(priv->pageClient.get(), toImpl(pageGroupRef)); else priv->pageProxy = toImpl(ewk_context_WKContext_get(context))->createWebPage(priv->pageClient.get(), WebPageGroup::create().get()); + + addToPageViewMap(ewkView); + #if USE(COORDINATED_GRAPHICS) priv->pageProxy->pageGroup()->preferences()->setAcceleratedCompositingEnabled(true); priv->pageProxy->pageGroup()->preferences()->setForceCompositingMode(true); @@ -812,11 +912,11 @@ Ewk_Context* ewk_view_context_get(const Evas_Object* ewkView) /** * @internal - * The uri of view was changed by the frame loader. + * The url of view was changed by the frame loader. * - * Emits signal: "uri,changed" with pointer to new uri string. + * Emits signal: "url,changed" with pointer to new url string. */ -void ewk_view_uri_update(Evas_Object* ewkView) +void ewk_view_url_update(Evas_Object* ewkView) { EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData); EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv); @@ -825,32 +925,32 @@ void ewk_view_uri_update(Evas_Object* ewkView) if (activeURL.isEmpty()) return; - if (priv->uri == activeURL.utf8().data()) + if (priv->url == activeURL.utf8().data()) return; - priv->uri = activeURL.utf8().data(); - const char* callbackArgument = static_cast<const char*>(priv->uri); - evas_object_smart_callback_call(ewkView, "uri,changed", const_cast<char*>(callbackArgument)); + priv->url = activeURL.utf8().data(); + const char* callbackArgument = static_cast<const char*>(priv->url); + evas_object_smart_callback_call(ewkView, "url,changed", const_cast<char*>(callbackArgument)); } -Eina_Bool ewk_view_uri_set(Evas_Object* ewkView, const char* uri) +Eina_Bool ewk_view_url_set(Evas_Object* ewkView, const char* url) { EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false); EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false); - EINA_SAFETY_ON_NULL_RETURN_VAL(uri, false); + EINA_SAFETY_ON_NULL_RETURN_VAL(url, false); - priv->pageProxy->loadURL(uri); - ewk_view_uri_update(ewkView); + priv->pageProxy->loadURL(url); + ewk_view_url_update(ewkView); return true; } -const char* ewk_view_uri_get(const Evas_Object* ewkView) +const char* ewk_view_url_get(const Evas_Object* ewkView) { EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0); EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0); - return priv->uri; + return priv->url; } Eina_Bool ewk_view_reload(Evas_Object* ewkView) @@ -859,7 +959,7 @@ Eina_Bool ewk_view_reload(Evas_Object* ewkView) EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false); priv->pageProxy->reload(/*reloadFromOrigin*/ false); - ewk_view_uri_update(ewkView); + ewk_view_url_update(ewkView); return true; } @@ -870,7 +970,7 @@ Eina_Bool ewk_view_reload_bypass_cache(Evas_Object* ewkView) EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false); priv->pageProxy->reload(/*reloadFromOrigin*/ true); - ewk_view_uri_update(ewkView); + ewk_view_url_update(ewkView); return true; } @@ -899,15 +999,15 @@ Ewk_Settings* ewk_view_settings_get(const Evas_Object* ewkView) * * Emits signal: "resource,request,new" with pointer to resource request. */ -void ewk_view_resource_load_initiated(Evas_Object* ewkView, uint64_t resourceIdentifier, Ewk_Web_Resource* resource, Ewk_Url_Request* request) +void ewk_view_resource_load_initiated(Evas_Object* ewkView, uint64_t resourceIdentifier, Ewk_Resource* resource, Ewk_Url_Request* request) { EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData); EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv); - Ewk_Web_Resource_Request resourceRequest = {resource, request, 0}; + Ewk_Resource_Request resourceRequest = {resource, request, 0}; // Keep the resource internally to reuse it later. - priv->loadingResourcesMap.add(resourceIdentifier, ewk_web_resource_ref(resource)); + priv->loadingResourcesMap.add(resourceIdentifier, ewk_resource_ref(resource)); evas_object_smart_callback_call(ewkView, "resource,request,new", &resourceRequest); } @@ -926,8 +1026,8 @@ void ewk_view_resource_load_response(Evas_Object* ewkView, uint64_t resourceIden if (!priv->loadingResourcesMap.contains(resourceIdentifier)) return; - Ewk_Web_Resource* resource = priv->loadingResourcesMap.get(resourceIdentifier); - Ewk_Web_Resource_Load_Response resourceLoadResponse = {resource, response}; + Ewk_Resource* resource = priv->loadingResourcesMap.get(resourceIdentifier); + Ewk_Resource_Load_Response resourceLoadResponse = {resource, response}; evas_object_smart_callback_call(ewkView, "resource,request,response", &resourceLoadResponse); } @@ -937,7 +1037,7 @@ void ewk_view_resource_load_response(Evas_Object* ewkView, uint64_t resourceIden * * Emits signal: "resource,request,finished" with pointer to the resource load error. */ -void ewk_view_resource_load_failed(Evas_Object* ewkView, uint64_t resourceIdentifier, Ewk_Web_Error* error) +void ewk_view_resource_load_failed(Evas_Object* ewkView, uint64_t resourceIdentifier, Ewk_Error* error) { EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData); EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv); @@ -945,8 +1045,8 @@ void ewk_view_resource_load_failed(Evas_Object* ewkView, uint64_t resourceIdenti if (!priv->loadingResourcesMap.contains(resourceIdentifier)) return; - Ewk_Web_Resource* resource = priv->loadingResourcesMap.get(resourceIdentifier); - Ewk_Web_Resource_Load_Error resourceLoadError = {resource, error}; + Ewk_Resource* resource = priv->loadingResourcesMap.get(resourceIdentifier); + Ewk_Resource_Load_Error resourceLoadError = {resource, error}; evas_object_smart_callback_call(ewkView, "resource,request,failed", &resourceLoadError); } @@ -964,10 +1064,10 @@ void ewk_view_resource_load_finished(Evas_Object* ewkView, uint64_t resourceIden if (!priv->loadingResourcesMap.contains(resourceIdentifier)) return; - Ewk_Web_Resource* resource = priv->loadingResourcesMap.take(resourceIdentifier); + Ewk_Resource* resource = priv->loadingResourcesMap.take(resourceIdentifier); evas_object_smart_callback_call(ewkView, "resource,request,finished", resource); - ewk_web_resource_unref(resource); + ewk_resource_unref(resource); } /** @@ -984,8 +1084,8 @@ void ewk_view_resource_request_sent(Evas_Object* ewkView, uint64_t resourceIdent if (!priv->loadingResourcesMap.contains(resourceIdentifier)) return; - Ewk_Web_Resource* resource = priv->loadingResourcesMap.get(resourceIdentifier); - Ewk_Web_Resource_Request resourceRequest = {resource, request, redirectResponse}; + Ewk_Resource* resource = priv->loadingResourcesMap.get(resourceIdentifier); + Ewk_Resource_Request resourceRequest = {resource, request, redirectResponse}; evas_object_smart_callback_call(ewkView, "resource,request,sent", &resourceRequest); } @@ -1207,6 +1307,22 @@ void ewk_view_full_screen_exit(Evas_Object* ewkView) } #endif +#if ENABLE(SQL_DATABASE) +/** + * @internal + * Calls exceeded_database_quota callback or falls back to default behavior returns default database quota. + */ +unsigned long long ewk_view_database_quota_exceeded(Evas_Object* ewkView, const char* databaseName, const char* displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage) +{ + EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0); + + static const unsigned long long defaultQuota = 5 * 1024 * 1204; // 5 MB + if (smartData->api->exceeded_database_quota) + return smartData->api->exceeded_database_quota(smartData, databaseName, displayName, currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage); + + return defaultQuota; +} +#endif /** * @internal @@ -1236,7 +1352,7 @@ void ewk_view_download_job_requested(Evas_Object* ewkView, Ewk_Download_Job* dow * * Emits signal: "download,failed" with pointer to a Ewk_Download_Job_Error. */ -void ewk_view_download_job_failed(Evas_Object* ewkView, Ewk_Download_Job* download, Ewk_Web_Error* error) +void ewk_view_download_job_failed(Evas_Object* ewkView, Ewk_Download_Job* download, Ewk_Error* error) { Ewk_Download_Job_Error downloadError = { download, error }; evas_object_smart_callback_call(ewkView, "download,failed", &downloadError); @@ -1347,11 +1463,11 @@ void ewk_view_form_submission_request_new(Evas_Object* ewkView, Ewk_Form_Submiss * @internal * Reports load failed with error information. * - * Emits signal: "load,error" with pointer to Ewk_Web_Error. + * Emits signal: "load,error" with pointer to Ewk_Error. */ -void ewk_view_load_error(Evas_Object* ewkView, const Ewk_Web_Error* error) +void ewk_view_load_error(Evas_Object* ewkView, const Ewk_Error* error) { - evas_object_smart_callback_call(ewkView, "load,error", const_cast<Ewk_Web_Error*>(error)); + evas_object_smart_callback_call(ewkView, "load,error", const_cast<Ewk_Error*>(error)); } /** @@ -1362,7 +1478,7 @@ void ewk_view_load_error(Evas_Object* ewkView, const Ewk_Web_Error* error) */ void ewk_view_load_finished(Evas_Object* ewkView) { - ewk_view_uri_update(ewkView); + ewk_view_url_update(ewkView); evas_object_smart_callback_call(ewkView, "load,finished", 0); } @@ -1370,11 +1486,11 @@ void ewk_view_load_finished(Evas_Object* ewkView) * @internal * Reports view provisional load failed with error information. * - * Emits signal: "load,provisional,failed" with pointer to Ewk_Web_Error. + * Emits signal: "load,provisional,failed" with pointer to Ewk_Error. */ -void ewk_view_load_provisional_failed(Evas_Object* ewkView, const Ewk_Web_Error* error) +void ewk_view_load_provisional_failed(Evas_Object* ewkView, const Ewk_Error* error) { - evas_object_smart_callback_call(ewkView, "load,provisional,failed", const_cast<Ewk_Web_Error*>(error)); + evas_object_smart_callback_call(ewkView, "load,provisional,failed", const_cast<Ewk_Error*>(error)); } /** @@ -1385,7 +1501,7 @@ void ewk_view_load_provisional_failed(Evas_Object* ewkView, const Ewk_Web_Error* */ void ewk_view_load_provisional_redirect(Evas_Object* ewkView) { - ewk_view_uri_update(ewkView); + ewk_view_url_update(ewkView); evas_object_smart_callback_call(ewkView, "load,provisional,redirect", 0); } @@ -1404,12 +1520,23 @@ void ewk_view_load_provisional_started(Evas_Object* ewkView) // the loadingResources HashMap to start clean. _ewk_view_priv_loading_resources_clear(priv->loadingResourcesMap); - ewk_view_uri_update(ewkView); + ewk_view_url_update(ewkView); evas_object_smart_callback_call(ewkView, "load,provisional,started", 0); } /** * @internal + * Reports that the view's back / forward list has changed. + * + * Emits signal: "back,forward,list,changed". + */ +void ewk_view_back_forward_list_changed(Evas_Object* ewkView) +{ + evas_object_smart_callback_call(ewkView, "back,forward,list,changed", 0); +} + +/** + * @internal * Reports that a navigation policy decision should be taken. * * Emits signal: "policy,decision,navigation". @@ -1440,7 +1567,7 @@ Eina_Bool ewk_view_html_string_load(Evas_Object* ewkView, const char* html, cons priv->pageProxy->loadAlternateHTMLString(String::fromUTF8(html), baseUrl ? String::fromUTF8(baseUrl) : "", String::fromUTF8(unreachableUrl)); else priv->pageProxy->loadHTMLString(String::fromUTF8(html), baseUrl ? String::fromUTF8(baseUrl) : ""); - ewk_view_uri_update(ewkView); + ewk_view_url_update(ewkView); return true; } @@ -1458,6 +1585,13 @@ void ewk_view_intent_service_register(Evas_Object* ewkView, const Ewk_Intent_Ser } #endif // ENABLE(WEB_INTENTS_TAG) +const Evas_Object* ewk_view_from_page_get(const WebKit::WebPageProxy* page) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(page, 0); + + return pageViewMap().get(page); +} + WebPageProxy* ewk_view_page_get(const Evas_Object* ewkView) { EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0); @@ -1517,14 +1651,13 @@ COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_SHOW_OVERLAY, kWKFindOptionsShowOv COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_SHOW_FIND_INDICATOR, kWKFindOptionsShowFindIndicator); COMPILE_ASSERT_MATCHING_ENUM(EWK_FIND_OPTIONS_SHOW_HIGHLIGHT, kWKFindOptionsShowHighlight); -Eina_Bool ewk_view_text_find(Evas_Object* ewkView, const char* text, Ewk_Find_Options options, unsigned int maxMatchCount) +Eina_Bool ewk_view_text_find(Evas_Object* ewkView, const char* text, Ewk_Find_Options options, unsigned maxMatchCount) { EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false); EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false); EINA_SAFETY_ON_NULL_RETURN_VAL(text, false); - WKRetainPtr<WKStringRef> findText(AdoptWK, WKStringCreateWithUTF8CString(text)); - WKPageFindString(toAPI(priv->pageProxy.get()), findText.get(), static_cast<WKFindOptions>(options), maxMatchCount); + priv->pageProxy->findString(String::fromUTF8(text), static_cast<WebKit::FindOptions>(options), maxMatchCount); return true; } @@ -1534,7 +1667,18 @@ Eina_Bool ewk_view_text_find_highlight_clear(Evas_Object* ewkView) EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false); EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false); - WKPageHideFindUI(toAPI(priv->pageProxy.get())); + priv->pageProxy->hideFindUI(); + + return true; +} + +Eina_Bool ewk_view_text_matches_count(Evas_Object* ewkView, const char* text, Ewk_Find_Options options, unsigned maxMatchCount) +{ + EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false); + EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false); + EINA_SAFETY_ON_NULL_RETURN_VAL(text, false); + + priv->pageProxy->countStringMatches(String::fromUTF8(text), static_cast<WebKit::FindOptions>(options), maxMatchCount); return true; } @@ -1778,3 +1922,85 @@ Eina_Bool ewk_view_feed_touch_event(Evas_Object* ewkView, Ewk_Touch_Event_Type t return false; #endif } + +Eina_Bool ewk_view_touch_events_enabled_set(Evas_Object* ewkView, Eina_Bool enabled) +{ +#if ENABLE(TOUCH_EVENTS) + EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false); + EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false); + + enabled = !!enabled; + if (priv->areTouchEventsEnabled == enabled) + return true; + + priv->areTouchEventsEnabled = enabled; + if (enabled) { + // FIXME: We have to connect touch callbacks with mouse and multi events + // because the Evas creates mouse events for first touch and multi events + // for second and third touches. Below codes should be fixed when the Evas + // supports the touch events. + // See https://bugs.webkit.org/show_bug.cgi?id=97785 for details. + evas_object_event_callback_add(ewkView, EVAS_CALLBACK_MOUSE_DOWN, _ewk_view_on_touch_down, smartData); + evas_object_event_callback_add(ewkView, EVAS_CALLBACK_MOUSE_UP, _ewk_view_on_touch_up, smartData); + evas_object_event_callback_add(ewkView, EVAS_CALLBACK_MOUSE_MOVE, _ewk_view_on_touch_move, smartData); + evas_object_event_callback_add(ewkView, EVAS_CALLBACK_MULTI_DOWN, _ewk_view_on_touch_down, smartData); + evas_object_event_callback_add(ewkView, EVAS_CALLBACK_MULTI_UP, _ewk_view_on_touch_up, smartData); + evas_object_event_callback_add(ewkView, EVAS_CALLBACK_MULTI_MOVE, _ewk_view_on_touch_move, smartData); + } else { + evas_object_event_callback_del(ewkView, EVAS_CALLBACK_MOUSE_DOWN, _ewk_view_on_touch_down); + evas_object_event_callback_del(ewkView, EVAS_CALLBACK_MOUSE_UP, _ewk_view_on_touch_up); + evas_object_event_callback_del(ewkView, EVAS_CALLBACK_MOUSE_MOVE, _ewk_view_on_touch_move); + evas_object_event_callback_del(ewkView, EVAS_CALLBACK_MULTI_DOWN, _ewk_view_on_touch_down); + evas_object_event_callback_del(ewkView, EVAS_CALLBACK_MULTI_UP, _ewk_view_on_touch_up); + evas_object_event_callback_del(ewkView, EVAS_CALLBACK_MULTI_MOVE, _ewk_view_on_touch_move); + } + + return true; +#else + return false; +#endif +} + +Eina_Bool ewk_view_touch_events_enabled_get(const Evas_Object* ewkView) +{ +#if ENABLE(TOUCH_EVENTS) + EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false); + EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false); + + return priv->areTouchEventsEnabled; +#else + return false; +#endif +} + +Eina_Bool ewk_view_inspector_show(Evas_Object* ewkView) +{ +#if ENABLE(INSPECTOR) + EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false); + EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false); + + WebInspectorProxy* inspector = priv->pageProxy->inspector(); + if (inspector) + inspector->show(); + + return true; +#else + return false; +#endif +} + +Eina_Bool ewk_view_inspector_close(Evas_Object* ewkView) +{ +#if ENABLE(INSPECTOR) + EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false); + EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false); + + WebInspectorProxy* inspector = priv->pageProxy->inspector(); + if (inspector) + inspector->close(); + + return true; +#else + return false; +#endif +} diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view.h b/Source/WebKit2/UIProcess/API/efl/ewk_view.h index 13f138c87..e9cbe4e1f 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view.h @@ -26,6 +26,7 @@ * * The following signals (see evas_object_smart_callback_add()) are emitted: * + * - "back,forward,list,changed", void: reports that the view's back / forward list had changed. * - "close,window", void: window is closed. * - "create,window", Evas_Object**: a new window is created. * - "download,cancelled", Ewk_Download_Job*: reports that a download was effectively cancelled. @@ -44,10 +45,10 @@ * ewk_form_submission_request_submit() will be called automatically. * - "intent,request,new", Ewk_Intent*: reports new Web intent request. * - "intent,service,register", Ewk_Intent_Service*: reports new Web intent service registration. - * - "load,error", const Ewk_Web_Error*: reports main frame load failed. + * - "load,error", const Ewk_Error*: reports main frame load failed. * - "load,finished", void: reports load finished. * - "load,progress", double*: load progress has changed (value from 0.0 to 1.0). - * - "load,provisional,failed", const Ewk_Web_Error*: view provisional load failed. + * - "load,provisional,failed", const Ewk_Error*: view provisional load failed. * - "load,provisional,redirect", void: view received redirect for provisional load. * - "load,provisional,started", void: view started provisional load. * - "policy,decision,navigation", Ewk_Navigation_Policy_Decision*: a navigation policy decision should be taken. @@ -56,14 +57,14 @@ * - "policy,decision,new,window", Ewk_Navigation_Policy_Decision*: a new window policy decision should be taken. * To make a policy decision asynchronously, simply increment the reference count of the * #Ewk_Navigation_Policy_Decision object using ewk_navigation_policy_decision_ref(). - * - "resource,request,failed", const Ewk_Web_Resource_Load_Error*: a resource failed loading. - * - "resource,request,finished", const Ewk_Web_Resource*: a resource finished loading. - * - "resource,request,new", const Ewk_Web_Resource_Request*: a resource request was initiated. - * - "resource,request,response", Ewk_Web_Resource_Load_Response*: a response to a resource request was received. - * - "resource,request,sent", const Ewk_Web_Resource_Request*: a resource request was sent. + * - "resource,request,failed", const Ewk_Resource_Load_Error*: a resource failed loading. + * - "resource,request,finished", const Ewk_Resource*: a resource finished loading. + * - "resource,request,new", const Ewk_Resource_Request*: a resource request was initiated. + * - "resource,request,response", Ewk_Resource_Load_Response*: a response to a resource request was received. + * - "resource,request,sent", const Ewk_Resource_Request*: a resource request was sent. * - "text,found", unsigned int*: the requested text was found and it gives the number of matches. * - "title,changed", const char*: title of the main frame was changed. - * - "uri,changed", const char*: uri of the main frame was changed. + * - "url,changed", const char*: url of the main frame was changed. * - "webprocess,crashed", Eina_Bool*: expects a @c EINA_TRUE if web process crash is handled; @c EINA_FALSE, otherwise. */ @@ -73,13 +74,13 @@ #include "ewk_back_forward_list.h" #include "ewk_context.h" #include "ewk_download_job.h" +#include "ewk_error.h" #include "ewk_intent.h" +#include "ewk_resource.h" #include "ewk_settings.h" #include "ewk_touch.h" #include "ewk_url_request.h" #include "ewk_url_response.h" -#include "ewk_web_error.h" -#include "ewk_web_resource.h" #include <Evas.h> #ifdef __cplusplus @@ -127,13 +128,17 @@ struct _Ewk_View_Smart_Class { // - Shows and hides color picker. Eina_Bool (*input_picker_color_request)(Ewk_View_Smart_Data *sd, int r, int g, int b, int a); Eina_Bool (*input_picker_color_dismiss)(Ewk_View_Smart_Data *sd); + + // storage: + // - Web database. + unsigned long long (*exceeded_database_quota)(Ewk_View_Smart_Data *sd, const char *databaseName, const char *displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage); }; /** * The version you have to put into the version field * in the @a Ewk_View_Smart_Class structure. */ -#define EWK_VIEW_SMART_CLASS_VERSION 5UL +#define EWK_VIEW_SMART_CLASS_VERSION 6UL /** * Initializer for whole Ewk_View_Smart_Class structure. @@ -145,7 +150,7 @@ struct _Ewk_View_Smart_Class { * @see EWK_VIEW_SMART_CLASS_INIT_VERSION * @see EWK_VIEW_SMART_CLASS_INIT_NAME_VERSION */ -#define EWK_VIEW_SMART_CLASS_INIT(smart_class_init) {smart_class_init, EWK_VIEW_SMART_CLASS_VERSION, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define EWK_VIEW_SMART_CLASS_INIT(smart_class_init) {smart_class_init, EWK_VIEW_SMART_CLASS_VERSION, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} /** * Initializer to zero a whole Ewk_View_Smart_Class structure. @@ -197,40 +202,40 @@ struct _Ewk_View_Smart_Data { } changed; }; -/// Creates a type name for _Ewk_Web_Resource_Request. -typedef struct _Ewk_Web_Resource_Request Ewk_Web_Resource_Request; +/// Creates a type name for _Ewk_Resource_Request. +typedef struct _Ewk_Resource_Request Ewk_Resource_Request; /** * @brief Structure containing details about a resource request. */ -struct _Ewk_Web_Resource_Request { - Ewk_Web_Resource *resource; /**< resource being requested */ +struct _Ewk_Resource_Request { + Ewk_Resource *resource; /**< resource being requested */ Ewk_Url_Request *request; /**< URL request for the resource */ Ewk_Url_Response *redirect_response; /**< Possible redirect response for the resource or @c NULL */ }; -/// Creates a type name for _Ewk_Web_Resource_Load_Response. -typedef struct _Ewk_Web_Resource_Load_Response Ewk_Web_Resource_Load_Response; +/// Creates a type name for _Ewk_Resource_Load_Response. +typedef struct _Ewk_Resource_Load_Response Ewk_Resource_Load_Response; /** * @brief Structure containing details about a response to a resource request. */ -struct _Ewk_Web_Resource_Load_Response { - Ewk_Web_Resource *resource; /**< resource requested */ - Ewk_Url_Response *response; /**< resource load response */ +struct _Ewk_Resource_Load_Response { + Ewk_Resource *resource; /**< resource requested */ + Ewk_Url_Response *response; /**< resource load response */ }; -/// Creates a type name for _Ewk_Web_Resource_Load_Error. -typedef struct _Ewk_Web_Resource_Load_Error Ewk_Web_Resource_Load_Error; +/// Creates a type name for _Ewk_Resource_Load_Error. +typedef struct _Ewk_Resource_Load_Error Ewk_Resource_Load_Error; /** * @brief Structure containing details about a resource load error. * * Details given about a resource load failure. */ -struct _Ewk_Web_Resource_Load_Error { - Ewk_Web_Resource *resource; /**< resource that failed loading */ - Ewk_Web_Error *error; /**< load error */ +struct _Ewk_Resource_Load_Error { + Ewk_Resource *resource; /**< resource that failed loading */ + Ewk_Error *error; /**< load error */ }; /// Creates a type name for _Ewk_Download_Job_Error. @@ -241,7 +246,7 @@ typedef struct _Ewk_Download_Job_Error Ewk_Download_Job_Error; */ struct _Ewk_Download_Job_Error { Ewk_Download_Job *download_job; /**< download that failed */ - Ewk_Web_Error *error; /**< download error */ + Ewk_Error *error; /**< download error */ }; /** @@ -329,27 +334,27 @@ EAPI Evas_Object *ewk_view_add_with_context(Evas *e, Ewk_Context *context); EAPI Ewk_Context *ewk_view_context_get(const Evas_Object *o); /** - * Asks the object to load the given URI. + * Asks the object to load the given URL. * - * @param o view object to load @a URI - * @param uri uniform resource identifier to load + * @param o view object to load @a URL + * @param url uniform resource identifier to load * * @return @c EINA_TRUE is returned if @a o is valid, irrespective of load, * or @c EINA_FALSE on failure */ -EAPI Eina_Bool ewk_view_uri_set(Evas_Object *o, const char *uri); +EAPI Eina_Bool ewk_view_url_set(Evas_Object *o, const char *url); /** - * Returns the current URI string of view object. + * Returns the current URL string of view object. * * It returns an internal string and should not * be modified. The string is guaranteed to be stringshared. * - * @param o view object to get current URI + * @param o view object to get current URL * - * @return current URI on success or @c NULL on failure + * @return current URL on success or @c NULL on failure */ -EAPI const char *ewk_view_uri_get(const Evas_Object *o); +EAPI const char *ewk_view_url_get(const Evas_Object *o); /** * Asks the main frame to reload the current document. @@ -613,27 +618,50 @@ EAPI const char *ewk_view_setting_encoding_custom_get(const Evas_Object *o); EAPI Eina_Bool ewk_view_setting_encoding_custom_set(Evas_Object *o, const char *encoding); /** -* Searches the given string in the document. -* -* @param o view object to find text -* @param text text to find -* @param options options to find -* @param max count to find, unlimited if 0 -* -* @return @c EINA_TRUE on success, @c EINA_FALSE on errors -*/ -EAPI Eina_Bool ewk_view_text_find(Evas_Object *o, const char *text, Ewk_Find_Options options, unsigned int max_match_count); + * Searches and hightlights the given string in the document. + * + * @param o view object to find text + * @param text text to find + * @param options options to find + * @param max_match_count maximum match count to find, unlimited if 0 + * + * @return @c EINA_TRUE on success, @c EINA_FALSE on errors + */ +EAPI Eina_Bool ewk_view_text_find(Evas_Object *o, const char *text, Ewk_Find_Options options, unsigned max_match_count); /** -* Clears the highlight of searched text. -* -* @param o view object to find text -* -* @return @c EINA_TRUE on success, @c EINA_FALSE on errors -*/ + * Clears the highlight of searched text. + * + * @param o view object to find text + * + * @return @c EINA_TRUE on success, @c EINA_FALSE on errors + */ EAPI Eina_Bool ewk_view_text_find_highlight_clear(Evas_Object *o); /** + * Counts the given string in the document. + * + * This does not highlight the matched string and just count the matched string. + * + * As the search is carried out through the whole document, + * only the following EWK_FIND_OPTIONS are valid. + * - EWK_FIND_OPTIONS_NONE + * - EWK_FIND_OPTIONS_CASE_INSENSITIVE + * - EWK_FIND_OPTIONS_AT_WORD_START + * - EWK_FIND_OPTIONS_TREAT_MEDIAL_CAPITAL_AS_WORD_START + * + * The "text,found" callback will be called with the number of matched string. + * + * @param o view object to find text + * @param text text to find + * @param options options to find + * @param max_match_count maximum match count to find, unlimited if 0 + * + * @return @c EINA_TRUE on success, @c EINA_FALSE on errors + */ +EAPI Eina_Bool ewk_view_text_matches_count(Evas_Object *o, const char *text, Ewk_Find_Options options, unsigned max_match_count); + +/** * Selects index of current popup menu. * * @param o view object contains popup menu. @@ -708,6 +736,48 @@ EAPI Eina_Bool ewk_view_color_picker_color_set(Evas_Object *o, int r, int g, int */ EAPI Eina_Bool ewk_view_feed_touch_event(Evas_Object *o, Ewk_Touch_Event_Type type, const Eina_List *points, const Evas_Modifier *modifiers); +/** + * Sets whether the ewk_view supports the touch events or not. + * + * The ewk_view will support the touch events if @c EINA_TRUE or not support the + * touch events otherwise. The default value is @c EINA_FALSE. + * + * @param o view object to enable/disable the touch events + * @param enabled a state to set + * + * @return @c EINA_TRUE on success or @c EINA_FALSE on failure + */ +EAPI Eina_Bool ewk_view_touch_events_enabled_set(Evas_Object *o, Eina_Bool enabled); + +/** + * Queries if the ewk_view supports the touch events. + * + * @param o view object to query if the touch events are enabled + * + * @return @c EINA_TRUE if the touch events are enabled or @c EINA_FALSE otherwise + */ +EAPI Eina_Bool ewk_view_touch_events_enabled_get(const Evas_Object *o); + +/** + * Show the inspector to debug a web page. + * + * @param o The view to show the inspector. + * + * @return @c EINA_TRUE on success or @c EINA_FALSE on failure + * + * @see ewk_settings_developer_extras_enabled_set() + */ +EAPI Eina_Bool ewk_view_inspector_show(Evas_Object *o); + +/** + * Close the inspector + * + * @param o The view to close the inspector. + * + * @return @c EINA_TRUE on success or @c EINA_FALSE on failure + */ +EAPI Eina_Bool ewk_view_inspector_close(Evas_Object *o); + #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view_find_client.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_view_find_client.cpp index 637e7aec2..1edc3cbfd 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view_find_client.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view_find_client.cpp @@ -34,9 +34,19 @@ static inline Evas_Object* toEwkView(const void* clientInfo) return static_cast<Evas_Object*>(const_cast<void*>(clientInfo)); } -static void didFindString(WKPageRef, WKStringRef /*string*/, unsigned matchCount, const void* clientInfo) +static void didFindString(WKPageRef, WKStringRef, unsigned matchCount, const void* clientInfo) { - ewk_view_text_found(toEwkView(clientInfo), static_cast<unsigned int>(matchCount)); + ewk_view_text_found(toEwkView(clientInfo), matchCount); +} + +static void didFailToFindString(WKPageRef, WKStringRef, const void* clientInfo) +{ + ewk_view_text_found(toEwkView(clientInfo), 0); +} + +static void didCountStringMatches(WKPageRef, WKStringRef, unsigned matchCount, const void* clientInfo) +{ + ewk_view_text_found(toEwkView(clientInfo), matchCount); } void ewk_view_find_client_attach(WKPageRef pageRef, Evas_Object* ewkView) @@ -46,5 +56,7 @@ void ewk_view_find_client_attach(WKPageRef pageRef, Evas_Object* ewkView) findClient.version = kWKPageFindClientCurrentVersion; findClient.clientInfo = ewkView; findClient.didFindString = didFindString; + findClient.didFailToFindString = didFailToFindString; + findClient.didCountStringMatches = didCountStringMatches; WKPageSetPageFindClient(pageRef, &findClient); } diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view_loader_client.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_view_loader_client.cpp index 997ca35a8..a3afdb4ba 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view_loader_client.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view_loader_client.cpp @@ -28,14 +28,13 @@ #include "WKFrame.h" #include "ewk_back_forward_list_private.h" +#include "ewk_error_private.h" #include "ewk_intent.h" #include "ewk_intent_private.h" #include "ewk_intent_service.h" #include "ewk_intent_service_private.h" #include "ewk_view_loader_client_private.h" #include "ewk_view_private.h" -#include "ewk_web_error.h" -#include "ewk_web_error_private.h" #include <wtf/text/CString.h> using namespace WebKit; @@ -90,10 +89,10 @@ static void didFailLoadWithErrorForFrame(WKPageRef, WKFrameRef frame, WKErrorRef return; Evas_Object* ewkView = static_cast<Evas_Object*>(const_cast<void*>(clientInfo)); - Ewk_Web_Error* ewkError = ewk_web_error_new(error); + Ewk_Error* ewkError = ewk_error_new(error); ewk_view_load_error(ewkView, ewkError); ewk_view_load_finished(ewkView); - ewk_web_error_free(ewkError); + ewk_error_free(ewkError); } static void didStartProvisionalLoadForFrame(WKPageRef, WKFrameRef frame, WKTypeRef /*userData*/, const void* clientInfo) @@ -120,9 +119,9 @@ static void didFailProvisionalLoadWithErrorForFrame(WKPageRef, WKFrameRef frame, return; Evas_Object* ewkView = static_cast<Evas_Object*>(const_cast<void*>(clientInfo)); - Ewk_Web_Error* ewkError = ewk_web_error_new(error); + Ewk_Error* ewkError = ewk_error_new(error); ewk_view_load_provisional_failed(ewkView, ewkError); - ewk_web_error_free(ewkError); + ewk_error_free(ewkError); } static void didChangeBackForwardList(WKPageRef, WKBackForwardListItemRef addedItem, WKArrayRef removedItems, const void* clientInfo) @@ -131,6 +130,7 @@ static void didChangeBackForwardList(WKPageRef, WKBackForwardListItemRef addedIt ASSERT(ewkView); ewk_back_forward_list_changed(ewk_view_back_forward_list_get(ewkView), addedItem, removedItems); + ewk_view_back_forward_list_changed(ewkView); } static void didSameDocumentNavigationForFrame(WKPageRef, WKFrameRef frame, WKSameDocumentNavigationType, WKTypeRef, const void* clientInfo) @@ -139,7 +139,7 @@ static void didSameDocumentNavigationForFrame(WKPageRef, WKFrameRef frame, WKSam return; Evas_Object* ewkView = static_cast<Evas_Object*>(const_cast<void*>(clientInfo)); - ewk_view_uri_update(ewkView); + ewk_view_url_update(ewkView); } void ewk_view_loader_client_attach(WKPageRef pageRef, Evas_Object* ewkView) diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view_private.h b/Source/WebKit2/UIProcess/API/efl/ewk_view_private.h index 4cba22d36..8ec91c13c 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view_private.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view_private.h @@ -43,8 +43,8 @@ typedef struct _Ewk_Download_Job Ewk_Download_Job; typedef struct _Ewk_Form_Submission_Request Ewk_Form_Submission_Request; typedef struct _Ewk_Url_Request Ewk_Url_Request; typedef struct _Ewk_Url_Response Ewk_Url_Response; -typedef struct _Ewk_Web_Error Ewk_Web_Error; -typedef struct _Ewk_Web_Resource Ewk_Web_Resource; +typedef struct _Ewk_Error Ewk_Error; +typedef struct _Ewk_Resource Ewk_Resource; typedef struct _Ewk_Navigation_Policy_Decision Ewk_Navigation_Policy_Decision; #if ENABLE(WEB_INTENTS) typedef struct _Ewk_Intent Ewk_Intent; @@ -56,7 +56,7 @@ typedef struct _Ewk_Intent_Service Ewk_Intent_Service; void ewk_view_cursor_set(Evas_Object* ewkView, const WebCore::Cursor& cursor); void ewk_view_display(Evas_Object* ewkView, const WebCore::IntRect& rect); void ewk_view_download_job_cancelled(Evas_Object* ewkView, Ewk_Download_Job*); -void ewk_view_download_job_failed(Evas_Object* ewkView, Ewk_Download_Job*, Ewk_Web_Error*); +void ewk_view_download_job_failed(Evas_Object* ewkView, Ewk_Download_Job*, Ewk_Error*); void ewk_view_download_job_finished(Evas_Object* ewkView, Ewk_Download_Job*); void ewk_view_download_job_requested(Evas_Object* ewkView, Ewk_Download_Job*); void ewk_view_form_submission_request_new(Evas_Object* ewkView, Ewk_Form_Submission_Request*); @@ -65,10 +65,10 @@ void ewk_view_full_screen_enter(Evas_Object* ewkView); void ewk_view_full_screen_exit(Evas_Object* ewkView); #endif void ewk_view_image_data_set(Evas_Object* ewkView, void* imageData, const WebCore::IntSize& size); -void ewk_view_load_error(Evas_Object* ewkView, const Ewk_Web_Error* error); +void ewk_view_load_error(Evas_Object* ewkView, const Ewk_Error* error); void ewk_view_load_finished(Evas_Object* ewkView); void ewk_view_load_progress_changed(Evas_Object* ewkView, double progress); -void ewk_view_load_provisional_failed(Evas_Object* ewkView, const Ewk_Web_Error* error); +void ewk_view_load_provisional_failed(Evas_Object* ewkView, const Ewk_Error* error); void ewk_view_load_provisional_redirect(Evas_Object* ewkView); void ewk_view_load_provisional_started(Evas_Object* ewkView); void ewk_view_navigation_policy_decision(Evas_Object* ewkView, Ewk_Navigation_Policy_Decision* decision); @@ -76,14 +76,15 @@ void ewk_view_new_window_policy_decision(Evas_Object* ewkView, Ewk_Navigation_Po void ewk_view_page_close(Evas_Object* ewkView); WKPageRef ewk_view_page_create(Evas_Object* ewkView); void ewk_view_title_changed(Evas_Object* ewkView, const char* title); -void ewk_view_resource_load_failed(Evas_Object* ewkView, uint64_t resourceIdentifier, Ewk_Web_Error* error); +void ewk_view_resource_load_failed(Evas_Object* ewkView, uint64_t resourceIdentifier, Ewk_Error* error); void ewk_view_resource_load_finished(Evas_Object* ewkView, uint64_t resourceIdentifier); -void ewk_view_resource_load_initiated(Evas_Object* ewkView, uint64_t resourceIdentifier, Ewk_Web_Resource* resource, Ewk_Url_Request* request); +void ewk_view_resource_load_initiated(Evas_Object* ewkView, uint64_t resourceIdentifier, Ewk_Resource* resource, Ewk_Url_Request* request); void ewk_view_resource_load_response(Evas_Object* ewkView, uint64_t resourceIdentifier, Ewk_Url_Response* response); void ewk_view_resource_request_sent(Evas_Object* ewkView, uint64_t resourceIdentifier, Ewk_Url_Request* request, Ewk_Url_Response* redirectResponse); void ewk_view_text_found(Evas_Object* ewkView, unsigned int matchCount); -void ewk_view_uri_update(Evas_Object* ewkView); +void ewk_view_url_update(Evas_Object* ewkView); void ewk_view_contents_size_changed(const Evas_Object* ewkView, const WebCore::IntSize&); +void ewk_view_back_forward_list_changed(Evas_Object* ewkView); Evas_Object* ewk_view_base_add(Evas* canvas, WKContextRef, WKPageGroupRef); @@ -94,6 +95,7 @@ void ewk_view_intent_request_new(Evas_Object* ewkView, const Ewk_Intent* ewkInte void ewk_view_intent_service_register(Evas_Object* ewkView, const Ewk_Intent_Service* ewkIntentService); #endif +const Evas_Object* ewk_view_from_page_get(const WebKit::WebPageProxy*); WebKit::WebPageProxy* ewk_view_page_get(const Evas_Object* ewkView); WebCore::IntSize ewk_view_size_get(const Evas_Object* ewkView); @@ -114,4 +116,8 @@ void ewk_view_color_picker_request(Evas_Object* ewkView, int r, int g, int b, in void ewk_view_color_picker_dismiss(Evas_Object* ewkView); #endif +#if ENABLE(SQL_DATABASE) +unsigned long long ewk_view_database_quota_exceeded(Evas_Object* ewkView, const char* databaseName, const char* displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage); +#endif + #endif // ewk_view_private_h diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view_resource_load_client.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_view_resource_load_client.cpp index 113e178b9..469e18278 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view_resource_load_client.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view_resource_load_client.cpp @@ -32,16 +32,15 @@ #include "WKURL.h" #include "WKURLRequest.h" #include "WKURLResponse.h" +#include "ewk_error_private.h" +#include "ewk_resource.h" +#include "ewk_resource_private.h" #include "ewk_url_request.h" #include "ewk_url_request_private.h" #include "ewk_url_response.h" #include "ewk_url_response_private.h" #include "ewk_view_private.h" #include "ewk_view_resource_load_client_private.h" -#include "ewk_web_error.h" -#include "ewk_web_error_private.h" -#include "ewk_web_resource.h" -#include "ewk_web_resource_private.h" #include <wtf/text/CString.h> using namespace WebCore; @@ -57,19 +56,17 @@ static void didInitiateLoadForResource(WKPageRef, WKFrameRef wkFrame, uint64_t r bool isMainResource = (WKFrameIsMainFrame(wkFrame) && pageIsProvisionallyLoading); WKRetainPtr<WKURLRef> wkUrl(AdoptWK, WKURLRequestCopyURL(wkRequest)); - Ewk_Web_Resource* resource = ewk_web_resource_new(toImpl(wkUrl.get())->string().utf8().data(), isMainResource); - Ewk_Url_Request* request = ewk_url_request_new(wkRequest); - ewk_view_resource_load_initiated(toEwkView(clientInfo), resourceIdentifier, resource, request); - ewk_web_resource_unref(resource); - ewk_url_request_unref(request); + Ewk_Resource* resource = ewk_resource_new(toImpl(wkUrl.get())->string().utf8().data(), isMainResource); + RefPtr<Ewk_Url_Request> request = adoptRef(ewk_url_request_new(wkRequest)); + ewk_view_resource_load_initiated(toEwkView(clientInfo), resourceIdentifier, resource, request.get()); + ewk_resource_unref(resource); } static void didSendRequestForResource(WKPageRef, WKFrameRef, uint64_t resourceIdentifier, WKURLRequestRef wkRequest, WKURLResponseRef wkRedirectResponse, const void* clientInfo) { - Ewk_Url_Request* request = ewk_url_request_new(wkRequest); + RefPtr<Ewk_Url_Request> request = adoptRef(ewk_url_request_new(wkRequest)); Ewk_Url_Response* redirectResponse = wkRedirectResponse ? ewk_url_response_new(toImpl(wkRedirectResponse)->resourceResponse()) : 0; - ewk_view_resource_request_sent(toEwkView(clientInfo), resourceIdentifier, request, redirectResponse); - ewk_url_request_unref(request); + ewk_view_resource_request_sent(toEwkView(clientInfo), resourceIdentifier, request.get(), redirectResponse); if (redirectResponse) ewk_url_response_unref(redirectResponse); } @@ -88,10 +85,10 @@ static void didFinishLoadForResource(WKPageRef, WKFrameRef, uint64_t resourceIde static void didFailLoadForResource(WKPageRef, WKFrameRef, uint64_t resourceIdentifier, WKErrorRef wkError, const void* clientInfo) { - Ewk_Web_Error* ewkError = ewk_web_error_new(wkError); + Ewk_Error* ewkError = ewk_error_new(wkError); ewk_view_resource_load_failed(toEwkView(clientInfo), resourceIdentifier, ewkError); ewk_view_resource_load_finished(toEwkView(clientInfo), resourceIdentifier); - ewk_web_error_free(ewkError); + ewk_error_free(ewkError); } void ewk_view_resource_load_client_attach(WKPageRef pageRef, Evas_Object* ewkView) diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view_ui_client.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_view_ui_client.cpp index 6bbf8956c..0f7bd9277 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view_ui_client.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view_ui_client.cpp @@ -28,6 +28,7 @@ #include "WKString.h" #include "ewk_view_private.h" #include "ewk_view_ui_client_private.h" +#include <Ecore_Evas.h> static inline Evas_Object* toEwkView(const void* clientInfo) { @@ -73,6 +74,45 @@ static void hideColorPicker(WKPageRef, const void* clientInfo) } #endif +#if ENABLE(SQL_DATABASE) +static unsigned long long exceededDatabaseQuota(WKPageRef, WKFrameRef, WKSecurityOriginRef, WKStringRef databaseName, WKStringRef displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentDatabaseUsage, unsigned long long expectedUsage, const void* clientInfo) +{ + return ewk_view_database_quota_exceeded(toEwkView(clientInfo), WKEinaSharedString(databaseName), WKEinaSharedString(displayName), currentQuota, currentOriginUsage, currentDatabaseUsage, expectedUsage); +} +#endif + +static void focus(WKPageRef, const void* clientInfo) +{ + evas_object_focus_set(toEwkView(clientInfo), true); +} + +static void unfocus(WKPageRef, const void* clientInfo) +{ + evas_object_focus_set(toEwkView(clientInfo), false); +} + +static void takeFocus(WKPageRef, WKFocusDirection, const void* clientInfo) +{ + // FIXME: this is only a partial implementation. + evas_object_focus_set(toEwkView(clientInfo), false); +} + +static WKRect getWindowFrame(WKPageRef, const void* clientInfo) +{ + int x, y, width, height; + + Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(toEwkView(clientInfo))); + ecore_evas_request_geometry_get(ee, &x, &y, &width, &height); + + return WKRectMake(x, y, width, height); +} + +static void setWindowFrame(WKPageRef, WKRect frame, const void* clientInfo) +{ + Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(toEwkView(clientInfo))); + ecore_evas_move_resize(ee, frame.origin.x, frame.origin.y, frame.size.width, frame.size.height); +} + void ewk_view_ui_client_attach(WKPageRef pageRef, Evas_Object* ewkView) { WKPageUIClient uiClient; @@ -84,6 +124,14 @@ void ewk_view_ui_client_attach(WKPageRef pageRef, Evas_Object* ewkView) uiClient.runJavaScriptAlert = runJavaScriptAlert; uiClient.runJavaScriptConfirm = runJavaScriptConfirm; uiClient.runJavaScriptPrompt = runJavaScriptPrompt; + uiClient.takeFocus = takeFocus; + uiClient.focus = focus; + uiClient.unfocus = unfocus; + uiClient.getWindowFrame = getWindowFrame; + uiClient.setWindowFrame = setWindowFrame; +#if ENABLE(SQL_DATABASE) + uiClient.exceededDatabaseQuota = exceededDatabaseQuota; +#endif #if ENABLE(INPUT_TYPE_COLOR) uiClient.showColorPicker = showColorPicker; diff --git a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp index 1691f0d7c..e02f011ca 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp +++ b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp @@ -50,10 +50,7 @@ void EWK2UnitTestBase::SetUp() unsigned int width = environment->defaultWidth(); unsigned int height = environment->defaultHeight(); - if (environment->useX11Window()) - m_ecoreEvas = ecore_evas_new(0, 0, 0, width, height, 0); - else - m_ecoreEvas = ecore_evas_buffer_new(width, height); + m_ecoreEvas = ecore_evas_new(0, 0, 0, width, height, 0); ecore_evas_show(m_ecoreEvas); Evas* evas = ecore_evas_get(m_ecoreEvas); @@ -74,17 +71,17 @@ void EWK2UnitTestBase::TearDown() ewk_shutdown(); } -void EWK2UnitTestBase::loadUrlSync(const char* url) +bool EWK2UnitTestBase::loadUrlSync(const char* url, double timeoutSeconds) { - ewk_view_uri_set(m_webView, url); - waitUntilLoadFinished(); + ewk_view_url_set(m_webView, url); + return waitUntilLoadFinished(timeoutSeconds); } class CallbackDataTimer { public: - CallbackDataTimer(double timeoutSeconds, Ecore_Task_Cb callback) + explicit CallbackDataTimer(double timeoutSeconds) : m_done(false) - , m_timer(timeoutSeconds >= 0 ? ecore_timer_add(timeoutSeconds, callback, this) : 0) + , m_timer(timeoutSeconds >= 0 ? ecore_timer_add(timeoutSeconds, reinterpret_cast<Ecore_Task_Cb>(timeOutCallback), this) : 0) , m_didTimeOut(false) { } @@ -108,6 +105,19 @@ public: bool didTimeOut() const { return m_didTimeOut; } +protected: + bool m_done; + Ecore_Timer* m_timer; + bool m_didTimeOut; + +private: + static bool timeOutCallback(void* userData) + { + CallbackDataTimer* data = static_cast<CallbackDataTimer*>(userData); + data->setTimedOut(); + return ECORE_CALLBACK_CANCEL; + } + void setTimedOut() { m_done = true; @@ -115,17 +125,13 @@ public: m_didTimeOut = true; } -protected: - bool m_done; - Ecore_Timer* m_timer; - bool m_didTimeOut; }; template <class T> class CallbackDataExpectedValue : public CallbackDataTimer { public: - CallbackDataExpectedValue(const T& expectedValue, double timeoutSeconds, Ecore_Task_Cb callback) - : CallbackDataTimer(timeoutSeconds, callback) + CallbackDataExpectedValue(const T& expectedValue, double timeoutSeconds) + : CallbackDataTimer(timeoutSeconds) , m_expectedValue(expectedValue) { } @@ -145,17 +151,9 @@ static void onLoadFinished(void* userData, Evas_Object* webView, void* eventInfo data->setDone(); } -static bool timeOutWhileWaitingUntilLoadFinished(void* userData) -{ - CallbackDataTimer* data = static_cast<CallbackDataTimer*>(userData); - data->setTimedOut(); - - return ECORE_CALLBACK_CANCEL; -} - bool EWK2UnitTestBase::waitUntilLoadFinished(double timeoutSeconds) { - CallbackDataTimer data(timeoutSeconds, reinterpret_cast<Ecore_Task_Cb>(timeOutWhileWaitingUntilLoadFinished)); + CallbackDataTimer data(timeoutSeconds); evas_object_smart_callback_add(m_webView, "load,finished", onLoadFinished, &data); @@ -177,17 +175,9 @@ static void onTitleChanged(void* userData, Evas_Object* webView, void*) data->setDone(); } -static bool timeOutWhileWaitingUntilTitleChangedTo(void* userData) -{ - CallbackDataExpectedValue<CString>* data = static_cast<CallbackDataExpectedValue<CString>*>(userData); - data->setTimedOut(); - - return ECORE_CALLBACK_CANCEL; -} - bool EWK2UnitTestBase::waitUntilTitleChangedTo(const char* expectedTitle, double timeoutSeconds) { - CallbackDataExpectedValue<CString> data(expectedTitle, timeoutSeconds, reinterpret_cast<Ecore_Task_Cb>(timeOutWhileWaitingUntilTitleChangedTo)); + CallbackDataExpectedValue<CString> data(expectedTitle, timeoutSeconds); evas_object_smart_callback_add(m_webView, "title,changed", onTitleChanged, &data); @@ -199,34 +189,26 @@ bool EWK2UnitTestBase::waitUntilTitleChangedTo(const char* expectedTitle, double return !data.didTimeOut(); } -static void onURIChanged(void* userData, Evas_Object* webView, void*) +static void onURLChanged(void* userData, Evas_Object* webView, void*) { CallbackDataExpectedValue<CString>* data = static_cast<CallbackDataExpectedValue<CString>*>(userData); - if (strcmp(ewk_view_uri_get(webView), data->expectedValue().data())) + if (strcmp(ewk_view_url_get(webView), data->expectedValue().data())) return; data->setDone(); } -static bool timeOutWhileWaitingUntilURIChangedTo(void* userData) -{ - CallbackDataExpectedValue<CString>* data = static_cast<CallbackDataExpectedValue<CString>*>(userData); - data->setTimedOut(); - - return ECORE_CALLBACK_CANCEL; -} - -bool EWK2UnitTestBase::waitUntilURIChangedTo(const char* expectedURI, double timeoutSeconds) +bool EWK2UnitTestBase::waitUntilURLChangedTo(const char* expectedURL, double timeoutSeconds) { - CallbackDataExpectedValue<CString> data(expectedURI, timeoutSeconds, reinterpret_cast<Ecore_Task_Cb>(timeOutWhileWaitingUntilURIChangedTo)); + CallbackDataExpectedValue<CString> data(expectedURL, timeoutSeconds); - evas_object_smart_callback_add(m_webView, "uri,changed", onURIChanged, &data); + evas_object_smart_callback_add(m_webView, "url,changed", onURLChanged, &data); while (!data.isDone()) ecore_main_loop_iterate(); - evas_object_smart_callback_del(m_webView, "uri,changed", onURIChanged); + evas_object_smart_callback_del(m_webView, "url,changed", onURLChanged); return !data.didTimeOut(); } @@ -239,4 +221,38 @@ void EWK2UnitTestBase::mouseClick(int x, int y) evas_event_feed_mouse_up(evas, /* Left */ 1, EVAS_BUTTON_NONE, 0, 0); } +void EWK2UnitTestBase::mouseDown(int x, int y) +{ + Evas* evas = evas_object_evas_get(m_webView); + evas_event_feed_mouse_move(evas, x, y, 0, 0); + evas_event_feed_mouse_down(evas, /* Left */ 1, EVAS_BUTTON_NONE, 0, 0); +} + +void EWK2UnitTestBase::mouseUp(int x, int y) +{ + Evas* evas = evas_object_evas_get(m_webView); + evas_event_feed_mouse_move(evas, x, y, 0, 0); + evas_event_feed_mouse_up(evas, /* Left */ 1, EVAS_BUTTON_NONE, 0, 0); +} + +void EWK2UnitTestBase::mouseMove(int x, int y) +{ + evas_event_feed_mouse_move(evas_object_evas_get(m_webView), x, y, 0, 0); +} + +void EWK2UnitTestBase::multiDown(int id, int x, int y) +{ + evas_event_feed_multi_down(evas_object_evas_get(m_webView), id, x, y, 0, 0, 0, 0, 0, 0, 0, EVAS_BUTTON_NONE, 0, 0); +} + +void EWK2UnitTestBase::multiUp(int id, int x, int y) +{ + evas_event_feed_multi_up(evas_object_evas_get(m_webView), id, x, y, 0, 0, 0, 0, 0, 0, 0, EVAS_BUTTON_NONE, 0, 0); +} + +void EWK2UnitTestBase::multiMove(int id, int x, int y) +{ + evas_event_feed_multi_move(evas_object_evas_get(m_webView), id, x, y, 0, 0, 0, 0, 0, 0, 0, 0, 0); +} + } // namespace EWK2UnitTest diff --git a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h index e1146b198..2ebb95093 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h +++ b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h @@ -40,14 +40,20 @@ protected: virtual void SetUp(); virtual void TearDown(); - void loadUrlSync(const char* url); - static const double defaultTimeoutSeconds = 10.0; + + bool loadUrlSync(const char* url, double timeoutSeconds = defaultTimeoutSeconds); bool waitUntilLoadFinished(double timeoutSeconds = defaultTimeoutSeconds); bool waitUntilTitleChangedTo(const char* expectedTitle, double timeoutSeconds = defaultTimeoutSeconds); - bool waitUntilURIChangedTo(const char* expectedURI, double timeoutSeconds = defaultTimeoutSeconds); + bool waitUntilURLChangedTo(const char* expectedURL, double timeoutSeconds = defaultTimeoutSeconds); void mouseClick(int x, int y); + void mouseDown(int x, int y); + void mouseUp(int x, int y); + void mouseMove(int x, int y); + void multiDown(int id, int x, int y); + void multiUp(int id, int x, int y); + void multiMove(int id, int x, int y); private: Evas_Object* m_webView; diff --git a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.cpp b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.cpp index 0b7977f54..f9e0f7b73 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.cpp +++ b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.cpp @@ -26,10 +26,9 @@ namespace EWK2UnitTest { -EWK2UnitTestEnvironment::EWK2UnitTestEnvironment(bool useX11Window) +EWK2UnitTestEnvironment::EWK2UnitTestEnvironment() : m_defaultWidth(800) , m_defaultHeight(600) - , m_useX11Window(useX11Window) { } diff --git a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.h b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.h index 4255b01b4..8b401b56a 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.h +++ b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.h @@ -27,9 +27,8 @@ namespace EWK2UnitTest { class EWK2UnitTestEnvironment : public ::testing::Environment { public: - EWK2UnitTestEnvironment(bool useX11Window); + EWK2UnitTestEnvironment(); - bool useX11Window() const { return m_useX11Window; } const char* defaultTestPageUrl() const; const char* defaultTheme() const; const char* injectedBundleSample() const; @@ -42,8 +41,6 @@ public: private: unsigned int m_defaultWidth; unsigned int m_defaultHeight; - - bool m_useX11Window; }; } // namespace EWK2UnitTest diff --git a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestMain.cpp b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestMain.cpp index 06e9c069a..778d261e8 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestMain.cpp +++ b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestMain.cpp @@ -26,27 +26,11 @@ using namespace EWK2UnitTest; EWK2UnitTestEnvironment* environment = 0; -static bool parseArguments(int argc, char** argv) -{ - int useX11Window = 0; - - static const option options[] = { - {"useX11Window", no_argument, &useX11Window, 1}, - {0, 0, 0, 0} - }; - - while (getopt_long(argc, argv, "", options, 0) != -1) { } - - return useX11Window; -} - int main(int argc, char** argv) { - bool useX11Window = parseArguments(argc, argv); - ::testing::InitGoogleTest(&argc, argv); - environment = new EWK2UnitTestEnvironment(useX11Window); + environment = new EWK2UnitTestEnvironment(); testing::AddGlobalTestEnvironment(environment); return RUN_ALL_TESTS(); diff --git a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestServer.cpp b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestServer.cpp index 52e6af46e..4ef4cf76f 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestServer.cpp +++ b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestServer.cpp @@ -27,14 +27,14 @@ EWK2UnitTestServer::EWK2UnitTestServer() soup_address_resolve_sync(address, 0); m_soupServer = soup_server_new(SOUP_SERVER_INTERFACE, address, static_cast<char*>(0)); - m_baseURI = soup_uri_new("http://127.0.0.1/"); - soup_uri_set_port(m_baseURI, soup_server_get_port(m_soupServer)); + m_baseURL = soup_uri_new("http://127.0.0.1/"); + soup_uri_set_port(m_baseURL, soup_server_get_port(m_soupServer)); g_object_unref(address); } EWK2UnitTestServer::~EWK2UnitTestServer() { - soup_uri_free(m_baseURI); + soup_uri_free(m_baseURL); g_object_unref(m_soupServer); } @@ -44,13 +44,13 @@ void EWK2UnitTestServer::run(SoupServerCallback serverCallback) soup_server_add_handler(m_soupServer, 0, serverCallback, 0, 0); } -CString EWK2UnitTestServer::getURIForPath(const char* path) const +CString EWK2UnitTestServer::getURLForPath(const char* path) const { - SoupURI* soupURI = soup_uri_new_with_base(m_baseURI, path); - char* uri = soup_uri_to_string(soupURI, false); - CString uriString = uri; - free(uri); - soup_uri_free(soupURI); + SoupURI* soupURL = soup_uri_new_with_base(m_baseURL, path); + char* url = soup_uri_to_string(soupURL, false); + CString urlString = url; + free(url); + soup_uri_free(soupURL); - return uriString; + return urlString; } diff --git a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestServer.h b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestServer.h index 3eb146f06..b967ce409 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestServer.h +++ b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestServer.h @@ -29,14 +29,12 @@ public: EWK2UnitTestServer(); virtual ~EWK2UnitTestServer(); - SoupURI* baseURI() const { return m_baseURI; } - - CString getURIForPath(const char* path) const; + CString getURLForPath(const char* path) const; void run(SoupServerCallback); private: SoupServer* m_soupServer; - SoupURI* m_baseURI; + SoupURI* m_baseURL; }; #endif // EWK2UnitTestServer_h diff --git a/Source/WebKit2/UIProcess/API/efl/tests/resources/frame_flattening_test.html b/Source/WebKit2/UIProcess/API/efl/tests/resources/frame_flattening_test.html new file mode 100644 index 000000000..6367992bb --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/tests/resources/frame_flattening_test.html @@ -0,0 +1,4 @@ +<!doctype html> +<body onload="document.title=document.getElementById('test').offsetWidth;"> +<iframe id="test" src="./frame_flattening_test_subframe.html" width="200" frameborder="0"></iframe> +</body> diff --git a/Source/WebKit2/UIProcess/API/efl/tests/resources/frame_flattening_test_subframe.html b/Source/WebKit2/UIProcess/API/efl/tests/resources/frame_flattening_test_subframe.html new file mode 100644 index 000000000..56ef7c9bd --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/tests/resources/frame_flattening_test_subframe.html @@ -0,0 +1,11 @@ +<!doctype html> +<head> +<style> +body { +width:600px; +margin:0px; +padding:0px; +} +</style> +</head> +<body></body> diff --git a/Source/WebKit2/UIProcess/API/efl/tests/resources/local_file_access.html b/Source/WebKit2/UIProcess/API/efl/tests/resources/local_file_access.html new file mode 100644 index 000000000..a71fbf976 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/tests/resources/local_file_access.html @@ -0,0 +1,31 @@ +<html> +<head> +<script> +function checkFrameLoaded() +{ + var myframe = document.getElementById('myframe'); + var testWindow = myframe.contentWindow; + var state = null; + try { + var state = testWindow.document.readyState; + if (state == "complete") { + document.title = "Frame loaded"; + return; + } + } catch(e) {} + document.title = "Frame NOT loaded"; +} + +function loadFrame() +{ + var myframe = document.getElementById('myframe'); + myframe.src = "default_test_page.html"; + + setTimeout("checkFrameLoaded()", 300); +} +</script> +</head> +<body onload="loadFrame()"> +<iframe id="myframe"></iframe> +</body> +</html> diff --git a/Source/WebKit2/UIProcess/API/efl/tests/resources/redirect_uri_to_default.html b/Source/WebKit2/UIProcess/API/efl/tests/resources/redirect_url_to_default.html index 846fd1113..846fd1113 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/resources/redirect_uri_to_default.html +++ b/Source/WebKit2/UIProcess/API/efl/tests/resources/redirect_url_to_default.html diff --git a/Source/WebKit2/UIProcess/API/efl/tests/resources/window_move_resize.html b/Source/WebKit2/UIProcess/API/efl/tests/resources/window_move_resize.html new file mode 100644 index 000000000..693ac2ef2 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/tests/resources/window_move_resize.html @@ -0,0 +1,15 @@ +<html> +<head> +<title>Window move and resize test</title> +<script> +function test() +{ + window.resizeTo(200, 100); + window.moveTo(150, 200); + document.title = "Moved and resized"; +} +</script> +</head> +<body onload="test()"> +</body> +</html> diff --git a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp index 9542b76f0..80d7755ec 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp +++ b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_back_forward_list.cpp @@ -61,19 +61,19 @@ static void serverCallbackNavigation(SoupServer* server, SoupMessage* message, c soup_message_body_complete(message->response_body); } -static inline void checkItem(Ewk_Back_Forward_List_Item* item, const char* title, const char* uri, const char* originalURI) +static inline void checkItem(Ewk_Back_Forward_List_Item* item, const char* title, const char* url, const char* originalURL) { ASSERT_TRUE(item); - EXPECT_STREQ(uri, ewk_back_forward_list_item_uri_get(item)); + EXPECT_STREQ(url, ewk_back_forward_list_item_url_get(item)); EXPECT_STREQ(title, ewk_back_forward_list_item_title_get(item)); - EXPECT_STREQ(originalURI, ewk_back_forward_list_item_original_uri_get(item)); + EXPECT_STREQ(originalURL, ewk_back_forward_list_item_original_url_get(item)); } static inline WKEinaSharedString urlFromTitle(EWK2UnitTestServer* httpServer, const char* title) { Eina_Strbuf* path = eina_strbuf_new(); eina_strbuf_append_printf(path, "/%s", title); - WKEinaSharedString res = httpServer->getURIForPath(eina_strbuf_string_get(path)).data(); + WKEinaSharedString res = httpServer->getURLForPath(eina_strbuf_string_get(path)).data(); eina_strbuf_free(path); return res; @@ -89,7 +89,7 @@ static inline void freeEinaList(Eina_List* list) TEST_F(EWK2UnitTestBase, ewk_back_forward_list_current_item_get) { const char* url = environment->defaultTestPageUrl(); - loadUrlSync(url); + ASSERT_TRUE(loadUrlSync(url)); Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView()); ASSERT_TRUE(backForwardList); @@ -106,11 +106,11 @@ TEST_F(EWK2UnitTestBase, ewk_back_forward_list_previous_item_get) httpServer->run(serverCallbackNavigation); WKEinaSharedString url1 = urlFromTitle(httpServer.get(), title1); - loadUrlSync(url1); - ASSERT_STREQ(ewk_view_title_get(webView()), title1); + ASSERT_TRUE(loadUrlSync(url1)); + ASSERT_STREQ(title1, ewk_view_title_get(webView())); - loadUrlSync(urlFromTitle(httpServer.get(), title2)); - ASSERT_STREQ(ewk_view_title_get(webView()), title2); + ASSERT_TRUE(loadUrlSync(urlFromTitle(httpServer.get(), title2))); + ASSERT_STREQ(title2, ewk_view_title_get(webView())); Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView()); ASSERT_TRUE(backForwardList); @@ -127,12 +127,12 @@ TEST_F(EWK2UnitTestBase, ewk_back_forward_list_next_item_get) OwnPtr<EWK2UnitTestServer> httpServer = adoptPtr(new EWK2UnitTestServer); httpServer->run(serverCallbackNavigation); - loadUrlSync(urlFromTitle(httpServer.get(), title1)); - ASSERT_STREQ(ewk_view_title_get(webView()), title1); + ASSERT_TRUE(loadUrlSync(urlFromTitle(httpServer.get(), title1))); + ASSERT_STREQ(title1, ewk_view_title_get(webView())); WKEinaSharedString url2 = urlFromTitle(httpServer.get(), title2); - loadUrlSync(url2); - ASSERT_STREQ(ewk_view_title_get(webView()), title2); + ASSERT_TRUE(loadUrlSync(url2)); + ASSERT_STREQ(title2, ewk_view_title_get(webView())); // Go back to Page1. ewk_view_back(webView()); @@ -154,11 +154,11 @@ TEST_F(EWK2UnitTestBase, ewk_back_forward_list_item_at_index_get) httpServer->run(serverCallbackNavigation); WKEinaSharedString url1 = urlFromTitle(httpServer.get(), title1); - loadUrlSync(url1); - ASSERT_STREQ(ewk_view_title_get(webView()), title1); + ASSERT_TRUE(loadUrlSync(url1)); + ASSERT_STREQ(title1, ewk_view_title_get(webView())); - loadUrlSync(urlFromTitle(httpServer.get(), title2)); - ASSERT_STREQ(ewk_view_title_get(webView()), title2); + ASSERT_TRUE(loadUrlSync(urlFromTitle(httpServer.get(), title2))); + ASSERT_STREQ(title2, ewk_view_title_get(webView())); Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView()); ASSERT_TRUE(backForwardList); @@ -178,16 +178,16 @@ TEST_F(EWK2UnitTestBase, ewk_back_forward_list_count) OwnPtr<EWK2UnitTestServer> httpServer = adoptPtr(new EWK2UnitTestServer); httpServer->run(serverCallbackNavigation); - loadUrlSync(urlFromTitle(httpServer.get(), title1)); - ASSERT_STREQ(ewk_view_title_get(webView()), title1); + ASSERT_TRUE(loadUrlSync(urlFromTitle(httpServer.get(), title1))); + ASSERT_STREQ(title1, ewk_view_title_get(webView())); - loadUrlSync(urlFromTitle(httpServer.get(), title2)); - ASSERT_STREQ(ewk_view_title_get(webView()), title2); + ASSERT_TRUE(loadUrlSync(urlFromTitle(httpServer.get(), title2))); + ASSERT_STREQ(title2, ewk_view_title_get(webView())); Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView()); ASSERT_TRUE(backForwardList); - EXPECT_EQ(ewk_back_forward_list_count(backForwardList), 2); + EXPECT_EQ(2, ewk_back_forward_list_count(backForwardList)); } TEST_F(EWK2UnitTestBase, ewk_back_forward_list_n_back_items_copy) @@ -196,22 +196,22 @@ TEST_F(EWK2UnitTestBase, ewk_back_forward_list_n_back_items_copy) httpServer->run(serverCallbackNavigation); WKEinaSharedString url1 = urlFromTitle(httpServer.get(), title1); - loadUrlSync(url1); - ASSERT_STREQ(ewk_view_title_get(webView()), title1); + ASSERT_TRUE(loadUrlSync(url1)); + ASSERT_STREQ(title1, ewk_view_title_get(webView())); WKEinaSharedString url2 = urlFromTitle(httpServer.get(), title2); - loadUrlSync(url2); - ASSERT_STREQ(ewk_view_title_get(webView()), title2); + ASSERT_TRUE(loadUrlSync(url2)); + ASSERT_STREQ(title2, ewk_view_title_get(webView())); - loadUrlSync(urlFromTitle(httpServer.get(), title3)); - ASSERT_STREQ(ewk_view_title_get(webView()), title3); + ASSERT_TRUE(loadUrlSync(urlFromTitle(httpServer.get(), title3))); + ASSERT_STREQ(title3, ewk_view_title_get(webView())); Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView()); ASSERT_TRUE(backForwardList); Eina_List* backList = ewk_back_forward_list_n_back_items_copy(backForwardList, 1); ASSERT_TRUE(backList); - ASSERT_EQ(eina_list_count(backList), 1); + ASSERT_EQ(1, eina_list_count(backList)); checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(backList, 0)), title2, url2, url2); freeEinaList(backList); @@ -221,7 +221,7 @@ TEST_F(EWK2UnitTestBase, ewk_back_forward_list_n_back_items_copy) backList = ewk_back_forward_list_n_back_items_copy(backForwardList, -1); ASSERT_TRUE(backList); - ASSERT_EQ(eina_list_count(backList), 2); + ASSERT_EQ(2, eina_list_count(backList)); checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(backList, 0)), title1, url1, url1); checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(backList, 1)), title2, url2, url2); freeEinaList(backList); @@ -232,16 +232,16 @@ TEST_F(EWK2UnitTestBase, ewk_back_forward_list_n_forward_items_copy) OwnPtr<EWK2UnitTestServer> httpServer = adoptPtr(new EWK2UnitTestServer); httpServer->run(serverCallbackNavigation); - loadUrlSync(urlFromTitle(httpServer.get(), title1)); - ASSERT_STREQ(ewk_view_title_get(webView()), title1); + ASSERT_TRUE(loadUrlSync(urlFromTitle(httpServer.get(), title1))); + ASSERT_STREQ(title1, ewk_view_title_get(webView())); WKEinaSharedString url2 = urlFromTitle(httpServer.get(), title2); - loadUrlSync(url2); - ASSERT_STREQ(ewk_view_title_get(webView()), title2); + ASSERT_TRUE(loadUrlSync(url2)); + ASSERT_STREQ(title2, ewk_view_title_get(webView())); WKEinaSharedString url3 = urlFromTitle(httpServer.get(), title3); - loadUrlSync(url3); - ASSERT_STREQ(ewk_view_title_get(webView()), title3); + ASSERT_TRUE(loadUrlSync(url3)); + ASSERT_STREQ(title3, ewk_view_title_get(webView())); // Go back to Page1. ewk_view_back(webView()); @@ -254,7 +254,7 @@ TEST_F(EWK2UnitTestBase, ewk_back_forward_list_n_forward_items_copy) Eina_List* forwardList = ewk_back_forward_list_n_forward_items_copy(backForwardList, 1); ASSERT_TRUE(forwardList); - ASSERT_EQ(eina_list_count(forwardList), 1); + ASSERT_EQ(1, eina_list_count(forwardList)); checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(forwardList, 0)), title2, url2, url2); freeEinaList(forwardList); @@ -264,7 +264,7 @@ TEST_F(EWK2UnitTestBase, ewk_back_forward_list_n_forward_items_copy) forwardList = ewk_back_forward_list_n_forward_items_copy(backForwardList, -1); ASSERT_TRUE(forwardList); - ASSERT_EQ(eina_list_count(forwardList), 2); + ASSERT_EQ(2, eina_list_count(forwardList)); checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(forwardList, 0)), title2, url2, url2); checkItem(static_cast<Ewk_Back_Forward_List_Item*>(eina_list_nth(forwardList, 1)), title3, url3, url3); freeEinaList(forwardList); diff --git a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_context.cpp b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_context.cpp index 82ded55da..dff485348 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_context.cpp +++ b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_context.cpp @@ -56,19 +56,19 @@ TEST_F(EWK2UnitTestBase, ewk_context_cookie_manager_get) static void schemeRequestCallback(Ewk_Url_Scheme_Request* request, void* userData) { const char* scheme = ewk_url_scheme_request_scheme_get(request); - ASSERT_STREQ(scheme, "fooscheme"); + ASSERT_STREQ("fooscheme", scheme); const char* url = ewk_url_scheme_request_url_get(request); - ASSERT_STREQ(url, "fooscheme:MyPath"); + ASSERT_STREQ("fooscheme:MyPath", url); const char* path = ewk_url_scheme_request_path_get(request); - ASSERT_STREQ(path, "MyPath"); + ASSERT_STREQ("MyPath", path); ASSERT_TRUE(ewk_url_scheme_request_finish(request, htmlReply, strlen(htmlReply), "text/html")); } -TEST_F(EWK2UnitTestBase, ewk_context_uri_scheme_register) +TEST_F(EWK2UnitTestBase, ewk_context_url_scheme_register) { - ewk_context_uri_scheme_register(ewk_view_context_get(webView()), "fooscheme", schemeRequestCallback, 0); - loadUrlSync("fooscheme:MyPath"); - ASSERT_STREQ(ewk_view_title_get(webView()), "Foo"); + ewk_context_url_scheme_register(ewk_view_context_get(webView()), "fooscheme", schemeRequestCallback, 0); + ASSERT_TRUE(loadUrlSync("fooscheme:MyPath")); + ASSERT_STREQ("Foo", ewk_view_title_get(webView())); } struct VibrationCbData { @@ -128,7 +128,7 @@ TEST_F(EWK2UnitTestBase, ewk_context_vibration_client_callbacks_set) // This case the pattern will cause the device to vibrate for 200 ms, be still for 100 ms, and then vibrate for 5000 ms. loadVibrationHTMLString(webView(), "[200, 100, 5000]", true, &data); - ASSERT_EQ(data.vibrateCalledCount, 2); + ASSERT_EQ(2, data.vibrateCalledCount); ASSERT_TRUE(data.didReceiveVibrateCallback); // Cancel outstanding vibration pattern. @@ -141,13 +141,13 @@ TEST_F(EWK2UnitTestBase, ewk_context_vibration_client_callbacks_set) // Make sure we don't receive vibration event. loadVibrationHTMLString(webView(), "[5000]", false, &data); ASSERT_TRUE(waitUntilTitleChangedTo("Loaded")); - ASSERT_STREQ(ewk_view_title_get(webView()), "Loaded"); + ASSERT_STREQ("Loaded", ewk_view_title_get(webView())); ASSERT_FALSE(data.didReceiveVibrateCallback); // Make sure we don't receive cancel vibration event. loadVibrationHTMLString(webView(), "0", false, &data); ASSERT_TRUE(waitUntilTitleChangedTo("Loaded")); - ASSERT_STREQ(ewk_view_title_get(webView()), "Loaded"); + ASSERT_STREQ("Loaded", ewk_view_title_get(webView())); ASSERT_FALSE(data.didReceiveCancelVibrationCallback); } diff --git a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_context_history_callbacks.cpp b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_context_history_callbacks.cpp new file mode 100644 index 000000000..f60a16c2f --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_context_history_callbacks.cpp @@ -0,0 +1,183 @@ +/* + * Copyright (C) 2012 Intel Corporation. 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 "UnitTestUtils/EWK2UnitTestBase.h" +#include "UnitTestUtils/EWK2UnitTestEnvironment.h" +#include "UnitTestUtils/EWK2UnitTestServer.h" +#include <EWebKit2.h> +#include <Ecore.h> +#include <gtest/gtest.h> + +using namespace EWK2UnitTest; + +extern EWK2UnitTestEnvironment* environment; + +static const char defaultTitle[] = "Default Testing Web Page"; + +static const char toBeRedirectedPath[] = "/some_page_to_be_redirected"; +static const char redirectionTargetPath[] = "/redirection_target"; + +static EWK2UnitTestServer* httpServer() +{ + static EWK2UnitTestServer* server = 0; + + if (!server) + server = new EWK2UnitTestServer; + + return server; +} + +#define DECLARE_INVOKE_FLAG(functionName) \ + static bool functionName##Invoked = false; + +#define WAS_INVOKED(functionName) \ + if (functionName##Invoked) \ + return; \ + functionName##Invoked = true + +#define CHECK_WAS_INVOKED(functionName) \ + ASSERT_TRUE(functionName##Invoked) + +DECLARE_INVOKE_FLAG(navigateWithNavigationData) +DECLARE_INVOKE_FLAG(performClientRedirect) +DECLARE_INVOKE_FLAG(performServerRedirect) +DECLARE_INVOKE_FLAG(updateHistoryTitle) +DECLARE_INVOKE_FLAG(populateVisitedLinks) + +static void navigateWithNavigationData(const Evas_Object* view, Ewk_Navigation_Data* navigationData, void* userData) +{ + WAS_INVOKED(navigateWithNavigationData); + + EWK2UnitTestBase* unitTest = static_cast<EWK2UnitTestBase*>(userData); + ASSERT_TRUE(unitTest); + ASSERT_EQ(unitTest->webView(), view); + // FIXME: WebFrameLoaderClient sends empty title. + // ASSERT_STREQ(defaultTitle, ewk_navigation_data_title_get(navigationData)); + ASSERT_STREQ(environment->defaultTestPageUrl(), ewk_navigation_data_url_get(navigationData)); + + Ewk_Url_Request* request = ewk_navigation_data_original_request_get(navigationData); + ASSERT_STREQ("GET", ewk_url_request_http_method_get(request)); + ASSERT_STREQ(environment->defaultTestPageUrl(), ewk_url_request_url_get(request)); + ASSERT_EQ(0, ewk_request_cookies_first_party_get(request)); +} + +static void performClientRedirect(const Evas_Object* view, const char* sourceUrl, const char* destinationUrl, void* userData) +{ + WAS_INVOKED(performClientRedirect); + + EWK2UnitTestBase* unitTest = static_cast<EWK2UnitTestBase*>(userData); + ASSERT_TRUE(unitTest); + ASSERT_EQ(unitTest->webView(), view); + ASSERT_STREQ(environment->urlForResource("redirect_url_to_default.html").data(), sourceUrl); + ASSERT_STREQ(environment->defaultTestPageUrl(), destinationUrl); +} + +static void performServerRedirect(const Evas_Object* view, const char* sourceUrl, const char* destinationUrl, void* userData) +{ + WAS_INVOKED(performServerRedirect); + + EWK2UnitTestBase* unitTest = static_cast<EWK2UnitTestBase*>(userData); + ASSERT_TRUE(unitTest); + ASSERT_EQ(unitTest->webView(), view); + ASSERT_STREQ(httpServer()->getURLForPath(toBeRedirectedPath).data(), sourceUrl); + ASSERT_STREQ(httpServer()->getURLForPath(redirectionTargetPath).data(), destinationUrl); +} + +static void updateHistoryTitle(const Evas_Object* view, const char* title, const char* url, void* userData) +{ + WAS_INVOKED(updateHistoryTitle); + + EWK2UnitTestBase* unitTest = static_cast<EWK2UnitTestBase*>(userData); + ASSERT_TRUE(unitTest); + ASSERT_EQ(unitTest->webView(), view); + ASSERT_STREQ(defaultTitle, title); + ASSERT_STREQ(environment->defaultTestPageUrl(), url); +} + +static void populateVisitedLinks(void* userData) +{ + WAS_INVOKED(populateVisitedLinks); + + EWK2UnitTestBase* unitTest = static_cast<EWK2UnitTestBase*>(userData); + ASSERT_TRUE(unitTest); +} + +static void onLoadFinishedForRedirection(void* userData, Evas_Object*, void*) +{ + int* countLoadFinished = static_cast<int*>(userData); + --(*countLoadFinished); +} + +static void serverCallbackRedirection(SoupServer*, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) +{ + if (message->method != SOUP_METHOD_GET) { + soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); + return; + } + + if (strcmp(path, redirectionTargetPath)) { // Redirect if 'path' is not equal to 'redirectionTargetPath'. + soup_message_set_status(message, SOUP_STATUS_TEMPORARY_REDIRECT); + soup_message_headers_append(message->response_headers, "Location", httpServer()->getURLForPath(redirectionTargetPath).data()); + return; + } + + soup_message_set_status(message, SOUP_STATUS_OK); + Eina_Strbuf* body = eina_strbuf_new(); + eina_strbuf_append_printf(body, "<html><title>Redirection Target</title></html>"); + const size_t bodyLength = eina_strbuf_length_get(body); + soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, eina_strbuf_string_steal(body), bodyLength); + eina_strbuf_free(body); + + soup_message_body_complete(message->response_body); +} + +TEST_F(EWK2UnitTestBase, ewk_context_history_callbacks_set) +{ + ewk_context_history_callbacks_set(ewk_view_context_get(webView()), navigateWithNavigationData, performClientRedirect, performServerRedirect, updateHistoryTitle, populateVisitedLinks, this); + + // Test navigation. + ASSERT_TRUE(loadUrlSync(environment->defaultTestPageUrl())); + CHECK_WAS_INVOKED(navigateWithNavigationData); + CHECK_WAS_INVOKED(updateHistoryTitle); + CHECK_WAS_INVOKED(populateVisitedLinks); + + // Test client redirect. + int countLoadFinished = 2; + evas_object_smart_callback_add(webView(), "load,finished", onLoadFinishedForRedirection, &countLoadFinished); + ewk_view_url_set(webView(), environment->urlForResource("redirect_url_to_default.html").data()); + while (countLoadFinished) + ecore_main_loop_iterate(); + evas_object_smart_callback_del(webView(), "load,finished", onLoadFinishedForRedirection); + CHECK_WAS_INVOKED(performClientRedirect); + + // Test server redirect. + httpServer()->run(serverCallbackRedirection); + + ASSERT_TRUE(loadUrlSync(httpServer()->getURLForPath(toBeRedirectedPath).data())); + CHECK_WAS_INVOKED(performServerRedirect); +} + diff --git a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_cookie_manager.cpp b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_cookie_manager.cpp index 4353ced79..598b15519 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_cookie_manager.cpp +++ b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_cookie_manager.cpp @@ -65,7 +65,7 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char* soup_message_body_complete(message->response_body); } -static void getAcceptPolicyCallback(Ewk_Cookie_Accept_Policy policy, Ewk_Web_Error* error, void* event_info) +static void getAcceptPolicyCallback(Ewk_Cookie_Accept_Policy policy, Ewk_Error* error, void* event_info) { ASSERT_FALSE(error); Ewk_Cookie_Accept_Policy* ret = static_cast<Ewk_Cookie_Accept_Policy*>(event_info); @@ -81,7 +81,7 @@ static Ewk_Cookie_Accept_Policy getAcceptPolicy(Ewk_Cookie_Manager* manager) return policy; } -static void getHostnamesWithCookiesCallback(Eina_List* hostnames, Ewk_Web_Error* error, void* event_info) +static void getHostnamesWithCookiesCallback(Eina_List* hostnames, Ewk_Error* error, void* event_info) { ASSERT_FALSE(error); @@ -116,6 +116,11 @@ static int countHostnamesWithCookies(Ewk_Cookie_Manager* manager) return count; } +static int compareHostNames(const void* hostName1, const void* hostName2) +{ + return strcmp(static_cast<const char*>(hostName1), static_cast<const char*>(hostName2)); +} + TEST_F(EWK2UnitTestBase, ewk_cookie_manager_accept_policy) { OwnPtr<EWK2UnitTestServer> httpServer = adoptPtr(new EWK2UnitTestServer); @@ -125,32 +130,33 @@ TEST_F(EWK2UnitTestBase, ewk_cookie_manager_accept_policy) ASSERT_TRUE(cookieManager); // Default policy is EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY. - ASSERT_EQ(getAcceptPolicy(cookieManager), EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY); - loadUrlSync(httpServer->getURIForPath("/index.html").data()); + ASSERT_EQ(EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY, getAcceptPolicy(cookieManager)); + ASSERT_TRUE(loadUrlSync(httpServer->getURLForPath("/index.html").data())); Eina_List* hostnames = getHostnamesWithCookies(cookieManager); - ASSERT_EQ(eina_list_count(hostnames), 1); - ASSERT_STREQ(static_cast<char*>(eina_list_nth(hostnames, 0)), FIRST_PARTY_DOMAIN); + ASSERT_EQ(1, eina_list_count(hostnames)); + ASSERT_STREQ(FIRST_PARTY_DOMAIN, static_cast<char*>(eina_list_nth(hostnames, 0))); freeHostNames(hostnames); ewk_cookie_manager_cookies_clear(cookieManager); // Change policy to EWK_COOKIE_ACCEPT_POLICY_ALWAYS ewk_cookie_manager_accept_policy_set(cookieManager, EWK_COOKIE_ACCEPT_POLICY_ALWAYS); - ASSERT_EQ(getAcceptPolicy(cookieManager), EWK_COOKIE_ACCEPT_POLICY_ALWAYS); - loadUrlSync(httpServer->getURIForPath("/index.html").data()); + ASSERT_EQ(EWK_COOKIE_ACCEPT_POLICY_ALWAYS, getAcceptPolicy(cookieManager)); + ASSERT_TRUE(loadUrlSync(httpServer->getURLForPath("/index.html").data())); hostnames = getHostnamesWithCookies(cookieManager); - ASSERT_EQ(eina_list_count(hostnames), 2); - ASSERT_STREQ(static_cast<char*>(eina_list_nth(hostnames, 0)), FIRST_PARTY_DOMAIN); - ASSERT_STREQ(static_cast<char*>(eina_list_nth(hostnames, 1)), THIRD_PARTY_DOMAIN); + ASSERT_EQ(2, eina_list_count(hostnames)); + hostnames = eina_list_sort(hostnames, eina_list_count(hostnames), compareHostNames); + ASSERT_STREQ(FIRST_PARTY_DOMAIN, static_cast<char*>(eina_list_nth(hostnames, 0))); + ASSERT_STREQ(THIRD_PARTY_DOMAIN, static_cast<char*>(eina_list_nth(hostnames, 1))); freeHostNames(hostnames); ewk_cookie_manager_cookies_clear(cookieManager); // Change policy to EWK_COOKIE_ACCEPT_POLICY_NEVER ewk_cookie_manager_accept_policy_set(cookieManager, EWK_COOKIE_ACCEPT_POLICY_NEVER); - ASSERT_EQ(getAcceptPolicy(cookieManager), EWK_COOKIE_ACCEPT_POLICY_NEVER); - loadUrlSync(httpServer->getURIForPath("/index.html").data()); - ASSERT_EQ(countHostnamesWithCookies(cookieManager), 0); + ASSERT_EQ(EWK_COOKIE_ACCEPT_POLICY_NEVER, getAcceptPolicy(cookieManager)); + ASSERT_TRUE(loadUrlSync(httpServer->getURLForPath("/index.html").data())); + ASSERT_EQ(0, countHostnamesWithCookies(cookieManager)); } void onCookiesChanged(void *eventInfo) @@ -168,14 +174,14 @@ TEST_F(EWK2UnitTestBase, ewk_cookie_manager_changes_watch) ASSERT_TRUE(cookieManager); ewk_cookie_manager_accept_policy_set(cookieManager, EWK_COOKIE_ACCEPT_POLICY_ALWAYS); - ASSERT_EQ(getAcceptPolicy(cookieManager), EWK_COOKIE_ACCEPT_POLICY_ALWAYS); + ASSERT_EQ(EWK_COOKIE_ACCEPT_POLICY_ALWAYS, getAcceptPolicy(cookieManager)); // Watch for changes bool cookiesChanged = false; ewk_cookie_manager_changes_watch(cookieManager, onCookiesChanged, &cookiesChanged); // Check for cookie changes notifications - loadUrlSync(httpServer->getURIForPath("/index.html").data()); + ASSERT_TRUE(loadUrlSync(httpServer->getURLForPath("/index.html").data())); while (!cookiesChanged) ecore_main_loop_iterate(); @@ -190,8 +196,8 @@ TEST_F(EWK2UnitTestBase, ewk_cookie_manager_changes_watch) // Stop watching for notifications ewk_cookie_manager_changes_watch(cookieManager, 0, 0); cookiesChanged = false; - loadUrlSync(httpServer->getURIForPath("/index.html").data()); - ASSERT_EQ(countHostnamesWithCookies(cookieManager), 2); + ASSERT_TRUE(loadUrlSync(httpServer->getURLForPath("/index.html").data())); + ASSERT_EQ(2, countHostnamesWithCookies(cookieManager)); ASSERT_FALSE(cookiesChanged); // Watch again for notifications @@ -204,15 +210,15 @@ TEST_F(EWK2UnitTestBase, ewk_cookie_manager_changes_watch) ASSERT_TRUE(mktemp(textStorage2)); ewk_cookie_manager_persistent_storage_set(cookieManager, textStorage1, EWK_COOKIE_PERSISTENT_STORAGE_TEXT); - loadUrlSync(httpServer->getURIForPath("/index.html").data()); - ASSERT_EQ(countHostnamesWithCookies(cookieManager), 2); + ASSERT_TRUE(loadUrlSync(httpServer->getURLForPath("/index.html").data())); + ASSERT_EQ(2, countHostnamesWithCookies(cookieManager)); cookiesChanged = false; ewk_cookie_manager_persistent_storage_set(cookieManager, textStorage2, EWK_COOKIE_PERSISTENT_STORAGE_TEXT); - ASSERT_EQ(countHostnamesWithCookies(cookieManager), 0); + ASSERT_EQ(0, countHostnamesWithCookies(cookieManager)); ewk_cookie_manager_persistent_storage_set(cookieManager, textStorage1, EWK_COOKIE_PERSISTENT_STORAGE_TEXT); - ASSERT_EQ(countHostnamesWithCookies(cookieManager), 2); + ASSERT_EQ(2, countHostnamesWithCookies(cookieManager)); ASSERT_FALSE(cookiesChanged); @@ -231,31 +237,31 @@ TEST_F(EWK2UnitTestBase, ewk_cookie_manager_cookies_delete) ASSERT_TRUE(cookieManager); ewk_cookie_manager_accept_policy_set(cookieManager, EWK_COOKIE_ACCEPT_POLICY_ALWAYS); - ASSERT_EQ(getAcceptPolicy(cookieManager), EWK_COOKIE_ACCEPT_POLICY_ALWAYS); + ASSERT_EQ(EWK_COOKIE_ACCEPT_POLICY_ALWAYS, getAcceptPolicy(cookieManager)); - loadUrlSync(httpServer->getURIForPath("/index.html").data()); + ASSERT_TRUE(loadUrlSync(httpServer->getURLForPath("/index.html").data())); Eina_List* hostnames = getHostnamesWithCookies(cookieManager); - ASSERT_EQ(eina_list_count(hostnames), 2); + ASSERT_EQ(2, eina_list_count(hostnames)); freeHostNames(hostnames); // Delete first party cookie ewk_cookie_manager_hostname_cookies_clear(cookieManager, FIRST_PARTY_DOMAIN); hostnames = getHostnamesWithCookies(cookieManager); - ASSERT_EQ(eina_list_count(hostnames), 1); - ASSERT_STREQ(static_cast<char*>(eina_list_nth(hostnames, 0)), THIRD_PARTY_DOMAIN); + ASSERT_EQ(1, eina_list_count(hostnames)); + ASSERT_STREQ(THIRD_PARTY_DOMAIN, static_cast<char*>(eina_list_nth(hostnames, 0))); freeHostNames(hostnames); // Delete third party cookie ewk_cookie_manager_hostname_cookies_clear(cookieManager, THIRD_PARTY_DOMAIN); - ASSERT_EQ(countHostnamesWithCookies(cookieManager), 0); + ASSERT_EQ(0, countHostnamesWithCookies(cookieManager)); // Get all cookies again - loadUrlSync(httpServer->getURIForPath("/index.html").data()); - ASSERT_EQ(countHostnamesWithCookies(cookieManager), 2); + ASSERT_TRUE(loadUrlSync(httpServer->getURLForPath("/index.html").data())); + ASSERT_EQ(2, countHostnamesWithCookies(cookieManager)); // Clear all cookies ewk_cookie_manager_cookies_clear(cookieManager); - ASSERT_EQ(countHostnamesWithCookies(cookieManager), 0); + ASSERT_EQ(0, countHostnamesWithCookies(cookieManager)); } TEST_F(EWK2UnitTestBase, DISABLED_ewk_cookie_manager_permanent_storage) @@ -273,33 +279,33 @@ TEST_F(EWK2UnitTestBase, DISABLED_ewk_cookie_manager_permanent_storage) ASSERT_TRUE(cookieManager); ewk_cookie_manager_accept_policy_set(cookieManager, EWK_COOKIE_ACCEPT_POLICY_ALWAYS); - ASSERT_EQ(getAcceptPolicy(cookieManager), EWK_COOKIE_ACCEPT_POLICY_ALWAYS); + ASSERT_EQ(EWK_COOKIE_ACCEPT_POLICY_ALWAYS, getAcceptPolicy(cookieManager)); // Text storage using a new file. ewk_cookie_manager_persistent_storage_set(cookieManager, textStorage, EWK_COOKIE_PERSISTENT_STORAGE_TEXT); - ASSERT_EQ(countHostnamesWithCookies(cookieManager), 0); + ASSERT_EQ(0, countHostnamesWithCookies(cookieManager)); - loadUrlSync(httpServer->getURIForPath("/index.html").data()); - ASSERT_EQ(countHostnamesWithCookies(cookieManager), 2); + ASSERT_TRUE(loadUrlSync(httpServer->getURLForPath("/index.html").data())); + ASSERT_EQ(2, countHostnamesWithCookies(cookieManager)); // SQLite storage using a new file. ewk_cookie_manager_persistent_storage_set(cookieManager, sqliteStorage, EWK_COOKIE_PERSISTENT_STORAGE_SQLITE); - ASSERT_EQ(countHostnamesWithCookies(cookieManager), 0); + ASSERT_EQ(0, countHostnamesWithCookies(cookieManager)); - loadUrlSync(httpServer->getURIForPath("/index.html").data()); - ASSERT_EQ(countHostnamesWithCookies(cookieManager), 2); + ASSERT_TRUE(loadUrlSync(httpServer->getURLForPath("/index.html").data())); + ASSERT_EQ(2, countHostnamesWithCookies(cookieManager)); // Text storage using an existing file. ewk_cookie_manager_persistent_storage_set(cookieManager, textStorage, EWK_COOKIE_PERSISTENT_STORAGE_TEXT); - ASSERT_EQ(countHostnamesWithCookies(cookieManager), 2); + ASSERT_EQ(2, countHostnamesWithCookies(cookieManager)); ewk_cookie_manager_cookies_clear(cookieManager); - ASSERT_EQ(countHostnamesWithCookies(cookieManager), 0); + ASSERT_EQ(0, countHostnamesWithCookies(cookieManager)); // SQLite storage with an existing file. ewk_cookie_manager_persistent_storage_set(cookieManager, sqliteStorage, EWK_COOKIE_PERSISTENT_STORAGE_SQLITE); - ASSERT_EQ(countHostnamesWithCookies(cookieManager), 2); + ASSERT_EQ(2, countHostnamesWithCookies(cookieManager)); ewk_cookie_manager_cookies_clear(cookieManager); - ASSERT_EQ(countHostnamesWithCookies(cookieManager), 0); + ASSERT_EQ(0, countHostnamesWithCookies(cookieManager)); // Final clean up. unlink(textStorage); diff --git a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_download_job.cpp b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_download_job.cpp index 22c97aad8..1494926e2 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_download_job.cpp +++ b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_download_job.cpp @@ -102,23 +102,23 @@ static void on_download_requested(void* userData, Evas_Object* webview, void* ev { DownloadTestData* testData = static_cast<DownloadTestData*>(userData); Ewk_Download_Job* download = static_cast<Ewk_Download_Job*>(eventInfo); - ASSERT_EQ(ewk_download_job_state_get(download), EWK_DOWNLOAD_JOB_STATE_NOT_STARTED); - ASSERT_EQ(ewk_download_job_estimated_progress_get(download), 0); - ASSERT_EQ(ewk_download_job_elapsed_time_get(download), 0); + ASSERT_EQ(EWK_DOWNLOAD_JOB_STATE_NOT_STARTED, ewk_download_job_state_get(download)); + ASSERT_EQ(0, ewk_download_job_estimated_progress_get(download)); + ASSERT_EQ(0, ewk_download_job_elapsed_time_get(download)); Ewk_Url_Request* request = ewk_download_job_request_get(download); ASSERT_TRUE(request); - EXPECT_STREQ(ewk_url_request_url_get(request), testData->fileUrl); + EXPECT_STREQ(testData->fileUrl, ewk_url_request_url_get(request)); Ewk_Url_Response* response = ewk_download_job_response_get(download); ASSERT_TRUE(response); - EXPECT_STREQ(ewk_url_response_mime_type_get(response), "application/pdf"); + EXPECT_STREQ("application/pdf", ewk_url_response_mime_type_get(response)); - EXPECT_STREQ(ewk_download_job_suggested_filename_get(download), serverSuggestedFilename); + EXPECT_STREQ(serverSuggestedFilename, ewk_download_job_suggested_filename_get(download)); ASSERT_FALSE(fileExists(testData->destinationPath)); ewk_download_job_destination_set(download, testData->destinationPath); - EXPECT_STREQ(ewk_download_job_destination_get(download), testData->destinationPath); + EXPECT_STREQ(testData->destinationPath, ewk_download_job_destination_get(download)); } static void on_download_cancelled(void* userData, Evas_Object* webview, void* eventInfo) @@ -131,7 +131,7 @@ static void on_download_cancelled(void* userData, Evas_Object* webview, void* ev static void on_download_failed(void* userData, Evas_Object* webview, void* eventInfo) { Ewk_Download_Job_Error* downloadError = static_cast<Ewk_Download_Job_Error*>(eventInfo); - fprintf(stderr, "Download error: %s\n", ewk_web_error_description_get(downloadError->error)); + fprintf(stderr, "Download error: %s\n", ewk_error_description_get(downloadError->error)); ecore_main_loop_quit(); FAIL(); } @@ -141,8 +141,8 @@ static void on_download_finished(void* userData, Evas_Object* webview, void* eve DownloadTestData* testData = static_cast<DownloadTestData*>(userData); Ewk_Download_Job* download = static_cast<Ewk_Download_Job*>(eventInfo); - ASSERT_EQ(ewk_download_job_estimated_progress_get(download), 1); - ASSERT_EQ(ewk_download_job_state_get(download), EWK_DOWNLOAD_JOB_STATE_FINISHED); + ASSERT_EQ(1, ewk_download_job_estimated_progress_get(download)); + ASSERT_EQ(EWK_DOWNLOAD_JOB_STATE_FINISHED, ewk_download_job_state_get(download)); ASSERT_GT(ewk_download_job_elapsed_time_get(download), 0); ASSERT_TRUE(fileExists(testData->destinationPath)); @@ -159,7 +159,7 @@ TEST_F(EWK2UnitTestBase, ewk_download) char destinationPath[] = "/tmp/pdf-file.XXXXXX"; ASSERT_TRUE(mktemp(destinationPath)); - CString fileUrl = httpServer->getURIForPath(testFilePath); + CString fileUrl = httpServer->getURLForPath(testFilePath); DownloadTestData userData = { fileUrl.data(), destinationPath }; ASSERT_FALSE(fileExists(destinationPath)); @@ -170,7 +170,7 @@ TEST_F(EWK2UnitTestBase, ewk_download) evas_object_smart_callback_add(webView(), "download,finished", on_download_finished, &userData); // Download test pdf - ewk_view_uri_set(webView(), fileUrl.data()); + ewk_view_url_set(webView(), fileUrl.data()); ecore_main_loop_begin(); // Clean up diff --git a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_intents.cpp b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_intents.cpp index be8b0ffa8..4b46cd883 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_intents.cpp +++ b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_intents.cpp @@ -43,18 +43,18 @@ static void onIntentServiceRegistration(void* userData, Evas_Object*, void* even Ewk_Intent_Service* service = static_cast<Ewk_Intent_Service*>(eventInfo); ASSERT_TRUE(service); - EXPECT_STREQ(ewk_intent_service_action_get(service), "action"); - EXPECT_STREQ(ewk_intent_service_type_get(service), "type"); - EXPECT_STREQ(ewk_intent_service_title_get(service), "Title"); - EXPECT_STREQ(ewk_intent_service_href_get(service), "http://example.com/service"); - EXPECT_STREQ(ewk_intent_service_disposition_get(service), "inline"); + EXPECT_STREQ("action", ewk_intent_service_action_get(service)); + EXPECT_STREQ("type", ewk_intent_service_type_get(service)); + EXPECT_STREQ("Title", ewk_intent_service_title_get(service)); + EXPECT_STREQ("http://example.com/service", ewk_intent_service_href_get(service)); + EXPECT_STREQ("inline", ewk_intent_service_disposition_get(service)); } TEST_F(EWK2UnitTestBase, ewk_intent_service_registration) { bool intentRegistered = false; evas_object_smart_callback_add(webView(), "intent,service,register", onIntentServiceRegistration, &intentRegistered); - loadUrlSync(environment->urlForResource("intent-service.html").data()); + ASSERT_TRUE(loadUrlSync(environment->urlForResource("intent-service.html").data())); evas_object_smart_callback_del(webView(), "intent,service,register", onIntentServiceRegistration); ASSERT_TRUE(intentRegistered); } @@ -76,22 +76,22 @@ static void onIntentReceived(void* userData, Evas_Object*, void* eventInfo) if (*intentReceivedCount == 1) { // First intent. - EXPECT_STREQ(ewk_intent_action_get(intent), "action1"); - EXPECT_STREQ(ewk_intent_type_get(intent), "mime/type1"); - EXPECT_STREQ(ewk_intent_service_get(intent), "http://service1.com/"); - EXPECT_STREQ(ewk_intent_extra_get(intent, "key1"), "value1"); - EXPECT_STREQ(ewk_intent_extra_get(intent, "key2"), "value2"); + EXPECT_STREQ("action1", ewk_intent_action_get(intent)); + EXPECT_STREQ("mime/type1", ewk_intent_type_get(intent)); + EXPECT_STREQ("http://service1.com/", ewk_intent_service_get(intent)); + EXPECT_STREQ("value1", ewk_intent_extra_get(intent, "key1")); + EXPECT_STREQ("value2", ewk_intent_extra_get(intent, "key2")); } else { // Second intent. - EXPECT_STREQ(ewk_intent_action_get(intent), "action2"); - EXPECT_STREQ(ewk_intent_type_get(intent), "mime/type2"); + EXPECT_STREQ("action2", ewk_intent_action_get(intent)); + EXPECT_STREQ("mime/type2", ewk_intent_type_get(intent)); Eina_List* suggestions = ewk_intent_suggestions_get(intent); ASSERT_TRUE(suggestions); - ASSERT_EQ(eina_list_count(suggestions), 2); + ASSERT_EQ(2, eina_list_count(suggestions)); // We need to sort the suggestions since Intent is using a HashSet internally. suggestions = eina_list_sort(suggestions, 2, stringSortCb); - EXPECT_STREQ(static_cast<const char*>(eina_list_nth(suggestions, 0)), "http://service1.com/"); - EXPECT_STREQ(static_cast<const char*>(eina_list_nth(suggestions, 1)), "http://service2.com/"); + EXPECT_STREQ("http://service1.com/", static_cast<const char*>(eina_list_nth(suggestions, 0))); + EXPECT_STREQ("http://service2.com/", static_cast<const char*>(eina_list_nth(suggestions, 1))); void* listData = 0; EINA_LIST_FREE(suggestions, listData) @@ -103,18 +103,18 @@ TEST_F(EWK2UnitTestBase, ewk_intent_request) { unsigned intentReceivedCount = 0; evas_object_smart_callback_add(webView(), "intent,request,new", onIntentReceived, &intentReceivedCount); - loadUrlSync(environment->urlForResource("intent-request.html").data()); + ASSERT_TRUE(loadUrlSync(environment->urlForResource("intent-request.html").data())); // A user gesture is required for the intent to start. mouseClick(5, 5); while (intentReceivedCount != 1) ecore_main_loop_iterate(); - ASSERT_EQ(intentReceivedCount, 1); + ASSERT_EQ(1, intentReceivedCount); // Generate a second intent request. mouseClick(5, 5); while (intentReceivedCount != 2) ecore_main_loop_iterate(); - ASSERT_EQ(intentReceivedCount, 2); + ASSERT_EQ(2, intentReceivedCount); evas_object_smart_callback_del(webView(), "intent,request,new", onIntentReceived); } diff --git a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_refptr_evas_object.cpp b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_refptr_evas_object.cpp index fb6e57269..939d20c6d 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_refptr_evas_object.cpp +++ b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_refptr_evas_object.cpp @@ -65,14 +65,14 @@ TEST_F(EWK2UnitTestBase, reffing) RefPtr<Evas_Object> object = adoptRef(evas_object_box_add(canvas())); ASSERT_TRUE(object); // Evas_Objec external ref count is not as you would expect. - ASSERT_EQ(evas_object_ref_get(object.get()), 0); + ASSERT_EQ(0, evas_object_ref_get(object.get())); { RefPtr<Evas_Object> aRef = object; ASSERT_TRUE(object); ASSERT_TRUE(aRef); - ASSERT_EQ(evas_object_ref_get(object.get()), 1); - ASSERT_EQ(evas_object_ref_get(aRef.get()), 1); + ASSERT_EQ(1, evas_object_ref_get(object.get())); + ASSERT_EQ(1, evas_object_ref_get(aRef.get())); { RefPtr<Evas_Object> bRef = object; @@ -81,51 +81,51 @@ TEST_F(EWK2UnitTestBase, reffing) ASSERT_TRUE(aRef); ASSERT_TRUE(bRef); - ASSERT_EQ(evas_object_ref_get(object.get()), 2); - ASSERT_EQ(evas_object_ref_get(aRef.get()), 2); + ASSERT_EQ(2, evas_object_ref_get(object.get())); + ASSERT_EQ(2, evas_object_ref_get(aRef.get())); RefPtr<Evas_Object> cRef = bRef; ASSERT_TRUE(cRef); - ASSERT_EQ(evas_object_ref_get(object.get()), 3); - ASSERT_EQ(evas_object_ref_get(aRef.get()), 3); - ASSERT_EQ(evas_object_ref_get(bRef.get()), 3); - ASSERT_EQ(evas_object_ref_get(cRef.get()), 3); + ASSERT_EQ(3, evas_object_ref_get(object.get())); + ASSERT_EQ(3, evas_object_ref_get(aRef.get())); + ASSERT_EQ(3, evas_object_ref_get(bRef.get())); + ASSERT_EQ(3, evas_object_ref_get(cRef.get())); bRef.clear(); - ASSERT_EQ(evas_object_ref_get(object.get()), 2); - ASSERT_EQ(evas_object_ref_get(aRef.get()), 2); - ASSERT_EQ(evas_object_ref_get(cRef.get()), 2); + ASSERT_EQ(2, evas_object_ref_get(object.get())); + ASSERT_EQ(2, evas_object_ref_get(aRef.get())); + ASSERT_EQ(2, evas_object_ref_get(cRef.get())); } - ASSERT_EQ(evas_object_ref_get(object.get()), 1); - ASSERT_EQ(evas_object_ref_get(aRef.get()), 1); + ASSERT_EQ(1, evas_object_ref_get(object.get())); + ASSERT_EQ(1, evas_object_ref_get(aRef.get())); } - ASSERT_EQ(evas_object_ref_get(object.get()), 0); + ASSERT_EQ(0, evas_object_ref_get(object.get())); } TEST_F(EWK2UnitTestBase, destruction) { RefPtr<Evas_Object> object = adoptRef(evas_object_box_add(canvas())); ASSERT_TRUE(object); - ASSERT_EQ(evas_object_ref_get(object.get()), 0); + ASSERT_EQ(0, evas_object_ref_get(object.get())); RefPtr<Evas_Object> aRef = object; ASSERT_TRUE(object); ASSERT_TRUE(aRef); - ASSERT_EQ(evas_object_ref_get(object.get()), 1); - ASSERT_EQ(evas_object_ref_get(aRef.get()), 1); + ASSERT_EQ(1, evas_object_ref_get(object.get())); + ASSERT_EQ(1, evas_object_ref_get(aRef.get())); object = nullptr; - ASSERT_EQ(evas_object_ref_get(object.get()), 0); - ASSERT_EQ(evas_object_ref_get(aRef.get()), 0); + ASSERT_EQ(0, evas_object_ref_get(object.get())); + ASSERT_EQ(0, evas_object_ref_get(aRef.get())); object = aRef; - ASSERT_EQ(evas_object_ref_get(object.get()), 1); - ASSERT_EQ(evas_object_ref_get(aRef.get()), 1); + ASSERT_EQ(1, evas_object_ref_get(object.get())); + ASSERT_EQ(1, evas_object_ref_get(aRef.get())); object = 0; - ASSERT_EQ(evas_object_ref_get(object.get()), 0); - ASSERT_EQ(evas_object_ref_get(aRef.get()), 0); + ASSERT_EQ(0, evas_object_ref_get(object.get())); + ASSERT_EQ(0, evas_object_ref_get(aRef.get())); aRef.clear(); ASSERT_FALSE(aRef); diff --git a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_settings.cpp b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_settings.cpp index 9889bbae7..32f981788 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_settings.cpp +++ b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_settings.cpp @@ -26,11 +26,14 @@ #include "config.h" #include "UnitTestUtils/EWK2UnitTestBase.h" +#include "UnitTestUtils/EWK2UnitTestEnvironment.h" #include <EWebKit2.h> #include <Eina.h> using namespace EWK2UnitTest; +extern EWK2UnitTestEnvironment* environment; + TEST_F(EWK2UnitTestBase, ewk_settings_fullscreen_enabled) { Ewk_Settings* settings = ewk_view_settings_get(webView()); @@ -95,3 +98,62 @@ TEST_F(EWK2UnitTestBase, ewk_settings_developer_extras_enabled) ASSERT_TRUE(ewk_settings_developer_extras_enabled_set(settings, EINA_FALSE)); ASSERT_FALSE(ewk_settings_developer_extras_enabled_get(settings)); } + +TEST_F(EWK2UnitTestBase, ewk_settings_file_access_from_file_urls_allowed) +{ + CString testURL = environment->urlForResource("local_file_access.html"); + Ewk_Settings* settings = ewk_view_settings_get(webView()); + + ASSERT_FALSE(ewk_settings_file_access_from_file_urls_allowed_get(settings)); + + ASSERT_TRUE(ewk_settings_file_access_from_file_urls_allowed_set(settings, true)); + ASSERT_TRUE(ewk_settings_file_access_from_file_urls_allowed_get(settings)); + + // Check that file access from file:// URLs is allowed. + ewk_view_url_set(webView(), testURL.data()); + ASSERT_TRUE(waitUntilTitleChangedTo("Frame loaded")); + + ASSERT_TRUE(ewk_settings_file_access_from_file_urls_allowed_set(settings, false)); + ASSERT_FALSE(ewk_settings_file_access_from_file_urls_allowed_get(settings)); + + // Check that file access from file:// URLs is NOT allowed. + ewk_view_url_set(webView(), testURL.data()); + ASSERT_TRUE(waitUntilTitleChangedTo("Frame NOT loaded")); +} + +TEST_F(EWK2UnitTestBase, ewk_settings_frame_flattening_enabled_set) +{ + Ewk_Settings* settings = ewk_view_settings_get(webView()); + ASSERT_TRUE(settings); + + // The frame flattening is disabled by default. + ASSERT_FALSE(ewk_settings_frame_flattening_enabled_get(settings)); + ewk_view_url_set(webView(), environment->urlForResource("frame_flattening_test.html").data()); + waitUntilTitleChangedTo("200"); // width of iframe tag. + ASSERT_STREQ("200", ewk_view_title_get(webView())); + + ASSERT_TRUE(ewk_settings_frame_flattening_enabled_set(settings, true)); + ASSERT_TRUE(ewk_settings_frame_flattening_enabled_get(settings)); + ewk_view_url_set(webView(), environment->urlForResource("frame_flattening_test.html").data()); + waitUntilTitleChangedTo("600"); // width of frame_flattening_test_subframe.html + ASSERT_STREQ("600", ewk_view_title_get(webView())); + + ASSERT_TRUE(ewk_settings_frame_flattening_enabled_set(settings, false)); + ASSERT_FALSE(ewk_settings_frame_flattening_enabled_get(settings)); + ewk_view_url_set(webView(), environment->urlForResource("frame_flattening_test.html").data()); + waitUntilTitleChangedTo("200"); // width of iframe tag. + ASSERT_STREQ("200", ewk_view_title_get(webView())); +} + +TEST_F(EWK2UnitTestBase, ewk_settings_dns_prefetching_enabled) +{ + Ewk_Settings* settings = ewk_view_settings_get(webView()); + + // DNS prefeching is disabled by default. + ASSERT_FALSE(ewk_settings_dns_prefetching_enabled_get(settings)); + ASSERT_TRUE(ewk_settings_dns_prefetching_enabled_set(settings, true)); + ASSERT_TRUE(ewk_settings_dns_prefetching_enabled_get(settings)); + + ASSERT_TRUE(ewk_settings_dns_prefetching_enabled_set(settings, false)); + ASSERT_FALSE(ewk_settings_dns_prefetching_enabled_get(settings)); +} diff --git a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp index 73f3ac749..0ab0c912e 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp +++ b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp @@ -44,42 +44,42 @@ static void onLoadFinishedForRedirection(void* userData, Evas_Object*, void*) (*countLoadFinished)--; } -TEST_F(EWK2UnitTestBase, ewk_view_uri_get) +TEST_F(EWK2UnitTestBase, ewk_view_url_get) { - loadUrlSync(environment->defaultTestPageUrl()); - EXPECT_STREQ(ewk_view_uri_get(webView()), environment->defaultTestPageUrl()); + ASSERT_TRUE(loadUrlSync(environment->defaultTestPageUrl())); + EXPECT_STREQ(environment->defaultTestPageUrl(), ewk_view_url_get(webView())); int countLoadFinished = 2; evas_object_smart_callback_add(webView(), "load,finished", onLoadFinishedForRedirection, &countLoadFinished); - ewk_view_uri_set(webView(), environment->urlForResource("redirect_uri_to_default.html").data()); + ewk_view_url_set(webView(), environment->urlForResource("redirect_url_to_default.html").data()); while (countLoadFinished) ecore_main_loop_iterate(); evas_object_smart_callback_del(webView(), "load,finished", onLoadFinishedForRedirection); - EXPECT_STREQ(ewk_view_uri_get(webView()), environment->defaultTestPageUrl()); + EXPECT_STREQ(environment->defaultTestPageUrl(), ewk_view_url_get(webView())); } TEST_F(EWK2UnitTestBase, ewk_view_device_pixel_ratio) { - loadUrlSync(environment->defaultTestPageUrl()); + ASSERT_TRUE(loadUrlSync(environment->defaultTestPageUrl())); // Default pixel ratio is 1.0 - ASSERT_FLOAT_EQ(ewk_view_device_pixel_ratio_get(webView()), 1); + ASSERT_FLOAT_EQ(1, ewk_view_device_pixel_ratio_get(webView())); ASSERT_TRUE(ewk_view_device_pixel_ratio_set(webView(), 1.2)); - ASSERT_FLOAT_EQ(ewk_view_device_pixel_ratio_get(webView()), 1.2); + ASSERT_FLOAT_EQ(1.2, ewk_view_device_pixel_ratio_get(webView())); ASSERT_TRUE(ewk_view_device_pixel_ratio_set(webView(), 1)); - ASSERT_FLOAT_EQ(ewk_view_device_pixel_ratio_get(webView()), 1); + ASSERT_FLOAT_EQ(1, ewk_view_device_pixel_ratio_get(webView())); } TEST_F(EWK2UnitTestBase, ewk_view_html_string_load) { ewk_view_html_string_load(webView(), "<html><head><title>Foo</title></head><body>Bar</body></html>", 0, 0); ASSERT_TRUE(waitUntilTitleChangedTo("Foo")); - ASSERT_STREQ(ewk_view_title_get(webView()), "Foo"); + ASSERT_STREQ("Foo", ewk_view_title_get(webView())); ewk_view_html_string_load(webView(), "<html><head><title>Bar</title></head><body>Foo</body></html>", 0, 0); ASSERT_TRUE(waitUntilTitleChangedTo("Bar")); - ASSERT_STREQ(ewk_view_title_get(webView()), "Bar"); + ASSERT_STREQ("Bar", ewk_view_title_get(webView())); } static void serverCallbackNavigation(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) @@ -106,28 +106,28 @@ TEST_F(EWK2UnitTestBase, ewk_view_navigation) httpServer->run(serverCallbackNavigation); // Visit Page1 - loadUrlSync(httpServer->getURIForPath("/Page1").data()); - ASSERT_STREQ(ewk_view_title_get(webView()), "Page1"); + ASSERT_TRUE(loadUrlSync(httpServer->getURLForPath("/Page1").data())); + ASSERT_STREQ("Page1", ewk_view_title_get(webView())); ASSERT_FALSE(ewk_view_back_possible(webView())); ASSERT_FALSE(ewk_view_forward_possible(webView())); // Visit Page2 - loadUrlSync(httpServer->getURIForPath("/Page2").data()); - ASSERT_STREQ(ewk_view_title_get(webView()), "Page2"); + ASSERT_TRUE(loadUrlSync(httpServer->getURLForPath("/Page2").data())); + ASSERT_STREQ("Page2", ewk_view_title_get(webView())); ASSERT_TRUE(ewk_view_back_possible(webView())); ASSERT_FALSE(ewk_view_forward_possible(webView())); // Go back to Page1 ewk_view_back(webView()); ASSERT_TRUE(waitUntilTitleChangedTo("Page1")); - ASSERT_STREQ(ewk_view_title_get(webView()), "Page1"); + ASSERT_STREQ("Page1", ewk_view_title_get(webView())); ASSERT_FALSE(ewk_view_back_possible(webView())); ASSERT_TRUE(ewk_view_forward_possible(webView())); // Go forward to Page2 ewk_view_forward(webView()); ASSERT_TRUE(waitUntilTitleChangedTo("Page2")); - ASSERT_STREQ(ewk_view_title_get(webView()), "Page2"); + ASSERT_STREQ("Page2", ewk_view_title_get(webView())); ASSERT_TRUE(ewk_view_back_possible(webView())); ASSERT_FALSE(ewk_view_forward_possible(webView())); } @@ -136,7 +136,7 @@ TEST_F(EWK2UnitTestBase, ewk_view_setting_encoding_custom) { ASSERT_FALSE(ewk_view_setting_encoding_custom_get(webView())); ASSERT_TRUE(ewk_view_setting_encoding_custom_set(webView(), "UTF-8")); - ASSERT_STREQ(ewk_view_setting_encoding_custom_get(webView()), "UTF-8"); + ASSERT_STREQ("UTF-8", ewk_view_setting_encoding_custom_get(webView())); // Set the default charset. ASSERT_TRUE(ewk_view_setting_encoding_custom_set(webView(), 0)); ASSERT_FALSE(ewk_view_setting_encoding_custom_get(webView())); @@ -151,19 +151,19 @@ static void onFormAboutToBeSubmitted(void* userData, Evas_Object*, void* eventIn Eina_List* fieldNames = ewk_form_submission_request_field_names_get(request); ASSERT_TRUE(fieldNames); - ASSERT_EQ(eina_list_count(fieldNames), 3); + ASSERT_EQ(3, eina_list_count(fieldNames)); void* data; EINA_LIST_FREE(fieldNames, data) eina_stringshare_del(static_cast<char*>(data)); const char* value1 = ewk_form_submission_request_field_value_get(request, "text1"); - ASSERT_STREQ(value1, "value1"); + ASSERT_STREQ("value1", value1); eina_stringshare_del(value1); const char* value2 = ewk_form_submission_request_field_value_get(request, "text2"); - ASSERT_STREQ(value2, "value2"); + ASSERT_STREQ("value2", value2); eina_stringshare_del(value2); const char* password = ewk_form_submission_request_field_value_get(request, "password"); - ASSERT_STREQ(password, "secret"); + ASSERT_STREQ("secret", password); eina_stringshare_del(password); *handled = true; @@ -195,9 +195,9 @@ TEST_F(EWK2UnitTestBase, ewk_view_form_submission_request) static inline void checkBasicPopupMenuItem(Ewk_Popup_Menu_Item* item, const char* title, bool enabled) { - EXPECT_EQ(ewk_popup_menu_item_type_get(item), EWK_POPUP_MENU_ITEM); - EXPECT_STREQ(ewk_popup_menu_item_text_get(item), title); - EXPECT_EQ(ewk_popup_menu_item_enabled_get(item), enabled); + EXPECT_EQ(EWK_POPUP_MENU_ITEM, ewk_popup_menu_item_type_get(item)); + EXPECT_STREQ(title, ewk_popup_menu_item_text_get(item)); + EXPECT_EQ(enabled, ewk_popup_menu_item_enabled_get(item)); } static Eina_Bool selectItemAfterDelayed(void* data) @@ -208,25 +208,25 @@ static Eina_Bool selectItemAfterDelayed(void* data) static Eina_Bool showPopupMenu(Ewk_View_Smart_Data* smartData, Eina_Rectangle, Ewk_Text_Direction, double, Eina_List* list, int selectedIndex) { - EXPECT_EQ(selectedIndex, 2); + EXPECT_EQ(2, selectedIndex); Ewk_Popup_Menu_Item* item = static_cast<Ewk_Popup_Menu_Item*>(eina_list_nth(list, 0)); checkBasicPopupMenuItem(item, "first", true); - EXPECT_EQ(ewk_popup_menu_item_text_direction_get(item), EWK_TEXT_DIRECTION_LEFT_TO_RIGHT); - EXPECT_STREQ(ewk_popup_menu_item_tooltip_get(item), ""); - EXPECT_STREQ(ewk_popup_menu_item_accessibility_text_get(item), ""); + EXPECT_EQ(EWK_TEXT_DIRECTION_LEFT_TO_RIGHT, ewk_popup_menu_item_text_direction_get(item)); + EXPECT_STREQ("", ewk_popup_menu_item_tooltip_get(item)); + EXPECT_STREQ("", ewk_popup_menu_item_accessibility_text_get(item)); EXPECT_FALSE(ewk_popup_menu_item_is_label_get(item)); EXPECT_FALSE(ewk_popup_menu_item_selected_get(item)); item = static_cast<Ewk_Popup_Menu_Item*>(eina_list_nth(list, 1)); checkBasicPopupMenuItem(item, "second", false); - EXPECT_EQ(ewk_popup_menu_item_enabled_get(item), false); + EXPECT_FALSE(ewk_popup_menu_item_enabled_get(item)); item = static_cast<Ewk_Popup_Menu_Item*>(eina_list_nth(list, 2)); checkBasicPopupMenuItem(item, "third", true); - EXPECT_EQ(ewk_popup_menu_item_text_direction_get(item), EWK_TEXT_DIRECTION_RIGHT_TO_LEFT); - EXPECT_STREQ(ewk_popup_menu_item_tooltip_get(item), "tooltip"); - EXPECT_STREQ(ewk_popup_menu_item_accessibility_text_get(item), "aria"); + EXPECT_EQ(EWK_TEXT_DIRECTION_RIGHT_TO_LEFT, ewk_popup_menu_item_text_direction_get(item)); + EXPECT_STREQ("tooltip", ewk_popup_menu_item_tooltip_get(item)); + EXPECT_STREQ("aria", ewk_popup_menu_item_accessibility_text_get(item)); EXPECT_TRUE(ewk_popup_menu_item_selected_get(item)); item = static_cast<Ewk_Popup_Menu_Item*>(eina_list_nth(list, 3)); @@ -237,8 +237,8 @@ static Eina_Bool showPopupMenu(Ewk_View_Smart_Data* smartData, Eina_Rectangle, E checkBasicPopupMenuItem(item, " forth", true); item = static_cast<Ewk_Popup_Menu_Item*>(eina_list_nth(list, 5)); - EXPECT_EQ(ewk_popup_menu_item_type_get(item), EWK_POPUP_MENU_UNKNOWN); - EXPECT_STREQ(ewk_popup_menu_item_text_get(item), 0); + EXPECT_EQ(EWK_POPUP_MENU_UNKNOWN, ewk_popup_menu_item_type_get(item)); + EXPECT_STREQ(0, ewk_popup_menu_item_text_get(item)); ecore_timer_add(0, selectItemAfterDelayed, smartData->self); return true; @@ -310,18 +310,6 @@ static Eina_Bool fullScreenCallback(Ewk_View_Smart_Data* smartData) return false; } -static void checkFullScreenProperty(Evas_Object* webView, bool expectedState) -{ - if (environment->useX11Window()) { - Ewk_View_Smart_Data* smartData = static_cast<Ewk_View_Smart_Data*>(evas_object_smart_data_get(webView)); - Ecore_Evas* ecoreEvas = ecore_evas_ecore_evas_get(smartData->base.evas); - bool windowState = false; - while (((windowState = ecore_evas_fullscreen_get(ecoreEvas)) != expectedState)) - ecore_main_loop_iterate(); - ASSERT_TRUE(expectedState == windowState); - } -} - TEST_F(EWK2UnitTestBase, ewk_view_full_screen_enter) { const char fullscreenHTML[] = @@ -339,7 +327,6 @@ TEST_F(EWK2UnitTestBase, ewk_view_full_screen_enter) mouseClick(50, 50); ASSERT_TRUE(waitUntilTitleChangedTo("fullscreen entered")); ASSERT_TRUE(fullScreenCallbackCalled); - checkFullScreenProperty(webView(), true); } TEST_F(EWK2UnitTestBase, ewk_view_full_screen_exit) @@ -360,18 +347,17 @@ TEST_F(EWK2UnitTestBase, ewk_view_full_screen_exit) mouseClick(50, 50); ASSERT_TRUE(waitUntilTitleChangedTo("fullscreen exited")); ASSERT_TRUE(fullScreenCallbackCalled); - checkFullScreenProperty(webView(), false); } TEST_F(EWK2UnitTestBase, ewk_view_same_page_navigation) { - // Tests that same page navigation updates the page URI. + // Tests that same page navigation updates the page URL. String testUrl = environment->urlForResource("same_page_navigation.html").data(); - loadUrlSync(testUrl.utf8().data()); - ASSERT_STREQ(testUrl.utf8().data(), ewk_view_uri_get(webView())); + ASSERT_TRUE(loadUrlSync(testUrl.utf8().data())); + ASSERT_STREQ(testUrl.utf8().data(), ewk_view_url_get(webView())); mouseClick(50, 50); testUrl = testUrl + '#'; - ASSERT_TRUE(waitUntilURIChangedTo(testUrl.utf8().data())); + ASSERT_TRUE(waitUntilURLChangedTo(testUrl.utf8().data())); } TEST_F(EWK2UnitTestBase, ewk_view_title_changed) @@ -381,21 +367,21 @@ TEST_F(EWK2UnitTestBase, ewk_view_title_changed) "<body onload=\"document.title='Title after changed';\"></body>"; ewk_view_html_string_load(webView(), titleChangedHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo("Title after changed")); - EXPECT_STREQ(ewk_view_title_get(webView()), "Title after changed"); + EXPECT_STREQ("Title after changed", ewk_view_title_get(webView())); titleChangedHTML = "<!doctype html><head><title>Title before changed</title></head>" "<body onload=\"document.title='';\"></body>"; ewk_view_html_string_load(webView(), titleChangedHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo("")); - EXPECT_STREQ(ewk_view_title_get(webView()), ""); + EXPECT_STREQ("", ewk_view_title_get(webView())); titleChangedHTML = "<!doctype html><head><title>Title before changed</title></head>" "<body onload=\"document.title=null;\"></body>"; ewk_view_html_string_load(webView(), titleChangedHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo("")); - EXPECT_STREQ(ewk_view_title_get(webView()), ""); + EXPECT_STREQ("", ewk_view_title_get(webView())); } static struct { @@ -431,35 +417,35 @@ TEST_F(EWK2UnitTestBase, ewk_view_run_javascript_alert) alertCallbackData.called = false; ewk_view_html_string_load(webView(), alertHTML, 0, 0); EXPECT_TRUE(waitUntilLoadFinished()); - EXPECT_EQ(alertCallbackData.called, true); + EXPECT_TRUE(alertCallbackData.called); alertHTML = "<!doctype html><body onload=\"alert('');\"></body>"; alertCallbackData.expectedMessage = ""; alertCallbackData.called = false; ewk_view_html_string_load(webView(), alertHTML, 0, 0); EXPECT_TRUE(waitUntilLoadFinished()); - EXPECT_EQ(alertCallbackData.called, true); + EXPECT_TRUE(alertCallbackData.called); alertHTML = "<!doctype html><body onload=\"alert(null);\"></body>"; alertCallbackData.expectedMessage = "null"; alertCallbackData.called = false; ewk_view_html_string_load(webView(), alertHTML, 0, 0); EXPECT_TRUE(waitUntilLoadFinished()); - EXPECT_EQ(alertCallbackData.called, true); + EXPECT_TRUE(alertCallbackData.called); alertHTML = "<!doctype html><body onload=\"alert();\"></body>"; alertCallbackData.expectedMessage = "undefined"; alertCallbackData.called = false; ewk_view_html_string_load(webView(), alertHTML, 0, 0); EXPECT_TRUE(waitUntilLoadFinished()); - EXPECT_EQ(alertCallbackData.called, true); + EXPECT_TRUE(alertCallbackData.called); ewkViewClass()->run_javascript_alert = 0; alertCallbackData.called = false; ewk_view_html_string_load(webView(), alertHTML, 0, 0); EXPECT_TRUE(waitUntilLoadFinished()); - EXPECT_EQ(alertCallbackData.called, false); + EXPECT_FALSE(alertCallbackData.called); } static Eina_Bool checkConfirm(Ewk_View_Smart_Data*, const char* message) @@ -479,16 +465,16 @@ TEST_F(EWK2UnitTestBase, ewk_view_run_javascript_confirm) confirmCallbackData.called = false; ewk_view_html_string_load(webView(), confirmHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo("true")); - EXPECT_STREQ(ewk_view_title_get(webView()), "true"); - EXPECT_EQ(confirmCallbackData.called, true); + EXPECT_STREQ("true", ewk_view_title_get(webView())); + EXPECT_TRUE(confirmCallbackData.called); confirmCallbackData.expectedMessage = "Confirm message"; confirmCallbackData.result = false; confirmCallbackData.called = false; ewk_view_html_string_load(webView(), confirmHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo("false")); - EXPECT_STREQ(ewk_view_title_get(webView()), "false"); - EXPECT_EQ(confirmCallbackData.called, true); + EXPECT_STREQ("false", ewk_view_title_get(webView())); + EXPECT_TRUE(confirmCallbackData.called); confirmHTML = "<!doctype html><body onload=\"document.title = confirm('');\"></body>"; confirmCallbackData.expectedMessage = ""; @@ -496,8 +482,8 @@ TEST_F(EWK2UnitTestBase, ewk_view_run_javascript_confirm) confirmCallbackData.called = false; ewk_view_html_string_load(webView(), confirmHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo("true")); - EXPECT_STREQ(ewk_view_title_get(webView()), "true"); - EXPECT_EQ(confirmCallbackData.called, true); + EXPECT_STREQ("true", ewk_view_title_get(webView())); + EXPECT_TRUE(confirmCallbackData.called); confirmHTML = "<!doctype html><body onload=\"document.title = confirm(null);\"></body>"; confirmCallbackData.expectedMessage = "null"; @@ -505,8 +491,8 @@ TEST_F(EWK2UnitTestBase, ewk_view_run_javascript_confirm) confirmCallbackData.called = false; ewk_view_html_string_load(webView(), confirmHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo("true")); - EXPECT_STREQ(ewk_view_title_get(webView()), "true"); - EXPECT_EQ(confirmCallbackData.called, true); + EXPECT_STREQ("true", ewk_view_title_get(webView())); + EXPECT_TRUE(confirmCallbackData.called); confirmHTML = "<!doctype html><body onload=\"document.title = confirm();\"></body>"; confirmCallbackData.expectedMessage = "undefined"; @@ -514,16 +500,16 @@ TEST_F(EWK2UnitTestBase, ewk_view_run_javascript_confirm) confirmCallbackData.called = false; ewk_view_html_string_load(webView(), confirmHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo("true")); - EXPECT_STREQ(ewk_view_title_get(webView()), "true"); - EXPECT_EQ(confirmCallbackData.called, true); + EXPECT_STREQ("true", ewk_view_title_get(webView())); + EXPECT_TRUE(confirmCallbackData.called); ewkViewClass()->run_javascript_confirm = 0; confirmCallbackData.called = false; ewk_view_html_string_load(webView(), confirmHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo("false")); - EXPECT_STREQ(ewk_view_title_get(webView()), "false"); - EXPECT_EQ(confirmCallbackData.called, false); + EXPECT_STREQ("false", ewk_view_title_get(webView())); + EXPECT_FALSE(confirmCallbackData.called); } static const char* checkPrompt(Ewk_View_Smart_Data*, const char* message, const char* defaultValue) @@ -552,8 +538,8 @@ TEST_F(EWK2UnitTestBase, ewk_view_run_javascript_prompt) promptCallbackData.called = false; ewk_view_html_string_load(webView(), promptHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo(promptResult)); - EXPECT_STREQ(ewk_view_title_get(webView()), promptResult); - EXPECT_EQ(promptCallbackData.called, true); + EXPECT_STREQ(promptResult, ewk_view_title_get(webView())); + EXPECT_TRUE(promptCallbackData.called); promptHTML = "<!doctype html><body onload=\"document.title = prompt('Prompt message', '');\"></body>"; promptCallbackData.expectedMessage = promptMessage; @@ -562,8 +548,8 @@ TEST_F(EWK2UnitTestBase, ewk_view_run_javascript_prompt) promptCallbackData.called = false; ewk_view_html_string_load(webView(), promptHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo(promptResult)); - EXPECT_STREQ(ewk_view_title_get(webView()), promptResult); - EXPECT_EQ(promptCallbackData.called, true); + EXPECT_STREQ(promptResult, ewk_view_title_get(webView())); + EXPECT_TRUE(promptCallbackData.called); promptHTML = "<!doctype html><body onload=\"document.title = prompt('Prompt message');\"></body>"; promptCallbackData.expectedMessage = promptMessage; @@ -572,8 +558,8 @@ TEST_F(EWK2UnitTestBase, ewk_view_run_javascript_prompt) promptCallbackData.called = false; ewk_view_html_string_load(webView(), promptHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo(promptResult)); - EXPECT_STREQ(ewk_view_title_get(webView()), promptResult); - EXPECT_EQ(promptCallbackData.called, true); + EXPECT_STREQ(promptResult, ewk_view_title_get(webView())); + EXPECT_TRUE(promptCallbackData.called); promptHTML = "<!doctype html><body onload=\"document.title = prompt('');\"></body>"; promptCallbackData.expectedMessage = ""; @@ -582,8 +568,8 @@ TEST_F(EWK2UnitTestBase, ewk_view_run_javascript_prompt) promptCallbackData.called = false; ewk_view_html_string_load(webView(), promptHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo(promptResult)); - EXPECT_STREQ(ewk_view_title_get(webView()), promptResult); - EXPECT_EQ(promptCallbackData.called, true); + EXPECT_STREQ(promptResult, ewk_view_title_get(webView())); + EXPECT_TRUE(promptCallbackData.called); promptHTML = "<!doctype html><body onload=\"document.title = prompt();\"></body>"; promptCallbackData.expectedMessage = "undefined"; @@ -592,8 +578,8 @@ TEST_F(EWK2UnitTestBase, ewk_view_run_javascript_prompt) promptCallbackData.called = false; ewk_view_html_string_load(webView(), promptHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo(promptResult)); - EXPECT_STREQ(ewk_view_title_get(webView()), promptResult); - EXPECT_EQ(promptCallbackData.called, true); + EXPECT_STREQ(promptResult, ewk_view_title_get(webView())); + EXPECT_TRUE(promptCallbackData.called); promptHTML = "<html><head><title>Default title</title></head>" "<body onload=\"var promptResult = prompt('Prompt message');" @@ -605,8 +591,8 @@ TEST_F(EWK2UnitTestBase, ewk_view_run_javascript_prompt) promptCallbackData.called = false; ewk_view_html_string_load(webView(), promptHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo("")); - EXPECT_STREQ(ewk_view_title_get(webView()), ""); - EXPECT_EQ(promptCallbackData.called, true); + EXPECT_STREQ("", ewk_view_title_get(webView())); + EXPECT_TRUE(promptCallbackData.called); promptCallbackData.expectedMessage = promptMessage; promptCallbackData.expectedDefaultValue = ""; @@ -614,16 +600,16 @@ TEST_F(EWK2UnitTestBase, ewk_view_run_javascript_prompt) promptCallbackData.called = false; ewk_view_html_string_load(webView(), promptHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo("null")); - EXPECT_STREQ(ewk_view_title_get(webView()), "null"); - EXPECT_EQ(promptCallbackData.called, true); + EXPECT_STREQ("null", ewk_view_title_get(webView())); + EXPECT_TRUE(promptCallbackData.called); ewkViewClass()->run_javascript_prompt = 0; promptCallbackData.called = false; ewk_view_html_string_load(webView(), promptHTML, 0, 0); EXPECT_TRUE(waitUntilTitleChangedTo("null")); - EXPECT_STREQ(ewk_view_title_get(webView()), "null"); - EXPECT_EQ(promptCallbackData.called, false); + EXPECT_STREQ("null", ewk_view_title_get(webView())); + EXPECT_FALSE(promptCallbackData.called); } #if ENABLE(INPUT_TYPE_COLOR) @@ -665,18 +651,18 @@ static Eina_Bool showColorPicker(Ewk_View_Smart_Data* smartData, int r, int g, i if (isFirstRun) { // 2. Check initial value from html file. - EXPECT_EQ(r, initialRed); - EXPECT_EQ(g, initialGreen); - EXPECT_EQ(b, initialBlue); - EXPECT_EQ(a, initialAlpha); + EXPECT_EQ(initialRed, r); + EXPECT_EQ(initialGreen, g); + EXPECT_EQ(initialBlue, b); + EXPECT_EQ(initialAlpha, a); isFirstRun = false; } else { // 7. Input values should be same as changed color. - EXPECT_EQ(r, changedRed); - EXPECT_EQ(g, changedGreen); - EXPECT_EQ(b, changedBlue); - EXPECT_EQ(a, changedAlpha); + EXPECT_EQ(changedRed, r); + EXPECT_EQ(changedGreen, g); + EXPECT_EQ(changedBlue, b); + EXPECT_EQ(changedAlpha, a); evas_object_smart_callback_call(smartData->self, "input,type,color,request", 0); return true; @@ -744,7 +730,7 @@ TEST_F(EWK2UnitTestBase, ewk_view_color_picker_color_set) while (!handled) ecore_main_loop_iterate(); - // 8. Click button to remove input element during color picker is shown. + // 8. Click button to remove input element durlng color picker is shown. api->input_picker_color_dismiss = hideColorPickerByRemovingElement; mouseClick(80, 20); @@ -787,3 +773,168 @@ TEST_F(EWK2UnitTestBase, ewk_view_feed_touch_event) eina_list_free(points); } + +static void onTextFound(void* userData, Evas_Object*, void* eventInfo) +{ + int* result = static_cast<int*>(userData); + unsigned* matchCount = static_cast<unsigned*>(eventInfo); + + *result = *matchCount; +} + +TEST_F(EWK2UnitTestBase, ewk_view_text_find) +{ + const char textFindHTML[] = + "<!DOCTYPE html>" + "<body>" + "apple apple apple banana banana coconut" + "</body>"; + ewk_view_html_string_load(webView(), textFindHTML, 0, 0); + waitUntilLoadFinished(); + + int matchCount = -1; + evas_object_smart_callback_add(webView(), "text,found", onTextFound, &matchCount); + + ewk_view_text_find(webView(), "apple", EWK_FIND_OPTIONS_SHOW_OVERLAY, 100); + while (matchCount < 0) + ecore_main_loop_iterate(); + EXPECT_EQ(3, matchCount); + + matchCount = -1; + ewk_view_text_find(webView(), "mango", EWK_FIND_OPTIONS_SHOW_OVERLAY, 100); + while (matchCount < 0) + ecore_main_loop_iterate(); + EXPECT_EQ(0, matchCount); + + evas_object_smart_callback_del(webView(), "text,found", onTextFound); +} + +TEST_F(EWK2UnitTestBase, ewk_view_text_matches_count) +{ + const char textFindHTML[] = + "<!DOCTYPE html>" + "<body>" + "apple Apple apple apple banana bananaApple banana coconut" + "</body>"; + ewk_view_html_string_load(webView(), textFindHTML, 0, 0); + waitUntilLoadFinished(); + + int matchCount = -1; + evas_object_smart_callback_add(webView(), "text,found", onTextFound, &matchCount); + + ewk_view_text_matches_count(webView(), "apple", EWK_FIND_OPTIONS_NONE, 100); + while (matchCount < 0) + ecore_main_loop_iterate(); + EXPECT_EQ(3, matchCount); + + matchCount = -1; + ewk_view_text_matches_count(webView(), "apple", EWK_FIND_OPTIONS_CASE_INSENSITIVE, 100); + while (matchCount < 0) + ecore_main_loop_iterate(); + EXPECT_EQ(5, matchCount); + + matchCount = -1; + ewk_view_text_matches_count(webView(), "Apple", EWK_FIND_OPTIONS_AT_WORD_STARTS, 100); + while (matchCount < 0) + ecore_main_loop_iterate(); + EXPECT_EQ(1, matchCount); + + matchCount = -1; + ewk_view_text_matches_count(webView(), "Apple", EWK_FIND_OPTIONS_TREAT_MEDIAL_CAPITAL_AS_WORD_START, 100); + while (matchCount < 0) + ecore_main_loop_iterate(); + EXPECT_EQ(2, matchCount); + + matchCount = -1; + ewk_view_text_matches_count(webView(), "mango", EWK_FIND_OPTIONS_NONE, 100); + while (matchCount < 0) + ecore_main_loop_iterate(); + EXPECT_EQ(0, matchCount); + + // If we have more matches than allowed, -1 is returned as a matched count. + matchCount = -2; + ewk_view_text_matches_count(webView(), "apple", EWK_FIND_OPTIONS_NONE, 2); + while (matchCount < -1) + ecore_main_loop_iterate(); + EXPECT_EQ(-1, matchCount); + + evas_object_smart_callback_del(webView(), "text,found", onTextFound); +} + +TEST_F(EWK2UnitTestBase, ewk_view_touch_events_enabled) +{ + ASSERT_FALSE(ewk_view_touch_events_enabled_get(webView())); + + ASSERT_TRUE(ewk_view_touch_events_enabled_set(webView(), true)); + ASSERT_TRUE(ewk_view_touch_events_enabled_get(webView())); + + ASSERT_TRUE(ewk_view_touch_events_enabled_set(webView(), 2)); + ASSERT_TRUE(ewk_view_touch_events_enabled_get(webView())); + + const char* touchHTML = + "<!doctype html><body><div style=\"width:100px; height:100px;\" " + "ontouchstart=\"document.title='touchstarted' + event.touches.length;\" " + "ontouchmove=\"document.title='touchmoved' + event.touches.length;\" " + "ontouchend=\"document.title='touchended' + event.touches.length;\">" + "</div></body>"; + + ewk_view_html_string_load(webView(), touchHTML, "file:///", 0); + ASSERT_TRUE(waitUntilLoadFinished()); + + mouseDown(10, 10); + ASSERT_TRUE(waitUntilTitleChangedTo("touchstarted1")); + + multiDown(1, 30, 30); + ASSERT_TRUE(waitUntilTitleChangedTo("touchstarted2")); + + multiMove(1, 40, 40); + ASSERT_TRUE(waitUntilTitleChangedTo("touchmoved2")); + + multiUp(1, 40, 40); + ASSERT_TRUE(waitUntilTitleChangedTo("touchended1")); + + mouseMove(20, 20); + ASSERT_TRUE(waitUntilTitleChangedTo("touchmoved1")); + + mouseUp(20, 20); + ASSERT_TRUE(waitUntilTitleChangedTo("touchended0")); + + ASSERT_TRUE(ewk_view_touch_events_enabled_set(webView(), false)); + ASSERT_FALSE(ewk_view_touch_events_enabled_get(webView())); +} + +Eina_Bool windowMoveResizeTimedOut(void* data) +{ + *static_cast<bool*>(data) = true; +} + +TEST_F(EWK2UnitTestBase, window_move_resize) +{ + int x, y, width, height; + Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_object_evas_get(webView())); + ecore_evas_geometry_get(ee, 0, 0, &width, &height); + + EXPECT_EQ(800, width); + EXPECT_EQ(600, height); + + ewk_view_url_set(webView(), environment->urlForResource("window_move_resize.html").data()); + ASSERT_TRUE(waitUntilTitleChangedTo("Moved and resized")); + + // Check that the window has been moved and resized. + ecore_evas_request_geometry_get(ee, &x, &y, &width, &height); + EXPECT_EQ(150, x); + EXPECT_EQ(200, y); + EXPECT_EQ(200, width); + EXPECT_EQ(100, height); +} + +TEST_F(EWK2UnitTestBase, ewk_view_inspector) +{ +#if ENABLE(INSPECTOR) + ASSERT_TRUE(ewk_view_inspector_show(webView())); + ASSERT_TRUE(ewk_view_inspector_close(webView())); +#else + ASSERT_FALSE(ewk_view_inspector_show(webView())); + ASSERT_FALSE(ewk_view_inspector_close(webView())); +#endif +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp index 6e72496ef..79c1c3e2a 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadClient.cpp @@ -34,13 +34,13 @@ using namespace WebKit; static void didStart(WKContextRef, WKDownloadRef wkDownload, const void* clientInfo) { - GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(wkDownload); + GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload)); webkitWebContextDownloadStarted(WEBKIT_WEB_CONTEXT(clientInfo), download.get()); } static void didReceiveResponse(WKContextRef, WKDownloadRef wkDownload, WKURLResponseRef wkResponse, const void* clientInfo) { - GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(wkDownload); + GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload)); if (webkitDownloadIsCancelled(download.get())) return; @@ -50,13 +50,13 @@ static void didReceiveResponse(WKContextRef, WKDownloadRef wkDownload, WKURLResp static void didReceiveData(WKContextRef, WKDownloadRef wkDownload, uint64_t length, const void* clientInfo) { - GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(wkDownload); + GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload)); webkitDownloadNotifyProgress(download.get(), length); } static WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownloadRef wkDownload, WKStringRef filename, bool* allowOverwrite, const void* clientInfo) { - GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(wkDownload); + GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload)); CString destinationURI = webkitDownloadDecideDestinationWithSuggestedFilename(download.get(), toImpl(filename)->string().utf8()); return WKStringCreateWithUTF8CString(destinationURI.data()); @@ -64,33 +64,33 @@ static WKStringRef decideDestinationWithSuggestedFilename(WKContextRef, WKDownlo static void didCreateDestination(WKContextRef, WKDownloadRef wkDownload, WKStringRef path, const void* clientInfo) { - GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(wkDownload); + GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload)); webkitDownloadDestinationCreated(download.get(), toImpl(path)->string().utf8()); } static void didFail(WKContextRef, WKDownloadRef wkDownload, WKErrorRef error, const void *clientInfo) { - GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(wkDownload); + GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload)); if (webkitDownloadIsCancelled(download.get())) { // Cancellation takes precedence over other errors. webkitDownloadCancelled(download.get()); } else webkitDownloadFailed(download.get(), toImpl(error)->platformError()); - webkitWebContextRemoveDownload(wkDownload); + webkitWebContextRemoveDownload(toImpl(wkDownload)); } static void didCancel(WKContextRef, WKDownloadRef wkDownload, const void *clientInfo) { - GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(wkDownload); + GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload)); webkitDownloadCancelled(download.get()); - webkitWebContextRemoveDownload(wkDownload); + webkitWebContextRemoveDownload(toImpl(wkDownload)); } static void didFinish(WKContextRef wkContext, WKDownloadRef wkDownload, const void *clientInfo) { - GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(wkDownload); + GRefPtr<WebKitDownload> download = webkitWebContextGetOrCreateDownload(toImpl(wkDownload)); webkitDownloadFinished(download.get()); - webkitWebContextRemoveDownload(wkDownload); + webkitWebContextRemoveDownload(toImpl(wkDownload)); } void attachDownloadClientToContext(WebKitWebContext* webContext) @@ -110,6 +110,6 @@ void attachDownloadClientToContext(WebKitWebContext* webContext) didCancel, 0, // processDidCrash }; - WKContextSetDownloadClient(webkitWebContextGetWKContext(webContext), &wkDownloadClient); + WKContextSetDownloadClient(toAPI(webkitWebContextGetContext(webContext)), &wkDownloadClient); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.cpp new file mode 100644 index 000000000..cb016ab09 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.cpp @@ -0,0 +1,391 @@ +/* + * Copyright (C) 2012 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2,1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "WebKitFaviconDatabase.h" + +#include "WebKitFaviconDatabasePrivate.h" +#include "WebKitPrivate.h" +#include <WebCore/FileSystem.h> +#include <WebCore/Image.h> +#include <WebCore/IntSize.h> +#include <WebCore/RefPtrCairo.h> +#include <glib/gi18n-lib.h> +#include <wtf/MainThread.h> +#include <wtf/gobject/GOwnPtr.h> +#include <wtf/gobject/GRefPtr.h> +#include <wtf/text/CString.h> + +using namespace WebKit; + +enum { + ICON_READY, + + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0, }; + +typedef Vector<GRefPtr<GSimpleAsyncResult> > PendingIconRequestVector; +typedef HashMap<String, PendingIconRequestVector*> PendingIconRequestMap; + +struct _WebKitFaviconDatabasePrivate { + RefPtr<WebIconDatabase> iconDatabase; + PendingIconRequestMap pendingIconRequests; +}; + +G_DEFINE_TYPE(WebKitFaviconDatabase, webkit_favicon_database, G_TYPE_OBJECT) + +static void webkit_favicon_database_init(WebKitFaviconDatabase* manager) +{ + WebKitFaviconDatabasePrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(manager, WEBKIT_TYPE_FAVICON_DATABASE, WebKitFaviconDatabasePrivate); + manager->priv = priv; + new (priv) WebKitFaviconDatabasePrivate(); +} + +static void webkitFaviconDatabaseDispose(GObject* object) +{ + WebKitFaviconDatabase* database = WEBKIT_FAVICON_DATABASE(object); + + WebKitFaviconDatabasePrivate* priv = database->priv; + if (priv->iconDatabase->isOpen()) + priv->iconDatabase->close(); + + G_OBJECT_CLASS(webkit_favicon_database_parent_class)->dispose(object); +} + +static void webkitFaviconDatabaseFinalize(GObject* object) +{ + WebKitFaviconDatabase* database = WEBKIT_FAVICON_DATABASE(object); + database->priv->~WebKitFaviconDatabasePrivate(); + G_OBJECT_CLASS(webkit_favicon_database_parent_class)->finalize(object); +} + +static void webkit_favicon_database_class_init(WebKitFaviconDatabaseClass* faviconDatabaseClass) +{ + GObjectClass* gObjectClass = G_OBJECT_CLASS(faviconDatabaseClass); + gObjectClass->dispose = webkitFaviconDatabaseDispose; + gObjectClass->finalize = webkitFaviconDatabaseFinalize; + + /** + * WebKitFaviconDatabase::favicon-ready: + * @database: the object on which the signal is emitted + * @page_uri: the URI of the Web page containing the icon. + * + * This signal gets emitted when the favicon of @page_uri is + * ready. This means that the favicon's data is ready to be used + * by the application, either because it has been loaded from the + * network, if it's the first time it gets retrieved, or because + * it has been already imported from the icon database. + */ + signals[ICON_READY] = + g_signal_new("favicon-ready", + G_TYPE_FROM_CLASS(faviconDatabaseClass), + G_SIGNAL_RUN_LAST, + 0, 0, 0, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, + G_TYPE_STRING); + + g_type_class_add_private(faviconDatabaseClass, sizeof(WebKitFaviconDatabasePrivate)); +} + +struct GetFaviconSurfaceAsyncData { + GRefPtr<WebKitFaviconDatabase> faviconDatabase; + String pageURL; + RefPtr<cairo_surface_t> icon; + GOwnPtr<GError> error; + GRefPtr<GCancellable> cancellable; +}; +WEBKIT_DEFINE_ASYNC_DATA_STRUCT(GetFaviconSurfaceAsyncData) + +static cairo_surface_t* getIconSurfaceSynchronously(WebKitFaviconDatabase* database, const String& pageURL, GError** error) +{ + ASSERT(isMainThread()); + + database->priv->iconDatabase->retainIconForPageURL(pageURL); + + // The exact size we pass is irrelevant to the iconDatabase code. + // We must pass something greater than 0x0 to get an icon. + WebCore::Image* iconImage = database->priv->iconDatabase->imageForPageURL(pageURL, WebCore::IntSize(1, 1)); + if (!iconImage) { + g_set_error(error, WEBKIT_FAVICON_DATABASE_ERROR, WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_UNKNOWN, _("Unknown favicon for page %s"), pageURL.utf8().data()); + database->priv->iconDatabase->releaseIconForPageURL(pageURL); + return 0; + } + + WebCore::NativeImagePtr icon = iconImage->nativeImageForCurrentFrame(); + if (!icon) { + g_set_error(error, WEBKIT_FAVICON_DATABASE_ERROR, WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_NOT_FOUND, _("Page %s does not have a favicon"), pageURL.utf8().data()); + database->priv->iconDatabase->releaseIconForPageURL(pageURL); + return 0; + } + + return icon->surface(); +} + +static void deletePendingIconRequests(WebKitFaviconDatabase* database, PendingIconRequestVector* requests, const String& pageURL) +{ + database->priv->pendingIconRequests.remove(pageURL); + delete requests; +} + +static void processPendingIconsForPageURL(WebKitFaviconDatabase* database, const String& pageURL) +{ + PendingIconRequestVector* pendingIconRequests = database->priv->pendingIconRequests.get(pageURL); + if (!pendingIconRequests) + return; + + GOwnPtr<GError> error; + RefPtr<cairo_surface_t> icon = getIconSurfaceSynchronously(database, pageURL, &error.outPtr()); + + for (size_t i = 0; i < pendingIconRequests->size(); ++i) { + GSimpleAsyncResult* result = pendingIconRequests->at(i).get(); + GetFaviconSurfaceAsyncData* data = static_cast<GetFaviconSurfaceAsyncData*>(g_simple_async_result_get_op_res_gpointer(result)); + if (!g_cancellable_is_cancelled(data->cancellable.get())) { + if (error) + g_propagate_error(&data->error.outPtr(), error.release()); + else + data->icon = icon; + } + + g_simple_async_result_complete(result); + } + deletePendingIconRequests(database, pendingIconRequests, pageURL); +} + +static void iconDataReadyForPageURLCallback(WKIconDatabaseRef wkIconDatabase, WKURLRef wkPageURL, const void* clientInfo) +{ + ASSERT(isMainThread()); + + WebKitFaviconDatabase* database = WEBKIT_FAVICON_DATABASE(clientInfo); + String pageURL = toImpl(wkPageURL)->string(); + + processPendingIconsForPageURL(database, pageURL); + g_signal_emit(database, signals[ICON_READY], 0, pageURL.utf8().data()); +} + +WebKitFaviconDatabase* webkitFaviconDatabaseCreate(WebIconDatabase* iconDatabase) +{ + WebKitFaviconDatabase* faviconDatabase = WEBKIT_FAVICON_DATABASE(g_object_new(WEBKIT_TYPE_FAVICON_DATABASE, NULL)); + faviconDatabase->priv->iconDatabase = iconDatabase; + + WKIconDatabaseClient wkIconDatabaseClient = { + kWKIconDatabaseClientCurrentVersion, + faviconDatabase, // clientInfo + 0, // didChangeIconForPageURLCallback + 0, // didRemoveAllIconsCallback + iconDataReadyForPageURLCallback, + }; + WKIconDatabaseSetIconDatabaseClient(toAPI(iconDatabase), &wkIconDatabaseClient); + return faviconDatabase; +} + +cairo_surface_t* webkitFaviconDatabaseGetFavicon(WebKitFaviconDatabase* database, const CString& pageURL) +{ + ASSERT(WEBKIT_IS_FAVICON_DATABASE(database)); + ASSERT(!pageURL.isNull()); + + cairo_surface_t* iconSurface = getIconSurfaceSynchronously(database, String::fromUTF8(pageURL.data()), 0); + if (!iconSurface) + return 0; + + return cairo_surface_reference(iconSurface); +} + +static PendingIconRequestVector* getOrCreatePendingIconRequests(WebKitFaviconDatabase* database, const String& pageURL) +{ + PendingIconRequestVector* icons = database->priv->pendingIconRequests.get(pageURL); + if (!icons) { + icons = new PendingIconRequestVector; + database->priv->pendingIconRequests.set(pageURL, icons); + } + + return icons; +} + +static void setErrorForAsyncResult(GSimpleAsyncResult* result, WebKitFaviconDatabaseError error, const String& pageURL = String()) +{ + ASSERT(result); + + switch (error) { + case WEBKIT_FAVICON_DATABASE_ERROR_NOT_INITIALIZED: + g_simple_async_result_set_error(result, WEBKIT_FAVICON_DATABASE_ERROR, error, _("Favicons database not initialized yet")); + break; + + case WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_NOT_FOUND: + g_simple_async_result_set_error(result, WEBKIT_FAVICON_DATABASE_ERROR, error, _("Page %s does not have a favicon"), pageURL.utf8().data()); + break; + + case WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_UNKNOWN: + g_simple_async_result_set_error(result, WEBKIT_FAVICON_DATABASE_ERROR, error, _("Unknown favicon for page %s"), pageURL.utf8().data()); + break; + + default: + ASSERT_NOT_REACHED(); + } +} + +GQuark webkit_favicon_database_error_quark(void) +{ + return g_quark_from_static_string("WebKitFaviconDatabaseError"); +} + +/** + * webkit_favicon_database_get_favicon: + * @database: a #WebKitFaviconDatabase + * @page_uri: URI of the page for which we want to retrieve the favicon + * @cancellable: (allow-none): A #GCancellable or %NULL. + * @callback: (scope async): A #GAsyncReadyCallback to call when the request is + * satisfied or %NULL if you don't care about the result. + * @user_data: (closure): The data to pass to @callback. + * + * Asynchronously obtains a #cairo_surface_t of the favicon for the + * given page URI. It returns the cached icon if it's in the database + * asynchronously waiting for the icon to be read from the database. + * + * This is an asynchronous method. When the operation is finished, callback will + * be invoked. You can then call webkit_favicon_database_get_favicon_finish() + * to get the result of the operation. + */ +void webkit_favicon_database_get_favicon(WebKitFaviconDatabase* database, const gchar* pageURI, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData) +{ + g_return_if_fail(WEBKIT_IS_FAVICON_DATABASE(database)); + g_return_if_fail(pageURI); + + GRefPtr<GSimpleAsyncResult> result = adoptGRef(g_simple_async_result_new(G_OBJECT(database), callback, userData, reinterpret_cast<gpointer>(webkit_favicon_database_get_favicon))); + g_simple_async_result_set_check_cancellable(result.get(), cancellable); + + GetFaviconSurfaceAsyncData* data = createGetFaviconSurfaceAsyncData(); + g_simple_async_result_set_op_res_gpointer(result.get(), data, reinterpret_cast<GDestroyNotify>(destroyGetFaviconSurfaceAsyncData)); + data->faviconDatabase = database; + data->pageURL = String::fromUTF8(pageURI); + data->cancellable = cancellable; + + WebKitFaviconDatabasePrivate* priv = database->priv; + WebIconDatabase* iconDatabaseImpl = priv->iconDatabase.get(); + if (!iconDatabaseImpl->isOpen()) { + setErrorForAsyncResult(result.get(), WEBKIT_FAVICON_DATABASE_ERROR_NOT_INITIALIZED); + g_simple_async_result_complete_in_idle(result.get()); + return; + } + + if (data->pageURL.isEmpty() || data->pageURL.startsWith("about:")) { + setErrorForAsyncResult(result.get(), WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_NOT_FOUND, data->pageURL); + g_simple_async_result_complete_in_idle(result.get()); + return; + } + + // We ask for the icon directly. If we don't get the icon data now, + // we'll be notified later (even if the database is still importing icons). + GOwnPtr<GError> error; + data->icon = getIconSurfaceSynchronously(database, data->pageURL, &error.outPtr()); + if (data->icon) { + g_simple_async_result_complete_in_idle(result.get()); + return; + } + + if (g_error_matches(error.get(), WEBKIT_FAVICON_DATABASE_ERROR, WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_NOT_FOUND)) { + g_simple_async_result_take_error(result.get(), error.release()); + g_simple_async_result_complete_in_idle(result.get()); + return; + } + + // If there's not a valid icon, but there's an iconURL registered, + // or it's still not registered but the import process hasn't + // finished yet, we need to wait for iconDataReadyForPage to be + // called before making and informed decision. + String iconURLForPageURL; + iconDatabaseImpl->synchronousIconURLForPageURL(data->pageURL, iconURLForPageURL); + if (!iconURLForPageURL.isEmpty() || !iconDatabaseImpl->isUrlImportCompleted()) { + PendingIconRequestVector* icons = getOrCreatePendingIconRequests(database, data->pageURL); + ASSERT(icons); + icons->append(result); + return; + } + + setErrorForAsyncResult(result.get(), WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_UNKNOWN, data->pageURL); + g_simple_async_result_complete_in_idle(result.get()); +} + +/** + * webkit_favicon_database_get_favicon_finish: + * @database: a #WebKitFaviconDatabase + * @result: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to webkit_favicon_database_get_favicon() + * @error: (allow-none): Return location for error or %NULL. + * + * Finishes an operation started with webkit_favicon_database_get_favicon(). + * + * Returns: (transfer full): a new reference to a #cairo_surface_t, or + * %NULL in case of error. + */ +cairo_surface_t* webkit_favicon_database_get_favicon_finish(WebKitFaviconDatabase* database, GAsyncResult* result, GError** error) +{ + GSimpleAsyncResult* simpleResult = G_SIMPLE_ASYNC_RESULT(result); + g_warn_if_fail(g_simple_async_result_get_source_tag(simpleResult) == webkit_favicon_database_get_favicon); + + if (g_simple_async_result_propagate_error(simpleResult, error)) + return 0; + + GetFaviconSurfaceAsyncData* data = static_cast<GetFaviconSurfaceAsyncData*>(g_simple_async_result_get_op_res_gpointer(simpleResult)); + ASSERT(data); + if (data->error) { + g_propagate_error(error, data->error.release()); + return 0; + } + + return cairo_surface_reference(data->icon.get()); +} + +/** + * webkit_favicon_database_get_favicon_uri: + * @database: a #WebKitFaviconDatabase + * @page_uri: URI of the page containing the icon + * + * Obtains the URI of the favicon for the given @page_uri. + * + * Returns: a newly allocated URI for the favicon, or %NULL if the + * database doesn't have a favicon for @page_uri. + */ +gchar* webkit_favicon_database_get_favicon_uri(WebKitFaviconDatabase* database, const gchar* pageURL) +{ + g_return_val_if_fail(WEBKIT_IS_FAVICON_DATABASE(database), 0); + g_return_val_if_fail(pageURL, 0); + ASSERT(isMainThread()); + + String iconURLForPageURL; + database->priv->iconDatabase->synchronousIconURLForPageURL(String::fromUTF8(pageURL), iconURLForPageURL); + if (iconURLForPageURL.isEmpty()) + return 0; + + return g_strdup(iconURLForPageURL.utf8().data()); +} + +/** + * webkit_favicon_database_clear: + * @database: a #WebKitFaviconDatabase + * + * Clears all icons from the database. + */ +void webkit_favicon_database_clear(WebKitFaviconDatabase* database) +{ + g_return_if_fail(WEBKIT_IS_FAVICON_DATABASE(database)); + + database->priv->iconDatabase->removeAllIcons(); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.h b/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.h new file mode 100644 index 000000000..811a8e6bb --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabase.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2012 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2,1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) +#error "Only <webkit2/webkit2.h> can be included directly." +#endif + +#ifndef WebKitFaviconDatabase_h +#define WebKitFaviconDatabase_h + +#include <cairo.h> +#include <gio/gio.h> +#include <glib-object.h> +#include <webkit2/WebKitDefines.h> + +G_BEGIN_DECLS + +#define WEBKIT_TYPE_FAVICON_DATABASE (webkit_favicon_database_get_type()) +#define WEBKIT_FAVICON_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_FAVICON_DATABASE, WebKitFaviconDatabase)) +#define WEBKIT_IS_FAVICON_DATABASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_FAVICON_DATABASE)) +#define WEBKIT_FAVICON_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_FAVICON_DATABASE, WebKitFaviconDatabaseClass)) +#define WEBKIT_IS_FAVICON_DATABASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_FAVICON_DATABASE)) +#define WEBKIT_FAVICON_DATABASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_FAVICON_DATABASE, WebKitFaviconDatabaseClass)) +#define WEBKIT_FAVICON_DATABASE_ERROR (webkit_favicon_database_error_quark()) + +typedef struct _WebKitFaviconDatabase WebKitFaviconDatabase; +typedef struct _WebKitFaviconDatabaseClass WebKitFaviconDatabaseClass; +typedef struct _WebKitFaviconDatabasePrivate WebKitFaviconDatabasePrivate; + +struct _WebKitFaviconDatabase { + GObject parent; + + WebKitFaviconDatabasePrivate *priv; +}; + +struct _WebKitFaviconDatabaseClass { + GObjectClass parent_class; +}; + +/** + * WebKitFaviconDatabaseError: + * @WEBKIT_FAVICON_DATABASE_ERROR_NOT_INITIALIZED: The #WebKitFaviconDatabase has not been initialized yet + * @WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_NOT_FOUND: There is not an icon available for the requested URL + * @WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_UNKNOWN: There might be an icon for the requested URL, but its data is unknown at the moment + * + * Enum values used to denote the various errors related to the #WebKitFaviconDatabase. + **/ +typedef enum { + WEBKIT_FAVICON_DATABASE_ERROR_NOT_INITIALIZED, + WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_NOT_FOUND, + WEBKIT_FAVICON_DATABASE_ERROR_FAVICON_UNKNOWN +} WebKitFaviconDatabaseError; + +WEBKIT_API GQuark +webkit_favicon_database_error_quark (void); + +WEBKIT_API GType +webkit_favicon_database_get_type (void); + +WEBKIT_API void +webkit_favicon_database_get_favicon (WebKitFaviconDatabase *database, + const gchar *page_uri, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +WEBKIT_API cairo_surface_t * +webkit_favicon_database_get_favicon_finish (WebKitFaviconDatabase *database, + GAsyncResult *result, + GError **error); +WEBKIT_API gchar * +webkit_favicon_database_get_favicon_uri (WebKitFaviconDatabase *database, + const gchar *page_uri); +WEBKIT_API void +webkit_favicon_database_clear (WebKitFaviconDatabase *database); + +G_END_DECLS + +#endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabasePrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabasePrivate.h new file mode 100644 index 000000000..6c50949fb --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitFaviconDatabasePrivate.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2012 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef WebKitFaviconDatabasePrivate_h +#define WebKitFaviconDatabasePrivate_h + +#include "WebIconDatabase.h" +#include "WebKitFaviconDatabase.h" +#include <wtf/text/CString.h> + +using namespace WebKit; + +WebKitFaviconDatabase* webkitFaviconDatabaseCreate(WebIconDatabase*); +cairo_surface_t* webkitFaviconDatabaseGetFavicon(WebKitFaviconDatabase*, const CString&); + +#endif // WebKitFaviconDatabasePrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResult.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResult.cpp index 84ad04d03..2a1b8d5a3 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResult.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResult.cpp @@ -21,15 +21,16 @@ #include "WebKitJavascriptResult.h" #include "WebKitJavascriptResultPrivate.h" +#include "WebSerializedScriptValue.h" #include <wtf/gobject/GRefPtr.h> struct _WebKitJavascriptResult { - _WebKitJavascriptResult(WebKitWebView* view, WKSerializedScriptValueRef wkSerializedScriptValue) + _WebKitJavascriptResult(WebKitWebView* view, WebSerializedScriptValue* serializedScriptValue) : webView(view) , referenceCount(1) - { - value = WKSerializedScriptValueDeserialize(wkSerializedScriptValue, webkit_web_view_get_javascript_global_context(view), 0); - } + { + value = serializedScriptValue->deserialize(webkit_web_view_get_javascript_global_context(view), 0); + } GRefPtr<WebKitWebView> webView; JSValueRef value; @@ -39,10 +40,10 @@ struct _WebKitJavascriptResult { G_DEFINE_BOXED_TYPE(WebKitJavascriptResult, webkit_javascript_result, webkit_javascript_result_ref, webkit_javascript_result_unref) -WebKitJavascriptResult* webkitJavascriptResultCreate(WebKitWebView* webView, WKSerializedScriptValueRef wkSerializedScriptValue) +WebKitJavascriptResult* webkitJavascriptResultCreate(WebKitWebView* webView, WebSerializedScriptValue* serializedScriptValue) { WebKitJavascriptResult* result = g_slice_new(WebKitJavascriptResult); - new (result) WebKitJavascriptResult(webView, wkSerializedScriptValue); + new (result) WebKitJavascriptResult(webView, serializedScriptValue); return result; } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResultPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResultPrivate.h index 840ead058..ac7578857 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResultPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResultPrivate.h @@ -24,6 +24,8 @@ #include "WebKitPrivate.h" #include "WebKitWebView.h" -WebKitJavascriptResult* webkitJavascriptResultCreate(WebKitWebView*, WKSerializedScriptValueRef); +using namespace WebKit; + +WebKitJavascriptResult* webkitJavascriptResultCreate(WebKitWebView*, WebSerializedScriptValue*); #endif // WebKitJavascriptResultPrivate_h diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitLoaderClient.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitLoaderClient.cpp index 6c3bf920a..457c40141 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitLoaderClient.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitLoaderClient.cpp @@ -152,6 +152,7 @@ void attachLoaderClientToView(WebKitWebView* webView) 0, // pluginDidFail 0, // didReceiveIntentForFrame 0, // registerIntentServiceForFrame + 0, // didLayout }; WKPageRef wkPage = toAPI(webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView))); WKPageSetPageLoaderClient(wkPage, &wkLoaderClient); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h index 8fede827f..9ceafecb6 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h @@ -34,6 +34,7 @@ #include <WebKit2/WKGeolocationManager.h> #include <WebKit2/WKGeolocationPermissionRequest.h> #include <WebKit2/WKGeolocationPosition.h> +#include <WebKit2/WKIconDatabase.h> #include <WebKit2/WKInspector.h> #include <WebKit2/WKInspectorClientGtk.h> #include <WebKit2/WKRetainPtr.h> diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitRequestManagerClient.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitRequestManagerClient.cpp index 8ea09f200..babafe651 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitRequestManagerClient.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitRequestManagerClient.cpp @@ -26,10 +26,10 @@ using namespace WebKit; -static void didReceiveURIRequest(WKSoupRequestManagerRef soupRequestManagerRef, WKURLRef urlRef, uint64_t requestID, const void* clientInfo) +static void didReceiveURIRequest(WKSoupRequestManagerRef soupRequestManagerRef, WKURLRef urlRef, WKPageRef initiatingPageRef, uint64_t requestID, const void* clientInfo) { WebKitWebContext* webContext = WEBKIT_WEB_CONTEXT(clientInfo); - GRefPtr<WebKitURISchemeRequest> request = adoptGRef(webkitURISchemeRequestCreate(webContext, soupRequestManagerRef, urlRef, requestID)); + GRefPtr<WebKitURISchemeRequest> request = adoptGRef(webkitURISchemeRequestCreate(webContext, soupRequestManagerRef, urlRef, initiatingPageRef, requestID)); webkitWebContextReceivedURIRequest(webContext, request.get()); } @@ -46,6 +46,6 @@ void attachRequestManagerClientToContext(WebKitWebContext* webContext) didReceiveURIRequest, didFailToLoadURIRequest }; - WKSoupRequestManagerSetClient(webkitWebContextGetRequestManager(webContext), &wkRequestManagerClient); + WKSoupRequestManagerSetClient(toAPI(webkitWebContextGetRequestManager(webContext)), &wkRequestManagerClient); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitSecurityManager.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitSecurityManager.cpp index 53b46f875..d170fcf3f 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitSecurityManager.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitSecurityManager.cpp @@ -74,7 +74,7 @@ WebKitSecurityManager* webkitSecurityManagerCreate(WebKitWebContext* webContext) static void registerSecurityPolicyForURIScheme(WebKitSecurityManager* manager, const char* scheme, SecurityPolicy policy) { String urlScheme = String::fromUTF8(scheme); - WebContext* webContext = toImpl(webkitWebContextGetWKContext(manager->priv->webContext)); + WebContext* webContext = webkitWebContextGetContext(manager->priv->webContext); // We keep the WebCore::SchemeRegistry of the UI process in sync with the // web process one, so that we can return the SecurityPolicy for diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp index c0a64162a..17d4c881b 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp @@ -34,6 +34,7 @@ #include "WebKitPrivate.h" #include "WebKitSettingsPrivate.h" #include "WebPageProxy.h" +#include "WebPreferences.h" #include <WebCore/UserAgentGtk.h> #include <glib/gi18n-lib.h> #include <wtf/text/CString.h> @@ -117,7 +118,8 @@ enum { PROP_DRAW_COMPOSITING_INDICATORS, PROP_ENABLE_SITE_SPECIFIC_QUIRKS, PROP_ENABLE_PAGE_CACHE, - PROP_USER_AGENT + PROP_USER_AGENT, + PROP_ENABLE_SMOOTH_SCROLLING }; static void webKitSettingsSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec) @@ -251,6 +253,9 @@ static void webKitSettingsSetProperty(GObject* object, guint propId, const GValu case PROP_USER_AGENT: webkit_settings_set_user_agent(settings, g_value_get_string(value)); break; + case PROP_ENABLE_SMOOTH_SCROLLING: + webkit_settings_set_enable_smooth_scrolling(settings, g_value_get_boolean(value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); break; @@ -388,6 +393,9 @@ static void webKitSettingsGetProperty(GObject* object, guint propId, GValue* val case PROP_USER_AGENT: g_value_set_string(value, webkit_settings_get_user_agent(settings)); break; + case PROP_ENABLE_SMOOTH_SCROLLING: + g_value_set_boolean(value, webkit_settings_get_enable_smooth_scrolling(settings)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); break; @@ -1039,6 +1047,19 @@ static void webkit_settings_class_init(WebKitSettingsClass* klass) 0, // A null string forces the standard user agent. readWriteConstructParamFlags)); + /** + * WebKitSettings:enable-smooth-scrolling: + * + * Enable or disable smooth scrolling. + */ + g_object_class_install_property(gObjectClass, + PROP_ENABLE_SMOOTH_SCROLLING, + g_param_spec_boolean("enable-smooth-scrolling", + _("Enable smooth scrolling"), + _("Whether to enable smooth scrolling"), + FALSE, + readWriteConstructParamFlags)); + g_type_class_add_private(klass, sizeof(WebKitSettingsPrivate)); } @@ -2644,3 +2665,38 @@ void webkit_settings_set_user_agent_with_application_details(WebKitSettings* set CString newUserAgent = WebCore::standardUserAgent(String::fromUTF8(applicationName), String::fromUTF8(applicationVersion)).utf8(); webkit_settings_set_user_agent(settings, newUserAgent.data()); } + +/** + * webkit_settings_get_enable_smooth_scrolling: + * @settings: a #WebKitSettings + * + * Get the #WebKitSettings:enable-smooth-scrolling property. + * + * Returns: %TRUE if smooth scrolling is enabled or %FALSE otherwise. + */ +gboolean webkit_settings_get_enable_smooth_scrolling(WebKitSettings* settings) +{ + g_return_val_if_fail(WEBKIT_IS_SETTINGS(settings), FALSE); + + return WebKit::toImpl(settings->priv->preferences.get())->scrollAnimatorEnabled(); +} + +/** + * webkit_settings_set_enable_smooth_scrolling: + * @settings: a #WebKitSettings + * @enabled: Value to be set + * + * Set the #WebKitSettings:enable-smooth-scrolling property. + */ +void webkit_settings_set_enable_smooth_scrolling(WebKitSettings* settings, gboolean enabled) +{ + g_return_if_fail(WEBKIT_IS_SETTINGS(settings)); + + WebKitSettingsPrivate* priv = settings->priv; + bool currentValue = WebKit::toImpl(priv->preferences.get())->scrollAnimatorEnabled(); + if (currentValue == enabled) + return; + + WebKit::toImpl(priv->preferences.get())->setScrollAnimatorEnabled(enabled); + g_object_notify(G_OBJECT(settings), "enable-smooth-scrolling"); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h b/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h index b35a23f06..a9fe86a30 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.h @@ -373,6 +373,13 @@ webkit_settings_set_user_agent_with_application_details (WebKitSettings * const gchar *application_name, const gchar *application_version); +WEBKIT_API gboolean +webkit_settings_get_enable_smooth_scrolling (WebKitSettings *settings); + +WEBKIT_API void +webkit_settings_set_enable_smooth_scrolling (WebKitSettings *settings, + gboolean enabled); + G_END_DECLS #endif /* WebKitSettings_h */ diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequest.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequest.cpp index e62c1faf5..e69831f29 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequest.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequest.cpp @@ -22,6 +22,8 @@ #include "WebKitURISchemeRequestPrivate.h" #include "WebKitWebContextPrivate.h" +#include "WebKitWebView.h" +#include "WebPageProxy.h" #include <WebCore/GOwnPtrSoup.h> #include <libsoup/soup.h> #include <wtf/gobject/GRefPtr.h> @@ -36,6 +38,7 @@ G_DEFINE_TYPE(WebKitURISchemeRequest, webkit_uri_scheme_request, G_TYPE_OBJECT) struct _WebKitURISchemeRequestPrivate { WebKitWebContext* webContext; WKRetainPtr<WKSoupRequestManagerRef> wkRequestManager; + WKRetainPtr<WKPageRef> wkInitiatingPage; uint64_t requestID; CString uri; GOwnPtr<SoupURI> soupURI; @@ -68,12 +71,13 @@ static void webkit_uri_scheme_request_class_init(WebKitURISchemeRequestClass* re g_type_class_add_private(requestClass, sizeof(WebKitURISchemeRequestPrivate)); } -WebKitURISchemeRequest* webkitURISchemeRequestCreate(WebKitWebContext* webContext, WKSoupRequestManagerRef wkRequestManager, WKURLRef wkURL, uint64_t requestID) +WebKitURISchemeRequest* webkitURISchemeRequestCreate(WebKitWebContext* webContext, WKSoupRequestManagerRef wkRequestManager, WKURLRef wkURL, WKPageRef wkInitiatingPage, uint64_t requestID) { WebKitURISchemeRequest* request = WEBKIT_URI_SCHEME_REQUEST(g_object_new(WEBKIT_TYPE_URI_SCHEME_REQUEST, NULL)); request->priv->webContext = webContext; request->priv->wkRequestManager = wkRequestManager; request->priv->uri = toImpl(wkURL)->string().utf8(); + request->priv->wkInitiatingPage = wkInitiatingPage; request->priv->requestID = requestID; return request; } @@ -138,6 +142,21 @@ const char* webkit_uri_scheme_request_get_path(WebKitURISchemeRequest* request) return request->priv->soupURI->path; } +/** + * webkit_uri_scheme_request_get_web_view: + * @request: a #WebKitURISchemeRequest + * + * Get the #WebKitWebView that initiated the request. + * + * Returns: (transfer none): the #WebKitWebView that initiated @request. + */ +WebKitWebView* webkit_uri_scheme_request_get_web_view(WebKitURISchemeRequest* request) +{ + g_return_val_if_fail(WEBKIT_IS_URI_SCHEME_REQUEST(request), 0); + + return WEBKIT_WEB_VIEW(toImpl(request->priv->wkInitiatingPage.get())->viewWidget()); +} + static void webkitURISchemeRequestReadCallback(GInputStream* inputStream, GAsyncResult* result, WebKitURISchemeRequest* schemeRequest) { GRefPtr<WebKitURISchemeRequest> request = adoptGRef(schemeRequest); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequest.h b/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequest.h index 34f214489..9ead50709 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequest.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequest.h @@ -51,22 +51,25 @@ struct _WebKitURISchemeRequestClass { }; WEBKIT_API GType -webkit_uri_scheme_request_get_type (void); +webkit_uri_scheme_request_get_type (void); WEBKIT_API const gchar * -webkit_uri_scheme_request_get_scheme (WebKitURISchemeRequest *request); +webkit_uri_scheme_request_get_scheme (WebKitURISchemeRequest *request); WEBKIT_API const gchar * -webkit_uri_scheme_request_get_uri (WebKitURISchemeRequest *request); +webkit_uri_scheme_request_get_uri (WebKitURISchemeRequest *request); WEBKIT_API const gchar * -webkit_uri_scheme_request_get_path (WebKitURISchemeRequest *request); +webkit_uri_scheme_request_get_path (WebKitURISchemeRequest *request); + +WEBKIT_API WebKitWebView * +webkit_uri_scheme_request_get_web_view (WebKitURISchemeRequest *request); WEBKIT_API void -webkit_uri_scheme_request_finish (WebKitURISchemeRequest *request, - GInputStream *stream, - gint64 stream_length, - const gchar *mime_type); +webkit_uri_scheme_request_finish (WebKitURISchemeRequest *request, + GInputStream *stream, + gint64 stream_length, + const gchar *mime_type); G_END_DECLS diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequestPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequestPrivate.h index 149813def..b7c011f66 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequestPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequestPrivate.h @@ -25,7 +25,7 @@ #include "WebKitWebContext.h" #include <WebKit2/WKSoupRequestManager.h> -WebKitURISchemeRequest* webkitURISchemeRequestCreate(WebKitWebContext*, WKSoupRequestManagerRef, WKURLRef, uint64_t requestID); +WebKitURISchemeRequest* webkitURISchemeRequestCreate(WebKitWebContext*, WKSoupRequestManagerRef, WKURLRef, WKPageRef, uint64_t requestID); uint64_t webkitURISchemeRequestGetID(WebKitURISchemeRequest*); void webkitURISchemeRequestCancel(WebKitURISchemeRequest*); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp index 5b2c26697..dab18a87d 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp @@ -20,10 +20,10 @@ #include "config.h" #include "WebKitWebContext.h" -#include "WebContext.h" #include "WebKitCookieManagerPrivate.h" #include "WebKitDownloadClient.h" #include "WebKitDownloadPrivate.h" +#include "WebKitFaviconDatabasePrivate.h" #include "WebKitGeolocationProvider.h" #include "WebKitPluginPrivate.h" #include "WebKitPrivate.h" @@ -32,7 +32,9 @@ #include "WebKitTextChecker.h" #include "WebKitURISchemeRequestPrivate.h" #include "WebKitWebContextPrivate.h" +#include "WebResourceCacheManagerProxy.h" #include <WebCore/FileSystem.h> +#include <WebCore/IconDatabase.h> #include <WebCore/Language.h> #include <wtf/HashMap.h> #include <wtf/OwnPtr.h> @@ -42,8 +44,6 @@ #include <wtf/gobject/GRefPtr.h> #include <wtf/text/CString.h> -using namespace WebKit; - enum { DOWNLOAD_STARTED, @@ -93,11 +93,12 @@ typedef HashMap<String, RefPtr<WebKitURISchemeHandler> > URISchemeHandlerMap; typedef HashMap<uint64_t, GRefPtr<WebKitURISchemeRequest> > URISchemeRequestMap; struct _WebKitWebContextPrivate { - WKRetainPtr<WKContextRef> context; + RefPtr<WebContext> context; GRefPtr<WebKitCookieManager> cookieManager; + GRefPtr<WebKitFaviconDatabase> faviconDatabase; GRefPtr<WebKitSecurityManager> securityManager; - WKRetainPtr<WKSoupRequestManagerRef> requestManager; + RefPtr<WebSoupRequestManagerProxy> requestManager; URISchemeHandlerMap uriSchemeHandlers; URISchemeRequestMap uriSchemeRequests; #if ENABLE(GEOLOCATION) @@ -106,6 +107,7 @@ struct _WebKitWebContextPrivate { #if ENABLE(SPELLCHECK) OwnPtr<WebKitTextChecker> textChecker; #endif + CString faviconDatabaseDirectory; }; static guint signals[LAST_SIGNAL] = { 0, }; @@ -152,17 +154,20 @@ static void webkit_web_context_class_init(WebKitWebContextClass* webContextClass static gpointer createDefaultWebContext(gpointer) { static GRefPtr<WebKitWebContext> webContext = adoptGRef(WEBKIT_WEB_CONTEXT(g_object_new(WEBKIT_TYPE_WEB_CONTEXT, NULL))); - webContext->priv->context = WKContextCreate(); - webContext->priv->requestManager = WKContextGetSoupRequestManager(webContext->priv->context.get()); - WKContextSetCacheModel(webContext->priv->context.get(), kWKCacheModelPrimaryWebBrowser); + WebKitWebContextPrivate* priv = webContext->priv; + + priv->context = WebContext::create(String()); + priv->requestManager = webContext->priv->context->soupRequestManagerProxy(); + priv->context->setCacheModel(CacheModelPrimaryWebBrowser); + attachDownloadClientToContext(webContext.get()); attachRequestManagerClientToContext(webContext.get()); + #if ENABLE(GEOLOCATION) - WKGeolocationManagerRef wkGeolocationManager = WKContextGetGeolocationManager(webContext->priv->context.get()); - webContext->priv->geolocationProvider = WebKitGeolocationProvider::create(wkGeolocationManager); + priv->geolocationProvider = WebKitGeolocationProvider::create(toAPI(priv->context->geolocationManagerProxy())); #endif #if ENABLE(SPELLCHECK) - webContext->priv->textChecker = WebKitTextChecker::create(); + priv->textChecker = WebKitTextChecker::create(); #endif return webContext.get(); } @@ -206,26 +211,26 @@ WebKitWebContext* webkit_web_context_get_default(void) */ void webkit_web_context_set_cache_model(WebKitWebContext* context, WebKitCacheModel model) { - WKCacheModel cacheModel; + CacheModel cacheModel; g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); switch (model) { case WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER: - cacheModel = kWKCacheModelDocumentViewer; + cacheModel = CacheModelDocumentViewer; break; case WEBKIT_CACHE_MODEL_WEB_BROWSER: - cacheModel = kWKCacheModelPrimaryWebBrowser; + cacheModel = CacheModelPrimaryWebBrowser; break; case WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER: - cacheModel = kWKCacheModelDocumentBrowser; + cacheModel = CacheModelDocumentBrowser; break; default: g_assert_not_reached(); } - WebKitWebContextPrivate* priv = context->priv; - if (cacheModel != WKContextGetCacheModel(priv->context.get())) - WKContextSetCacheModel(priv->context.get(), cacheModel); + + if (cacheModel != context->priv->context->cacheModel()) + context->priv->context->setCacheModel(cacheModel); } /** @@ -242,13 +247,12 @@ WebKitCacheModel webkit_web_context_get_cache_model(WebKitWebContext* context) { g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), WEBKIT_CACHE_MODEL_WEB_BROWSER); - WebKitWebContextPrivate* priv = context->priv; - switch (WKContextGetCacheModel(priv->context.get())) { - case kWKCacheModelDocumentViewer: + switch (context->priv->context->cacheModel()) { + case CacheModelDocumentViewer: return WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER; - case kWKCacheModelPrimaryWebBrowser: + case CacheModelPrimaryWebBrowser: return WEBKIT_CACHE_MODEL_WEB_BROWSER; - case kWKCacheModelDocumentBrowser: + case CacheModelDocumentBrowser: return WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER; default: g_assert_not_reached(); @@ -268,11 +272,10 @@ void webkit_web_context_clear_cache(WebKitWebContext* context) { g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); - WebKitWebContextPrivate* priv = context->priv; - WKResourceCacheManagerClearCacheForAllOrigins(WKContextGetResourceCacheManager(priv->context.get()), WKResourceCachesToClearAll); + context->priv->context->resourceCacheManagerProxy()->clearCacheForAllOrigins(AllResourceCaches); } -typedef HashMap<WKDownloadRef, GRefPtr<WebKitDownload> > DownloadsMap; +typedef HashMap<DownloadProxy*, GRefPtr<WebKitDownload> > DownloadsMap; static DownloadsMap& downloadsMap() { @@ -295,12 +298,9 @@ WebKitDownload* webkit_web_context_download_uri(WebKitWebContext* context, const g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0); g_return_val_if_fail(uri, 0); - WebKitWebContextPrivate* priv = context->priv; - WKRetainPtr<WKURLRef> wkURL(AdoptWK, WKURLCreateWithUTF8CString(uri)); - WKRetainPtr<WKURLRequestRef> wkRequest(AdoptWK, WKURLRequestCreateWithWKURL(wkURL.get())); - WKRetainPtr<WKDownloadRef> wkDownload = WKContextDownloadURLRequest(priv->context.get(), wkRequest.get()); - WebKitDownload* download = webkitDownloadCreate(wkDownload.get()); - downloadsMap().set(wkDownload.get(), download); + DownloadProxy* downloadProxy = context->priv->context->download(0, WebCore::ResourceRequest(String::fromUTF8(uri))); + WebKitDownload* download = webkitDownloadCreate(toAPI(downloadProxy)); + downloadsMap().set(downloadProxy, download); return download; } @@ -318,11 +318,107 @@ WebKitCookieManager* webkit_web_context_get_cookie_manager(WebKitWebContext* con WebKitWebContextPrivate* priv = context->priv; if (!priv->cookieManager) - priv->cookieManager = adoptGRef(webkitCookieManagerCreate(WKContextGetCookieManager(priv->context.get()))); + priv->cookieManager = adoptGRef(webkitCookieManagerCreate(toAPI(priv->context->cookieManagerProxy()))); return priv->cookieManager.get(); } +static void ensureFaviconDatabase(WebKitWebContext* context) +{ + WebKitWebContextPrivate* priv = context->priv; + if (priv->faviconDatabase) + return; + + priv->faviconDatabase = adoptGRef(webkitFaviconDatabaseCreate(priv->context->iconDatabase())); +} + +/** + * webkit_web_context_set_favicon_database_directory: + * @context: a #WebKitWebContext + * @path: (allow-none): an absolute path to the icon database + * directory or %NULL to use the defaults + * + * Set the directory path to be used to store the favicons database + * for @context on disk. Passing %NULL as @path means using the + * default directory for the platform (see g_get_user_data_dir()). + * + * Calling this method also means enabling the favicons database for + * its use from the applications, so that's why it's expected to be + * called only once. Further calls for the same instance of + * #WebKitWebContext won't cause any effect. + */ +void webkit_web_context_set_favicon_database_directory(WebKitWebContext* context, const gchar* path) +{ + g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); + + WebKitWebContextPrivate* priv = context->priv; + WebIconDatabase* iconDatabase = priv->context->iconDatabase(); + if (iconDatabase->isOpen()) + return; + + ensureFaviconDatabase(context); + + // Use default if 0 is passed as parameter. + String directoryPath = WebCore::filenameToString(path); + priv->faviconDatabaseDirectory = directoryPath.isEmpty() + ? priv->context->iconDatabasePath().utf8() + : directoryPath.utf8(); + + // Build the full path to the icon database file on disk. + GOwnPtr<gchar> faviconDatabasePath(g_build_filename(priv->faviconDatabaseDirectory.data(), + WebCore::IconDatabase::defaultDatabaseFilename().utf8().data(), + NULL)); + + // Setting the path will cause the icon database to be opened. + priv->context->setIconDatabasePath(WebCore::filenameToString(faviconDatabasePath.get())); +} + +/** + * webkit_web_context_get_favicon_database_directory: + * @context: a #WebKitWebContext + * + * Get the directory path being used to store the favicons database + * for @context, or %NULL if + * webkit_web_context_set_favicon_database_directory() hasn't been + * called yet. + * + * This function will always return the same path after having called + * webkit_web_context_set_favicon_database_directory() for the first + * time. + * + * Returns: (transfer none): the path of the directory of the favicons + * database associated with @context, or %NULL. + */ +const gchar* webkit_web_context_get_favicon_database_directory(WebKitWebContext *context) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0); + + WebKitWebContextPrivate* priv = context->priv; + if (priv->faviconDatabaseDirectory.isNull()) + return 0; + + return priv->faviconDatabaseDirectory.data(); +} + +/** + * webkit_web_context_get_favicon_database: + * @context: a #WebKitWebContext + * + * Get the #WebKitFaviconDatabase associated with @context. + * + * To initialize the database you need to call + * webkit_web_context_set_favicon_database_directory(). + * + * Returns: (transfer none): the #WebKitFaviconDatabase of @context. + */ +WebKitFaviconDatabase* webkit_web_context_get_favicon_database(WebKitWebContext* context) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0); + + ensureFaviconDatabase(context); + return context->priv->faviconDatabase.get(); +} + /** * webkit_web_context_get_security_manager: * @context: a #WebKitWebContext @@ -354,7 +450,7 @@ void webkit_web_context_set_additional_plugins_directory(WebKitWebContext* conte g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); g_return_if_fail(directory); - toImpl(context->priv->context.get())->setAdditionalPluginsDirectory(WebCore::filenameToString(directory)); + context->priv->context->setAdditionalPluginsDirectory(WebCore::filenameToString(directory)); } struct GetPluginsAsyncData { @@ -365,7 +461,7 @@ WEBKIT_DEFINE_ASYNC_DATA_STRUCT(GetPluginsAsyncData) static void webkitWebContextGetPluginThread(GSimpleAsyncResult* result, GObject* object, GCancellable*) { GetPluginsAsyncData* data = static_cast<GetPluginsAsyncData*>(g_simple_async_result_get_op_res_gpointer(result)); - data->plugins = toImpl(WEBKIT_WEB_CONTEXT(object)->priv->context.get())->pluginInfoStore().plugins(); + data->plugins = WEBKIT_WEB_CONTEXT(object)->priv->context->pluginInfoStore().plugins(); } /** @@ -472,8 +568,7 @@ void webkit_web_context_register_uri_scheme(WebKitWebContext* context, const cha RefPtr<WebKitURISchemeHandler> handler = adoptRef(new WebKitURISchemeHandler(callback, userData, destroyNotify)); context->priv->uriSchemeHandlers.set(String::fromUTF8(scheme), handler.get()); - WKRetainPtr<WKStringRef> wkScheme(AdoptWK, WKStringCreateWithUTF8CString(scheme)); - WKSoupRequestManagerRegisterURIScheme(context->priv->requestManager.get(), wkScheme.get()); + context->priv->requestManager->registerURIScheme(String::fromUTF8(scheme)); } /** @@ -587,20 +682,20 @@ void webkit_web_context_set_preferred_languages(WebKitWebContext* context, const WebCore::languageDidChange(); } -WebKitDownload* webkitWebContextGetOrCreateDownload(WKDownloadRef wkDownload) +WebKitDownload* webkitWebContextGetOrCreateDownload(DownloadProxy* downloadProxy) { - GRefPtr<WebKitDownload> download = downloadsMap().get(wkDownload); + GRefPtr<WebKitDownload> download = downloadsMap().get(downloadProxy); if (download) return download.get(); - download = adoptGRef(webkitDownloadCreate(wkDownload)); - downloadsMap().set(wkDownload, download.get()); + download = adoptGRef(webkitDownloadCreate(toAPI(downloadProxy))); + downloadsMap().set(downloadProxy, download.get()); return download.get(); } -void webkitWebContextRemoveDownload(WKDownloadRef wkDownload) +void webkitWebContextRemoveDownload(DownloadProxy* downloadProxy) { - downloadsMap().remove(wkDownload); + downloadsMap().remove(downloadProxy); } void webkitWebContextDownloadStarted(WebKitWebContext* context, WebKitDownload* download) @@ -608,14 +703,14 @@ void webkitWebContextDownloadStarted(WebKitWebContext* context, WebKitDownload* g_signal_emit(context, signals[DOWNLOAD_STARTED], 0, download); } -WKContextRef webkitWebContextGetWKContext(WebKitWebContext* context) +WebContext* webkitWebContextGetContext(WebKitWebContext* context) { g_assert(WEBKIT_IS_WEB_CONTEXT(context)); return context->priv->context.get(); } -WKSoupRequestManagerRef webkitWebContextGetRequestManager(WebKitWebContext* context) +WebSoupRequestManagerProxy* webkitWebContextGetRequestManager(WebKitWebContext* context) { return context->priv->requestManager.get(); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h index f77086f4d..ae79bec87 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h @@ -28,6 +28,7 @@ #include <webkit2/WebKitCookieManager.h> #include <webkit2/WebKitDefines.h> #include <webkit2/WebKitDownload.h> +#include <webkit2/WebKitFaviconDatabase.h> #include <webkit2/WebKitSecurityManager.h> #include <webkit2/WebKitURISchemeRequest.h> @@ -114,6 +115,15 @@ webkit_web_context_download_uri (WebKitWebContext WEBKIT_API WebKitCookieManager * webkit_web_context_get_cookie_manager (WebKitWebContext *context); +WEBKIT_API WebKitFaviconDatabase * +webkit_web_context_get_favicon_database (WebKitWebContext *context); + +WEBKIT_API void +webkit_web_context_set_favicon_database_directory (WebKitWebContext *context, + const gchar *path); +WEBKIT_API const gchar * +webkit_web_context_get_favicon_database_directory (WebKitWebContext *context); + WEBKIT_API WebKitSecurityManager * webkit_web_context_get_security_manager (WebKitWebContext *context); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h index 9e5536b3a..67be48d5c 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h @@ -26,15 +26,20 @@ #ifndef WebKitWebContextPrivate_h #define WebKitWebContextPrivate_h +#include "DownloadProxy.h" +#include "WebContext.h" #include "WebKitPrivate.h" #include "WebKitURISchemeRequest.h" #include "WebKitWebContext.h" +#include "WebSoupRequestManagerProxy.h" -WKContextRef webkitWebContextGetWKContext(WebKitWebContext*); -WebKitDownload* webkitWebContextGetOrCreateDownload(WKDownloadRef); -void webkitWebContextRemoveDownload(WKDownloadRef); +using namespace WebKit; + +WebContext* webkitWebContextGetContext(WebKitWebContext*); +WebKitDownload* webkitWebContextGetOrCreateDownload(DownloadProxy*); +void webkitWebContextRemoveDownload(DownloadProxy*); void webkitWebContextDownloadStarted(WebKitWebContext*, WebKitDownload*); -WKSoupRequestManagerRef webkitWebContextGetRequestManager(WebKitWebContext*); +WebSoupRequestManagerProxy* webkitWebContextGetRequestManager(WebKitWebContext*); void webkitWebContextReceivedURIRequest(WebKitWebContext*, WebKitURISchemeRequest*); void webkitWebContextDidFailToLoadURIRequest(WebKitWebContext*, uint64_t requestID); void webkitWebContextDidFinishURIRequest(WebKitWebContext*, uint64_t requestID); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp index 301be899c..236a4f304 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp @@ -30,6 +30,7 @@ #include "WebKitContextMenuPrivate.h" #include "WebKitEnumTypes.h" #include "WebKitError.h" +#include "WebKitFaviconDatabasePrivate.h" #include "WebKitFormClient.h" #include "WebKitFullscreenClient.h" #include "WebKitHitTestResultPrivate.h" @@ -56,6 +57,7 @@ #include <WebCore/DragIcon.h> #include <WebCore/GOwnPtrGtk.h> #include <WebCore/GtkUtilities.h> +#include <WebCore/RefPtrCairo.h> #include <glib/gi18n-lib.h> #include <wtf/gobject/GOwnPtr.h> #include <wtf/gobject/GRefPtr.h> @@ -102,6 +104,7 @@ enum { PROP_WEB_CONTEXT, PROP_TITLE, PROP_ESTIMATED_LOAD_PROGRESS, + PROP_FAVICON, PROP_URI, PROP_ZOOM_LEVEL, PROP_IS_LOADING @@ -120,6 +123,7 @@ struct _WebKitWebViewPrivate { bool waitingForMainResource; gulong mainResourceResponseHandlerID; + gulong watchForChangesInFaviconHandlerID; WebKitLoadEvent lastDelayedEvent; GRefPtr<WebKitBackForwardList> backForwardList; @@ -139,6 +143,9 @@ struct _WebKitWebViewPrivate { ResourcesMap subresourcesMap; GRefPtr<WebKitWebInspector> inspector; + + RefPtr<cairo_surface_t> favicon; + GRefPtr<GCancellable> faviconCancellable; }; static guint signals[LAST_SIGNAL] = { 0, }; @@ -260,6 +267,37 @@ static void userAgentChanged(WebKitSettings* settings, GParamSpec*, WebKitWebVie getPage(webView)->setCustomUserAgent(String::fromUTF8(webkit_settings_get_user_agent(settings))); } +static void webkitWebViewCancelFaviconRequest(WebKitWebView* webView) +{ + if (!webView->priv->faviconCancellable) + return; + + g_cancellable_cancel(webView->priv->faviconCancellable.get()); + webView->priv->faviconCancellable = 0; +} + +static void webkitWebViewUpdateFavicon(WebKitWebView* webView, cairo_surface_t* favicon) +{ + if (webView->priv->favicon.get() == favicon) + return; + + webView->priv->favicon = favicon; + g_object_notify(G_OBJECT(webView), "favicon"); +} + +static void iconReadyCallback(WebKitFaviconDatabase* database, const char* uri, WebKitWebView* webView) +{ + // Consider only the icon matching the active URI for this webview. + if (webView->priv->activeURI != uri) + return; + + // Update the favicon only if we don't have one already. + if (!webView->priv->favicon) { + RefPtr<cairo_surface_t> favicon = adoptRef(webkitFaviconDatabaseGetFavicon(database, webView->priv->activeURI)); + webkitWebViewUpdateFavicon(webView, favicon.get()); + } +} + static void webkitWebViewSetSettings(WebKitWebView* webView, WebKitSettings* settings) { webView->priv->settings = settings; @@ -285,6 +323,29 @@ static void webkitWebViewDisconnectMainResourceResponseChangedSignalHandler(WebK priv->mainResourceResponseHandlerID = 0; } +static void webkitWebViewWatchForChangesInFavicon(WebKitWebView* webView) +{ + WebKitWebViewPrivate* priv = webView->priv; + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(priv->context); + + // Make sure we only connect to this signal once per view. + if (priv->watchForChangesInFaviconHandlerID) + return; + + priv->watchForChangesInFaviconHandlerID = + g_signal_connect(database, "favicon-ready", G_CALLBACK(iconReadyCallback), webView); +} + +static void webkitWebViewDisconnectFaviconDatabaseSignalHandlers(WebKitWebView* webView) +{ + WebKitWebViewPrivate* priv = webView->priv; + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(priv->context); + + if (priv->watchForChangesInFaviconHandlerID) + g_signal_handler_disconnect(database, priv->watchForChangesInFaviconHandlerID); + priv->watchForChangesInFaviconHandlerID = 0; +} + static void fileChooserDialogResponseCallback(GtkDialog* dialog, gint responseID, WebKitFileChooserRequest* request) { GRefPtr<WebKitFileChooserRequest> adoptedRequest = adoptGRef(request); @@ -337,7 +398,7 @@ static void webkitWebViewConstructed(GObject* object) WebKitWebViewPrivate* priv = webView->priv; WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(webView); - webkitWebViewBaseCreateWebPage(webViewBase, toImpl(webkitWebContextGetWKContext(priv->context)), 0); + webkitWebViewBaseCreateWebPage(webViewBase, webkitWebContextGetContext(priv->context), 0); attachLoaderClientToView(webView); attachUIClientToView(webView); @@ -385,6 +446,9 @@ static void webkitWebViewGetProperty(GObject* object, guint propId, GValue* valu case PROP_ESTIMATED_LOAD_PROGRESS: g_value_set_double(value, webkit_web_view_get_estimated_load_progress(webView)); break; + case PROP_FAVICON: + g_value_set_pointer(value, webkit_web_view_get_favicon(webView)); + break; case PROP_URI: g_value_set_string(value, webkit_web_view_get_uri(webView)); break; @@ -411,8 +475,10 @@ static void webkitWebViewFinalize(GObject* object) if (priv->modalLoop && g_main_loop_is_running(priv->modalLoop.get())) g_main_loop_quit(priv->modalLoop.get()); + webkitWebViewCancelFaviconRequest(webView); webkitWebViewDisconnectMainResourceResponseChangedSignalHandler(webView); webkitWebViewDisconnectSettingsSignalHandlers(webView); + webkitWebViewDisconnectFaviconDatabaseSignalHandlers(webView); priv->~WebKitWebViewPrivate(); G_OBJECT_CLASS(webkit_web_view_parent_class)->finalize(object); @@ -500,6 +566,18 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) 0.0, 1.0, 0.0, WEBKIT_PARAM_READABLE)); /** + * WebKitWebView:favicon: + * + * The favicon currently associated to the #WebKitWebView. + * See webkit_web_view_get_favicon() for more details. + */ + g_object_class_install_property(gObjectClass, + PROP_FAVICON, + g_param_spec_pointer("favicon", + _("Favicon"), + _("The favicon associated to the view, if any"), + WEBKIT_PARAM_READABLE)); + /** * WebKitWebView:uri: * * The current active URI of the #WebKitWebView. @@ -1158,9 +1236,10 @@ static void setCertificateToMainResource(WebKitWebView* webView) static void webkitWebViewEmitLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent) { - if (loadEvent == WEBKIT_LOAD_STARTED) + if (loadEvent == WEBKIT_LOAD_STARTED) { webkitWebViewSetIsLoading(webView, true); - else if (loadEvent == WEBKIT_LOAD_FINISHED) { + webkitWebViewWatchForChangesInFavicon(webView); + } else if (loadEvent == WEBKIT_LOAD_FINISHED) { webkitWebViewSetIsLoading(webView, false); webView->priv->waitingForMainResource = false; webkitWebViewDisconnectMainResourceResponseChangedSignalHandler(webView); @@ -1182,29 +1261,52 @@ static void webkitWebViewEmitDelayedLoadEvents(WebKitWebView* webView) priv->waitingForMainResource = false; } +static void getFaviconReadyCallback(GObject* object, GAsyncResult* result, gpointer userData) +{ + GOwnPtr<GError> error; + RefPtr<cairo_surface_t> favicon = adoptRef(webkit_favicon_database_get_favicon_finish(WEBKIT_FAVICON_DATABASE(object), result, &error.outPtr())); + if (!g_error_matches(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + WebKitWebView* webView = WEBKIT_WEB_VIEW(userData); + webkitWebViewUpdateFavicon(webView, favicon.get()); + webView->priv->faviconCancellable = 0; + } +} + +static void webkitWebViewRequestFavicon(WebKitWebView* webView) +{ + WebKitWebViewPrivate* priv = webView->priv; + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(priv->context); + priv->faviconCancellable = adoptGRef(g_cancellable_new()); + webkit_favicon_database_get_favicon(database, priv->activeURI.data(), priv->faviconCancellable.get(), getFaviconReadyCallback, webView); +} + void webkitWebViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent) { + WebKitWebViewPrivate* priv = webView->priv; if (loadEvent == WEBKIT_LOAD_STARTED) { // Finish a possible previous load waiting for main resource. webkitWebViewEmitDelayedLoadEvents(webView); - webView->priv->loadingResourcesMap.clear(); - webView->priv->mainResource = 0; - webView->priv->waitingForMainResource = false; + webkitWebViewCancelFaviconRequest(webView); + priv->loadingResourcesMap.clear(); + priv->mainResource = 0; + priv->waitingForMainResource = false; } else if (loadEvent == WEBKIT_LOAD_COMMITTED) { - webView->priv->subresourcesMap.clear(); - if (!webView->priv->mainResource) { + webkitWebViewRequestFavicon(webView); + + priv->subresourcesMap.clear(); + if (!priv->mainResource) { // When a page is loaded from the history cache, the main resource load callbacks // are called when the main frame load is finished. We want to make sure there's a // main resource available when load has been committed, so we delay the emission of // load-changed signal until main resource object has been created. - webView->priv->waitingForMainResource = true; + priv->waitingForMainResource = true; } else setCertificateToMainResource(webView); } - if (webView->priv->waitingForMainResource) - webView->priv->lastDelayedEvent = loadEvent; + if (priv->waitingForMainResource) + priv->lastDelayedEvent = loadEvent; else webkitWebViewEmitLoadChanged(webView, loadEvent); } @@ -1850,6 +1952,26 @@ const gchar* webkit_web_view_get_uri(WebKitWebView* webView) } /** + * webkit_web_view_get_favicon: + * @web_view: a #WebKitWebView + * + * Returns favicon currently associated to @web_view, if any. You can + * connect to notify::favicon signal of @web_view to be notified when + * the favicon is available. + * + * Returns: (transfer none): a pointer to a #cairo_surface_t with the + * favicon or %NULL if there's no icon associated with @web_view. + */ +cairo_surface_t* webkit_web_view_get_favicon(WebKitWebView* webView) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + if (webView->priv->activeURI.isNull()) + return 0; + + return webView->priv->favicon.get(); +} + +/** * webkit_web_view_get_custom_charset: * @web_view: a #WebKitWebView * @@ -2192,7 +2314,7 @@ static void webkitWebViewRunJavaScriptCallback(WKSerializedScriptValueRef wkSeri g_simple_async_result_take_error(result.get(), error); else if (wkSerializedScriptValue) { GRefPtr<WebKitWebView> webView = adoptGRef(WEBKIT_WEB_VIEW(g_async_result_get_source_object(G_ASYNC_RESULT(result.get())))); - data->scriptResult = webkitJavascriptResultCreate(webView.get(), wkSerializedScriptValue); + data->scriptResult = webkitJavascriptResultCreate(webView.get(), toImpl(wkSerializedScriptValue)); } else { g_set_error_literal(&error, WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED, _("An exception was raised in JavaScript")); g_simple_async_result_take_error(result.get(), error); @@ -2307,6 +2429,94 @@ WebKitJavascriptResult* webkit_web_view_run_javascript_finish(WebKitWebView* web return data->scriptResult ? webkit_javascript_result_ref(data->scriptResult) : 0; } +static void resourcesStreamReadCallback(GObject* object, GAsyncResult* result, gpointer userData) +{ + GOutputStream* outputStream = G_OUTPUT_STREAM(object); + GRefPtr<GSimpleAsyncResult> runJavascriptResult = adoptGRef(G_SIMPLE_ASYNC_RESULT(userData)); + + GError* error = 0; + g_output_stream_splice_finish(outputStream, result, &error); + if (error) { + g_simple_async_result_take_error(runJavascriptResult.get(), error); + g_simple_async_result_complete(runJavascriptResult.get()); + return; + } + + GRefPtr<WebKitWebView> webView = adoptGRef(WEBKIT_WEB_VIEW(g_async_result_get_source_object(G_ASYNC_RESULT(runJavascriptResult.get())))); + gpointer outputStreamData = g_memory_output_stream_get_data(G_MEMORY_OUTPUT_STREAM(outputStream)); + getPage(webView.get())->runJavaScriptInMainFrame(String::fromUTF8(reinterpret_cast<const gchar*>(outputStreamData)), + ScriptValueCallback::create(runJavascriptResult.leakRef(), webkitWebViewRunJavaScriptCallback)); +} + +/** + * webkit_web_view_run_javascript_from_gresource: + * @web_view: a #WebKitWebView + * @resource: the location of the resource to load + * @cancellable: (allow-none): a #GCancellable or %NULL to ignore + * @callback: (scope async): a #GAsyncReadyCallback to call when the script finished + * @user_data: (closure): the data to pass to callback function + * + * Asynchronously run the script from @resource in the context of the + * current page in @web_view. + * + * When the operation is finished, @callback will be called. You can + * then call webkit_web_view_run_javascript_from_gresource_finish() to get the result + * of the operation. + */ +void webkit_web_view_run_javascript_from_gresource(WebKitWebView* webView, const gchar* resource, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(resource); + + GRefPtr<GSimpleAsyncResult> result = adoptGRef(g_simple_async_result_new(G_OBJECT(webView), callback, userData, + reinterpret_cast<gpointer>(webkit_web_view_run_javascript_from_gresource))); + RunJavaScriptAsyncData* data = createRunJavaScriptAsyncData(); + data->cancellable = cancellable; + g_simple_async_result_set_op_res_gpointer(result.get(), data, reinterpret_cast<GDestroyNotify>(destroyRunJavaScriptAsyncData)); + + GError* error = 0; + GRefPtr<GInputStream> inputStream = adoptGRef(g_resources_open_stream(resource, G_RESOURCE_LOOKUP_FLAGS_NONE, &error)); + if (error) { + g_simple_async_result_take_error(result.get(), error); + g_simple_async_result_complete_in_idle(result.get()); + return; + } + + GRefPtr<GOutputStream> outputStream = adoptGRef(g_memory_output_stream_new(0, 0, fastRealloc, fastFree)); + g_output_stream_splice_async(outputStream.get(), inputStream.get(), + static_cast<GOutputStreamSpliceFlags>(G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET), + G_PRIORITY_DEFAULT, + cancellable, resourcesStreamReadCallback, result.leakRef()); +} + +/** + * webkit_web_view_run_javascript_from_gresource_finish: + * @web_view: a #WebKitWebView + * @result: a #GAsyncResult + * @error: return location for error or %NULL to ignore + * + * Finish an asynchronous operation started with webkit_web_view_run_javascript_from_gresource(). + * + * Check webkit_web_view_run_javascript_finish() for a usage example. + * + * Returns: (transfer full): a #WebKitJavascriptResult with the result of the last executed statement in @script + * or %NULL in case of error + */ +WebKitJavascriptResult* webkit_web_view_run_javascript_from_gresource_finish(WebKitWebView* webView, GAsyncResult* result, GError** error) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); + g_return_val_if_fail(G_IS_ASYNC_RESULT(result), 0); + + GSimpleAsyncResult* simpleResult = G_SIMPLE_ASYNC_RESULT(result); + g_warn_if_fail(g_simple_async_result_get_source_tag(simpleResult) == webkit_web_view_run_javascript_from_gresource); + + if (g_simple_async_result_propagate_error(simpleResult, error)) + return 0; + + RunJavaScriptAsyncData* data = static_cast<RunJavaScriptAsyncData*>(g_simple_async_result_get_op_res_gpointer(simpleResult)); + return data->scriptResult ? webkit_javascript_result_ref(data->scriptResult) : 0; +} + /** * webkit_web_view_get_main_resource: * @web_view: a #WebKitWebView @@ -2341,7 +2551,7 @@ GList* webkit_web_view_get_subresources(WebKitWebView* webView) WebKitWebViewPrivate* priv = webView->priv; ResourcesMap::const_iterator end = priv->subresourcesMap.end(); for (ResourcesMap::const_iterator it = priv->subresourcesMap.begin(); it != end; ++it) - subresources = g_list_prepend(subresources, it->second.get()); + subresources = g_list_prepend(subresources, it->value.get()); return g_list_reverse(subresources); } diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h index 8a397b752..ac2e2813f 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h @@ -191,170 +191,185 @@ struct _WebKitWebViewClass { }; WEBKIT_API GType -webkit_web_view_get_type (void); +webkit_web_view_get_type (void); WEBKIT_API GtkWidget * -webkit_web_view_new (void); +webkit_web_view_new (void); WEBKIT_API GtkWidget * -webkit_web_view_new_with_context (WebKitWebContext *context); +webkit_web_view_new_with_context (WebKitWebContext *context); WEBKIT_API WebKitWebContext * -webkit_web_view_get_context (WebKitWebView *web_view); +webkit_web_view_get_context (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_load_uri (WebKitWebView *web_view, - const gchar *uri); +webkit_web_view_load_uri (WebKitWebView *web_view, + const gchar *uri); WEBKIT_API void -webkit_web_view_load_html (WebKitWebView *web_view, - const gchar *content, - const gchar *base_uri); +webkit_web_view_load_html (WebKitWebView *web_view, + const gchar *content, + const gchar *base_uri); WEBKIT_API void -webkit_web_view_load_alternate_html (WebKitWebView *web_view, - const gchar *content, - const gchar *content_uri, - const gchar *base_uri); +webkit_web_view_load_alternate_html (WebKitWebView *web_view, + const gchar *content, + const gchar *content_uri, + const gchar *base_uri); WEBKIT_API void -webkit_web_view_load_plain_text (WebKitWebView *web_view, - const gchar *plain_text); +webkit_web_view_load_plain_text (WebKitWebView *web_view, + const gchar *plain_text); WEBKIT_API void -webkit_web_view_load_request (WebKitWebView *web_view, - WebKitURIRequest *request); +webkit_web_view_load_request (WebKitWebView *web_view, + WebKitURIRequest *request); WEBKIT_API void -webkit_web_view_stop_loading (WebKitWebView *web_view); +webkit_web_view_stop_loading (WebKitWebView *web_view); WEBKIT_API gboolean -webkit_web_view_is_loading (WebKitWebView *web_view); +webkit_web_view_is_loading (WebKitWebView *web_view); WEBKIT_API const gchar * -webkit_web_view_get_title (WebKitWebView *web_view); +webkit_web_view_get_title (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_reload (WebKitWebView *web_view); +webkit_web_view_reload (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_reload_bypass_cache (WebKitWebView *web_view); +webkit_web_view_reload_bypass_cache (WebKitWebView *web_view); WEBKIT_API gdouble -webkit_web_view_get_estimated_load_progress (WebKitWebView *web_view); +webkit_web_view_get_estimated_load_progress (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_go_back (WebKitWebView *web_view); +webkit_web_view_go_back (WebKitWebView *web_view); WEBKIT_API gboolean -webkit_web_view_can_go_back (WebKitWebView *web_view); +webkit_web_view_can_go_back (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_go_forward (WebKitWebView *web_view); +webkit_web_view_go_forward (WebKitWebView *web_view); WEBKIT_API gboolean -webkit_web_view_can_go_forward (WebKitWebView *web_view); +webkit_web_view_can_go_forward (WebKitWebView *web_view); WEBKIT_API WebKitBackForwardList * -webkit_web_view_get_back_forward_list (WebKitWebView *web_view); +webkit_web_view_get_back_forward_list (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_go_to_back_forward_list_item (WebKitWebView *web_view, - WebKitBackForwardListItem *list_item); +webkit_web_view_go_to_back_forward_list_item (WebKitWebView *web_view, + WebKitBackForwardListItem *list_item); WEBKIT_API const gchar * -webkit_web_view_get_uri (WebKitWebView *web_view); +webkit_web_view_get_uri (WebKitWebView *web_view); + +WEBKIT_API cairo_surface_t * +webkit_web_view_get_favicon (WebKitWebView *web_view); WEBKIT_API const gchar * -webkit_web_view_get_custom_charset (WebKitWebView *web_view); +webkit_web_view_get_custom_charset (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_set_custom_charset (WebKitWebView *web_view, - const gchar *charset); +webkit_web_view_set_custom_charset (WebKitWebView *web_view, + const gchar *charset); WEBKIT_API void -webkit_web_view_set_settings (WebKitWebView *web_view, - WebKitSettings *settings); +webkit_web_view_set_settings (WebKitWebView *web_view, + WebKitSettings *settings); WEBKIT_API WebKitSettings * -webkit_web_view_get_settings (WebKitWebView *web_view); +webkit_web_view_get_settings (WebKitWebView *web_view); WEBKIT_API WebKitWindowProperties * -webkit_web_view_get_window_properties (WebKitWebView *web_view); +webkit_web_view_get_window_properties (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_set_zoom_level (WebKitWebView *web_view, - gdouble zoom_level); +webkit_web_view_set_zoom_level (WebKitWebView *web_view, + gdouble zoom_level); WEBKIT_API gdouble -webkit_web_view_get_zoom_level (WebKitWebView *web_view); +webkit_web_view_get_zoom_level (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_can_execute_editing_command (WebKitWebView *web_view, - const gchar *command, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); +webkit_web_view_can_execute_editing_command (WebKitWebView *web_view, + const gchar *command, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); WEBKIT_API gboolean -webkit_web_view_can_execute_editing_command_finish (WebKitWebView *web_view, - GAsyncResult *result, - GError **error); +webkit_web_view_can_execute_editing_command_finish (WebKitWebView *web_view, + GAsyncResult *result, + GError **error); WEBKIT_API void -webkit_web_view_execute_editing_command (WebKitWebView *web_view, - const gchar *command); +webkit_web_view_execute_editing_command (WebKitWebView *web_view, + const gchar *command); WEBKIT_API WebKitFindController * -webkit_web_view_get_find_controller (WebKitWebView *web_view); +webkit_web_view_get_find_controller (WebKitWebView *web_view); WEBKIT_API JSGlobalContextRef -webkit_web_view_get_javascript_global_context (WebKitWebView *web_view); +webkit_web_view_get_javascript_global_context (WebKitWebView *web_view); WEBKIT_API void -webkit_web_view_run_javascript (WebKitWebView *web_view, - const gchar *script, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); +webkit_web_view_run_javascript (WebKitWebView *web_view, + const gchar *script, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +WEBKIT_API WebKitJavascriptResult * +webkit_web_view_run_javascript_finish (WebKitWebView *web_view, + GAsyncResult *result, + GError **error); + +WEBKIT_API void +webkit_web_view_run_javascript_from_gresource (WebKitWebView *web_view, + const gchar *resource, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); + WEBKIT_API WebKitJavascriptResult * -webkit_web_view_run_javascript_finish (WebKitWebView *web_view, - GAsyncResult *result, - GError **error); +webkit_web_view_run_javascript_from_gresource_finish (WebKitWebView *web_view, + GAsyncResult *result, + GError **error); WEBKIT_API WebKitWebResource * -webkit_web_view_get_main_resource (WebKitWebView *web_view); +webkit_web_view_get_main_resource (WebKitWebView *web_view); WEBKIT_API GList * -webkit_web_view_get_subresources (WebKitWebView *web_view); +webkit_web_view_get_subresources (WebKitWebView *web_view); WEBKIT_API WebKitWebInspector * -webkit_web_view_get_inspector (WebKitWebView *web_view); +webkit_web_view_get_inspector (WebKitWebView *web_view); WEBKIT_API gboolean -webkit_web_view_can_show_mime_type (WebKitWebView *web_view, - const gchar *mime_type); +webkit_web_view_can_show_mime_type (WebKitWebView *web_view, + const gchar *mime_type); WEBKIT_API void -webkit_web_view_save (WebKitWebView *web_view, - WebKitSaveMode save_mode, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); +webkit_web_view_save (WebKitWebView *web_view, + WebKitSaveMode save_mode, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); WEBKIT_API GInputStream * -webkit_web_view_save_finish (WebKitWebView *web_view, - GAsyncResult *result, - GError **error); +webkit_web_view_save_finish (WebKitWebView *web_view, + GAsyncResult *result, + GError **error); WEBKIT_API void -webkit_web_view_save_to_file (WebKitWebView *web_view, - GFile *file, - WebKitSaveMode save_mode, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); +webkit_web_view_save_to_file (WebKitWebView *web_view, + GFile *file, + WebKitSaveMode save_mode, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); WEBKIT_API gboolean -webkit_web_view_save_to_file_finish (WebKitWebView *web_view, - GAsyncResult *result, - GError **error); +webkit_web_view_save_to_file_finish (WebKitWebView *web_view, + GAsyncResult *result, + GError **error); G_END_DECLS diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp index b42b2ee8f..e5bac671e 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp @@ -75,6 +75,10 @@ using namespace WebCore; typedef HashMap<GtkWidget*, IntRect> WebKitWebViewChildrenMap; +#if USE(TEXTURE_MAPPER_GL) +void redirectedWindowDamagedCallback(void* data); +#endif + struct _WebKitWebViewBasePrivate { WebKitWebViewChildrenMap children; OwnPtr<PageClientImpl> pageClient; @@ -111,7 +115,6 @@ struct _WebKitWebViewBasePrivate { #if USE(TEXTURE_MAPPER_GL) OwnPtr<RedirectedXCompositeWindow> redirectedWindow; - bool readyToRenderAcceleratedCompositingResults; #endif }; @@ -300,7 +303,7 @@ static void webkitWebViewBaseContainerForall(GtkContainer* container, gboolean i WebKitWebViewChildrenMap children = priv->children; WebKitWebViewChildrenMap::const_iterator end = children.end(); for (WebKitWebViewChildrenMap::const_iterator current = children.begin(); current != end; ++current) - (*callback)(current->first, callbackData); + (*callback)(current->key, callbackData); if (includeInternals && priv->inspectorView) (*callback)(priv->inspectorView, callbackData); @@ -351,7 +354,8 @@ static void webkit_web_view_base_init(WebKitWebViewBase* webkitWebViewBase) #if USE(TEXTURE_MAPPER_GL) priv->redirectedWindow = RedirectedXCompositeWindow::create(IntSize(1, 1)); - priv->readyToRenderAcceleratedCompositingResults = false; + if (priv->redirectedWindow) + priv->redirectedWindow->setDamageNotifyCallback(redirectedWindowDamagedCallback, webkitWebViewBase); #endif } @@ -364,10 +368,9 @@ static bool webkitWebViewRenderAcceleratedCompositingResults(WebKitWebViewBase* // To avoid flashes when initializing accelerated compositing for the first // time, we wait until we know there's a frame ready before rendering. WebKitWebViewBasePrivate* priv = webViewBase->priv; - if (!priv->readyToRenderAcceleratedCompositingResults) + if (!priv->redirectedWindow) return false; - ASSERT(priv->redirectedWindow); cairo_rectangle(cr, clipRect->x, clipRect->y, clipRect->width, clipRect->height); cairo_surface_t* surface = priv->redirectedWindow->cairoSurfaceForWidget(GTK_WIDGET(webViewBase)); cairo_set_source_surface(cr, surface, 0, 0); @@ -430,7 +433,7 @@ static void resizeWebKitWebViewBaseFromAllocation(WebKitWebViewBase* webViewBase } #if USE(TEXTURE_MAPPER_GL) - if (sizeChanged) + if (sizeChanged && webViewBase->priv->redirectedWindow) webViewBase->priv->redirectedWindow->resize(viewRect.size()); #endif @@ -801,7 +804,8 @@ void webkitWebViewBaseCreateWebPage(WebKitWebViewBase* webkitWebViewBase, WebCon #endif #if USE(TEXTURE_MAPPER_GL) - priv->pageProxy->setAcceleratedCompositingWindowId(priv->redirectedWindow->windowId()); + if (priv->redirectedWindow) + priv->pageProxy->setAcceleratedCompositingWindowId(priv->redirectedWindow->windowId()); #endif } @@ -928,37 +932,9 @@ GdkEvent* webkitWebViewBaseTakeContextMenuEvent(WebKitWebViewBase* webkitWebView } #if USE(TEXTURE_MAPPER_GL) -static gboolean queueAnotherDrawOfAcceleratedCompositingResults(gpointer* webViewBasePointer) +void redirectedWindowDamagedCallback(void* data) { - // The WebViewBase may have been destroyed in the time since we queued this - // draw and the time we are actually executing. - if (!*webViewBasePointer) { - fastFree(webViewBasePointer); - return FALSE; - } - - WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(*webViewBasePointer); - gtk_widget_queue_draw(GTK_WIDGET(webViewBase)); - webViewBase->priv->readyToRenderAcceleratedCompositingResults = true; - - g_object_remove_weak_pointer(G_OBJECT(webViewBase), webViewBasePointer); - fastFree(webViewBasePointer); - - return FALSE; -} - -void webkitWebViewBaseQueueDrawOfAcceleratedCompositingResults(WebKitWebViewBase* webViewBase) -{ - gtk_widget_queue_draw(GTK_WIDGET(webViewBase)); - - // Redraw again, one frame later, as it might take some time for the new GL frame to be available. - // This prevents the display from always being one frame behind in the case GL hasn't yet finished - // rendering to the window. - // TODO: Add XDamage support to RedirectedXCompositeWindow to accomplish this. - gpointer* webViewBasePointer = static_cast<gpointer*>(fastMalloc(sizeof(gpointer))); - g_object_add_weak_pointer(G_OBJECT(webViewBase), webViewBasePointer); - *webViewBasePointer = webViewBase; - g_timeout_add(1000 / 60, reinterpret_cast<GSourceFunc>(queueAnotherDrawOfAcceleratedCompositingResults), webViewBasePointer); + gtk_widget_queue_draw(GTK_WIDGET(data)); } #endif diff --git a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml index a7f34e6d1..8623af33e 100644 --- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml +++ b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml @@ -30,6 +30,7 @@ <xi:include href="xml/WebKitPrintOperation.xml"/> <xi:include href="xml/WebKitWebResource.xml"/> <xi:include href="xml/WebKitError.xml"/> + <xi:include href="xml/WebKitFaviconDatabase.xml"/> <xi:include href="xml/WebKitFileChooserRequest.xml"/> <xi:include href="xml/WebKitFindController.xml"/> <xi:include href="xml/WebKitCookieManager.xml"/> diff --git a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt index 1827b6b16..f56267b9a 100644 --- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt +++ b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt @@ -30,6 +30,9 @@ webkit_web_context_set_cache_model webkit_web_context_clear_cache webkit_web_context_download_uri webkit_web_context_get_cookie_manager +webkit_web_context_get_favicon_database +webkit_web_context_set_favicon_database_directory +webkit_web_context_get_favicon_database_directory webkit_web_context_get_security_manager webkit_web_context_set_additional_plugins_directory webkit_web_context_get_plugins @@ -98,6 +101,7 @@ webkit_web_view_set_custom_charset webkit_web_view_get_back_forward_list webkit_web_view_go_to_back_forward_list_item webkit_web_view_get_uri +webkit_web_view_get_favicon webkit_web_view_set_settings webkit_web_view_get_settings webkit_web_view_get_window_properties @@ -111,6 +115,8 @@ webkit_web_view_get_inspector webkit_web_view_get_javascript_global_context webkit_web_view_run_javascript webkit_web_view_run_javascript_finish +webkit_web_view_run_javascript_from_gresource +webkit_web_view_run_javascript_from_gresource_finish webkit_web_view_can_show_mime_type webkit_web_view_save webkit_web_view_save_finish @@ -291,6 +297,8 @@ webkit_settings_set_enable_page_cache webkit_settings_get_user_agent webkit_settings_set_user_agent webkit_settings_set_user_agent_with_application_details +webkit_settings_get_enable_smooth_scrolling +webkit_settings_set_enable_smooth_scrolling <SUBSECTION Standard> WebKitSettingsClass @@ -602,6 +610,31 @@ webkit_javascript_error_quark </SECTION> <SECTION> +<FILE>WebKitFaviconDatabase</FILE> +WebKitFaviconDatabase +WEBKIT_FAVICON_DATABASE_ERROR +WebKitFaviconDatabaseError +webkit_favicon_database_get_favicon +webkit_favicon_database_get_favicon_finish +webkit_favicon_database_get_favicon_uri +webkit_favicon_database_clear + +<SUBSECTION Standard> +WebKitFaviconDatabaseClass +WEBKIT_TYPE_FAVICON_DATABASE +WEBKIT_FAVICON_DATABASE +WEBKIT_IS_FAVICON_DATABASE +WEBKIT_FAVICON_DATABASE_CLASS +WEBKIT_IS_FAVICON_DATABASE_CLASS +WEBKIT_FAVICON_DATABASE_GET_CLASS + +<SUBSECTION Private> +WebKitFaviconDatabasePrivate +webkit_favicon_database_get_type +webkit_favicon_database_error_quark +</SECTION> + +<SECTION> <FILE>WebKitFileChooserRequest</FILE> WebKitFileChooserRequest webkit_file_chooser_request_get_mime_types @@ -745,6 +778,7 @@ WebKitURISchemeRequest webkit_uri_scheme_request_get_scheme webkit_uri_scheme_request_get_uri webkit_uri_scheme_request_get_path +webkit_uri_scheme_request_get_web_view webkit_uri_scheme_request_finish <SUBSECTION Standard> diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am b/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am index 3fadf40b4..06ea1af7c 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am +++ b/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am @@ -11,6 +11,7 @@ TEST_PROGS += \ Programs/WebKit2APITests/TestResources \ Programs/WebKit2APITests/TestSSL \ Programs/WebKit2APITests/TestWebKitVersion \ + Programs/WebKit2APITests/TestWebKitFaviconDatabase \ Programs/WebKit2APITests/TestWebKitFindController \ Programs/WebKit2APITests/TestWebKitPolicyClient \ Programs/WebKit2APITests/TestWebKitSettings \ @@ -29,6 +30,7 @@ endif webkit2_tests_cppflags = \ -DWEBKIT_EXEC_PATH=\"${shell pwd}/$(top_builddir)/Programs\" \ -DWEBKIT_SRC_DIR=\"${shell pwd}/${srcdir}\" \ + -DWEBKIT_DERIVED_SRC_DIR=\"${shell pwd}/${top_builddir}/DerivedSources\" \ $(javascriptcore_cppflags) \ -I$(srcdir)/Source/JavaScriptCore \ -I$(srcdir)/Source \ @@ -55,6 +57,12 @@ webkit2_tests_ldflags = \ -no-install \ -no-fast-install +DerivedSources/WebKit2/webkit2gtk-tests-resources.gresource: Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies $(srcdir)/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml) + $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) $< + +DISTCLEANFILES += DerivedSources/WebKit2/webkit2gtk-tests-resources.gresource +noinst_DATA += DerivedSources/WebKit2/webkit2gtk-tests-resources.gresource + noinst_LTLIBRARIES += Libraries/libWebKit2APITestCore.la Libraries_libWebKit2APITestCore_la_SOURCES = \ Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp \ @@ -69,7 +77,9 @@ Libraries_libWebKit2APITestCore_la_CPPFLAGS = $(webkit2_tests_cppflags) EXTRA_DIST += \ Source/WebKit2/UIProcess/API/gtk/tests/resources/test-cert.pem \ - Source/WebKit2/UIProcess/API/gtk/tests/resources/test-key.pem + Source/WebKit2/UIProcess/API/gtk/tests/resources/test-key.pem \ + Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml \ + Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js Programs_WebKit2APITests_TestWebKitWebContext_SOURCES = \ Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp @@ -141,6 +151,12 @@ Programs_WebKit2APITests_TestPrinting_CPPFLAGS = $(webkit2_tests_cppflags) $(GTK Programs_WebKit2APITests_TestPrinting_LDADD = $(webkit2_tests_ldadd) $(GTK_UNIX_PRINTING_LIBS) Programs_WebKit2APITests_TestPrinting_LDFLAGS = $(webkit2_tests_ldflags) +Programs_WebKit2APITests_TestWebKitFaviconDatabase_SOURCES = \ + Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp +Programs_WebKit2APITests_TestWebKitFaviconDatabase_CPPFLAGS = $(webkit2_tests_cppflags) +Programs_WebKit2APITests_TestWebKitFaviconDatabase_LDADD = $(webkit2_tests_ldadd) +Programs_WebKit2APITests_TestWebKitFaviconDatabase_LDFLAGS = $(webkit2_tests_ldflags) + Programs_WebKit2APITests_TestWebKitFindController_SOURCES = \ Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp Programs_WebKit2APITests_TestWebKitFindController_CPPFLAGS = $(webkit2_tests_cppflags) diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp index e70e391ff..b479366a4 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp @@ -38,6 +38,11 @@ static void serverCallback(SoupServer* server, SoupMessage* msg, const char* pat return; } + if (g_str_has_suffix(path, "favicon.ico")) { + soup_message_set_status(msg, SOUP_STATUS_NOT_FOUND); + return; + } + soup_message_set_status(msg, SOUP_STATUS_OK); char* body = g_strdup_printf("<html><title>%s</title><body>%s</body></html>", path + 1, path + 1); diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp index 2fe8998b5..94aeef6e1 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp @@ -295,7 +295,7 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char* } else if (g_str_equal(path, "/image.png")) soup_message_headers_replace(message->response_headers, "Set-Cookie", "baz=qux; Max-Age=60"); else - g_assert_not_reached(); + soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); soup_message_body_complete(message->response_body); } diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp index c3a14193d..8fcf33009 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp @@ -312,7 +312,8 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char* soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString)); soup_server_unpause_message(server, message); return; - } + } else + soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); soup_message_body_complete(message->response_body); } diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp index 8622af19c..9db47f82b 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp @@ -25,12 +25,24 @@ void beforeAll(); void afterAll(); +static void registerGResource(void) +{ + GOwnPtr<char> resourcesPath(g_build_filename(WEBKIT_DERIVED_SRC_DIR, "WebKit2", "webkit2gtk-tests-resources.gresource", NULL)); + GResource* resource = g_resource_load(resourcesPath.get(), 0); + g_assert(resource); + + g_resources_register(resource); + g_resource_unref(resource); +} + int main(int argc, char** argv) { gtk_test_init(&argc, &argv, 0); g_setenv("WEBKIT_EXEC_PATH", WEBKIT_EXEC_PATH, FALSE); g_test_bug_base("https://bugs.webkit.org/"); + registerGResource(); + beforeAll(); int returnValue = g_test_run(); afterAll(); diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp index 7e2e5de61..20b90b0b4 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp @@ -80,6 +80,11 @@ public: { test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(resource)); test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request)); + + // Ignore favicons. + if (g_str_has_suffix(webkit_uri_request_get_uri(request), "favicon.ico")) + return; + test->resourceLoadStarted(resource, request); g_signal_connect(resource, "sent-request", G_CALLBACK(resourceSentRequestCallback), test); g_signal_connect(resource, "notify::response", G_CALLBACK(resourceReceivedResponseCallback), test); @@ -507,21 +512,31 @@ static void testWebResourceGetData(ResourcesTest* test, gconstpointer) static void testWebViewResourcesHistoryCache(SingleResourceLoadTest* test, gconstpointer) { - test->loadURI(kServer->getURIForPath("/").data()); + CString javascriptURI = kServer->getURIForPath("/javascript.html"); + test->loadURI(javascriptURI.data()); test->waitUntilResourceLoadFinished(); - g_assert(webkit_web_view_get_main_resource(test->m_webView)); + WebKitWebResource* resource = webkit_web_view_get_main_resource(test->m_webView); + g_assert(resource); + g_assert_cmpstr(webkit_web_resource_get_uri(resource), ==, javascriptURI.data()); - test->loadURI(kServer->getURIForPath("/javascript.html").data()); + CString simpleStyleCSSURI = kServer->getURIForPath("/simple-style-css.html"); + test->loadURI(simpleStyleCSSURI.data()); test->waitUntilResourceLoadFinished(); - g_assert(webkit_web_view_get_main_resource(test->m_webView)); + resource = webkit_web_view_get_main_resource(test->m_webView); + g_assert(resource); + g_assert_cmpstr(webkit_web_resource_get_uri(resource), ==, simpleStyleCSSURI.data()); test->goBack(); test->waitUntilResourceLoadFinished(); - g_assert(webkit_web_view_get_main_resource(test->m_webView)); + resource = webkit_web_view_get_main_resource(test->m_webView); + g_assert(resource); + g_assert_cmpstr(webkit_web_resource_get_uri(resource), ==, javascriptURI.data()); test->goForward(); test->waitUntilResourceLoadFinished(); - g_assert(webkit_web_view_get_main_resource(test->m_webView)); + resource = webkit_web_view_get_main_resource(test->m_webView); + g_assert(resource); + g_assert_cmpstr(webkit_web_resource_get_uri(resource), ==, simpleStyleCSSURI.data()); } static void addCacheHTTPHeadersToResponse(SoupMessage* message) @@ -567,6 +582,9 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char* } else if (g_str_equal(path, "/invalid-css.html")) { static const char* invalidCSSHtml = "<html><head><link rel='stylesheet' href='/invalid.css' type='text/css'></head><body></html>"; soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, invalidCSSHtml, strlen(invalidCSSHtml)); + } else if (g_str_equal(path, "/simple-style-css.html")) { + static const char* simpleStyleCSSHtml = "<html><head><link rel='stylesheet' href='/simple-style.css' type='text/css'></head><body></html>"; + soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, simpleStyleCSSHtml, strlen(simpleStyleCSSHtml)); } else if (g_str_equal(path, "/style.css")) { soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, kStyleCSS, strlen(kStyleCSS)); addCacheHTTPHeadersToResponse(message); @@ -594,6 +612,8 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char* soup_message_headers_append(message->response_headers, "Location", "/simple-style.css"); } else if (g_str_equal(path, "/invalid.css")) soup_message_set_status(message, SOUP_STATUS_CANT_CONNECT); + else + soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); soup_message_body_complete(message->response_body); } diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp index 40e9fbeee..8fa013dc4 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp @@ -82,9 +82,12 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char* return; } - soup_message_set_status(message, SOUP_STATUS_OK); - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, indexHTML, strlen(indexHTML)); - soup_message_body_complete(message->response_body); + if (g_str_equal(path, "/")) { + soup_message_set_status(message, SOUP_STATUS_OK); + soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, indexHTML, strlen(indexHTML)); + soup_message_body_complete(message->response_body); + } else + soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); } void beforeAll() diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp new file mode 100644 index 000000000..40fb5a17a --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp @@ -0,0 +1,246 @@ +/* + * Copyright (C) 2012 Igalia S.L. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2,1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#include "WebKitTestServer.h" +#include "WebViewTest.h" +#include <glib/gstdio.h> +#include <libsoup/soup.h> +#include <wtf/gobject/GOwnPtr.h> + +static WebKitTestServer* kServer; +static char* kTempDirectory; + +class FaviconDatabaseTest: public WebViewTest { +public: + MAKE_GLIB_TEST_FIXTURE(FaviconDatabaseTest); + + FaviconDatabaseTest() + : m_webContext(webkit_web_context_get_default()) + , m_favicon(0) + , m_error(0) + , m_iconReadySignalReceived(false) + , m_faviconNotificationReceived(false) + { + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(m_webContext); + g_signal_connect(database, "favicon-ready", G_CALLBACK(iconReadyCallback), this); + } + + ~FaviconDatabaseTest() + { + if (m_favicon) + cairo_surface_destroy(m_favicon); + + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(m_webContext); + g_signal_handlers_disconnect_matched(database, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); + } + + static void iconReadyCallback(WebKitFaviconDatabase* database, const char* pageURI, FaviconDatabaseTest* test) + { + g_assert_cmpstr(webkit_web_view_get_uri(test->m_webView), ==, pageURI); + test->m_iconReadySignalReceived = true; + } + + static void faviconChangedCallback(WebKitWebView* webView, GParamSpec* pspec, gpointer data) + { + FaviconDatabaseTest* test = static_cast<FaviconDatabaseTest*>(data); + g_assert(test->m_webView == webView); + test->m_faviconNotificationReceived = true; + test->quitMainLoop(); + } + + static void getFaviconCallback(GObject* sourceObject, GAsyncResult* result, void* data) + { + FaviconDatabaseTest* test = static_cast<FaviconDatabaseTest*>(data); + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext); + test->m_favicon = webkit_favicon_database_get_favicon_finish(database, result, &test->m_error.outPtr()); + test->quitMainLoop(); + } + + void waitUntilFaviconChanged() + { + m_faviconNotificationReceived = false; + unsigned long handlerID = g_signal_connect(m_webView, "notify::favicon", G_CALLBACK(faviconChangedCallback), this); + g_main_loop_run(m_mainLoop); + g_signal_handler_disconnect(m_webView, handlerID); + } + + void getFaviconForPageURIAndWaitUntilReady(const char* pageURI) + { + m_error.clear(); + if (m_favicon) { + cairo_surface_destroy(m_favicon); + m_favicon = 0; + } + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(m_webContext); + webkit_favicon_database_get_favicon(database, pageURI, 0, getFaviconCallback, this); + g_main_loop_run(m_mainLoop); + } + + WebKitWebContext* m_webContext; + cairo_surface_t* m_favicon; + GOwnPtr<GError> m_error; + bool m_iconReadySignalReceived; + bool m_faviconNotificationReceived; +}; + +static void +serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable* query, SoupClientContext* context, void* data) +{ + if (message->method != SOUP_METHOD_GET) { + soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); + return; + } + + char* contents; + gsize length; + if (g_str_equal(path, "/favicon.ico")) { + GOwnPtr<char> pathToFavicon(g_build_filename(Test::getWebKit1TestResoucesDir().data(), "blank.ico", NULL)); + g_file_get_contents(pathToFavicon.get(), &contents, &length, 0); + } else if (g_str_equal(path, "/nofavicon/favicon.ico")) { + soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); + soup_message_body_complete(message->response_body); + return; + } else { + contents = g_strdup("<html><body>test</body></html>"); + length = strlen(contents); + } + + soup_message_set_status(message, SOUP_STATUS_OK); + soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, length); + soup_message_body_complete(message->response_body); +} + +static void testNotInitialized(FaviconDatabaseTest* test, gconstpointer) +{ + // Try to retrieve a valid favicon from a not initialized database. + test->getFaviconForPageURIAndWaitUntilReady(kServer->getURIForPath("/").data()); + g_assert(!test->m_favicon); + g_assert(test->m_error); + g_assert_cmpint(test->m_error->code, ==, WEBKIT_FAVICON_DATABASE_ERROR_NOT_INITIALIZED); +} + +static void testSetDirectory(FaviconDatabaseTest* test, gconstpointer) +{ + webkit_web_context_set_favicon_database_directory(test->m_webContext, kTempDirectory); + g_assert_cmpstr(kTempDirectory, ==, webkit_web_context_get_favicon_database_directory(test->m_webContext)); +} + +static void testClearDatabase(FaviconDatabaseTest* test, gconstpointer) +{ + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext); + webkit_favicon_database_clear(database); + + GOwnPtr<char> iconURI(webkit_favicon_database_get_favicon_uri(database, kServer->getURIForPath("/").data())); + g_assert(!iconURI); +} + +static void testGetFavicon(FaviconDatabaseTest* test, gconstpointer) +{ + // We need to load the page first to ensure the icon data will be + // in the database in case there's an associated favicon. + test->loadURI(kServer->getURIForPath("/").data()); + test->waitUntilFaviconChanged(); + g_assert(test->m_iconReadySignalReceived); + + // Check the API retrieving a valid favicon. + test->m_iconReadySignalReceived = false; + test->getFaviconForPageURIAndWaitUntilReady(kServer->getURIForPath("/").data()); + g_assert(test->m_favicon); + g_assert(!test->m_error); + g_assert(!test->m_iconReadySignalReceived); + + // Check that width and height match those from blank.ico (16x16 favicon). + g_assert_cmpint(cairo_image_surface_get_width(test->m_favicon), ==, 16); + g_assert_cmpint(cairo_image_surface_get_height(test->m_favicon), ==, 16); + + // Check the API retrieving an invalid favicon. + test->loadURI(kServer->getURIForPath("/nofavicon").data()); + test->waitUntilFaviconChanged(); + g_assert(!test->m_iconReadySignalReceived); + + test->getFaviconForPageURIAndWaitUntilReady(kServer->getURIForPath("/nofavicon/").data()); + g_assert(!test->m_favicon); + g_assert(test->m_error); + g_assert(!test->m_iconReadySignalReceived); +} + +static void testGetFaviconURI(FaviconDatabaseTest* test, gconstpointer) +{ + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext); + + const char* baseURI = kServer->getURIForPath("/").data(); + GOwnPtr<char> iconURI(webkit_favicon_database_get_favicon_uri(database, baseURI)); + g_assert_cmpstr(iconURI.get(), ==, kServer->getURIForPath("/favicon.ico").data()); +} + +static void testWebViewFavicon(FaviconDatabaseTest* test, gconstpointer) +{ + cairo_surface_t* iconFromWebView = webkit_web_view_get_favicon(test->m_webView); + g_assert(!iconFromWebView); + + test->loadURI(kServer->getURIForPath("/").data()); + test->waitUntilFaviconChanged(); + g_assert(test->m_faviconNotificationReceived); + + iconFromWebView = webkit_web_view_get_favicon(test->m_webView); + g_assert(iconFromWebView); + g_assert_cmpuint(cairo_image_surface_get_width(iconFromWebView), ==, 16); + g_assert_cmpuint(cairo_image_surface_get_height(iconFromWebView), ==, 16); +} + +void beforeAll() +{ + // Start a soup server for testing. + kServer = new WebKitTestServer(); + kServer->run(serverCallback); + + kTempDirectory = g_dir_make_tmp("WebKit2Tests-XXXXXX", 0); + g_assert(kTempDirectory); + + // Add tests to the suite. + FaviconDatabaseTest::add("WebKitFaviconDatabase", "not-initialized", testNotInitialized); + FaviconDatabaseTest::add("WebKitFaviconDatabase", "set-directory", testSetDirectory); + FaviconDatabaseTest::add("WebKitFaviconDatabase", "get-favicon", testGetFavicon); + FaviconDatabaseTest::add("WebKitFaviconDatabase", "get-favicon-uri", testGetFaviconURI); + FaviconDatabaseTest::add("WebKitFaviconDatabase", "clear-database", testClearDatabase); + FaviconDatabaseTest::add("WebKitWebView", "favicon", testWebViewFavicon); +} + +static void webkitFaviconDatabaseFinalizedCallback(gpointer, GObject*) +{ + if (!g_file_test(kTempDirectory, G_FILE_TEST_IS_DIR)) + return; + + GOwnPtr<char> filename(g_build_filename(kTempDirectory, "WebpageIcons.db", NULL)); + g_unlink(filename.get()); + + g_rmdir(kTempDirectory); +} + +void afterAll() +{ + delete kServer; + + // Delete the temporary files after the IconDatabase has been + // closed, that is, once WebKitFaviconDatabase is being destroyed. + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(webkit_web_context_get_default()); + g_object_weak_ref(G_OBJECT(database), webkitFaviconDatabaseFinalizedCallback, 0); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp index 9f6ce7819..abbfd652a 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp @@ -232,11 +232,13 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char* return; } - soup_message_set_status(message, SOUP_STATUS_OK); - - static const char* responseString = "<html><body>Testing!</body></html>"; - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString)); - soup_message_body_complete(message->response_body); + if (g_str_equal(path, "/")) { + static const char* responseString = "<html><body>Testing!</body></html>"; + soup_message_set_status(message, SOUP_STATUS_OK); + soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString)); + soup_message_body_complete(message->response_body); + } else + soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); } void beforeAll() diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp index d8e355472..c7a0dc259 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp @@ -243,6 +243,11 @@ static void testWebKitSettings(Test*, gconstpointer) webkit_settings_set_enable_page_cache(settings, FALSE); g_assert(!webkit_settings_get_enable_page_cache(settings)); + // By default, smooth scrolling is disabled. + g_assert(!webkit_settings_get_enable_smooth_scrolling(settings)); + webkit_settings_set_enable_smooth_scrolling(settings, TRUE); + g_assert(webkit_settings_get_enable_smooth_scrolling(settings)); + g_object_unref(G_OBJECT(settings)); } @@ -315,10 +320,13 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char* return; } - soup_message_set_status(message, SOUP_STATUS_OK); - const char* userAgent = soup_message_headers_get_one(message->request_headers, "User-Agent"); - soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, userAgent, strlen(userAgent)); - soup_message_body_complete(message->response_body); + if (g_str_equal(path, "/")) { + const char* userAgent = soup_message_headers_get_one(message->request_headers, "User-Agent"); + soup_message_set_status(message, SOUP_STATUS_OK); + soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, userAgent, strlen(userAgent)); + soup_message_body_complete(message->response_body); + } else + soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); } void beforeAll() diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp index 7a13d285d..185c06cfe 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp @@ -146,6 +146,8 @@ public: test->m_uriSchemeRequest = request; test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request)); + g_assert(webkit_uri_scheme_request_get_web_view(request) == test->m_webView); + GRefPtr<GInputStream> inputStream = adoptGRef(g_memory_input_stream_new()); test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(inputStream.get())); @@ -291,10 +293,13 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char* return; } - soup_message_set_status(message, SOUP_STATUS_OK); - const char* acceptLanguage = soup_message_headers_get_one(message->request_headers, "Accept-Language"); - soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, acceptLanguage, strlen(acceptLanguage)); - soup_message_body_complete(message->response_body); + if (g_str_equal(path, "/")) { + const char* acceptLanguage = soup_message_headers_get_one(message->request_headers, "Accept-Language"); + soup_message_set_status(message, SOUP_STATUS_OK); + soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, acceptLanguage, strlen(acceptLanguage)); + soup_message_body_complete(message->response_body); + } else + soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); } class SecurityPolicyTest: public Test { diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp index 02e8138de..f5197b936 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp @@ -643,6 +643,17 @@ static void testWebViewRunJavaScript(WebViewTest* test, gconstpointer) g_assert(!error.get()); g_assert(WebViewTest::javascriptResultIsUndefined(javascriptResult)); + javascriptResult = test->runJavaScriptFromGResourceAndWaitUntilFinished("/org/webkit/webkit2gtk/tests/link-title.js", &error.outPtr()); + g_assert(javascriptResult); + g_assert(!error.get()); + valueString.set(WebViewTest::javascriptResultToCString(javascriptResult)); + g_assert_cmpstr(valueString.get(), ==, "WebKitGTK+ Title"); + + javascriptResult = test->runJavaScriptFromGResourceAndWaitUntilFinished("/wrong/path/to/resource.js", &error.outPtr()); + g_assert(!javascriptResult); + g_assert_error(error.get(), G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND); + error.clear(); + javascriptResult = test->runJavaScriptAndWaitUntilFinished("foo();", &error.outPtr()); g_assert(!javascriptResult); g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED); diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp index 04747480e..7e7eb0167 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp @@ -313,6 +313,12 @@ static void runJavaScriptReadyCallback(GObject*, GAsyncResult* result, WebViewTe g_main_loop_quit(test->m_mainLoop); } +static void runJavaScriptFromGResourceReadyCallback(GObject*, GAsyncResult* result, WebViewTest* test) +{ + test->m_javascriptResult = webkit_web_view_run_javascript_from_gresource_finish(test->m_webView, result, test->m_javascriptError); + g_main_loop_quit(test->m_mainLoop); +} + WebKitJavascriptResult* WebViewTest::runJavaScriptAndWaitUntilFinished(const char* javascript, GError** error) { if (m_javascriptResult) @@ -325,6 +331,18 @@ WebKitJavascriptResult* WebViewTest::runJavaScriptAndWaitUntilFinished(const cha return m_javascriptResult; } +WebKitJavascriptResult* WebViewTest::runJavaScriptFromGResourceAndWaitUntilFinished(const char* resource, GError** error) +{ + if (m_javascriptResult) + webkit_javascript_result_unref(m_javascriptResult); + m_javascriptResult = 0; + m_javascriptError = error; + webkit_web_view_run_javascript_from_gresource(m_webView, resource, 0, reinterpret_cast<GAsyncReadyCallback>(runJavaScriptFromGResourceReadyCallback), this); + g_main_loop_run(m_mainLoop); + + return m_javascriptResult; +} + static char* jsValueToCString(JSGlobalContextRef context, JSValueRef value) { g_assert(value); diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h index 25209caa3..06f398f96 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h +++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h @@ -55,6 +55,7 @@ public: void keyStroke(unsigned int keyVal, unsigned int keyModifiers = 0); WebKitJavascriptResult* runJavaScriptAndWaitUntilFinished(const char* javascript, GError**); + WebKitJavascriptResult* runJavaScriptFromGResourceAndWaitUntilFinished(const char* resource, GError**); // Javascript result helpers. static char* javascriptResultToCString(WebKitJavascriptResult*); diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js b/Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js new file mode 100644 index 000000000..2c824da38 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js @@ -0,0 +1 @@ +window.document.getElementById('WebKitLink').title; diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml b/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml new file mode 100644 index 000000000..4f1e5a654 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/org/webkit/webkit2gtk/tests/"> + <file alias="link-title.js">Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js</file> + </gresource> +</gresources> diff --git a/Source/WebKit2/UIProcess/API/gtk/webkit2.h b/Source/WebKit2/UIProcess/API/gtk/webkit2.h index e1f3ba04a..1b4fa86a1 100644 --- a/Source/WebKit2/UIProcess/API/gtk/webkit2.h +++ b/Source/WebKit2/UIProcess/API/gtk/webkit2.h @@ -34,6 +34,7 @@ #include <webkit2/WebKitEditingCommands.h> #include <webkit2/WebKitEnumTypes.h> #include <webkit2/WebKitError.h> +#include <webkit2/WebKitFaviconDatabase.h> #include <webkit2/WebKitFileChooserRequest.h> #include <webkit2/WebKitFindController.h> #include <webkit2/WebKitFormSubmissionRequest.h> diff --git a/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextGroup.h b/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextGroup.h index f3428fc93..f26c952c0 100644 --- a/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextGroup.h +++ b/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextGroup.h @@ -36,6 +36,11 @@ WK_EXPORT - (id)initWithIdentifier:(NSString *)identifier; +/* User Content */ + +- (void)addUserStyleSheet:(NSString *)source baseURL:(NSURL *)baseURL whitelist:(NSArray *)whitelist blacklist:(NSArray *)blacklist mainFrameOnly:(BOOL)mainFrameOnly; +- (void)removeAllUserStyleSheets; + /* Settings */ diff --git a/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextGroup.mm b/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextGroup.mm index 338d390ca..87cffd0e7 100644 --- a/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextGroup.mm +++ b/Source/WebKit2/UIProcess/API/mac/WKBrowsingContextGroup.mm @@ -27,10 +27,14 @@ #import "WKBrowsingContextGroup.h" #import "WKBrowsingContextGroupInternal.h" +#import "WKArray.h" #import "WKPageGroup.h" #import "WKPreferences.h" #import "WKRetainPtr.h" #import "WKStringCF.h" +#import "WKURL.h" +#import "WKURLCF.h" +#import <wtf/Vector.h> @interface WKBrowsingContextGroupData : NSObject { @public @@ -81,6 +85,43 @@ WKPreferencesSetPluginsEnabled(WKPageGroupGetPreferences(self._pageGroupRef), allowsPlugIns); } +static WKArrayRef createWKArray(NSArray *array) +{ + NSUInteger count = [array count]; + if (count == 0) + return WKArrayRef(); + + Vector<WKTypeRef> stringVector; + stringVector.reserveInitialCapacity(count); + for (NSUInteger i = 0; i < count; ++i) { + id entry = [array objectAtIndex:i]; + if ([entry isKindOfClass:[NSString class]]) + stringVector.uncheckedAppend(WKStringCreateWithCFString((CFStringRef)entry)); + + } + + return WKArrayCreateAdoptingValues(stringVector.data(), stringVector.size()); +} + +-(void)addUserStyleSheet:(NSString *)source baseURL:(NSURL *)baseURL whitelist:(NSArray *)whitelist blacklist:(NSArray *)blacklist mainFrameOnly:(BOOL)mainFrameOnly +{ + if (!source) + return; + + WKRetainPtr<WKStringRef> wkSource = adoptWK(WKStringCreateWithCFString((CFStringRef)source)); + WKRetainPtr<WKURLRef> wkBaseURL = adoptWK(WKURLCreateWithCFURL((CFURLRef)baseURL)); + WKRetainPtr<WKArrayRef> wkWhitelist = adoptWK(createWKArray(whitelist)); + WKRetainPtr<WKArrayRef> wkBlacklist = adoptWK(createWKArray(blacklist)); + WKUserContentInjectedFrames injectedFrames = mainFrameOnly ? kWKInjectInTopFrameOnly : kWKInjectInAllFrames; + + WKPageGroupAddUserStyleSheet(self._pageGroupRef, wkSource.get(), wkBaseURL.get(), wkWhitelist.get(), wkBlacklist.get(), injectedFrames); +} + +- (void)removeAllUserStyleSheets +{ + WKPageGroupRemoveAllUserStyleSheets(self._pageGroupRef); +} + @end @implementation WKBrowsingContextGroup (Internal) diff --git a/Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm b/Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm index 63c58895f..ca1cad582 100644 --- a/Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm +++ b/Source/WebKit2/UIProcess/API/mac/WKPrintingView.mm @@ -194,8 +194,8 @@ static BOOL isForcingPreviewUpdate; - (uint64_t)_expectedPreviewCallbackForRect:(const IntRect&)rect { for (HashMap<uint64_t, WebCore::IntRect>::iterator iter = _expectedPreviewCallbacks.begin(); iter != _expectedPreviewCallbacks.end(); ++iter) { - if (iter->second == rect) - return iter->first; + if (iter->value == rect) + return iter->key; } return 0; } @@ -229,8 +229,8 @@ static void pageDidDrawToPDF(WKDataRef dataRef, WKErrorRef, void* untypedContext ASSERT([view _isPrintingPreview]); if (data) { - HashMap<WebCore::IntRect, Vector<uint8_t> >::AddResult entry = view->_pagePreviews.add(iter->second, Vector<uint8_t>()); - entry.iterator->second.append(data->bytes(), data->size()); + HashMap<WebCore::IntRect, Vector<uint8_t> >::AddResult entry = view->_pagePreviews.add(iter->value, Vector<uint8_t>()); + entry.iterator->value.append(data->bytes(), data->size()); } view->_expectedPreviewCallbacks.remove(context->callbackID); bool receivedResponseToLatestRequest = view->_latestExpectedPreviewCallback == context->callbackID; @@ -494,7 +494,7 @@ static void prepareDataForPrintingOnSecondaryThread(void* untypedContext) return; } - const Vector<uint8_t>& pdfDataBytes = pagePreviewIterator->second; + const Vector<uint8_t>& pdfDataBytes = pagePreviewIterator->value; RetainPtr<NSData> pdfData(AdoptNS, [[NSData alloc] initWithBytes:pdfDataBytes.data() length:pdfDataBytes.size()]); RetainPtr<PDFDocument> pdfDocument(AdoptNS, [[pdfDocumentClass() alloc] initWithData:pdfData.get()]); diff --git a/Source/WebKit2/UIProcess/API/mac/WKView.mm b/Source/WebKit2/UIProcess/API/mac/WKView.mm index 9d69399d4..d4b301298 100644 --- a/Source/WebKit2/UIProcess/API/mac/WKView.mm +++ b/Source/WebKit2/UIProcess/API/mac/WKView.mm @@ -428,7 +428,7 @@ static String commandNameForSelector(SEL selector) static const SelectorNameMap* exceptionMap = createSelectorExceptionMap(); SelectorNameMap::const_iterator it = exceptionMap->find(selector); if (it != exceptionMap->end()) - return it->second; + return it->value; // Remove the trailing colon. // No need to capitalize the command name since Editor command names are @@ -742,7 +742,7 @@ static void validateCommandCallback(WKStringRef commandName, bool isEnabled, int // Add this item to the vector of items for a given command that are awaiting validation. ValidationMap::AddResult addResult = _data->_validationMap.add(commandName, ValidationVector()); - addResult.iterator->second.append(item); + addResult.iterator->value.append(item); if (addResult.isNewEntry) { // If we are not already awaiting validation for this command, start the asynchronous validation process. // FIXME: Theoretically, there is a race here; when we get the answer it might be old, from a previous time diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp b/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp index db51b85dd..71688cbe6 100644 --- a/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp +++ b/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp @@ -158,7 +158,7 @@ void QQuickWebPagePrivate::updateSize() DrawingAreaProxy* drawingArea = webPageProxy->drawingArea(); if (drawingArea && drawingArea->layerTreeCoordinatorProxy()) - drawingArea->layerTreeCoordinatorProxy()->setContentsSize(contentsSize); + drawingArea->layerTreeCoordinatorProxy()->setContentsSize(WebCore::FloatSize(contentsSize)); q->setSize(scaledSize); diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp index b78cae0f3..07ed832ce 100644 --- a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp +++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp @@ -268,6 +268,7 @@ QQuickWebViewPrivate::QQuickWebViewPrivate(QQuickWebView* viewport) , filePicker(0) , databaseQuotaDialog(0) , colorChooser(0) + , m_betweenLoadCommitAndFirstFrame(false) , m_useDefaultContentItemSize(true) , m_navigatorQtObjectEnabled(false) , m_renderToOffscreenBuffer(false) @@ -330,14 +331,6 @@ void QQuickWebViewPrivate::loadDidStop() emit q->loadingChanged(&loadRequest); } -void QQuickWebViewPrivate::onComponentComplete() -{ - Q_Q(QQuickWebView); - m_pageViewportControllerClient.reset(new PageViewportControllerClientQt(q, pageView.data())); - m_pageViewportController.reset(new PageViewportController(webPageProxy.get(), m_pageViewportControllerClient.data())); - pageView->eventHandler()->setViewportController(m_pageViewportControllerClient.data()); -} - void QQuickWebViewPrivate::setTransparentBackground(bool enable) { webPageProxy->setDrawsTransparentBackground(enable); @@ -370,6 +363,7 @@ void QQuickWebViewPrivate::loadDidCommit() Q_Q(QQuickWebView); ASSERT(q->loading()); + m_betweenLoadCommitAndFirstFrame = true; emit q->navigationHistoryChanged(); emit q->titleChanged(); } @@ -452,10 +446,18 @@ void QQuickWebViewPrivate::setNeedsDisplay() q->page()->d->paint(&painter); return; } - q->page()->update(); } +void QQuickWebViewPrivate::didRenderFrame() +{ + Q_Q(QQuickWebView); + if (m_betweenLoadCommitAndFirstFrame) { + emit q->experimental()->loadVisuallyCommitted(); + m_betweenLoadCommitAndFirstFrame = false; + } +} + void QQuickWebViewPrivate::processDidCrash() { Q_Q(QQuickWebView); @@ -478,8 +480,6 @@ void QQuickWebViewPrivate::didRelaunchProcess() { qWarning("WARNING: The web process has been successfully restarted."); - // Reset to default so that the later update can reach the web process. - webPageProxy->setCustomDeviceScaleFactor(0); webPageProxy->drawingArea()->setSize(viewSize(), IntSize()); updateViewportSize(); @@ -820,12 +820,17 @@ void QQuickWebViewLegacyPrivate::updateViewportSize() QSizeF viewportSize = q->boundingRect().size(); if (viewportSize.isEmpty()) return; + + float devicePixelRatio = webPageProxy->deviceScaleFactor(); pageView->setContentsSize(viewportSize); + // Make sure that our scale matches the one passed to setVisibleContentsRect. + pageView->setContentsScale(devicePixelRatio); + // The fixed layout is handled by the FrameView and the drawing area doesn't behave differently // whether its fixed or not. We still need to tell the drawing area which part of it // has to be rendered on tiles, and in desktop mode it's all of it. - webPageProxy->drawingArea()->setSize(viewportSize.toSize(), IntSize()); - webPageProxy->drawingArea()->setVisibleContentsRect(FloatRect(FloatPoint(), viewportSize), 1, FloatPoint()); + webPageProxy->drawingArea()->setSize((viewportSize / devicePixelRatio).toSize(), IntSize()); + webPageProxy->drawingArea()->setVisibleContentsRect(FloatRect(FloatPoint(), FloatSize(viewportSize / devicePixelRatio)), devicePixelRatio, FloatPoint()); } qreal QQuickWebViewLegacyPrivate::zoomFactor() const @@ -853,6 +858,11 @@ void QQuickWebViewFlickablePrivate::onComponentComplete() { QQuickWebViewPrivate::onComponentComplete(); + Q_Q(QQuickWebView); + m_pageViewportControllerClient.reset(new PageViewportControllerClientQt(q, pageView.data())); + m_pageViewportController.reset(new PageViewportController(webPageProxy.get(), m_pageViewportControllerClient.data())); + pageView->eventHandler()->setViewportController(m_pageViewportControllerClient.data()); + // Trigger setting of correct visibility flags after everything was allocated and initialized. _q_onVisibleChanged(); } @@ -868,7 +878,7 @@ void QQuickWebViewFlickablePrivate::updateViewportSize() Q_Q(QQuickWebView); if (m_pageViewportController) - m_pageViewportController->didChangeViewportSize(QSizeF(q->width(), q->height())); + m_pageViewportController->didChangeViewportSize(FloatSize(q->width(), q->height())); } void QQuickWebViewFlickablePrivate::pageDidRequestScroll(const QPoint& pos) @@ -877,13 +887,6 @@ void QQuickWebViewFlickablePrivate::pageDidRequestScroll(const QPoint& pos) m_pageViewportController->pageDidRequestScroll(pos); } -void QQuickWebViewFlickablePrivate::didChangeContentsSize(const QSize& newSize) -{ - QQuickWebViewPrivate::didChangeContentsSize(newSize); - pageView->setContentsSize(newSize); // emits contentsSizeChanged() - m_pageViewportController->didChangeContentsSize(newSize); -} - void QQuickWebViewFlickablePrivate::handleMouseEvent(QMouseEvent* event) { if (!pageView->eventHandler()) @@ -1233,7 +1236,7 @@ void QQuickWebViewExperimental::setDevicePixelRatio(qreal devicePixelRatio) if (0 >= devicePixelRatio || devicePixelRatio == this->devicePixelRatio()) return; - d->webPageProxy->setCustomDeviceScaleFactor(devicePixelRatio); + d->webPageProxy->setIntrinsicDeviceScaleFactor(devicePixelRatio); emit devicePixelRatioChanged(); } diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h index e8b1bf7a1..89e7fbc99 100644 --- a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h +++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p.h @@ -355,6 +355,7 @@ public Q_SLOTS: void evaluateJavaScript(const QString& script, const QJSValue& value = QJSValue()); Q_SIGNALS: + void loadVisuallyCommitted(); void alertDialogChanged(); void confirmDialogChanged(); void promptDialogChanged(); diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h index f172ad68f..15bf818d7 100644 --- a/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h +++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview_p_p.h @@ -70,7 +70,7 @@ public: virtual void initialize(WKContextRef contextRef = 0, WKPageGroupRef pageGroupRef = 0); - virtual void onComponentComplete(); + virtual void onComponentComplete() { } virtual void provisionalLoadDidStart(const WTF::String& url); virtual void didReceiveServerRedirectForProvisionalLoad(const WTF::String& url); @@ -88,8 +88,9 @@ public: int loadProgress() const { return m_loadProgress; } void setNeedsDisplay(); + void didRenderFrame(); - WebKit::PageViewportController* viewportController() const { return m_pageViewportController.data(); } + virtual WebKit::PageViewportController* viewportController() const { return 0; } virtual void updateViewportSize() { } void updateTouchViewportSize(); @@ -130,7 +131,6 @@ public: WebCore::IntSize viewSize() const; void didReceiveMessageFromNavigatorQtObject(const String& message); virtual void pageDidRequestScroll(const QPoint& pos) { } - virtual void didChangeContentsSize(const QSize& newSize) { } void processDidCrash(); void didRelaunchProcess(); PassOwnPtr<WebKit::DrawingAreaProxy> createDrawingAreaProxy(); @@ -172,9 +172,6 @@ protected: QScopedPointer<QQuickWebPage> pageView; QQuickWebView* q_ptr; - QScopedPointer<WebKit::PageViewportController> m_pageViewportController; - QScopedPointer<WebKit::PageViewportControllerClientQt> m_pageViewportControllerClient; - FlickableAxisLocker axisLocker; QQmlComponent* alertDialog; @@ -190,6 +187,7 @@ protected: QList<QUrl> userScripts; + bool m_betweenLoadCommitAndFirstFrame; bool m_useDefaultContentItemSize; bool m_navigatorQtObjectEnabled; bool m_renderToOffscreenBuffer; @@ -220,11 +218,15 @@ public: virtual void onComponentComplete(); virtual void didChangeViewportProperties(const WebCore::ViewportAttributes&); + virtual WebKit::PageViewportController* viewportController() const { return m_pageViewportController.data(); } virtual void updateViewportSize(); virtual void pageDidRequestScroll(const QPoint& pos); - virtual void didChangeContentsSize(const QSize& newSize); virtual void handleMouseEvent(QMouseEvent*); + +private: + QScopedPointer<WebKit::PageViewportController> m_pageViewportController; + QScopedPointer<WebKit::PageViewportControllerClientQt> m_pageViewportControllerClient; }; #endif // qquickwebview_p_p_h diff --git a/Source/WebKit2/UIProcess/API/qt/raw/qrawwebview.cpp b/Source/WebKit2/UIProcess/API/qt/raw/qrawwebview.cpp index 0a7a684cf..5f6c16d56 100644 --- a/Source/WebKit2/UIProcess/API/qt/raw/qrawwebview.cpp +++ b/Source/WebKit2/UIProcess/API/qt/raw/qrawwebview.cpp @@ -167,6 +167,11 @@ void QRawWebViewPrivate::toolTipChanged(const String&, const String& newTooltip) notImplemented(); } +void QRawWebViewPrivate::pageTransitionViewportReady() +{ + m_webPageProxy->commitPageTransitionViewport(); +} + void QRawWebViewPrivate::startDrag(const WebCore::DragData& dragData, PassRefPtr<WebKit::ShareableBitmap> dragImage) { notImplemented(); @@ -319,6 +324,7 @@ void QRawWebView::setActive(bool active) { d->m_active = active; d->m_webPageProxy->viewStateDidChange(WebKit::WebPageProxy::ViewWindowIsActive); + layerTreeRenderer()->setActive(active); } QSize QRawWebView::size() const @@ -352,17 +358,20 @@ WKPageRef QRawWebView::pageRef() return toAPI(d->m_webPageProxy.get()); } -void QRawWebView::paint(const QMatrix4x4& transform, float opacity, unsigned paintFlags) +WebKit::LayerTreeRenderer* QRawWebView::layerTreeRenderer() const { WebKit::DrawingAreaProxy* drawingArea = d->m_webPageProxy->drawingArea(); if (!drawingArea) - return; - - WebKit::LayerTreeCoordinatorProxy* coordinatorProxy = drawingArea->layerTreeCoordinatorProxy(); - if (!coordinatorProxy) - return; + return 0; + WebKit::LayerTreeCoordinatorProxy* layerTreeCoordinatorProxy = drawingArea->layerTreeCoordinatorProxy(); + if (!layerTreeCoordinatorProxy) + return 0; + return layerTreeCoordinatorProxy->layerTreeRenderer(); +} - WebKit::LayerTreeRenderer* renderer = coordinatorProxy->layerTreeRenderer(); +void QRawWebView::paint(const QMatrix4x4& transform, float opacity, unsigned paintFlags) +{ + WebKit::LayerTreeRenderer* renderer = layerTreeRenderer(); if (!renderer) return; diff --git a/Source/WebKit2/UIProcess/API/qt/raw/qrawwebview_p.h b/Source/WebKit2/UIProcess/API/qt/raw/qrawwebview_p.h index f8f15b06d..015815ad8 100644 --- a/Source/WebKit2/UIProcess/API/qt/raw/qrawwebview_p.h +++ b/Source/WebKit2/UIProcess/API/qt/raw/qrawwebview_p.h @@ -47,6 +47,10 @@ QT_END_NAMESPACE class QRawWebViewPrivate; +namespace WebKit { +class LayerTreeRenderer; +} + class QRawWebViewClient { public: virtual ~QRawWebViewClient() { } @@ -97,6 +101,8 @@ public: void sendTouchEvent(QTouchEvent*); private: + WebKit::LayerTreeRenderer* layerTreeRenderer() const; + QRawWebViewPrivate* d; }; diff --git a/Source/WebKit2/UIProcess/API/qt/raw/qrawwebview_p_p.h b/Source/WebKit2/UIProcess/API/qt/raw/qrawwebview_p_p.h index 55bc85ba0..545096d02 100644 --- a/Source/WebKit2/UIProcess/API/qt/raw/qrawwebview_p_p.h +++ b/Source/WebKit2/UIProcess/API/qt/raw/qrawwebview_p_p.h @@ -82,6 +82,7 @@ public: virtual void setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves); virtual void toolTipChanged(const String&, const String& newTooltip); + virtual void pageTransitionViewportReady(); virtual void startDrag(const WebCore::DragData& dragData, PassRefPtr<WebKit::ShareableBitmap> dragImage); @@ -104,6 +105,7 @@ public: virtual void didRelaunchProcess(); virtual void setViewNeedsDisplay(const WebCore::IntRect& rect); virtual void didChangeContentsSize(const WebCore::IntSize& newSize); + virtual void didRenderFrame(const WebCore::IntSize& contentsSize, const WebCore::IntRect& coveredRect) { } virtual void setCursor(const WebCore::Cursor&); virtual bool isViewFocused() { return m_focused; } diff --git a/Source/WebKit2/UIProcess/API/qt/tests/inspectorserver/inspectorserver.pro b/Source/WebKit2/UIProcess/API/qt/tests/inspectorserver/inspectorserver.pro index 4a8d86f80..bc5307f2d 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/inspectorserver/inspectorserver.pro +++ b/Source/WebKit2/UIProcess/API/qt/tests/inspectorserver/inspectorserver.pro @@ -1,4 +1,4 @@ include(../tests.pri) SOURCES += $${TARGET}.cpp -QT += webkit-private +QT += webkitwidgets-private DEFINES += IMPORT_DIR=\"\\\"$${ROOT_BUILD_DIR}$${QMAKE_DIR_SEP}imports\\\"\" diff --git a/Source/WebKit2/UIProcess/API/qt/tests/publicapi/publicapi.pro b/Source/WebKit2/UIProcess/API/qt/tests/publicapi/publicapi.pro index 02dc197c7..ba8f4cea3 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/publicapi/publicapi.pro +++ b/Source/WebKit2/UIProcess/API/qt/tests/publicapi/publicapi.pro @@ -1,3 +1,3 @@ include(../tests.pri) SOURCES += $${TARGET}.cpp -QT += webkit-private +QT += webkitwidgets-private diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior.pro b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior.pro index 3fd3d4583..7c72fd2f1 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior.pro +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior.pro @@ -3,7 +3,7 @@ SOURCES += tst_qmltests.cpp TARGET = tst_qmltests_DesktopBehavior OBJECTS_DIR = obj_DesktopBehavior/$$activeBuildConfig() -QT += webkit-private +QT += webkitwidgets-private CONFIG += warn_on testcase QT += qmltest diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView.pro b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView.pro index b340235e4..3e217b369 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView.pro +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView.pro @@ -3,7 +3,7 @@ SOURCES += tst_qmltests.cpp TARGET = tst_qmltests_WebView OBJECTS_DIR = obj_WebView/$$activeBuildConfig() -QT += webkit-private +QT += webkitwidgets-private CONFIG += warn_on testcase QT += qmltest diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_doubleTapToZoom.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_doubleTapToZoom.qml index 691455708..d21ef211a 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_doubleTapToZoom.qml +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_doubleTapToZoom.qml @@ -40,6 +40,7 @@ Item { TestCase { name: "DoubleTapToZoom" + when: windowShown property variant test: webView.experimental.test @@ -78,7 +79,7 @@ Item { function test_basic() { webView.url = webView.content - verify(webView.waitForLoadSucceeded()) + verify(webView.waitForViewportReady()) compare(documentSize(), "480x720") diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_fitToView.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_fitToView.qml index f12da5de8..fcd3d9301 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_fitToView.qml +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_fitToView.qml @@ -38,6 +38,7 @@ Item { TestCase { name: "FitToView" + when: windowShown property variant test: webView.experimental.test @@ -69,7 +70,7 @@ Item { function test_basic() { webView.url = webView.content - verify(webView.waitForLoadSucceeded()) + verify(webView.waitForViewportReady()) compare(documentSize(), "480x720") compare(test.contentsScale, 1.0) diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_wheelEventHandling.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_wheelEventHandling.qml index 1fc1559ab..aa6d711a1 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_wheelEventHandling.qml +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView/tst_wheelEventHandling.qml @@ -21,12 +21,13 @@ Item { TestCase { name: "WheelEventHandling" + when: windowShown property variant test: webView.experimental.test function init() { webView.url = Qt.resolvedUrl("../common/test4.html") - verify(webView.waitForLoadSucceeded()) + verify(webView.waitForViewportReady()) webView.contentY = 0 } @@ -38,7 +39,7 @@ Item { scrollSpy.wait() var position = webView.contentY webView.reload() - verify(webView.waitForLoadSucceeded()) + verify(webView.waitForViewportReady()) // The check below will fail if the previous position was not restored after reload. verify(position == webView.contentY) } @@ -46,7 +47,7 @@ Item { function test_wheelScrollEventAfterReload() { scrollSpy.clear() webView.reload() - verify(webView.waitForLoadSucceeded()) + verify(webView.waitForViewportReady()) var centerPoint = Qt.point(webView.width / 2, webView.height / 2) test.wheelEvent(webView, centerPoint.x, centerPoint.y, -500); // The signal spy below will time out if the wheel event did not scroll the content. diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/TestWebView.qml b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/TestWebView.qml index 0dd7bccee..5a05f9b3e 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/TestWebView.qml +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/common/TestWebView.qml @@ -5,43 +5,47 @@ import QtWebKit.experimental 1.0 WebView { property var loadStatus: null + property var viewportReady: false function waitForLoadSucceeded() { - var timeout = 5000 - var i = 0 - while (i < timeout && loadStatus != WebView.LoadSucceededStatus) { - testResult.wait(50) - i += 50 - } - var success = loadStatus == WebView.LoadSucceededStatus + var success = _waitFor(function() { return loadStatus == WebView.LoadSucceededStatus }) loadStatus = null return success } + function waitForViewportReady() { + // Note: You need to have "when: windowShown" in your TestCase for this to work. + // The viewport is locked until the first frame is rendered, and the rendering isn't + // activated until the WebView is visible in a mapped QQuickView. + return _waitFor(function() { return viewportReady }) + } function waitForLoadFailed() { - var timeout = 5000 - var i = 0 - while (i < timeout && loadStatus != WebView.LoadFailedStatus) { - testResult.wait(50) - i += 50 - } - var failure = loadStatus == WebView.LoadFailedStatus + var failure = _waitFor(function() { return loadStatus == WebView.LoadFailedStatus }) loadStatus = null return failure } function waitForLoadStopped() { + var stop = _waitFor(function() { return loadStatus == WebView.LoadStoppedStatus }) + loadStatus = null + return stop + } + function _waitFor(predicate) { var timeout = 5000 var i = 0 - while (i < timeout && loadStatus != WebView.LoadStoppedStatus) { + while (i < timeout && !predicate()) { testResult.wait(50) i += 50 } - var stop = loadStatus == WebView.LoadStoppedStatus - loadStatus = null - return stop + return predicate() } TestResult { id: testResult } - onLoadingChanged: loadStatus = loadRequest.status + experimental.onLoadVisuallyCommitted: viewportReady = true + onLoadingChanged: { + loadStatus = loadRequest.status + if (loadRequest.status == WebView.LoadStartedStatus) + viewportReady = false + } + } diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/qquickwebview.pro b/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/qquickwebview.pro index 4a8d86f80..bc5307f2d 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/qquickwebview.pro +++ b/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/qquickwebview.pro @@ -1,4 +1,4 @@ include(../tests.pri) SOURCES += $${TARGET}.cpp -QT += webkit-private +QT += webkitwidgets-private DEFINES += IMPORT_DIR=\"\\\"$${ROOT_BUILD_DIR}$${QMAKE_DIR_SEP}imports\\\"\" diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/tst_qquickwebview.cpp b/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/tst_qquickwebview.cpp index 5b98ae7b7..558053729 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/tst_qquickwebview.cpp +++ b/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/tst_qquickwebview.cpp @@ -440,10 +440,11 @@ void tst_QQuickWebView::inputMethodHints() void tst_QQuickWebView::scrollRequest() { - webView()->setSize(QSizeF(300, 400)); + m_window->setGeometry(0, 0, 300, 400); + m_window->show(); webView()->setUrl(QUrl::fromLocalFile(QLatin1String(TESTS_SOURCE_DIR "/html/scroll.html"))); - QVERIFY(waitForLoadSucceeded(webView())); + QVERIFY(waitForViewportReady(webView())); // COMPARE with the position requested in the html // Use qRound as that is also used when calculating the position diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qrawwebview/qrawwebview.pro b/Source/WebKit2/UIProcess/API/qt/tests/qrawwebview/qrawwebview.pro index 02dc197c7..ba8f4cea3 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qrawwebview/qrawwebview.pro +++ b/Source/WebKit2/UIProcess/API/qt/tests/qrawwebview/qrawwebview.pro @@ -1,3 +1,3 @@ include(../tests.pri) SOURCES += $${TARGET}.cpp -QT += webkit-private +QT += webkitwidgets-private diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qrawwebview/tst_qrawwebview.cpp b/Source/WebKit2/UIProcess/API/qt/tests/qrawwebview/tst_qrawwebview.cpp index 31102b876..208288d1e 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qrawwebview/tst_qrawwebview.cpp +++ b/Source/WebKit2/UIProcess/API/qt/tests/qrawwebview/tst_qrawwebview.cpp @@ -27,6 +27,7 @@ #include <WebKit2/WKContext.h> #include <WebKit2/WKPageGroup.h> +#include <WebKit2/WKPageLoadTypes.h> #include <WebKit2/WKPreferences.h> #include <WebKit2/WKPreferencesPrivate.h> #include <WebKit2/WKStringQt.h> @@ -60,15 +61,18 @@ class WebView : public QObject, public QRawWebViewClient { public: WebView(const QSize& size, bool transparent = false) { + m_webView = new QRawWebView(webContext(), webPageGroup(QString()), this); + m_webView->setTransparentBackground(transparent); + m_webView->create(); + WKPageLoaderClient loaderClient; memset(&loaderClient, 0, sizeof(WKPageLoaderClient)); + loaderClient.version = kWKPageLoaderClientCurrentVersion; loaderClient.clientInfo = this; - loaderClient.didFirstVisuallyNonEmptyLayoutForFrame = WebView::finishFirstLayoutForFrame; + loaderClient.didLayout = WebView::didLayout; - m_webView = new QRawWebView(webContext(), webPageGroup(QString()), this); WKPageSetPageLoaderClient(m_webView->pageRef(), &loaderClient); - m_webView->setTransparentBackground(transparent); - m_webView->create(); + WKPageListenForLayoutMilestones(m_webView->pageRef(), kWKDidFirstVisuallyNonEmptyLayout); WKPageSetUseFixedLayout(m_webView->pageRef(), true); m_webView->setSize(size); @@ -118,7 +122,7 @@ public: static_cast<WebView*>(context)->onRepaintDone(); } - static void finishFirstLayoutForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void *clientInfo) + static void didLayout(WKPageRef page, WKLayoutMilestones milestones, WKTypeRef userData, const void *clientInfo) { static_cast<WebView*>(const_cast<void*>(clientInfo))->frameLoaded(); } @@ -152,7 +156,9 @@ public: tst_qrawwebview() : m_resourceDir(QString::fromLatin1(TESTS_SOURCE_DIR "/html/resources")) , m_baseUrl(QUrl::fromLocalFile(TESTS_SOURCE_DIR "/html").toString()) - { } + { + addQtWebProcessToPath(); + } private Q_SLOTS: void paint() { run(&tst_qrawwebview::doPaint, m_resourceDir + "/qwkview_paint.png"); } diff --git a/Source/WebKit2/UIProcess/API/qt/tests/tests.pri b/Source/WebKit2/UIProcess/API/qt/tests/tests.pri index a1133530d..123b25ce2 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/tests.pri +++ b/Source/WebKit2/UIProcess/API/qt/tests/tests.pri @@ -6,7 +6,7 @@ TARGET = tst_$$TARGET INCLUDEPATH += $$PWD SOURCES += ../util.cpp -QT += testlib webkit +QT += testlib webkitwidgets have?(QTQUICK) { QT += qml quick quick-private HEADERS += ../bytearraytestdata.h \ diff --git a/Source/WebKit2/UIProcess/API/qt/tests/util.cpp b/Source/WebKit2/UIProcess/API/qt/tests/util.cpp index 4525e882b..fce3cc7f6 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/util.cpp +++ b/Source/WebKit2/UIProcess/API/qt/tests/util.cpp @@ -57,10 +57,10 @@ bool waitForSignal(QObject* obj, const char* signal, int timeout) return timeoutSpy.isEmpty(); } -static void messageHandler(QtMsgType type, const char* message) +static void messageHandler(QtMsgType type, const QMessageLogContext&, const QString& message) { if (type == QtCriticalMsg) { - fprintf(stderr, "%s\n", message); + fprintf(stderr, "%s\n", qPrintable(message)); return; } // Do nothing @@ -68,7 +68,7 @@ static void messageHandler(QtMsgType type, const char* message) void suppressDebugOutput() { - qInstallMsgHandler(messageHandler); \ + qInstallMessageHandler(messageHandler); \ if (qgetenv("QT_WEBKIT_SUPPRESS_WEB_PROCESS_OUTPUT").isEmpty()) \ qputenv("QT_WEBKIT_SUPPRESS_WEB_PROCESS_OUTPUT", "1"); } @@ -126,6 +126,13 @@ bool waitForLoadFailed(QQuickWebView* webView, int timeout) return timeoutSpy.isEmpty(); } +bool waitForViewportReady(QQuickWebView* webView, int timeout) +{ + // The viewport is locked until the first frame of a page load is rendered. + // The QQuickView needs to be shown for this to succeed. + return waitForSignal(webView->experimental(), SIGNAL(loadVisuallyCommitted()), timeout); +} + LoadStartedCatcher::LoadStartedCatcher(QQuickWebView* webView) : m_webView(webView) { diff --git a/Source/WebKit2/UIProcess/API/qt/tests/util.h b/Source/WebKit2/UIProcess/API/qt/tests/util.h index 0c14a1ff4..4834029b4 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/util.h +++ b/Source/WebKit2/UIProcess/API/qt/tests/util.h @@ -36,6 +36,7 @@ void suppressDebugOutput(); #if defined(HAVE_QTQUICK) && HAVE_QTQUICK bool waitForLoadSucceeded(QQuickWebView* webView, int timeout = 10000); bool waitForLoadFailed(QQuickWebView* webView, int timeout = 10000); +bool waitForViewportReady(QQuickWebView* webView, int timeout = 10000); class LoadStartedCatcher : public QObject { Q_OBJECT |