OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include <wtf/HashSet.h> | 7 #include <wtf/HashSet.h> |
8 #include <wtf/RefPtr.h> | 8 #include <wtf/RefPtr.h> |
9 #include <wtf/Vector.h> | 9 #include <wtf/Vector.h> |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 void DebuggerAgentImpl::DebugBreak() { | 55 void DebuggerAgentImpl::DebugBreak() { |
56 DebuggerAgentManager::DebugBreak(this); | 56 DebuggerAgentManager::DebugBreak(this); |
57 } | 57 } |
58 | 58 |
59 void DebuggerAgentImpl::DebuggerOutput(const std::string& command) { | 59 void DebuggerAgentImpl::DebuggerOutput(const std::string& command) { |
60 delegate_->DebuggerOutput(command); | 60 delegate_->DebuggerOutput(command); |
61 webdevtools_agent_->ForceRepaint(); | 61 webdevtools_agent_->ForceRepaint(); |
62 } | 62 } |
63 | 63 |
64 void DebuggerAgentImpl::SetDocument(Document* document) { | 64 void DebuggerAgentImpl::CreateUtilityContext( |
| 65 Document* document, |
| 66 v8::Persistent<v8::Context>* context) { |
| 67 if (!context->IsEmpty()) { |
| 68 context->Dispose(); |
| 69 } |
65 v8::HandleScope scope; | 70 v8::HandleScope scope; |
66 | 71 |
67 if (!document) { | |
68 context_.Dispose(); | |
69 return; | |
70 } | |
71 | |
72 // TODO(pfeldman): Validate against Soeren. | 72 // TODO(pfeldman): Validate against Soeren. |
73 // Set up the DOM window as the prototype of the new global object. | 73 // Set up the DOM window as the prototype of the new global object. |
74 v8::Handle<v8::Context> window_context = | 74 v8::Handle<v8::Context> window_context = |
75 V8Proxy::GetContext(document->frame()); | 75 V8Proxy::GetContext(document->frame()); |
76 v8::Handle<v8::Object> window_global = window_context->Global(); | 76 v8::Handle<v8::Object> window_global = window_context->Global(); |
77 v8::Handle<v8::Value> window_wrapper = | 77 v8::Handle<v8::Value> window_wrapper = |
78 V8Proxy::LookupDOMWrapper(V8ClassIndex::DOMWINDOW, window_global); | 78 V8Proxy::LookupDOMWrapper(V8ClassIndex::DOMWINDOW, window_global); |
79 | 79 |
80 ASSERT(V8Proxy::DOMWrapperToNative<DOMWindow>(window_wrapper) == | 80 ASSERT(V8Proxy::DOMWrapperToNative<DOMWindow>(window_wrapper) == |
81 document->frame()->domWindow()); | 81 document->frame()->domWindow()); |
82 | 82 |
83 // Create a new environment using an empty template for the shadow | 83 // Create a new environment using an empty template for the shadow |
84 // object. Reuse the global object if one has been created earlier. | 84 // object. Reuse the global object if one has been created earlier. |
85 v8::Handle<v8::ObjectTemplate> global_template = | 85 v8::Handle<v8::ObjectTemplate> global_template = |
86 V8DOMWindow::GetShadowObjectTemplate(); | 86 V8DOMWindow::GetShadowObjectTemplate(); |
87 | 87 |
88 // Install a security handler with V8. | 88 // Install a security handler with V8. |
89 global_template->SetAccessCheckCallbacks( | 89 global_template->SetAccessCheckCallbacks( |
90 V8Custom::v8DOMWindowNamedSecurityCheck, | 90 V8Custom::v8DOMWindowNamedSecurityCheck, |
91 V8Custom::v8DOMWindowIndexedSecurityCheck, | 91 V8Custom::v8DOMWindowIndexedSecurityCheck, |
92 v8::Integer::New(V8ClassIndex::DOMWINDOW)); | 92 v8::Integer::New(V8ClassIndex::DOMWINDOW)); |
93 | 93 |
94 context_ = v8::Context::New( | 94 *context = v8::Context::New( |
95 NULL /* no extensions */, | 95 NULL /* no extensions */, |
96 global_template, | 96 global_template, |
97 v8::Handle<v8::Object>()); | 97 v8::Handle<v8::Object>()); |
98 v8::Context::Scope context_scope(context_); | 98 v8::Context::Scope context_scope(*context); |
99 v8::Handle<v8::Object> global = context_->Global(); | 99 v8::Handle<v8::Object> global = (*context)->Global(); |
100 | 100 |
101 v8::Handle<v8::String> implicit_proto_string = v8::String::New("__proto__"); | 101 v8::Handle<v8::String> implicit_proto_string = v8::String::New("__proto__"); |
102 global->Set(implicit_proto_string, window_wrapper); | 102 global->Set(implicit_proto_string, window_wrapper); |
103 | 103 |
104 // Give the code running in the new context a way to get access to the | 104 // Give the code running in the new context a way to get access to the |
105 // original context. | 105 // original context. |
106 global->Set(v8::String::New("contentWindow"), window_global); | 106 global->Set(v8::String::New("contentWindow"), window_global); |
107 | 107 |
108 // Inject javascript into the context. | 108 // Inject javascript into the context. |
109 StringPiece basejs = webkit_glue::GetDataResource(IDR_DEVTOOLS_BASE_JS); | 109 StringPiece basejs = webkit_glue::GetDataResource(IDR_DEVTOOLS_BASE_JS); |
110 v8::Script::Compile(v8::String::New(basejs.as_string().c_str()))->Run(); | 110 v8::Script::Compile(v8::String::New(basejs.as_string().c_str()))->Run(); |
111 StringPiece jsonjs = webkit_glue::GetDataResource(IDR_DEVTOOLS_JSON_JS); | 111 StringPiece jsonjs = webkit_glue::GetDataResource(IDR_DEVTOOLS_JSON_JS); |
112 v8::Script::Compile(v8::String::New(jsonjs.as_string().c_str()))->Run(); | 112 v8::Script::Compile(v8::String::New(jsonjs.as_string().c_str()))->Run(); |
113 StringPiece injectjs = webkit_glue::GetDataResource(IDR_DEVTOOLS_INJECT_JS); | 113 StringPiece injectjs = webkit_glue::GetDataResource(IDR_DEVTOOLS_INJECT_JS); |
114 v8::Script::Compile(v8::String::New(injectjs.as_string().c_str()))->Run(); | 114 v8::Script::Compile(v8::String::New(injectjs.as_string().c_str()))->Run(); |
115 StringPiece inject_dispatchjs = webkit_glue::GetDataResource( | 115 StringPiece inject_dispatchjs = webkit_glue::GetDataResource( |
116 IDR_DEVTOOLS_INJECT_DISPATCH_JS); | 116 IDR_DEVTOOLS_INJECT_DISPATCH_JS); |
117 v8::Script::Compile(v8::String::New( | 117 v8::Script::Compile(v8::String::New( |
118 inject_dispatchjs.as_string().c_str()))->Run(); | 118 inject_dispatchjs.as_string().c_str()))->Run(); |
119 } | 119 } |
120 | 120 |
121 String DebuggerAgentImpl::ExecuteUtilityFunction( | 121 String DebuggerAgentImpl::ExecuteUtilityFunction( |
| 122 v8::Handle<v8::Context> context, |
122 const String &function_name, | 123 const String &function_name, |
123 Node* node, | 124 Node* node, |
124 const String& json_args, | 125 const String& json_args, |
125 String* exception) { | 126 String* exception) { |
126 v8::HandleScope scope; | 127 v8::HandleScope scope; |
127 ASSERT(!context_.IsEmpty()); | 128 ASSERT(!context.IsEmpty()); |
128 v8::Context::Scope context_scope(context_); | 129 v8::Context::Scope context_scope(context); |
129 v8::Handle<v8::Function> function = v8::Local<v8::Function>::Cast( | 130 v8::Handle<v8::Function> function = v8::Local<v8::Function>::Cast( |
130 context_->Global()->Get(v8::String::New("devtools$$dispatch"))); | 131 context->Global()->Get(v8::String::New("devtools$$dispatch"))); |
131 | 132 |
132 v8::Handle<v8::Value> node_wrapper = | 133 v8::Handle<v8::Value> node_wrapper = |
133 V8Proxy::ToV8Object(V8ClassIndex::NODE, node); | 134 V8Proxy::ToV8Object(V8ClassIndex::NODE, node); |
134 v8::Handle<v8::String> function_name_wrapper = v8::Handle<v8::String>( | 135 v8::Handle<v8::String> function_name_wrapper = v8::Handle<v8::String>( |
135 v8::String::New(function_name.utf8().data())); | 136 v8::String::New(function_name.utf8().data())); |
136 v8::Handle<v8::String> json_args_wrapper = v8::Handle<v8::String>( | 137 v8::Handle<v8::String> json_args_wrapper = v8::Handle<v8::String>( |
137 v8::String::New(json_args.utf8().data())); | 138 v8::String::New(json_args.utf8().data())); |
138 v8::Handle<v8::Value> args[] = { | 139 v8::Handle<v8::Value> args[] = { |
139 function_name_wrapper, | 140 function_name_wrapper, |
140 node_wrapper, | 141 node_wrapper, |
141 json_args_wrapper | 142 json_args_wrapper |
142 }; | 143 }; |
143 | 144 |
144 v8::TryCatch try_catch; | 145 v8::TryCatch try_catch; |
145 v8::Handle<v8::Value> res_obj = function->Call(context_->Global(), 3, args); | 146 v8::Handle<v8::Value> res_obj = function->Call(context->Global(), 3, args); |
146 if (try_catch.HasCaught()) { | 147 if (try_catch.HasCaught()) { |
147 *exception = WebCore::ToWebCoreString(try_catch.Message()->Get()); | 148 *exception = WebCore::ToWebCoreString(try_catch.Message()->Get()); |
148 return ""; | 149 return ""; |
149 } else { | 150 } else { |
150 v8::Handle<v8::String> res_json = v8::Handle<v8::String>::Cast(res_obj); | 151 v8::Handle<v8::String> res_json = v8::Handle<v8::String>::Cast(res_obj); |
151 return WebCore::toWebCoreString(res_json); | 152 return WebCore::toWebCoreString(res_json); |
152 } | 153 } |
153 } | 154 } |
154 | 155 |
155 void DebuggerAgentImpl::RunWithDeferredMessages( | 156 void DebuggerAgentImpl::RunWithDeferredMessages( |
(...skipping 15 matching lines...) Expand all Loading... |
171 for (HashSet<DebuggerAgentImpl*>::const_iterator ag_it = agents.begin(); | 172 for (HashSet<DebuggerAgentImpl*>::const_iterator ag_it = agents.begin(); |
172 ag_it != agents.end(); ++ag_it) { | 173 ag_it != agents.end(); ++ag_it) { |
173 (*ag_it)->web_view()->SetIgnoreInputEvents(false); | 174 (*ag_it)->web_view()->SetIgnoreInputEvents(false); |
174 } | 175 } |
175 deleteAllValues(deferrers); | 176 deleteAllValues(deferrers); |
176 } | 177 } |
177 | 178 |
178 WebCore::Page* DebuggerAgentImpl::GetPage() { | 179 WebCore::Page* DebuggerAgentImpl::GetPage() { |
179 return web_view_impl_->page(); | 180 return web_view_impl_->page(); |
180 } | 181 } |
OLD | NEW |