2012-04-03 03:34:16 +02:00
|
|
|
/// Copyright (c) 2012 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions (c) 2011 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/browser_message_filter.h"
|
|
|
|
|
2012-11-20 21:08:36 +01:00
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
2012-12-30 12:17:49 +01:00
|
|
|
#include "libcef/browser/browser_info.h"
|
2012-11-20 21:08:36 +01:00
|
|
|
#include "libcef/browser/content_browser_client.h"
|
|
|
|
#include "libcef/browser/context.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/origin_whitelist_impl.h"
|
|
|
|
#include "libcef/browser/thread_util.h"
|
|
|
|
#include "libcef/common/cef_messages.h"
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "libcef/common/content_client.h"
|
2012-11-20 21:08:36 +01:00
|
|
|
#include "libcef/common/values_impl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#include "base/compiler_specific.h"
|
|
|
|
#include "base/bind.h"
|
2013-02-08 01:07:41 +01:00
|
|
|
#include "content/common/view_messages.h"
|
2012-11-20 21:08:36 +01:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CefBrowserMessageFilter::CefBrowserMessageFilter(
|
|
|
|
content::RenderProcessHost* host)
|
|
|
|
: host_(host),
|
|
|
|
channel_(NULL) {
|
|
|
|
}
|
|
|
|
|
|
|
|
CefBrowserMessageFilter::~CefBrowserMessageFilter() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMessageFilter::OnFilterAdded(IPC::Channel* channel) {
|
|
|
|
channel_ = channel;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMessageFilter::OnFilterRemoved() {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserMessageFilter::OnMessageReceived(const IPC::Message& message) {
|
|
|
|
bool handled = true;
|
2013-02-08 01:07:41 +01:00
|
|
|
if (message.type() == ViewHostMsg_CreateWindow::ID) {
|
|
|
|
// Observe but don't handle this message.
|
|
|
|
handled = false;
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
IPC_BEGIN_MESSAGE_MAP(CefBrowserMessageFilter, message)
|
2012-11-20 21:08:36 +01:00
|
|
|
IPC_MESSAGE_HANDLER(CefProcessHostMsg_GetNewRenderThreadInfo,
|
|
|
|
OnGetNewRenderThreadInfo)
|
|
|
|
IPC_MESSAGE_HANDLER(CefProcessHostMsg_GetNewBrowserInfo,
|
|
|
|
OnGetNewBrowserInfo)
|
2013-02-09 23:38:24 +01:00
|
|
|
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_CreateWindow, OnCreateWindow)
|
2012-04-03 03:34:16 +02:00
|
|
|
IPC_MESSAGE_UNHANDLED(handled = false)
|
|
|
|
IPC_END_MESSAGE_MAP()
|
|
|
|
return handled;
|
|
|
|
}
|
|
|
|
|
2012-11-20 21:08:36 +01:00
|
|
|
bool CefBrowserMessageFilter::Send(IPC::Message* message) {
|
|
|
|
return host_->Send(message);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-11-20 21:08:36 +01:00
|
|
|
void CefBrowserMessageFilter::OnGetNewRenderThreadInfo(
|
|
|
|
CefProcessHostMsg_GetNewRenderThreadInfo_Params* params) {
|
|
|
|
GetCrossOriginWhitelistEntries(¶ms->cross_origin_whitelist_entries);
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
CefRefPtr<CefApp> app = CefContentClient::Get()->application();
|
2012-11-20 21:08:36 +01:00
|
|
|
if (app.get()) {
|
|
|
|
CefRefPtr<CefBrowserProcessHandler> handler =
|
|
|
|
app->GetBrowserProcessHandler();
|
|
|
|
if (handler.get()) {
|
|
|
|
CefRefPtr<CefListValueImpl> listValuePtr(
|
|
|
|
new CefListValueImpl(¶ms->extra_info, false, false));
|
|
|
|
handler->OnRenderProcessThreadCreated(listValuePtr.get());
|
|
|
|
listValuePtr->Detach(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMessageFilter::OnGetNewBrowserInfo(
|
|
|
|
int routing_id, CefProcessHostMsg_GetNewBrowserInfo_Params* params) {
|
2012-12-30 12:17:49 +01:00
|
|
|
// Popup windows may not have info yet.
|
|
|
|
scoped_refptr<CefBrowserInfo> info =
|
|
|
|
CefContentBrowserClient::Get()->GetOrCreateBrowserInfo(host_->GetID(),
|
|
|
|
routing_id);
|
|
|
|
params->browser_id = info->browser_id();
|
|
|
|
params->is_popup = info->is_popup();
|
2013-04-16 21:23:00 +02:00
|
|
|
params->is_window_rendering_disabled = info->is_window_rendering_disabled();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2013-02-08 01:07:41 +01:00
|
|
|
|
|
|
|
void CefBrowserMessageFilter::OnCreateWindow(
|
|
|
|
const ViewHostMsg_CreateWindow_Params& params,
|
2013-02-09 23:38:24 +01:00
|
|
|
IPC::Message* reply_msg) {
|
2013-02-08 01:07:41 +01:00
|
|
|
CefContentBrowserClient::LastCreateWindowParams lcwp;
|
2013-02-09 23:38:24 +01:00
|
|
|
lcwp.opener_process_id = host_->GetID();
|
|
|
|
lcwp.opener_view_id = params.opener_id;
|
2013-02-08 01:07:41 +01:00
|
|
|
lcwp.opener_frame_id = params.opener_frame_id;
|
|
|
|
lcwp.target_url = params.target_url;
|
|
|
|
lcwp.target_frame_name = params.frame_name;
|
|
|
|
CefContentBrowserClient::Get()->set_last_create_window_params(lcwp);
|
2013-02-09 23:38:24 +01:00
|
|
|
|
|
|
|
// Reply message is not used.
|
|
|
|
delete reply_msg;
|
2013-02-08 01:07:41 +01:00
|
|
|
}
|