/platform/external/webkit/WebCore/bindings/js/JSDOMWindowCustom.h

https://github.com/aharish/totoro-gb-opensource-update2 · C Header · 83 lines · 51 code · 15 blank · 17 comment · 5 complexity · 6e0411e5ec08b0fbaa4c2d8555cf0b06 MD5 · raw file

  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. #ifndef JSDOMWindowCustom_h
  19. #define JSDOMWindowCustom_h
  20. #include "JSDOMWindow.h"
  21. #include "JSDOMWindowShell.h"
  22. #include <wtf/AlwaysInline.h>
  23. namespace WebCore {
  24. inline JSDOMWindow* asJSDOMWindow(JSC::JSGlobalObject* globalObject)
  25. {
  26. return static_cast<JSDOMWindow*>(globalObject);
  27. }
  28. inline const JSDOMWindow* asJSDOMWindow(const JSC::JSGlobalObject* globalObject)
  29. {
  30. return static_cast<const JSDOMWindow*>(globalObject);
  31. }
  32. inline bool JSDOMWindowBase::allowsAccessFrom(const JSGlobalObject* other) const
  33. {
  34. if (allowsAccessFromPrivate(other))
  35. return true;
  36. printErrorMessage(crossDomainAccessErrorMessage(other));
  37. return false;
  38. }
  39. inline bool JSDOMWindowBase::allowsAccessFrom(JSC::ExecState* exec) const
  40. {
  41. if (allowsAccessFromPrivate(exec->lexicalGlobalObject()))
  42. return true;
  43. printErrorMessage(crossDomainAccessErrorMessage(exec->lexicalGlobalObject()));
  44. return false;
  45. }
  46. inline bool JSDOMWindowBase::allowsAccessFromNoErrorMessage(JSC::ExecState* exec) const
  47. {
  48. return allowsAccessFromPrivate(exec->lexicalGlobalObject());
  49. }
  50. inline bool JSDOMWindowBase::allowsAccessFrom(JSC::ExecState* exec, String& message) const
  51. {
  52. if (allowsAccessFromPrivate(exec->lexicalGlobalObject()))
  53. return true;
  54. message = crossDomainAccessErrorMessage(exec->lexicalGlobalObject());
  55. return false;
  56. }
  57. ALWAYS_INLINE bool JSDOMWindowBase::allowsAccessFromPrivate(const JSGlobalObject* other) const
  58. {
  59. const JSDOMWindow* originWindow = asJSDOMWindow(other);
  60. const JSDOMWindow* targetWindow = d()->shell->window();
  61. if (originWindow == targetWindow)
  62. return true;
  63. const SecurityOrigin* originSecurityOrigin = originWindow->impl()->securityOrigin();
  64. const SecurityOrigin* targetSecurityOrigin = targetWindow->impl()->securityOrigin();
  65. return originSecurityOrigin->canAccess(targetSecurityOrigin);
  66. }
  67. }
  68. #endif // JSDOMWindowCustom_h