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 26namespace WebCore { 27 28inline JSDOMWindow* asJSDOMWindow(JSC::JSGlobalObject* globalObject) 29{ 30 return static_cast<JSDOMWindow*>(globalObject); 31} 32 33inline const JSDOMWindow* asJSDOMWindow(const JSC::JSGlobalObject* globalObject) 34{ 35 return static_cast<const JSDOMWindow*>(globalObject); 36} 37 38inline bool JSDOMWindowBase::allowsAccessFrom(const JSGlobalObject* other) const 39{ 40 if (allowsAccessFromPrivate(other)) 41 return true; 42 printErrorMessage(crossDomainAccessErrorMessage(other)); 43 return false; 44} 45 46inline 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 54inline bool JSDOMWindowBase::allowsAccessFromNoErrorMessage(JSC::ExecState* exec) const 55{ 56 return allowsAccessFromPrivate(exec->lexicalGlobalObject()); 57} 58 59inline 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 67ALWAYS_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