| 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 Extension; | 16 class Extension; |
| 17 class ExtensionDOMUI; |
| 17 class ExtensionFunction; | 18 class ExtensionFunction; |
| 18 class ExtensionHost; | 19 class ExtensionHost; |
| 20 class ExtensionPopupHost; |
| 19 class Profile; | 21 class Profile; |
| 20 class RenderViewHost; | 22 class RenderViewHost; |
| 21 class RenderViewHostDelegate; | 23 class RenderViewHostDelegate; |
| 22 class Value; | 24 class Value; |
| 23 | 25 |
| 24 // A factory function for creating new ExtensionFunction instances. | 26 // A factory function for creating new ExtensionFunction instances. |
| 25 typedef ExtensionFunction* (*ExtensionFunctionFactory)(); | 27 typedef ExtensionFunction* (*ExtensionFunctionFactory)(); |
| 26 | 28 |
| 27 // ExtensionFunctionDispatcher receives requests to execute functions from | 29 // ExtensionFunctionDispatcher receives requests to execute functions from |
| 28 // Chromium extensions running in a RenderViewHost and dispatches them to the | 30 // Chromium extensions running in a RenderViewHost and dispatches them to the |
| 29 // appropriate handler. It lives entirely on the UI thread. | 31 // appropriate handler. It lives entirely on the UI thread. |
| 30 class ExtensionFunctionDispatcher { | 32 class ExtensionFunctionDispatcher { |
| 31 public: | 33 public: |
| 32 class Delegate { | 34 class Delegate { |
| 33 public: | 35 public: |
| 34 virtual Browser* GetBrowser() = 0; | 36 virtual Browser* GetBrowser() = 0; |
| 35 virtual ExtensionHost* GetExtensionHost() { return NULL; } | 37 virtual ExtensionHost* GetExtensionHost() { return NULL; } |
| 38 virtual ExtensionDOMUI* GetExtensionDOMUI() { return NULL; } |
| 36 }; | 39 }; |
| 37 | 40 |
| 38 // The peer object allows us to notify ExtensionFunctions when we are | 41 // The peer object allows us to notify ExtensionFunctions when we are |
| 39 // destroyed. | 42 // destroyed. |
| 40 // TODO: this should use WeakPtr | 43 // TODO: this should use WeakPtr |
| 41 struct Peer : public base::RefCounted<Peer> { | 44 struct Peer : public base::RefCounted<Peer> { |
| 42 Peer(ExtensionFunctionDispatcher* dispatcher) : dispatcher_(dispatcher) {} | 45 explicit Peer(ExtensionFunctionDispatcher* dispatcher) |
| 46 : dispatcher_(dispatcher) {} |
| 43 ExtensionFunctionDispatcher* dispatcher_; | 47 ExtensionFunctionDispatcher* dispatcher_; |
| 44 | 48 |
| 45 private: | 49 private: |
| 46 friend class base::RefCounted<Peer>; | 50 friend class base::RefCounted<Peer>; |
| 47 | 51 |
| 48 ~Peer() {} | 52 ~Peer() {} |
| 49 }; | 53 }; |
| 50 | 54 |
| 51 // Gets a list of all known extension function names. | 55 // Gets a list of all known extension function names. |
| 52 static void GetAllFunctionNames(std::vector<std::string>* names); | 56 static void GetAllFunctionNames(std::vector<std::string>* names); |
| 53 | 57 |
| 54 // Override a previously registered function. Returns true if successful, | 58 // Override a previously registered function. Returns true if successful, |
| 55 // false if no such function was registered. | 59 // false if no such function was registered. |
| 56 static bool OverrideFunction(const std::string& name, | 60 static bool OverrideFunction(const std::string& name, |
| 57 ExtensionFunctionFactory factory); | 61 ExtensionFunctionFactory factory); |
| 58 | 62 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 71 void HandleRequest(const std::string& name, const Value* args, | 75 void HandleRequest(const std::string& name, const Value* args, |
| 72 int request_id, bool has_callback); | 76 int request_id, bool has_callback); |
| 73 | 77 |
| 74 // Send a response to a function. | 78 // Send a response to a function. |
| 75 void SendResponse(ExtensionFunction* api, bool success); | 79 void SendResponse(ExtensionFunction* api, bool success); |
| 76 | 80 |
| 77 // Gets the browser extension functions should operate relative to. For | 81 // Gets the browser extension functions should operate relative to. For |
| 78 // example, for positioning windows, or alert boxes, or creating tabs. | 82 // example, for positioning windows, or alert boxes, or creating tabs. |
| 79 Browser* GetBrowser(); | 83 Browser* GetBrowser(); |
| 80 | 84 |
| 85 // Get the extension popup hosting environment for the ExtensionHost |
| 86 // or ExtensionDOMUI associted with this dispatcher. |
| 87 ExtensionPopupHost* GetPopupHost(); |
| 88 |
| 81 // Gets the ExtensionHost associated with this object. In the case of | 89 // Gets the ExtensionHost associated with this object. In the case of |
| 82 // tab hosted extension pages, this will return NULL. | 90 // tab hosted extension pages, this will return NULL. |
| 83 ExtensionHost* GetExtensionHost(); | 91 ExtensionHost* GetExtensionHost(); |
| 84 | 92 |
| 93 // Gets the ExtensionDOMUI associated with this object. In the case of |
| 94 // non-tab-hosted extension pages, this will return NULL. |
| 95 ExtensionDOMUI* GetExtensionDOMUI(); |
| 96 |
| 85 // Gets the extension the function is being invoked by. This should not ever | 97 // Gets the extension the function is being invoked by. This should not ever |
| 86 // return NULL. | 98 // return NULL. |
| 87 Extension* GetExtension(); | 99 Extension* GetExtension(); |
| 88 | 100 |
| 89 // Handle a malformed message. Possibly the result of an attack, so kill | 101 // Handle a malformed message. Possibly the result of an attack, so kill |
| 90 // the renderer. | 102 // the renderer. |
| 91 void HandleBadMessage(ExtensionFunction* api); | 103 void HandleBadMessage(ExtensionFunction* api); |
| 92 | 104 |
| 93 // Gets the URL for the view we're displaying. | 105 // Gets the URL for the view we're displaying. |
| 94 const GURL& url() { return url_; } | 106 const GURL& url() { return url_; } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 113 | 125 |
| 114 // AutomationExtensionFunction requires access to the RenderViewHost | 126 // AutomationExtensionFunction requires access to the RenderViewHost |
| 115 // associated with us. We make it a friend rather than exposing the | 127 // associated with us. We make it a friend rather than exposing the |
| 116 // RenderViewHost as a public method as we wouldn't want everyone to | 128 // RenderViewHost as a public method as we wouldn't want everyone to |
| 117 // start assuming a 1:1 relationship between us and RenderViewHost, | 129 // start assuming a 1:1 relationship between us and RenderViewHost, |
| 118 // whereas AutomationExtensionFunction is by necessity "tight" with us. | 130 // whereas AutomationExtensionFunction is by necessity "tight" with us. |
| 119 friend class AutomationExtensionFunction; | 131 friend class AutomationExtensionFunction; |
| 120 }; | 132 }; |
| 121 | 133 |
| 122 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ | 134 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ |
| OLD | NEW |