• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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 #ifndef WebDevToolsAgentImpl_h
32 #define WebDevToolsAgentImpl_h
33 
34 #include "APUAgentDelegate.h"
35 #include "DevToolsRPC.h"
36 #include "ToolsAgent.h"
37 #include "WebDevToolsAgentPrivate.h"
38 
39 #include <v8.h>
40 #include <wtf/OwnPtr.h>
41 
42 namespace WebCore {
43 class Document;
44 class InspectorController;
45 class Node;
46 class String;
47 }
48 
49 namespace WebKit {
50 
51 class DebuggerAgentDelegateStub;
52 class DebuggerAgentImpl;
53 class WebDevToolsAgentClient;
54 class WebFrame;
55 class WebFrameImpl;
56 class WebString;
57 class WebURLRequest;
58 class WebURLResponse;
59 class WebViewImpl;
60 struct WebURLError;
61 struct WebDevToolsMessageData;
62 
63 class WebDevToolsAgentImpl : public WebDevToolsAgentPrivate,
64                              public ToolsAgent,
65                              public DevToolsRPC::Delegate {
66 public:
67     WebDevToolsAgentImpl(WebViewImpl* webViewImpl, WebDevToolsAgentClient* client);
68     virtual ~WebDevToolsAgentImpl();
69 
70     // ToolsAgent implementation.
71     virtual void dispatchOnInspectorController(int callId, const WebCore::String& functionName, const WebCore::String& jsonArgs);
72     virtual void dispatchOnInjectedScript(int callId, int injectedScriptId, const WebCore::String& functionName, const WebCore::String& jsonArgs, bool async);
73 
74     // WebDevToolsAgentPrivate implementation.
75     virtual void didClearWindowObject(WebFrameImpl* frame);
76     virtual void didCommitProvisionalLoad(WebFrameImpl* frame, bool isNewNavigation);
77 
78     // WebDevToolsAgent implementation.
79     virtual void attach();
80     virtual void detach();
81     virtual void didNavigate();
82     virtual void dispatchMessageFromFrontend(const WebDevToolsMessageData& data);
83     virtual void inspectElementAt(const WebPoint& point);
84     virtual void evaluateInWebInspector(long callId, const WebString& script);
85     virtual void setRuntimeFeatureEnabled(const WebString& feature, bool enabled);
86     virtual void setTimelineProfilingEnabled(bool enable);
87 
88     virtual void identifierForInitialRequest(unsigned long, WebFrame*, const WebURLRequest&);
89     virtual void willSendRequest(unsigned long, const WebURLRequest&);
90     virtual void didReceiveData(unsigned long, int length);
91     virtual void didReceiveResponse(unsigned long, const WebURLResponse&);
92     virtual void didFinishLoading(unsigned long);
93     virtual void didFailLoading(unsigned long, const WebURLError&);
94 
95     // DevToolsRPC::Delegate implementation.
96     virtual void sendRpcMessage(const WebDevToolsMessageData& data);
97 
98     void forceRepaint();
99 
hostId()100     int hostId() { return m_hostId; }
101 
102 private:
103     static v8::Handle<v8::Value> jsDispatchOnClient(const v8::Arguments& args);
104     static v8::Handle<v8::Value> jsDispatchToApu(const v8::Arguments& args);
105     static v8::Handle<v8::Value> jsEvaluateOnSelf(const v8::Arguments& args);
106     static v8::Handle<v8::Value> jsOnRuntimeFeatureStateChanged(const v8::Arguments& args);
107 
108     void disposeUtilityContext();
109     void unhideResourcesPanelIfNecessary();
110 
111     void compileUtilityScripts();
112     void initDevToolsAgentHost();
113     void resetInspectorFrontendProxy();
114     void setApuAgentEnabled(bool enabled);
115 
116     WebCore::InspectorController* inspectorController();
117 
118     // Creates InspectorBackend v8 wrapper in the utility context so that it's
119     // methods prototype is Function.protoype object from the utility context.
120     // Otherwise some useful methods  defined on Function.prototype(such as bind)
121     // are missing for InspectorController native methods.
122     v8::Local<v8::Object> createInspectorBackendV8Wrapper();
123 
124     int m_hostId;
125     WebDevToolsAgentClient* m_client;
126     WebViewImpl* m_webViewImpl;
127     OwnPtr<DebuggerAgentDelegateStub> m_debuggerAgentDelegateStub;
128     OwnPtr<ToolsAgentDelegateStub> m_toolsAgentDelegateStub;
129     OwnPtr<DebuggerAgentImpl> m_debuggerAgentImpl;
130     OwnPtr<ApuAgentDelegateStub> m_apuAgentDelegateStub;
131     bool m_apuAgentEnabled;
132     bool m_resourceTrackingWasEnabled;
133     bool m_attached;
134     // TODO(pfeldman): This should not be needed once GC styles issue is fixed
135     // for matching rules.
136     v8::Persistent<v8::Context> m_utilityContext;
137 };
138 
139 } // namespace WebKit
140 
141 #endif
142