summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_function.h
diff options
context:
space:
mode:
authorrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-08 20:37:43 +0000
committerrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-08 20:37:43 +0000
commita7664e14960e48758f985b4de48607cb197b78b6 (patch)
tree9d7083e85f65bc4798c48e4effc437feae0df7c1 /chrome/browser/extensions/extension_function.h
parent01a22e2616272096c5f83bff8183ae48ec5e8380 (diff)
downloadchromium_src-a7664e14960e48758f985b4de48607cb197b78b6.zip
chromium_src-a7664e14960e48758f985b4de48607cb197b78b6.tar.gz
chromium_src-a7664e14960e48758f985b4de48607cb197b78b6.tar.bz2
Move GetExtension() from ExtensionFunctionDispatcher to ExtensionFunction.
EFD's can expire during the processing of AsyncExtensionFunctions, so this change enables them to retain access to their extension to complete their work. This fixes a bug in executeScript where when a file source was used, but the call was made from a popup which which had closed, by the time the file source was loaded, the EFD had been destroyed. Go boom. BUG=32431 TEST=All tests should pass Review URL: http://codereview.chromium.org/1549026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43999 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_function.h')
-rw-r--r--chrome/browser/extensions/extension_function.h36
1 files changed, 26 insertions, 10 deletions
diff --git a/chrome/browser/extensions/extension_function.h b/chrome/browser/extensions/extension_function.h
index 1727ae0..0e51321 100644
--- a/chrome/browser/extensions/extension_function.h
+++ b/chrome/browser/extensions/extension_function.h
@@ -12,6 +12,8 @@
#include "base/scoped_ptr.h"
#include "base/ref_counted.h"
#include "chrome/browser/extensions/extension_function_dispatcher.h"
+#include "chrome/browser/extensions/extensions_service.h"
+#include "chrome/browser/profile.h"
class ExtensionFunctionDispatcher;
class Profile;
@@ -46,6 +48,17 @@ class ExtensionFunction : public base::RefCounted<ExtensionFunction> {
void set_name(const std::string& name) { name_ = name; }
const std::string name() const { return name_; }
+ // Set the profile which contains the extension that has originated this
+ // function call.
+ void set_profile(Profile* profile) { profile_ = profile; }
+ Profile* profile() const { return profile_; }
+
+ // Set the id of this function call's extension.
+ void set_extension_id(std::string extension_id) {
+ extension_id_ = extension_id;
+ }
+ std::string extension_id() const { return extension_id_; }
+
// Specifies the raw arguments to the function, as a JSON value.
virtual void SetArgs(const Value* args) = 0;
@@ -92,12 +105,12 @@ class ExtensionFunction : public base::RefCounted<ExtensionFunction> {
virtual ~ExtensionFunction() {}
// Gets the extension that called this function. This can return NULL for
- // async functions.
+ // async functions, for example if the extension is unloaded while the
+ // function is running.
Extension* GetExtension() {
- if (dispatcher())
- return dispatcher()->GetExtension();
- else
- return NULL;
+ ExtensionsService* service = profile_->GetExtensionsService();
+ DCHECK(service);
+ return service->GetExtensionById(extension_id_, false);
}
// Gets the "current" browser, if any.
@@ -126,6 +139,12 @@ class ExtensionFunction : public base::RefCounted<ExtensionFunction> {
// Id of this request, used to map the response back to the caller.
int request_id_;
+ // The Profile of this function's extension.
+ Profile* profile_;
+
+ // The id of this function's extension.
+ std::string extension_id_;
+
// The name of this function.
std::string name_;
@@ -176,13 +195,10 @@ class AsyncExtensionFunction : public ExtensionFunction {
return static_cast<DictionaryValue*>(args_.get());
}
+ // Return true if the argument to this function at |index| was provided and
+ // is non-null.
bool HasOptionalArgument(size_t index);
- // Note: After Run() returns, dispatcher() can be NULL. Since these getters
- // rely on dispatcher(), make sure it is valid before using them.
- std::string extension_id();
- Profile* profile() const;
-
// The arguments to the API. Only non-null if argument were specified.
scoped_ptr<Value> args_;