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 "ContextMenuController.h"
35
#include "ContextMenuItem.h"
36
#include "DOMWindow.h"
40
#include "InspectorController.h"
41
#include "InspectorFrontendClientImpl.h"
42
#include "InspectorFrontendHost.h"
45
#include "Pasteboard.h"
46
#include "ScriptController.h"
47
#include "SecurityOrigin.h"
49
#include "V8Binding.h"
50
#include "V8DOMWrapper.h"
51
#include "V8InspectorFrontendHost.h"
52
#include "V8MouseEvent.h"
54
#include "V8Utilities.h"
55
#include "WebDevToolsFrontendClient.h"
56
#include "WebFrameImpl.h"
57
#include "WebScriptSource.h"
58
#include "WebViewImpl.h"
59
#include <wtf/OwnPtr.h>
60
#include <wtf/Vector.h>
61
#include <wtf/text/WTFString.h>
63
using namespace WebCore;
67
static v8::Local<v8::String> ToV8String(const String& s)
70
return v8::Local<v8::String>();
72
return v8::String::New(reinterpret_cast<const uint16_t*>(s.characters()), s.length());
75
WebDevToolsFrontend* WebDevToolsFrontend::create(
77
WebDevToolsFrontendClient* client,
78
const WebString& applicationLocale)
80
return new WebDevToolsFrontendImpl(
81
static_cast<WebViewImpl*>(view),
86
WebDevToolsFrontendImpl::WebDevToolsFrontendImpl(
87
WebViewImpl* webViewImpl,
88
WebDevToolsFrontendClient* client,
89
const String& applicationLocale)
90
: m_webViewImpl(webViewImpl)
92
, m_applicationLocale(applicationLocale)
94
InspectorController* ic = m_webViewImpl->page()->inspectorController();
95
ic->setInspectorFrontendClient(adoptPtr(new InspectorFrontendClientImpl(m_webViewImpl->page(), m_client, this)));
97
// Put each DevTools frontend Page into its own (single page) group so that it's not
98
// deferred along with the inspected page.
99
m_webViewImpl->page()->setGroupName(String());
102
WebDevToolsFrontendImpl::~WebDevToolsFrontendImpl()
106
void WebDevToolsFrontendImpl::dispatchOnInspectorFrontend(const WebString& message)
108
WebFrameImpl* frame = m_webViewImpl->mainFrameImpl();
109
v8::HandleScope scope;
110
v8::Handle<v8::Context> frameContext = frame->frame() ? frame->frame()->script()->currentWorldContext() : v8::Local<v8::Context>();
111
v8::Context::Scope contextScope(frameContext);
112
v8::Handle<v8::Value> inspectorFrontendApiValue = frameContext->Global()->Get(v8::String::New("InspectorFrontendAPI"));
113
if (!inspectorFrontendApiValue->IsObject())
115
v8::Handle<v8::Object> inspectorFrontendApi = v8::Handle<v8::Object>::Cast(inspectorFrontendApiValue);
116
v8::Handle<v8::Value> dispatchFunction = inspectorFrontendApi->Get(v8::String::New("dispatchMessage"));
117
// The frame might have navigated away from the front-end page (which is still weird).
118
if (!dispatchFunction->IsFunction())
120
v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(dispatchFunction);
121
Vector< v8::Handle<v8::Value> > args;
122
args.append(ToV8String(message));
123
v8::TryCatch tryCatch;
124
tryCatch.SetVerbose(true);
125
ScriptController::callFunctionWithInstrumentation(frame->frame() ? frame->frame()->document() : 0, function, inspectorFrontendApi, args.size(), args.data());
128
} // namespace WebKit