/platform/external/webkit/WebCore/bindings/v8/V8IsolatedContext.cpp

https://github.com/aharish/totoro-gb-opensource-update2 · C++ · 92 lines · 38 code · 15 blank · 39 comment · 1 complexity · 5e4323c84835a7a3fa47bf40e4ce46be MD5 · raw file

  1. /*
  2. * Copyright (C) 2009 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 "V8IsolatedContext.h"
  32. #include "Frame.h"
  33. #include "FrameLoaderClient.h"
  34. #include "HashMap.h"
  35. #include "ScriptController.h"
  36. #include "V8DOMWindow.h"
  37. #include "V8HiddenPropertyName.h"
  38. #include <v8.h>
  39. namespace WebCore {
  40. void V8IsolatedContext::contextWeakReferenceCallback(v8::Persistent<v8::Value> object, void* isolatedContext)
  41. {
  42. // Our context is going away. Time to clean up the world.
  43. V8IsolatedContext* context = static_cast<V8IsolatedContext*>(isolatedContext);
  44. delete context;
  45. }
  46. V8IsolatedContext::V8IsolatedContext(V8Proxy* proxy, int extensionGroup)
  47. : m_world(IsolatedWorld::create())
  48. {
  49. v8::HandleScope scope;
  50. // FIXME: We should be creating a new V8DOMWindowShell here instead of riping out the context.
  51. m_context = SharedPersistent<v8::Context>::create(proxy->windowShell()->createNewContext(v8::Handle<v8::Object>(), extensionGroup));
  52. if (m_context->get().IsEmpty())
  53. return;
  54. // Run code in the new context.
  55. v8::Context::Scope contextScope(m_context->get());
  56. getGlobalObject(m_context->get())->SetPointerInInternalField(V8DOMWindow::enteredIsolatedWorldIndex, this);
  57. V8DOMWindowShell::installHiddenObjectPrototype(m_context->get());
  58. // FIXME: This will go away once we have a windowShell for the isolated world.
  59. proxy->windowShell()->installDOMWindow(m_context->get(), proxy->frame()->domWindow());
  60. // Using the default security token means that the canAccess is always
  61. // called, which is slow.
  62. // FIXME: Use tokens where possible. This will mean keeping track of all
  63. // created contexts so that they can all be updated when the
  64. // document domain
  65. // changes.
  66. m_context->get()->UseDefaultSecurityToken();
  67. proxy->frame()->loader()->client()->didCreateIsolatedScriptContext();
  68. }
  69. void V8IsolatedContext::destroy()
  70. {
  71. m_context->get().MakeWeak(this, &contextWeakReferenceCallback);
  72. }
  73. V8IsolatedContext::~V8IsolatedContext()
  74. {
  75. m_context->disposeHandle();
  76. }
  77. } // namespace WebCore