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 V8WindowShell_h
32 #define V8WindowShell_h
34 #include "bindings/v8/DOMWrapperWorld.h"
35 #include "bindings/v8/ScopedPersistent.h"
36 #include "bindings/v8/V8PerContextData.h"
37 #include "bindings/v8/WrapperTypeInfo.h"
38 #include "gin/public/context_holder.h"
39 #include "platform/weborigin/SecurityOrigin.h"
40 #include "wtf/Forward.h"
41 #include "wtf/HashMap.h"
42 #include "wtf/PassRefPtr.h"
43 #include "wtf/RefCounted.h"
44 #include "wtf/RefPtr.h"
45 #include "wtf/text/AtomicString.h"
55 // V8WindowShell represents all the per-global object state for a Frame that
56 // persist between navigations.
59 static PassOwnPtr<V8WindowShell> create(Frame*, PassRefPtr<DOMWrapperWorld>, v8::Isolate*);
61 v8::Local<v8::Context> context() const { return m_contextHolder ? m_contextHolder->context() : v8::Local<v8::Context>(); }
63 // Update document object of the frame.
64 void updateDocument();
66 void namedItemAdded(HTMLDocument*, const AtomicString&);
67 void namedItemRemoved(HTMLDocument*, const AtomicString&);
69 // Update the security origin of a document
70 // (e.g., after setting docoument.domain).
71 void updateSecurityOrigin(SecurityOrigin*);
73 bool isContextInitialized() { return m_contextHolder; }
74 bool isGlobalInitialized() { return !m_global.isEmpty(); }
76 bool initializeIfNeeded();
77 void updateDocumentWrapper(v8::Handle<v8::Object> wrapper);
79 void clearForNavigation();
80 void clearForClose(bool destroyGlobal);
82 DOMWrapperWorld* world() { return m_world.get(); }
83 static bool contextHasCorrectPrototype(v8::Handle<v8::Context>);
86 V8WindowShell(Frame*, PassRefPtr<DOMWrapperWorld>, v8::Isolate*);
89 enum GlobalDetachmentBehavior {
93 void disposeContext(GlobalDetachmentBehavior);
95 void setSecurityToken(SecurityOrigin*);
97 // The JavaScript wrapper for the document object is cached on the global
98 // object for fast access. UpdateDocumentProperty sets the wrapper
99 // for the current document on the global object. ClearDocumentProperty
100 // deletes the document wrapper from the global object.
101 void updateDocumentProperty();
102 void clearDocumentProperty();
104 void createContext();
105 bool installDOMWindow();
107 static V8WindowShell* enteredIsolatedWorldContext();
110 RefPtr<DOMWrapperWorld> m_world;
111 v8::Isolate* m_isolate;
113 OwnPtr<V8PerContextData> m_perContextData;
115 OwnPtr<gin::ContextHolder> m_contextHolder;
116 ScopedPersistent<v8::Object> m_global;
117 ScopedPersistent<v8::Object> m_document;
120 } // namespace WebCore
122 #endif // V8WindowShell_h