initial import
[vuplus_webkit] / Source / WebKit / chromium / src / InspectorFrontendClientImpl.cpp
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 #include "config.h"
32 #include "InspectorFrontendClientImpl.h"
33
34 #include "Document.h"
35 #include "Frame.h"
36 #include "InspectorFrontendHost.h"
37 #include "Page.h"
38 #include "PlatformString.h"
39 #include "V8InspectorFrontendHost.h"
40 #include "V8Proxy.h"
41 #include "WebDevToolsFrontendClient.h"
42 #include "WebDevToolsFrontendImpl.h"
43 #include "WebString.h"
44
45 using namespace WebCore;
46
47 namespace WebKit {
48
49 InspectorFrontendClientImpl::InspectorFrontendClientImpl(Page* frontendPage, WebDevToolsFrontendClient* client, WebDevToolsFrontendImpl* frontend)
50     : m_frontendPage(frontendPage)
51     , m_client(client)
52     , m_frontend(frontend)
53 {
54 }
55
56 InspectorFrontendClientImpl::~InspectorFrontendClientImpl()
57 {
58     if (m_frontendHost)
59         m_frontendHost->disconnectClient();
60     m_client = 0;
61 }
62
63 void InspectorFrontendClientImpl::windowObjectCleared()
64 {
65     v8::HandleScope handleScope;
66     v8::Handle<v8::Context> frameContext = V8Proxy::context(m_frontendPage->mainFrame());
67     v8::Context::Scope contextScope(frameContext);
68
69     ASSERT(!m_frontendHost);
70     m_frontendHost = InspectorFrontendHost::create(this, m_frontendPage);
71     v8::Handle<v8::Value> frontendHostObj = toV8(m_frontendHost.get());
72     v8::Handle<v8::Object> global = frameContext->Global();
73
74     global->Set(v8::String::New("InspectorFrontendHost"), frontendHostObj);
75 }
76
77 void InspectorFrontendClientImpl::frontendLoaded()
78 {
79     m_frontend->frontendLoaded();
80 }
81
82 void InspectorFrontendClientImpl::moveWindowBy(float x, float y)
83 {
84 }
85
86 String InspectorFrontendClientImpl::localizedStringsURL()
87 {
88     return "";
89 }
90
91 String InspectorFrontendClientImpl::hiddenPanels()
92 {
93     if (m_client->shouldHideScriptsPanel())
94         return "scripts";
95     return "";
96 }
97
98 void InspectorFrontendClientImpl::bringToFront()
99 {
100     m_client->activateWindow();
101 }
102
103 void InspectorFrontendClientImpl::closeWindow()
104 {
105     m_client->closeWindow();
106 }
107
108 void InspectorFrontendClientImpl::disconnectFromBackend()
109 {
110     m_client->closeWindow();
111 }
112
113 void InspectorFrontendClientImpl::requestAttachWindow()
114 {
115     m_client->requestDockWindow();
116 }
117
118 void InspectorFrontendClientImpl::requestDetachWindow()
119 {
120     m_client->requestUndockWindow();
121 }
122
123 void InspectorFrontendClientImpl::changeAttachedWindowHeight(unsigned)
124 {
125     // Do nothing;
126 }
127
128 void InspectorFrontendClientImpl::saveAs(const String& fileName, const String& content)
129 {
130     m_client->saveAs(fileName, content);
131 }
132
133 void InspectorFrontendClientImpl::inspectedURLChanged(const String& url)
134 {
135     m_frontendPage->mainFrame()->document()->setTitle("Developer Tools - " + url);
136 }
137
138 void InspectorFrontendClientImpl::sendMessageToBackend(const String& message)
139 {
140     m_client->sendMessageToBackend(message);
141 }
142
143 } // namespace WebKit