~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit/chromium/src/WebDevToolsFrontendImpl.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "WebDevToolsFrontendImpl.h"
 
33
 
 
34
#include "ContextMenuController.h"
 
35
#include "ContextMenuItem.h"
 
36
#include "DOMWindow.h"
 
37
#include "Document.h"
 
38
#include "Event.h"
 
39
#include "Frame.h"
 
40
#include "InspectorController.h"
 
41
#include "InspectorFrontendClientImpl.h"
 
42
#include "InspectorFrontendHost.h"
 
43
#include "Node.h"
 
44
#include "Page.h"
 
45
#include "Pasteboard.h"
 
46
#include "ScriptController.h"
 
47
#include "SecurityOrigin.h"
 
48
#include "Settings.h"
 
49
#include "V8Binding.h"
 
50
#include "V8DOMWrapper.h"
 
51
#include "V8InspectorFrontendHost.h"
 
52
#include "V8MouseEvent.h"
 
53
#include "V8Node.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>
 
62
 
 
63
using namespace WebCore;
 
64
 
 
65
namespace WebKit {
 
66
 
 
67
static v8::Local<v8::String> ToV8String(const String& s)
 
68
{
 
69
    if (s.isNull())
 
70
        return v8::Local<v8::String>();
 
71
 
 
72
    return v8::String::New(reinterpret_cast<const uint16_t*>(s.characters()), s.length());
 
73
}
 
74
 
 
75
WebDevToolsFrontend* WebDevToolsFrontend::create(
 
76
    WebView* view,
 
77
    WebDevToolsFrontendClient* client,
 
78
    const WebString& applicationLocale)
 
79
{
 
80
    return new WebDevToolsFrontendImpl(
 
81
      static_cast<WebViewImpl*>(view),
 
82
      client,
 
83
      applicationLocale);
 
84
}
 
85
 
 
86
WebDevToolsFrontendImpl::WebDevToolsFrontendImpl(
 
87
    WebViewImpl* webViewImpl,
 
88
    WebDevToolsFrontendClient* client,
 
89
    const String& applicationLocale)
 
90
    : m_webViewImpl(webViewImpl)
 
91
    , m_client(client)
 
92
    , m_applicationLocale(applicationLocale)
 
93
{
 
94
    InspectorController* ic = m_webViewImpl->page()->inspectorController();
 
95
    ic->setInspectorFrontendClient(adoptPtr(new InspectorFrontendClientImpl(m_webViewImpl->page(), m_client, this)));
 
96
 
 
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());
 
100
}
 
101
 
 
102
WebDevToolsFrontendImpl::~WebDevToolsFrontendImpl()
 
103
{
 
104
}
 
105
 
 
106
void WebDevToolsFrontendImpl::dispatchOnInspectorFrontend(const WebString& message)
 
107
{
 
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())
 
114
        return;
 
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())
 
119
        return;
 
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());
 
126
}
 
127
 
 
128
} // namespace WebKit