Skip to content

Instantly share code, notes, and snippets.

@alivedise
Created August 6, 2013 09:46
Show Gist options
  • Select an option

  • Save alivedise/6163202 to your computer and use it in GitHub Desktop.

Select an option

Save alivedise/6163202 to your computer and use it in GitHub Desktop.
Bug 881797 WIP
diff --git a/dom/activities/src/Activity.cpp b/dom/activities/src/Activity.cpp
--- a/dom/activities/src/Activity.cpp
+++ b/dom/activities/src/Activity.cpp
@@ -60,31 +60,74 @@ Activity::Initialize(nsISupports* aOwner
nsString message =
NS_LITERAL_STRING("Can start activity from non user input or chrome code");
console->LogStringMessage(message.get());
return NS_OK;
}
+ // Reject the following Activity request if we're processing.
+ if (Activity::mProcessingActivity) {
+ nsCOMPtr<nsIDOMRequestService> rs =
+ do_GetService("@mozilla.org/dom/dom-request-service;1");
+ rs->FireErrorAsync(static_cast<DOMRequest*>(this),
+ NS_LITERAL_STRING("TooQuick"));
+
+ nsCOMPtr<nsIConsoleService> console(
+ do_GetService("@mozilla.org/consoleservice;1"));
+ NS_ENSURE_TRUE(console, NS_OK);
+
+ nsString message =
+ NS_LITERAL_STRING("activity request too quickly.");
+ console->LogStringMessage(message.get());
+
+ return NS_OK;
+ }
+
// Instantiate a JS proxy that will do the child <-> parent communication
// with the JS implementation of the backend.
nsresult rv;
mProxy = do_CreateInstance("@mozilla.org/dom/activities/proxy;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
mProxy->StartActivity(static_cast<nsIDOMDOMRequest*>(this), aOptions, window);
+ Activity::mProcessingActivity = true;
+
+ if (!mTimer)
+ {
+ mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
+ NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create a timer");
+ if (NS_SUCCEEDED(rv))
+ {
+ mTimer->InitWithFuncCallback(Activity::FireTimer, this, 1000,
+ nsITimer::TYPE_ONE_SHOT);
+ }
+ }
return NS_OK;
}
+void
+Activity::FireTimer(nsITimer* aTimer, void* aClosure)
+{
+ Activity::mProcessingActivity = false;
+}
+
Activity::~Activity()
{
if (mProxy) {
mProxy->Cleanup();
}
+
+ if (mTimer)
+ {
+ mTimer->Cancel();
+ mTimer = nullptr;
+ Activity::mProcessingActivity = false;
+ }
}
Activity::Activity()
: DOMRequest()
{
// Unfortunately we must explicitly declare the default constructor in order
// to prevent an implicitly deleted constructor in DOMRequest compile error
// in GCC 4.6.
diff --git a/dom/activities/src/Activity.h b/dom/activities/src/Activity.h
--- a/dom/activities/src/Activity.h
+++ b/dom/activities/src/Activity.h
@@ -4,16 +4,17 @@
#ifndef mozilla_dom_activities_Activity_h
#define mozilla_dom_activities_Activity_h
#include "DOMRequest.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "nsIActivityProxy.h"
#include "mozilla/Preferences.h"
+#include "nsITimer.h"
#define NS_DOMACTIVITY_CID \
{0x1c5b0930, 0xc90c, 0x4e9c, {0xaf, 0x4e, 0xb0, 0xb7, 0xa6, 0x59, 0xb4, 0xed}}
#define NS_DOMACTIVITY_CONTRACTID "@mozilla.org/dom/activity;1"
namespace mozilla {
namespace dom {
@@ -44,16 +45,19 @@ public:
Activity();
protected:
nsresult Initialize(nsISupports* aOwner,
nsIDOMMozActivityOptions* aOptions);
nsCOMPtr<nsIActivityProxy> mProxy;
+ nsCOMPtr<nsITimer> mTimer;
+ static bool mProcessingActivity;
+ static void FireTimer(nsITimer* aTimer, void* aClosure);
~Activity();
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_activities_Activity_h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment