diff options
Diffstat (limited to 'Source/WebKit2/UIProcess/API')
58 files changed, 1114 insertions, 497 deletions
diff --git a/Source/WebKit2/UIProcess/API/C/WKIntentData.cpp b/Source/WebKit2/UIProcess/API/C/WKIntentData.cpp index 7a92db54c..92e61871c 100644 --- a/Source/WebKit2/UIProcess/API/C/WKIntentData.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKIntentData.cpp @@ -31,6 +31,7 @@ #include "WKAPICast.h" #include "WKDictionary.h" #include "WKString.h" +#include "WebSerializedScriptValue.h" #if ENABLE(WEB_INTENTS) #include "WebIntentData.h" @@ -47,27 +48,6 @@ WKTypeID WKIntentDataGetTypeID() #endif } -WKIntentDataRef WKIntentDataCreate(WKDictionaryRef initDictionaryRef) -{ -#if ENABLE(WEB_INTENTS) - IntentData intentData; - WKStringRef action = static_cast<WKStringRef>(WKDictionaryGetItemForKey(initDictionaryRef, WKStringCreateWithUTF8CString("action"))); - ASSERT(action); - intentData.action = toImpl(action)->string(); - WKStringRef type = static_cast<WKStringRef>(WKDictionaryGetItemForKey(initDictionaryRef, WKStringCreateWithUTF8CString("type"))); - ASSERT(type); - intentData.type = toImpl(type)->string(); - WKSerializedScriptValueRef data = static_cast<WKSerializedScriptValueRef>(WKDictionaryGetItemForKey(initDictionaryRef, WKStringCreateWithUTF8CString("data"))); - if (data) - intentData.data = toImpl(data)->dataReference().vector(); - - RefPtr<WebIntentData> webIntentData = WebIntentData::create(intentData); - return toAPI(webIntentData.release().leakRef()); -#else - return 0; -#endif -} - WKStringRef WKIntentDataCopyAction(WKIntentDataRef intentRef) { #if ENABLE(WEB_INTENTS) @@ -104,7 +84,7 @@ WKArrayRef WKIntentDataCopySuggestions(WKIntentDataRef intentRef) #endif } -WKStringRef WKIntentDataCopyExtra(WKIntentDataRef intentRef, WKStringRef key) +WKStringRef WKIntentDataCopyExtraValue(WKIntentDataRef intentRef, WKStringRef key) { #if ENABLE(WEB_INTENTS) return toCopiedAPI(toImpl(intentRef)->extra(toWTFString(key))); diff --git a/Source/WebKit2/UIProcess/API/C/WKIntentData.h b/Source/WebKit2/UIProcess/API/C/WKIntentData.h index 1f809ec8d..caf1b459f 100644 --- a/Source/WebKit2/UIProcess/API/C/WKIntentData.h +++ b/Source/WebKit2/UIProcess/API/C/WKIntentData.h @@ -34,13 +34,11 @@ extern "C" { WK_EXPORT WKTypeID WKIntentDataGetTypeID(); -WK_EXPORT WKIntentDataRef WKIntentDataCreate(WKDictionaryRef initDictionary); - WK_EXPORT WKStringRef WKIntentDataCopyAction(WKIntentDataRef intentRef); WK_EXPORT WKStringRef WKIntentDataCopyType(WKIntentDataRef intentRef); WK_EXPORT WKURLRef WKIntentDataCopyService(WKIntentDataRef intentRef); WK_EXPORT WKArrayRef WKIntentDataCopySuggestions(WKIntentDataRef intentRef); -WK_EXPORT WKStringRef WKIntentDataCopyExtra(WKIntentDataRef intentRef, WKStringRef key); +WK_EXPORT WKStringRef WKIntentDataCopyExtraValue(WKIntentDataRef intentRef, WKStringRef key); WK_EXPORT WKDictionaryRef WKIntentDataCopyExtras(WKIntentDataRef intentRef); #ifdef __cplusplus diff --git a/Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.cpp b/Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.cpp index c6f7a661c..6a7c53e8f 100644 --- a/Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.cpp +++ b/Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2012 Samsung Electronics. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -46,3 +47,12 @@ WKArrayRef WKOpenPanelParametersCopyAcceptedMIMETypes(WKOpenPanelParametersRef p { return toAPI(toImpl(parametersRef)->acceptMIMETypes().leakRef()); } + +WKStringRef WKOpenPanelParametersCopyCapture(WKOpenPanelParametersRef parametersRef) +{ +#if ENABLE(MEDIA_CAPTURE) + return toCopiedAPI(toImpl(parametersRef)->capture()); +#else + return 0; +#endif +} diff --git a/Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.h b/Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.h index 64577bad9..ddcaae265 100644 --- a/Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.h +++ b/Source/WebKit2/UIProcess/API/C/WKOpenPanelParameters.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2012 Samsung Electronics. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -42,6 +43,8 @@ WK_EXPORT bool WKOpenPanelParametersGetAllowsMultipleFiles(WKOpenPanelParameters WK_EXPORT WKArrayRef WKOpenPanelParametersCopyAcceptedMIMETypes(WKOpenPanelParametersRef parameters); +WK_EXPORT WKStringRef WKOpenPanelParametersCopyCapture(WKOpenPanelParametersRef parameters); + #ifdef __cplusplus } #endif diff --git a/Source/WebKit2/UIProcess/API/cpp/efl/WKEinaSharedString.cpp b/Source/WebKit2/UIProcess/API/cpp/efl/WKEinaSharedString.cpp index d2681203c..ea43df167 100644 --- a/Source/WebKit2/UIProcess/API/cpp/efl/WKEinaSharedString.cpp +++ b/Source/WebKit2/UIProcess/API/cpp/efl/WKEinaSharedString.cpp @@ -100,3 +100,8 @@ WKEinaSharedString& WKEinaSharedString::operator=(const char* str) eina_stringshare_replace(&m_string, str); return *this; } + +bool WKEinaSharedString::operator==(const char* str) const +{ + return (!str || !m_string) ? (str == m_string) : !strcmp(m_string, str); +} diff --git a/Source/WebKit2/UIProcess/API/cpp/efl/WKEinaSharedString.h b/Source/WebKit2/UIProcess/API/cpp/efl/WKEinaSharedString.h index 83f661418..68d76f4ea 100644 --- a/Source/WebKit2/UIProcess/API/cpp/efl/WKEinaSharedString.h +++ b/Source/WebKit2/UIProcess/API/cpp/efl/WKEinaSharedString.h @@ -52,6 +52,9 @@ public: ALWAYS_INLINE bool operator==(const WKEinaSharedString& other) const { return this->m_string == other.m_string; } ALWAYS_INLINE bool operator!=(const WKEinaSharedString& other) const { return !(*this == other); } + bool operator==(const char* str) const; + ALWAYS_INLINE bool operator!=(const char* str) const { return !(*this == str); } + ALWAYS_INLINE operator const char* () const { return m_string; } ALWAYS_INLINE bool isNull() const { return !m_string; } 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 5b8e2d7ea..acf8d5645 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_back_forward_list.cpp @@ -128,7 +128,8 @@ unsigned ewk_back_forward_list_count(Ewk_Back_Forward_List* list) */ void ewk_back_forward_list_changed(Ewk_Back_Forward_List* list, WKBackForwardListItemRef wkAddedItem, WKArrayRef wkRemovedItems) { - addItemToWrapperCache(list, wkAddedItem); // Puts new item to the cache. + if (wkAddedItem) // Checking also here to avoid EINA_SAFETY_ON_NULL_RETURN_VAL warnings. + addItemToWrapperCache(list, wkAddedItem); // Puts new item to the cache. const size_t removedItemsSize = wkRemovedItems ? WKArrayGetSize(wkRemovedItems) : 0; for (size_t i = 0; i < removedItemsSize; ++i) { 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 a8586b23d..871187d2a 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,16 +39,13 @@ using namespace WebKit; struct _Ewk_Back_Forward_List_Item { unsigned int __ref; /**< the reference count of the object */ WKRetainPtr<WKBackForwardListItemRef> wkItem; - WKEinaSharedString uri; - WKEinaSharedString title; - WKEinaSharedString originalUri; + mutable WKEinaSharedString uri; + mutable WKEinaSharedString title; + mutable WKEinaSharedString originalUri; _Ewk_Back_Forward_List_Item(WKBackForwardListItemRef itemRef) : __ref(1) , wkItem(itemRef) - , uri(AdoptWK, WKBackForwardListItemCopyURL(itemRef)) - , title(AdoptWK, WKBackForwardListItemCopyTitle(itemRef)) - , originalUri(AdoptWK, WKBackForwardListItemCopyOriginalURL(itemRef)) { } ~_Ewk_Back_Forward_List_Item() @@ -57,6 +54,17 @@ struct _Ewk_Back_Forward_List_Item { } }; +#define EWK_BACK_FORWARD_LIST_ITEM_WK_GET_OR_RETURN(item, wkItem_, ...) \ + if (!(item)) { \ + EINA_LOG_CRIT("item is NULL."); \ + return __VA_ARGS__; \ + } \ + if (!(item)->wkItem) { \ + EINA_LOG_CRIT("item->wkItem is NULL."); \ + return __VA_ARGS__; \ + } \ + WKBackForwardListItemRef wkItem_ = (item)->wkItem.get() + void ewk_back_forward_list_item_ref(Ewk_Back_Forward_List_Item* item) { EINA_SAFETY_ON_NULL_RETURN(item); @@ -75,21 +83,27 @@ void ewk_back_forward_list_item_unref(Ewk_Back_Forward_List_Item* item) const char* ewk_back_forward_list_item_uri_get(const Ewk_Back_Forward_List_Item* item) { - EINA_SAFETY_ON_NULL_RETURN_VAL(item, 0); + EWK_BACK_FORWARD_LIST_ITEM_WK_GET_OR_RETURN(item, wkItem, 0); + + item->uri = WKEinaSharedString(AdoptWK, WKBackForwardListItemCopyURL(wkItem)); return item->uri; } const char* ewk_back_forward_list_item_title_get(const Ewk_Back_Forward_List_Item* item) { - EINA_SAFETY_ON_NULL_RETURN_VAL(item, 0); + EWK_BACK_FORWARD_LIST_ITEM_WK_GET_OR_RETURN(item, wkItem, 0); + + item->title = WKEinaSharedString(AdoptWK, WKBackForwardListItemCopyTitle(wkItem)); return item->title; } const char* ewk_back_forward_list_item_original_uri_get(const Ewk_Back_Forward_List_Item* item) { - EINA_SAFETY_ON_NULL_RETURN_VAL(item, 0); + EWK_BACK_FORWARD_LIST_ITEM_WK_GET_OR_RETURN(item, wkItem, 0); + + item->originalUri = WKEinaSharedString(AdoptWK, WKBackForwardListItemCopyOriginalURL(wkItem)); return item->originalUri; } diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_download_job.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_download_job.cpp index c41681071..a27abc40d 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_download_job.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_download_job.cpp @@ -28,6 +28,7 @@ #include "DownloadProxy.h" #include "WKAPICast.h" +#include "WKEinaSharedString.h" #include "WKRetainPtr.h" #include "WebURLRequest.h" #include "ewk_download_job_private.h" @@ -50,8 +51,8 @@ struct _Ewk_Download_Job { double startTime; double endTime; uint64_t downloaded; /**< length already downloaded */ - const char* destination; - const char* suggestedFilename; + WKEinaSharedString destination; + WKEinaSharedString suggestedFilename; _Ewk_Download_Job(DownloadProxy* download, Evas_Object* ewkView) : __ref(1) @@ -63,8 +64,6 @@ struct _Ewk_Download_Job { , startTime(-1) , endTime(-1) , downloaded(0) - , destination(0) - , suggestedFilename(0) { } ~_Ewk_Download_Job() @@ -74,8 +73,6 @@ struct _Ewk_Download_Job { ewk_url_request_unref(request); if (response) ewk_url_response_unref(response); - eina_stringshare_del(destination); - eina_stringshare_del(suggestedFilename); } }; @@ -159,7 +156,7 @@ Eina_Bool ewk_download_job_destination_set(Ewk_Download_Job* download, const cha EINA_SAFETY_ON_NULL_RETURN_VAL(download, false); EINA_SAFETY_ON_NULL_RETURN_VAL(destination, false); - eina_stringshare_replace(&download->destination, destination); + download->destination = destination; return true; } @@ -236,7 +233,7 @@ void ewk_download_job_suggested_filename_set(Ewk_Download_Job* download, const c { EINA_SAFETY_ON_NULL_RETURN(download); - eina_stringshare_replace(&download->suggestedFilename, suggestedFilename); + download->suggestedFilename = suggestedFilename; } /** diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_intent.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_intent.cpp index 856179346..ed5950311 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_intent.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_intent.cpp @@ -29,6 +29,7 @@ #include "WKAPICast.h" #include "WKArray.h" #include "WKDictionary.h" +#include "WKEinaSharedString.h" #include "WKIntentData.h" #include "WKRetainPtr.h" #include "WKString.h" @@ -47,26 +48,23 @@ struct _Ewk_Intent { #if ENABLE(WEB_INTENTS) WKRetainPtr<WKIntentDataRef> wkIntent; #endif - const char* action; - const char* type; - const char* service; + WKEinaSharedString action; + WKEinaSharedString type; + WKEinaSharedString service; _Ewk_Intent(WKIntentDataRef intentRef) : __ref(1) #if ENABLE(WEB_INTENTS) , wkIntent(intentRef) + , action(AdoptWK, WKIntentDataCopyAction(intentRef)) + , type(AdoptWK, WKIntentDataCopyType(intentRef)) + , service(AdoptWK, WKIntentDataCopyService(intentRef)) #endif - , action(0) - , type(0) - , service(0) { } ~_Ewk_Intent() { ASSERT(!__ref); - eina_stringshare_del(action); - eina_stringshare_del(type); - eina_stringshare_del(service); } }; @@ -103,47 +101,23 @@ void ewk_intent_unref(Ewk_Intent* intent) const char* ewk_intent_action_get(const Ewk_Intent* intent) { -#if ENABLE(WEB_INTENTS) - EWK_INTENT_WK_GET_OR_RETURN(intent, wkIntent, 0); - - WKRetainPtr<WKStringRef> wkAction(AdoptWK, WKIntentDataCopyAction(wkIntent)); - Ewk_Intent* ewkIntent = const_cast<Ewk_Intent*>(intent); - eina_stringshare_replace(&ewkIntent->action, toImpl(wkAction.get())->string().utf8().data()); + EINA_SAFETY_ON_NULL_RETURN_VAL(intent, 0); return intent->action; -#else - return 0; -#endif } const char* ewk_intent_type_get(const Ewk_Intent* intent) { -#if ENABLE(WEB_INTENTS) - EWK_INTENT_WK_GET_OR_RETURN(intent, wkIntent, 0); - - WKRetainPtr<WKStringRef> wkType(AdoptWK, WKIntentDataCopyType(wkIntent)); - Ewk_Intent* ewkIntent = const_cast<Ewk_Intent*>(intent); - eina_stringshare_replace(&ewkIntent->type, toImpl(wkType.get())->string().utf8().data()); + EINA_SAFETY_ON_NULL_RETURN_VAL(intent, 0); return intent->type; -#else - return 0; -#endif } const char* ewk_intent_service_get(const Ewk_Intent* intent) { -#if ENABLE(WEB_INTENTS) - EWK_INTENT_WK_GET_OR_RETURN(intent, wkIntent, 0); - - WKRetainPtr<WKURLRef> wkService(AdoptWK, WKIntentDataCopyService(wkIntent)); - Ewk_Intent* ewkIntent = const_cast<Ewk_Intent*>(intent); - eina_stringshare_replace(&ewkIntent->service, toImpl(wkService.get())->string().utf8().data()); + EINA_SAFETY_ON_NULL_RETURN_VAL(intent, 0); return intent->service; -#else - return 0; -#endif } Eina_List* ewk_intent_suggestions_get(const Ewk_Intent* intent) @@ -171,7 +145,7 @@ const char* ewk_intent_extra_get(const Ewk_Intent* intent, const char* key) EWK_INTENT_WK_GET_OR_RETURN(intent, wkIntent, 0); WKRetainPtr<WKStringRef> keyRef = adoptWK(WKStringCreateWithUTF8CString(key)); - WKRetainPtr<WKStringRef> wkValue(AdoptWK, WKIntentDataCopyExtra(wkIntent, keyRef.get())); + WKRetainPtr<WKStringRef> wkValue(AdoptWK, WKIntentDataCopyExtraValue(wkIntent, keyRef.get())); String value = toImpl(wkValue.get())->string(); if (value.isEmpty()) return 0; diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_intent_service.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_intent_service.cpp index 18422b757..19215724b 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_intent_service.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_intent_service.cpp @@ -28,6 +28,7 @@ #include "IntentServiceInfo.h" #include "WKAPICast.h" +#include "WKEinaSharedString.h" #include "WKIntentServiceInfo.h" #include "WKRetainPtr.h" #include "WKURL.h" @@ -42,49 +43,30 @@ using namespace WebKit; */ struct _Ewk_Intent_Service { unsigned int __ref; /**< the reference count of the object */ -#if ENABLE(WEB_INTENTS_TAG) - WKRetainPtr<WKIntentServiceInfoRef> wkService; -#endif - const char* action; - const char* type; - const char* href; - const char* title; - const char* disposition; + + WKEinaSharedString action; + WKEinaSharedString type; + WKEinaSharedString href; + WKEinaSharedString title; + WKEinaSharedString disposition; _Ewk_Intent_Service(WKIntentServiceInfoRef serviceRef) : __ref(1) #if ENABLE(WEB_INTENTS_TAG) - , wkService(serviceRef) + , action(AdoptWK, WKIntentServiceInfoCopyAction(serviceRef)) + , type(AdoptWK, WKIntentServiceInfoCopyType(serviceRef)) + , href(AdoptWK, WKIntentServiceInfoCopyHref(serviceRef)) + , title(AdoptWK, WKIntentServiceInfoCopyTitle(serviceRef)) + , disposition(AdoptWK, WKIntentServiceInfoCopyDisposition(serviceRef)) #endif - , action(0) - , type(0) - , href(0) - , title(0) - , disposition(0) { } ~_Ewk_Intent_Service() { ASSERT(!__ref); - eina_stringshare_del(action); - eina_stringshare_del(type); - eina_stringshare_del(href); - eina_stringshare_del(title); - eina_stringshare_del(disposition); } }; -#define EWK_INTENT_SERVICE_WK_GET_OR_RETURN(service, wkService_, ...) \ - if (!(service)) { \ - EINA_LOG_CRIT("service is NULL."); \ - return __VA_ARGS__; \ - } \ - if (!(service)->wkService) { \ - EINA_LOG_CRIT("service->wkService is NULL."); \ - return __VA_ARGS__; \ - } \ - WKIntentServiceInfoRef wkService_ = (service)->wkService.get() - void ewk_intent_service_ref(Ewk_Intent_Service* service) { #if ENABLE(WEB_INTENTS_TAG) @@ -107,77 +89,37 @@ void ewk_intent_service_unref(Ewk_Intent_Service* service) const char* ewk_intent_service_action_get(const Ewk_Intent_Service* service) { -#if ENABLE(WEB_INTENTS_TAG) - EWK_INTENT_SERVICE_WK_GET_OR_RETURN(service, wkService, 0); - - WKRetainPtr<WKStringRef> wkAction(AdoptWK, WKIntentServiceInfoCopyAction(wkService)); - Ewk_Intent_Service* ewkIntentService = const_cast<Ewk_Intent_Service*>(service); - eina_stringshare_replace(&ewkIntentService->action, toImpl(wkAction.get())->string().utf8().data()); + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); return service->action; -#else - return 0; -#endif } const char* ewk_intent_service_type_get(const Ewk_Intent_Service* service) { -#if ENABLE(WEB_INTENTS_TAG) - EWK_INTENT_SERVICE_WK_GET_OR_RETURN(service, wkService, 0); - - WKRetainPtr<WKStringRef> wkType(AdoptWK, WKIntentServiceInfoCopyType(wkService)); - Ewk_Intent_Service* ewkIntentService = const_cast<Ewk_Intent_Service*>(service); - eina_stringshare_replace(&ewkIntentService->type, toImpl(wkType.get())->string().utf8().data()); + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); return service->type; -#else - return 0; -#endif } const char* ewk_intent_service_href_get(const Ewk_Intent_Service* service) { -#if ENABLE(WEB_INTENTS_TAG) - EWK_INTENT_SERVICE_WK_GET_OR_RETURN(service, wkService, 0); - - WKRetainPtr<WKURLRef> wkHref(AdoptWK, WKIntentServiceInfoCopyHref(wkService)); - Ewk_Intent_Service* ewkIntentService = const_cast<Ewk_Intent_Service*>(service); - eina_stringshare_replace(&ewkIntentService->href, toImpl(wkHref.get())->string().utf8().data()); + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); return service->href; -#else - return 0; -#endif } const char* ewk_intent_service_title_get(const Ewk_Intent_Service* service) { -#if ENABLE(WEB_INTENTS_TAG) - EWK_INTENT_SERVICE_WK_GET_OR_RETURN(service, wkService, 0); - - WKRetainPtr<WKStringRef> wkTitle(AdoptWK, WKIntentServiceInfoCopyTitle(wkService)); - Ewk_Intent_Service* ewkIntentService = const_cast<Ewk_Intent_Service*>(service); - eina_stringshare_replace(&ewkIntentService->title, toImpl(wkTitle.get())->string().utf8().data()); + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); return service->title; -#else - return 0; -#endif } const char* ewk_intent_service_disposition_get(const Ewk_Intent_Service* service) { -#if ENABLE(WEB_INTENTS_TAG) - EWK_INTENT_SERVICE_WK_GET_OR_RETURN(service, wkService, 0); - - WKRetainPtr<WKStringRef> wkDisposition(AdoptWK, WKIntentServiceInfoCopyDisposition(wkService)); - Ewk_Intent_Service* ewkIntentService = const_cast<Ewk_Intent_Service*>(service); - eina_stringshare_replace(&ewkIntentService->disposition, toImpl(wkDisposition.get())->string().utf8().data()); + EINA_SAFETY_ON_NULL_RETURN_VAL(service, 0); return service->disposition; -#else - return 0; -#endif } #if ENABLE(WEB_INTENTS_TAG) 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 ae725d74a..190810962 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_navigation_policy_decision.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_navigation_policy_decision.cpp @@ -27,6 +27,7 @@ #include "ewk_navigation_policy_decision.h" #include "WKAPICast.h" +#include "WKEinaSharedString.h" #include "WKFramePolicyListener.h" #include "WKRetainPtr.h" #include "ewk_navigation_policy_decision_private.h" @@ -47,7 +48,7 @@ struct _Ewk_Navigation_Policy_Decision { Event_Mouse_Button mouseButton; Event_Modifier_Keys modifiers; Ewk_Url_Request* request; - const char* frameName; + 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) : __ref(1) @@ -57,7 +58,7 @@ struct _Ewk_Navigation_Policy_Decision { , mouseButton(_mouseButton) , modifiers(_modifiers) , request(_request) - , frameName(eina_stringshare_add(_frameName)) + , frameName(_frameName) { } ~_Ewk_Navigation_Policy_Decision() @@ -69,7 +70,6 @@ struct _Ewk_Navigation_Policy_Decision { WKFramePolicyListenerUse(listener.get()); ewk_url_request_unref(request); - eina_stringshare_del(frameName); } }; diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_url_request.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_url_request.cpp index f209952fe..5816b2feb 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_url_request.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_url_request.cpp @@ -27,7 +27,7 @@ #include "ewk_url_request.h" #include "WKAPICast.h" -#include "WKRetainPtr.h" +#include "WKEinaSharedString.h" #include "WKURL.h" #include "WKURLRequest.h" #include "WebURLRequest.h" @@ -42,40 +42,24 @@ using namespace WebKit; */ struct _Ewk_Url_Request { unsigned int __ref; /**< the reference count of the object */ - WKRetainPtr<WKURLRequestRef> wkRequest; - const char* url; - const char* first_party; - const char* http_method; + WKEinaSharedString url; + WKEinaSharedString first_party; + WKEinaSharedString http_method; _Ewk_Url_Request(WKURLRequestRef requestRef) : __ref(1) - , wkRequest(requestRef) - , url(0) - , first_party(0) - , http_method(0) + , url(AdoptWK, WKURLRequestCopyURL(requestRef)) + , first_party(AdoptWK, WKURLRequestCopyFirstPartyForCookies(requestRef)) + , http_method(AdoptWK, WKURLRequestCopyHTTPMethod(requestRef)) { } ~_Ewk_Url_Request() { ASSERT(!__ref); - eina_stringshare_del(url); - eina_stringshare_del(first_party); - eina_stringshare_del(http_method); } }; -#define EWK_URL_REQUEST_WK_GET_OR_RETURN(request, wkRequest_, ...) \ - if (!(request)) { \ - EINA_LOG_CRIT("request is NULL."); \ - return __VA_ARGS__; \ - } \ - if (!(request)->wkRequest) { \ - EINA_LOG_CRIT("request->wkRequest is NULL."); \ - return __VA_ARGS__; \ - } \ - WKURLRequestRef wkRequest_ = (request)->wkRequest.get() - void ewk_url_request_ref(Ewk_Url_Request* request) { EINA_SAFETY_ON_NULL_RETURN(request); @@ -94,31 +78,21 @@ void ewk_url_request_unref(Ewk_Url_Request* request) const char* ewk_url_request_url_get(const Ewk_Url_Request* request) { - EWK_URL_REQUEST_WK_GET_OR_RETURN(request, wkRequest, 0); - - WKRetainPtr<WKURLRef> wkUrl(AdoptWK, WKURLRequestCopyURL(wkRequest)); - Ewk_Url_Request* ewkRequest = const_cast<Ewk_Url_Request*>(request); - eina_stringshare_replace(&ewkRequest->url, toImpl(wkUrl.get())->string().utf8().data()); + EINA_SAFETY_ON_NULL_RETURN_VAL(request, 0); return request->url; } const char* ewk_request_cookies_first_party_get(const Ewk_Url_Request* request) { - EWK_URL_REQUEST_WK_GET_OR_RETURN(request, wkRequest, 0); - - Ewk_Url_Request* ewkRequest = const_cast<Ewk_Url_Request*>(request); - eina_stringshare_replace(&ewkRequest->first_party, toImpl(wkRequest)->resourceRequest().firstPartyForCookies().string().utf8().data()); + EINA_SAFETY_ON_NULL_RETURN_VAL(request, 0); return request->first_party; } const char* ewk_url_request_http_method_get(const Ewk_Url_Request* request) { - EWK_URL_REQUEST_WK_GET_OR_RETURN(request, wkRequest, 0); - - Ewk_Url_Request* ewkRequest = const_cast<Ewk_Url_Request*>(request); - eina_stringshare_replace(&ewkRequest->http_method, toImpl(wkRequest)->resourceRequest().httpMethod().utf8().data()); + EINA_SAFETY_ON_NULL_RETURN_VAL(request, 0); return request->http_method; } diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_url_response.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_url_response.cpp index 8f9f5366a..8d0a8ee30 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_url_response.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_url_response.cpp @@ -26,9 +26,14 @@ #include "config.h" #include "ewk_url_response.h" +#include "WKAPICast.h" +#include "WKEinaSharedString.h" +#include "WKURLResponse.h" #include "ewk_url_response_private.h" #include <wtf/text/CString.h> +using namespace WebKit; + /** * \struct _Ewk_Url_Response * @brief Contains the URL response data. @@ -37,21 +42,19 @@ struct _Ewk_Url_Response { unsigned int __ref; /**< the reference count of the object */ WebCore::ResourceResponse coreResponse; - const char* url; - const char* mimeType; + WKEinaSharedString url; + WKEinaSharedString mimeType; _Ewk_Url_Response(const WebCore::ResourceResponse& _coreResponse) : __ref(1) , coreResponse(_coreResponse) - , url(0) - , mimeType(0) + , url(AdoptWK, WKURLResponseCopyURL(toAPI(coreResponse))) + , mimeType(AdoptWK, WKURLResponseCopyMIMEType(toAPI(coreResponse))) { } ~_Ewk_Url_Response() { ASSERT(!__ref); - eina_stringshare_del(url); - eina_stringshare_del(mimeType); } }; @@ -75,9 +78,6 @@ const char* ewk_url_response_url_get(const Ewk_Url_Response* response) { EINA_SAFETY_ON_NULL_RETURN_VAL(response, 0); - Ewk_Url_Response* ewkResponse = const_cast<Ewk_Url_Response*>(response); - eina_stringshare_replace(&ewkResponse->url, response->coreResponse.url().string().utf8().data()); - return response->url; } @@ -92,9 +92,6 @@ const char* ewk_url_response_mime_type_get(const Ewk_Url_Response* response) { EINA_SAFETY_ON_NULL_RETURN_VAL(response, 0); - Ewk_Url_Response* ewkResponse = const_cast<Ewk_Url_Response*>(response); - eina_stringshare_replace(&ewkResponse->mimeType, response->coreResponse.mimeType().utf8().data()); - return response->mimeType; } diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp index 7d8b1ce05..ce7f7b454 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view.cpp @@ -26,6 +26,7 @@ #include "NativeWebWheelEvent.h" #include "PageClientImpl.h" #include "WKAPICast.h" +#include "WKEinaSharedString.h" #include "WKFindOptions.h" #include "WKRetainPtr.h" #include "WKString.h" @@ -73,11 +74,11 @@ struct _Ewk_View_Private_Data { OwnPtr<EflViewportHandler> viewportHandler; #endif - const char* uri; - const char* title; - const char* theme; - const char* customEncoding; - const char* cursorGroup; + WKEinaSharedString uri; + WKEinaSharedString title; + WKEinaSharedString theme; + WKEinaSharedString customEncoding; + WKEinaSharedString cursorGroup; Evas_Object* cursorObject; LoadingResourcesMap loadingResourcesMap; Ewk_Back_Forward_List* backForwardList; @@ -93,12 +94,7 @@ struct _Ewk_View_Private_Data { #endif _Ewk_View_Private_Data() - : uri(0) - , title(0) - , theme(0) - , customEncoding(0) - , cursorGroup(0) - , cursorObject(0) + : cursorObject(0) , backForwardList(0) #ifdef HAVE_ECORE_X , isUsingEcoreX(false) @@ -112,10 +108,6 @@ struct _Ewk_View_Private_Data { ~_Ewk_View_Private_Data() { - eina_stringshare_del(uri); - eina_stringshare_del(title); - eina_stringshare_del(theme); - eina_stringshare_del(customEncoding); _ewk_view_priv_loading_resources_clear(loadingResourcesMap); if (cursorObject) @@ -771,10 +763,12 @@ void ewk_view_uri_update(Evas_Object* ewkView) if (activeURL.isEmpty()) return; - if (!eina_stringshare_replace(&priv->uri, activeURL.utf8().data())) + if (priv->uri == activeURL.utf8().data()) return; - evas_object_smart_callback_call(ewkView, "uri,changed", static_cast<void*>(const_cast<char*>(priv->uri))); + 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)); } Eina_Bool ewk_view_uri_set(Evas_Object* ewkView, const char* uri) @@ -933,7 +927,7 @@ const char* ewk_view_title_get(const Evas_Object* ewkView) EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0); CString title = priv->pageClient->page()->pageTitle().utf8(); - eina_stringshare_replace(&priv->title, title.data()); + priv->title = title.data(); return priv->title; } @@ -1032,10 +1026,10 @@ void ewk_view_theme_set(Evas_Object* ewkView, const char* path) EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData); EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv); - if (!eina_stringshare_replace(&priv->theme, path)) - return; - - priv->pageClient->page()->setThemePath(path); + if (priv->theme != path) { + priv->theme = path; + priv->pageClient->page()->setThemePath(path); + } } const char* ewk_view_theme_get(const Evas_Object* ewkView) @@ -1381,7 +1375,7 @@ const char* ewk_view_setting_encoding_custom_get(const Evas_Object* ewkView) if (customEncoding.isEmpty()) return 0; - eina_stringshare_replace(&priv->customEncoding, customEncoding.utf8().data()); + priv->customEncoding = customEncoding.utf8().data(); return priv->customEncoding; } @@ -1391,8 +1385,8 @@ Eina_Bool ewk_view_setting_encoding_custom_set(Evas_Object* ewkView, const char* EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, false); EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, false); - if (eina_stringshare_replace(&priv->customEncoding, encoding)) - priv->pageClient->page()->setCustomTextEncodingName(encoding ? encoding : String()); + priv->customEncoding = encoding; + priv->pageClient->page()->setCustomTextEncodingName(encoding ? encoding : String()); return true; } diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_view.h b/Source/WebKit2/UIProcess/API/efl/ewk_view.h index 423f9e143..6064cf855 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_view.h +++ b/Source/WebKit2/UIProcess/API/efl/ewk_view.h @@ -42,7 +42,7 @@ * when done to continue with the form submission. If the last reference is removed on a * #Ewk_Form_Submission_Request and the form has not been submitted yet, * ewk_form_submission_request_submit() will be called automatically. - * - "intent,request,new", Ewk_Intent_Request*: reports new Web intent request. + * - "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,finished", void: reports load finished. diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_web_error.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_web_error.cpp index e6e3eb891..70380bdd2 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_web_error.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_web_error.cpp @@ -27,6 +27,7 @@ #include "ewk_web_error.h" #include "ErrorsEfl.h" +#include "WKEinaSharedString.h" #include "WKString.h" #include "WKURL.h" #include "ewk_web_error_private.h" @@ -41,19 +42,17 @@ using namespace WebKit; struct _Ewk_Web_Error { WKRetainPtr<WKErrorRef> wkError; - const char* url; - const char* description; + WKEinaSharedString url; + WKEinaSharedString description; _Ewk_Web_Error(WKErrorRef errorRef) : wkError(errorRef) - , url(0) - , description(0) + , url(AdoptWK, WKErrorCopyFailingURL(errorRef)) + , description(AdoptWK, WKErrorCopyLocalizedDescription(errorRef)) { } ~_Ewk_Web_Error() { - eina_stringshare_del(url); - eina_stringshare_del(description); } }; @@ -97,11 +96,7 @@ Ewk_Web_Error_Type ewk_web_error_type_get(const Ewk_Web_Error* error) const char* ewk_web_error_url_get(const Ewk_Web_Error* error) { - EWK_WEB_ERROR_WK_GET_OR_RETURN(error, wkError, 0); - - WKRetainPtr<WKURLRef> wkUrl(AdoptWK, WKErrorCopyFailingURL(wkError)); - Ewk_Web_Error* ewkError = const_cast<Ewk_Web_Error*>(error); - eina_stringshare_replace(&ewkError->url, toImpl(wkUrl.get())->string().utf8().data()); + EINA_SAFETY_ON_NULL_RETURN_VAL(error, 0); return error->url; } @@ -115,11 +110,7 @@ int ewk_web_error_code_get(const Ewk_Web_Error* error) const char* ewk_web_error_description_get(const Ewk_Web_Error* error) { - EWK_WEB_ERROR_WK_GET_OR_RETURN(error, wkError, 0); - - WKRetainPtr<WKStringRef> wkDescription(AdoptWK, WKErrorCopyLocalizedDescription(wkError)); - Ewk_Web_Error* ewkError = const_cast<Ewk_Web_Error*>(error); - eina_stringshare_replace(&ewkError->description, toImpl(wkDescription.get())->string().utf8().data()); + EINA_SAFETY_ON_NULL_RETURN_VAL(error, 0); return error->description; } diff --git a/Source/WebKit2/UIProcess/API/efl/ewk_web_resource.cpp b/Source/WebKit2/UIProcess/API/efl/ewk_web_resource.cpp index e0d728a9e..355592df4 100644 --- a/Source/WebKit2/UIProcess/API/efl/ewk_web_resource.cpp +++ b/Source/WebKit2/UIProcess/API/efl/ewk_web_resource.cpp @@ -26,24 +26,24 @@ #include "config.h" #include "ewk_web_resource.h" +#include "WKEinaSharedString.h" #include "ewk_web_resource_private.h" #include <wtf/text/CString.h> struct _Ewk_Web_Resource { unsigned int __ref; /**< the reference count of the object */ - const char* url; + WKEinaSharedString url; bool isMainResource; - _Ewk_Web_Resource(const char* _url, bool _isMainResource) + _Ewk_Web_Resource(const char* url, bool isMainResource) : __ref(1) - , url(eina_stringshare_add(_url)) - , isMainResource(_isMainResource) + , url(url) + , isMainResource(isMainResource) { } ~_Ewk_Web_Resource() { ASSERT(!__ref); - eina_stringshare_del(url); } }; diff --git a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp index 4069e25fa..39bc5a4db 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp +++ b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp @@ -112,4 +112,12 @@ void EWK2UnitTestBase::waitUntilTitleChangedTo(const char* expectedTitle) evas_object_smart_callback_del(m_webView, "title,changed", onTitleChanged); } +void EWK2UnitTestBase::mouseClick(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); + evas_event_feed_mouse_up(evas, /* Left */ 1, EVAS_BUTTON_NONE, 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 64b9bce60..29d55bee4 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h +++ b/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h @@ -38,6 +38,7 @@ protected: void loadUrlSync(const char* url); void waitUntilTitleChangedTo(const char* expectedTitle); + void mouseClick(int x, int y); private: Evas_Object* m_webView; diff --git a/Source/WebKit2/UIProcess/API/efl/tests/resources/default_test_page.html b/Source/WebKit2/UIProcess/API/efl/tests/resources/default_test_page.html index edd81e732..5d1e00856 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/resources/default_test_page.html +++ b/Source/WebKit2/UIProcess/API/efl/tests/resources/default_test_page.html @@ -1,4 +1,5 @@ <HTML> +<title>Default Testing Web Page</title> <BODY> <H2 align="center">EFL Unit Tests</H2> <H2 align="center">Default Testing Web Page</H2> diff --git a/Source/WebKit2/UIProcess/API/efl/tests/resources/intent-request.html b/Source/WebKit2/UIProcess/API/efl/tests/resources/intent-request.html new file mode 100644 index 000000000..7b06cbec9 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/tests/resources/intent-request.html @@ -0,0 +1,29 @@ +<html> +<head> +<title>Web intent request test</title> +<script type="text/javascript"> +var clickCount = 0; + +function buttonClicked() { + if (clickCount == 0) { + var testIntent = new WebKitIntent( + {"action": "action1", + "type": "mime/type1", + "service": "http://service1.com/", + "extras": {"key1": "value1", "key2": "value2"}}); + navigator.webkitStartActivity(testIntent); + } else if (clickCount == 1) { + var testIntent = new WebKitIntent( + {"action": "action2", + "type": "mime/type2", + "suggestions": ["http://service1.com/", "http://service2.com/"]}); + navigator.webkitStartActivity(testIntent); + } + clickCount++; +} +</script> +</head> +<body> +<input type="button" id="button" value="Start Web Intent" onmouseup="buttonClicked()" style="position: absolute; top: 0px; left: 0px;"/> +</body> +</html> diff --git a/Source/WebKit2/UIProcess/API/efl/tests/resources/intent-service.html b/Source/WebKit2/UIProcess/API/efl/tests/resources/intent-service.html new file mode 100644 index 000000000..1d9fa2a33 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/tests/resources/intent-service.html @@ -0,0 +1,9 @@ +<html> +<head> +<title>Web Intent service registration test</title> +</head> + <body> + <intent action="action" type="type" title="Title" href="http://example.com/service" disposition="inline"></intent> + Registered Intent Service. + </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 new file mode 100644 index 000000000..af10981ec --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_back_forward_list.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 "WKEinaSharedString.h" +#include <EWebKit2.h> +#include <gtest/gtest.h> +#include <wtf/OwnPtr.h> +#include <wtf/PassOwnPtr.h> + +using namespace EWK2UnitTest; +using namespace WTF; + +extern EWK2UnitTestEnvironment* environment; + +static const char title1[] = "Page1"; +static const char title2[] = "Page2"; + +static void serverCallbackNavigation(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) +{ + if (message->method != SOUP_METHOD_GET) { + soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); + return; + } + + soup_message_set_status(message, SOUP_STATUS_OK); + + Eina_Strbuf* body = eina_strbuf_new(); + eina_strbuf_append_printf(body, "<html><title>%s</title><body>%s</body></html>", path + 1, path + 1); + 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); +} + +static inline void checkItem(Ewk_Back_Forward_List_Item* item, const char* title, const char* uri, const char* originalURI) +{ + ASSERT_TRUE(item); + EXPECT_STREQ(uri, ewk_back_forward_list_item_uri_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)); +} + +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(); + eina_strbuf_free(path); + + return res; +} + +TEST_F(EWK2UnitTestBase, ewk_back_forward_list_current_item_get) +{ + const char* url = environment->defaultTestPageUrl(); + loadUrlSync(url); + Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView()); + ASSERT_TRUE(backForwardList); + + Ewk_Back_Forward_List_Item* currentItem = ewk_back_forward_list_current_item_get(backForwardList); + checkItem(currentItem, ewk_view_title_get(webView()), url, url); + + Ewk_Back_Forward_List_Item* anotherCurrentItem = ewk_back_forward_list_current_item_get(backForwardList); + ASSERT_EQ(currentItem, anotherCurrentItem); +} + +TEST_F(EWK2UnitTestBase, ewk_back_forward_list_previous_item_get) +{ + OwnPtr<EWK2UnitTestServer> httpServer = adoptPtr(new EWK2UnitTestServer); + httpServer->run(serverCallbackNavigation); + + WKEinaSharedString url1 = urlFromTitle(httpServer.get(), title1); + loadUrlSync(url1); + ASSERT_STREQ(ewk_view_title_get(webView()), title1); + + loadUrlSync(urlFromTitle(httpServer.get(), title2)); + ASSERT_STREQ(ewk_view_title_get(webView()), title2); + + Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView()); + ASSERT_TRUE(backForwardList); + + Ewk_Back_Forward_List_Item* previousItem = ewk_back_forward_list_previous_item_get(backForwardList); + checkItem(previousItem, title1, url1, url1); + + Ewk_Back_Forward_List_Item* anotherPreviousItem = ewk_back_forward_list_previous_item_get(backForwardList); + ASSERT_EQ(previousItem, anotherPreviousItem); +} + +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); + + WKEinaSharedString url2 = urlFromTitle(httpServer.get(), title2); + loadUrlSync(url2); + ASSERT_STREQ(ewk_view_title_get(webView()), title2); + + // Go back to Page1. + ewk_view_back(webView()); + waitUntilTitleChangedTo(title1); + + Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView()); + ASSERT_TRUE(backForwardList); + + Ewk_Back_Forward_List_Item* nextItem = ewk_back_forward_list_next_item_get(backForwardList); + checkItem(nextItem, title2, url2, url2); + + Ewk_Back_Forward_List_Item* anotherNextItem = ewk_back_forward_list_next_item_get(backForwardList); + ASSERT_EQ(nextItem, anotherNextItem); +} + +TEST_F(EWK2UnitTestBase, ewk_back_forward_list_item_at_index_get) +{ + OwnPtr<EWK2UnitTestServer> httpServer = adoptPtr(new EWK2UnitTestServer); + httpServer->run(serverCallbackNavigation); + + WKEinaSharedString url1 = urlFromTitle(httpServer.get(), title1); + loadUrlSync(url1); + ASSERT_STREQ(ewk_view_title_get(webView()), title1); + + loadUrlSync(urlFromTitle(httpServer.get(), title2)); + ASSERT_STREQ(ewk_view_title_get(webView()), title2); + + Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView()); + ASSERT_TRUE(backForwardList); + + Ewk_Back_Forward_List_Item* previousItem = ewk_back_forward_list_item_at_index_get(backForwardList, -1); + checkItem(previousItem, title1, url1, url1); + + Ewk_Back_Forward_List_Item* anotherPreviousItem = ewk_back_forward_list_item_at_index_get(backForwardList, -1); + ASSERT_EQ(previousItem, anotherPreviousItem); + + Ewk_Back_Forward_List_Item* nonExistingItem = ewk_back_forward_list_item_at_index_get(backForwardList, 10); + ASSERT_FALSE(nonExistingItem); +} + +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); + + loadUrlSync(urlFromTitle(httpServer.get(), title2)); + ASSERT_STREQ(ewk_view_title_get(webView()), title2); + + Ewk_Back_Forward_List* backForwardList = ewk_view_back_forward_list_get(webView()); + ASSERT_TRUE(backForwardList); + + EXPECT_EQ(ewk_back_forward_list_count(backForwardList), 2); +} 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 034f87140..a5e8157da 100644 --- a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_context.cpp +++ b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_context.cpp @@ -28,6 +28,7 @@ #include "UnitTestUtils/EWK2UnitTestBase.h" #include "UnitTestUtils/EWK2UnitTestEnvironment.h" #include <EWebKit2.h> +#include <Ecore.h> #include <gtest/gtest.h> using namespace EWK2UnitTest; @@ -67,3 +68,83 @@ TEST_F(EWK2UnitTestBase, ewk_context_uri_scheme_register) loadUrlSync("fooscheme:MyPath"); ASSERT_STREQ(ewk_view_title_get(webView()), "Foo"); } + +struct VibrationCbData { + bool didReceiveVibrateCallback; // Whether the vibration event received. + bool didReceiveCancelVibrationCallback; // Whether the cancel vibration event received. + unsigned vibrateCalledCount; // Vibrate callbacks count. + uint64_t expectedVibrationTime; // Expected vibration time. +}; + +static void vibrateCallback(uint64_t vibrationTime, void* userData) +{ + VibrationCbData* data = static_cast<VibrationCbData*>(userData); + if (vibrationTime == data->expectedVibrationTime) + data->didReceiveVibrateCallback = true; + data->vibrateCalledCount++; +} + +static void cancelVibrationCallback(void* userData) +{ + VibrationCbData* data = static_cast<VibrationCbData*>(userData); + data->didReceiveCancelVibrationCallback = true; +} + +static void loadVibrationHTMLString(Evas_Object* webView, const char* vibrationPattern, bool waitForVibrationEvent, VibrationCbData* data) +{ + const char* content = + "<html><head><script type='text/javascript'>function vibrate() { navigator.vibrate(%s);" + " document.title = \"Loaded\"; }</script></head><body onload='vibrate()'></body></html>"; + + data->didReceiveVibrateCallback = false; + data->didReceiveCancelVibrationCallback = false; + data->vibrateCalledCount = 0; + Eina_Strbuf* buffer = eina_strbuf_new(); + eina_strbuf_append_printf(buffer, content, vibrationPattern); + ewk_view_html_string_load(webView, eina_strbuf_string_get(buffer), 0, 0); + eina_strbuf_free(buffer); + + if (!waitForVibrationEvent) + return; + + while (!data->didReceiveVibrateCallback && !data->didReceiveCancelVibrationCallback) + ecore_main_loop_iterate(); +} + +TEST_F(EWK2UnitTestBase, ewk_context_vibration_client_callbacks_set) +{ + VibrationCbData data = { false, false, 0, 5000 }; + ewk_context_vibration_client_callbacks_set(ewk_context_default_get(), vibrateCallback, cancelVibrationCallback, &data); + + // Vibrate for 5 seconds. + loadVibrationHTMLString(webView(), "5000", true, &data); + ASSERT_TRUE(data.didReceiveVibrateCallback); + + // Cancel any existing vibrations. + loadVibrationHTMLString(webView(), "0", true, &data); + ASSERT_TRUE(data.didReceiveCancelVibrationCallback); + + // 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_TRUE(data.didReceiveVibrateCallback); + + // Cancel outstanding vibration pattern. + loadVibrationHTMLString(webView(), "[0]", true, &data); + ASSERT_TRUE(data.didReceiveCancelVibrationCallback); + + // Stop listening for vibration events, by calling the function with null for the callbacks. + ewk_context_vibration_client_callbacks_set(ewk_context_default_get(), 0, 0, &data); + + // Make sure we don't receive vibration event. + loadVibrationHTMLString(webView(), "[5000]", false, &data); + waitUntilTitleChangedTo("Loaded"); + ASSERT_STREQ(ewk_view_title_get(webView()), "Loaded"); + ASSERT_FALSE(data.didReceiveVibrateCallback); + + // Make sure we don't receive cancel vibration event. + loadVibrationHTMLString(webView(), "0", false, &data); + waitUntilTitleChangedTo("Loaded"); + ASSERT_STREQ(ewk_view_title_get(webView()), "Loaded"); + ASSERT_FALSE(data.didReceiveCancelVibrationCallback); +} 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 7dbd496bd..10be26cb5 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 @@ -57,7 +57,7 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char* eina_strbuf_append_printf(buffer, INDEX_HTML_STRING, soup_server_get_port(server)); soup_message_headers_replace(message->response_headers, "Set-Cookie", "foo=bar; Max-Age=60"); soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, eina_strbuf_string_steal(buffer), eina_strbuf_length_get(buffer)); - eina_strbuf_string_free(buffer); + eina_strbuf_free(buffer); } else if (!strcmp(path, "/image.png")) soup_message_headers_replace(message->response_headers, "Set-Cookie", "baz=qux; Max-Age=60"); else diff --git a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_eina_shared_string.cpp b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_eina_shared_string.cpp new file mode 100644 index 000000000..7f62e0b1e --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_eina_shared_string.cpp @@ -0,0 +1,118 @@ +/* + * 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 "WKEinaSharedString.h" +#include <EWebKit2.h> +#include <Ecore.h> +#include <WebKit2/WKString.h> +#include <WebKit2/WKURL.h> +#include <gtest/gtest.h> + +using namespace EWK2UnitTest; + +extern EWK2UnitTestEnvironment* environment; + +// Use macro here instead of global variables in order not to have always the same pointers. +#define testString "I'm test string!" +#define anotherTestString "I'm another test string!" +#define testUrl "file:///path/somewhere" + +static inline void checkString(const WKEinaSharedString& string, const char* pattern) +{ + ASSERT_EQ(string.isNull(), pattern ? false : true); + ASSERT_EQ(string.length(), pattern ? strlen(pattern) : 0); // Compare length. + ASSERT_EQ(string, pattern); // Compare values. Check '==' operator with WKEinaSharedString and plain string. + ASSERT_STREQ(string, pattern); // Compare values. Check 'const char*' operator. +} + +TEST_F(EWK2UnitTestBase, constructEmpty) +{ + WKEinaSharedString emptyString; + checkString(emptyString, 0); +} + +TEST_F(EWK2UnitTestBase, constructFromPlainString) +{ + WKEinaSharedString emptyString(testString); + checkString(emptyString, testString); +} + +TEST_F(EWK2UnitTestBase, constructFromWKString) +{ + WKEinaSharedString string(AdoptWK, WKStringCreateWithUTF8CString(testString)); + checkString(string, testString); +} + +TEST_F(EWK2UnitTestBase, constructFromWKURL) +{ + WKEinaSharedString string(AdoptWK, WKURLCreateWithUTF8CString(testUrl)); + checkString(string, testUrl); +} + +TEST_F(EWK2UnitTestBase, costructCopy) +{ + WKEinaSharedString string(testString); + WKEinaSharedString copyString(string); + checkString(string, testString); + checkString(copyString, testString); + ASSERT_EQ(string, copyString); // Check '==' operator with two instances of WKEinaSharedString. +} + +TEST_F(EWK2UnitTestBase, comparisonOperators) +{ + WKEinaSharedString string(testString); + WKEinaSharedString sameString(testString); + WKEinaSharedString anotherString(anotherTestString); + + ASSERT_EQ(string, sameString); // Check '==' operator with two instances of WKEinaSharedString. + ASSERT_NE(string, anotherString); // Check '!=' operator with two instances of WKEinaSharedString. + + const char* explicitlySharedString = eina_stringshare_add(testString); + ASSERT_EQ(static_cast<const char*>(string), explicitlySharedString); // Compare pointers. + ASSERT_STREQ(string, explicitlySharedString); // Compare values. + eina_stringshare_del(explicitlySharedString); + + ASSERT_EQ(string, string); // Self-comparison. +} + +TEST_F(EWK2UnitTestBase, assignmentOperators) +{ + WKEinaSharedString string; + + string = testString; + checkString(string, testString); + + WKEinaSharedString anotherString(anotherTestString); + string = anotherString; + checkString(string, anotherTestString); + ASSERT_EQ(string, anotherString); + + string = string; // Check that self-assignment does not break WKEinaSharedString internal data. + checkString(string, anotherTestString); +} diff --git a/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_intents.cpp b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_intents.cpp new file mode 100644 index 000000000..fdf7fdf23 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_intents.cpp @@ -0,0 +1,116 @@ +/* + * 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> + +using namespace EWK2UnitTest; + +extern EWK2UnitTestEnvironment* environment; + +static void onIntentServiceRegistration(void* userData, Evas_Object*, void* eventInfo) +{ + bool* intentRegistered = static_cast<bool*>(userData); + ASSERT_FALSE(*intentRegistered); + *intentRegistered = true; + + 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"); +} + +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()); + evas_object_smart_callback_del(webView(), "intent,service,register", onIntentServiceRegistration); + ASSERT_TRUE(intentRegistered); +} + +int stringSortCb(const void* d1, const void* d2) +{ + return strcmp(static_cast<const char*>(d1), static_cast<const char*>(d2)); +} + +static void onIntentReceived(void* userData, Evas_Object*, void* eventInfo) +{ + unsigned* intentReceivedCount = static_cast<unsigned*>(userData); + ASSERT_GE(*intentReceivedCount, 0); + ASSERT_LE(*intentReceivedCount, 1); + ++(*intentReceivedCount); + + Ewk_Intent* intent = static_cast<Ewk_Intent*>(eventInfo); + ASSERT_TRUE(intent); + + 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"); + } else { + // Second intent. + EXPECT_STREQ(ewk_intent_action_get(intent), "action2"); + EXPECT_STREQ(ewk_intent_type_get(intent), "mime/type2"); + Eina_List* suggestions = ewk_intent_suggestions_get(intent); + ASSERT_TRUE(suggestions); + ASSERT_EQ(eina_list_count(suggestions), 2); + // 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/"); + } +} + +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()); + + // A user gesture is required for the intent to start. + mouseClick(5, 5); + while (intentReceivedCount != 1) + ecore_main_loop_iterate(); + ASSERT_EQ(intentReceivedCount, 1); + + // Generate a second intent request. + mouseClick(5, 5); + while (intentReceivedCount != 2) + ecore_main_loop_iterate(); + ASSERT_EQ(intentReceivedCount, 2); + evas_object_smart_callback_del(webView(), "intent,request,new", onIntentReceived); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp index 43ec3338d..29811fc6a 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp @@ -33,7 +33,8 @@ enum { PROP_URI, PROP_STATUS_CODE, PROP_CONTENT_LENGTH, - PROP_MIME_TYPE + PROP_MIME_TYPE, + PROP_SUGGESTED_FILENAME }; using namespace WebKit; @@ -45,6 +46,7 @@ struct _WebKitURIResponsePrivate { WebCore::ResourceResponse resourceResponse; CString uri; CString mimeType; + CString suggestedFilename; }; static void webkitURIResponseFinalize(GObject* object) @@ -70,6 +72,9 @@ static void webkitURIResponseGetProperty(GObject* object, guint propId, GValue* case PROP_MIME_TYPE: g_value_set_string(value, webkit_uri_response_get_mime_type(response)); break; + case PROP_SUGGESTED_FILENAME: + g_value_set_string(value, webkit_uri_response_get_suggested_filename(response)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec); } @@ -133,6 +138,19 @@ static void webkit_uri_response_class_init(WebKitURIResponseClass* responseClass 0, WEBKIT_PARAM_READABLE)); + /** + * WebKitURIResponse:suggested-filename: + * + * The suggested filename for the URI response. + */ + g_object_class_install_property(objectClass, + PROP_SUGGESTED_FILENAME, + g_param_spec_string("suggested-filename", + _("Suggested Filename"), + _("The suggested filename for the URI response"), + 0, + WEBKIT_PARAM_READABLE)); + g_type_class_add_private(responseClass, sizeof(WebKitURIResponsePrivate)); } @@ -230,6 +248,28 @@ gboolean webkit_uri_response_get_https_status(WebKitURIResponse* response, GTlsC return !!response->priv->resourceResponse.soupMessageCertificate(); } +/** + * webkit_uri_response_get_suggested_filename: + * @response: a #WebKitURIResponse + * + * Get the suggested filename for @response, as specified by + * the 'Content-Disposition' HTTP header, or %NULL if it's not + * present. + * + * Returns: (transfer none): the suggested filename or %NULL if + * the 'Content-Disposition' HTTP header is not present. + */ +const gchar* webkit_uri_response_get_suggested_filename(WebKitURIResponse* response) +{ + g_return_val_if_fail(WEBKIT_IS_URI_RESPONSE(response), 0); + + if (response->priv->resourceResponse.suggestedFilename().isEmpty()) + return 0; + + response->priv->suggestedFilename = response->priv->resourceResponse.suggestedFilename().utf8(); + return response->priv->suggestedFilename.data(); +} + WebKitURIResponse* webkitURIResponseCreateForResourceResponse(const WebCore::ResourceResponse& resourceResponse) { WebKitURIResponse* uriResponse = WEBKIT_URI_RESPONSE(g_object_new(WEBKIT_TYPE_URI_RESPONSE, NULL)); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h b/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h index 19705921a..d90cf4132 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h @@ -53,24 +53,26 @@ struct _WebKitURIResponseClass { }; WEBKIT_API GType -webkit_uri_response_get_type (void); +webkit_uri_response_get_type (void); WEBKIT_API const gchar * -webkit_uri_response_get_uri (WebKitURIResponse *response); +webkit_uri_response_get_uri (WebKitURIResponse *response); WEBKIT_API guint -webkit_uri_response_get_status_code (WebKitURIResponse *response); +webkit_uri_response_get_status_code (WebKitURIResponse *response); WEBKIT_API guint64 -webkit_uri_response_get_content_length (WebKitURIResponse *response); +webkit_uri_response_get_content_length (WebKitURIResponse *response); WEBKIT_API const gchar * -webkit_uri_response_get_mime_type (WebKitURIResponse *response); +webkit_uri_response_get_mime_type (WebKitURIResponse *response); WEBKIT_API gboolean -webkit_uri_response_get_https_status (WebKitURIResponse *response, - GTlsCertificate **certificate, - GTlsCertificateFlags *errors); +webkit_uri_response_get_https_status (WebKitURIResponse *response, + GTlsCertificate **certificate, + GTlsCertificateFlags *errors); +WEBKIT_API const gchar * +webkit_uri_response_get_suggested_filename (WebKitURIResponse *response); G_END_DECLS diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp index fe9df9f75..620c9a876 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp @@ -32,6 +32,7 @@ #include "WebKitURISchemeRequestPrivate.h" #include "WebKitWebContextPrivate.h" #include <WebCore/FileSystem.h> +#include <WebCore/Language.h> #include <wtf/HashMap.h> #include <wtf/OwnPtr.h> #include <wtf/gobject/GOwnPtr.h> @@ -518,6 +519,31 @@ void webkit_web_context_set_spell_checking_languages(WebKitWebContext* context, #endif } +/** + * webkit_web_context_set_preferred_languages: + * @context: a #WebKitWebContext + * @languages: (element-type utf8): a #GList of language identifiers + * + * Set the list of preferred languages, sorted from most desirable + * to least desirable. The list will be used to build the "Accept-Language" + * header that will be included in the network requests started by + * the #WebKitWebContext. + */ +void webkit_web_context_set_preferred_languages(WebKitWebContext* context, GList* languageList) +{ + g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context)); + + if (!languageList) + return; + + Vector<String> languages; + for (GList* iter = languageList; iter; iter = g_list_next(iter)) + languages.append(String::fromUTF8(static_cast<char*>(iter->data)).lower().replace("_", "-")); + + WebCore::overrideUserPreferredLanguages(languages); + WebCore::languageDidChange(); +} + WebKitDownload* webkitWebContextGetOrCreateDownload(WKDownloadRef wkDownload) { GRefPtr<WebKitDownload> download = downloadsMap().get(wkDownload); diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h index 0d32ba5bb..5af7f2414 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h @@ -146,6 +146,10 @@ WEBKIT_API void webkit_web_context_set_spell_checking_languages (WebKitWebContext *context, const gchar *languages); +WEBKIT_API void +webkit_web_context_set_preferred_languages (WebKitWebContext *context, + GList *languages); + G_END_DECLS #endif diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp index 80e5fff23..ee86d448a 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp @@ -79,7 +79,7 @@ enum { MOUSE_TARGET_CHANGED, - PRINT_REQUESTED, + PRINT, RESOURCE_LOAD_STARTED, @@ -106,13 +106,6 @@ enum { PROP_ZOOM_LEVEL }; -typedef enum { - NotReplacingContent, - WillReplaceContent, - ReplacingContent, - DidReplaceContent -} ReplaceContentStatus; - typedef HashMap<uint64_t, GRefPtr<WebKitWebResource> > LoadingResourcesMap; typedef HashMap<String, GRefPtr<WebKitWebResource> > ResourcesMap; @@ -122,7 +115,6 @@ struct _WebKitWebViewPrivate { CString customTextEncoding; double estimatedLoadProgress; CString activeURI; - ReplaceContentStatus replaceContentStatus; bool waitingForMainResource; gulong mainResourceResponseHandlerID; @@ -159,7 +151,7 @@ static gboolean webkitWebViewLoadFail(WebKitWebView* webView, WebKitLoadEvent, c return FALSE; GOwnPtr<char> htmlString(g_strdup_printf("<html><body>%s</body></html>", error->message)); - webkit_web_view_replace_content(webView, htmlString.get(), failingURI, 0); + webkit_web_view_load_alternate_html(webView, htmlString.get(), failingURI, 0); return TRUE; } @@ -882,7 +874,7 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) WEBKIT_TYPE_HIT_TEST_RESULT, G_TYPE_UINT); /** - * WebKitWebView::print-requested: + * WebKitWebView::print: * @web_view: the #WebKitWebView on which the signal is emitted * @print_operation: the #WebKitPrintOperation that will handle the print request * @@ -899,11 +891,11 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) * Returns: %TRUE to stop other handlers from being invoked for the event. * %FALSE to propagate the event further. */ - signals[PRINT_REQUESTED] = - g_signal_new("print-requested", + signals[PRINT] = + g_signal_new("print", G_TYPE_FROM_CLASS(webViewClass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET(WebKitWebViewClass, print_requested), + G_STRUCT_OFFSET(WebKitWebViewClass, print), g_signal_accumulator_true_handled, 0, webkit_marshal_BOOLEAN__OBJECT, G_TYPE_BOOLEAN, 1, @@ -1107,25 +1099,6 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) WEBKIT_TYPE_FORM_SUBMISSION_REQUEST); } -static bool updateReplaceContentStatus(WebKitWebView* webView, WebKitLoadEvent loadEvent) -{ - if (webView->priv->replaceContentStatus == ReplacingContent) { - if (loadEvent == WEBKIT_LOAD_FINISHED) - webView->priv->replaceContentStatus = DidReplaceContent; - return true; - } - - if (loadEvent == WEBKIT_LOAD_STARTED) { - if (webView->priv->replaceContentStatus == WillReplaceContent) { - webView->priv->replaceContentStatus = ReplacingContent; - return true; - } - webView->priv->replaceContentStatus = NotReplacingContent; - } - - return false; -} - static void setCertificateToMainResource(WebKitWebView* webView) { WebKitWebViewPrivate* priv = webView->priv; @@ -1169,21 +1142,16 @@ void webkitWebViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent) webView->priv->waitingForMainResource = false; } else if (loadEvent == WEBKIT_LOAD_COMMITTED) { webView->priv->subresourcesMap.clear(); - if (webView->priv->replaceContentStatus != ReplacingContent) { - if (!webView->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; - } else - setCertificateToMainResource(webView); - } + if (!webView->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; + } else + setCertificateToMainResource(webView); } - if (updateReplaceContentStatus(webView, loadEvent)) - return; - if (webView->priv->waitingForMainResource) webView->priv->lastDelayedEvent = loadEvent; else @@ -1192,9 +1160,6 @@ void webkitWebViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent) void webkitWebViewLoadFailed(WebKitWebView* webView, WebKitLoadEvent loadEvent, const char* failingURI, GError *error) { - if (webView->priv->replaceContentStatus == ReplacingContent) - return; - gboolean returnValue; g_signal_emit(webView, signals[LOAD_FAILED], 0, loadEvent, failingURI, error, &returnValue); g_signal_emit(webView, signals[LOAD_CHANGED], 0, WEBKIT_LOAD_FINISHED); @@ -1212,9 +1177,6 @@ void webkitWebViewSetTitle(WebKitWebView* webView, const CString& title) void webkitWebViewSetEstimatedLoadProgress(WebKitWebView* webView, double estimatedLoadProgress) { - if (webView->priv->replaceContentStatus != NotReplacingContent) - return; - if (webView->priv->estimatedLoadProgress == estimatedLoadProgress) return; @@ -1321,7 +1283,7 @@ void webkitWebViewPrintFrame(WebKitWebView* webView, WKFrameRef wkFrame) { GRefPtr<WebKitPrintOperation> printOperation = adoptGRef(webkit_print_operation_new(webView)); gboolean returnValue; - g_signal_emit(webView, signals[PRINT_REQUESTED], 0, printOperation.get(), &returnValue); + g_signal_emit(webView, signals[PRINT], 0, printOperation.get(), &returnValue); if (returnValue) return; @@ -1349,16 +1311,8 @@ static void waitForMainResourceResponseIfWaitingForResource(WebKitWebView* webVi g_signal_connect(priv->mainResource.get(), "notify::response", G_CALLBACK(mainResourceResponseChangedCallback), webView); } -static inline bool webkitWebViewIsReplacingContentOrDidReplaceContent(WebKitWebView* webView) -{ - return (webView->priv->replaceContentStatus == ReplacingContent || webView->priv->replaceContentStatus == DidReplaceContent); -} - void webkitWebViewResourceLoadStarted(WebKitWebView* webView, WKFrameRef wkFrame, uint64_t resourceIdentifier, WebKitURIRequest* request, bool isMainResource) { - if (webkitWebViewIsReplacingContentOrDidReplaceContent(webView)) - return; - WebKitWebViewPrivate* priv = webView->priv; WebKitWebResource* resource = webkitWebResourceCreate(wkFrame, request, isMainResource); if (WKFrameIsMainFrame(wkFrame) && (isMainResource || !priv->mainResource)) { @@ -1371,9 +1325,6 @@ void webkitWebViewResourceLoadStarted(WebKitWebView* webView, WKFrameRef wkFrame WebKitWebResource* webkitWebViewGetLoadingWebResource(WebKitWebView* webView, uint64_t resourceIdentifier) { - if (webkitWebViewIsReplacingContentOrDidReplaceContent(webView)) - return 0; - GRefPtr<WebKitWebResource> resource = webView->priv->loadingResourcesMap.get(resourceIdentifier); ASSERT(resource.get()); return resource.get(); @@ -1381,9 +1332,6 @@ WebKitWebResource* webkitWebViewGetLoadingWebResource(WebKitWebView* webView, ui void webkitWebViewRemoveLoadingWebResource(WebKitWebView* webView, uint64_t resourceIdentifier) { - if (webkitWebViewIsReplacingContentOrDidReplaceContent(webView)) - return; - WebKitWebViewPrivate* priv = webView->priv; ASSERT(priv->loadingResourcesMap.contains(resourceIdentifier)); priv->loadingResourcesMap.remove(resourceIdentifier); @@ -1391,9 +1339,6 @@ void webkitWebViewRemoveLoadingWebResource(WebKitWebView* webView, uint64_t reso WebKitWebResource* webkitWebViewResourceLoadFinished(WebKitWebView* webView, uint64_t resourceIdentifier) { - if (webkitWebViewIsReplacingContentOrDidReplaceContent(webView)) - return 0; - WebKitWebViewPrivate* priv = webView->priv; WebKitWebResource* resource = webkitWebViewGetLoadingWebResource(webView, resourceIdentifier); if (resource != priv->mainResource) @@ -1597,6 +1542,33 @@ void webkit_web_view_load_html(WebKitWebView* webView, const gchar* content, con } /** + * webkit_web_view_load_alternate_html: + * @web_view: a #WebKitWebView + * @content: the new content to display as the main page of the @web_view + * @content_uri: the URI for the alternate page content + * @base_uri: (allow-none): the base URI for relative locations or %NULL + * + * Load the given @content string for the URI @content_uri. + * This allows clients to display page-loading errors in the #WebKitWebView itself. + * When this method is called from #WebKitWebView::load-failed signal to show an + * error page, the the back-forward list is maintained appropriately. + * For everything else this method works the same way as webkit_web_view_load_html(). + */ +void webkit_web_view_load_alternate_html(WebKitWebView* webView, const gchar* content, const gchar* contentURI, const gchar* baseURI) +{ + g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); + g_return_if_fail(content); + g_return_if_fail(contentURI); + + WKRetainPtr<WKStringRef> htmlString(AdoptWK, WKStringCreateWithUTF8CString(content)); + WKRetainPtr<WKURLRef> contentURL(AdoptWK, WKURLCreateWithUTF8CString(contentURI)); + WKRetainPtr<WKURLRef> baseURL = baseURI ? adoptWK(WKURLCreateWithUTF8CString(baseURI)) : 0; + WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)); + WKPageLoadAlternateHTMLString(toAPI(page), htmlString.get(), baseURL.get(), contentURL.get()); + webkitWebViewUpdateURI(webView); +} + +/** * webkit_web_view_load_plain_text: * @web_view: a #WebKitWebView * @plain_text: The plain text to load @@ -1637,36 +1609,6 @@ void webkit_web_view_load_request(WebKitWebView* webView, WebKitURIRequest* requ } /** - * webkit_web_view_replace_content: - * @web_view: a #WebKitWebView - * @content: the new content to display as the main page of the @web_view - * @content_uri: the URI for the page content - * @base_uri: (allow-none): the base URI for relative locations or %NULL - * - * Replace the content of @web_view with @content using @content_uri as page URI. - * This allows clients to display page-loading errors in the #WebKitWebView itself. - * This is typically called from #WebKitWebView::load-failed signal. The URI passed in - * @base_uri has to be an absolute URI. The mime type of the document will be "text/html". - * Signals #WebKitWebView::load-changed and #WebKitWebView::load-failed are not emitted - * when replacing content of a #WebKitWebView using this method. - */ -void webkit_web_view_replace_content(WebKitWebView* webView, const gchar* content, const gchar* contentURI, const gchar* baseURI) -{ - g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); - g_return_if_fail(content); - g_return_if_fail(contentURI); - - webView->priv->replaceContentStatus = WillReplaceContent; - - WKRetainPtr<WKStringRef> htmlString(AdoptWK, WKStringCreateWithUTF8CString(content)); - WKRetainPtr<WKURLRef> contentURL(AdoptWK, WKURLCreateWithUTF8CString(contentURI)); - WKRetainPtr<WKURLRef> baseURL = baseURI ? adoptWK(WKURLCreateWithUTF8CString(baseURI)) : 0; - WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView)); - WKPageLoadAlternateHTMLString(toAPI(page), htmlString.get(), baseURL.get(), contentURL.get()); - webkitWebViewUpdateURI(webView); -} - -/** * webkit_web_view_get_title: * @web_view: a #WebKitWebView * @@ -1815,6 +1757,10 @@ gboolean webkit_web_view_can_go_forward(WebKitWebView* webView) * the requested URI is "about:blank". * </para></listitem> * <listitem><para> + * If the load operation was started by webkit_web_view_load_alternate_html(), + * the requested URI is content URI provided. + * </para></listitem> + * <listitem><para> * If the load operation was started by webkit_web_view_go_back() or * webkit_web_view_go_forward(), the requested URI is the original URI * of the previous/next item in the #WebKitBackForwardList of @web_view. @@ -1838,10 +1784,6 @@ gboolean webkit_web_view_can_go_forward(WebKitWebView* webView) * one and it will not change unless a new load operation is started * or a navigation action within the same page is performed. * </para></listitem> - * <listitem><para> - * When the page content is replaced using webkit_web_view_replace_content(), - * the active URI is the content_uri provided. - * </para></listitem> * </orderedlist> * * You can monitor the active URI by connecting to the notify::uri diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h index 6ebd17f04..540014ac4 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h @@ -162,7 +162,7 @@ struct _WebKitWebViewClass { void (* mouse_target_changed) (WebKitWebView *web_view, WebKitHitTestResult *hit_test_result, guint modifiers); - gboolean (* print_requested) (WebKitWebView *web_view, + gboolean (* print) (WebKitWebView *web_view, WebKitPrintOperation *print_operation); void (* resource_load_started) (WebKitWebView *web_view, WebKitWebResource *resource, @@ -210,7 +210,11 @@ WEBKIT_API void 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_API void webkit_web_view_load_plain_text (WebKitWebView *web_view, const gchar *plain_text); @@ -222,12 +226,6 @@ webkit_web_view_load_request (WebKitWebView *w WEBKIT_API void webkit_web_view_stop_loading (WebKitWebView *web_view); -WEBKIT_API void -webkit_web_view_replace_content (WebKitWebView *web_view, - const gchar *content, - const gchar *content_uri, - const gchar *base_uri); - WEBKIT_API const gchar * webkit_web_view_get_title (WebKitWebView *web_view); diff --git a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt index 92da1ebe5..596498c83 100644 --- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt +++ b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt @@ -37,6 +37,7 @@ webkit_web_context_get_spell_checking_enabled webkit_web_context_set_spell_checking_enabled webkit_web_context_get_spell_checking_languages webkit_web_context_set_spell_checking_languages +webkit_web_context_set_preferred_languages <SUBSECTION URI Scheme> WebKitURISchemeRequestCallback @@ -75,9 +76,9 @@ webkit_web_view_new_with_context webkit_web_view_get_context webkit_web_view_load_uri webkit_web_view_load_html +webkit_web_view_load_alternate_html webkit_web_view_load_plain_text webkit_web_view_load_request -webkit_web_view_replace_content webkit_web_view_can_go_back webkit_web_view_go_back webkit_web_view_can_go_forward @@ -325,6 +326,7 @@ webkit_uri_response_get_status_code webkit_uri_response_get_content_length webkit_uri_response_get_mime_type webkit_uri_response_get_https_status +webkit_uri_response_get_suggested_filename <SUBSECTION Standard> WebKitURIResponseClass diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestContextMenu.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestContextMenu.cpp index 876685712..eff59862b 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestContextMenu.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestContextMenu.cpp @@ -74,6 +74,24 @@ public: quitMainLoop(); } + GtkMenu* getPopupMenu() + { + GOwnPtr<GList> toplevels(gtk_window_list_toplevels()); + for (GList* iter = toplevels.get(); iter; iter = g_list_next(iter)) { + if (!GTK_IS_WINDOW(iter->data)) + continue; + + GtkWidget* child = gtk_bin_get_child(GTK_BIN(iter->data)); + if (!GTK_IS_MENU(child)) + continue; + + if (gtk_menu_get_attach_widget(GTK_MENU(child)) == GTK_WIDGET(m_webView)) + return GTK_MENU(child); + } + g_assert_not_reached(); + return 0; + } + bool shouldShowInputMethodsMenu() { GtkSettings* settings = gtk_widget_get_settings(GTK_WIDGET(m_webView)); @@ -391,24 +409,6 @@ public: return false; } - GtkMenu* getPopupMenu() - { - GOwnPtr<GList> toplevels(gtk_window_list_toplevels()); - for (GList* iter = toplevels.get(); iter; iter = g_list_next(iter)) { - if (!GTK_IS_WINDOW(iter->data)) - continue; - - GtkWidget* child = gtk_bin_get_child(GTK_BIN(iter->data)); - if (!GTK_IS_MENU(child)) - continue; - - if (gtk_menu_get_attach_widget(GTK_MENU(child)) == GTK_WIDGET(m_webView)) - return GTK_MENU(child); - } - g_assert_not_reached(); - return 0; - } - GtkMenuItem* getMenuItem(GtkMenu* menu, const gchar* itemLabel) { GOwnPtr<GList> items(gtk_container_get_children(GTK_CONTAINER(menu))); @@ -721,6 +721,115 @@ static void testContextMenuDismissed(ContextMenuDismissedTest* test, gconstpoint g_assert(test->m_dismissed); } +class ContextMenuSmartSeparatorsTest: public ContextMenuTest { +public: + MAKE_GLIB_TEST_FIXTURE(ContextMenuSmartSeparatorsTest); + + bool contextMenu(WebKitContextMenu* contextMenu, GdkEvent*, WebKitHitTestResult*) + { + webkit_context_menu_remove_all(contextMenu); + + webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); + webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); + webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_from_stock_action(WEBKIT_CONTEXT_MENU_ACTION_GO_BACK)); + webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_from_stock_action(WEBKIT_CONTEXT_MENU_ACTION_GO_FORWARD)); + webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); + webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); + webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_from_stock_action(WEBKIT_CONTEXT_MENU_ACTION_COPY)); + webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); + webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_from_stock_action(WEBKIT_CONTEXT_MENU_ACTION_INSPECT_ELEMENT)); + webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); + webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); + + quitMainLoop(); + + return false; + } + + GtkMenu* showContextMenuAndGetGtkMenu() + { + showContextMenuAndWaitUntilFinished(); + return getPopupMenu(); + } +}; + +static void testContextMenuSmartSeparators(ContextMenuSmartSeparatorsTest* test, gconstpointer) +{ + test->showInWindowAndWaitUntilMapped(); + + test->loadHtml("<html><body>WebKitGTK+ Context menu tests</body></html>", "file:///"); + test->waitUntilLoadFinished(); + + GtkMenu* menu = test->showContextMenuAndGetGtkMenu(); + g_assert(menu); + + // Leading and trailing separators are not added to the context menu. + GOwnPtr<GList> menuItems(gtk_container_get_children(GTK_CONTAINER(menu))); + g_assert_cmpuint(g_list_length(menuItems.get()), ==, 6); + GtkWidget* item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 0)); + g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 1)); + g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 2)); + g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 3)); + g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 4)); + g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 5)); + g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + + // Hiding a menu item between two separators hides the following separator. + GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(g_list_nth_data(menuItems.get(), 3))); + gtk_action_set_visible(action, FALSE); + menuItems.set(gtk_container_get_children(GTK_CONTAINER(menu))); + g_assert_cmpuint(g_list_length(menuItems.get()), ==, 6); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 0)); + g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 1)); + g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 2)); + g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 3)); + g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && !gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 4)); + g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item) && !gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 5)); + g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + gtk_action_set_visible(action, TRUE); + + // Showing an action between two separators shows the hidden separator. + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 0)); + g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 1)); + g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 2)); + g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 3)); + g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 4)); + g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 5)); + g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + + // Trailing separators are hidden too. + action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(g_list_nth_data(menuItems.get(), 5))); + gtk_action_set_visible(action, FALSE); + menuItems.set(gtk_container_get_children(GTK_CONTAINER(menu))); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 0)); + g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 1)); + g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 2)); + g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 3)); + g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 4)); + g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item) && !gtk_widget_get_visible(item)); + item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 5)); + g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && !gtk_widget_get_visible(item)); +} + void beforeAll() { ContextMenuDefaultTest::add("WebKitWebView", "default-menu", testContextMenuDefaultMenu); @@ -729,6 +838,7 @@ void beforeAll() ContextMenuDisabledTest::add("WebKitWebView", "disable-menu", testContextMenuDisableMenu); ContextMenuSubmenuTest::add("WebKitWebView", "submenu", testContextMenuSubMenu); ContextMenuDismissedTest::add("WebKitWebView", "menu-dismissed", testContextMenuDismissed); + ContextMenuSmartSeparatorsTest::add("WebKitWebView", "smart-separators", testContextMenuSmartSeparators); } void afterAll() diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp index 59eed7658..dabf072e3 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp @@ -70,6 +70,13 @@ static void testLoadHtml(LoadTrackingTest* test, gconstpointer) assertNormalLoadHappened(test->m_loadEvents); } +static void testLoadAlternateHTML(LoadTrackingTest* test, gconstpointer) +{ + test->loadAlternateHTML("<html><body>Alternate page</body></html>", "http://error-page.foo/", 0); + test->waitUntilLoadFinished(); + assertNormalLoadHappened(test->m_loadEvents); +} + static void testLoadPlainText(LoadTrackingTest* test, gconstpointer) { test->loadPlainText("Hello WebKit-GTK+"); @@ -262,6 +269,7 @@ void beforeAll() LoadTrackingTest::add("WebKitWebView", "loading-status", testLoadingStatus); LoadTrackingTest::add("WebKitWebView", "loading-error", testLoadingError); LoadTrackingTest::add("WebKitWebView", "load-html", testLoadHtml); + LoadTrackingTest::add("WebKitWebView", "load-alternate-html", testLoadAlternateHTML); LoadTrackingTest::add("WebKitWebView", "load-plain-text", testLoadPlainText); LoadTrackingTest::add("WebKitWebView", "load-request", testLoadRequest); LoadStopTrackingTest::add("WebKitWebView", "stop-loading", testLoadCancelled); diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp index 150c31bd3..123831f76 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp @@ -49,7 +49,7 @@ static void testPrintOperationPrintSettings(WebViewTest* test, gconstpointer) g_assert(webkit_print_operation_get_page_setup(printOperation.get()) == pageSetup.get()); } -static gboolean webViewPrintRequestedCallback(WebKitWebView* webView, WebKitPrintOperation* printOperation, WebViewTest* test) +static gboolean webViewPrintCallback(WebKitWebView* webView, WebKitPrintOperation* printOperation, WebViewTest* test) { g_assert(webView == test->m_webView); @@ -64,9 +64,9 @@ static gboolean webViewPrintRequestedCallback(WebKitWebView* webView, WebKitPrin return TRUE; } -static void testWebViewPrintRequested(WebViewTest* test, gconstpointer) +static void testWebViewPrint(WebViewTest* test, gconstpointer) { - g_signal_connect(test->m_webView, "print-requested", G_CALLBACK(webViewPrintRequestedCallback), test); + g_signal_connect(test->m_webView, "print", G_CALLBACK(webViewPrintCallback), test); test->loadHtml("<html><body onLoad=\"print();\">WebKitGTK+ printing test</body></html>", 0); g_main_loop_run(test->m_mainLoop); } @@ -196,7 +196,7 @@ void beforeAll() g_assert(kTempDirectory); WebViewTest::add("WebKitPrintOperation", "printing-settings", testPrintOperationPrintSettings); - WebViewTest::add("WebKitWebView", "print-requested", testWebViewPrintRequested); + WebViewTest::add("WebKitWebView", "print", testWebViewPrint); #ifdef HAVE_GTK_UNIX_PRINTING PrintTest::add("WebKitPrintOperation", "print", testPrintOperationPrint); PrintTest::add("WebKitPrintOperation", "print-errors", testPrintOperationErrors); diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp index dc7a518dd..7e2e5de61 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp @@ -397,6 +397,17 @@ static void testWebResourceMimeType(SingleResourceLoadTest* test, gconstpointer) g_assert_cmpstr(webkit_uri_response_get_mime_type(response), ==, "text/css"); } +static void testWebResourceSuggestedFilename(SingleResourceLoadTest* test, gconstpointer) +{ + test->loadURI(kServer->getURIForPath("/javascript.html").data()); + WebKitURIResponse* response = test->waitUntilResourceLoadFinishedAndReturnURIResponse(); + g_assert_cmpstr(webkit_uri_response_get_suggested_filename(response), ==, "JavaScript.js"); + + test->loadURI(kServer->getURIForPath("/image.html").data()); + response = test->waitUntilResourceLoadFinishedAndReturnURIResponse(); + g_assert(!webkit_uri_response_get_suggested_filename(response)); +} + class ResourceURITrackingTest: public SingleResourceLoadTest { public: MAKE_GLIB_TEST_FIXTURE(ResourceURITrackingTest); @@ -494,32 +505,6 @@ static void testWebResourceGetData(ResourcesTest* test, gconstpointer) test->checkResourceData(WEBKIT_WEB_RESOURCE(item->data)); } -static void replacedContentResourceLoadStartedCallback() -{ - g_assert_not_reached(); -} - -static void testWebViewResourcesReplacedContent(ResourcesTest* test, gconstpointer) -{ - test->loadURI(kServer->getURIForPath("/").data()); - // FIXME: this should be 4 instead of 3, but we don't get the css image resource - // due to bug https://bugs.webkit.org/show_bug.cgi?id=78510. - test->waitUntilResourcesLoaded(3); - - static const char* replacedHtml = - "<html><head>" - " <title>Content Replaced</title>" - " <link rel='stylesheet' href='data:text/css,body { margin: 0px; padding: 0px; }' type='text/css'>" - " <script language='javascript' src='data:application/javascript,function foo () { var a = 1; }'></script>" - "</head><body onload='document.title=\"Loaded\"'>WebKitGTK+ resources on replaced content test</body></html>"; - g_signal_connect(test->m_webView, "resource-load-started", G_CALLBACK(replacedContentResourceLoadStartedCallback), test); - test->replaceContent(replacedHtml, "http://error-page.foo", 0); - test->waitUntilTitleChangedTo("Loaded"); - - g_assert(!webkit_web_view_get_main_resource(test->m_webView)); - g_assert(!webkit_web_view_get_subresources(test->m_webView)); -} - static void testWebViewResourcesHistoryCache(SingleResourceLoadTest* test, gconstpointer) { test->loadURI(kServer->getURIForPath("/").data()); @@ -588,6 +573,7 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char* } else if (g_str_equal(path, "/javascript.js")) { soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, kJavascript, strlen(kJavascript)); soup_message_headers_append(message->response_headers, "Content-Type", "text/javascript"); + soup_message_headers_append(message->response_headers, "Content-Disposition", "filename=JavaScript.js"); } else if (g_str_equal(path, "/blank.ico")) { GOwnPtr<char> filePath(g_build_filename(Test::getWebKit1TestResoucesDir().data(), path, NULL)); char* contents; @@ -620,9 +606,9 @@ void beforeAll() SingleResourceLoadTest::add("WebKitWebResource", "loading", testWebResourceLoading); SingleResourceLoadTest::add("WebKitWebResource", "response", testWebResourceResponse); SingleResourceLoadTest::add("WebKitWebResource", "mime-type", testWebResourceMimeType); + SingleResourceLoadTest::add("WebKitWebResource", "suggested-filename", testWebResourceSuggestedFilename); ResourceURITrackingTest::add("WebKitWebResource", "active-uri", testWebResourceActiveURI); ResourcesTest::add("WebKitWebResource", "get-data", testWebResourceGetData); - ResourcesTest::add("WebKitWebView", "replaced-content", testWebViewResourcesReplacedContent); SingleResourceLoadTest::add("WebKitWebView", "history-cache", testWebViewResourcesHistoryCache); } diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp index a185db8a7..a2af7bd8d 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp @@ -165,14 +165,14 @@ static void testFindControllerNext(FindControllerTest* test, gconstpointer) test->waitUntilFindFinished(); g_assert(test->m_textFound); - g_assert(test->m_matchCount == 2); + g_assert(test->m_matchCount == 1); g_assert(!(webkit_find_controller_get_options(test->m_findController.get()) & WEBKIT_FIND_OPTIONS_BACKWARDS)); webkit_find_controller_search_next(test->m_findController.get()); test->waitUntilFindFinished(); g_assert(!test->m_textFound); - g_assert(test->m_matchCount == 2); + g_assert(test->m_matchCount == 1); g_assert(!(webkit_find_controller_get_options(test->m_findController.get()) & WEBKIT_FIND_OPTIONS_BACKWARDS)); } @@ -191,14 +191,14 @@ static void testFindControllerPrevious(FindControllerTest* test, gconstpointer) test->waitUntilFindFinished(); g_assert(test->m_textFound); - g_assert(test->m_matchCount == 2); + g_assert(test->m_matchCount == 1); g_assert(!(webkit_find_controller_get_options(test->m_findController.get()) & WEBKIT_FIND_OPTIONS_BACKWARDS)); webkit_find_controller_search_previous(test->m_findController.get()); test->waitUntilFindFinished(); g_assert(test->m_textFound); - g_assert(test->m_matchCount == 2); + g_assert(test->m_matchCount == 1); g_assert(webkit_find_controller_get_options(test->m_findController.get()) & WEBKIT_FIND_OPTIONS_BACKWARDS); } diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp index 1b172dfee..cde0bc34a 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp @@ -20,6 +20,7 @@ #include "config.h" #include "LoadTrackingTest.h" +#include "WebKitTestServer.h" #include <gtk/gtk.h> #include <webkit2/webkit2.h> #include <wtf/HashMap.h> @@ -27,6 +28,8 @@ #include <wtf/gobject/GRefPtr.h> #include <wtf/text/StringHash.h> +static WebKitTestServer* kServer; + static void testWebContextDefault(Test* test, gconstpointer) { // Check there's a single instance of the default web context. @@ -165,35 +168,6 @@ public: webkit_web_context_register_uri_scheme(webkit_web_context_get_default(), scheme, uriSchemeRequestCallback, this); } - static void resourceGetDataCallback(GObject* object, GAsyncResult* result, gpointer userData) - { - size_t dataSize; - GOwnPtr<GError> error; - unsigned char* data = webkit_web_resource_get_data_finish(WEBKIT_WEB_RESOURCE(object), result, &dataSize, &error.outPtr()); - g_assert(data); - - URISchemeTest* test = static_cast<URISchemeTest*>(userData); - test->m_resourceData.set(reinterpret_cast<char*>(data)); - test->m_resourceDataSize = dataSize; - g_main_loop_quit(test->m_mainLoop); - } - - const char* mainResourceData(size_t& mainResourceDataSize) - { - m_resourceDataSize = 0; - m_resourceData.clear(); - WebKitWebResource* resource = webkit_web_view_get_main_resource(m_webView); - g_assert(resource); - - webkit_web_resource_get_data(resource, 0, resourceGetDataCallback, this); - g_main_loop_run(m_mainLoop); - - mainResourceDataSize = m_resourceDataSize; - return m_resourceData.get(); - } - - GOwnPtr<char> m_resourceData; - size_t m_resourceDataSize; GRefPtr<WebKitURISchemeRequest> m_uriSchemeRequest; HashMap<String, URISchemeHandler> m_handlersMap; }; @@ -266,14 +240,57 @@ static void testWebContextSpellChecker(Test* test, gconstpointer) g_assert(webkit_web_context_get_spell_checking_enabled(webContext)); } +static void testWebContextLanguages(WebViewTest* test, gconstpointer) +{ + static const char* expectedDefaultLanguage = "en"; + test->loadURI(kServer->getURIForPath("/").data()); + test->waitUntilLoadFinished(); + size_t mainResourceDataSize = 0; + const char* mainResourceData = test->mainResourceData(mainResourceDataSize); + g_assert_cmpuint(mainResourceDataSize, ==, strlen(expectedDefaultLanguage)); + g_assert(!strncmp(mainResourceData, expectedDefaultLanguage, mainResourceDataSize)); + + GList* languages = g_list_prepend(0, const_cast<gpointer>(static_cast<const void*>("dE"))); + languages = g_list_prepend(languages, const_cast<gpointer>(static_cast<const void*>("ES_es"))); + languages = g_list_prepend(languages, const_cast<gpointer>(static_cast<const void*>("en"))); + webkit_web_context_set_preferred_languages(webkit_web_context_get_default(), languages); + g_list_free(languages); + + static const char* expectedLanguages = "en, es-es;q=0.90, de;q=0.80"; + test->loadURI(kServer->getURIForPath("/").data()); + test->waitUntilLoadFinished(); + mainResourceDataSize = 0; + mainResourceData = test->mainResourceData(mainResourceDataSize); + g_assert_cmpuint(mainResourceDataSize, ==, strlen(expectedLanguages)); + g_assert(!strncmp(mainResourceData, expectedLanguages, mainResourceDataSize)); +} + +static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) +{ + if (message->method != SOUP_METHOD_GET) { + soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); + 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); +} + void beforeAll() { + kServer = new WebKitTestServer(); + kServer->run(serverCallback); + Test::add("WebKitWebContext", "default-context", testWebContextDefault); PluginsTest::add("WebKitWebContext", "get-plugins", testWebContextGetPlugins); URISchemeTest::add("WebKitWebContext", "uri-scheme", testWebContextURIScheme); Test::add("WebKitWebContext", "spell-checker", testWebContextSpellChecker); + WebViewTest::add("WebKitWebContext", "languages", testWebContextLanguages); } void afterAll() { + delete kServer; } diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp index 22796bf73..cc67c5d63 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp @@ -74,24 +74,6 @@ static void testWebViewSettings(WebViewTest* test, gconstpointer) g_assert(webkit_settings_get_enable_javascript(settings)); } -static void replaceContentLoadCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent, WebViewTest* test) -{ - // There might be an event from a previous load, - // but never a WEBKIT_LOAD_STARTED after webkit_web_view_replace_content(). - g_assert_cmpint(loadEvent, !=, WEBKIT_LOAD_STARTED); -} - -static void testWebViewReplaceContent(WebViewTest* test, gconstpointer) -{ - test->loadHtml("<html><head><title>Replace Content Test</title></head><body>Content to replace</body></html>", 0); - test->waitUntilTitleChangedTo("Replace Content Test"); - - g_signal_connect(test->m_webView, "load-changed", G_CALLBACK(replaceContentLoadCallback), test); - test->replaceContent("<html><body onload='document.title=\"Content Replaced\"'>New Content</body></html>", - "http://foo.com/bar", 0); - test->waitUntilTitleChangedTo("Content Replaced"); -} - static const char* kAlertDialogMessage = "WebKitGTK+ alert dialog message"; static const char* kConfirmDialogMessage = "WebKitGTK+ confirm dialog message"; static const char* kPromptDialogMessage = "WebKitGTK+ prompt dialog message"; @@ -1048,7 +1030,6 @@ void beforeAll() WebViewTest::add("WebKitWebView", "default-context", testWebViewDefaultContext); WebViewTest::add("WebKitWebView", "custom-charset", testWebViewCustomCharset); WebViewTest::add("WebKitWebView", "settings", testWebViewSettings); - WebViewTest::add("WebKitWebView", "replace-content", testWebViewReplaceContent); UIClientTest::add("WebKitWebView", "create-ready-close", testWebViewCreateReadyClose); ModalDialogsTest::add("WebKitWebView", "allow-modal-dialogs", testWebViewAllowModalDialogs); ModalDialogsTest::add("WebKitWebView", "disallow-modal-dialogs", testWebViewDisallowModalDialogs); diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp index 321b6a37a..a8d20f88c 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp @@ -29,6 +29,7 @@ WebViewTest::WebViewTest() , m_mainLoop(g_main_loop_new(0, TRUE)) , m_parentWindow(0) , m_javascriptResult(0) + , m_resourceDataSize(0) { assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_webView)); } @@ -70,10 +71,10 @@ void WebViewTest::loadRequest(WebKitURIRequest* request) webkit_web_view_load_request(m_webView, request); } -void WebViewTest::replaceContent(const char* html, const char* contentURI, const char* baseURI) +void WebViewTest::loadAlternateHTML(const char* html, const char* contentURI, const char* baseURI) { m_activeURI = contentURI; - webkit_web_view_replace_content(m_webView, html, contentURI, baseURI); + webkit_web_view_load_alternate_html(m_webView, html, contentURI, baseURI); } void WebViewTest::goBack() @@ -197,6 +198,33 @@ void WebViewTest::resizeView(int width, int height) gtk_widget_size_allocate(GTK_WIDGET(m_webView), &allocation); } +static void resourceGetDataCallback(GObject* object, GAsyncResult* result, gpointer userData) +{ + size_t dataSize; + GOwnPtr<GError> error; + unsigned char* data = webkit_web_resource_get_data_finish(WEBKIT_WEB_RESOURCE(object), result, &dataSize, &error.outPtr()); + g_assert(data); + + WebViewTest* test = static_cast<WebViewTest*>(userData); + test->m_resourceData.set(reinterpret_cast<char*>(data)); + test->m_resourceDataSize = dataSize; + g_main_loop_quit(test->m_mainLoop); +} + +const char* WebViewTest::mainResourceData(size_t& mainResourceDataSize) +{ + m_resourceDataSize = 0; + m_resourceData.clear(); + WebKitWebResource* resource = webkit_web_view_get_main_resource(m_webView); + g_assert(resource); + + webkit_web_resource_get_data(resource, 0, resourceGetDataCallback, this); + g_main_loop_run(m_mainLoop); + + mainResourceDataSize = m_resourceDataSize; + return m_resourceData.get(); +} + void WebViewTest::mouseMoveTo(int x, int y, unsigned int mouseModifiers) { g_assert(m_parentWindow); diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h index 8e469f142..25209caa3 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h +++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h @@ -35,7 +35,7 @@ public: virtual void loadHtml(const char* html, const char* baseURI); virtual void loadPlainText(const char* plainText); virtual void loadRequest(WebKitURIRequest*); - void replaceContent(const char* html, const char* contentURI, const char* baseURI); + void loadAlternateHTML(const char* html, const char* contentURI, const char* baseURI); void goBack(); void goForward(); void goToBackForwardListItem(WebKitBackForwardListItem*); @@ -48,6 +48,7 @@ public: void waitUntilTitleChanged(); void showInWindowAndWaitUntilMapped(GtkWindowType = GTK_WINDOW_POPUP); void resizeView(int width, int height); + const char* mainResourceData(size_t& mainResourceDataSize); void mouseMoveTo(int x, int y, unsigned int mouseModifiers = 0); void clickMouseButton(int x, int y, unsigned int button = 1, unsigned int mouseModifiers = 0); @@ -69,6 +70,8 @@ public: CString m_expectedTitle; WebKitJavascriptResult* m_javascriptResult; GError** m_javascriptError; + GOwnPtr<char> m_resourceData; + size_t m_resourceDataSize; private: void doMouseButtonEvent(GdkEventType, int, int, unsigned int, unsigned int); diff --git a/Source/WebKit2/UIProcess/API/mac/WKView.mm b/Source/WebKit2/UIProcess/API/mac/WKView.mm index a11ef65d0..eb6b819c5 100644 --- a/Source/WebKit2/UIProcess/API/mac/WKView.mm +++ b/Source/WebKit2/UIProcess/API/mac/WKView.mm @@ -1895,8 +1895,17 @@ static NSString * const backingPropertyOldScaleFactorKey = @"NSBackingPropertyOl NSWindow *currentWindow = [self window]; if (window == currentWindow) return; - - _data->_pageClient->viewWillMoveToAnotherWindow(); + +#if __MAC_OS_X_VERSION_MIN_REQUIRED == 1070 + // Avoid calling the code added in 121482 that ensures that the undo stack is cleaned up + // before the WKView is moved from one window to another when the WKView is being moved + // out of a popover window. This avoids a bug in OS X 10.7 that was fixed in 10.8. + // While this technically reopens a potentially crashing code path that 121482 closed, + // it only reopens it for WKViews that are used for text editing and that are removed + // from an NSPopover at some time earlier than tear-down of the NSPopover. + if (![currentWindow isKindOfClass:NSClassFromString(@"_NSPopoverWindow")]) +#endif + _data->_pageClient->viewWillMoveToAnotherWindow(); [self removeWindowObservers]; [self addWindowObserversForWindow:window]; diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp b/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp index 7911f167c..db51b85dd 100644 --- a/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp +++ b/Source/WebKit2/UIProcess/API/qt/qquickwebpage.cpp @@ -55,7 +55,6 @@ QQuickWebPagePrivate::QQuickWebPagePrivate(QQuickWebPage* q, QQuickWebView* view , viewportItem(viewportItem) , webPageProxy(0) , paintingIsInitialized(false) - , m_paintNode(0) , contentsScale(1) { } diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebpage_p_p.h b/Source/WebKit2/UIProcess/API/qt/qquickwebpage_p_p.h index ba0e42eda..ad1c6ad3f 100644 --- a/Source/WebKit2/UIProcess/API/qt/qquickwebpage_p_p.h +++ b/Source/WebKit2/UIProcess/API/qt/qquickwebpage_p_p.h @@ -47,7 +47,6 @@ public: QQuickWebView* const viewportItem; WebKit::WebPageProxy* webPageProxy; bool paintingIsInitialized; - QSGNode* m_paintNode; QSizeF contentsSize; qreal contentsScale; diff --git a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp index 6ca413f66..921586d1b 100644 --- a/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp +++ b/Source/WebKit2/UIProcess/API/qt/qquickwebview.cpp @@ -33,8 +33,10 @@ #include "QtWebPageLoadClient.h" #include "QtWebPagePolicyClient.h" #include "WebBackForwardList.h" +#if ENABLE(INSPECTOR_SERVER) #include "WebInspectorProxy.h" #include "WebInspectorServer.h" +#endif #if ENABLE(FULLSCREEN_API) #include "WebFullScreenManagerProxy.h" #endif @@ -1331,7 +1333,11 @@ void QQuickWebViewExperimental::setUserScripts(const QList<QUrl>& userScripts) QUrl QQuickWebViewExperimental::remoteInspectorUrl() const { +#if ENABLE(INSPECTOR_SERVER) return QUrl(WebInspectorServer::shared().inspectorUrlForPageID(d_ptr->webPageProxy->inspector()->remoteInspectionPageID())); +#else + return QUrl(); +#endif } QQuickUrlSchemeDelegate* QQuickWebViewExperimental::schemeDelegates_At(QQmlListProperty<QQuickUrlSchemeDelegate>* property, int index) diff --git a/Source/WebKit2/UIProcess/API/qt/qwebkittest_p.h b/Source/WebKit2/UIProcess/API/qt/qwebkittest_p.h index c0d3e1187..3754f169a 100644 --- a/Source/WebKit2/UIProcess/API/qt/qwebkittest_p.h +++ b/Source/WebKit2/UIProcess/API/qt/qwebkittest_p.h @@ -47,13 +47,13 @@ class QWEBKIT_EXPORT QWebKitTest : public QObject { Q_PROPERTY(QVariant minimumScale READ minimumScale NOTIFY viewportChanged) Q_PROPERTY(QVariant layoutSize READ layoutSize NOTIFY viewportChanged) -signals: +Q_SIGNALS: void contentsSizeChanged(); void contentsScaleChanged(); void contentsScaleCommitted(); void viewportChanged(); -public slots: +public Q_SLOTS: bool touchTap(QObject* item, qreal x, qreal y, int delay = -1); bool touchDoubleTap(QObject* item, qreal x, qreal y, int delay = -1); bool wheelEvent(QObject* item, qreal x, qreal y, int delta, Qt::Orientation orient = Qt::Vertical); diff --git a/Source/WebKit2/UIProcess/API/qt/tests/html/inputmethod.html b/Source/WebKit2/UIProcess/API/qt/tests/html/inputmethod.html index f3ca937d2..dc9140f9d 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/html/inputmethod.html +++ b/Source/WebKit2/UIProcess/API/qt/tests/html/inputmethod.html @@ -5,5 +5,7 @@ <body> <h1>Basic page</h1> <input id="inputField" /> +<input id="emailInputField" type="email" /> +<div id="editableDiv" contenteditable></div> </body> </html> diff --git a/Source/WebKit2/UIProcess/API/qt/tests/inspectorserver/tst_inspectorserver.cpp b/Source/WebKit2/UIProcess/API/qt/tests/inspectorserver/tst_inspectorserver.cpp index 3d2a95a6c..2ad673a4b 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/inspectorserver/tst_inspectorserver.cpp +++ b/Source/WebKit2/UIProcess/API/qt/tests/inspectorserver/tst_inspectorserver.cpp @@ -38,7 +38,7 @@ class tst_InspectorServer : public QObject { public: tst_InspectorServer(); -private slots: +private Q_SLOTS: void init(); void cleanup(); diff --git a/Source/WebKit2/UIProcess/API/qt/tests/publicapi/tst_publicapi.cpp b/Source/WebKit2/UIProcess/API/qt/tests/publicapi/tst_publicapi.cpp index 12e0ab903..d0ea1beb8 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/publicapi/tst_publicapi.cpp +++ b/Source/WebKit2/UIProcess/API/qt/tests/publicapi/tst_publicapi.cpp @@ -31,7 +31,7 @@ class tst_publicapi : public QObject { Q_OBJECT -private slots: +private Q_SLOTS: void publicAPI(); }; diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior.pro b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior.pro index 11733ce48..3fd3d4583 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior.pro +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/DesktopBehavior.pro @@ -6,7 +6,6 @@ OBJECTS_DIR = obj_DesktopBehavior/$$activeBuildConfig() QT += webkit-private CONFIG += warn_on testcase -QT -= testlib QT += qmltest DEFINES += DISABLE_FLICKABLE_VIEWPORT=1 diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView.pro b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView.pro index fd940d43d..b340235e4 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView.pro +++ b/Source/WebKit2/UIProcess/API/qt/tests/qmltests/WebView.pro @@ -6,7 +6,6 @@ OBJECTS_DIR = obj_WebView/$$activeBuildConfig() QT += webkit-private CONFIG += warn_on testcase -QT -= testlib QT += qmltest # Test the QML files under WebView in the source repository. 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 d347e158a..5b98ae7b7 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/tst_qquickwebview.cpp +++ b/Source/WebKit2/UIProcess/API/qt/tests/qquickwebview/tst_qquickwebview.cpp @@ -31,7 +31,7 @@ class tst_QQuickWebView : public QObject { public: tst_QQuickWebView(); -private slots: +private Q_SLOTS: void init(); void cleanup(); @@ -58,6 +58,7 @@ private slots: void transparentWebViews(); void inputMethod(); + void inputMethodHints(); void basicRenderingSanity(); private: @@ -410,6 +411,33 @@ void tst_QQuickWebView::inputMethod() QVERIFY(!view->flags().testFlag(QQuickItem::ItemAcceptsInputMethod)); } +void tst_QQuickWebView::inputMethodHints() +{ + QQuickWebView* view = webView(); + + view->setUrl(QUrl::fromLocalFile(QLatin1String(TESTS_SOURCE_DIR "/html/inputmethod.html"))); + QVERIFY(waitForLoadSucceeded(view)); + + // Setting focus on an input element results in an element in its shadow tree becoming the focus node. + // Input hints should not be set from this shadow tree node but from the input element itself. + runJavaScript("document.getElementById('emailInputField').focus();"); + QVERIFY(view->flags().testFlag(QQuickItem::ItemAcceptsInputMethod)); + QInputMethodQueryEvent query(Qt::ImHints); + QGuiApplication::sendEvent(view, &query); + Qt::InputMethodHints hints(query.value(Qt::ImHints).toUInt() & Qt::ImhExclusiveInputMask); + QCOMPARE(hints, Qt::ImhEmailCharactersOnly); + + // The focus of an editable DIV is given directly to it, so no shadow root element + // is necessary. This tests the WebPage::editorState() method ability to get the + // right element without breaking. + runJavaScript("document.getElementById('editableDiv').focus();"); + QVERIFY(view->flags().testFlag(QQuickItem::ItemAcceptsInputMethod)); + query = QInputMethodQueryEvent(Qt::ImHints); + QGuiApplication::sendEvent(view, &query); + hints = Qt::InputMethodHints(query.value(Qt::ImHints).toUInt()); + QCOMPARE(hints, Qt::ImhNone); +} + void tst_QQuickWebView::scrollRequest() { webView()->setSize(QSizeF(300, 400)); 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 b322bacd4..93d669cee 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/qrawwebview/tst_qrawwebview.cpp +++ b/Source/WebKit2/UIProcess/API/qt/tests/qrawwebview/tst_qrawwebview.cpp @@ -123,7 +123,7 @@ public: static_cast<WebView*>(const_cast<void*>(clientInfo))->frameLoaded(); } -signals: +Q_SIGNALS: void loaded(); private: @@ -154,7 +154,7 @@ public: , m_baseUrl(QUrl::fromLocalFile(TESTS_SOURCE_DIR "/html").toString()) { } -private slots: +private Q_SLOTS: void paint() { run(&tst_qrawwebview::doPaint, m_resourceDir + "/qwkview_paint.png"); } void noBackground1() { run(&tst_qrawwebview::doNoBackground1, m_resourceDir + "/qwkview_noBackground1.png"); } void noBackground2() { run(&tst_qrawwebview::doNoBackground2, m_resourceDir + "/qwkview_noBackground1.png"); } diff --git a/Source/WebKit2/UIProcess/API/qt/tests/util.cpp b/Source/WebKit2/UIProcess/API/qt/tests/util.cpp index cdd1f9961..6c91de717 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/util.cpp +++ b/Source/WebKit2/UIProcess/API/qt/tests/util.cpp @@ -65,10 +65,10 @@ public: { connect(webView, SIGNAL(loadingChanged(QWebLoadRequest*)), SLOT(onLoadingChanged(QWebLoadRequest*))); } -signals: +Q_SIGNALS: void loadSucceeded(); void loadFailed(); -private slots: +private Q_SLOTS: void onLoadingChanged(QWebLoadRequest* loadRequest) { if (loadRequest->status() == QQuickWebView::LoadSucceededStatus) diff --git a/Source/WebKit2/UIProcess/API/qt/tests/util.h b/Source/WebKit2/UIProcess/API/qt/tests/util.h index 907ddb05f..ebb162cc4 100644 --- a/Source/WebKit2/UIProcess/API/qt/tests/util.h +++ b/Source/WebKit2/UIProcess/API/qt/tests/util.h @@ -40,9 +40,9 @@ class LoadStartedCatcher : public QObject { Q_OBJECT public: LoadStartedCatcher(QQuickWebView* webView); -public slots: +public Q_SLOTS: void onLoadingChanged(QWebLoadRequest* loadRequest); -signals: +Q_SIGNALS: void finished(); private: QQuickWebView* m_webView; |