diff options
author | Andrei Popescu <andreip@google.com> | 2010-03-29 12:08:36 +0100 |
---|---|---|
committer | Andrei Popescu <andreip@google.com> | 2010-03-29 12:29:03 +0100 |
commit | 8fecd9c9a62aa89fb44ed3142ba583dc7b8cbe29 (patch) | |
tree | 4a83eb4114f8b5e124c80b9e95e9f70f786a4415 | |
parent | deb08023e61ef15357d4ffda961ae9de873c45a0 (diff) | |
download | external_webkit-8fecd9c9a62aa89fb44ed3142ba583dc7b8cbe29.zip external_webkit-8fecd9c9a62aa89fb44ed3142ba583dc7b8cbe29.tar.gz external_webkit-8fecd9c9a62aa89fb44ed3142ba583dc7b8cbe29.tar.bz2 |
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
-rw-r--r-- | WebCore/Android.v8bindings.mk | 1 | ||||
-rw-r--r-- | WebCore/bindings/v8/ScriptCachedFrameData.cpp | 67 | ||||
-rw-r--r-- | WebCore/bindings/v8/ScriptCachedFrameData.h | 67 | ||||
-rw-r--r-- | WebCore/bindings/v8/V8DOMWindowShell.cpp | 10 | ||||
-rw-r--r-- | WebCore/bindings/v8/V8DOMWindowShell.h | 1 |
5 files changed, 132 insertions, 14 deletions
diff --git a/WebCore/Android.v8bindings.mk b/WebCore/Android.v8bindings.mk index 673d2ab..fb09c00 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 0000000..6d2f41c --- /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 e6530f4..f700a48 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 <v8.h> +#include <wtf/Noncopyable.h> + +namespace WebCore { + +class Frame; +class DOMWindow; + +class ScriptCachedFrameData : public Noncopyable { +public: + ScriptCachedFrameData(Frame*); + ~ScriptCachedFrameData() { } + + void restore(Frame*); + void clear(); + DOMWindow* domWindow() const; + +private: + OwnHandle<v8::Object> m_global; + OwnHandle<v8::Context> 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 0a21f44..cdf4393 100644 --- a/WebCore/bindings/v8/V8DOMWindowShell.cpp +++ b/WebCore/bindings/v8/V8DOMWindowShell.cpp @@ -368,6 +368,16 @@ v8::Persistent<v8::Context> V8DOMWindowShell::createNewContext(v8::Handle<v8::Ob return result; } +void V8DOMWindowShell::setContext(v8::Handle<v8::Context> 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<v8::Context>::New(context); +} + bool V8DOMWindowShell::installDOMWindow(v8::Handle<v8::Context> context, DOMWindow* window) { v8::Handle<v8::String> implicitProtoString = v8::String::New("__proto__"); diff --git a/WebCore/bindings/v8/V8DOMWindowShell.h b/WebCore/bindings/v8/V8DOMWindowShell.h index 5114f7a..6b8952d 100644 --- a/WebCore/bindings/v8/V8DOMWindowShell.h +++ b/WebCore/bindings/v8/V8DOMWindowShell.h @@ -60,6 +60,7 @@ public: bool isContextInitialized(); v8::Persistent<v8::Context> createNewContext(v8::Handle<v8::Object> global, int extensionGroup); + void setContext(v8::Handle<v8::Context>); static bool installDOMWindow(v8::Handle<v8::Context> context, DOMWindow*); void initContextIfNeeded(); |