[WK2] API::Error creation functions should return Ref<>
authorzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Apr 2015 06:31:29 +0000 (06:31 +0000)
committerzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Apr 2015 06:31:29 +0000 (06:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=144222

Reviewed by Darin Adler.

Have API::Error creation functions return Ref<>.
The call-sites are also updated, using and operating
on the returned Ref<> object where possible.

* Shared/API/APIError.h:
(API::Error::create):
* Shared/API/c/cf/WKErrorCF.cpp:
(WKErrorCreateWithCFError):
* UIProcess/API/C/WKOriginDataManager.cpp:
(WKOriginDataManagerDeleteEntriesForOrigin):
(WKOriginDataManagerDeleteEntriesModifiedBetweenDates):
(WKOriginDataManagerDeleteAllEntries):
* UIProcess/API/C/WKPage.cpp:
(toGenericCallbackFunction):
(WKPageForceRepaint):
(WKPageValidateCommand):
(WKPageComputePagesForPrinting):
* UIProcess/API/C/WKPluginSiteDataManager.cpp:
(WKPluginSiteDataManagerClearSiteData):
(WKPluginSiteDataManagerClearAllSiteData):
* UIProcess/GenericCallback.h:
(WebKit::toGenericCallbackFunction):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::printFinishedCallback):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183459 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/API/APIError.h
Source/WebKit2/Shared/API/c/cf/WKErrorCF.cpp
Source/WebKit2/UIProcess/API/C/WKOriginDataManager.cpp
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/API/C/WKPluginSiteDataManager.cpp
Source/WebKit2/UIProcess/GenericCallback.h
Source/WebKit2/UIProcess/WebPageProxy.cpp

index c6f6ffd..3e1d6a1 100644 (file)
@@ -1,3 +1,35 @@
+2015-04-27  Zan Dobersek  <zdobersek@igalia.com>
+
+        [WK2] API::Error creation functions should return Ref<>
+        https://bugs.webkit.org/show_bug.cgi?id=144222
+
+        Reviewed by Darin Adler.
+
+        Have API::Error creation functions return Ref<>.
+        The call-sites are also updated, using and operating
+        on the returned Ref<> object where possible.
+
+        * Shared/API/APIError.h:
+        (API::Error::create):
+        * Shared/API/c/cf/WKErrorCF.cpp:
+        (WKErrorCreateWithCFError):
+        * UIProcess/API/C/WKOriginDataManager.cpp:
+        (WKOriginDataManagerDeleteEntriesForOrigin):
+        (WKOriginDataManagerDeleteEntriesModifiedBetweenDates):
+        (WKOriginDataManagerDeleteAllEntries):
+        * UIProcess/API/C/WKPage.cpp:
+        (toGenericCallbackFunction):
+        (WKPageForceRepaint):
+        (WKPageValidateCommand):
+        (WKPageComputePagesForPrinting):
+        * UIProcess/API/C/WKPluginSiteDataManager.cpp:
+        (WKPluginSiteDataManagerClearSiteData):
+        (WKPluginSiteDataManagerClearAllSiteData):
+        * UIProcess/GenericCallback.h:
+        (WebKit::toGenericCallbackFunction):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::printFinishedCallback):
+
 2015-04-27  Sungmann Cho  <sungmann.cho@navercorp.com>
 
         [GTK] Remove unnecessary semicolon from WebKitNotificationProvider.h.
index 8cb1cf4..c29e95f 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "APIObject.h"
 #include <WebCore/ResourceError.h>
-#include <wtf/PassRefPtr.h>
 
 namespace IPC {
 class ArgumentDecoder;
@@ -39,14 +38,14 @@ namespace API {
 
 class Error : public ObjectImpl<Object::Type::Error> {
 public:
-    static PassRefPtr<Error> create()
+    static Ref<Error> create()
     {
-        return adoptRef(new Error);
+        return adoptRef(*new Error);
     }
 
-    static PassRefPtr<Error> create(const WebCore::ResourceError& error)
+    static Ref<Error> create(const WebCore::ResourceError& error)
     {
-        return adoptRef(new Error(error));
+        return adoptRef(*new Error(error));
     }
 
     static const WTF::String& webKitErrorDomain();
index 7892483..39ad959 100644 (file)
@@ -34,8 +34,7 @@ using namespace WebKit;
 
 WKErrorRef WKErrorCreateWithCFError(CFErrorRef cfError)
 {
-    RefPtr<API::Error> error = API::Error::create(ResourceError(cfError));
-    return toAPI(error.release().leakRef());
+    return toAPI(&API::Error::create(ResourceError(cfError)).leakRef());
 }
 
 CFErrorRef WKErrorCopyCFError(CFAllocatorRef alloc, WKErrorRef error)
index cbcf5d5..4d6e41a 100644 (file)
@@ -44,20 +44,20 @@ void WKOriginDataManagerGetOrigins(WKOriginDataManagerRef originDataManagerRef,
 void WKOriginDataManagerDeleteEntriesForOrigin(WKOriginDataManagerRef originDataManagerRef, WKOriginDataTypes types, WKSecurityOriginRef originRef, void* context, WKOriginDataManagerDeleteEntriesCallbackFunction callback)
 {
     toImpl(originDataManagerRef)->deleteEntriesForOrigin(types, toImpl(originRef), [context, callback](CallbackBase::Error error) {
-        callback(error != CallbackBase::Error::None ? toAPI(API::Error::create().get()) : 0, context);
+        callback(error != CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
     });
 }
 
 void WKOriginDataManagerDeleteEntriesModifiedBetweenDates(WKOriginDataManagerRef originDataManagerRef, WKOriginDataTypes types, double startDate, double endDate, void* context, WKOriginDataManagerDeleteEntriesCallbackFunction callback)
 {
     toImpl(originDataManagerRef)->deleteEntriesModifiedBetweenDates(types, startDate, endDate, [context, callback](CallbackBase::Error error) {
-        callback(error != CallbackBase::Error::None ? toAPI(API::Error::create().get()) : 0, context);
+        callback(error != CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
     });
 }
 
 void WKOriginDataManagerDeleteAllEntries(WKOriginDataManagerRef originDataManagerRef, WKOriginDataTypes types, void* context, WKOriginDataManagerDeleteEntriesCallbackFunction callback)
 {
     toImpl(originDataManagerRef)->deleteAllEntries(types, [context, callback](CallbackBase::Error error) {
-        callback(error != CallbackBase::Error::None ? toAPI(API::Error::create().get()) : 0, context);
+        callback(error != CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
     });
 }
index 4a6da19..27d8a12 100644 (file)
@@ -1954,7 +1954,7 @@ void WKPageRunJavaScriptInMainFrame_b(WKPageRef pageRef, WKStringRef scriptRef,
 static std::function<void (const String&, WebKit::CallbackBase::Error)> toGenericCallbackFunction(void* context, void (*callback)(WKStringRef, WKErrorRef, void*))
 {
     return [context, callback](const String& returnValue, WebKit::CallbackBase::Error error) {
-        callback(toAPI(API::String::create(returnValue).ptr()), error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().get()) : 0, context);
+        callback(toAPI(API::String::create(returnValue).ptr()), error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
     };
 }
 
@@ -1998,7 +1998,7 @@ void WKPageGetContentsAsMHTMLData(WKPageRef pageRef, bool useBinaryEncoding, voi
 void WKPageForceRepaint(WKPageRef pageRef, void* context, WKPageForceRepaintFunction callback)
 {
     toImpl(pageRef)->forceRepaint(VoidCallback::create([context, callback](WebKit::CallbackBase::Error error) {
-        callback(error == WebKit::CallbackBase::Error::None ? nullptr : toAPI(API::Error::create().get()), context);
+        callback(error == WebKit::CallbackBase::Error::None ? nullptr : toAPI(API::Error::create().ptr()), context);
     }));
 }
 
@@ -2035,7 +2035,7 @@ WKStringRef WKPageCopyStandardUserAgentWithApplicationName(WKStringRef applicati
 void WKPageValidateCommand(WKPageRef pageRef, WKStringRef command, void* context, WKPageValidateCommandCallback callback)
 {
     toImpl(pageRef)->validateCommand(toImpl(command)->string(), [context, callback](const String& commandName, bool isEnabled, int32_t state, WebKit::CallbackBase::Error error) {
-        callback(toAPI(API::String::create(commandName).ptr()), isEnabled, state, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().get()) : 0, context);
+        callback(toAPI(API::String::create(commandName).ptr()), isEnabled, state, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
     });
 }
 
@@ -2060,7 +2060,7 @@ void WKPageComputePagesForPrinting(WKPageRef page, WKFrameRef frame, WKPrintInfo
         Vector<WKRect> wkRects(rects.size());
         for (size_t i = 0; i < rects.size(); ++i)
             wkRects[i] = toAPI(rects[i]);
-        callback(wkRects.data(), wkRects.size(), scaleFactor, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().get()) : 0, context);
+        callback(wkRects.data(), wkRects.size(), scaleFactor, error != WebKit::CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
     }));
 }
 
index a16135c..2282996 100644 (file)
@@ -76,7 +76,7 @@ void WKPluginSiteDataManagerClearSiteData(WKPluginSiteDataManagerRef managerRef,
 {
 #if ENABLE(NETSCAPE_PLUGIN_API)
     toImpl(managerRef)->clearSiteData(toImpl(sitesRef), toNPClearSiteDataFlags(flags), maxAgeInSeconds, [context, function](CallbackBase::Error error) {
-        function(error == CallbackBase::Error::None ? nullptr : toAPI(API::Error::create().get()), context);
+        function(error == CallbackBase::Error::None ? nullptr : toAPI(API::Error::create().ptr()), context);
     });
 #else
     UNUSED_PARAM(managerRef);
@@ -92,7 +92,7 @@ void WKPluginSiteDataManagerClearAllSiteData(WKPluginSiteDataManagerRef managerR
 {
 #if ENABLE(NETSCAPE_PLUGIN_API)
     toImpl(managerRef)->clearSiteData(0, NP_CLEAR_ALL, std::numeric_limits<uint64_t>::max(), [context, function](CallbackBase::Error error) {
-        function(error == CallbackBase::Error::None ? nullptr : toAPI(API::Error::create().get()), context);
+        function(error == CallbackBase::Error::None ? nullptr : toAPI(API::Error::create().ptr()), context);
     });
 #else
     UNUSED_PARAM(managerRef);
index 5ad06ce..93ca3e8 100644 (file)
@@ -150,7 +150,7 @@ template<typename APIReturnValueType, typename InternalReturnValueType = typenam
 static typename GenericCallback<InternalReturnValueType>::CallbackFunction toGenericCallbackFunction(void* context, void (*callback)(APIReturnValueType, WKErrorRef, void*))
 {
     return [context, callback](InternalReturnValueType returnValue, CallbackBase::Error error) {
-        callback(toAPI(returnValue), error != CallbackBase::Error::None ? toAPI(API::Error::create().get()) : 0, context);
+        callback(toAPI(returnValue), error != CallbackBase::Error::None ? toAPI(API::Error::create().ptr()) : 0, context);
     };
 }
 
index 59445d9..0d43827 100644 (file)
@@ -4681,8 +4681,7 @@ void WebPageProxy::printFinishedCallback(const ResourceError& printError, uint64
         return;
     }
 
-    RefPtr<API::Error> error = API::Error::create(printError);
-    callback->performCallbackWithReturnValue(error.get());
+    callback->performCallbackWithReturnValue(API::Error::create(printError).ptr());
 }
 #endif