Commit 3245f6b8 authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

Lazy installation of NavigatorContentUtils on Supplement

NavigatorContentUtils has been installed by
ModulesInitialized::InstallSupplements while a frame is
created. But, it's also possible to install NavigatorContentUtils
when it's real functions are called like other Supplements.

The lazy installation is a typical use case of Supplement as
well as it helps to occupy less memory if not used.

Bug: 987080
Change-Id: If22d7c992b987e59dd326546663bb4c5a16d7959
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1715167Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Gyuyoung Kim <gyuyoung@igalia.com>
Cr-Commit-Position: refs/heads/master@{#680310}
parent 2104fb82
...@@ -63,8 +63,6 @@ ...@@ -63,8 +63,6 @@
#include "third_party/blink/renderer/modules/media_controls/media_controls_impl.h" #include "third_party/blink/renderer/modules/media_controls/media_controls_impl.h"
#include "third_party/blink/renderer/modules/mediastream/user_media_client.h" #include "third_party/blink/renderer/modules/mediastream/user_media_client.h"
#include "third_party/blink/renderer/modules/mediastream/user_media_controller.h" #include "third_party/blink/renderer/modules/mediastream/user_media_controller.h"
#include "third_party/blink/renderer/modules/navigatorcontentutils/navigator_content_utils.h"
#include "third_party/blink/renderer/modules/navigatorcontentutils/navigator_content_utils_client.h"
#include "third_party/blink/renderer/modules/picture_in_picture/picture_in_picture_controller_impl.h" #include "third_party/blink/renderer/modules/picture_in_picture/picture_in_picture_controller_impl.h"
#include "third_party/blink/renderer/modules/presentation/presentation_controller.h" #include "third_party/blink/renderer/modules/presentation/presentation_controller.h"
#include "third_party/blink/renderer/modules/presentation/presentation_receiver.h" #include "third_party/blink/renderer/modules/presentation/presentation_receiver.h"
...@@ -188,9 +186,6 @@ void ModulesInitializer::InstallSupplements(LocalFrame& frame) const { ...@@ -188,9 +186,6 @@ void ModulesInitializer::InstallSupplements(LocalFrame& frame) const {
frame, std::make_unique<UserMediaClient>(client->UserMediaClient())); frame, std::make_unique<UserMediaClient>(client->UserMediaClient()));
ProvideIndexedDBClientTo(frame, MakeGarbageCollected<IndexedDBClient>(frame)); ProvideIndexedDBClientTo(frame, MakeGarbageCollected<IndexedDBClient>(frame));
ProvideLocalFileSystemTo(frame, std::make_unique<LocalFileSystemClient>()); ProvideLocalFileSystemTo(frame, std::make_unique<LocalFileSystemClient>());
NavigatorContentUtils::ProvideTo(
*frame.DomWindow()->navigator(),
MakeGarbageCollected<NavigatorContentUtilsClient>(web_frame));
ScreenOrientationControllerImpl::ProvideTo(frame); ScreenOrientationControllerImpl::ProvideTo(frame);
if (RuntimeEnabledFeatures::PresentationEnabled()) if (RuntimeEnabledFeatures::PresentationEnabled())
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/modules/navigatorcontentutils/navigator_content_utils_client.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h" #include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h" #include "third_party/blink/renderer/platform/weborigin/security_origin.h"
...@@ -37,6 +39,8 @@ ...@@ -37,6 +39,8 @@
namespace blink { namespace blink {
const char NavigatorContentUtils::kSupplementName[] = "NavigatorContentUtils";
static const HashSet<String>& SupportedSchemes() { static const HashSet<String>& SupportedSchemes() {
DEFINE_STATIC_LOCAL( DEFINE_STATIC_LOCAL(
HashSet<String>, supported_schemes, HashSet<String>, supported_schemes,
...@@ -117,8 +121,18 @@ static bool VerifyCustomHandlerScheme(const String& scheme, ...@@ -117,8 +121,18 @@ static bool VerifyCustomHandlerScheme(const String& scheme,
return false; return false;
} }
NavigatorContentUtils* NavigatorContentUtils::From(Navigator& navigator) { NavigatorContentUtils& NavigatorContentUtils::From(Navigator& navigator,
return Supplement<Navigator>::From<NavigatorContentUtils>(navigator); LocalFrame& frame) {
NavigatorContentUtils* navigator_content_utils =
Supplement<Navigator>::From<NavigatorContentUtils>(navigator);
if (!navigator_content_utils) {
WebLocalFrameImpl* web_frame = WebLocalFrameImpl::FromFrame(&frame);
navigator_content_utils = MakeGarbageCollected<NavigatorContentUtils>(
navigator,
MakeGarbageCollected<NavigatorContentUtilsClient>(web_frame));
ProvideTo(navigator, navigator_content_utils);
}
return *navigator_content_utils;
} }
NavigatorContentUtils::~NavigatorContentUtils() = default; NavigatorContentUtils::~NavigatorContentUtils() = default;
...@@ -129,10 +143,10 @@ void NavigatorContentUtils::registerProtocolHandler( ...@@ -129,10 +143,10 @@ void NavigatorContentUtils::registerProtocolHandler(
const String& url, const String& url,
const String& title, const String& title,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (!navigator.GetFrame()) LocalFrame* frame = navigator.GetFrame();
if (!frame)
return; return;
Document* document = frame->GetDocument();
Document* document = navigator.GetFrame()->GetDocument();
DCHECK(document); DCHECK(document);
if (!VerifyCustomHandlerURL(*document, url, exception_state)) if (!VerifyCustomHandlerURL(*document, url, exception_state))
...@@ -147,8 +161,9 @@ void NavigatorContentUtils::registerProtocolHandler( ...@@ -147,8 +161,9 @@ void NavigatorContentUtils::registerProtocolHandler(
? WebFeature::kRegisterProtocolHandlerSecureOrigin ? WebFeature::kRegisterProtocolHandlerSecureOrigin
: WebFeature::kRegisterProtocolHandlerInsecureOrigin); : WebFeature::kRegisterProtocolHandlerInsecureOrigin);
NavigatorContentUtils::From(navigator)->Client()->RegisterProtocolHandler( NavigatorContentUtils::From(navigator, *frame)
scheme, document->CompleteURL(url), title); .Client()
->RegisterProtocolHandler(scheme, document->CompleteURL(url), title);
} }
void NavigatorContentUtils::unregisterProtocolHandler( void NavigatorContentUtils::unregisterProtocolHandler(
...@@ -156,10 +171,10 @@ void NavigatorContentUtils::unregisterProtocolHandler( ...@@ -156,10 +171,10 @@ void NavigatorContentUtils::unregisterProtocolHandler(
const String& scheme, const String& scheme,
const String& url, const String& url,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (!navigator.GetFrame()) LocalFrame* frame = navigator.GetFrame();
if (!frame)
return; return;
Document* document = frame->GetDocument();
Document* document = navigator.GetFrame()->GetDocument();
DCHECK(document); DCHECK(document);
if (!VerifyCustomHandlerURL(*document, url, exception_state)) if (!VerifyCustomHandlerURL(*document, url, exception_state))
...@@ -168,8 +183,9 @@ void NavigatorContentUtils::unregisterProtocolHandler( ...@@ -168,8 +183,9 @@ void NavigatorContentUtils::unregisterProtocolHandler(
if (!VerifyCustomHandlerScheme(scheme, exception_state)) if (!VerifyCustomHandlerScheme(scheme, exception_state))
return; return;
NavigatorContentUtils::From(navigator)->Client()->UnregisterProtocolHandler( NavigatorContentUtils::From(navigator, *frame)
scheme, document->CompleteURL(url)); .Client()
->UnregisterProtocolHandler(scheme, document->CompleteURL(url));
} }
void NavigatorContentUtils::Trace(blink::Visitor* visitor) { void NavigatorContentUtils::Trace(blink::Visitor* visitor) {
...@@ -177,13 +193,4 @@ void NavigatorContentUtils::Trace(blink::Visitor* visitor) { ...@@ -177,13 +193,4 @@ void NavigatorContentUtils::Trace(blink::Visitor* visitor) {
Supplement<Navigator>::Trace(visitor); Supplement<Navigator>::Trace(visitor);
} }
const char NavigatorContentUtils::kSupplementName[] = "NavigatorContentUtils";
void NavigatorContentUtils::ProvideTo(Navigator& navigator,
NavigatorContentUtilsClient* client) {
Supplement<Navigator>::ProvideTo(
navigator,
MakeGarbageCollected<NavigatorContentUtils>(navigator, client));
}
} // namespace blink } // namespace blink
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "third_party/blink/renderer/core/frame/navigator.h" #include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/modules/navigatorcontentutils/navigator_content_utils_client.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/supplementable.h" #include "third_party/blink/renderer/platform/supplementable.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
...@@ -37,7 +36,10 @@ ...@@ -37,7 +36,10 @@
namespace blink { namespace blink {
class ExceptionState; class ExceptionState;
class NavigatorContentUtilsClient;
// It is owned by Navigator, and an instance is created lazily by calling
// NavigatorContentUtils::From() via [register/unregister]ProtocolHandler.
class MODULES_EXPORT NavigatorContentUtils final class MODULES_EXPORT NavigatorContentUtils final
: public GarbageCollectedFinalized<NavigatorContentUtils>, : public GarbageCollectedFinalized<NavigatorContentUtils>,
public Supplement<Navigator> { public Supplement<Navigator> {
...@@ -51,8 +53,6 @@ class MODULES_EXPORT NavigatorContentUtils final ...@@ -51,8 +53,6 @@ class MODULES_EXPORT NavigatorContentUtils final
: Supplement<Navigator>(navigator), client_(client) {} : Supplement<Navigator>(navigator), client_(client) {}
virtual ~NavigatorContentUtils(); virtual ~NavigatorContentUtils();
static NavigatorContentUtils* From(Navigator&);
static void registerProtocolHandler(Navigator&, static void registerProtocolHandler(Navigator&,
const String& scheme, const String& scheme,
const String& url, const String& url,
...@@ -63,8 +63,6 @@ class MODULES_EXPORT NavigatorContentUtils final ...@@ -63,8 +63,6 @@ class MODULES_EXPORT NavigatorContentUtils final
const String& url, const String& url,
ExceptionState&); ExceptionState&);
static void ProvideTo(Navigator&, NavigatorContentUtilsClient*);
void Trace(blink::Visitor*) override; void Trace(blink::Visitor*) override;
void SetClientForTest(NavigatorContentUtilsClient* client) { void SetClientForTest(NavigatorContentUtilsClient* client) {
...@@ -72,6 +70,8 @@ class MODULES_EXPORT NavigatorContentUtils final ...@@ -72,6 +70,8 @@ class MODULES_EXPORT NavigatorContentUtils final
} }
private: private:
static NavigatorContentUtils& From(Navigator&, LocalFrame& frame);
NavigatorContentUtilsClient* Client() { return client_.Get(); } NavigatorContentUtilsClient* Client() { return client_.Get(); }
Member<NavigatorContentUtilsClient> client_; Member<NavigatorContentUtilsClient> client_;
......
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