dom/workers/WorkerScope.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/workers/WorkerScope.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,169 @@
     1.4 +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef mozilla_dom_workerscope_h__
    1.10 +#define mozilla_dom_workerscope_h__
    1.11 +
    1.12 +#include "Workers.h"
    1.13 +#include "mozilla/DOMEventTargetHelper.h"
    1.14 +
    1.15 +namespace mozilla {
    1.16 +namespace dom {
    1.17 +
    1.18 +class Console;
    1.19 +class Function;
    1.20 +
    1.21 +} // namespace dom
    1.22 +} // namespace mozilla
    1.23 +
    1.24 +BEGIN_WORKERS_NAMESPACE
    1.25 +
    1.26 +class WorkerPrivate;
    1.27 +class WorkerLocation;
    1.28 +class WorkerNavigator;
    1.29 +
    1.30 +class WorkerGlobalScope : public DOMEventTargetHelper,
    1.31 +                          public nsIGlobalObject
    1.32 +{
    1.33 +  nsRefPtr<Console> mConsole;
    1.34 +  nsRefPtr<WorkerLocation> mLocation;
    1.35 +  nsRefPtr<WorkerNavigator> mNavigator;
    1.36 +
    1.37 +protected:
    1.38 +  WorkerPrivate* mWorkerPrivate;
    1.39 +
    1.40 +  WorkerGlobalScope(WorkerPrivate* aWorkerPrivate);
    1.41 +  virtual ~WorkerGlobalScope();
    1.42 +
    1.43 +public:
    1.44 +  virtual JSObject*
    1.45 +  WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    1.46 +
    1.47 +  virtual JSObject*
    1.48 +  WrapGlobalObject(JSContext* aCx) = 0;
    1.49 +
    1.50 +  virtual JSObject*
    1.51 +  GetGlobalJSObject(void) MOZ_OVERRIDE
    1.52 +  {
    1.53 +    return GetWrapper();
    1.54 +  }
    1.55 +
    1.56 +  NS_DECL_ISUPPORTS_INHERITED
    1.57 +  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WorkerGlobalScope,
    1.58 +                                                         DOMEventTargetHelper)
    1.59 +
    1.60 +  already_AddRefed<WorkerGlobalScope>
    1.61 +  Self()
    1.62 +  {
    1.63 +    return nsRefPtr<WorkerGlobalScope>(this).forget();
    1.64 +  }
    1.65 +
    1.66 +  already_AddRefed<Console>
    1.67 +  GetConsole();
    1.68 +
    1.69 +  already_AddRefed<WorkerLocation>
    1.70 +  Location();
    1.71 +
    1.72 +  already_AddRefed<WorkerNavigator>
    1.73 +  Navigator();
    1.74 +
    1.75 +  already_AddRefed<WorkerNavigator>
    1.76 +  GetExistingNavigator() const;
    1.77 +
    1.78 +  void
    1.79 +  Close(JSContext* aCx);
    1.80 +
    1.81 +  OnErrorEventHandlerNonNull*
    1.82 +  GetOnerror();
    1.83 +  void
    1.84 +  SetOnerror(OnErrorEventHandlerNonNull* aHandler);
    1.85 +
    1.86 +  void
    1.87 +  ImportScripts(JSContext* aCx, const Sequence<nsString>& aScriptURLs,
    1.88 +                ErrorResult& aRv);
    1.89 +
    1.90 +  int32_t
    1.91 +  SetTimeout(JSContext* aCx, Function& aHandler, const int32_t aTimeout,
    1.92 +             const Sequence<JS::Value>& aArguments, ErrorResult& aRv);
    1.93 +  int32_t
    1.94 +  SetTimeout(JSContext* /* unused */, const nsAString& aHandler,
    1.95 +             const int32_t aTimeout, const Sequence<JS::Value>& /* unused */,
    1.96 +             ErrorResult& aRv);
    1.97 +  void
    1.98 +  ClearTimeout(int32_t aHandle, ErrorResult& aRv);
    1.99 +  int32_t
   1.100 +  SetInterval(JSContext* aCx, Function& aHandler,
   1.101 +              const Optional<int32_t>& aTimeout,
   1.102 +              const Sequence<JS::Value>& aArguments, ErrorResult& aRv);
   1.103 +  int32_t
   1.104 +  SetInterval(JSContext* /* unused */, const nsAString& aHandler,
   1.105 +              const Optional<int32_t>& aTimeout,
   1.106 +              const Sequence<JS::Value>& /* unused */, ErrorResult& aRv);
   1.107 +  void
   1.108 +  ClearInterval(int32_t aHandle, ErrorResult& aRv);
   1.109 +
   1.110 +  void
   1.111 +  Atob(const nsAString& aAtob, nsAString& aOutput, ErrorResult& aRv) const;
   1.112 +  void
   1.113 +  Btoa(const nsAString& aBtoa, nsAString& aOutput, ErrorResult& aRv) const;
   1.114 +
   1.115 +  IMPL_EVENT_HANDLER(online)
   1.116 +  IMPL_EVENT_HANDLER(offline)
   1.117 +  IMPL_EVENT_HANDLER(close)
   1.118 +
   1.119 +  void
   1.120 +  Dump(const Optional<nsAString>& aString) const;
   1.121 +};
   1.122 +
   1.123 +class DedicatedWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope
   1.124 +{
   1.125 +  ~DedicatedWorkerGlobalScope() { }
   1.126 +
   1.127 +public:
   1.128 +  DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate);
   1.129 +
   1.130 +  static bool
   1.131 +  Visible(JSContext* aCx, JSObject* aObj);
   1.132 +
   1.133 +  virtual JSObject*
   1.134 +  WrapGlobalObject(JSContext* aCx) MOZ_OVERRIDE;
   1.135 +
   1.136 +  void
   1.137 +  PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
   1.138 +              const Optional<Sequence<JS::Value>>& aTransferable,
   1.139 +              ErrorResult& aRv);
   1.140 +
   1.141 +  IMPL_EVENT_HANDLER(message)
   1.142 +};
   1.143 +
   1.144 +class SharedWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope
   1.145 +{
   1.146 +  const nsCString mName;
   1.147 +
   1.148 +  ~SharedWorkerGlobalScope() { }
   1.149 +
   1.150 +public:
   1.151 +  SharedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate,
   1.152 +                          const nsCString& aName);
   1.153 +
   1.154 +  static bool
   1.155 +  Visible(JSContext* aCx, JSObject* aObj);
   1.156 +
   1.157 +  virtual JSObject*
   1.158 +  WrapGlobalObject(JSContext* aCx) MOZ_OVERRIDE;
   1.159 +
   1.160 +  void GetName(DOMString& aName) const {
   1.161 +    aName.AsAString() = NS_ConvertUTF8toUTF16(mName);
   1.162 +  }
   1.163 +
   1.164 +  IMPL_EVENT_HANDLER(connect)
   1.165 +};
   1.166 +
   1.167 +JSObject*
   1.168 +CreateGlobalScope(JSContext* aCx);
   1.169 +
   1.170 +END_WORKERS_NAMESPACE
   1.171 +
   1.172 +#endif /* mozilla_dom_workerscope_h__ */

mercurial