| 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 <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 13 #include "googleurl/src/gurl.h" |
| 12 | 14 |
| 13 class Browser; | 15 class Browser; |
| 14 class ExtensionFunction; | 16 class ExtensionFunction; |
| 15 class Profile; | 17 class Profile; |
| 16 class RenderViewHost; | 18 class RenderViewHost; |
| 17 class RenderViewHostDelegate; | 19 class RenderViewHostDelegate; |
| 18 | 20 |
| 19 // A factory function for creating new ExtensionFunction instances. | 21 // A factory function for creating new ExtensionFunction instances. |
| 20 typedef ExtensionFunction* (*ExtensionFunctionFactory)(); | 22 typedef ExtensionFunction* (*ExtensionFunctionFactory)(); |
| 21 | 23 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 40 static void GetAllFunctionNames(std::vector<std::string>* names); | 42 static void GetAllFunctionNames(std::vector<std::string>* names); |
| 41 | 43 |
| 42 // Override a previously registered function. Returns true if successful, | 44 // Override a previously registered function. Returns true if successful, |
| 43 // false if no such function was registered. | 45 // false if no such function was registered. |
| 44 static bool OverrideFunction(const std::string& name, | 46 static bool OverrideFunction(const std::string& name, |
| 45 ExtensionFunctionFactory factory); | 47 ExtensionFunctionFactory factory); |
| 46 | 48 |
| 47 // Resets all functions to their initial implementation. | 49 // Resets all functions to their initial implementation. |
| 48 static void ResetFunctions(); | 50 static void ResetFunctions(); |
| 49 | 51 |
| 52 // Retrieves a vector of all EFD instances. |
| 53 static std::set<ExtensionFunctionDispatcher*>* all_instances(); |
| 54 |
| 50 ExtensionFunctionDispatcher(RenderViewHost* render_view_host, | 55 ExtensionFunctionDispatcher(RenderViewHost* render_view_host, |
| 51 Delegate* delegate, | 56 Delegate* delegate, |
| 52 const std::string& extension_id); | 57 const GURL& url); |
| 53 ~ExtensionFunctionDispatcher(); | 58 ~ExtensionFunctionDispatcher(); |
| 54 | 59 |
| 55 // Handle a request to execute an extension function. | 60 // Handle a request to execute an extension function. |
| 56 void HandleRequest(const std::string& name, const std::string& args, | 61 void HandleRequest(const std::string& name, const std::string& args, |
| 57 int request_id, bool has_callback); | 62 int request_id, bool has_callback); |
| 58 | 63 |
| 59 // Send a response to a function. | 64 // Send a response to a function. |
| 60 void SendResponse(ExtensionFunction* api, bool success); | 65 void SendResponse(ExtensionFunction* api, bool success); |
| 61 | 66 |
| 62 // Gets the browser extension functions should operate relative to. For | 67 // Gets the browser extension functions should operate relative to. For |
| 63 // example, for positioning windows, or alert boxes, or creating tabs. | 68 // example, for positioning windows, or alert boxes, or creating tabs. |
| 64 Browser* GetBrowser(); | 69 Browser* GetBrowser(); |
| 65 | 70 |
| 66 // Handle a malformed message. Possibly the result of an attack, so kill | 71 // Handle a malformed message. Possibly the result of an attack, so kill |
| 67 // the renderer. | 72 // the renderer. |
| 68 void HandleBadMessage(ExtensionFunction* api); | 73 void HandleBadMessage(ExtensionFunction* api); |
| 69 | 74 |
| 75 // Gets the URL for the view we're displaying. |
| 76 const GURL& url() { return url_; } |
| 77 |
| 70 // Gets the ID for this extension. | 78 // Gets the ID for this extension. |
| 71 std::string extension_id() { return extension_id_; } | 79 const std::string extension_id() { return url_.host(); } |
| 72 | 80 |
| 73 // The profile that this dispatcher is associated with. | 81 // The profile that this dispatcher is associated with. |
| 74 Profile* profile(); | 82 Profile* profile(); |
| 75 | 83 |
| 84 // The RenderViewHost this dispatcher is associated with. |
| 85 RenderViewHost* render_view_host() { return render_view_host_; } |
| 86 |
| 76 private: | 87 private: |
| 77 RenderViewHost* render_view_host_; | 88 RenderViewHost* render_view_host_; |
| 78 | 89 |
| 79 Delegate* delegate_; | 90 Delegate* delegate_; |
| 80 | 91 |
| 81 std::string extension_id_; | 92 GURL url_; |
| 82 | 93 |
| 83 scoped_refptr<Peer> peer_; | 94 scoped_refptr<Peer> peer_; |
| 84 | 95 |
| 85 // AutomationExtensionFunction requires access to the RenderViewHost | 96 // AutomationExtensionFunction requires access to the RenderViewHost |
| 86 // associated with us. We make it a friend rather than exposing the | 97 // associated with us. We make it a friend rather than exposing the |
| 87 // RenderViewHost as a public method as we wouldn't want everyone to | 98 // RenderViewHost as a public method as we wouldn't want everyone to |
| 88 // start assuming a 1:1 relationship between us and RenderViewHost, | 99 // start assuming a 1:1 relationship between us and RenderViewHost, |
| 89 // whereas AutomationExtensionFunction is by necessity "tight" with us. | 100 // whereas AutomationExtensionFunction is by necessity "tight" with us. |
| 90 friend class AutomationExtensionFunction; | 101 friend class AutomationExtensionFunction; |
| 91 }; | 102 }; |
| 92 | 103 |
| 93 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ | 104 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_DISPATCHER_H_ |
| OLD | NEW |