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 "WebDevToolsFrontendImpl.h"
34 #include "BoundObject.h"
35 #include "ContextMenuController.h"
36 #include "ContextMenuItem.h"
37 #include "DOMWindow.h"
41 #include "InspectorBackend.h"
42 #include "InspectorController.h"
43 #include "InspectorFrontendClientImpl.h"
44 #include "InspectorFrontendHost.h"
47 #include "Pasteboard.h"
48 #include "PlatformString.h"
49 #include "SecurityOrigin.h"
51 #include "V8Binding.h"
52 #include "V8DOMWrapper.h"
53 #include "V8InspectorFrontendHost.h"
54 #include "V8MouseEvent.h"
57 #include "V8Utilities.h"
58 #include "WebDevToolsFrontendClient.h"
59 #include "WebFrameImpl.h"
60 #include "WebScriptSource.h"
61 #include "WebViewImpl.h"
62 #include <wtf/OwnPtr.h>
63 #include <wtf/Vector.h>
65 using namespace WebCore;
69 static v8::Local<v8::String> ToV8String(const String& s)
72 return v8::Local<v8::String>();
74 return v8::String::New(reinterpret_cast<const uint16_t*>(s.characters()), s.length());
77 WebDevToolsFrontend* WebDevToolsFrontend::create(
79 WebDevToolsFrontendClient* client,
80 const WebString& applicationLocale)
82 return new WebDevToolsFrontendImpl(
83 static_cast<WebViewImpl*>(view),
88 WebDevToolsFrontendImpl::WebDevToolsFrontendImpl(
89 WebViewImpl* webViewImpl,
90 WebDevToolsFrontendClient* client,
91 const String& applicationLocale)
92 : m_webViewImpl(webViewImpl)
94 , m_applicationLocale(applicationLocale)
96 InspectorController* ic = m_webViewImpl->page()->inspectorController();
97 ic->setInspectorFrontendClient(new InspectorFrontendClientImpl(m_webViewImpl->page(), m_client, this));
99 // Put each DevTools frontend Page into its own (single page) group so that it's not
100 // deferred along with the inspected page.
101 m_webViewImpl->page()->setGroupName(String());
104 WebDevToolsFrontendImpl::~WebDevToolsFrontendImpl()
108 void WebDevToolsFrontendImpl::dispatchOnInspectorFrontend(const WebString& message)
110 WebFrameImpl* frame = m_webViewImpl->mainFrameImpl();
111 v8::HandleScope scope;
112 v8::Handle<v8::Context> frameContext = V8Proxy::context(frame->frame());
113 v8::Context::Scope contextScope(frameContext);
114 v8::Handle<v8::Value> dispatchFunction = frameContext->Global()->Get(v8::String::New("WebInspector_syncDispatch"));
115 // The frame might have navigated away from the front-end page (which is still weird).
116 if (!dispatchFunction->IsFunction())
118 v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(dispatchFunction);
119 Vector< v8::Handle<v8::Value> > args;
120 args.append(ToV8String(message));
121 v8::TryCatch tryCatch;
122 tryCatch.SetVerbose(true);
123 function->Call(frameContext->Global(), args.size(), args.data());
126 void WebDevToolsFrontendImpl::frontendLoaded()
128 m_client->sendFrontendLoaded();
131 } // namespace WebKit