2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
28 #include <wtf/Forward.h>
29 #include <wtf/Noncopyable.h>
30 #include <wtf/ProcessID.h>
31 #include <wtf/RefCounted.h>
32 #include <wtf/RefPtr.h>
33 #include <wtf/Vector.h>
34 #include <wtf/text/WTFString.h>
43 class SandboxExtensionImpl;
45 class SandboxExtension : public RefCounted<SandboxExtension> {
55 WTF_MAKE_NONCOPYABLE(Handle);
58 #if ENABLE(SANDBOX_EXTENSIONS)
60 Handle& operator=(Handle&&);
62 Handle(Handle&&) = default;
63 Handle& operator=(Handle&&) = default;
67 void encode(IPC::Encoder&) const;
68 static Optional<Handle> decode(IPC::Decoder&);
71 friend class SandboxExtension;
72 #if ENABLE(SANDBOX_EXTENSIONS)
73 mutable std::unique_ptr<SandboxExtensionImpl> m_sandboxExtension;
78 WTF_MAKE_NONCOPYABLE(HandleArray);
81 HandleArray(HandleArray&&) = default;
82 HandleArray& operator=(HandleArray&&) = default;
84 void allocate(size_t);
85 Handle& operator[](size_t i);
86 Handle& at(size_t i) { return operator[](i); }
87 const Handle& operator[](size_t i) const;
89 void encode(IPC::Encoder&) const;
90 static Optional<HandleArray> decode(IPC::Decoder&);
93 #if ENABLE(SANDBOX_EXTENSIONS)
94 Vector<Handle> m_data;
100 static RefPtr<SandboxExtension> create(Handle&&);
101 static bool createHandle(const String& path, Type, Handle&);
102 static bool createHandleWithoutResolvingPath(const String& path, Type, Handle&);
103 static bool createHandleForReadWriteDirectory(const String& path, Handle&); // Will attempt to create the directory.
104 static String createHandleForTemporaryFile(const String& prefix, Type, Handle&);
105 static bool createHandleForGenericExtension(const String& extensionClass, Handle&);
106 static bool createHandleForMachLookupByPid(const String& service, ProcessID, Handle&);
112 bool consumePermanently();
113 static bool consumePermanently(const Handle&);
116 explicit SandboxExtension(const Handle&);
118 #if ENABLE(SANDBOX_EXTENSIONS)
119 mutable std::unique_ptr<SandboxExtensionImpl> m_sandboxExtension;
120 size_t m_useCount { 0 };
124 #if !ENABLE(SANDBOX_EXTENSIONS)
125 inline SandboxExtension::Handle::Handle() { }
126 inline SandboxExtension::Handle::~Handle() { }
127 inline void SandboxExtension::Handle::encode(IPC::Encoder&) const { }
128 inline Optional<SandboxExtension::Handle> SandboxExtension::Handle::decode(IPC::Decoder&) { return SandboxExtension::Handle { }; }
129 inline SandboxExtension::HandleArray::HandleArray() { }
130 inline SandboxExtension::HandleArray::~HandleArray() { }
131 inline void SandboxExtension::HandleArray::allocate(size_t) { }
132 inline size_t SandboxExtension::HandleArray::size() const { return 0; }
133 inline const SandboxExtension::Handle& SandboxExtension::HandleArray::operator[](size_t) const { return m_emptyHandle; }
134 inline SandboxExtension::Handle& SandboxExtension::HandleArray::operator[](size_t) { return m_emptyHandle; }
135 inline void SandboxExtension::HandleArray::encode(IPC::Encoder&) const { }
136 inline auto SandboxExtension::HandleArray::decode(IPC::Decoder&) -> Optional<HandleArray> { return {{ }}; }
137 inline RefPtr<SandboxExtension> SandboxExtension::create(Handle&&) { return nullptr; }
138 inline bool SandboxExtension::createHandle(const String&, Type, Handle&) { return true; }
139 inline bool SandboxExtension::createHandleWithoutResolvingPath(const String&, Type, Handle&) { return true; }
140 inline bool SandboxExtension::createHandleForReadWriteDirectory(const String&, Handle&) { return true; }
141 inline String SandboxExtension::createHandleForTemporaryFile(const String& /*prefix*/, Type, Handle&) {return String();}
142 inline bool SandboxExtension::createHandleForGenericExtension(const String& /*extensionClass*/, Handle&) { return true; }
143 inline SandboxExtension::~SandboxExtension() { }
144 inline bool SandboxExtension::revoke() { return true; }
145 inline bool SandboxExtension::consume() { return true; }
146 inline bool SandboxExtension::consumePermanently() { return true; }
147 inline bool SandboxExtension::consumePermanently(const Handle&) { return true; }
148 inline String stringByResolvingSymlinksInPath(const String& path) { return path; }
149 inline String resolvePathForSandboxExtension(const String& path) { return path; }
150 inline String resolveAndCreateReadWriteDirectoryForSandboxExtension(const String& path) { return path; }
152 String stringByResolvingSymlinksInPath(const String& path);
153 String resolvePathForSandboxExtension(const String& path);
154 String resolveAndCreateReadWriteDirectoryForSandboxExtension(const String& path);
157 } // namespace WebKit