Index: public/platform/WebPassOwnPtr.h |
diff --git a/public/platform/WebPrivateOwnPtr.h b/public/platform/WebPassOwnPtr.h |
similarity index 50% |
copy from public/platform/WebPrivateOwnPtr.h |
copy to public/platform/WebPassOwnPtr.h |
index 5e13f07b348bc9749d69a4d2e957ca0eea297910..9c53d8f597c1e1f25b8549a539e4ae3a9263cc08 100644 |
--- a/public/platform/WebPrivateOwnPtr.h |
+++ b/public/platform/WebPassOwnPtr.h |
@@ -1,5 +1,5 @@ |
/* |
- * Copyright (C) 2010 Google Inc. All rights reserved. |
+ * Copyright (C) 2013 Intel Corporation. All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
@@ -23,53 +23,73 @@ |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
-#ifndef WebPrivateOwnPtr_h |
-#define WebPrivateOwnPtr_h |
+#ifndef WebPassOwnPtr_h |
+#define WebPassOwnPtr_h |
#include "WebCommon.h" |
+#if INSIDE_BLINK |
+#include "wtf/OwnPtr.h" |
+#include "wtf/PassOwnPtr.h" |
+#include "wtf/UnusedParam.h" |
+#endif |
+ |
namespace WebKit { |
-// This class is an implementation detail of the WebKit API. It exists |
-// to help simplify the implementation of WebKit interfaces that merely |
-// wrap a pointer to a WebCore class. It's similar to WebPrivatePtr, but it |
-// wraps a naked pointer rather than a reference counted. |
-// Note: you must call reset(0) on the implementation side in order to delete |
-// the WebCore pointer. |
+// It exists to help transfer the ownership of either OwnPtr or PassOwnPtr from Blink to Chromium. |
+// |
+// A typical usage is as follows: |
+// in Blink side |
+// OwnPtr<WebAnimation> animation; |
+// WebLayer layer; |
+// layer->addAnimation(animation); |
+// |
+// in Chromium side |
+// bool WebAnimation::addAnimation(WebPassOwnPtr<WebAnimation> pop_animation) { |
+// scoped_ptr<WebAnimation> animation(pop_animation.leakPtr()); |
+// ... |
+// } |
template <typename T> |
-class WebPrivateOwnPtr { |
+class WebPassOwnPtr { |
public: |
- WebPrivateOwnPtr() : m_ptr(0) {} |
- ~WebPrivateOwnPtr() { BLINK_ASSERT(!m_ptr); } |
+ WebPassOwnPtr() : m_ptr(0) { } |
+ ~WebPassOwnPtr() { BLINK_ASSERT(!m_ptr); delete m_ptr; } |
+ WebPassOwnPtr(const WebPassOwnPtr& o) : m_ptr(o.leakPtr()) { } |
-#if INSIDE_BLINK |
- explicit WebPrivateOwnPtr(T* ptr) |
- : m_ptr(ptr) |
+ T* leakPtr() const |
{ |
+ T* ptr = m_ptr; |
+ m_ptr = 0; |
+ return ptr; |
} |
- void reset(T* ptr) |
+#if INSIDE_BLINK |
+ explicit WebPassOwnPtr(T* ptr) |
+ : m_ptr(ptr) |
{ |
- delete m_ptr; |
- m_ptr = ptr; |
+ COMPILE_ASSERT(sizeof(T) > 0, TypeMustBeComplete); |
} |
- T* get() const { return m_ptr; } |
- |
- T* operator->() const |
- { |
- BLINK_ASSERT(m_ptr); |
- return m_ptr; |
- } |
+ template<typename U> WebPassOwnPtr(const PassOwnPtr<U>&); |
#endif // INSIDE_BLINK |
private: |
- T* m_ptr; |
+ WebPassOwnPtr& operator=(const WebPassOwnPtr&); |
- WebPrivateOwnPtr(const WebPrivateOwnPtr&); |
- void operator=(const WebPrivateOwnPtr&); |
+ mutable T* m_ptr; |
}; |
+#if INSIDE_BLINK |
+template<typename T> template<typename U> inline WebPassOwnPtr<T>::WebPassOwnPtr(const PassOwnPtr<U>& o) |
+ : m_ptr(o.leakPtr()) |
+{ |
+ using WTF::EnableIf; |
+ using WTF::IsPointerConvertible; |
+ EnsurePtrConvertibleArgDefn(U, T) typeChecker = true; |
+ UNUSED_PARAM(typeChecker); |
+} |
+#endif |
+ |
} // namespace WebKit |
#endif |