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"
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
MSVC_PUSH_WARNING_LEVEL(0);
|
|
|
|
#include "bindings/core/v8/V8RecursionScope.h"
|
|
|
|
MSVC_POP_WARNING();
|
|
|
|
#undef FROM_HERE
|
|
|
|
#undef LOG
|
|
|
|
|
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"
|
2014-04-04 18:50:38 +02:00
|
|
|
#include "libcef/renderer/content_renderer_client.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"
|
2015-04-20 13:11:11 +02:00
|
|
|
#include "third_party/WebKit/public/web/WebLocalFrame.h"
|
|
|
|
#include "third_party/WebKit/public/web/WebKit.h"
|
2014-04-04 18:50:38 +02:00
|
|
|
|
|
|
|
CefRenderFrameObserver::CefRenderFrameObserver(
|
|
|
|
content::RenderFrame* render_frame)
|
|
|
|
: content::RenderFrameObserver(render_frame) {
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRenderFrameObserver::~CefRenderFrameObserver() {
|
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
void CefRenderFrameObserver::DidCreateScriptContext(
|
|
|
|
v8::Handle<v8::Context> context,
|
|
|
|
int extension_group,
|
|
|
|
int world_id) {
|
|
|
|
blink::WebLocalFrame* frame = render_frame()->GetWebFrame();
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowserImpl> browserPtr =
|
|
|
|
CefBrowserImpl::GetBrowserForMainFrame(frame->top());
|
|
|
|
if (!browserPtr.get())
|
|
|
|
return;
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
CefRefPtr<CefRenderProcessHandler> handler;
|
|
|
|
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
|
|
|
if (application.get())
|
|
|
|
handler = application->GetRenderProcessHandler();
|
|
|
|
if (!handler.get())
|
|
|
|
return;
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
CefRefPtr<CefFrameImpl> framePtr = browserPtr->GetWebFrameImpl(frame);
|
|
|
|
|
|
|
|
v8::Isolate* isolate = blink::mainThreadIsolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Context::Scope scope(context);
|
|
|
|
blink::V8RecursionScope recursion_scope(isolate);
|
|
|
|
|
|
|
|
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 =
|
|
|
|
CefBrowserImpl::GetBrowserForMainFrame(frame->top());
|
|
|
|
if (browserPtr.get()) {
|
|
|
|
CefRefPtr<CefApp> application = CefContentClient::Get()->application();
|
|
|
|
if (application.get()) {
|
|
|
|
CefRefPtr<CefRenderProcessHandler> handler =
|
|
|
|
application->GetRenderProcessHandler();
|
|
|
|
if (handler.get()) {
|
2015-04-20 13:11:11 +02:00
|
|
|
CefRefPtr<CefFrameImpl> framePtr = browserPtr->GetWebFrameImpl(frame);
|
|
|
|
|
|
|
|
v8::Isolate* isolate = blink::mainThreadIsolate();
|
|
|
|
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.
|
|
|
|
blink::ScriptForbiddenScope 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
|
|
|
}
|