diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-18 06:21:09 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-18 06:21:09 +0000 |
commit | 91733b650d1e31b84a50860b3e5780d97b11d86d (patch) | |
tree | ba9408fd798e6e7ea3ad13219e6feea2689118cb /webkit/api | |
parent | 90e11737beffdf76a1cab1868ec8456c5580d2fe (diff) | |
download | chromium_src-91733b650d1e31b84a50860b3e5780d97b11d86d.zip chromium_src-91733b650d1e31b84a50860b3e5780d97b11d86d.tar.gz chromium_src-91733b650d1e31b84a50860b3e5780d97b11d86d.tar.bz2 |
Introduce WebKit::WebSecurityOrigin as a wrapper around
WebCore::SecurityOrigin.
This provides us a little wiggle room in the future in
case we ever want to provide more details about a
security origin beyond just its stringified value.
This was done on recommendation from Adam Barth.
R=jorlow
BUG=21967
TEST=none
Review URL: http://codereview.chromium.org/211013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26554 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/api')
-rw-r--r-- | webkit/api/public/WebFrame.h | 3 | ||||
-rw-r--r-- | webkit/api/public/WebFrameClient.h | 4 | ||||
-rw-r--r-- | webkit/api/public/WebSecurityOrigin.h | 73 | ||||
-rw-r--r-- | webkit/api/src/WebSecurityOrigin.cpp | 89 |
4 files changed, 166 insertions, 3 deletions
diff --git a/webkit/api/public/WebFrame.h b/webkit/api/public/WebFrame.h index b5840ba..07f5cf5 100644 --- a/webkit/api/public/WebFrame.h +++ b/webkit/api/public/WebFrame.h @@ -50,6 +50,7 @@ namespace WebKit { class WebForm; class WebHistoryItem; class WebRange; + class WebSecurityOrigin; class WebString; class WebURL; class WebURLRequest; @@ -161,7 +162,7 @@ namespace WebKit { // Scripting ---------------------------------------------------------- // Returns the security origin of the current document. - virtual WebString securityOrigin() const = 0; + virtual WebSecurityOrigin securityOrigin() const = 0; // This grants the currently loaded document access to all security // origins (including file URLs). Use with care. The access is diff --git a/webkit/api/public/WebFrameClient.h b/webkit/api/public/WebFrameClient.h index a126bb5..4d42965 100644 --- a/webkit/api/public/WebFrameClient.h +++ b/webkit/api/public/WebFrameClient.h @@ -42,6 +42,7 @@ namespace WebKit { class WebMediaPlayer; class WebMediaPlayerClient; class WebPlugin; + class WebSecurityOrigin; class WebString; class WebURL; class WebURLRequest; @@ -205,8 +206,7 @@ namespace WebKit { // The indicated security origin has run active content (such as a // script) from an insecure source. Note that the insecure content can // spread to other frames in the same origin. - virtual void didRunInsecureContent( - WebFrame*, const WebString& securityOrigin) = 0; + virtual void didRunInsecureContent(WebFrame*, const WebSecurityOrigin&) = 0; // Script notifications ------------------------------------------------ diff --git a/webkit/api/public/WebSecurityOrigin.h b/webkit/api/public/WebSecurityOrigin.h new file mode 100644 index 0000000..1905643 --- /dev/null +++ b/webkit/api/public/WebSecurityOrigin.h @@ -0,0 +1,73 @@ +/* + * 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. + */ + +#ifndef WebSecurityOrigin_h +#define WebSecurityOrigin_h + +#include "WebCommon.h" + +#if WEBKIT_IMPLEMENTATION +namespace WebCore { class SecurityOrigin; } +namespace WTF { template <typename T> class PassRefPtr; } +#endif + +namespace WebKit { + class WebSecurityOriginPrivate; + class WebString; + + class WebSecurityOrigin { + public: + ~WebSecurityOrigin() { reset(); } + + WebSecurityOrigin() : m_private(0) { } + WebSecurityOrigin(const WebSecurityOrigin& s) : m_private(0) { assign(s); } + WebSecurityOrigin& operator=(const WebSecurityOrigin& s) { assign(s); return *this; } + + WEBKIT_API void reset(); + WEBKIT_API void assign(const WebSecurityOrigin&); + + bool isNull() const { return m_private == 0; } + + WEBKIT_API WebString toString() const; + +#if WEBKIT_IMPLEMENTATION + WebSecurityOrigin(const WTF::PassRefPtr<WebCore::SecurityOrigin>&); + WebSecurityOrigin& operator=(const WTF::PassRefPtr<WebCore::SecurityOrigin>&); + operator WTF::PassRefPtr<WebCore::SecurityOrigin>() const; +#endif + + private: + void assign(WebSecurityOriginPrivate*); + WebSecurityOriginPrivate* m_private; + }; + +} // namespace WebKit + +#endif diff --git a/webkit/api/src/WebSecurityOrigin.cpp b/webkit/api/src/WebSecurityOrigin.cpp new file mode 100644 index 0000000..f1641e3 --- /dev/null +++ b/webkit/api/src/WebSecurityOrigin.cpp @@ -0,0 +1,89 @@ +/* + * 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 "WebSecurityOrigin.h" + +#include "SecurityOrigin.h" +#include "WebString.h" +#include <wtf/PassRefPtr.h> + +using namespace WebCore; + +namespace WebKit { + +class WebSecurityOriginPrivate : public SecurityOrigin { +}; + +void WebSecurityOrigin::reset() +{ + assign(0); +} + +void WebSecurityOrigin::assign(const WebSecurityOrigin& other) +{ + WebSecurityOriginPrivate* p = const_cast<WebSecurityOriginPrivate*>(other.m_private); + p->ref(); + assign(p); +} + +WebString WebSecurityOrigin::toString() const +{ + if (m_private) + return m_private->toString(); + + return WebString::fromUTF8("null"); +} + +WebSecurityOrigin::WebSecurityOrigin(const WTF::PassRefPtr<WebCore::SecurityOrigin>& origin) + : m_private(static_cast<WebSecurityOriginPrivate*>(origin.releaseRef())) +{ +} + +WebSecurityOrigin& WebSecurityOrigin::operator=(const WTF::PassRefPtr<WebCore::SecurityOrigin>& origin) +{ + assign(static_cast<WebSecurityOriginPrivate*>(origin.releaseRef())); + return *this; +} + +WebSecurityOrigin::operator WTF::PassRefPtr<WebCore::SecurityOrigin>() const +{ + return PassRefPtr<SecurityOrigin>(const_cast<WebSecurityOriginPrivate*>(m_private)); +} + +void WebSecurityOrigin::assign(WebSecurityOriginPrivate* p) +{ + // p is already ref'd for us by the caller + if (m_private) + m_private->deref(); + m_private = p; +} + +} // namespace WebKit |