summaryrefslogtreecommitdiffstats
path: root/webkit/api
diff options
context:
space:
mode:
Diffstat (limited to 'webkit/api')
-rw-r--r--webkit/api/public/WebDragData.h7
-rw-r--r--webkit/api/public/WebHTTPBody.h13
-rw-r--r--webkit/api/public/WebURLRequest.h2
-rw-r--r--webkit/api/src/WebDragData.cpp27
-rw-r--r--webkit/api/src/WebHTTPBody.cpp31
-rw-r--r--webkit/api/src/WebURLRequest.cpp6
-rw-r--r--webkit/api/src/WebURLRequestPrivate.h5
7 files changed, 62 insertions, 29 deletions
diff --git a/webkit/api/public/WebDragData.h b/webkit/api/public/WebDragData.h
index fe3abab..cb162dc 100644
--- a/webkit/api/public/WebDragData.h
+++ b/webkit/api/public/WebDragData.h
@@ -1,10 +1,10 @@
/*
* 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
@@ -14,7 +14,7 @@
* * 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
@@ -98,6 +98,7 @@ namespace WebKit {
private:
void assign(WebDragDataPrivate*);
+ void ensureMutable();
WebDragDataPrivate* m_private;
};
diff --git a/webkit/api/public/WebHTTPBody.h b/webkit/api/public/WebHTTPBody.h
index 59a008d..c3ea05f 100644
--- a/webkit/api/public/WebHTTPBody.h
+++ b/webkit/api/public/WebHTTPBody.h
@@ -43,7 +43,7 @@ namespace WTF { template <typename T> class PassRefPtr; }
namespace WebKit {
class WebHTTPBodyPrivate;
- class WebHTTPBody : public WebNonCopyable {
+ class WebHTTPBody {
public:
struct Element {
enum { TypeData, TypeFile } type;
@@ -54,11 +54,14 @@ namespace WebKit {
~WebHTTPBody() { reset(); }
WebHTTPBody() : m_private(0) { }
-
- bool isNull() const { return m_private == 0; }
+ WebHTTPBody(const WebHTTPBody& b) : m_private(0) { assign(b); }
+ WebHTTPBody& operator=(const WebHTTPBody& b) { assign(b); return *this; }
WEBKIT_API void initialize();
WEBKIT_API void reset();
+ WEBKIT_API void assign(const WebHTTPBody&);
+
+ bool isNull() const { return m_private == 0; }
// Returns the number of elements comprising the http body.
WEBKIT_API size_t elementCount() const;
@@ -77,12 +80,14 @@ namespace WebKit {
WEBKIT_API void setIdentifier(long long);
#if WEBKIT_IMPLEMENTATION
- void rebind(WTF::PassRefPtr<WebCore::FormData>);
+ WebHTTPBody(const WTF::PassRefPtr<WebCore::FormData>&);
+ WebHTTPBody& operator=(const WTF::PassRefPtr<WebCore::FormData>&);
operator WTF::PassRefPtr<WebCore::FormData>() const;
#endif
private:
void assign(WebHTTPBodyPrivate*);
+ void ensureMutable();
WebHTTPBodyPrivate* m_private;
};
diff --git a/webkit/api/public/WebURLRequest.h b/webkit/api/public/WebURLRequest.h
index 5e4ee07..dcd580a 100644
--- a/webkit/api/public/WebURLRequest.h
+++ b/webkit/api/public/WebURLRequest.h
@@ -100,7 +100,7 @@ namespace WebKit {
WEBKIT_API void clearHTTPHeaderField(const WebString& name);
WEBKIT_API void visitHTTPHeaderFields(WebHTTPHeaderVisitor*) const;
- WEBKIT_API const WebHTTPBody& httpBody() const;
+ WEBKIT_API WebHTTPBody httpBody() const;
WEBKIT_API void setHTTPBody(const WebHTTPBody&);
// Controls whether upload progress events are generated when a request
diff --git a/webkit/api/src/WebDragData.cpp b/webkit/api/src/WebDragData.cpp
index 044c6ea..facbcd2 100644
--- a/webkit/api/src/WebDragData.cpp
+++ b/webkit/api/src/WebDragData.cpp
@@ -71,7 +71,7 @@ WebURL WebDragData::url() const
void WebDragData::setURL(const WebURL& url)
{
- ASSERT(!isNull());
+ ensureMutable();
m_private->url = url;
}
@@ -83,7 +83,7 @@ WebString WebDragData::urlTitle() const
void WebDragData::setURLTitle(const WebString& urlTitle)
{
- ASSERT(!isNull());
+ ensureMutable();
m_private->urlTitle = urlTitle;
}
@@ -95,7 +95,7 @@ WebString WebDragData::fileExtension() const
void WebDragData::setFileExtension(const WebString& fileExtension)
{
- ASSERT(!isNull());
+ ensureMutable();
m_private->fileExtension = fileExtension;
}
@@ -113,14 +113,14 @@ void WebDragData::fileNames(WebVector<WebString>& fileNames) const
void WebDragData::setFileNames(const WebVector<WebString>& fileNames)
{
- ASSERT(!isNull());
+ ensureMutable();
m_private->filenames.clear();
m_private->filenames.append(fileNames.data(), fileNames.size());
}
void WebDragData::appendToFileNames(const WebString& fileName)
{
- ASSERT(!isNull());
+ ensureMutable();
m_private->filenames.append(fileName);
}
@@ -132,7 +132,7 @@ WebString WebDragData::plainText() const
void WebDragData::setPlainText(const WebString& plainText)
{
- ASSERT(!isNull());
+ ensureMutable();
m_private->plainText = plainText;
}
@@ -144,7 +144,7 @@ WebString WebDragData::htmlText() const
void WebDragData::setHTMLText(const WebString& htmlText)
{
- ASSERT(!isNull());
+ ensureMutable();
m_private->textHtml = htmlText;
}
@@ -156,7 +156,7 @@ WebURL WebDragData::htmlBaseURL() const
void WebDragData::setHTMLBaseURL(const WebURL& htmlBaseURL)
{
- ASSERT(!isNull());
+ ensureMutable();
m_private->htmlBaseUrl = htmlBaseURL;
}
@@ -168,7 +168,7 @@ WebString WebDragData::fileContentFileName() const
void WebDragData::setFileContentFileName(const WebString& fileName)
{
- ASSERT(!isNull());
+ ensureMutable();
m_private->fileContentFilename = fileName;
}
@@ -180,7 +180,7 @@ WebData WebDragData::fileContent() const
void WebDragData::setFileContent(const WebData& fileContent)
{
- ASSERT(!isNull());
+ ensureMutable();
m_private->fileContent = fileContent;
}
@@ -208,4 +208,11 @@ void WebDragData::assign(WebDragDataPrivate* p)
m_private = p;
}
+void WebDragData::ensureMutable()
+{
+ ASSERT(!isNull());
+ if (!m_private->hasOneRef())
+ assign(static_cast<WebDragDataPrivate*>(m_private->copy().releaseRef()));
+}
+
} // namespace WebKit
diff --git a/webkit/api/src/WebHTTPBody.cpp b/webkit/api/src/WebHTTPBody.cpp
index 69875e7..bd66b08 100644
--- a/webkit/api/src/WebHTTPBody.cpp
+++ b/webkit/api/src/WebHTTPBody.cpp
@@ -50,13 +50,23 @@ void WebHTTPBody::reset()
assign(0);
}
+void WebHTTPBody::assign(const WebHTTPBody& other)
+{
+ WebHTTPBodyPrivate* p = const_cast<WebHTTPBodyPrivate*>(other.m_private);
+ p->ref();
+ assign(p);
+}
+
size_t WebHTTPBody::elementCount() const
{
+ ASSERT(!isNull());
return m_private->elements().size();
}
bool WebHTTPBody::elementAt(size_t index, Element& result) const
{
+ ASSERT(!isNull());
+
if (index >= m_private->elements().size())
return false;
@@ -83,6 +93,7 @@ bool WebHTTPBody::elementAt(size_t index, Element& result) const
void WebHTTPBody::appendData(const WebData& data)
{
+ ensureMutable();
// FIXME: FormDataElement::m_data should be a SharedBuffer<char>. Then we
// could avoid this buffer copy.
m_private->appendData(data.data(), data.size());
@@ -90,22 +101,31 @@ void WebHTTPBody::appendData(const WebData& data)
void WebHTTPBody::appendFile(const WebString& filePath)
{
+ ensureMutable();
m_private->appendFile(filePath);
}
long long WebHTTPBody::identifier() const
{
+ ASSERT(!isNull());
return m_private->identifier();
}
void WebHTTPBody::setIdentifier(long long identifier)
{
+ ensureMutable();
return m_private->setIdentifier(identifier);
}
-void WebHTTPBody::rebind(PassRefPtr<FormData> formData)
+WebHTTPBody::WebHTTPBody(const PassRefPtr<FormData>& data)
+ : m_private(static_cast<WebHTTPBodyPrivate*>(data.releaseRef()))
+{
+}
+
+WebHTTPBody& WebHTTPBody::operator=(const PassRefPtr<FormData>& data)
{
- assign(static_cast<WebHTTPBodyPrivate*>(formData.releaseRef()));
+ assign(static_cast<WebHTTPBodyPrivate*>(data.releaseRef()));
+ return *this;
}
WebHTTPBody::operator PassRefPtr<FormData>() const
@@ -121,4 +141,11 @@ void WebHTTPBody::assign(WebHTTPBodyPrivate* p)
m_private = p;
}
+void WebHTTPBody::ensureMutable()
+{
+ ASSERT(!isNull());
+ if (!m_private->hasOneRef())
+ assign(static_cast<WebHTTPBodyPrivate*>(m_private->copy().releaseRef()));
+}
+
} // namespace WebKit
diff --git a/webkit/api/src/WebURLRequest.cpp b/webkit/api/src/WebURLRequest.cpp
index b62206c..6c92e7f 100644
--- a/webkit/api/src/WebURLRequest.cpp
+++ b/webkit/api/src/WebURLRequest.cpp
@@ -147,16 +147,14 @@ void WebURLRequest::visitHTTPHeaderFields(WebHTTPHeaderVisitor* visitor) const
visitor->visitHeader(String(it->first), it->second);
}
-const WebHTTPBody& WebURLRequest::httpBody() const
+WebHTTPBody WebURLRequest::httpBody() const
{
- m_private->m_httpBody.rebind(m_private->m_resourceRequest->httpBody());
- return m_private->m_httpBody;
+ return m_private->m_resourceRequest->httpBody();
}
void WebURLRequest::setHTTPBody(const WebHTTPBody& httpBody)
{
m_private->m_resourceRequest->setHTTPBody(httpBody);
- m_private->m_httpBody.rebind(0); // Free memory of the old body
}
bool WebURLRequest::reportUploadProgress() const
diff --git a/webkit/api/src/WebURLRequestPrivate.h b/webkit/api/src/WebURLRequestPrivate.h
index a2b0187..5c95a6f 100644
--- a/webkit/api/src/WebURLRequestPrivate.h
+++ b/webkit/api/src/WebURLRequestPrivate.h
@@ -31,10 +31,6 @@
#ifndef WebURLRequestPrivate_h
#define WebURLRequestPrivate_h
-// FIXME: This relative path is a temporary hack to support using this
-// header from webkit/glue.
-#include "../public/WebHTTPBody.h"
-
namespace WebCore { struct ResourceRequest; }
namespace WebKit {
@@ -47,7 +43,6 @@ namespace WebKit {
virtual void dispose() = 0;
WebCore::ResourceRequest* m_resourceRequest;
- WebHTTPBody m_httpBody;
};
} // namespace WebKit