Commit c62cd107 authored by gavinp@chromium.org's avatar gavinp@chromium.org

Add status events on <link rel=prerender> elements.

https://bugs.webkit.org/show_bug.cgi?id=96474

Reviewed by Adam Barth.

The new PrerenderStatusEvent is sent to link elements when
prerenders are started by the embedder, and also sent when they
are stopped. Pages using this feature can now serialize launching
prerenders, and track timing performance.

Source/Platform:

* chromium/public/WebPrerender.h:
(WebKit::WebPrerender::WebPrerender):
(WebKit::WebPrerender::operator=):
(WebPrerender):

Source/WebCore:

Tested in a new WebKitUnitTest for the chromium port.

* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* dom/EventNames.h:
(WebCore):
* html/HTMLLinkElement.cpp:
(WebCore):
(WebCore::HTMLLinkElement::didStartLinkPrerender):
(WebCore::HTMLLinkElement::didStopLinkPrerender):
(WebCore::HTMLLinkElement::didSendLoadForLinkPrerender):
(WebCore::HTMLLinkElement::didSendDOMContentLoadedForLinkPrerender):
* html/HTMLLinkElement.h:
(HTMLLinkElement):
* loader/LinkLoader.cpp:
(WebCore::LinkLoader::didStartPrerender):
(WebCore):
(WebCore::LinkLoader::didStopPrerender):
(WebCore::LinkLoader::didSendLoadForPrerender):
(WebCore::LinkLoader::didSendDOMContentLoadedForPrerender):
(WebCore::LinkLoader::loadLink):
* loader/LinkLoader.h:
(LinkLoader):
* loader/LinkLoaderClient.h:
(LinkLoaderClient):
* loader/Prerenderer.cpp:
(WebCore::Prerenderer::render):
* loader/Prerenderer.h:
(WebCore):
(Prerenderer):
* platform/PrerenderClient.h: Copied from Source/WebCore/loader/LinkLoaderClient.h.
(WebCore):
(PrerenderClient):
(WebCore::PrerenderClient::~PrerenderClient):
* platform/PrerenderHandle.h:
(WebCore):
(PrerenderHandle):
* platform/chromium/Prerender.cpp:
(WebCore::Prerender::Prerender):
(WebCore::Prerender::removeClient):
(WebCore):
(WebCore::Prerender::add):
(WebCore::Prerender::cancel):
(WebCore::Prerender::abandon):
(WebCore::Prerender::didStartPrerender):
(WebCore::Prerender::didStopPrerender):
(WebCore::Prerender::didSendLoadForPrerender):
(WebCore::Prerender::didSendDOMContentLoadedForPrerender):
* platform/chromium/Prerender.h:
(WebKit):
(WebCore):
(Prerender):
* platform/chromium/PrerenderHandle.cpp:
(WebCore::PrerenderHandle::create):
(WebCore::PrerenderHandle::PrerenderHandle):
(WebCore::PrerenderHandle::~PrerenderHandle):
(WebCore::PrerenderHandle::removeClient):
(WebCore):
* platform/chromium/support/WebPrerender.cpp:
(WebKit::WebPrerender::toPrerender):
(WebKit):
(WebKit::WebPrerender::assign):
(WebKit::WebPrerender::isNull):
(WebKit::WebPrerender::didStartPrerender):
(WebKit::WebPrerender::didStopPrerender):
(WebKit::WebPrerender::didSendLoadForPrerender):
(WebKit::WebPrerender::didSendDOMContentLoadedForPrerender):

Source/WebKit/chromium:

* WebKit.gyp:
* WebKit.gypi:
* tests/FrameTestHelpers.cpp:
(WebKit::FrameTestHelpers::createWebView):
(FrameTestHelpers):
(WebKit::FrameTestHelpers::createWebViewAndLoad):
* tests/FrameTestHelpers.h:
(FrameTestHelpers):
* tests/PrerenderingTest.cpp: Added.
* tests/data/prerender/multiple_prerenders.html: Added.
* tests/data/prerender/single_prerender.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@137045 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c4356687
2012-12-08 Gavin Peters <gavinp@chromium.org>
Add status events on <link rel=prerender> elements.
https://bugs.webkit.org/show_bug.cgi?id=96474
Reviewed by Adam Barth.
The new PrerenderStatusEvent is sent to link elements when
prerenders are started by the embedder, and also sent when they
are stopped. Pages using this feature can now serialize launching
prerenders, and track timing performance.
* chromium/public/WebPrerender.h:
(WebKit::WebPrerender::WebPrerender):
(WebKit::WebPrerender::operator=):
(WebPrerender):
2012-12-07 Scott Violet <sky@chromium.org>
[chromium] Remove linux theme related files and switch to default
......
......@@ -54,11 +54,24 @@ public:
virtual ~ExtraData() { }
};
WebPrerender() { }
WebPrerender(const WebPrerender& other) { assign(other); }
WebPrerender& operator=(const WebPrerender& other)
{
assign(other);
return *this;
}
#if WEBKIT_IMPLEMENTATION
explicit WebPrerender(PassRefPtr<WebCore::Prerender>);
~WebPrerender();
const WebCore::Prerender* toPrerender() const;
#endif
WEBKIT_EXPORT void assign(const WebPrerender&);
WEBKIT_EXPORT bool isNull() const;
WEBKIT_EXPORT WebURL url() const;
WEBKIT_EXPORT WebString referrer() const;
WEBKIT_EXPORT WebReferrerPolicy referrerPolicy() const;
......@@ -66,9 +79,12 @@ public:
WEBKIT_EXPORT void setExtraData(ExtraData*);
WEBKIT_EXPORT const ExtraData* extraData() const;
private:
WebPrerender();
WEBKIT_EXPORT void didStartPrerender();
WEBKIT_EXPORT void didStopPrerender();
WEBKIT_EXPORT void didSendLoadForPrerender();
WEBKIT_EXPORT void didSendDOMContentLoadedForPrerender();
private:
WebPrivatePtr<WebCore::Prerender> m_private;
};
......
2012-12-08 Gavin Peters <gavinp@chromium.org>
Add status events on <link rel=prerender> elements.
https://bugs.webkit.org/show_bug.cgi?id=96474
Reviewed by Adam Barth.
The new PrerenderStatusEvent is sent to link elements when
prerenders are started by the embedder, and also sent when they
are stopped. Pages using this feature can now serialize launching
prerenders, and track timing performance.
Tested in a new WebKitUnitTest for the chromium port.
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* dom/EventNames.h:
(WebCore):
* html/HTMLLinkElement.cpp:
(WebCore):
(WebCore::HTMLLinkElement::didStartLinkPrerender):
(WebCore::HTMLLinkElement::didStopLinkPrerender):
(WebCore::HTMLLinkElement::didSendLoadForLinkPrerender):
(WebCore::HTMLLinkElement::didSendDOMContentLoadedForLinkPrerender):
* html/HTMLLinkElement.h:
(HTMLLinkElement):
* loader/LinkLoader.cpp:
(WebCore::LinkLoader::didStartPrerender):
(WebCore):
(WebCore::LinkLoader::didStopPrerender):
(WebCore::LinkLoader::didSendLoadForPrerender):
(WebCore::LinkLoader::didSendDOMContentLoadedForPrerender):
(WebCore::LinkLoader::loadLink):
* loader/LinkLoader.h:
(LinkLoader):
* loader/LinkLoaderClient.h:
(LinkLoaderClient):
* loader/Prerenderer.cpp:
(WebCore::Prerenderer::render):
* loader/Prerenderer.h:
(WebCore):
(Prerenderer):
* platform/PrerenderClient.h: Copied from Source/WebCore/loader/LinkLoaderClient.h.
(WebCore):
(PrerenderClient):
(WebCore::PrerenderClient::~PrerenderClient):
* platform/PrerenderHandle.h:
(WebCore):
(PrerenderHandle):
* platform/chromium/Prerender.cpp:
(WebCore::Prerender::Prerender):
(WebCore::Prerender::removeClient):
(WebCore):
(WebCore::Prerender::add):
(WebCore::Prerender::cancel):
(WebCore::Prerender::abandon):
(WebCore::Prerender::didStartPrerender):
(WebCore::Prerender::didStopPrerender):
(WebCore::Prerender::didSendLoadForPrerender):
(WebCore::Prerender::didSendDOMContentLoadedForPrerender):
* platform/chromium/Prerender.h:
(WebKit):
(WebCore):
(Prerender):
* platform/chromium/PrerenderHandle.cpp:
(WebCore::PrerenderHandle::create):
(WebCore::PrerenderHandle::PrerenderHandle):
(WebCore::PrerenderHandle::~PrerenderHandle):
(WebCore::PrerenderHandle::removeClient):
(WebCore):
* platform/chromium/support/WebPrerender.cpp:
(WebKit::WebPrerender::toPrerender):
(WebKit):
(WebKit::WebPrerender::assign):
(WebKit::WebPrerender::isNull):
(WebKit::WebPrerender::didStartPrerender):
(WebKit::WebPrerender::didStopPrerender):
(WebKit::WebPrerender::didSendLoadForPrerender):
(WebKit::WebPrerender::didSendDOMContentLoadedForPrerender):
2012-12-08 Gustavo Noronha Silva <gns@gnome.org>
Reviewed by Martin Robinson.
......@@ -5801,6 +5801,7 @@ webcore_platform_sources += \
Source/WebCore/platform/PopupMenuClient.h \
Source/WebCore/platform/PopupMenu.h \
Source/WebCore/platform/PopupMenuStyle.h \
Source/WebCore/platform/PrerenderClient.h \
Source/WebCore/platform/PrerenderHandle.h \
Source/WebCore/platform/PurgeableBuffer.h \
Source/WebCore/platform/PurgePriority.h \
......
......@@ -2335,6 +2335,7 @@ HEADERS += \
platform/Timer.h \
platform/Widget.h \
platform/PlatformStrategies.h \
platform/PrerenderClient.h \
platform/PrerenderHandle.h \
platform/LocalizedStrings.h \
plugins/DOMMimeTypeArray.h \
......
......@@ -3472,6 +3472,7 @@
'platform/PlatformTouchEvent.h',
'platform/PlatformTouchPoint.h',
'platform/PrerenderHandle.h',
'platform/PrerenderClient.h',
'platform/PurgeableBuffer.h',
'platform/ReferrerPolicy.h',
'platform/RunLoopTimer.h',
......
......@@ -28741,6 +28741,10 @@
RelativePath="..\platform\PopupMenuStyle.h"
>
</File>
<File
RelativePath="..\platform\PrerenderClient.h"
>
</File>
<File
RelativePath="..\platform\PrerenderHandle.h"
>
......@@ -3760,6 +3760,7 @@
9856F8D11549E84F00B04F3A /* PrerenderHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = 9856F8D01549E84F00B04F3A /* PrerenderHandle.h */; };
985BB96D13A94058007A0B69 /* LinkRelAttribute.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 985BB96B13A94058007A0B69 /* LinkRelAttribute.cpp */; };
985BB96E13A94058007A0B69 /* LinkRelAttribute.h in Headers */ = {isa = PBXBuildFile; fileRef = 985BB96C13A94058007A0B69 /* LinkRelAttribute.h */; };
986EA88315FFF29000985E5E /* PrerenderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 986EA88215FFF29000985E5E /* PrerenderClient.h */; };
98CE4326129E00BD005821DC /* LinkLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 98CE4325129E00BD005821DC /* LinkLoader.cpp */; };
98CE432A129E00E5005821DC /* LinkLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 98CE4329129E00E5005821DC /* LinkLoader.h */; };
98EB1F951313FE0500D0E1EA /* NotImplemented.h in Headers */ = {isa = PBXBuildFile; fileRef = 98EB1F941313FE0500D0E1EA /* NotImplemented.h */; settings = {ATTRIBUTES = (Private, ); }; };
......@@ -11081,6 +11082,7 @@
9856F8D01549E84F00B04F3A /* PrerenderHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrerenderHandle.h; sourceTree = "<group>"; };
985BB96B13A94058007A0B69 /* LinkRelAttribute.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LinkRelAttribute.cpp; sourceTree = "<group>"; };
985BB96C13A94058007A0B69 /* LinkRelAttribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LinkRelAttribute.h; sourceTree = "<group>"; };
986EA88215FFF29000985E5E /* PrerenderClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrerenderClient.h; sourceTree = "<group>"; };
98CE4325129E00BD005821DC /* LinkLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LinkLoader.cpp; sourceTree = "<group>"; };
98CE4329129E00E5005821DC /* LinkLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LinkLoader.h; sourceTree = "<group>"; };
98EB1F941313FE0500D0E1EA /* NotImplemented.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotImplemented.h; sourceTree = "<group>"; };
......@@ -15524,7 +15526,6 @@
49E912A70EFAC906009D0CAF /* AnimationList.cpp */,
49E912A80EFAC906009D0CAF /* AnimationList.h */,
0F580FAE149800D400FB5BD8 /* AnimationUtilities.h */,
9856F8D01549E84F00B04F3A /* PrerenderHandle.h */,
49E912A90EFAC906009D0CAF /* TimingFunction.h */,
);
name = animation;
......@@ -21118,6 +21119,8 @@
0668E1890ADD9624004128E0 /* PopupMenu.h */,
ABC128760B33AA6D00C693D5 /* PopupMenuClient.h */,
BC3BE12A0E98092F00835588 /* PopupMenuStyle.h */,
986EA88215FFF29000985E5E /* PrerenderClient.h */,
9856F8D01549E84F00B04F3A /* PrerenderHandle.h */,
E4D687780ED7AE4F006EA978 /* PurgeableBuffer.h */,
7E33CD00127F340D00BE8F17 /* PurgePriority.h */,
A72EA3BA1585CF55004FAA26 /* RefCountedSupplement.h */,
......@@ -25897,6 +25900,7 @@
D66817FB166FE6D700FA07B4 /* HTMLTemplateElement.h in Headers */,
D6489D26166FFCF1007C031B /* JSHTMLTemplateElement.h in Headers */,
31D591BC166C2E6C00E6BF02 /* PlugInOriginHash.h in Headers */,
986EA88315FFF29000985E5E /* PrerenderClient.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -247,6 +247,11 @@ namespace WebCore {
macro(autocomplete) \
macro(autocompleteerror) \
\
macro(webkitprerenderstart) \
macro(webkitprerenderstop) \
macro(webkitprerenderload) \
macro(webkitprerenderdomcontentloaded) \
\
// end of DOM_EVENT_NAMES_FOR_EACH
......
......@@ -32,6 +32,7 @@
#include "CachedResourceRequest.h"
#include "Document.h"
#include "DocumentStyleSheetCollection.h"
#include "Event.h"
#include "EventSender.h"
#include "Frame.h"
#include "FrameLoader.h"
......@@ -357,6 +358,28 @@ void HTMLLinkElement::linkLoadingErrored()
dispatchEvent(Event::create(eventNames().errorEvent, false, false));
}
#if ENABLE(LINK_PRERENDER)
void HTMLLinkElement::didStartLinkPrerender()
{
dispatchEvent(Event::create(eventNames().webkitprerenderstartEvent, false, false));
}
void HTMLLinkElement::didStopLinkPrerender()
{
dispatchEvent(Event::create(eventNames().webkitprerenderstopEvent, false, false));
}
void HTMLLinkElement::didSendLoadForLinkPrerender()
{
dispatchEvent(Event::create(eventNames().webkitprerenderloadEvent, false, false));
}
void HTMLLinkElement::didSendDOMContentLoadedForLinkPrerender()
{
dispatchEvent(Event::create(eventNames().webkitprerenderdomcontentloadedEvent, false, false));
}
#endif
bool HTMLLinkElement::sheetLoaded()
{
if (!styleSheetIsLoading()) {
......
......@@ -89,8 +89,14 @@ private:
virtual void notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred);
virtual void startLoadingDynamicSheet();
virtual void linkLoaded();
virtual void linkLoadingErrored();
virtual void linkLoaded() OVERRIDE;
virtual void linkLoadingErrored() OVERRIDE;
#if ENABLE(LINK_PRERENDER)
virtual void didStartLinkPrerender() OVERRIDE;
virtual void didStopLinkPrerender() OVERRIDE;
virtual void didSendLoadForLinkPrerender() OVERRIDE;
virtual void didSendDOMContentLoadedForLinkPrerender() OVERRIDE;
#endif
bool isAlternate() const { return m_disabledState == Unset && m_relAttribute.m_isAlternate; }
......
......@@ -90,6 +90,26 @@ void LinkLoader::notifyFinished(CachedResource* resource)
m_cachedLinkResource = 0;
}
void LinkLoader::didStartPrerender()
{
m_client->didStartLinkPrerender();
}
void LinkLoader::didStopPrerender()
{
m_client->didStopLinkPrerender();
}
void LinkLoader::didSendLoadForPrerender()
{
m_client->didSendLoadForLinkPrerender();
}
void LinkLoader::didSendDOMContentLoadedForPrerender()
{
m_client->didSendDOMContentLoadedForLinkPrerender();
}
bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const String& type,
const String& sizes, const KURL& href, Document* document)
{
......@@ -135,7 +155,7 @@ bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const String& ty
#if ENABLE(LINK_PRERENDER)
if (relAttribute.m_isLinkPrerender) {
ASSERT(!m_prerenderHandle);
m_prerenderHandle = document->prerenderer()->render(href);
m_prerenderHandle = document->prerenderer()->render(this, href);
}
#endif
return true;
......
......@@ -35,6 +35,7 @@
#include "CachedResourceClient.h"
#include "CachedResourceHandle.h"
#include "LinkLoaderClient.h"
#include "PrerenderClient.h"
#include "Timer.h"
#include <wtf/RefPtr.h>
......@@ -47,7 +48,8 @@ class PrerenderHandle;
#endif
// The LinkLoader can load link rel types icon, dns-prefetch, subresource, prefetch and prerender.
class LinkLoader : public CachedResourceClient {
class LinkLoader : public CachedResourceClient, public PrerenderClient {
public:
explicit LinkLoader(LinkLoaderClient*);
virtual ~LinkLoader();
......@@ -55,6 +57,14 @@ public:
// from CachedResourceClient
virtual void notifyFinished(CachedResource*);
#if ENABLE(LINK_PRERENDER)
// from PrerenderClient
virtual void didStartPrerender() OVERRIDE;
virtual void didStopPrerender() OVERRIDE;
virtual void didSendLoadForPrerender() OVERRIDE;
virtual void didSendDOMContentLoadedForPrerender() OVERRIDE;
#endif
void released();
bool loadLink(const LinkRelAttribute&, const String& type, const String& sizes, const KURL&, Document*);
......
......@@ -42,6 +42,13 @@ public:
virtual void linkLoaded() = 0;
virtual void linkLoadingErrored() = 0;
// There is no notification for cancellation.
#if ENABLE(LINK_PRERENDER)
virtual void didStartLinkPrerender() = 0;
virtual void didStopLinkPrerender() = 0;
virtual void didSendLoadForLinkPrerender() = 0;
virtual void didSendDOMContentLoadedForLinkPrerender() = 0;
#endif
};
}
......
......@@ -70,7 +70,7 @@ Prerenderer::~Prerenderer()
{
}
PassRefPtr<PrerenderHandle> Prerenderer::render(const KURL& url)
PassRefPtr<PrerenderHandle> Prerenderer::render(PrerenderClient* prerenderClient, const KURL& url)
{
// Prerenders are unlike requests in most ways (for instance, they pass down fragments, and they don't return data),
// but they do have referrers.
......@@ -81,7 +81,7 @@ PassRefPtr<PrerenderHandle> Prerenderer::render(const KURL& url)
const String referrer = SecurityPolicy::generateReferrerHeader(referrerPolicy, url, document()->frame()->loader()->outgoingReferrer());
RefPtr<PrerenderHandle> prerenderHandle = PrerenderHandle::create(url, referrer, referrerPolicy);
RefPtr<PrerenderHandle> prerenderHandle = PrerenderHandle::create(prerenderClient, url, referrer, referrerPolicy);
if (client())
client()->willAddPrerender(prerenderHandle.get());
......
......@@ -46,6 +46,7 @@
namespace WebCore {
class Document;
class PrerenderClient;
class PrerenderHandle;
class PrerendererClient;
class Page;
......@@ -55,23 +56,24 @@ class Prerenderer : public ActiveDOMObject {
public:
virtual ~Prerenderer();
PassRefPtr<PrerenderHandle> render(const KURL&);
PassRefPtr<PrerenderHandle> render(PrerenderClient*, const KURL&);
static PassOwnPtr<Prerenderer> create(Document*);
virtual void reportMemoryUsage(MemoryObjectInfo*) const;
// From ActiveDOMObject:
virtual bool canSuspend() const OVERRIDE { return true; }
virtual void stop() OVERRIDE;
virtual void suspend(ReasonForSuspension) OVERRIDE;
virtual void resume() OVERRIDE;
private:
typedef Vector<RefPtr<PrerenderHandle> > HandleVector;
typedef Vector<KURL> KURLVector;
explicit Prerenderer(Document*);
virtual bool canSuspend() const OVERRIDE { return true; }
virtual void stop() OVERRIDE;
virtual void suspend(ReasonForSuspension) OVERRIDE;
virtual void resume() OVERRIDE;
Document* document();
PrerendererClient* client();
......
/*
* Copyright (C) 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef PrerenderClient_h
#define PrerenderClient_h
namespace WebCore {
class PrerenderClient {
#if ENABLE(LINK_PRERENDER)
public:
virtual ~PrerenderClient() { }
virtual void didStartPrerender() = 0;
virtual void didStopPrerender() = 0;
virtual void didSendLoadForPrerender() = 0;
virtual void didSendDOMContentLoadedForPrerender() = 0;
#endif
};
}
#endif
......@@ -44,16 +44,17 @@ namespace WebCore {
class KURL;
class Prerender;
class PrerenderClient;
class PrerenderHandle : public RefCounted<PrerenderHandle> {
WTF_MAKE_NONCOPYABLE(PrerenderHandle);
public:
static PassRefPtr<PrerenderHandle> create(const KURL&, const String& referrer, ReferrerPolicy);
static PassRefPtr<PrerenderHandle> create(PrerenderClient*, const KURL&, const String& referrer, ReferrerPolicy);
~PrerenderHandle();
Prerender* prerender();
// FIXME: one day there will be events here, and we will be a PrerenderClient.
void removeClient();
// A prerender link element is added when it is inserted into a document.
void add();
......@@ -75,7 +76,8 @@ public:
ReferrerPolicy referrerPolicy() const;
private:
PrerenderHandle(const KURL&, const String& referrer, ReferrerPolicy);
PrerenderHandle(PrerenderClient*, const KURL&, const String& referrer, ReferrerPolicy);
RefPtr<Prerender> m_prerender;
};
......
......@@ -31,6 +31,7 @@
#include "config.h"
#include "Prerender.h"
#include "PrerenderClient.h"
#include <public/Platform.h>
#include <public/WebPrerender.h>
......@@ -43,8 +44,9 @@
namespace WebCore {
Prerender::Prerender(const KURL& url, const String& referrer, ReferrerPolicy policy)
: m_url(url)
Prerender::Prerender(PrerenderClient* client, const KURL& url, const String& referrer, ReferrerPolicy policy)
: m_client(client)
, m_url(url)
, m_referrer(referrer)
, m_referrerPolicy(policy)
{
......@@ -54,13 +56,17 @@ Prerender::~Prerender()
{
}
void Prerender::removeClient()
{
m_client = 0;
}
void Prerender::add()
{
WebKit::WebPrerenderingSupport* platform = WebKit::WebPrerenderingSupport::current();
if (!platform)
return;
WebKit::WebPrerender webPrerender(this);
platform->add(webPrerender);
platform->add(WebKit::WebPrerender(this));
}
void Prerender::cancel()
......@@ -68,8 +74,7 @@ void Prerender::cancel()
WebKit::WebPrerenderingSupport* platform = WebKit::WebPrerenderingSupport::current();
if (!platform)
return;
WebKit::WebPrerender webPrerender(this);
platform->cancel(webPrerender);
platform->cancel(WebKit::WebPrerender(this));
}
void Prerender::abandon()
......@@ -77,8 +82,7 @@ void Prerender::abandon()
WebKit::WebPrerenderingSupport* platform = WebKit::WebPrerenderingSupport::current();
if (!platform)
return;
WebKit::WebPrerender webPrerender(this);
platform->abandon(webPrerender);
platform->abandon(WebKit::WebPrerender(this));
}
void Prerender::suspend()
......@@ -91,6 +95,30 @@ void Prerender::resume()
add();
}
void Prerender::didStartPrerender()
{
if (m_client)
m_client->didStartPrerender();
}
void Prerender::didStopPrerender()
{
if (m_client)
m_client->didStopPrerender();
}
void Prerender::didSendLoadForPrerender()
{
if (m_client)
m_client->didSendLoadForPrerender();
}
void Prerender::didSendDOMContentLoadedForPrerender()
{
if (m_client)
m_client->didSendDOMContentLoadedForPrerender();
}
}
#endif // ENABLE(LINK_PRERENDER)
......@@ -44,8 +44,14 @@
#if ENABLE(LINK_PRERENDER)
namespace WebKit {
class WebPrerender;
}
namespace WebCore {
class PrerenderClient;
class Prerender : public RefCounted<Prerender> {
WTF_MAKE_NONCOPYABLE(Prerender);
public:
......@@ -54,9 +60,11 @@ public:
virtual ~ExtraData() { }
};
Prerender(const KURL&, const String& referrer, ReferrerPolicy);
Prerender(PrerenderClient*, const KURL&, const String& referrer, ReferrerPolicy);
~Prerender();
void removeClient();
void add();
void cancel();
void abandon();
......@@ -69,8 +77,15 @@ public:
void setExtraData(PassRefPtr<ExtraData> extraData) { m_extraData = extraData; }
ExtraData* extraData() { return m_extraData.get(); }
void didStartPrerender();