Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / messaging / message_service.h
index ed6eae9..6dcde00 100644 (file)
 #include "base/memory/scoped_ptr.h"
 #include "base/memory/weak_ptr.h"
 #include "chrome/browser/extensions/api/messaging/message_property_provider.h"
-#include "chrome/browser/extensions/api/messaging/native_message_process_host.h"
-#include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
-#include "chrome/common/extensions/api/messaging/message.h"
 #include "content/public/browser/notification_observer.h"
 #include "content/public/browser/notification_registrar.h"
+#include "extensions/browser/api/messaging/native_message_host.h"
+#include "extensions/browser/browser_context_keyed_api_factory.h"
+#include "extensions/common/api/messaging/message.h"
 
 class GURL;
 class Profile;
@@ -28,6 +28,7 @@ class DictionaryValue;
 }
 
 namespace content {
+class BrowserContext;
 class RenderProcessHost;
 class WebContents;
 }
@@ -58,9 +59,8 @@ class LazyBackgroundTaskQueue;
 // port: an IPC::Message::Process interface and an optional routing_id (in the
 // case that the port is a tab).  The Process is usually either a
 // RenderProcessHost or a RenderViewHost.
-class MessageService : public ProfileKeyedAPI,
-                       public content::NotificationObserver,
-                       public NativeMessageProcessHost::Client {
+class MessageService : public BrowserContextKeyedAPI,
+                       public content::NotificationObserver {
  public:
   // A messaging channel. Note that the opening port can be the same as the
   // receiver, if an extension background page wants to talk to its tab (for
@@ -104,18 +104,28 @@ class MessageService : public ProfileKeyedAPI,
     DISALLOW_COPY_AND_ASSIGN(MessagePort);
   };
 
+  enum PolicyPermission {
+    DISALLOW,           // The host is not allowed.
+    ALLOW_SYSTEM_ONLY,  // Allowed only when installed on system level.
+    ALLOW_ALL,          // Allowed when installed on system or user level.
+  };
+
+  static PolicyPermission IsNativeMessagingHostAllowed(
+      const PrefService* pref_service,
+      const std::string& native_host_name);
+
   // Allocates a pair of port ids.
   // NOTE: this can be called from any thread.
   static void AllocatePortIdPair(int* port1, int* port2);
 
-  explicit MessageService(Profile* profile);
-  virtual ~MessageService();
+  explicit MessageService(content::BrowserContext* context);
+  ~MessageService() override;
 
-  // ProfileKeyedAPI implementation.
-  static ProfileKeyedAPIFactory<MessageService>* GetFactoryInstance();
+  // BrowserContextKeyedAPI implementation.
+  static BrowserContextKeyedAPIFactory<MessageService>* GetFactoryInstance();
 
-  // Convenience method to get the MessageService for a profile.
-  static MessageService* Get(Profile* profile);
+  // Convenience method to get the MessageService for a browser context.
+  static MessageService* Get(content::BrowserContext* context);
 
   // Given an extension's ID, opens a channel between the given renderer "port"
   // and every listening context owned by that extension. |channel_name| is
@@ -145,21 +155,15 @@ class MessageService : public ProfileKeyedAPI,
 
   // Closes the message channel associated with the given port, and notifies
   // the other side.
-  virtual void CloseChannel(int port_id,
-                            const std::string& error_message) OVERRIDE;
+  void CloseChannel(int port_id, const std::string& error_message);
 
   // Enqueues a message on a pending channel, or sends a message to the given
   // port if the channel isn't pending.
   void PostMessage(int port_id, const Message& message);
 
-  // NativeMessageProcessHost::Client
-  virtual void PostMessageFromNativeProcess(
-      int port_id,
-      const std::string& message) OVERRIDE;
-
  private:
   friend class MockMessageService;
-  friend class ProfileKeyedAPIFactory<MessageService>;
+  friend class BrowserContextKeyedAPIFactory<MessageService>;
   struct OpenChannelParams;
 
   // A map of channel ID to its channel object.
@@ -174,7 +178,8 @@ class MessageService : public ProfileKeyedAPI,
   // A map of channel ID to information about the extension that is waiting
   // for that channel to open. Used for lazy background pages.
   typedef std::string ExtensionID;
-  typedef std::pair<Profile*, ExtensionID> PendingLazyBackgroundPageChannel;
+  typedef std::pair<content::BrowserContext*, ExtensionID>
+      PendingLazyBackgroundPageChannel;
   typedef std::map<int, PendingLazyBackgroundPageChannel>
       PendingLazyBackgroundPageChannelMap;
 
@@ -191,15 +196,15 @@ class MessageService : public ProfileKeyedAPI,
   void AddChannel(MessageChannel* channel, int receiver_port_id);
 
   // content::NotificationObserver interface.
-  virtual void Observe(int type,
-                       const content::NotificationSource& source,
-                       const content::NotificationDetails& details) OVERRIDE;
+  void Observe(int type,
+               const content::NotificationSource& source,
+               const content::NotificationDetails& details) override;
 
   // A process that might be in our list of channels has closed.
   void OnProcessClosed(content::RenderProcessHost* process);
 
-  void GotDomainBoundCert(scoped_ptr<OpenChannelParams> params,
-                          const std::string& tls_channel_id);
+  void GotChannelID(scoped_ptr<OpenChannelParams> params,
+                    const std::string& tls_channel_id);
 
   // Enqueues a message on a pending channel.
   void EnqueuePendingMessage(int port_id, int channel_id,
@@ -218,7 +223,7 @@ class MessageService : public ProfileKeyedAPI,
   // to open a channel. Returns true if a task was queued.
   // Takes ownership of |params| if true is returned.
   bool MaybeAddPendingLazyBackgroundPageOpenChannelTask(
-      Profile* profile,
+      content::BrowserContext* context,
       const Extension* extension,
       OpenChannelParams* params);
 
@@ -248,7 +253,7 @@ class MessageService : public ProfileKeyedAPI,
                             int port_id,
                             const std::string& error_message);
 
-  // ProfileKeyedAPI implementation.
+  // BrowserContextKeyedAPI implementation.
   static const char* service_name() {
     return "MessageService";
   }