/src/3rdparty/webkit/Source/WebCore/bindings/js/ScriptState.cpp

https://bitbucket.org/ultra_iter/qt-vtl · C++ · 96 lines · 55 code · 12 blank · 29 comment · 5 complexity · 88db6a0054a1373c6574eafbe099a6e9 MD5 · raw file

  1. /*
  2. * Copyright (C) 2009, 2011 Google Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above
  11. * copyright notice, this list of conditions and the following disclaimer
  12. * in the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Google Inc. nor the names of its
  15. * contributors may be used to endorse or promote products derived from
  16. * this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include "config.h"
  31. #include "ScriptState.h"
  32. #include "Frame.h"
  33. #include "JSDOMWindowBase.h"
  34. #include "JSWorkerContext.h"
  35. #include "Node.h"
  36. #include "Page.h"
  37. #include "WorkerContext.h"
  38. #include "WorkerScriptController.h"
  39. #include <interpreter/CallFrame.h>
  40. #include <runtime/JSGlobalObject.h>
  41. namespace WebCore {
  42. ScriptStateProtectedPtr::~ScriptStateProtectedPtr()
  43. {
  44. }
  45. ScriptStateProtectedPtr::ScriptStateProtectedPtr(ScriptState* scriptState)
  46. : m_globalObject(scriptState->globalData(), scriptState->lexicalGlobalObject())
  47. {
  48. }
  49. ScriptState* ScriptStateProtectedPtr::get() const
  50. {
  51. if (m_globalObject)
  52. return const_cast<JSC::JSGlobalObject*>(m_globalObject.get())->globalExec();
  53. return 0;
  54. }
  55. ScriptState* mainWorldScriptState(Frame* frame)
  56. {
  57. JSDOMWindowShell* shell = frame->script()->windowShell(mainThreadNormalWorld());
  58. return shell->window()->globalExec();
  59. }
  60. ScriptState* scriptStateFromNode(DOMWrapperWorld* world, Node* node)
  61. {
  62. if (!node)
  63. return 0;
  64. Document* document = node->document();
  65. if (!document)
  66. return 0;
  67. Frame* frame = document->frame();
  68. if (!frame)
  69. return 0;
  70. if (!frame->script()->canExecuteScripts(NotAboutToExecuteScript))
  71. return 0;
  72. return frame->script()->globalObject(world)->globalExec();
  73. }
  74. ScriptState* scriptStateFromPage(DOMWrapperWorld* world, Page* page)
  75. {
  76. return page->mainFrame()->script()->globalObject(world)->globalExec();
  77. }
  78. #if ENABLE(WORKERS)
  79. ScriptState* scriptStateFromWorkerContext(WorkerContext* workerContext)
  80. {
  81. return workerContext->script()->workerContextWrapper()->globalExec();
  82. }
  83. #endif
  84. }