diff options
author | yoav <yoav@yoav.ws> | 2016-01-15 16:29:58 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-16 00:31:19 +0000 |
commit | f85424718ca7a8ea3f330141ee68b717ae02f2f0 (patch) | |
tree | 708ba2e80cb00bfd629b33a8d5d90b3764a12bcf /third_party/WebKit/Source/core/loader/LinkPreloadResourceClients.h | |
parent | c56c412c10f2595ef448a09d5beeac4daf918c1b (diff) | |
download | chromium_src-f85424718ca7a8ea3f330141ee68b717ae02f2f0.zip chromium_src-f85424718ca7a8ea3f330141ee68b717ae02f2f0.tar.gz chromium_src-f85424718ca7a8ea3f330141ee68b717ae02f2f0.tar.bz2 |
Add <link rel=preload> onload support for scripts and styles
This CL adds onload support for <link rel=preload> for scripts and styles.
Support for other resource types will be added in a followup CL.
BUG=552289
Review URL: https://codereview.chromium.org/1577073005
Cr-Commit-Position: refs/heads/master@{#369892}
Diffstat (limited to 'third_party/WebKit/Source/core/loader/LinkPreloadResourceClients.h')
-rw-r--r-- | third_party/WebKit/Source/core/loader/LinkPreloadResourceClients.h | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/third_party/WebKit/Source/core/loader/LinkPreloadResourceClients.h b/third_party/WebKit/Source/core/loader/LinkPreloadResourceClients.h new file mode 100644 index 0000000..187f06c --- /dev/null +++ b/third_party/WebKit/Source/core/loader/LinkPreloadResourceClients.h @@ -0,0 +1,84 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef LinkPreloadResourceClients_h +#define LinkPreloadResourceClients_h + +#include "core/fetch/CSSStyleSheetResource.h" +#include "core/fetch/FontResource.h" +#include "core/fetch/ImageResourceClient.h" +#include "core/fetch/ResourceOwner.h" +#include "core/fetch/ScriptResource.h" +#include "core/fetch/StyleSheetResourceClient.h" + +namespace blink { + +class LinkLoader; + +class LinkPreloadResourceClient : public NoBaseWillBeGarbageCollectedFinalized<LinkPreloadResourceClient> { +public: + virtual ~LinkPreloadResourceClient() { } + + void triggerEvents(const Resource*) const; + +protected: + LinkPreloadResourceClient(LinkLoader* loader) + : m_loader(loader) + { + ASSERT(loader); + } + +private: + LinkLoader* m_loader; +}; + +class LinkPreloadScriptResourceClient: public LinkPreloadResourceClient, public ResourceOwner<ScriptResource, ScriptResourceClient> { +public: + static PassOwnPtr<LinkPreloadScriptResourceClient> create(LinkLoader* loader, ScriptResource* resource) + { + return adoptPtr(new LinkPreloadScriptResourceClient(loader, resource)); + } + + virtual String debugName() const { return "LinkPreloadScript"; } + + void notifyFinished(Resource* resource) override + { + ASSERT(this->resource() == resource); + triggerEvents(resource); + } + +private: + LinkPreloadScriptResourceClient(LinkLoader* loader, ScriptResource* resource) + : LinkPreloadResourceClient(loader) + { + setResource(resource); + } +}; + +class LinkPreloadStyleResourceClient: public LinkPreloadResourceClient, public ResourceOwner<CSSStyleSheetResource, StyleSheetResourceClient> { +public: + static PassOwnPtr<LinkPreloadStyleResourceClient> create(LinkLoader* loader, CSSStyleSheetResource* resource) + { + return adoptPtr(new LinkPreloadStyleResourceClient(loader, resource)); + } + + virtual String debugName() const { return "LinkPreloadStyle"; } + + void setCSSStyleSheet(const String&, const KURL&, const String&, const CSSStyleSheetResource* resource) override + { + ASSERT(this->resource() == resource); + triggerEvents(static_cast<const Resource*>(resource)); + } + +private: + LinkPreloadStyleResourceClient(LinkLoader* loader, CSSStyleSheetResource* resource) + : LinkPreloadResourceClient(loader) + { + setResource(resource); + } +}; + +} + +#endif // LinkPreloadResourceClients_h |