2014-04-04 18:50:38 +02:00
|
|
|
// Copyright 2014 The Chromium Embedded Framework Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found
|
|
|
|
// in the LICENSE file.
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
#include "base/compiler_specific.h"
|
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
// Enable deprecation warnings on Windows. See http://crbug.com/585142.
|
2016-03-16 03:55:59 +01:00
|
|
|
#if defined(OS_WIN)
|
2018-10-02 14:14:11 +02:00
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic error "-Wdeprecated-declarations"
|
|
|
|
#else
|
2016-03-16 03:55:59 +01:00
|
|
|
#pragma warning(push)
|
2017-05-17 11:29:28 +02:00
|
|
|
#pragma warning(default : 4996)
|
2016-03-16 03:55:59 +01:00
|
|
|
#endif
|
2018-10-02 14:14:11 +02:00
|
|
|
#endif
|
2015-04-20 13:11:11 +02:00
|
|
|
|
2014-04-04 18:50:38 +02:00
|
|
|
#include "libcef/renderer/render_frame_observer.h"
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
#include "libcef/common/content_client.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "libcef/renderer/blink_glue.h"
|
2019-05-11 00:14:48 +02:00
|
|
|
#include "libcef/renderer/browser_impl.h"
|
2019-05-24 22:23:43 +02:00
|
|
|
#include "libcef/renderer/dom_document_impl.h"
|
2015-04-20 13:11:11 +02:00
|
|
|
#include "libcef/renderer/v8_impl.h"
|
2014-04-04 18:50:38 +02:00
|
|
|
|
|
|
|
#include "content/public/renderer/render_frame.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/web/blink.h"
|
2019-05-24 22:23:43 +02:00
|
|
|
#include "third_party/blink/public/web/web_document.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/web/web_local_frame.h"
|
2019-05-24 22:23:43 +02:00
|
|
|
#include "third_party/blink/public/web/web_node.h"
|
2014-04-04 18:50:38 +02:00
|
|
|
|
|
|
|
CefRenderFrameObserver::CefRenderFrameObserver(
|
|
|
|
content::RenderFrame* render_frame)
|
2017-05-17 11:29:28 +02:00
|
|
|
: content::RenderFrameObserver(render_frame) {}
|
2014-04-04 18:50:38 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRenderFrameObserver::~CefRenderFrameObserver() {}
|
2014-04-04 18:50:38 +02:00
|
|
|
|
2017-09-06 23:40:58 +02:00
|
|
|
void CefRenderFrameObserver::OnInterfaceRequestForFrame(
|
|
|
|
const std::string& interface_name,
|
|
|
|
mojo::ScopedMessagePipeHandle* interface_pipe) {
|
|
|
|
registry_.TryBindInterface(interface_name, interface_pipe);
|
|
|
|
}
|
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
void CefRenderFrameObserver::DidFinishLoad() {
|
2019-05-24 22:23:43 +02:00
|
|
|
if (frame_) {
|
|
|
|
frame_->OnDidFinishLoad();
|
|
|
|
}
|
2017-05-31 17:33:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderFrameObserver::FrameDetached() {
|
2019-05-24 22:23:43 +02:00
|
|
|
if (frame_) {
|
|
|
|
frame_->OnDetached();
|
|
|
|
frame_ = nullptr;
|
|
|
|
}
|
2017-05-31 17:33:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderFrameObserver::FrameFocused() {
|
2019-05-24 22:23:43 +02:00
|
|
|
if (frame_) {
|
|
|
|
frame_->OnFocused();
|
|
|
|
}
|
2017-05-31 17:33:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderFrameObserver::FocusedNodeChanged(const blink::WebNode& node) {
|
|
|
|
blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
|
|
|
|
CefRefPtr<CefBrowserImpl> browserPtr =
|
|
|
|
CefBrowserImpl::GetBrowserForMainFrame(frame->Top());
|
2019-05-24 22:23:43 +02:00
|
|
|
if (!browserPtr)
|
2017-05-31 17:33:30 +02:00
|
|
|
return;
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefRenderProcessHandler> handler;
|
|
|
|
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
|
|
|
if (application)
|
|
|
|
handler = application->GetRenderProcessHandler();
|
|
|
|
if (!handler)
|
|
|
|
return;
|
2017-05-31 17:33:30 +02:00
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefFrameImpl> framePtr = browserPtr->GetWebFrameImpl(frame);
|
|
|
|
|
|
|
|
if (node.IsNull()) {
|
|
|
|
handler->OnFocusedNodeChanged(browserPtr.get(), framePtr.get(), nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node.GetDocument().IsNull())
|
2017-07-27 01:19:27 +02:00
|
|
|
return;
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
CefRefPtr<CefDOMDocumentImpl> documentImpl =
|
|
|
|
new CefDOMDocumentImpl(browserPtr.get(), frame);
|
|
|
|
handler->OnFocusedNodeChanged(browserPtr.get(), framePtr.get(),
|
|
|
|
documentImpl->GetOrCreateNode(node));
|
|
|
|
documentImpl->Detach();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderFrameObserver::DraggableRegionsChanged() {
|
|
|
|
if (frame_) {
|
|
|
|
frame_->OnDraggableRegionsChanged();
|
|
|
|
}
|
2017-07-27 01:19:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
void CefRenderFrameObserver::DidCreateScriptContext(
|
|
|
|
v8::Handle<v8::Context> context,
|
|
|
|
int world_id) {
|
|
|
|
blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
|
|
|
|
CefRefPtr<CefBrowserImpl> browserPtr =
|
2017-04-20 21:28:17 +02:00
|
|
|
CefBrowserImpl::GetBrowserForMainFrame(frame->Top());
|
2019-05-24 22:23:43 +02:00
|
|
|
if (!browserPtr)
|
2015-04-20 13:11:11 +02:00
|
|
|
return;
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
CefRefPtr<CefRenderProcessHandler> handler;
|
|
|
|
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
2019-05-24 22:23:43 +02:00
|
|
|
if (application)
|
2015-07-16 23:40:01 +02:00
|
|
|
handler = application->GetRenderProcessHandler();
|
2019-05-24 22:23:43 +02:00
|
|
|
if (!handler)
|
2015-07-16 23:40:01 +02:00
|
|
|
return;
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
CefRefPtr<CefFrameImpl> framePtr = browserPtr->GetWebFrameImpl(frame);
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
v8::Isolate* isolate = blink::MainThreadIsolate();
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Context::Scope scope(context);
|
2016-03-16 03:55:59 +01:00
|
|
|
v8::MicrotasksScope microtasks_scope(isolate,
|
|
|
|
v8::MicrotasksScope::kRunMicrotasks);
|
2015-04-20 13:11:11 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefV8Context> contextPtr(new CefV8ContextImpl(isolate, context));
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
handler->OnContextCreated(browserPtr.get(), framePtr.get(), contextPtr);
|
2015-04-20 13:11:11 +02:00
|
|
|
}
|
|
|
|
|
2014-04-04 18:50:38 +02:00
|
|
|
void CefRenderFrameObserver::WillReleaseScriptContext(
|
|
|
|
v8::Handle<v8::Context> context,
|
|
|
|
int world_id) {
|
2015-04-20 13:11:11 +02:00
|
|
|
blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
|
2015-07-16 23:40:01 +02:00
|
|
|
CefRefPtr<CefBrowserImpl> browserPtr =
|
2017-04-20 21:28:17 +02:00
|
|
|
CefBrowserImpl::GetBrowserForMainFrame(frame->Top());
|
2019-05-24 22:23:43 +02:00
|
|
|
if (browserPtr) {
|
2015-07-16 23:40:01 +02:00
|
|
|
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
2019-05-24 22:23:43 +02:00
|
|
|
if (application) {
|
2015-07-16 23:40:01 +02:00
|
|
|
CefRefPtr<CefRenderProcessHandler> handler =
|
|
|
|
application->GetRenderProcessHandler();
|
2019-05-24 22:23:43 +02:00
|
|
|
if (handler) {
|
2015-04-20 13:11:11 +02:00
|
|
|
CefRefPtr<CefFrameImpl> framePtr = browserPtr->GetWebFrameImpl(frame);
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
v8::Isolate* isolate = blink::MainThreadIsolate();
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
2016-02-05 01:49:19 +01:00
|
|
|
|
|
|
|
// The released context should not be used for script execution.
|
|
|
|
// Depending on how the context is released this may or may not already
|
|
|
|
// be set.
|
2018-04-19 17:44:42 +02:00
|
|
|
blink_glue::CefScriptForbiddenScope forbidScript;
|
2015-04-20 13:11:11 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefV8Context> contextPtr(
|
|
|
|
new CefV8ContextImpl(isolate, context));
|
|
|
|
|
|
|
|
handler->OnContextReleased(browserPtr.get(), framePtr.get(),
|
|
|
|
contextPtr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CefV8ReleaseContext(context);
|
2014-04-04 18:50:38 +02:00
|
|
|
}
|
2016-03-16 03:55:59 +01:00
|
|
|
|
2016-06-21 00:59:23 +02:00
|
|
|
void CefRenderFrameObserver::OnDestruct() {
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:43 +02:00
|
|
|
bool CefRenderFrameObserver::OnMessageReceived(const IPC::Message& message) {
|
|
|
|
if (frame_) {
|
|
|
|
return frame_->OnMessageReceived(message);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefRenderFrameObserver::AttachFrame(CefFrameImpl* frame) {
|
|
|
|
DCHECK(frame);
|
|
|
|
DCHECK(!frame_);
|
|
|
|
frame_ = frame;
|
|
|
|
frame_->OnAttached();
|
|
|
|
}
|
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
// Enable deprecation warnings on Windows. See http://crbug.com/585142.
|
2016-03-16 03:55:59 +01:00
|
|
|
#if defined(OS_WIN)
|
2018-10-02 14:14:11 +02:00
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#else
|
2016-03-16 03:55:59 +01:00
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
2018-10-02 14:14:11 +02:00
|
|
|
#endif
|