mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Support custom V8 bindings on WebWorker threads (issue #451).
- Add CefRenderProcessHandler callbacks for WebWorker context creation, release and uncaught exceptions. - Add CefTaskRunner class that supports posting of tasks to standard threads and WebWorker threads. - Organize V8 internal state information on a per-thread/per-Isolate basis. - Add webkit_451.patch that provides the WebKit implementation. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@972 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@ -1,108 +1,38 @@
|
||||
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
||||
// Copyright (c) 2013 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.
|
||||
|
||||
#include "include/cef_task.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/renderer/thread_util.h"
|
||||
#include "libcef/common/task_runner_impl.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
namespace {
|
||||
|
||||
const int kRenderThreadId = -1;
|
||||
const int kInvalidThreadId = -10;
|
||||
|
||||
int GetThreadId(CefThreadId threadId) {
|
||||
int id = kInvalidThreadId;
|
||||
|
||||
switch (threadId) {
|
||||
case TID_UI:
|
||||
id = BrowserThread::UI;
|
||||
break;
|
||||
case TID_DB:
|
||||
id = BrowserThread::DB;
|
||||
break;
|
||||
case TID_FILE:
|
||||
id = BrowserThread::FILE;
|
||||
break;
|
||||
case TID_FILE_USER_BLOCKING:
|
||||
id = BrowserThread::FILE_USER_BLOCKING;
|
||||
break;
|
||||
case TID_PROCESS_LAUNCHER:
|
||||
id = BrowserThread::PROCESS_LAUNCHER;
|
||||
break;
|
||||
case TID_CACHE:
|
||||
id = BrowserThread::CACHE;
|
||||
break;
|
||||
case TID_IO:
|
||||
id = BrowserThread::IO;
|
||||
break;
|
||||
case TID_RENDERER:
|
||||
id = kRenderThreadId;
|
||||
break;
|
||||
default:
|
||||
NOTREACHED() << "invalid thread id " << threadId;
|
||||
return kInvalidThreadId;
|
||||
};
|
||||
|
||||
if (id >= 0) {
|
||||
// Verify that we're on the browser process.
|
||||
if (content::GetContentClient()->browser())
|
||||
return id;
|
||||
NOTREACHED() << "called on invalid process";
|
||||
} else if (id == kRenderThreadId) {
|
||||
// Verify that we're on the renderer process.
|
||||
if (content::GetContentClient()->renderer())
|
||||
return id;
|
||||
NOTREACHED() << "called on invalid process";
|
||||
}
|
||||
|
||||
return kInvalidThreadId;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
#include "base/location.h"
|
||||
|
||||
bool CefCurrentlyOn(CefThreadId threadId) {
|
||||
int id = GetThreadId(threadId);
|
||||
if (id >= 0) {
|
||||
// Browser process.
|
||||
return CEF_CURRENTLY_ON(static_cast<BrowserThread::ID>(id));
|
||||
} else if (id == kRenderThreadId) {
|
||||
// Renderer process.
|
||||
return CEF_CURRENTLY_ON_RT();
|
||||
}
|
||||
scoped_refptr<base::SequencedTaskRunner> task_runner =
|
||||
CefTaskRunnerImpl::GetTaskRunner(threadId);
|
||||
if (task_runner.get())
|
||||
return task_runner->RunsTasksOnCurrentThread();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CefPostTask(CefThreadId threadId, CefRefPtr<CefTask> task) {
|
||||
int id = GetThreadId(threadId);
|
||||
if (id >= 0) {
|
||||
// Browser process.
|
||||
return CEF_POST_TASK(static_cast<BrowserThread::ID>(id),
|
||||
base::Bind(&CefTask::Execute, task, threadId));
|
||||
} else if (id == kRenderThreadId) {
|
||||
// Renderer process.
|
||||
return CEF_POST_TASK_RT(base::Bind(&CefTask::Execute, task, threadId));
|
||||
scoped_refptr<base::SequencedTaskRunner> task_runner =
|
||||
CefTaskRunnerImpl::GetTaskRunner(threadId);
|
||||
if (task_runner.get()) {
|
||||
return task_runner->PostTask(FROM_HERE,
|
||||
base::Bind(&CefTask::Execute, task));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CefPostDelayedTask(CefThreadId threadId, CefRefPtr<CefTask> task,
|
||||
int64 delay_ms) {
|
||||
int id = GetThreadId(threadId);
|
||||
if (id >= 0) {
|
||||
// Browser process.
|
||||
return CEF_POST_DELAYED_TASK(static_cast<BrowserThread::ID>(id),
|
||||
base::Bind(&CefTask::Execute, task, threadId),
|
||||
base::TimeDelta::FromMilliseconds(delay_ms));
|
||||
} else if (id == kRenderThreadId) {
|
||||
// Renderer process.
|
||||
return CEF_POST_DELAYED_TASK_RT(
|
||||
base::Bind(&CefTask::Execute, task, threadId),
|
||||
base::TimeDelta::FromMilliseconds(delay_ms));
|
||||
bool CefPostDelayedTask(CefThreadId threadId, CefRefPtr<CefTask> task, int64 delay_ms) {
|
||||
scoped_refptr<base::SequencedTaskRunner> task_runner =
|
||||
CefTaskRunnerImpl::GetTaskRunner(threadId);
|
||||
if (task_runner.get()) {
|
||||
return task_runner->PostDelayedTask(FROM_HERE,
|
||||
base::Bind(&CefTask::Execute, task),
|
||||
base::TimeDelta::FromMilliseconds(delay_ms));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user