How to Add New Features (without bloating RenderView/RenderViewHost/WebContents)
Problem
Historically, new features (i.e. autofill to pick an example) have been added by bolting on their code to RenderView in the renderer process, and RenderViewHost in the browser process. If a feature was handled on the IO thread in the browser process, then its IPC messages were dispatched in BrowserMessageFilter. RenderViewHost would often dispatch the IPC message only to call WebContents (through the RenderViewHostDelegate interface), which would then call to another piece of code. All the IPC messages between the browser and renderer were declared in a massive render_messages_internal.h. Touching each of these files for every feature meant that the classes became bloated.
Solution
We have added helper classes and mechanisms for filtering IPC messages on each of the above threads. This makes it easier to write self contained features.
Renderer side:
If you want to filter and send IPC messages, implement the RenderViewObserver
interface (content/
If your feature has part of the code in WebKit, avoid having callbacks go
through WebViewClient interface so that we don't bloat it. Consider creating a
new WebKit interface that the WebKit code calls, and have the renderer side
class implement it. As an example, see WebAutoFillClient
(third_party/
Browser UI thread:
The WebContentsObserver (content/
Other browser threads:
To filter and send IPC messages on other browser threads, such as IO/
In general, if a feature has more than a few IPC messages, they should be moved
into a separate file (i.e. not be added to render_messages_internal.h). This
also helps with filtering messages on a thread other than the IO thread. As an
example, see content/
void DatabaseMessageFilter::OverrideThreadForMessage( const IPC::Message& message, BrowserThread::ID* thread) { if (IPC_MESSAGE_CLASS(message) == DatabaseMsgStart) *thread = BrowserThread::FILE; }