| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_AUTOMATION_EXTENSION_PORT_CONTAINER_H_ | |
| 6 #define CHROME_BROWSER_AUTOMATION_EXTENSION_PORT_CONTAINER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "ipc/ipc_message.h" | |
| 14 | |
| 15 class AutomationProvider; | |
| 16 class ExtensionMessageService; | |
| 17 class GURL; | |
| 18 class ListValue; | |
| 19 class RenderViewHost; | |
| 20 | |
| 21 // This class represents an external port to an extension, opened | |
| 22 // through the automation interface. | |
| 23 class ExtensionPortContainer : public IPC::Message::Sender { | |
| 24 public: | |
| 25 | |
| 26 // Intercepts and processes a message posted through the automation interface. | |
| 27 // Returns true if the message was intercepted. | |
| 28 static bool InterceptMessageFromExternalHost(const std::string& message, | |
| 29 const std::string& origin, | |
| 30 const std::string& target, | |
| 31 AutomationProvider* automation, | |
| 32 RenderViewHost *view_host, | |
| 33 int tab_handle); | |
| 34 | |
| 35 ExtensionPortContainer(AutomationProvider* automation, int tab_handle); | |
| 36 ~ExtensionPortContainer(); | |
| 37 | |
| 38 int port_id() const { return port_id_; } | |
| 39 void set_port_id(int port_id) { port_id_ = port_id; } | |
| 40 | |
| 41 // IPC implementation. | |
| 42 virtual bool Send(IPC::Message* msg); | |
| 43 | |
| 44 private: | |
| 45 // Posts a message to the external host. | |
| 46 bool PostMessageToExternalPort(const std::string& message); | |
| 47 // Posts a request response message to the external host. | |
| 48 bool PostResponseToExternalPort(const std::string& message); | |
| 49 | |
| 50 // Forwards a message from the external port. | |
| 51 void PostMessageFromExternalPort(const std::string& message); | |
| 52 | |
| 53 // Attempts to connect this instance to the extension id, sends | |
| 54 // a response to the connecting party. | |
| 55 // Returns true if the connection was successful. | |
| 56 bool Connect(const std::string &extension_id, | |
| 57 int process_id, | |
| 58 int routing_id, | |
| 59 int connection_id, | |
| 60 const std::string& channel_name, | |
| 61 const std::string& tab_json); | |
| 62 | |
| 63 // Sends a connect response to the external port. | |
| 64 void SendConnectionResponse(int connection_id, int port_id); | |
| 65 | |
| 66 void OnExtensionMessageInvoke(const std::string& extension_id, | |
| 67 const std::string& function_name, | |
| 68 const ListValue& args, | |
| 69 const GURL& event_url); | |
| 70 void OnExtensionHandleMessage(const std::string& message, int source_port_id); | |
| 71 void OnExtensionPortDisconnected(int source_port_id); | |
| 72 | |
| 73 // Our automation provider. | |
| 74 AutomationProvider* automation_; | |
| 75 | |
| 76 // The extension message service. | |
| 77 scoped_refptr<ExtensionMessageService> service_; | |
| 78 | |
| 79 // Our assigned port id. | |
| 80 int port_id_; | |
| 81 // Handle to our associated tab. | |
| 82 int tab_handle_; | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(ExtensionPortContainer); | |
| 85 }; | |
| 86 | |
| 87 #endif // CHROME_BROWSER_AUTOMATION_EXTENSION_PORT_CONTAINER_H_ | |
| OLD | NEW |