summaryrefslogtreecommitdiffstats
path: root/webkit/api/src
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-24 04:59:17 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-24 04:59:17 +0000
commitfd7f2379b27a709bc84e5af24a6097c9c355fc6e (patch)
tree953ce8b34cbbf5655f70731b4de1af007cedb54d /webkit/api/src
parenta106946bf1fbfeb6003510e3c26dd919611fa4fd (diff)
downloadchromium_src-fd7f2379b27a709bc84e5af24a6097c9c355fc6e.zip
chromium_src-fd7f2379b27a709bc84e5af24a6097c9c355fc6e.tar.gz
chromium_src-fd7f2379b27a709bc84e5af24a6097c9c355fc6e.tar.bz2
Switch WebHTTPBody and WebDragData to implement copy-on-write behavior. This
allows me to return a copyable instance of these wrapper classes while preventing a consumer from modifying the WebCore objects being wrapped. A modification will just modify a copy. This is going to be especially helpful when it comes to wrapping HistoryItem. Note how this simplifies WebURLRequest a bit since it doesn't have to carry a WebHTTPBody member. The copy-on-write behavior is implemented in an ensureMutable method. This CL depends on https://bugs.webkit.org/show_bug.cgi?id=26622 BUG=none TEST=none R=dglazkov Review URL: http://codereview.chromium.org/141062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19103 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/api/src')
-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
4 files changed, 48 insertions, 21 deletions
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