2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
32 #include "web/WebDevToolsFrontendImpl.h"
34 #include "bindings/core/v8/ScriptController.h"
35 #include "bindings/core/v8/V8DevToolsHost.h"
36 #include "core/frame/LocalFrame.h"
37 #include "core/inspector/DevToolsHost.h"
38 #include "public/platform/WebSecurityOrigin.h"
39 #include "public/platform/WebString.h"
40 #include "public/web/WebDevToolsFrontendClient.h"
41 #include "web/WebLocalFrameImpl.h"
42 #include "web/WebViewImpl.h"
46 WebDevToolsFrontend
* WebDevToolsFrontend::create(
48 WebDevToolsFrontendClient
* client
,
49 const WebString
& applicationLocale
)
51 return new WebDevToolsFrontendImpl(toWebLocalFrameImpl(view
->mainFrame()), client
);
54 WebDevToolsFrontend
* WebDevToolsFrontend::create(
56 WebDevToolsFrontendClient
* client
,
57 const WebString
& applicationLocale
)
59 return new WebDevToolsFrontendImpl(toWebLocalFrameImpl(frame
), client
);
62 WebDevToolsFrontendImpl::WebDevToolsFrontendImpl(
63 WebLocalFrameImpl
* webFrame
,
64 WebDevToolsFrontendClient
* client
)
65 : m_webFrame(webFrame
)
68 m_webFrame
->setDevToolsFrontend(this);
71 WebDevToolsFrontendImpl::~WebDevToolsFrontendImpl()
75 void WebDevToolsFrontendImpl::didClearWindowObject(WebLocalFrameImpl
* frame
)
77 if (m_webFrame
== frame
) {
78 v8::Isolate
* isolate
= v8::Isolate::GetCurrent();
79 ScriptState
* scriptState
= ScriptState::forMainWorld(m_webFrame
->frame());
80 ScriptState::Scope
scope(scriptState
);
83 m_devtoolsHost
->disconnectClient();
84 m_devtoolsHost
= DevToolsHost::create(this, m_webFrame
->frame());
85 v8::Local
<v8::Object
> global
= scriptState
->context()->Global();
86 v8::Local
<v8::Value
> devtoolsHostObj
= toV8(m_devtoolsHost
.get(), global
, scriptState
->isolate());
87 ASSERT(!devtoolsHostObj
.IsEmpty());
88 global
->Set(v8AtomicString(isolate
, "DevToolsHost"), devtoolsHostObj
);
91 if (m_injectedScriptForOrigin
.isEmpty())
94 String origin
= frame
->securityOrigin().toString();
95 String script
= m_injectedScriptForOrigin
.get(origin
);
98 static int s_lastScriptId
= 0;
99 StringBuilder scriptWithId
;
100 scriptWithId
.append(script
);
101 scriptWithId
.append('(');
102 scriptWithId
.appendNumber(++s_lastScriptId
);
103 scriptWithId
.append(')');
104 frame
->frame()->script().executeScriptInMainWorld(scriptWithId
.toString());
107 void WebDevToolsFrontendImpl::sendMessageToBackend(const String
& message
)
110 m_client
->sendMessageToBackend(message
);
113 void WebDevToolsFrontendImpl::sendMessageToEmbedder(const String
& message
)
116 m_client
->sendMessageToEmbedder(message
);
119 bool WebDevToolsFrontendImpl::isUnderTest()
121 return m_client
? m_client
->isUnderTest() : false;
124 void WebDevToolsFrontendImpl::showContextMenu(LocalFrame
* targetFrame
, float x
, float y
, PassRefPtrWillBeRawPtr
<ContextMenuProvider
> menuProvider
)
126 WebLocalFrameImpl::fromFrame(targetFrame
)->viewImpl()->showContextMenuAtPoint(x
, y
, menuProvider
);
129 void WebDevToolsFrontendImpl::setInjectedScriptForOrigin(const String
& origin
, const String
& source
)
131 m_injectedScriptForOrigin
.set(origin
, source
);