Commit 84f686de authored by haraken's avatar haraken Committed by Commit bot

Supplement should have a Member to the corresponding Supplementable object

Currently a lot of Supplement objects are observing ContextLifecycleObservers
because they cannot access the corresponding Supplementable object, which is silly.
This CL adds a strong reference from a Supplement object to the corresponding
Supplementable object. That way we can remove a bunch of ContextLifecycleObservers
from Supplement objects in follow-up CLs.

MSVC requires to include X.h when inheriting from Supplement<X>.
This CL adds the necessary include statements.

BUG=610176

Review-Url: https://codereview.chromium.org/2606643002
Cr-Commit-Position: refs/heads/master@{#440733}
parent b80f567c
......@@ -21,6 +21,7 @@
#define Navigator_h
#include "bindings/core/v8/ScriptWrappable.h"
#include "core/CoreExport.h"
#include "core/frame/DOMWindowProperty.h"
#include "core/frame/NavigatorCPU.h"
#include "core/frame/NavigatorID.h"
......@@ -36,14 +37,14 @@ class LocalFrame;
typedef int ExceptionCode;
class Navigator final : public GarbageCollected<Navigator>,
public NavigatorCPU,
public NavigatorID,
public NavigatorLanguage,
public NavigatorOnLine,
public ScriptWrappable,
public DOMWindowProperty,
public Supplementable<Navigator> {
class CORE_EXPORT Navigator final : public GarbageCollected<Navigator>,
public NavigatorCPU,
public NavigatorID,
public NavigatorLanguage,
public NavigatorOnLine,
public ScriptWrappable,
public DOMWindowProperty,
public Supplementable<Navigator> {
DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(Navigator);
......
......@@ -5,9 +5,11 @@
#ifndef NavigatorCPU_h
#define NavigatorCPU_h
#include "core/CoreExport.h"
namespace blink {
class NavigatorCPU {
class CORE_EXPORT NavigatorCPU {
public:
unsigned hardwareConcurrency() const;
};
......
......@@ -31,11 +31,12 @@
#ifndef NavigatorID_h
#define NavigatorID_h
#include "core/CoreExport.h"
#include "wtf/text/WTFString.h"
namespace blink {
class NavigatorID {
class CORE_EXPORT NavigatorID {
public:
String appCodeName();
String appName();
......
......@@ -5,11 +5,12 @@
#ifndef NavigatorLanguage_h
#define NavigatorLanguage_h
#include "core/CoreExport.h"
#include "wtf/text/AtomicString.h"
namespace blink {
class NavigatorLanguage {
class CORE_EXPORT NavigatorLanguage {
public:
NavigatorLanguage();
......
......@@ -31,11 +31,12 @@
#ifndef NavigatorOnLine_h
#define NavigatorOnLine_h
#include "core/CoreExport.h"
#include "core/page/NetworkStateNotifier.h"
namespace blink {
class NavigatorOnLine {
class CORE_EXPORT NavigatorOnLine {
public:
bool onLine() { return networkStateNotifier().onLine(); }
};
......
......@@ -30,6 +30,7 @@
#define Screen_h
#include "bindings/core/v8/ScriptWrappable.h"
#include "core/CoreExport.h"
#include "core/dom/ContextLifecycleObserver.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......@@ -38,10 +39,10 @@ namespace blink {
class LocalFrame;
class Screen final : public GarbageCollected<Screen>,
public ScriptWrappable,
public ContextClient,
public Supplementable<Screen> {
class CORE_EXPORT Screen final : public GarbageCollected<Screen>,
public ScriptWrappable,
public ContextClient,
public Supplementable<Screen> {
DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(Screen);
......
......@@ -37,7 +37,9 @@
#include "bindings/core/v8/ScriptState.h"
#include "core/fileapi/FileReaderLoader.h"
#include "core/fileapi/FileReaderLoaderClient.h"
#include "core/frame/LocalDOMWindow.h"
#include "core/imagebitmap/ImageBitmapOptions.h"
#include "core/workers/WorkerGlobalScope.h"
#include "platform/Supplementable.h"
#include "platform/geometry/IntRect.h"
#include "third_party/skia/include/core/SkRefCnt.h"
......
......@@ -6,6 +6,7 @@
#define OriginTrialContext_h
#include "core/CoreExport.h"
#include "core/dom/ExecutionContext.h"
#include "platform/Supplementable.h"
#include "wtf/HashSet.h"
#include "wtf/Vector.h"
......
......@@ -7,6 +7,7 @@
#include "core/CoreExport.h"
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/LocalDOMWindow.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
#include "wtf/Noncopyable.h"
......
......@@ -30,6 +30,7 @@
#ifndef SharedWorkerPerformance_h
#define SharedWorkerPerformance_h
#include "core/workers/SharedWorker.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -32,6 +32,7 @@
#define WorkerGlobalScopePerformance_h
#include "core/timing/WorkerPerformance.h"
#include "core/workers/WorkerGlobalScope.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -42,8 +42,8 @@ class WorkerClients;
// This is created on the main thread, passed to the worker thread and
// attached to WorkerGlobalScope when it is created.
// This class can be used to provide "client" implementations to Workers.
class WorkerClients final : public GarbageCollected<WorkerClients>,
public Supplementable<WorkerClients> {
class CORE_EXPORT WorkerClients final : public GarbageCollected<WorkerClients>,
public Supplementable<WorkerClients> {
USING_GARBAGE_COLLECTED_MIXIN(WorkerClients);
WTF_MAKE_NONCOPYABLE(WorkerClients);
......
......@@ -27,6 +27,7 @@
#define WorkerNavigator_h
#include "bindings/core/v8/ScriptWrappable.h"
#include "core/CoreExport.h"
#include "core/frame/NavigatorCPU.h"
#include "core/frame/NavigatorID.h"
#include "core/frame/NavigatorOnLine.h"
......@@ -36,12 +37,13 @@
namespace blink {
class WorkerNavigator final : public GarbageCollectedFinalized<WorkerNavigator>,
public ScriptWrappable,
public NavigatorCPU,
public NavigatorID,
public NavigatorOnLine,
public Supplementable<WorkerNavigator> {
class CORE_EXPORT WorkerNavigator final
: public GarbageCollectedFinalized<WorkerNavigator>,
public ScriptWrappable,
public NavigatorCPU,
public NavigatorID,
public NavigatorOnLine,
public Supplementable<WorkerNavigator> {
DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(WorkerNavigator);
......
......@@ -5,6 +5,7 @@
#ifndef ServiceWorkerRegistrationSync_h
#define ServiceWorkerRegistrationSync_h
#include "modules/serviceworkers/ServiceWorkerRegistration.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -5,6 +5,7 @@
#ifndef NavigatorBluetooth_h
#define NavigatorBluetooth_h
#include "core/frame/Navigator.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -5,6 +5,7 @@
#ifndef NavigatorBudget_h
#define NavigatorBudget_h
#include "core/frame/Navigator.h"
#include "platform/Supplementable.h"
namespace blink {
......
......@@ -5,6 +5,7 @@
#ifndef WorkerNavigatorBudget_h
#define WorkerNavigatorBudget_h
#include "core/workers/WorkerNavigator.h"
#include "platform/Supplementable.h"
#include "platform/heap/GarbageCollected.h"
#include "wtf/Noncopyable.h"
......
......@@ -6,6 +6,7 @@
#define WindowAnimationWorklet_h
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/LocalDOMWindow.h"
#include "modules/ModulesExport.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -32,6 +32,7 @@
#define DOMWindowCrypto_h
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/LocalDOMWindow.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -6,6 +6,7 @@
#define WindowPaintWorklet_h
#include "core/frame/DOMWindowProperty.h"
#include "core/frame/LocalDOMWindow.h"
#include "modules/ModulesExport.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -32,6 +32,7 @@
#define NavigatorDoNotTrack_h
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/Navigator.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
#include "wtf/text/WTFString.h"
......
......@@ -8,6 +8,7 @@
#include "core/EventTypeNames.h"
#include "core/dom/DOMTypedArray.h"
#include "core/events/EventTarget.h"
#include "core/html/HTMLMediaElement.h"
#include "modules/ModulesExport.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -28,6 +28,7 @@
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/LocalDOMWindow.h"
#include "core/frame/Navigator.h"
#include "core/frame/PlatformEventController.h"
#include "modules/ModulesExport.h"
#include "platform/AsyncMethodRunner.h"
......
......@@ -21,6 +21,7 @@
#define NavigatorGeolocation_h
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/Navigator.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -6,6 +6,7 @@
#define NavigatorInstalledApp_h
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/Navigator.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
#include "wtf/text/WTFString.h"
......
......@@ -5,6 +5,7 @@
#ifndef NavigatorUserMedia_h
#define NavigatorUserMedia_h
#include "core/frame/Navigator.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -6,6 +6,7 @@
#define NavigatorNetworkInformation_h
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/Navigator.h"
#include "platform/Supplementable.h"
namespace blink {
......
......@@ -5,6 +5,7 @@
#ifndef WorkerNavigatorNetworkInformation_h
#define WorkerNavigatorNetworkInformation_h
#include "core/workers/WorkerNavigator.h"
#include "platform/Supplementable.h"
namespace blink {
......
......@@ -5,6 +5,7 @@
#ifndef NavigatorNFC_h
#define NavigatorNFC_h
#include "core/frame/Navigator.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -5,6 +5,7 @@
#ifndef HTMLIFrameElementPayments_h
#define HTMLIFrameElementPayments_h
#include "core/html/HTMLIFrameElement.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -5,6 +5,7 @@
#ifndef PaymentAppServiceWorkerRegistration_h
#define PaymentAppServiceWorkerRegistration_h
#include "modules/serviceworkers/ServiceWorkerRegistration.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -5,6 +5,7 @@
#ifndef NavigatorPermissions_h
#define NavigatorPermissions_h
#include "core/frame/Navigator.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -5,6 +5,7 @@
#ifndef WorkerNavigatorPermissions_h
#define WorkerNavigatorPermissions_h
#include "core/workers/WorkerNavigator.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -6,6 +6,7 @@
#define NavigatorPlugins_h
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/Navigator.h"
#include "platform/Supplementable.h"
namespace blink {
......
......@@ -5,6 +5,7 @@
#ifndef NavigatorPresentation_h
#define NavigatorPresentation_h
#include "core/frame/Navigator.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -5,6 +5,7 @@
#ifndef ServiceWorkerRegistrationPush_h
#define ServiceWorkerRegistrationPush_h
#include "modules/serviceworkers/ServiceWorkerRegistration.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -32,6 +32,7 @@
#define NavigatorStorageQuota_h
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/Navigator.h"
#include "modules/quota/DeprecatedStorageQuota.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -5,6 +5,7 @@
#ifndef HTMLMediaElementRemotePlayback_h
#define HTMLMediaElementRemotePlayback_h
#include "core/html/HTMLMediaElement.h"
#include "modules/ModulesExport.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -5,6 +5,7 @@
#ifndef ScreenScreenOrientation_h
#define ScreenScreenOrientation_h
#include "core/frame/Screen.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -27,6 +27,7 @@
#define DOMWindowSpeechSynthesis_h
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/LocalDOMWindow.h"
#include "modules/ModulesExport.h"
#include "modules/speech/SpeechSynthesis.h"
#include "platform/Supplementable.h"
......
......@@ -6,6 +6,7 @@
#define DOMWindowStorage_h
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/LocalDOMWindow.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -21,6 +21,7 @@
#define NavigatorVibration_h
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/Navigator.h"
#include "modules/ModulesExport.h"
#include "platform/Supplementable.h"
#include "platform/heap/GarbageCollected.h"
......
......@@ -8,6 +8,7 @@
#include "bindings/core/v8/ScriptPromise.h"
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/LocalDOMWindow.h"
#include "core/frame/Navigator.h"
#include "core/page/PageVisibilityObserver.h"
#include "modules/ModulesExport.h"
#include "modules/vr/VRDisplay.h"
......
......@@ -6,6 +6,7 @@
#define ScreenWakeLock_h
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/LocalFrame.h"
#include "core/page/PageVisibilityObserver.h"
#include "device/wake_lock/public/interfaces/wake_lock_service.mojom-blink.h"
#include "modules/ModulesExport.h"
......
......@@ -6,6 +6,7 @@
#define WindowAudioWorklet_h
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/LocalDOMWindow.h"
#include "modules/ModulesExport.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -33,6 +33,7 @@
#include "bindings/core/v8/ScriptPromise.h"
#include "core/dom/ContextLifecycleObserver.h"
#include "core/frame/Navigator.h"
#include "modules/webmidi/MIDIOptions.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -10,6 +10,7 @@
#include "bindings/core/v8/ScriptWrappable.h"
#include "core/dom/ContextLifecycleObserver.h"
#include "core/events/EventTarget.h"
#include "core/frame/Navigator.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
#include "public/platform/modules/webshare/webshare.mojom-blink.h"
......
......@@ -5,6 +5,7 @@
#ifndef NavigatorUSB_h
#define NavigatorUSB_h
#include "core/frame/Navigator.h"
#include "platform/Supplementable.h"
#include "platform/heap/Handle.h"
......
......@@ -95,6 +95,12 @@ class Supplementable;
template <typename T>
class Supplement : public GarbageCollectedMixin {
public:
// TODO(haraken): Remove the default constructor.
// All Supplement objects should be instantiated with m_host.
Supplement() {}
explicit Supplement(T& host) : m_host(&host) {}
T* host() const { return m_host; }
static void provideTo(Supplementable<T>& host,
const char* key,
Supplement<T>* supplement) {
......@@ -109,7 +115,10 @@ class Supplement : public GarbageCollectedMixin {
return host ? host->requireSupplement(key) : 0;
}
DEFINE_INLINE_VIRTUAL_TRACE() {}
DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(m_host); }
private:
Member<T> m_host;
};
// Supplementable<T> inherits from GarbageCollectedMixin virtually
......
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