Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: third_party/WebKit/WebCore/bindings/js/JSInspectorControllerCustom.cpp

Issue 39293: WebKit merge 41447:41498 [third_party/WebKit] (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: remove CRLF Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
4 * Copyright (C) 2009 Google Inc. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include "config.h"
34 #include "JSInspectorController.h"
35
36 #include "Console.h"
37 #if ENABLE(DATABASE)
38 #include "Database.h"
39 #include "JSDatabase.h"
40 #endif
41 #include "ExceptionCode.h"
42 #include "Frame.h"
43 #include "FrameLoader.h"
44 #include "InspectorController.h"
45 #include "InspectorResource.h"
46 #include "JavaScriptProfile.h"
47 #include "JSDOMWindow.h"
48 #include "JSInspectedObjectWrapper.h"
49 #include "JSInspectorCallbackWrapper.h"
50 #include "JSNode.h"
51 #include "JSRange.h"
52 #include "Node.h"
53 #include "Page.h"
54 #include "TextIterator.h"
55 #include "VisiblePosition.h"
56 #include <profiler/Profile.h>
57 #include <profiler/Profiler.h>
58 #include <runtime/JSArray.h>
59 #include <runtime/JSLock.h>
60 #include <wtf/Vector.h>
61
62 #if ENABLE(JAVASCRIPT_DEBUGGER)
63 #include "JavaScriptCallFrame.h"
64 #include "JavaScriptDebugServer.h"
65 #include "JSJavaScriptCallFrame.h"
66 #endif
67
68 using namespace JSC;
69
70 namespace WebCore {
71
72 JSValuePtr JSInspectorController::profiles(JSC::ExecState* exec, const JSC::ArgL ist&)
73 {
74 JSLock lock(false);
75 ArgList result;
76 const Vector<RefPtr<Profile> >& profiles = impl()->profiles();
77
78 for (size_t i = 0; i < profiles.size(); ++i)
79 result.append(toJS(exec, profiles[i].get()));
80
81 return constructArray(exec, result);
82 }
83
84 JSValuePtr JSInspectorController::highlightDOMNode(JSC::ExecState* exec, const J SC::ArgList& args)
85 {
86 if (args.size() < 1)
87 return jsUndefined();
88
89 JSQuarantinedObjectWrapper* wrapper = JSQuarantinedObjectWrapper::asWrapper( args.at(exec, 0));
90 if (!wrapper)
91 return jsUndefined();
92
93 Node* node = toNode(wrapper->unwrappedObject());
94 if (!node)
95 return jsUndefined();
96
97 impl()->highlight(node);
98
99 return jsUndefined();
100 }
101
102 JSValuePtr JSInspectorController::addResourceSourceToFrame(ExecState* exec, cons t ArgList& args)
103 {
104 if (args.size() < 2)
105 return jsUndefined();
106
107 bool ok = false;
108 unsigned identifier = args.at(exec, 0).toUInt32(exec, ok);
109 if (!ok)
110 return jsUndefined();
111
112 RefPtr<InspectorResource> resource = impl()->resources().get(identifier);
113 ASSERT(resource);
114 if (!resource)
115 return jsUndefined();
116
117 String sourceString = resource->sourceString();
118 if (sourceString.isEmpty())
119 return jsUndefined();
120
121 return jsBoolean(impl()->addSourceToFrame(resource->mimeType, sourceString, toNode(args.at(exec, 1))));
122 }
123
124 JSValuePtr JSInspectorController::addSourceToFrame(ExecState* exec, const ArgLis t& args)
125 {
126 if (args.size() < 3)
127 return jsUndefined();
128
129 String mimeType = args.at(exec, 0).toString(exec);
130 if (exec->hadException())
131 return jsUndefined();
132
133 String sourceString = args.at(exec, 1).toString(exec);
134 if (exec->hadException())
135 return jsUndefined();
136
137 return jsBoolean(impl()->addSourceToFrame(mimeType, sourceString, toNode(arg s.at(exec, 1))));
138 }
139
140 JSValuePtr JSInspectorController::getResourceDocumentNode(ExecState* exec, const ArgList& args)
141 {
142 if (args.size() < 1)
143 return jsUndefined();
144
145 bool ok = false;
146 unsigned identifier = args.at(exec, 0).toUInt32(exec, ok);
147 if (!ok)
148 return jsUndefined();
149
150 RefPtr<InspectorResource> resource = impl()->resources().get(identifier);
151 ASSERT(resource);
152 if (!resource)
153 return jsUndefined();
154
155 Frame* frame = resource->frame.get();
156 Document* document = frame->document();
157
158 if (document->isPluginDocument() || document->isImageDocument() || document- >isMediaDocument())
159 return jsUndefined();
160
161 // FIXME: I am not sure if this is actually needed. Can we just use exec?
162 ExecState* resourceExec = toJSDOMWindowShell(resource->frame.get())->window( )->globalExec();
163
164 JSLock lock(false);
165 return JSInspectedObjectWrapper::wrap(resourceExec, toJS(resourceExec, docum ent));
166 }
167
168 JSValuePtr JSInspectorController::search(ExecState* exec, const ArgList& args)
169 {
170 if (args.size() < 2)
171 return jsUndefined();
172
173 Node* node = toNode(args.at(exec, 0));
174 if (!node)
175 return jsUndefined();
176
177 String target = args.at(exec, 1).toString(exec);
178 if (exec->hadException())
179 return jsUndefined();
180
181 ArgList result;
182 RefPtr<Range> searchRange(rangeOfContents(node));
183
184 ExceptionCode ec = 0;
185 do {
186 RefPtr<Range> resultRange(findPlainText(searchRange.get(), target, true, false));
187 if (resultRange->collapsed(ec))
188 break;
189
190 // A non-collapsed result range can in some funky whitespace cases still not
191 // advance the range's start position (4509328). Break to avoid infinite loop.
192 VisiblePosition newStart = endVisiblePosition(resultRange.get(), DOWNSTR EAM);
193 if (newStart == startVisiblePosition(searchRange.get(), DOWNSTREAM))
194 break;
195
196 result.append(toJS(exec, resultRange.get()));
197
198 setStart(searchRange.get(), newStart);
199 } while (true);
200
201 return constructArray(exec, result);
202 }
203
204 #if ENABLE(DATABASE)
205 JSValuePtr JSInspectorController::databaseTableNames(ExecState* exec, const ArgL ist& args)
206 {
207 if (args.size() < 1)
208 return jsUndefined();
209
210 JSQuarantinedObjectWrapper* wrapper = JSQuarantinedObjectWrapper::asWrapper( args.at(exec, 0));
211 if (!wrapper)
212 return jsUndefined();
213
214 Database* database = toDatabase(wrapper->unwrappedObject());
215 if (!database)
216 return jsUndefined();
217
218 ArgList result;
219
220 Vector<String> tableNames = database->tableNames();
221 unsigned length = tableNames.size();
222 for (unsigned i = 0; i < length; ++i)
223 result.append(jsString(exec, tableNames[i]));
224
225 return constructArray(exec, result);
226 }
227 #endif
228
229 JSValuePtr JSInspectorController::inspectedWindow(ExecState*, const ArgList&)
230 {
231 JSDOMWindow* inspectedWindow = toJSDOMWindow(impl()->inspectedPage()->mainFr ame());
232 return JSInspectedObjectWrapper::wrap(inspectedWindow->globalExec(), inspect edWindow);
233 }
234
235 JSValuePtr JSInspectorController::setting(ExecState* exec, const ArgList& args)
236 {
237 if (args.size() < 1)
238 return jsUndefined();
239
240 String key = args.at(exec, 0).toString(exec);
241 if (exec->hadException())
242 return jsUndefined();
243
244 const InspectorController::Setting& setting = impl()->setting(key);
245
246 switch (setting.type()) {
247 default:
248 case InspectorController::Setting::NoType:
249 return jsUndefined();
250 case InspectorController::Setting::StringType:
251 return jsString(exec, setting.string());
252 case InspectorController::Setting::DoubleType:
253 return jsNumber(exec, setting.doubleValue());
254 case InspectorController::Setting::IntegerType:
255 return jsNumber(exec, setting.integerValue());
256 case InspectorController::Setting::BooleanType:
257 return jsBoolean(setting.booleanValue());
258 case InspectorController::Setting::StringVectorType: {
259 ArgList stringsArray;
260 const Vector<String>& strings = setting.stringVector();
261 const unsigned length = strings.size();
262 for (unsigned i = 0; i < length; ++i)
263 stringsArray.append(jsString(exec, strings[i]));
264 return constructArray(exec, stringsArray);
265 }
266 }
267 }
268
269 JSValuePtr JSInspectorController::setSetting(ExecState* exec, const ArgList& arg s)
270 {
271 if (args.size() < 2)
272 return jsUndefined();
273
274 String key = args.at(exec, 0).toString(exec);
275 if (exec->hadException())
276 return jsUndefined();
277
278 InspectorController::Setting setting;
279
280 JSValuePtr value = args.at(exec, 0);
281 if (value.isUndefined() || value.isNull()) {
282 // Do nothing. The setting is already NoType.
283 ASSERT(setting.type() == InspectorController::Setting::NoType);
284 } else if (value.isString())
285 setting.set(value.toString(exec));
286 else if (value.isNumber())
287 setting.set(value.toNumber(exec));
288 else if (value.isBoolean())
289 setting.set(value.toBoolean(exec));
290 else {
291 JSArray* jsArray = asArray(value);
292 if (!jsArray)
293 return jsUndefined();
294 Vector<String> strings;
295 for (unsigned i = 0; i < jsArray->length(); ++i) {
296 String item = jsArray->get(exec, i).toString(exec);
297 if (exec->hadException())
298 return jsUndefined();
299 strings.append(item);
300 }
301 setting.set(strings);
302 }
303
304 if (exec->hadException())
305 return jsUndefined();
306
307 impl()->setSetting(key, setting);
308
309 return jsUndefined();
310 }
311
312 JSValuePtr JSInspectorController::wrapCallback(ExecState* exec, const ArgList& a rgs)
313 {
314 if (args.size() < 1)
315 return jsUndefined();
316
317 return JSInspectorCallbackWrapper::wrap(exec, args.at(exec, 0));
318 }
319
320 JSValuePtr JSInspectorController::currentCallFrame(ExecState* exec, const ArgLis t&)
321 {
322 JavaScriptCallFrame* callFrame = impl()->currentCallFrame();
323 if (!callFrame || !callFrame->isValid())
324 return jsUndefined();
325
326 // FIXME: I am not sure if this is actually needed. Can we just use exec?
327 ExecState* globalExec = callFrame->scopeChain()->globalObject()->globalExec( );
328
329 JSLock lock(false);
330 return JSInspectedObjectWrapper::wrap(globalExec, toJS(exec, callFrame));
331 }
332
333 } // namespace WebCore
OLDNEW
« no previous file with comments | « third_party/WebKit/WebCore/WebCoreSources.bkl ('k') | third_party/WebKit/WebCore/bindings/js/ScriptController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698