diff options
author | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-23 22:21:43 +0000 |
---|---|---|
committer | mpcomplete@google.com <mpcomplete@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-23 22:21:43 +0000 |
commit | 0aa477bd3cd906e880891fd2e9f4739a53270a7f (patch) | |
tree | f78ab46e2bd5aca2812755d3240fd8cf4e83c8f5 /chrome/browser/extensions/extension_message_service.h | |
parent | 1d437b64e1aaf11827962de62694bcb806265d00 (diff) | |
download | chromium_src-0aa477bd3cd906e880891fd2e9f4739a53270a7f.zip chromium_src-0aa477bd3cd906e880891fd2e9f4739a53270a7f.tar.gz chromium_src-0aa477bd3cd906e880891fd2e9f4739a53270a7f.tar.bz2 |
Initial rev at a message passing API for extensions. So far, only passing
messages to the extension process is supported.
Review URL: http://codereview.chromium.org/48090
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12319 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_message_service.h')
-rwxr-xr-x | chrome/browser/extensions/extension_message_service.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_message_service.h b/chrome/browser/extensions/extension_message_service.h new file mode 100755 index 0000000..eef1676 --- /dev/null +++ b/chrome/browser/extensions/extension_message_service.h @@ -0,0 +1,73 @@ +// Copyright (c) 2009 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. + +#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ + +#include <map> +#include <string> + +class ExtensionView; +class ResourceMessageFilter; + +// This class manages message passing to and from extension processes. It +// maintains a list of available extensions, as well as a set of open channels. +// It should only be accessed on the IO thread, with the exception of +// RegisterExtensionView(). +// +// Terminology: +// channel: connection between two ports (one of which belongs to an extension) +// port: an IPC::Message::Sender interface through which we communicate to a +// process. We use MessageFilters for this since that allows us to send our +// messages on the IO thread. +class ExtensionMessageService { + public: + static ExtensionMessageService* GetInstance(); + + ExtensionMessageService(); + + // Registers an extension so that it can be referenced by its ID. This method + // should only be used by the UI thread. + void RegisterExtensionView(ExtensionView* view); + + // Given an extension's ID, opens a channel between the given renderer "port" + // and that extension. Returns a channel ID to be used for posting messages + // between the processes, or -1 if the extension doesn't exist. + int OpenChannelToExtension(const std::string& extension_id, + ResourceMessageFilter* renderer_port); + + // Sends a message to the extension via the given channel. + void PostMessage(int channel_id, const std::string& message); + + // Called to let us know that a renderer is going away. + void RendererShutdown(ResourceMessageFilter* renderer_port); + private: + class ExtensionFilter; + friend class ExtensionFilter; + + // Called when our ExtensionFilter is ready/going away. + void OnExtensionRegistered(ExtensionFilter* extension); + void OnExtensionUnregistered(ExtensionFilter* extension); + + // A map of extension ID to the extension port to communicate through. + // TODO(mpcomplete): Handle the case where there's multiple ExtensionViews + // in a given extension. + typedef std::map<std::string, ExtensionFilter*> ExtensionMap; + ExtensionMap extensions_; + + // The connection between the renderer and extension. + struct MessageChannel { + ExtensionFilter* extension_port; + ResourceMessageFilter* renderer_port; + }; + + // A map of channel ID to its channel object. + typedef std::map<int, MessageChannel> MessageChannelMap; + MessageChannelMap channels_; + + // For generating unique channel IDs. + int next_channel_id_; +}; + +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MESSAGE_SERVICE_H_ |