2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 #ifndef V8DOMWindowShell_h
32 #define V8DOMWindowShell_h
34 #include "WrapperTypeInfo.h"
35 #include <wtf/Forward.h>
36 #include <wtf/HashMap.h>
37 #include <wtf/PassRefPtr.h>
38 #include <wtf/RefCounted.h>
39 #include <wtf/RefPtr.h>
40 #include <wtf/text/AtomicString.h>
48 // V8WindowShell represents all the per-global object state for a Frame that
49 // persist between navigations.
50 class V8DOMWindowShell : public RefCounted<V8DOMWindowShell> {
52 static PassRefPtr<V8DOMWindowShell> create(Frame*);
54 v8::Handle<v8::Context> context() const { return m_context; }
56 // Update document object of the frame.
57 void updateDocument();
59 void namedItemAdded(HTMLDocument*, const AtomicString&);
60 void namedItemRemoved(HTMLDocument*, const AtomicString&);
62 // Update the security origin of a document
63 // (e.g., after setting docoument.domain).
64 void updateSecurityOrigin();
66 bool isContextInitialized();
68 v8::Persistent<v8::Context> createNewContext(v8::Handle<v8::Object> global, int extensionGroup);
69 void setContext(v8::Handle<v8::Context>);
70 static bool installDOMWindow(v8::Handle<v8::Context> context, DOMWindow*);
72 bool initContextIfNeeded();
73 void updateDocumentWrapper(v8::Handle<v8::Object> wrapper);
75 void clearForNavigation();
80 static v8::Handle<v8::Value> getHiddenObjectPrototype(v8::Handle<v8::Context>);
81 // WARNING: Call |installHiddenObjectPrototype| only on fresh contexts!
82 static bool installHiddenObjectPrototype(v8::Handle<v8::Context>);
84 // To create JS Wrapper objects, we create a cache of a 'boiler plate'
85 // object, and then simply Clone that object each time we need a new one.
86 // This is faster than going through the full object creation process.
87 v8::Local<v8::Object> createWrapperFromCache(WrapperTypeInfo* type)
89 v8::Persistent<v8::Object> boilerplate = m_wrapperBoilerplates.get(type);
90 return boilerplate.IsEmpty() ? createWrapperFromCacheSlowCase(type) : boilerplate->Clone();
93 static void setLocation(DOMWindow*, const String& relativeURL);
96 V8DOMWindowShell(Frame*);
98 void disposeContextHandles();
100 void setSecurityToken();
101 void clearDocumentWrapper();
103 // The JavaScript wrapper for the document object is cached on the global
104 // object for fast access. UpdateDocumentWrapperCache sets the wrapper
105 // for the current document on the global object. ClearDocumentWrapperCache
106 // deletes the document wrapper from the global object.
107 void updateDocumentWrapperCache();
108 void clearDocumentWrapperCache();
110 v8::Local<v8::Object> createWrapperFromCacheSlowCase(WrapperTypeInfo*);
114 // For each possible type of wrapper, we keep a boilerplate object.
115 // The boilerplate is used to create additional wrappers of the same type.
116 typedef WTF::HashMap<WrapperTypeInfo*, v8::Persistent<v8::Object> > WrapperBoilerplateMap;
117 WrapperBoilerplateMap m_wrapperBoilerplates;
119 v8::Persistent<v8::Context> m_context;
120 v8::Persistent<v8::Object> m_global;
121 v8::Persistent<v8::Object> m_document;
124 } // namespace WebCore
126 #endif // V8DOMWindowShell_h