2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef WebPrivatePtr_h
32 #define WebPrivatePtr_h
34 #include "WebCommon.h"
37 #include "wtf/PassRefPtr.h"
42 // This class is an implementation detail of the Blink API. It exists to help
43 // simplify the implementation of Blink interfaces that merely wrap a reference
44 // counted WebCore class.
46 // A typical implementation of a class which uses WebPrivatePtr might look like
50 // BLINK_EXPORT ~WebFoo();
52 // WebFoo(const WebFoo& other) { assign(other); }
53 // WebFoo& operator=(const WebFoo& other)
58 // BLINK_EXPORT void assign(const WebFoo&); // Implemented in the body.
60 // // Methods that are exposed to Chromium and which are specific to
62 // BLINK_EXPORT doWebFooThing();
64 // // Methods that are used only by other Blink classes should only be
65 // // declared when INSIDE_BLINK is set.
67 // WebFoo(const WTF::PassRefPtr<WebCore::Foo>&);
71 // WebPrivatePtr<WebCore::Foo> m_private;
75 // WebFoo::~WebFoo() { m_private.reset(); }
76 // void WebFoo::assign(const WebFoo& other) { ... }
81 WebPrivatePtr() : m_ptr(0) { }
84 // We don't destruct the object pointed by m_ptr here because we don't
85 // want to expose destructors of core classes to embedders. We should
86 // call reset() manually in destructors of classes with WebPrivatePtr
91 bool isNull() const { return !m_ptr; }
94 WebPrivatePtr(const PassRefPtr<T>& prp)
95 : m_ptr(prp.leakRef())
104 WebPrivatePtr<T>& operator=(const WebPrivatePtr<T>& other)
113 WebPrivatePtr<T>& operator=(const PassRefPtr<T>& prp)
115 assign(prp.leakRef());
124 T* operator->() const
135 // p is already ref'd for us by the caller
141 // Disable the assignment operator; we define it above for when
142 // INSIDE_BLINK is set, but we need to make sure that it is not
143 // used outside there; the compiler-provided version won't handle reference
144 // counting properly.
145 WebPrivatePtr<T>& operator=(const WebPrivatePtr<T>& other);
147 // Disable the copy constructor; classes that contain a WebPrivatePtr
148 // should implement their copy constructor using assign().
149 WebPrivatePtr(const WebPrivatePtr<T>&);