diff options
| author | Andrei Popescu <andreip@google.com> | 2009-06-08 17:39:30 +0100 |
|---|---|---|
| committer | Andrei Popescu <andreip@google.com> | 2009-06-08 17:40:48 +0100 |
| commit | 595f429f16d56891f697a15c3ec2fd2ec9647c5f (patch) | |
| tree | 0567454fd15ccfac8f82047ce0203a0878c186f6 /V8Binding/v8 | |
| parent | 91637c8ca6b8baa16edf528ee009b228d6e6c053 (diff) | |
| download | external_webkit-595f429f16d56891f697a15c3ec2fd2ec9647c5f.zip external_webkit-595f429f16d56891f697a15c3ec2fd2ec9647c5f.tar.gz external_webkit-595f429f16d56891f697a15c3ec2fd2ec9647c5f.tar.bz2 | |
Make AppCache work with v8:
-- Most changes follow Chrome's changes in the same area
-- I needed to update the CodeGeneratorV8.pm to the latest version
-- I needed to deprecate v8_utility.h and replace it with V8Utilities.h/cpp
Diffstat (limited to 'V8Binding/v8')
| -rw-r--r-- | V8Binding/v8/DOMObjectsInclude.h | 1 | ||||
| -rw-r--r-- | V8Binding/v8/V8Utilities.cpp | 110 | ||||
| -rw-r--r-- | V8Binding/v8/V8Utilities.h | 131 | ||||
| -rw-r--r-- | V8Binding/v8/v8_custom.h | 14 | ||||
| -rw-r--r-- | V8Binding/v8/v8_index.cpp | 4 | ||||
| -rw-r--r-- | V8Binding/v8/v8_index.h | 8 | ||||
| -rw-r--r-- | V8Binding/v8/v8_proxy.cpp | 16 | ||||
| -rw-r--r-- | V8Binding/v8/v8_proxy.h | 2 | ||||
| -rw-r--r-- | V8Binding/v8/v8_utility.h | 58 |
9 files changed, 285 insertions, 59 deletions
diff --git a/V8Binding/v8/DOMObjectsInclude.h b/V8Binding/v8/DOMObjectsInclude.h index b7b941e..0268bca 100644 --- a/V8Binding/v8/DOMObjectsInclude.h +++ b/V8Binding/v8/DOMObjectsInclude.h @@ -32,6 +32,7 @@ #include "Database.h" #include "DocumentType.h" #include "DocumentFragment.h" +#include "DOMApplicationCache.h" #include "DOMCoreException.h" #include "DOMImplementation.h" #include "DOMParser.h" diff --git a/V8Binding/v8/V8Utilities.cpp b/V8Binding/v8/V8Utilities.cpp new file mode 100644 index 0000000..8853506 --- /dev/null +++ b/V8Binding/v8/V8Utilities.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2008, 2009 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 + * 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. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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 "V8Utilities.h" + +#include <v8.h> + +#include "V8CustomBinding.h" +#include "V8Proxy.h" + +#include <wtf/Assertions.h> +#include "Frame.h" + +namespace WebCore { + +// Use an array to hold dependents. It works like a ref-counted scheme. +// A value can be added more than once to the DOM object. +void createHiddenDependency(v8::Local<v8::Object> object, v8::Local<v8::Value> value, int cacheIndex) +{ + v8::Local<v8::Value> cache = object->GetInternalField(cacheIndex); + if (cache->IsNull() || cache->IsUndefined()) { + cache = v8::Array::New(); + object->SetInternalField(cacheIndex, cache); + } + + v8::Local<v8::Array> cacheArray = v8::Local<v8::Array>::Cast(cache); + cacheArray->Set(v8::Integer::New(cacheArray->Length()), value); +} + +void removeHiddenDependency(v8::Local<v8::Object> object, v8::Local<v8::Value> value, int cacheIndex) +{ + v8::Local<v8::Value> cache = object->GetInternalField(cacheIndex); + ASSERT(cache->IsArray()); + v8::Local<v8::Array> cacheArray = v8::Local<v8::Array>::Cast(cache); + for (int i = cacheArray->Length() - 1; i >= 0; --i) { + v8::Local<v8::Value> cached = cacheArray->Get(v8::Integer::New(i)); + if (cached->StrictEquals(value)) { + cacheArray->Delete(i); + return; + } + } + + // We should only get here if we try to remove an event listener that was never added. + ASSERT_NOT_REACHED(); +} + +#if PLATFORM(ANDROID) + // The functions below are not needed on Android. +#else +bool processingUserGesture() +{ + Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); + return frame && frame->script()->processingUserGesture(); +} + +bool shouldAllowNavigation(Frame* frame) +{ + Frame* callingFrame = V8Proxy::retrieveFrameForCallingContext(); + return callingFrame && callingFrame->loader()->shouldAllowNavigation(frame); +} + +KURL completeURL(const String& relativeURL) +{ + // For histoical reasons, we need to complete the URL using the dynamic frame. + Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); + if (!frame) + return KURL(); + return frame->loader()->completeURL(relativeURL); +} + +void navigateIfAllowed(Frame* frame, const KURL& url, bool lockHistory, bool lockBackForwardList) +{ + Frame* callingFrame = V8Proxy::retrieveFrameForCallingContext(); + if (!callingFrame) + return; + + if (!protocolIsJavaScript(url) || ScriptController::isSafeScript(frame)) + frame->loader()->scheduleLocationChange(url.string(), callingFrame->loader()->outgoingReferrer(), lockHistory, lockBackForwardList, processingUserGesture()); +} +#endif // PLATFORM(ANDROID) + +} // namespace WebCore diff --git a/V8Binding/v8/V8Utilities.h b/V8Binding/v8/V8Utilities.h new file mode 100644 index 0000000..f4346f6 --- /dev/null +++ b/V8Binding/v8/V8Utilities.h @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2006, 2007, 2008, 2009 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 + * 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. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "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. + */ + +#ifndef V8Utilities_h +#define V8Utilities_h + +// FIXME: Remove once chromium dependencies on v8_utility.h are removed. +#define V8UTILITIES_DEFINED 1 + +#include <v8.h> + +namespace WebCore { + + class Frame; + class KURL; + class String; + + // Use an array to hold dependents. It works like a ref-counted scheme. A value can be added more than once to the DOM object. + void createHiddenDependency(v8::Local<v8::Object>, v8::Local<v8::Value>, int cacheIndex); + void removeHiddenDependency(v8::Local<v8::Object>, v8::Local<v8::Value>, int cacheIndex); + +#if PLATFORM(ANDROID) + // The functions below are not needed (yet) on Android. +#else + bool processingUserGesture(); + bool shouldAllowNavigation(Frame*); + KURL completeURL(const String& relativeURL); + void navigateIfAllowed(Frame*, const KURL&, bool lockHistory, bool lockBackForwardList); +#endif // PLATFORM(ANDROID) + + class AllowAllocation { + public: + inline AllowAllocation() + { + m_previous = m_current; + m_current = true; + } + + inline ~AllowAllocation() + { + m_current = m_previous; + } + + static bool m_current; + + private: + bool m_previous; + }; + + class SafeAllocation { + public: + static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>); + static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::ObjectTemplate>); + static inline v8::Local<v8::Object> newInstance(v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]); + + // FIXME: These NewInstance functions are here to ease upstreaming. Remove along with V8UTILITIES_DEFINED once chromium dependencies on v8_utility.h are removed. + static inline v8::Local<v8::Object> NewInstance(v8::Handle<v8::Function>); + static inline v8::Local<v8::Object> NewInstance(v8::Handle<v8::ObjectTemplate>); + static inline v8::Local<v8::Object> NewInstance(v8::Handle<v8::Function>, int argc, v8::Handle<v8::Value> argv[]); + }; + + v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::Function> function) + { + if (function.IsEmpty()) + return v8::Local<v8::Object>(); + AllowAllocation allow; + return function->NewInstance(); + } + + v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::ObjectTemplate> objectTemplate) + { + if (objectTemplate.IsEmpty()) + return v8::Local<v8::Object>(); + AllowAllocation allow; + return objectTemplate->NewInstance(); + } + + v8::Local<v8::Object> SafeAllocation::newInstance(v8::Handle<v8::Function> function, int argc, v8::Handle<v8::Value> argv[]) + { + if (function.IsEmpty()) + return v8::Local<v8::Object>(); + AllowAllocation allow; + return function->NewInstance(argc, argv); + } + + // FIXME: These NewInstance functions are here to ease upstreaming. Remove along with V8UTILITIES_DEFINED once chromium dependencies on v8_utility.h are removed. + v8::Local<v8::Object> SafeAllocation::NewInstance(v8::Handle<v8::Function> function) + { + return newInstance(function); + } + + v8::Local<v8::Object> SafeAllocation::NewInstance(v8::Handle<v8::ObjectTemplate> objectTemplate) + { + return newInstance(objectTemplate); + } + + v8::Local<v8::Object> SafeAllocation::NewInstance(v8::Handle<v8::Function> function, int argc, v8::Handle<v8::Value> argv[]) + { + return newInstance(function, argc, argv); + } + +} // namespace WebCore + +#endif // V8Utilities_h diff --git a/V8Binding/v8/v8_custom.h b/V8Binding/v8/v8_custom.h index a891e2e..caeac41 100644 --- a/V8Binding/v8/v8_custom.h +++ b/V8Binding/v8/v8_custom.h @@ -135,6 +135,13 @@ class V8Custom { static const int kStyleSheetInternalFieldCount = kDefaultWrapperInternalFieldCount + 1; +#if ENABLE(OFFLINE_WEB_APPLICATIONS) + static const int kDOMApplicationCacheCacheIndex = + kDefaultWrapperInternalFieldCount + 0; + static const int kDOMApplicationCacheFieldCount = + kDefaultWrapperInternalFieldCount + 1; +#endif + #define DECLARE_PROPERTY_ACCESSOR_GETTER(NAME) \ static v8::Handle<v8::Value> v8##NAME##AccessorGetter(\ v8::Local<v8::String> name, const v8::AccessorInfo& info); @@ -503,6 +510,13 @@ DECLARE_CALLBACK(WorkerContextAddEventListener) DECLARE_CALLBACK(WorkerContextRemoveEventListener) #endif +// AppCache +#if ENABLE(OFFLINE_WEB_APPLICATIONS) +DECLARE_PROPERTY_ACCESSOR(DOMApplicationCacheEventHandler) +DECLARE_CALLBACK(DOMApplicationCacheAddEventListener) +DECLARE_CALLBACK(DOMApplicationCacheRemoveEventListener) +#endif + #undef DECLARE_INDEXED_ACCESS_CHECK #undef DECLARE_NAMED_ACCESS_CHECK diff --git a/V8Binding/v8/v8_index.cpp b/V8Binding/v8/v8_index.cpp index fcc75e9..df138dc 100644 --- a/V8Binding/v8/v8_index.cpp +++ b/V8Binding/v8/v8_index.cpp @@ -392,6 +392,10 @@ #include "V8VoidCallback.h" #endif +#if ENABLE(OFFLINE_WEB_APPLICATIONS) +#include "V8DOMApplicationCache.h" +#endif + namespace WebCore { FunctionTemplateFactory V8ClassIndex::GetFactory(V8WrapperType type) { diff --git a/V8Binding/v8/v8_index.h b/V8Binding/v8/v8_index.h index b8d76ed..71453c3 100644 --- a/V8Binding/v8/v8_index.h +++ b/V8Binding/v8/v8_index.h @@ -39,6 +39,13 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); #define WORKER_NONNODE_WRAPPER_TYPES(V) #endif +#if ENABLE(OFFLINE_WEB_APPLICATIONS) +#define APPLICATIONCACHE_NONNODE_WRAPPER_TYPES(V) \ + V(DOMAPPLICATIONCACHE, DOMApplicationCache) +#else +#define APPLICATIONCACHE_NONNODE_WRAPPER_TYPES(V) +#endif + #define DOM_NODE_TYPES(V) \ V(ATTR, Attr) \ V(CHARACTERDATA, CharacterData) \ @@ -328,6 +335,7 @@ typedef v8::Persistent<v8::FunctionTemplate> (*FunctionTemplateFactory)(); V(XMLHTTPREQUESTPROGRESSEVENT, XMLHttpRequestProgressEvent) \ V(XMLSERIALIZER, XMLSerializer) \ ACTIVE_DOM_OBJECT_TYPES(V) \ + APPLICATIONCACHE_NONNODE_WRAPPER_TYPES(V) \ VIDEO_NONNODE_TYPES(V) \ WORKER_NONNODE_WRAPPER_TYPES(V) diff --git a/V8Binding/v8/v8_proxy.cpp b/V8Binding/v8/v8_proxy.cpp index 204b2bc..45b56d7 100644 --- a/V8Binding/v8/v8_proxy.cpp +++ b/V8Binding/v8/v8_proxy.cpp @@ -1658,6 +1658,16 @@ v8::Persistent<v8::FunctionTemplate> V8Proxy::GetTemplate( } #endif // WORKERS +#if ENABLE(OFFLINE_WEB_APPLICATIONS) + case V8ClassIndex::DOMAPPLICATIONCACHE: { + // Reserve one more internal field for keeping event listeners. + v8::Local<v8::ObjectTemplate> instance_template = + desc->InstanceTemplate(); + instance_template->SetInternalFieldCount( + V8Custom::kDOMApplicationCacheFieldCount); + break; + } +#endif // The following objects are created from JavaScript. case V8ClassIndex::DOMPARSER: @@ -3065,6 +3075,12 @@ v8::Handle<v8::Value> V8Proxy::EventTargetToV8Object(EventTarget* target) return ToV8Object(V8ClassIndex::WORKER, worker); #endif // WORKERS +#if ENABLE(OFFLINE_WEB_APPLICATIONS) + DOMApplicationCache* app_cache = target->toDOMApplicationCache(); + if (app_cache) + return ToV8Object(V8ClassIndex::DOMAPPLICATIONCACHE, app_cache); +#endif + Node* node = target->toNode(); if (node) return NodeToV8Object(node); diff --git a/V8Binding/v8/v8_proxy.h b/V8Binding/v8/v8_proxy.h index 45f9f39..17a2d1b 100644 --- a/V8Binding/v8/v8_proxy.h +++ b/V8Binding/v8/v8_proxy.h @@ -8,7 +8,7 @@ #include <v8.h> #include "v8_index.h" #include "v8_custom.h" -#include "v8_utility.h" +#include "V8Utilities.h" #include "Node.h" #include "NodeFilter.h" #include "PlatformString.h" // for WebCore::String diff --git a/V8Binding/v8/v8_utility.h b/V8Binding/v8/v8_utility.h deleted file mode 100644 index 620c04c..0000000 --- a/V8Binding/v8/v8_utility.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef V8_UTILITY_H__ -#define V8_UTILITY_H__ - -namespace WebCore { - -class AllowAllocation { - public: - inline AllowAllocation() { - m_prev = m_current; - m_current = true; - } - inline ~AllowAllocation() { - m_current = m_prev; - } - static bool m_current; - private: - bool m_prev; -}; - -class SafeAllocation { - public: - static inline v8::Local<v8::Object> NewInstance( - v8::Handle<v8::Function> fun); - static inline v8::Local<v8::Object> NewInstance( - v8::Handle<v8::ObjectTemplate> templ); - static inline v8::Local<v8::Object> NewInstance( - v8::Handle<v8::Function> fun, int argc, v8::Handle<v8::Value> argv[]); -}; - -v8::Local<v8::Object> SafeAllocation::NewInstance( - v8::Handle<v8::Function> fun) { - if (fun.IsEmpty()) - return v8::Local<v8::Object>(); - AllowAllocation allow; - return fun->NewInstance(); -} - -v8::Local<v8::Object> SafeAllocation::NewInstance( - v8::Handle<v8::ObjectTemplate> templ) { - if (templ.IsEmpty()) return v8::Local<v8::Object>(); - AllowAllocation allow; - return templ->NewInstance(); -} - -v8::Local<v8::Object> SafeAllocation::NewInstance( - v8::Handle<v8::Function> fun, int argc, v8::Handle<v8::Value> argv[]) { - if (fun.IsEmpty()) return v8::Local<v8::Object>(); - AllowAllocation allow; - return fun->NewInstance(argc, argv); -} - -} // namespace WebCore - -#endif // V8_UTILITY_H__ |
