diff options
Diffstat (limited to 'webkit/api')
-rw-r--r-- | webkit/api/public/WebFrame.h | 12 | ||||
-rw-r--r-- | webkit/api/public/WebHistoryItem.h | 54 | ||||
-rw-r--r-- | webkit/api/public/WebVector.h | 5 | ||||
-rw-r--r-- | webkit/api/src/WebHistoryItem.cpp | 295 |
4 files changed, 338 insertions, 28 deletions
diff --git a/webkit/api/public/WebFrame.h b/webkit/api/public/WebFrame.h index 72ae9bb..bf740da 100644 --- a/webkit/api/public/WebFrame.h +++ b/webkit/api/public/WebFrame.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 @@ -161,7 +161,7 @@ namespace WebKit { virtual void loadURL(const WebURLRequest&) = 0; virtual void loadData(const WebData& data, - const WebString& mimeType, + const WebString& mimeType, const WebString& textEncoding, const WebURL& baseURL, const WebURL& unreachableURL, @@ -184,11 +184,11 @@ namespace WebKit { // Returns the previous history item. Check WebHistoryItem::isNull() // before using. - virtual const WebHistoryItem& previousHistoryItem() = 0; + virtual WebHistoryItem previousHistoryItem() = 0; // Returns the current history item. Check WebHistoryItem::isNull() // before using. - virtual const WebHistoryItem& currentHistoryItem() = 0; + virtual WebHistoryItem currentHistoryItem() = 0; // View-source rendering mode. Set this before loading an URL to cause // it to be rendered in view-source mode. diff --git a/webkit/api/public/WebHistoryItem.h b/webkit/api/public/WebHistoryItem.h index 5b2b32d..49ee18c 100644 --- a/webkit/api/public/WebHistoryItem.h +++ b/webkit/api/public/WebHistoryItem.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 @@ -33,10 +33,15 @@ #include "WebCommon.h" +#if WEBKIT_IMPLEMENTATION +namespace WebCore { class HistoryItem; } +namespace WTF { template <typename T> class PassRefPtr; } +#endif + namespace WebKit { class WebHistoryItemPrivate; + class WebHTTPBody; class WebString; - class WebURL; struct WebPoint; template <typename T> class WebVector; @@ -59,17 +64,17 @@ namespace WebKit { bool isNull() const { return m_private == 0; } - WEBKIT_API WebURL url() const; - WEBKIT_API void setURL(const WebURL&); + WEBKIT_API WebString urlString() const; + WEBKIT_API void setURLString(const WebString&); - WEBKIT_API WebURL originalURL() const; - WEBKIT_API void setOriginalURL(const WebURL&); + WEBKIT_API WebString originalURLString() const; + WEBKIT_API void setOriginalURLString(const WebString&); - WEBKIT_API WebURL referrerURL() const; - WEBKIT_API void setReferrerURL(const WebURL&); + WEBKIT_API WebString referrer() const; + WEBKIT_API void setReferrer(const WebString&); WEBKIT_API WebString target() const; - WEBKIT_API void setTarget(const WebString&) const; + WEBKIT_API void setTarget(const WebString&); WEBKIT_API WebString parent() const; WEBKIT_API void setParent(const WebString&); @@ -84,31 +89,36 @@ namespace WebKit { WEBKIT_API void setLastVisitedTime(double); WEBKIT_API WebPoint scrollOffset() const; - WEBKIT_API void setScrollOffset(const WebPoint&) const; + WEBKIT_API void setScrollOffset(const WebPoint&); WEBKIT_API bool isTargetItem() const; - WEBKIT_API void setIsTargetItem(bool) const; + WEBKIT_API void setIsTargetItem(bool); WEBKIT_API int visitCount() const; - WEBKIT_API void setVisitCount(int) const; + WEBKIT_API void setVisitCount(int); - WEBKIT_API void documentState(WebVector<WebString>&) const; - WEBKIT_API void setDocumentState(const WebVector<WebString>&) const; + WEBKIT_API WebVector<WebString> documentState() const; + WEBKIT_API void setDocumentState(const WebVector<WebString>&); WEBKIT_API WebString httpContentType() const; - WEBKIT_API void setHTTPContentType(const WebString&) const; + WEBKIT_API void setHTTPContentType(const WebString&); - WEBKIT_API bool hasHTTPBody() const; - WEBKIT_API void httpBody(WebHTTPBody&) const; + WEBKIT_API WebHTTPBody httpBody() const; WEBKIT_API void setHTTPBody(const WebHTTPBody&); - WEBKIT_API void appendToHTTPBody(const WebHTTPBody::Element&); - WEBKIT_API bool hasChildren() const; - WEBKIT_API void children(WebVector<WebHistoryItem>&) const; + WEBKIT_API WebVector<WebHistoryItem> children() const; WEBKIT_API void setChildren(const WebVector<WebHistoryItem>&); WEBKIT_API void appendToChildren(const WebHistoryItem&); +#if WEBKIT_IMPLEMENTATION + WebHistoryItem(const WTF::PassRefPtr<WebCore::HistoryItem>&); + WebHistoryItem& operator=(const WTF::PassRefPtr<WebCore::HistoryItem>&); + operator WTF::PassRefPtr<WebCore::HistoryItem>() const; +#endif + private: + void assign(WebHistoryItemPrivate*); + void ensureMutable(); WebHistoryItemPrivate* m_private; }; diff --git a/webkit/api/public/WebVector.h b/webkit/api/public/WebVector.h index ed6f01c..af811d6 100644 --- a/webkit/api/public/WebVector.h +++ b/webkit/api/public/WebVector.h @@ -73,6 +73,11 @@ namespace WebKit { initialize(size); } + WebVector(const WebVector<T>& other) + { + initializeFrom(other.m_ptr, other.m_size); + } + template <typename C> WebVector(const C& other) { diff --git a/webkit/api/src/WebHistoryItem.cpp b/webkit/api/src/WebHistoryItem.cpp new file mode 100644 index 0000000..675831b --- /dev/null +++ b/webkit/api/src/WebHistoryItem.cpp @@ -0,0 +1,295 @@ +/* + * 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 "WebHistoryItem.h" + +#include "FormData.h" +#include "HistoryItem.h" +#include "KURL.h" + +#include "WebHTTPBody.h" +#include "WebPoint.h" +#include "WebString.h" +#include "WebVector.h" + +using namespace WebCore; + +namespace WebKit { + +class WebHistoryItemPrivate : public HistoryItem { +}; + +void WebHistoryItem::initialize() +{ + assign(static_cast<WebHistoryItemPrivate*>(HistoryItem::create().releaseRef())); +} + +void WebHistoryItem::reset() +{ + assign(0); +} + +void WebHistoryItem::assign(const WebHistoryItem& other) +{ + WebHistoryItemPrivate* p = const_cast<WebHistoryItemPrivate*>(other.m_private); + p->ref(); + assign(p); +} + +WebString WebHistoryItem::urlString() const +{ + ASSERT(!isNull()); + return m_private->urlString(); +} + +void WebHistoryItem::setURLString(const WebString& url) +{ + ensureMutable(); + m_private->setURLString(KURL(url).string()); +} + +WebString WebHistoryItem::originalURLString() const +{ + ASSERT(!isNull()); + return m_private->originalURLString(); +} + +void WebHistoryItem::setOriginalURLString(const WebString& originalURLString) +{ + ensureMutable(); + m_private->setOriginalURLString(originalURLString); +} + +WebString WebHistoryItem::referrer() const +{ + ASSERT(!isNull()); + return m_private->referrer(); +} + +void WebHistoryItem::setReferrer(const WebString& referrer) +{ + ensureMutable(); + m_private->setReferrer(referrer); +} + +WebString WebHistoryItem::target() const +{ + ASSERT(!isNull()); + return m_private->target(); +} + +void WebHistoryItem::setTarget(const WebString& target) +{ + ensureMutable(); + m_private->setTarget(target); +} + +WebString WebHistoryItem::parent() const +{ + ASSERT(!isNull()); + return m_private->parent(); +} + +void WebHistoryItem::setParent(const WebString& parent) +{ + ensureMutable(); + m_private->setParent(parent); +} + +WebString WebHistoryItem::title() const +{ + ASSERT(!isNull()); + return m_private->title(); +} + +void WebHistoryItem::setTitle(const WebString& title) +{ + ensureMutable(); + m_private->setTitle(title); +} + +WebString WebHistoryItem::alternateTitle() const +{ + ASSERT(!isNull()); + return m_private->alternateTitle(); +} + +void WebHistoryItem::setAlternateTitle(const WebString& alternateTitle) +{ + ensureMutable(); + m_private->setAlternateTitle(alternateTitle); +} + +double WebHistoryItem::lastVisitedTime() const +{ + ASSERT(!isNull()); + return m_private->lastVisitedTime(); +} + +void WebHistoryItem::setLastVisitedTime(double lastVisitedTime) +{ + ensureMutable(); + // FIXME: setLastVisitedTime increments the visit count, so we have to + // correct for that. Instead, we should have a back-door to just mutate + // the last visited time directly. + int count = m_private->visitCount(); + m_private->setLastVisitedTime(lastVisitedTime); + m_private->setVisitCount(count); +} + +WebPoint WebHistoryItem::scrollOffset() const +{ + ASSERT(!isNull()); + return m_private->scrollPoint(); +} + +void WebHistoryItem::setScrollOffset(const WebPoint& scrollOffset) +{ + ensureMutable(); + m_private->setScrollPoint(scrollOffset); +} + +bool WebHistoryItem::isTargetItem() const +{ + ASSERT(!isNull()); + return m_private->isTargetItem(); +} + +void WebHistoryItem::setIsTargetItem(bool isTargetItem) +{ + ensureMutable(); + m_private->setIsTargetItem(isTargetItem); +} + +int WebHistoryItem::visitCount() const +{ + ASSERT(!isNull()); + return m_private->visitCount(); +} + +void WebHistoryItem::setVisitCount(int count) +{ + ensureMutable(); + m_private->setVisitCount(count); +} + +WebVector<WebString> WebHistoryItem::documentState() const +{ + ASSERT(!isNull()); + return m_private->documentState(); +} + +void WebHistoryItem::setDocumentState(const WebVector<WebString>& state) +{ + ensureMutable(); + // FIXME: would be nice to avoid the intermediate copy + Vector<String> ds; + for (size_t i = 0; i < state.size(); ++i) + ds.append(state[i]); + m_private->setDocumentState(ds); +} + +WebString WebHistoryItem::httpContentType() const +{ + ASSERT(!isNull()); + return m_private->formContentType(); +} + +void WebHistoryItem::setHTTPContentType(const WebString& httpContentType) +{ + ensureMutable(); + m_private->setFormContentType(httpContentType); +} + +WebHTTPBody WebHistoryItem::httpBody() const +{ + ASSERT(!isNull()); + return m_private->formData(); +} + +void WebHistoryItem::setHTTPBody(const WebHTTPBody& httpBody) +{ + ensureMutable(); + m_private->setFormData(httpBody); +} + +WebVector<WebHistoryItem> WebHistoryItem::children() const +{ + ASSERT(!isNull()); + return m_private->children(); +} + +void WebHistoryItem::setChildren(const WebVector<WebHistoryItem>& items) +{ + ensureMutable(); + m_private->clearChildren(); + for (size_t i = 0; i < items.size(); ++i) + m_private->addChildItem(items[i]); +} + +void WebHistoryItem::appendToChildren(const WebHistoryItem& item) +{ + ensureMutable(); + m_private->addChildItem(item); +} + +WebHistoryItem::WebHistoryItem(const PassRefPtr<HistoryItem>& item) + : m_private(static_cast<WebHistoryItemPrivate*>(item.releaseRef())) +{ +} + +WebHistoryItem& WebHistoryItem::operator=(const PassRefPtr<HistoryItem>& item) +{ + assign(static_cast<WebHistoryItemPrivate*>(item.releaseRef())); + return *this; +} + +WebHistoryItem::operator PassRefPtr<HistoryItem>() const +{ + return m_private; +} + +void WebHistoryItem::assign(WebHistoryItemPrivate* p) +{ + // p is already ref'd for us by the caller + if (m_private) + m_private->deref(); + m_private = p; +} + +void WebHistoryItem::ensureMutable() +{ + ASSERT(!isNull()); + if (!m_private->hasOneRef()) + assign(static_cast<WebHistoryItemPrivate*>(m_private->copy().releaseRef())); +} + +} // namespace WebKit |