| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "web/WebDevToolsFrontendImpl.h" | 32 #include "web/WebDevToolsFrontendImpl.h" |
| 33 | 33 |
| 34 #include "bindings/core/v8/ScriptController.h" | 34 #include "bindings/core/v8/ScriptController.h" |
| 35 #include "bindings/core/v8/V8DevToolsHost.h" | 35 #include "bindings/core/v8/V8DevToolsHost.h" |
| 36 #include "core/frame/LocalFrame.h" | 36 #include "core/frame/LocalFrame.h" |
| 37 #include "core/inspector/DevToolsHost.h" | 37 #include "core/inspector/DevToolsHost.h" |
| 38 #include "core/inspector/InspectorController.h" | |
| 39 #include "core/page/Page.h" | |
| 40 #include "public/platform/WebString.h" | 38 #include "public/platform/WebString.h" |
| 41 #include "public/web/WebDevToolsFrontendClient.h" | 39 #include "public/web/WebDevToolsFrontendClient.h" |
| 40 #include "public/web/WebSecurityOrigin.h" |
| 41 #include "web/WebLocalFrameImpl.h" |
| 42 #include "web/WebViewImpl.h" | 42 #include "web/WebViewImpl.h" |
| 43 | 43 |
| 44 namespace blink { | 44 namespace blink { |
| 45 | 45 |
| 46 WebDevToolsFrontend* WebDevToolsFrontend::create( | 46 WebDevToolsFrontend* WebDevToolsFrontend::create( |
| 47 WebView* view, | 47 WebLocalFrame* frame, |
| 48 WebDevToolsFrontendClient* client, | 48 WebDevToolsFrontendClient* client, |
| 49 const WebString& applicationLocale) | 49 const WebString& applicationLocale) |
| 50 { | 50 { |
| 51 return new WebDevToolsFrontendImpl(toWebViewImpl(view), client); | 51 return new WebDevToolsFrontendImpl(toWebLocalFrameImpl(frame), client); |
| 52 } | 52 } |
| 53 | 53 |
| 54 WebDevToolsFrontendImpl::WebDevToolsFrontendImpl( | 54 WebDevToolsFrontendImpl::WebDevToolsFrontendImpl( |
| 55 WebViewImpl* webViewImpl, | 55 WebLocalFrameImpl* webFrame, |
| 56 WebDevToolsFrontendClient* client) | 56 WebDevToolsFrontendClient* client) |
| 57 : m_webViewImpl(webViewImpl) | 57 : m_webFrame(webFrame) |
| 58 , m_client(client) | 58 , m_client(client) |
| 59 { | 59 { |
| 60 m_webViewImpl->page()->inspectorController().setInspectorFrontendClient(this
); | 60 m_webFrame->setDevToolsFrontend(this); |
| 61 } | 61 } |
| 62 | 62 |
| 63 WebDevToolsFrontendImpl::~WebDevToolsFrontendImpl() | 63 WebDevToolsFrontendImpl::~WebDevToolsFrontendImpl() |
| 64 { | 64 { |
| 65 ASSERT(!m_devtoolsHost); | 65 ASSERT(!m_devtoolsHost); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void WebDevToolsFrontendImpl::dispose() | 68 void WebDevToolsFrontendImpl::didClearWindowObject(WebLocalFrameImpl* frame) |
| 69 { | 69 { |
| 70 if (m_devtoolsHost) { | 70 if (m_webFrame == frame) { |
| 71 m_devtoolsHost->disconnectClient(); | 71 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 72 m_devtoolsHost = nullptr; | 72 ScriptState* scriptState = ScriptState::forMainWorld(m_webFrame->frame()
); |
| 73 ScriptState::Scope scope(scriptState); |
| 74 |
| 75 if (m_devtoolsHost) |
| 76 m_devtoolsHost->disconnectClient(); |
| 77 m_devtoolsHost = DevToolsHost::create(this, m_webFrame->frame()); |
| 78 v8::Handle<v8::Object> global = scriptState->context()->Global(); |
| 79 v8::Handle<v8::Value> devtoolsHostObj = toV8(m_devtoolsHost.get(), globa
l, scriptState->isolate()); |
| 80 global->Set(v8::String::NewFromUtf8(isolate, "DevToolsHost"), devtoolsHo
stObj); |
| 73 } | 81 } |
| 74 m_client = 0; | |
| 75 } | |
| 76 | 82 |
| 77 void WebDevToolsFrontendImpl::windowObjectCleared() | 83 if (m_injectedScriptForOrigin.isEmpty()) |
| 78 { | 84 return; |
| 79 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
| 80 Page* page = m_webViewImpl->page(); | |
| 81 ASSERT(page->mainFrame()); | |
| 82 ScriptState* scriptState = ScriptState::forMainWorld(page->deprecatedLocalMa
inFrame()); | |
| 83 ScriptState::Scope scope(scriptState); | |
| 84 | 85 |
| 85 if (m_devtoolsHost) | 86 String origin = frame->securityOrigin().toString(); |
| 86 m_devtoolsHost->disconnectClient(); | 87 String script = m_injectedScriptForOrigin.get(origin); |
| 87 m_devtoolsHost = DevToolsHost::create(this, page); | 88 if (!script.isEmpty()) |
| 88 v8::Handle<v8::Object> global = scriptState->context()->Global(); | 89 frame->frame()->script().executeScriptInMainWorld(script + "()"); |
| 89 v8::Handle<v8::Value> devtoolsHostObj = toV8(m_devtoolsHost.get(), global, s
criptState->isolate()); | |
| 90 global->Set(v8::String::NewFromUtf8(isolate, "DevToolsHost"), devtoolsHostOb
j); | |
| 91 } | 90 } |
| 92 | 91 |
| 93 void WebDevToolsFrontendImpl::sendMessageToBackend(const String& message) | 92 void WebDevToolsFrontendImpl::sendMessageToBackend(const String& message) |
| 94 { | 93 { |
| 95 if (m_client) | 94 if (m_client) |
| 96 m_client->sendMessageToBackend(message); | 95 m_client->sendMessageToBackend(message); |
| 97 } | 96 } |
| 98 | 97 |
| 99 void WebDevToolsFrontendImpl::sendMessageToEmbedder(const String& message) | 98 void WebDevToolsFrontendImpl::sendMessageToEmbedder(const String& message) |
| 100 { | 99 { |
| 101 if (m_client) | 100 if (m_client) |
| 102 m_client->sendMessageToEmbedder(message); | 101 m_client->sendMessageToEmbedder(message); |
| 103 } | 102 } |
| 104 | 103 |
| 105 bool WebDevToolsFrontendImpl::isUnderTest() | 104 bool WebDevToolsFrontendImpl::isUnderTest() |
| 106 { | 105 { |
| 107 return m_client ? m_client->isUnderTest() : false; | 106 return m_client ? m_client->isUnderTest() : false; |
| 108 } | 107 } |
| 109 | 108 |
| 109 void WebDevToolsFrontendImpl::showContextMenu(float x, float y, PassRefPtrWillBe
RawPtr<ContextMenuProvider> menuProvider) |
| 110 { |
| 111 m_webFrame->viewImpl()->showContextMenuAtPoint(x, y, menuProvider); |
| 112 } |
| 113 |
| 114 void WebDevToolsFrontendImpl::setInjectedScriptForOrigin(const String& origin, c
onst String& source) |
| 115 { |
| 116 m_injectedScriptForOrigin.set(origin, source); |
| 117 } |
| 118 |
| 110 } // namespace blink | 119 } // namespace blink |
| OLD | NEW |