1 /*
2 * Copyright (C) 2008, 2009 Apple Inc. All rights reseved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #ifndef JSDOMWindowCustom_h
20 #define JSDOMWindowCustom_h
21
22 #include "JSDOMWindow.h"
23 #include "JSDOMWindowShell.h"
24 #include "SecurityOrigin.h"
25 #include <wtf/AlwaysInline.h>
26
27 namespace WebCore {
28
asJSDOMWindow(JSC::JSGlobalObject * globalObject)29 inline JSDOMWindow* asJSDOMWindow(JSC::JSGlobalObject* globalObject)
30 {
31 return static_cast<JSDOMWindow*>(globalObject);
32 }
33
asJSDOMWindow(const JSC::JSGlobalObject * globalObject)34 inline const JSDOMWindow* asJSDOMWindow(const JSC::JSGlobalObject* globalObject)
35 {
36 return static_cast<const JSDOMWindow*>(globalObject);
37 }
38
allowsAccessFrom(const JSGlobalObject * other)39 inline bool JSDOMWindowBase::allowsAccessFrom(const JSGlobalObject* other) const
40 {
41 if (allowsAccessFromPrivate(other))
42 return true;
43 printErrorMessage(crossDomainAccessErrorMessage(other));
44 return false;
45 }
46
allowsAccessFrom(JSC::ExecState * exec)47 inline bool JSDOMWindowBase::allowsAccessFrom(JSC::ExecState* exec) const
48 {
49 if (allowsAccessFromPrivate(exec->lexicalGlobalObject()))
50 return true;
51 printErrorMessage(crossDomainAccessErrorMessage(exec->lexicalGlobalObject()));
52 return false;
53 }
54
allowsAccessFromNoErrorMessage(JSC::ExecState * exec)55 inline bool JSDOMWindowBase::allowsAccessFromNoErrorMessage(JSC::ExecState* exec) const
56 {
57 return allowsAccessFromPrivate(exec->lexicalGlobalObject());
58 }
59
allowsAccessFrom(JSC::ExecState * exec,String & message)60 inline bool JSDOMWindowBase::allowsAccessFrom(JSC::ExecState* exec, String& message) const
61 {
62 if (allowsAccessFromPrivate(exec->lexicalGlobalObject()))
63 return true;
64 message = crossDomainAccessErrorMessage(exec->lexicalGlobalObject());
65 return false;
66 }
67
allowsAccessFromPrivate(const JSGlobalObject * other)68 ALWAYS_INLINE bool JSDOMWindowBase::allowsAccessFromPrivate(const JSGlobalObject* other) const
69 {
70 const JSDOMWindow* originWindow = asJSDOMWindow(other);
71 const JSDOMWindow* targetWindow = m_shell->window();
72
73 if (originWindow == targetWindow)
74 return true;
75
76 const SecurityOrigin* originSecurityOrigin = originWindow->impl()->securityOrigin();
77 const SecurityOrigin* targetSecurityOrigin = targetWindow->impl()->securityOrigin();
78
79 return originSecurityOrigin->canAccess(targetSecurityOrigin);
80 }
81
82 }
83
84 #endif // JSDOMWindowCustom_h
85