From 8fecd9c9a62aa89fb44ed3142ba583dc7b8cbe29 Mon Sep 17 00:00:00 2001 From: Andrei Popescu Date: Mon, 29 Mar 2010 12:08:36 +0100 Subject: [PATCH] Cherry pick patch in https://bugs.webkit.org/show_bug.cgi?id=36665 which adds V8 bindings for page cache. Fix b: 2533219 Change-Id: I57f067adbbef76b4f8ec6c50b9e85fb2b7fc619a --- WebCore/Android.v8bindings.mk | 1 + WebCore/bindings/v8/ScriptCachedFrameData.cpp | 67 +++++++++++++++++++++++++++ WebCore/bindings/v8/ScriptCachedFrameData.h | 67 +++++++++++++++++++++------ WebCore/bindings/v8/V8DOMWindowShell.cpp | 10 ++++ WebCore/bindings/v8/V8DOMWindowShell.h | 1 + 5 files changed, 132 insertions(+), 14 deletions(-) create mode 100644 WebCore/bindings/v8/ScriptCachedFrameData.cpp diff --git a/WebCore/Android.v8bindings.mk b/WebCore/Android.v8bindings.mk index 673d2ab37..fb09c0071 100644 --- a/WebCore/Android.v8bindings.mk +++ b/WebCore/Android.v8bindings.mk @@ -57,6 +57,7 @@ LOCAL_SRC_FILES += \ bindings/v8/ScheduledAction.cpp \ bindings/v8/ScopedDOMDataStore.cpp \ bindings/v8/ScriptArray.cpp \ + bindings/v8/ScriptCachedFrameData.cpp \ bindings/v8/ScriptCallFrame.cpp \ bindings/v8/ScriptCallStack.cpp \ bindings/v8/ScriptController.cpp \ diff --git a/WebCore/bindings/v8/ScriptCachedFrameData.cpp b/WebCore/bindings/v8/ScriptCachedFrameData.cpp new file mode 100644 index 000000000..6d2f41cb1 --- /dev/null +++ b/WebCore/bindings/v8/ScriptCachedFrameData.cpp @@ -0,0 +1,67 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "ScriptCachedFrameData.h" + +#include "Frame.h" +#include "ScriptController.h" +#include "V8DOMWindow.h" + +namespace WebCore { + +ScriptCachedFrameData::ScriptCachedFrameData(Frame* frame) + : m_domWindow(frame->domWindow()) +{ + v8::HandleScope handleScope; + // The context can only be the context of the main world. + ASSERT(V8Proxy::mainWorldContext(frame) == V8Proxy::context(frame)); + m_context.set(V8Proxy::mainWorldContext(frame)); + m_global.set(m_context.get()->Global()); +} + +DOMWindow* ScriptCachedFrameData::domWindow() const +{ + return m_domWindow; +} + +void ScriptCachedFrameData::restore(Frame* frame) +{ + v8::HandleScope handleScope; + v8::Context::Scope contextScope(m_context.get()); + + m_context.get()->ReattachGlobal(m_global.get()); + V8Proxy* proxy = V8Proxy::retrieve(frame); + if (proxy) + proxy->windowShell()->setContext(m_context.get()); +} + +void ScriptCachedFrameData::clear() +{ + m_context.clear(); + m_global.clear(); +} + +} // namespace WebCore diff --git a/WebCore/bindings/v8/ScriptCachedFrameData.h b/WebCore/bindings/v8/ScriptCachedFrameData.h index e6530f473..f700a4850 100644 --- a/WebCore/bindings/v8/ScriptCachedFrameData.h +++ b/WebCore/bindings/v8/ScriptCachedFrameData.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2009 Google Inc. All rights reserved. + * Copyright (C) 2010 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -28,25 +28,64 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ScriptCachedPageData_h -#define ScriptCachedPageData_h +#ifndef ScriptCachedFrameData_h +#define ScriptCachedFrameData_h +#if PLATFORM(CHROMIUM) // We don't use WebKit's page caching, so this implementation is just a stub. namespace WebCore { - class Frame; - class DOMWindow; - class ScriptCachedFrameData { - public: - ScriptCachedFrameData(Frame*) { } - ~ScriptCachedFrameData() { } +class Frame; +class DOMWindow; - void restore(Frame*) { } - void clear() { } - DOMWindow* domWindow() const { return 0; } - }; +class ScriptCachedFrameData { +public: + ScriptCachedFrameData(Frame*) { } + ~ScriptCachedFrameData() { } + + void restore(Frame*) { } + void clear() { } + DOMWindow* domWindow() const { return 0; } +}; + +} // namespace WebCore + +#elif PLATFORM(ANDROID) +// FIXME: the right guard should be ENABLE(PAGE_CACHE). Replace with the right guard, once +// https://bugs.webkit.org/show_bug.cgi?id=35061 is fixed. +// +// On Android we do use WebKit's page cache. For now we don't support isolated worlds +// so our implementation does not take them into account. + +#include "OwnHandle.h" +#include +#include + +namespace WebCore { + +class Frame; +class DOMWindow; + +class ScriptCachedFrameData : public Noncopyable { +public: + ScriptCachedFrameData(Frame*); + ~ScriptCachedFrameData() { } + + void restore(Frame*); + void clear(); + DOMWindow* domWindow() const; + +private: + OwnHandle m_global; + OwnHandle m_context; + DOMWindow* m_domWindow; +}; } // namespace WebCore -#endif // ScriptCachedPageData_h +#else +#error You need to consider whether you want Page Cache and either add a stub or a real implementation. +#endif // PLATFORM(CHROMIUM) + +#endif // ScriptCachedFrameData_h diff --git a/WebCore/bindings/v8/V8DOMWindowShell.cpp b/WebCore/bindings/v8/V8DOMWindowShell.cpp index 0a21f44e1..cdf43935c 100644 --- a/WebCore/bindings/v8/V8DOMWindowShell.cpp +++ b/WebCore/bindings/v8/V8DOMWindowShell.cpp @@ -368,6 +368,16 @@ v8::Persistent V8DOMWindowShell::createNewContext(v8::Handle context) +{ + // if we already have a context, clear it before setting the new one. + if (!m_context.IsEmpty()) { + m_context.Dispose(); + m_context.Clear(); + } + m_context = v8::Persistent::New(context); +} + bool V8DOMWindowShell::installDOMWindow(v8::Handle context, DOMWindow* window) { v8::Handle implicitProtoString = v8::String::New("__proto__"); diff --git a/WebCore/bindings/v8/V8DOMWindowShell.h b/WebCore/bindings/v8/V8DOMWindowShell.h index 5114f7ac0..6b8952db3 100644 --- a/WebCore/bindings/v8/V8DOMWindowShell.h +++ b/WebCore/bindings/v8/V8DOMWindowShell.h @@ -60,6 +60,7 @@ public: bool isContextInitialized(); v8::Persistent createNewContext(v8::Handle global, int extensionGroup); + void setContext(v8::Handle); static bool installDOMWindow(v8::Handle context, DOMWindow*); void initContextIfNeeded(); -- 2.11.0