diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-20 21:15:30 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-20 21:15:30 +0000 |
commit | 8ecad3a1d01d5e79b09cf12b454a97f3b9c2f578 (patch) | |
tree | bf21526a4735f73199cd1b2691a90114dbba7102 | |
parent | 1e74d39a70506cfcad8b224230d9f302c2f96ae7 (diff) | |
download | chromium_src-8ecad3a1d01d5e79b09cf12b454a97f3b9c2f578.zip chromium_src-8ecad3a1d01d5e79b09cf12b454a97f3b9c2f578.tar.gz chromium_src-8ecad3a1d01d5e79b09cf12b454a97f3b9c2f578.tar.bz2 |
Implement WebNode, and fix self assignment for WebKit api classes.
Review URL: http://codereview.chromium.org/149728
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21104 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/api/public/WebNode.h | 13 | ||||
-rw-r--r-- | webkit/api/src/WebImageCG.cpp | 4 | ||||
-rw-r--r-- | webkit/api/src/WebNode.cpp | 90 | ||||
-rw-r--r-- | webkit/api/src/WebURLRequest.cpp | 5 | ||||
-rw-r--r-- | webkit/api/src/WebURLResponse.cpp | 5 | ||||
-rw-r--r-- | webkit/webkit.gyp | 2 |
6 files changed, 116 insertions, 3 deletions
diff --git a/webkit/api/public/WebNode.h b/webkit/api/public/WebNode.h index 16f8d61..a52c067 100644 --- a/webkit/api/public/WebNode.h +++ b/webkit/api/public/WebNode.h @@ -32,6 +32,12 @@ #define WebNode_h #include "WebCommon.h" +#include "WebString.h" + +#if WEBKIT_IMPLEMENTATION +namespace WebCore { class Node; } +namespace WTF { template <typename T> class PassRefPtr; } +#endif namespace WebKit { class WebNodePrivate; @@ -53,7 +59,14 @@ namespace WebKit { WEBKIT_API WebNode parentNode() const; WEBKIT_API WebString nodeName() const; +#if WEBKIT_IMPLEMENTATION + WebNode(const WTF::PassRefPtr<WebCore::Node>&); + WebNode& operator=(const WTF::PassRefPtr<WebCore::Node>&); + operator WTF::PassRefPtr<WebCore::Node>() const; +#endif + private: + void assign(WebNodePrivate*); WebNodePrivate* m_private; }; diff --git a/webkit/api/src/WebImageCG.cpp b/webkit/api/src/WebImageCG.cpp index 1c28929..767e8e8 100644 --- a/webkit/api/src/WebImageCG.cpp +++ b/webkit/api/src/WebImageCG.cpp @@ -102,8 +102,10 @@ WebImage& WebImage::operator=(const PassRefPtr<Image>& image) void WebImage::assign(CGImageRef imageRef) { + // Make sure to retain the imageRef first incase m_imageRef == imageRef. + CGImageRetain(imageRef); CGImageRelease(m_imageRef); - CGImageRetain(m_imageRef = imageRef); + m_imageRef = imageRef; } } // namespace WebKit diff --git a/webkit/api/src/WebNode.cpp b/webkit/api/src/WebNode.cpp new file mode 100644 index 0000000..af187b6 --- /dev/null +++ b/webkit/api/src/WebNode.cpp @@ -0,0 +1,90 @@ +/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER OR 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 "WebNode.h"
+
+#include "Node.h"
+#include <wtf/PassRefPtr.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+class WebNodePrivate : public Node {
+};
+
+void WebNode::reset()
+{
+ assign(0);
+}
+
+void WebNode::assign(const WebNode& other)
+{
+ WebNodePrivate* p = const_cast<WebNodePrivate*>(other.m_private);
+ p->ref();
+ assign(p);
+}
+
+WebNode WebNode::parentNode() const
+{
+ return PassRefPtr<Node>(const_cast<Node*>(m_private->parentNode()));
+}
+
+WebString WebNode::nodeName() const
+{
+ return m_private->nodeName();
+}
+
+WebNode::WebNode(const WTF::PassRefPtr<WebCore::Node>& node)
+ : m_private(static_cast<WebNodePrivate*>(node.releaseRef()))
+{
+}
+
+WebNode& WebNode::operator=(const WTF::PassRefPtr<WebCore::Node>& node)
+{
+ assign(static_cast<WebNodePrivate*>(node.releaseRef()));
+ return *this;
+}
+
+WebNode::operator WTF::PassRefPtr<WebCore::Node>() const
+{
+ return PassRefPtr<Node>(const_cast<WebNodePrivate*>(m_private));
+}
+
+void WebNode::assign(WebNodePrivate* p)
+{
+ // p is already ref'd for us by the caller
+ if (m_private)
+ m_private->deref();
+ m_private = p;
+}
+
+} // namespace WebKit
diff --git a/webkit/api/src/WebURLRequest.cpp b/webkit/api/src/WebURLRequest.cpp index 4611872..d6eb114 100644 --- a/webkit/api/src/WebURLRequest.cpp +++ b/webkit/api/src/WebURLRequest.cpp @@ -74,7 +74,8 @@ void WebURLRequest::reset() void WebURLRequest::assign(const WebURLRequest& r) { - assign(r.m_private ? new WebURLRequestPrivateImpl(r.m_private) : 0); + if (&r != this) + assign(r.m_private ? new WebURLRequestPrivateImpl(r.m_private) : 0); } WebURL WebURLRequest::url() const @@ -227,6 +228,8 @@ const ResourceRequest& WebURLRequest::toResourceRequest() const void WebURLRequest::assign(WebURLRequestPrivate* p) { + // Subclasses may call this directly so a self-assignment check is needed + // here as well as in the public assign method. if (m_private == p) return; if (m_private) diff --git a/webkit/api/src/WebURLResponse.cpp b/webkit/api/src/WebURLResponse.cpp index 066000d..2fe6d64 100644 --- a/webkit/api/src/WebURLResponse.cpp +++ b/webkit/api/src/WebURLResponse.cpp @@ -74,7 +74,8 @@ void WebURLResponse::reset() void WebURLResponse::assign(const WebURLResponse& r) { - assign(r.m_private ? new WebURLResponsePrivateImpl(r.m_private) : 0); + if (&r != this) + assign(r.m_private ? new WebURLResponsePrivateImpl(r.m_private) : 0); } WebURL WebURLResponse::url() const @@ -241,6 +242,8 @@ const ResourceResponse& WebURLResponse::toResourceResponse() const void WebURLResponse::assign(WebURLResponsePrivate* p) { + // Subclasses may call this directly so a self-assignment check is needed + // here as well as in the public assign method. if (m_private == p) return; if (m_private) diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp index 0ae547d..c4495ab 100644 --- a/webkit/webkit.gyp +++ b/webkit/webkit.gyp @@ -1005,6 +1005,7 @@ 'api/public/WebMediaPlayerClient.h', 'api/public/WebMimeRegistry.h', 'api/public/WebNavigationType.h', + 'api/public/WebNode.h', 'api/public/WebNonCopyable.h', 'api/public/WebPluginListBuilder.h', 'api/public/WebPoint.h', @@ -1058,6 +1059,7 @@ 'api/src/WebKit.cpp', 'api/src/WebMediaPlayerClientImpl.cpp', 'api/src/WebMediaPlayerClientImpl.h', + 'api/src/WebNode.cpp', 'api/src/WebPluginListBuilderImpl.cpp', 'api/src/WebPluginListBuilderImpl.h', 'api/src/WebStorageAreaImpl.cpp', |