• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <wtf/AlwaysInline.h>
25 
26 namespace WebCore {
27 
asJSDOMWindow(JSC::JSGlobalObject * globalObject)28 inline JSDOMWindow* asJSDOMWindow(JSC::JSGlobalObject* globalObject)
29 {
30     return static_cast<JSDOMWindow*>(globalObject);
31 }
32 
asJSDOMWindow(const JSC::JSGlobalObject * globalObject)33 inline const JSDOMWindow* asJSDOMWindow(const JSC::JSGlobalObject* globalObject)
34 {
35     return static_cast<const JSDOMWindow*>(globalObject);
36 }
37 
allowsAccessFrom(const JSGlobalObject * other)38 inline bool JSDOMWindowBase::allowsAccessFrom(const JSGlobalObject* other) const
39 {
40     if (allowsAccessFromPrivate(other))
41         return true;
42     printErrorMessage(crossDomainAccessErrorMessage(other));
43     return false;
44 }
45 
allowsAccessFrom(JSC::ExecState * exec)46 inline bool JSDOMWindowBase::allowsAccessFrom(JSC::ExecState* exec) const
47 {
48     if (allowsAccessFromPrivate(exec->lexicalGlobalObject()))
49         return true;
50     printErrorMessage(crossDomainAccessErrorMessage(exec->lexicalGlobalObject()));
51     return false;
52 }
53 
allowsAccessFromNoErrorMessage(JSC::ExecState * exec)54 inline bool JSDOMWindowBase::allowsAccessFromNoErrorMessage(JSC::ExecState* exec) const
55 {
56     return allowsAccessFromPrivate(exec->lexicalGlobalObject());
57 }
58 
allowsAccessFrom(JSC::ExecState * exec,String & message)59 inline bool JSDOMWindowBase::allowsAccessFrom(JSC::ExecState* exec, String& message) const
60 {
61     if (allowsAccessFromPrivate(exec->lexicalGlobalObject()))
62         return true;
63     message = crossDomainAccessErrorMessage(exec->lexicalGlobalObject());
64     return false;
65 }
66 
allowsAccessFromPrivate(const JSGlobalObject * other)67 ALWAYS_INLINE bool JSDOMWindowBase::allowsAccessFromPrivate(const JSGlobalObject* other) const
68 {
69     const JSDOMWindow* originWindow = asJSDOMWindow(other);
70     const JSDOMWindow* targetWindow = m_shell->window();
71 
72     if (originWindow == targetWindow)
73         return true;
74 
75     const SecurityOrigin* originSecurityOrigin = originWindow->impl()->securityOrigin();
76     const SecurityOrigin* targetSecurityOrigin = targetWindow->impl()->securityOrigin();
77 
78     return originSecurityOrigin->canAccess(targetSecurityOrigin);
79 }
80 
81 }
82 
83 #endif // JSDOMWindowCustom_h
84