1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
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
13 * distribution.
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.
17 *
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.
29 */
30
31 #include "config.h"
32 #include "ScriptObjectQuarantine.h"
33
34 #include "Database.h"
35 #include "Document.h"
36 #include "DOMWindow.h"
37 #include "Frame.h"
38 #include "Page.h"
39 #include "ScriptObject.h"
40 #include "ScriptValue.h"
41
42 #include "V8Binding.h"
43 #include "V8Proxy.h"
44
45 #include <v8.h>
46
47 namespace WebCore {
48
quarantineValue(ScriptState * scriptState,const ScriptValue & value)49 ScriptValue quarantineValue(ScriptState* scriptState, const ScriptValue& value)
50 {
51 return value;
52 }
53
getQuarantinedScriptObject(Database * database,ScriptObject & quarantinedObject)54 bool getQuarantinedScriptObject(Database* database, ScriptObject& quarantinedObject)
55 {
56 ASSERT(database);
57
58 // FIXME: Implement when Database V8 bindings are enabled
59 ASSERT_NOT_REACHED();
60 quarantinedObject = ScriptObject();
61 return false;
62 }
63
getQuarantinedScriptObject(Frame * frame,Storage * storage,ScriptObject & quarantinedObject)64 bool getQuarantinedScriptObject(Frame* frame, Storage* storage, ScriptObject& quarantinedObject)
65 {
66 ASSERT(frame);
67 ASSERT(storage);
68
69 #if ENABLE(DOM_STORAGE)
70 v8::HandleScope handleScope;
71 v8::Local<v8::Context> context = V8Proxy::context(frame);
72 // FIXME: What if context.IsEmpty()?
73 v8::Context::Scope scope(context);
74
75 v8::Handle<v8::Value> v8Storage = V8DOMWrapper::convertToV8Object(V8ClassIndex::STORAGE, storage);
76 quarantinedObject = ScriptObject(frame->script()->state(), v8::Local<v8::Object>(v8::Object::Cast(*v8Storage)));
77 #else
78 ASSERT_NOT_REACHED();
79 quarantinedObject = ScriptObject();
80 #endif
81 return true;
82 }
83
getQuarantinedScriptObject(Node * node,ScriptObject & quarantinedObject)84 bool getQuarantinedScriptObject(Node* node, ScriptObject& quarantinedObject)
85 {
86 ASSERT(node);
87
88 v8::HandleScope handleScope;
89 // FIXME: What if document() is null?
90 // FIXME: Why are we grabbing the mainFrame?
91 Frame* frame = node->document()->page()->mainFrame();
92 v8::Local<v8::Context> context = V8Proxy::context(frame);
93 // FIXME: What if context.IsEmpty()?
94 v8::Context::Scope scope(context);
95
96 v8::Handle<v8::Value> v8Node = V8DOMWrapper::convertNodeToV8Object(node);
97 quarantinedObject = ScriptObject(frame->script()->state(), v8::Local<v8::Object>(v8::Object::Cast(*v8Node)));
98
99 return true;
100 }
101
getQuarantinedScriptObject(DOMWindow * domWindow,ScriptObject & quarantinedObject)102 bool getQuarantinedScriptObject(DOMWindow* domWindow, ScriptObject& quarantinedObject)
103 {
104 ASSERT(domWindow);
105
106 v8::HandleScope handleScope;
107 Frame* frame = domWindow->frame();
108 // FIXME: What if frame is null?
109 v8::Local<v8::Context> context = V8Proxy::context(frame);
110 // FIXME: What if context.IsEmpty()?
111 v8::Context::Scope scope(context);
112
113 v8::Handle<v8::Value> v8DomWindow = V8DOMWrapper::convertToV8Object(V8ClassIndex::DOMWINDOW, domWindow);
114 quarantinedObject = ScriptObject(frame->script()->state(), v8::Local<v8::Object>(v8::Object::Cast(*v8DomWindow)));
115
116 return true;
117 }
118
119
120 } // namespace WebCore
121