Commit c1a1685d authored by tkent@chromium.org's avatar tkent@chromium.org

Support UseCounter in dedicated workers.

BUG=376039
R=haraken@chromium.org, sigbjornf@opera.com, tyoshino@chromium.org

Review URL: https://codereview.chromium.org/342103003

git-svn-id: svn://svn.chromium.org/blink/trunk@176511 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 89fa7447
......@@ -35,6 +35,7 @@
#include "core/frame/FrameConsole.h"
#include "core/frame/FrameHost.h"
#include "core/frame/LocalFrame.h"
#include "core/workers/WorkerGlobalScope.h"
#include "public/platform/Platform.h"
namespace WebCore {
......@@ -606,16 +607,26 @@ void UseCounter::count(const Document& document, Feature feature)
void UseCounter::count(const ExecutionContext* context, Feature feature)
{
if (!context || !context->isDocument())
if (!context)
return;
if (context->isDocument()) {
count(*toDocument(context), feature);
return;
}
if (context->isWorkerGlobalScope())
toWorkerGlobalScope(context)->countFeature(feature);
}
void UseCounter::countDeprecation(ExecutionContext* context, Feature feature)
{
if (!context || !context->isDocument())
if (!context)
return;
if (context->isDocument()) {
UseCounter::countDeprecation(*toDocument(context), feature);
return;
}
if (context->isWorkerGlobalScope())
toWorkerGlobalScope(context)->countDeprecation(feature);
}
void UseCounter::countDeprecation(const DOMWindow* window, Feature feature)
......
......@@ -278,7 +278,7 @@ public:
HTMLMediaElementSeekToFragmentStart = 281,
HTMLMediaElementPauseAtFragmentEnd = 282,
PrefixedWindowURL = 283,
PrefixedWorkerURL = 284,
PrefixedWorkerURL = 284, // This didn't work because of crbug.com/376039. Available since M37.
WindowOrientation = 285,
DOMStringListContains = 286,
DocumentCaptureEvents = 287,
......@@ -307,8 +307,8 @@ public:
NamedNodeMapGetNamedItemNS = 310,
NamedNodeMapSetNamedItemNS = 311,
NamedNodeMapRemoveNamedItemNS = 312,
OpenWebDatabaseInWorker = 313, // This doesn't work because of crbug.com/376039.
OpenWebDatabaseSyncInWorker = 314, // This doesn't work because of crbug.com/376039.
OpenWebDatabaseInWorker = 313, // This didn't work because of crbug.com/376039. Available since M37.
OpenWebDatabaseSyncInWorker = 314, // This didn't work because of crbug.com/376039. Available since M37.
PrefixedAllowFullscreenAttribute = 315,
XHRProgressEventPosition = 316,
XHRProgressEventTotalSize = 317,
......@@ -478,7 +478,8 @@ public:
// "count" sets the bit for this feature to 1. Repeated calls are ignored.
static void count(const Document&, Feature);
// This doesn't count for non-Document ExecutionContext.
// This doesn't count for ExecutionContexts for shared workers and service
// workers.
static void count(const ExecutionContext*, Feature);
void count(CSSParserContext, CSSPropertyID);
void count(Feature);
......@@ -486,8 +487,12 @@ public:
// "countDeprecation" sets the bit for this feature to 1, and sends a deprecation
// warning to the console. Repeated calls are ignored.
//
// Be considerate to developers' consoles: features should only send deprecation warnings
// when we're actively interested in removing them from the platform.
// Be considerate to developers' consoles: features should only send
// deprecation warnings when we're actively interested in removing them from
// the platform.
//
// The ExecutionContext* overload doesn't work for shared workers and
// service workers.
static void countDeprecation(const DOMWindow*, Feature);
static void countDeprecation(ExecutionContext*, Feature);
static void countDeprecation(const Document&, Feature);
......
......@@ -78,11 +78,45 @@ void DedicatedWorkerGlobalScope::importScripts(const Vector<String>& urls, Excep
thread()->workerObjectProxy().reportPendingActivity(hasPendingActivity());
}
DedicatedWorkerThread* DedicatedWorkerGlobalScope::thread()
DedicatedWorkerThread* DedicatedWorkerGlobalScope::thread() const
{
return static_cast<DedicatedWorkerThread*>(Base::thread());
}
class UseCounterTask : public ExecutionContextTask {
public:
static PassOwnPtr<UseCounterTask> createCount(UseCounter::Feature feature) { return adoptPtr(new UseCounterTask(feature, false)); }
static PassOwnPtr<UseCounterTask> createDeprecation(UseCounter::Feature feature) { return adoptPtr(new UseCounterTask(feature, true)); }
private:
UseCounterTask(UseCounter::Feature feature, bool isDeprecation)
: m_feature(feature)
, m_isDeprecation(isDeprecation)
{
}
virtual void performTask(ExecutionContext* context) OVERRIDE
{
if (m_isDeprecation)
UseCounter::countDeprecation(*toDocument(context), m_feature);
else
UseCounter::count(*toDocument(context), m_feature);
}
UseCounter::Feature m_feature;
bool m_isDeprecation;
};
void DedicatedWorkerGlobalScope::countFeature(UseCounter::Feature feature) const
{
thread()->workerObjectProxy().postTaskToMainExecutionContext(UseCounterTask::createCount(feature));
}
void DedicatedWorkerGlobalScope::countDeprecation(UseCounter::Feature feature) const
{
thread()->workerObjectProxy().postTaskToMainExecutionContext(UseCounterTask::createDeprecation(feature));
}
void DedicatedWorkerGlobalScope::trace(Visitor* visitor)
{
WorkerGlobalScope::trace(visitor);
......
......@@ -48,6 +48,8 @@ public:
virtual ~DedicatedWorkerGlobalScope();
virtual bool isDedicatedWorkerGlobalScope() const OVERRIDE { return true; }
virtual void countFeature(UseCounter::Feature) const OVERRIDE;
virtual void countDeprecation(UseCounter::Feature) const OVERRIDE;
// Overridden to allow us to check our pending activity after executing imported script.
virtual void importScripts(const Vector<String>& urls, ExceptionState&) OVERRIDE;
......@@ -59,7 +61,7 @@ public:
DEFINE_ATTRIBUTE_EVENT_LISTENER(message);
DedicatedWorkerThread* thread();
DedicatedWorkerThread* thread() const;
virtual void trace(Visitor*) OVERRIDE;
......
......@@ -322,6 +322,16 @@ WorkerEventQueue* WorkerGlobalScope::eventQueue() const
return m_eventQueue.get();
}
void WorkerGlobalScope::countFeature(UseCounter::Feature) const
{
// FIXME: How should we count features for shared/service workers?
}
void WorkerGlobalScope::countDeprecation(UseCounter::Feature) const
{
// FIXME: How should we count features for shared/service workers?
}
void WorkerGlobalScope::trace(Visitor* visitor)
{
visitor->trace(m_console);
......
......@@ -33,6 +33,7 @@
#include "core/events/EventListener.h"
#include "core/events/EventTarget.h"
#include "core/frame/DOMWindowBase64.h"
#include "core/frame/UseCounter.h"
#include "core/frame/csp/ContentSecurityPolicy.h"
#include "core/workers/WorkerEventQueue.h"
#include "platform/heap/Handle.h"
......@@ -70,6 +71,8 @@ namespace WebCore {
virtual bool isSharedWorkerGlobalScope() const { return false; }
virtual bool isDedicatedWorkerGlobalScope() const { return false; }
virtual bool isServiceWorkerGlobalScope() const { return false; }
virtual void countFeature(UseCounter::Feature) const;
virtual void countDeprecation(UseCounter::Feature) const;
const KURL& url() const { return m_url; }
KURL completeURL(const String&) const;
......
......@@ -49,6 +49,11 @@ void WorkerObjectProxy::postMessageToWorkerObject(PassRefPtr<SerializedScriptVal
m_executionContext->postTask(bind(&WorkerMessagingProxy::postMessageToWorkerObject, m_messagingProxy, message, channels));
}
void WorkerObjectProxy::postTaskToMainExecutionContext(PassOwnPtr<ExecutionContextTask> task)
{
m_executionContext->postTask(task);
}
void WorkerObjectProxy::confirmMessageFromWorkerObject(bool hasPendingActivity)
{
m_executionContext->postTask(bind(&WorkerMessagingProxy::confirmMessageFromWorkerObject, m_messagingProxy, hasPendingActivity));
......
......@@ -39,6 +39,7 @@
namespace WebCore {
class ExecutionContext;
class ExecutionContextTask;
class WorkerMessagingProxy;
// A proxy to talk to the worker object. This object is created on the
......@@ -53,7 +54,7 @@ public:
virtual ~WorkerObjectProxy() { }
void postMessageToWorkerObject(PassRefPtr<SerializedScriptValue>, PassOwnPtr<MessagePortChannelArray>);
void postTaskToMainExecutionContext(PassOwnPtr<ExecutionContextTask>);
void confirmMessageFromWorkerObject(bool hasPendingActivity);
void reportPendingActivity(bool hasPendingActivity);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment