[webkit-dev] Propose some changes to WebKit implementation of HTML5 workers in order to run them in Chrome's worker process

Jian Li jianli at chromium.org
Mon Feb 2 18:10:07 PST 2009


The current WebKit implementation of HTML5 workers is based on cross-thread
communication in single process. To make it work for Chrome, we need to run
the workers in Chrome's worker process. Hence, we propose the following
changes:

MessagingWorkerProxy acts as the gateway between Worker and WorkerContext in
order to exchange messages. This does not work well across process. To
support both cross-thread and cross-process models, we propose splitting
MessagingWorkerProxy into two pieces: WorkerContextProxy and
WorkerObjectProxy.

For WebKit, MessagingWorkerProxy can implement both WorkerContextProxy and
WorkerObjectProxy, that communicate with each other via cross-thread task
posting. Some changes need also to be made in DOM objects in order to put
them in the right scope. For example, MessageWorkerTask.performTask can be
moved to Worker object and MessageWorkerContextTask.performTask can be moved
to WorkerContext object.

For Chrome, the implementation of WorkerContextProxy uses IPC to communicate
with the implementation of WorkerObjectProxy at the other end.

        Worker <=> WorkerContextProxy <=> ... <=> WorkParentProxy <=>
WorkerContext

  WebKit: \--- in main thread  ---/       CTC     \------ in worker thread
 -----/
  (CTC: Cross-thread communication by posting task)

  Chrome: \- in renderer process -/       IPC     \------ in worker process
-----/
  (IPC: Inter-process communication)


The abstractions of WorkerContextProxy and WorkerObjectProxy are defined as
the following:

// A proxy to talk to the worker context.
// All calls to any methods should come from main thread.
class WorkerContextProxy {
public:
  // Creator.
  static WorkerContextProxy* create();

  // Starts the worker context. Returns 0 if successful, error code
otherwise.
  virtual int startContext(const String& scriptUrl, Worker* worker) = 0;

  // Terminates the worker context.
  virtual void terminateContext() = 0;

  // Posts the message to the worker context.
  virtual void postMessageToContext(const String& message) = 0;

  // Has any pending activity?
  virtual bool hasPendingActivity() = 0;
};

// A proxy to talk to the worker object.
// All calls to any methods should come from worker thread.
class WorkerObjectProxy {
public:
  // Runs the script with the specified url.
  virtual bool run(const String& scriptURL) = 0;

  // Posts the message to the worker object.
  virtual void postMessageToObject(const String& message) = 0;

  // Posts the exception to the worker object.
  virtual void postExceptionToObject(const String& errorMessage, int
lineNumber, const String& sourceURL) = 0;
};
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20090202/ef1f3171/attachment.html>


More information about the webkit-dev mailing list