| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 | 14 |
| 15 class Browser; | 15 class Browser; |
| 16 class ExtensionFunction; | 16 class ExtensionFunction; |
| 17 class ExtensionHost; |
| 17 class Profile; | 18 class Profile; |
| 18 class RenderViewHost; | 19 class RenderViewHost; |
| 19 class RenderViewHostDelegate; | 20 class RenderViewHostDelegate; |
| 20 | 21 |
| 21 // A factory function for creating new ExtensionFunction instances. | 22 // A factory function for creating new ExtensionFunction instances. |
| 22 typedef ExtensionFunction* (*ExtensionFunctionFactory)(); | 23 typedef ExtensionFunction* (*ExtensionFunctionFactory)(); |
| 23 | 24 |
| 24 // ExtensionFunctionDispatcher receives requests to execute functions from | 25 // ExtensionFunctionDispatcher receives requests to execute functions from |
| 25 // Chromium extensions running in a RenderViewHost and dispatches them to the | 26 // Chromium extensions running in a RenderViewHost and dispatches them to the |
| 26 // appropriate handler. It lives entirely on the UI thread. | 27 // appropriate handler. It lives entirely on the UI thread. |
| 27 class ExtensionFunctionDispatcher { | 28 class ExtensionFunctionDispatcher { |
| 28 public: | 29 public: |
| 29 class Delegate { | 30 class Delegate { |
| 30 public: | 31 public: |
| 31 virtual Browser* GetBrowser() = 0; | 32 virtual Browser* GetBrowser() = 0; |
| 33 virtual ExtensionHost* GetHost() { return NULL; } |
| 32 }; | 34 }; |
| 33 | 35 |
| 34 // The peer object allows us to notify ExtensionFunctions when we are | 36 // The peer object allows us to notify ExtensionFunctions when we are |
| 35 // destroyed. | 37 // destroyed. |
| 36 struct Peer : public base::RefCounted<Peer> { | 38 struct Peer : public base::RefCounted<Peer> { |
| 37 Peer(ExtensionFunctionDispatcher* dispatcher) : dispatcher_(dispatcher) {} | 39 Peer(ExtensionFunctionDispatcher* dispatcher) : dispatcher_(dispatcher) {} |
| 38 ExtensionFunctionDispatcher* dispatcher_; | 40 ExtensionFunctionDispatcher* dispatcher_; |
| 39 }; | 41 }; |
| 40 | 42 |
| 41 // Gets a list of all known extension function names. | 43 // Gets a list of all known extension function names. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 61 void HandleRequest(const std::string& name, const std::string& args, | 63 void HandleRequest(const std::string& name, const std::string& args, |
| 62 int request_id, bool has_callback); | 64 int request_id, bool has_callback); |
| 63 | 65 |
| 64 // Send a response to a function. | 66 // Send a response to a function. |
| 65 void SendResponse(ExtensionFunction* api, bool success); | 67 void SendResponse(ExtensionFunction* api, bool success); |
| 66 | 68 |
| 67 // Gets the browser extension functions should operate relative to. For | 69 // Gets the browser extension functions should operate relative to. For |
| 68 // example, for positioning windows, or alert boxes, or creating tabs. | 70 // example, for positioning windows, or alert boxes, or creating tabs. |
| 69 Browser* GetBrowser(); | 71 Browser* GetBrowser(); |
| 70 | 72 |
| 73 // |
| 74 ExtensionHost* GetHost(); |
| 75 |
| 71 // Handle a malformed message. Possibly the result of an attack, so kill | 76 // Handle a malformed message. Possibly the result of an attack, so kill |
| 72 // the renderer. | 77 // the renderer. |
| 73 void HandleBadMessage(ExtensionFunction* api); | 78 void HandleBadMessage(ExtensionFunction* api); |
| 74 | 79 |
| 75 // Gets the URL for the view we're displaying. | 80 // Gets the URL for the view we're displaying. |
| 76 const GURL& url() { return url_; } | 81 const GURL& url() { return url_; } |
| 77 | 82 |
| 78 // Gets the ID for this extension. | 83 // Gets the ID for this extension. |
| 79 const std::string extension_id() { return url_.host(); } | 84 const std::string extension_id() { return url_.host(); } |
| 80 | 85 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 95 | 100 |
| 96 // AutomationExtensionFunction requires access to the RenderViewHost | 101 // AutomationExtensionFunction requires access to the RenderViewHost |
| 97 // associated with us. We make it a friend rather than exposing the | 102 // associated with us. We make it a friend rather than exposing the |
| 98 // RenderViewHost as a public method as we wouldn't want everyone to | 103 // RenderViewHost as a public method as we wouldn't want everyone to |
| 99 // start assuming a 1:1 relationship between us and RenderViewHost, | 104 // start assuming a 1:1 relationship between us and RenderViewHost, |
| 100 // whereas AutomationExtensionFunction is by necessity "tight" with us. | 105 // whereas AutomationExtensionFunction is by necessity "tight" with us. |
| 101 friend class AutomationExtensionFunction; | 106 friend class AutomationExtensionFunction; |
| 102 }; | 107 }; |
| 103 | 108 |
| 104 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ | 109 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ |
| OLD | NEW |