summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_function.h
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-15 22:58:33 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-15 22:58:33 +0000
commitb83e4600fc1c2f1c42598f8d89dbd36d9415309d (patch)
tree4b2ee497813a59a91105f91f6a5329224da18eac /chrome/browser/extensions/extension_function.h
parenta9a2668386addfa40ff262005d396468f54b99e2 (diff)
downloadchromium_src-b83e4600fc1c2f1c42598f8d89dbd36d9415309d.zip
chromium_src-b83e4600fc1c2f1c42598f8d89dbd36d9415309d.tar.gz
chromium_src-b83e4600fc1c2f1c42598f8d89dbd36d9415309d.tar.bz2
First step to enable end-to-end testing of extensions through the
automation interface. This adds a method to turn on automation of extension API functions, plumbing that redirects API requests through the automation interface when appropriate, and a couple of UITests that exercise the functionality. See http://codereview.chromium.org/113277 for the original review. Review URL: http://codereview.chromium.org/115427 Patch from Joi Sigurdsson <joi.sigurdsson@gmail.com>. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16207 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_function.h')
-rw-r--r--chrome/browser/extensions/extension_function.h81
1 files changed, 55 insertions, 26 deletions
diff --git a/chrome/browser/extensions/extension_function.h b/chrome/browser/extensions/extension_function.h
index b9074b7..cbe85b9 100644
--- a/chrome/browser/extensions/extension_function.h
+++ b/chrome/browser/extensions/extension_function.h
@@ -20,31 +20,71 @@ class Profile;
} \
} while (0)
-// Base class for an extension function.
-// TODO(aa): This will have to become reference counted when we introduce APIs
-// that live beyond a single stack frame.
+// Abstract base class for extension functions the ExtensionFunctionDispatcher
+// knows how to dispatch to.
+//
+// TODO(aa): This will have to become reference counted when we introduce
+// APIs that live beyond a single stack frame.
class ExtensionFunction {
public:
- ExtensionFunction() : bad_message_(false) {}
- virtual ~ExtensionFunction() {}
+ ExtensionFunction() : request_id_(-1), has_callback_(false) {}
+
+ // Specifies the name of the function.
+ virtual void SetName(const std::string& name) { }
+
+ // Specifies the raw arguments to the function, as a JSON-encoded string.
+ virtual void SetArgs(const std::string& args) = 0;
+
+ // Retrieves the results of the function as a JSON-encoded string (may
+ // be empty).
+ virtual const std::string GetResult() = 0;
+
+ // Retrieves any error string from the function.
+ virtual const std::string GetError() = 0;
void set_dispatcher(ExtensionFunctionDispatcher* dispatcher) {
dispatcher_ = dispatcher;
}
- void set_args(Value* args) { args_ = args; }
void set_request_id(int request_id) { request_id_ = request_id; }
int request_id() { return request_id_; }
- Value* result() { return result_.get(); }
- const std::string& error() { return error_; }
-
- void set_has_callback(bool has_callback) { has_callback_ = has_callback; }
+ void set_has_callback(bool has_callback) { has_callback_ = has_callback; }
bool has_callback() { return has_callback_; }
- // Execute the API. Clients should call set_args() and set_callback_id()
- // before calling this method. Derived classes should populate result_ and
- // error_ before returning.
+ // Execute the API. Clients should call set_raw_args() and
+ // set_request_id() before calling this method. Derived classes should be
+ // ready to return raw_result() and error() before returning from this
+ // function.
+ virtual void Run() = 0;
+
+ protected:
+ // The dispatcher that will service this extension function call.
+ ExtensionFunctionDispatcher* dispatcher_;
+
+ // Id of this request, used to map the response back to the caller.
+ int request_id_;
+
+ // True if the js caller provides a callback function to receive the response
+ // of this call.
+ bool has_callback_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ExtensionFunction);
+};
+
+// Base class for an extension function that runs asynchronously *relative to
+// the browser's UI thread*.
+// TODO(aa) Remove this extra level of inheritance once the browser stops
+// parsing JSON (and instead uses custom serialization of Value objects).
+class AsyncExtensionFunction : public ExtensionFunction {
+ public:
+ AsyncExtensionFunction() : bad_message_(false) {}
+ virtual ~AsyncExtensionFunction() {}
+
+ virtual void SetArgs(const std::string& args);
+ virtual const std::string GetResult();
+ virtual const std::string GetError() { return error_; }
virtual void Run() = 0;
protected:
@@ -69,21 +109,10 @@ class ExtensionFunction {
// returning. The calling renderer process will be killed.
bool bad_message_;
- // The dispatcher that will service this extension function call.
- ExtensionFunctionDispatcher* dispatcher_;
-
private:
- // Id of this request, used to map the response back to the caller.
- int request_id_;
-
- // True if the js caller provides a callback function to receive the response
- // of this call.
- bool has_callback_;
-
- DISALLOW_COPY_AND_ASSIGN(ExtensionFunction);
+ DISALLOW_COPY_AND_ASSIGN(AsyncExtensionFunction);
};
-
// A SyncExtensionFunction is an ExtensionFunction that runs synchronously
// *relative to the browser's UI thread*. Note that this has nothing to do with
// running synchronously relative to the extension process. From the extension
@@ -91,7 +120,7 @@ class ExtensionFunction {
//
// This kind of function is convenient for implementing simple APIs that just
// need to interact with things on the browser UI thread.
-class SyncExtensionFunction : public ExtensionFunction {
+class SyncExtensionFunction : public AsyncExtensionFunction {
public:
SyncExtensionFunction() {}