本文整理汇总了C++中WorkerPrivate::AddFeature方法的典型用法代码示例。如果您正苦于以下问题:C++ WorkerPrivate::AddFeature方法的具体用法?C++ WorkerPrivate::AddFeature怎么用?C++ WorkerPrivate::AddFeature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorkerPrivate
的用法示例。
在下文中一共展示了WorkerPrivate::AddFeature方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IDBOpenDBRequest
// static
already_AddRefed<IDBOpenDBRequest>
IDBOpenDBRequest::CreateForJS(IDBFactory* aFactory,
JS::Handle<JSObject*> aScriptOwner)
{
MOZ_ASSERT(aFactory);
aFactory->AssertIsOnOwningThread();
MOZ_ASSERT(aScriptOwner);
nsRefPtr<IDBOpenDBRequest> request = new IDBOpenDBRequest(aFactory, nullptr);
CaptureCaller(request->mFilename, &request->mLineNo);
request->SetScriptOwner(aScriptOwner);
if (!NS_IsMainThread()) {
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(workerPrivate);
workerPrivate->AssertIsOnWorkerThread();
JSContext* cx = workerPrivate->GetJSContext();
MOZ_ASSERT(cx);
nsAutoPtr<WorkerFeature> feature(new WorkerFeature(workerPrivate));
if (NS_WARN_IF(!workerPrivate->AddFeature(cx, feature))) {
return nullptr;
}
request->mWorkerFeature = Move(feature);
}
return request.forget();
}
示例2: ConnectToPBackground
void
MessagePort::Initialize(const nsID& aUUID,
const nsID& aDestinationUUID,
uint32_t aSequenceID, bool mNeutered,
State aState, ErrorResult& aRv)
{
MOZ_ASSERT(mIdentifier);
mIdentifier->uuid() = aUUID;
mIdentifier->destinationUuid() = aDestinationUUID;
mIdentifier->sequenceId() = aSequenceID;
mState = aState;
mNextStep = eNextStepNone;
if (mNeutered) {
// If this port is neutered we don't want to keep it alive artificially nor
// we want to add listeners or workerFeatures.
mState = eStateDisentangled;
return;
}
if (mState == eStateEntangling) {
ConnectToPBackground();
} else {
MOZ_ASSERT(mState == eStateUnshippedEntangled);
}
// The port has to keep itself alive until it's entangled.
UpdateMustKeepAlive();
if (NS_IsMainThread()) {
MOZ_ASSERT(GetOwner());
MOZ_ASSERT(GetOwner()->IsInnerWindow());
mInnerID = GetOwner()->WindowID();
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->AddObserver(this, "inner-window-destroyed", false);
}
} else {
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(workerPrivate);
MOZ_ASSERT(!mWorkerFeature);
nsAutoPtr<WorkerFeature> feature(new MessagePortFeature(this));
JSContext* cx = workerPrivate->GetJSContext();
if (NS_WARN_IF(!workerPrivate->AddFeature(cx, feature))) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
mWorkerFeature = Move(feature);
}
}
示例3: InitializeRunnable
/* static */ already_AddRefed<BroadcastChannel>
BroadcastChannel::Constructor(const GlobalObject& aGlobal,
const nsAString& aChannel,
ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
// Window is null in workers.
nsAutoString origin;
PrincipalInfo principalInfo;
bool privateBrowsing = false;
WorkerPrivate* workerPrivate = nullptr;
if (NS_IsMainThread()) {
nsCOMPtr<nsIGlobalObject> incumbent = mozilla::dom::GetIncumbentGlobal();
if (!incumbent) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsIPrincipal* principal = incumbent->PrincipalOrNull();
if (!principal) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
bool isNullPrincipal;
aRv = principal->GetIsNullPrincipal(&isNullPrincipal);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
if (NS_WARN_IF(isNullPrincipal)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
GetOrigin(principal, origin, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
aRv = PrincipalToPrincipalInfo(principal, &principalInfo);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
nsIDocument* doc = window->GetExtantDoc();
if (doc) {
privateBrowsing = nsContentUtils::IsInPrivateBrowsing(doc);
// No bfcache when BroadcastChannel is used.
doc->DisallowBFCaching();
}
} else {
JSContext* cx = aGlobal.Context();
workerPrivate = GetWorkerPrivateFromContext(cx);
MOZ_ASSERT(workerPrivate);
nsRefPtr<InitializeRunnable> runnable =
new InitializeRunnable(workerPrivate, origin, principalInfo,
privateBrowsing, aRv);
runnable->Dispatch(cx);
}
if (aRv.Failed()) {
return nullptr;
}
nsRefPtr<BroadcastChannel> bc =
new BroadcastChannel(window, principalInfo, origin, aChannel,
privateBrowsing);
// Register this component to PBackground.
PBackgroundChild* actor = BackgroundChild::GetForCurrentThread();
if (actor) {
bc->ActorCreated(actor);
} else {
BackgroundChild::GetOrCreateForCurrentThread(bc);
}
if (!workerPrivate) {
MOZ_ASSERT(window);
MOZ_ASSERT(window->IsInnerWindow());
bc->mInnerID = window->WindowID();
// Register as observer for inner-window-destroyed.
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->AddObserver(bc, "inner-window-destroyed", false);
}
} else {
bc->mWorkerFeature = new BroadcastChannelFeature(bc);
JSContext* cx = workerPrivate->GetJSContext();
if (NS_WARN_IF(!workerPrivate->AddFeature(cx, bc->mWorkerFeature))) {
NS_WARNING("Failed to register the BroadcastChannel worker feature.");
bc->mWorkerFeature = nullptr;
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
//.........这里部分代码省略.........