OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | |
3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> | |
4 * Copyright (C) 2010 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 | |
8 * are met: | |
9 * | |
10 * 1. Redistributions of source code must retain the above copyright | |
11 * notice, this list of conditions and the following disclaimer. | |
12 * 2. Redistributions in binary form must reproduce the above copyright | |
13 * notice, this list of conditions and the following disclaimer in the | |
14 * documentation and/or other materials provided with the distribution. | |
15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
16 * its contributors may be used to endorse or promote products derived | |
17 * from this software without specific prior written permission. | |
18 * | |
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #include "core/inspector/InjectedScriptHost.h" | |
32 | |
33 #include "core/inspector/InspectorConsoleAgent.h" | |
34 #include "core/inspector/v8/V8Debugger.h" | |
35 #include "core/inspector/v8/V8DebuggerAgent.h" | |
36 #include "platform/JSONValues.h" | |
37 | |
38 #include "wtf/RefPtr.h" | |
39 #include "wtf/text/StringBuilder.h" | |
40 | |
41 namespace blink { | |
42 | |
43 PassRefPtr<InjectedScriptHost> InjectedScriptHost::create() | |
44 { | |
45 return adoptRef(new InjectedScriptHost()); | |
46 } | |
47 | |
48 InjectedScriptHost::InjectedScriptHost() | |
49 : m_debuggerAgent(nullptr) | |
50 , m_inspectCallback(nullptr) | |
51 , m_clearConsoleCallback(nullptr) | |
52 , m_debugger(nullptr) | |
53 { | |
54 m_defaultInspectableObject = adoptPtr(new InspectableObject()); | |
55 } | |
56 | |
57 InjectedScriptHost::~InjectedScriptHost() | |
58 { | |
59 } | |
60 | |
61 void InjectedScriptHost::disconnect() | |
62 { | |
63 m_debuggerAgent = nullptr; | |
64 m_inspectCallback = nullptr; | |
65 m_clearConsoleCallback = nullptr; | |
66 m_debugger = nullptr; | |
67 } | |
68 | |
69 void InjectedScriptHost::inspectImpl(PassRefPtr<JSONValue> object, PassRefPtr<JS
ONValue> hints) | |
70 { | |
71 if (m_inspectCallback) { | |
72 RefPtr<TypeBuilder::Runtime::RemoteObject> remoteObject = TypeBuilder::R
untime::RemoteObject::runtimeCast(object); | |
73 (*m_inspectCallback)(remoteObject, hints->asObject()); | |
74 } | |
75 } | |
76 | |
77 void InjectedScriptHost::clearConsoleMessages() | |
78 { | |
79 if (m_clearConsoleCallback) | |
80 (*m_clearConsoleCallback)(); | |
81 } | |
82 | |
83 v8::Local<v8::Value> InjectedScriptHost::InspectableObject::get(v8::Local<v8::Co
ntext>) | |
84 { | |
85 return v8::Local<v8::Value>(); | |
86 }; | |
87 | |
88 void InjectedScriptHost::addInspectedObject(PassOwnPtr<InjectedScriptHost::Inspe
ctableObject> object) | |
89 { | |
90 m_inspectedObjects.prepend(object); | |
91 while (m_inspectedObjects.size() > 5) | |
92 m_inspectedObjects.removeLast(); | |
93 } | |
94 | |
95 void InjectedScriptHost::clearInspectedObjects() | |
96 { | |
97 m_inspectedObjects.clear(); | |
98 } | |
99 | |
100 InjectedScriptHost::InspectableObject* InjectedScriptHost::inspectedObject(unsig
ned num) | |
101 { | |
102 if (num >= m_inspectedObjects.size()) | |
103 return m_defaultInspectableObject.get(); | |
104 return m_inspectedObjects[num].get(); | |
105 } | |
106 | |
107 void InjectedScriptHost::debugFunction(const String& scriptId, int lineNumber, i
nt columnNumber) | |
108 { | |
109 if (m_debuggerAgent) | |
110 m_debuggerAgent->setBreakpoint(scriptId, lineNumber, columnNumber, V8Deb
uggerAgent::DebugCommandBreakpointSource); | |
111 } | |
112 | |
113 void InjectedScriptHost::undebugFunction(const String& scriptId, int lineNumber,
int columnNumber) | |
114 { | |
115 if (m_debuggerAgent) | |
116 m_debuggerAgent->removeBreakpoint(scriptId, lineNumber, columnNumber, V8
DebuggerAgent::DebugCommandBreakpointSource); | |
117 } | |
118 | |
119 void InjectedScriptHost::monitorFunction(const String& scriptId, int lineNumber,
int columnNumber, const String& functionName) | |
120 { | |
121 StringBuilder builder; | |
122 builder.appendLiteral("console.log(\"function "); | |
123 if (functionName.isEmpty()) | |
124 builder.appendLiteral("(anonymous function)"); | |
125 else | |
126 builder.append(functionName); | |
127 builder.appendLiteral(" called\" + (arguments.length > 0 ? \" with arguments
: \" + Array.prototype.join.call(arguments, \", \") : \"\")) && false"); | |
128 if (m_debuggerAgent) | |
129 m_debuggerAgent->setBreakpoint(scriptId, lineNumber, columnNumber, V8Deb
uggerAgent::MonitorCommandBreakpointSource, builder.toString()); | |
130 } | |
131 | |
132 void InjectedScriptHost::unmonitorFunction(const String& scriptId, int lineNumbe
r, int columnNumber) | |
133 { | |
134 if (m_debuggerAgent) | |
135 m_debuggerAgent->removeBreakpoint(scriptId, lineNumber, columnNumber, V8
DebuggerAgent::MonitorCommandBreakpointSource); | |
136 } | |
137 | |
138 } // namespace blink | |
OLD | NEW |