Commit 19cc688f authored by nick@chromium.org's avatar nick@chromium.org

Migrate PingLoader to be a LocalFrameLifecycleObserver.

BUG=526743,522622
TEST=webkit_unit_tests

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

git-svn-id: svn://svn.chromium.org/blink/trunk@201580 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 9a868785
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "core/events/MouseEvent.h" #include "core/events/MouseEvent.h"
#include "core/frame/FrameHost.h" #include "core/frame/FrameHost.h"
#include "core/frame/Settings.h" #include "core/frame/Settings.h"
#include "core/frame/UseCounter.h"
#include "core/html/HTMLImageElement.h" #include "core/html/HTMLImageElement.h"
#include "core/html/parser/HTMLParserIdioms.h" #include "core/html/parser/HTMLParserIdioms.h"
#include "core/layout/LayoutImage.h" #include "core/layout/LayoutImage.h"
......
...@@ -148,12 +148,9 @@ void BeaconLoader::willSendRequest(WebURLLoader*, WebURLRequest& passedNewReques ...@@ -148,12 +148,9 @@ void BeaconLoader::willSendRequest(WebURLLoader*, WebURLRequest& passedNewReques
StoredCredentials withCredentials = AllowStoredCredentials; StoredCredentials withCredentials = AllowStoredCredentials;
ResourceLoaderOptions options; ResourceLoaderOptions options;
if (!CrossOriginAccessControl::handleRedirect(m_beaconOrigin.get(), newRequest, redirectResponse, withCredentials, options, errorDescription)) { if (!CrossOriginAccessControl::handleRedirect(m_beaconOrigin.get(), newRequest, redirectResponse, withCredentials, options, errorDescription)) {
if (page() && page()->mainFrame()) { if (LocalFrame* localFrame = frame()) {
if (page()->mainFrame()->isLocalFrame()) { if (localFrame->document())
LocalFrame* localFrame = toLocalFrame(page()->mainFrame()); localFrame->document()->addConsoleMessage(ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, errorDescription));
if (localFrame->document())
localFrame->document()->addConsoleMessage(ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, errorDescription));
}
} }
// Cancel the load and self destruct. // Cancel the load and self destruct.
dispose(); dispose();
......
...@@ -134,7 +134,7 @@ void PingLoader::start(LocalFrame* frame, ResourceRequest& request, const FetchI ...@@ -134,7 +134,7 @@ void PingLoader::start(LocalFrame* frame, ResourceRequest& request, const FetchI
} }
PingLoader::PingLoader(LocalFrame* frame, ResourceRequest& request, const FetchInitiatorInfo& initiatorInfo, StoredCredentials credentialsAllowed) PingLoader::PingLoader(LocalFrame* frame, ResourceRequest& request, const FetchInitiatorInfo& initiatorInfo, StoredCredentials credentialsAllowed)
: PageLifecycleObserver(frame->page()) : LocalFrameLifecycleObserver(frame)
, m_timeout(this, &PingLoader::timeout) , m_timeout(this, &PingLoader::timeout)
, m_url(request.url()) , m_url(request.url())
, m_identifier(createUniqueIdentifier()) , m_identifier(createUniqueIdentifier())
...@@ -172,61 +172,60 @@ void PingLoader::dispose() ...@@ -172,61 +172,60 @@ void PingLoader::dispose()
void PingLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& response) void PingLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& response)
{ {
if (Page* page = this->page()) { if (LocalFrame* frame = this->frame()) {
TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::data(m_identifier, 0, true)); TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::data(m_identifier, 0, true));
const ResourceResponse& resourceResponse = response.toResourceResponse(); const ResourceResponse& resourceResponse = response.toResourceResponse();
InspectorInstrumentation::didReceiveResourceResponse(page->deprecatedLocalMainFrame(), m_identifier, 0, resourceResponse, 0); InspectorInstrumentation::didReceiveResourceResponse(frame, m_identifier, 0, resourceResponse, 0);
didFailLoading(page); didFailLoading(frame);
} }
dispose(); dispose();
} }
void PingLoader::didReceiveData(WebURLLoader*, const char*, int, int) void PingLoader::didReceiveData(WebURLLoader*, const char*, int, int)
{ {
if (Page* page = this->page()) { if (LocalFrame* frame = this->frame()) {
TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::data(m_identifier, 0, true)); TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::data(m_identifier, 0, true));
didFailLoading(page); didFailLoading(frame);
} }
dispose(); dispose();
} }
void PingLoader::didFinishLoading(WebURLLoader*, double, int64_t) void PingLoader::didFinishLoading(WebURLLoader*, double, int64_t)
{ {
if (Page* page = this->page()) { if (LocalFrame* frame = this->frame()) {
TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::data(m_identifier, 0, true)); TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::data(m_identifier, 0, true));
didFailLoading(page); didFailLoading(frame);
} }
dispose(); dispose();
} }
void PingLoader::didFail(WebURLLoader*, const WebURLError& resourceError) void PingLoader::didFail(WebURLLoader*, const WebURLError& resourceError)
{ {
if (Page* page = this->page()) { if (LocalFrame* frame = this->frame()) {
TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::data(m_identifier, 0, true)); TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::data(m_identifier, 0, true));
didFailLoading(page); didFailLoading(frame);
} }
dispose(); dispose();
} }
void PingLoader::timeout(Timer<PingLoader>*) void PingLoader::timeout(Timer<PingLoader>*)
{ {
if (Page* page = this->page()) { if (LocalFrame* frame = this->frame()) {
TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::data(m_identifier, 0, true)); TRACE_EVENT_INSTANT1("devtools.timeline", "ResourceFinish", TRACE_EVENT_SCOPE_THREAD, "data", InspectorResourceFinishEvent::data(m_identifier, 0, true));
didFailLoading(page); didFailLoading(frame);
} }
dispose(); dispose();
} }
void PingLoader::didFailLoading(Page* page) void PingLoader::didFailLoading(LocalFrame* frame)
{ {
LocalFrame* frame = page->deprecatedLocalMainFrame();
InspectorInstrumentation::didFailLoading(frame, m_identifier, ResourceError::cancelledError(m_url)); InspectorInstrumentation::didFailLoading(frame, m_identifier, ResourceError::cancelledError(m_url));
frame->console().didFailLoading(m_identifier, ResourceError::cancelledError(m_url)); frame->console().didFailLoading(m_identifier, ResourceError::cancelledError(m_url));
} }
DEFINE_TRACE(PingLoader) DEFINE_TRACE(PingLoader)
{ {
PageLifecycleObserver::trace(visitor); LocalFrameLifecycleObserver::trace(visitor);
} }
} // namespace blink } // namespace blink
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include "core/CoreExport.h" #include "core/CoreExport.h"
#include "core/fetch/ResourceLoaderOptions.h" #include "core/fetch/ResourceLoaderOptions.h"
#include "core/page/PageLifecycleObserver.h" #include "core/frame/LocalFrameLifecycleObserver.h"
#include "platform/Timer.h" #include "platform/Timer.h"
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
#include "public/platform/WebURLLoaderClient.h" #include "public/platform/WebURLLoaderClient.h"
...@@ -57,7 +57,7 @@ class ResourceRequest; ...@@ -57,7 +57,7 @@ class ResourceRequest;
// The ping loader is used by audit pings, beacon transmissions and image loads // The ping loader is used by audit pings, beacon transmissions and image loads
// during page unloading. // during page unloading.
// //
class CORE_EXPORT PingLoader : public RefCountedWillBeRefCountedGarbageCollected<PingLoader>, public PageLifecycleObserver, private WebURLLoaderClient { class CORE_EXPORT PingLoader : public RefCountedWillBeRefCountedGarbageCollected<PingLoader>, public LocalFrameLifecycleObserver, private WebURLLoaderClient {
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(PingLoader); WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(PingLoader);
WTF_MAKE_NONCOPYABLE(PingLoader); WTF_MAKE_NONCOPYABLE(PingLoader);
WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(PingLoader); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(PingLoader);
...@@ -83,14 +83,14 @@ protected: ...@@ -83,14 +83,14 @@ protected:
void dispose(); void dispose();
private: private:
void didReceiveResponse(WebURLLoader*, const WebURLResponse&) override; void didReceiveResponse(WebURLLoader*, const WebURLResponse&) final;
void didReceiveData(WebURLLoader*, const char*, int, int) override; void didReceiveData(WebURLLoader*, const char*, int, int) final;
void didFinishLoading(WebURLLoader*, double, int64_t) override; void didFinishLoading(WebURLLoader*, double, int64_t) final;
void didFail(WebURLLoader*, const WebURLError&) override; void didFail(WebURLLoader*, const WebURLError&) final;
void timeout(Timer<PingLoader>*); void timeout(Timer<PingLoader>*);
void didFailLoading(Page*); void didFailLoading(LocalFrame*);
OwnPtr<WebURLLoader> m_loader; OwnPtr<WebURLLoader> m_loader;
Timer<PingLoader> m_timeout; Timer<PingLoader> m_timeout;
......
...@@ -7793,6 +7793,28 @@ TEST_P(ParameterizedWebFrameTest, CreateLocalChildWithPreviousSibling) ...@@ -7793,6 +7793,28 @@ TEST_P(ParameterizedWebFrameTest, CreateLocalChildWithPreviousSibling)
view->close(); view->close();
} }
TEST_P(ParameterizedWebFrameTest, SendBeaconFromChildWithRemoteMainFrame)
{
FrameTestHelpers::TestWebViewClient viewClient;
FrameTestHelpers::TestWebRemoteFrameClient remoteClient;
WebView* view = WebView::create(&viewClient);
view->settings()->setJavaScriptEnabled(true);
view->setMainFrame(remoteClient.frame());
WebRemoteFrame* root = view->mainFrame()->toWebRemoteFrame();
root->setReplicatedOrigin(SecurityOrigin::createUnique());
FrameTestHelpers::TestWebFrameClient localFrameClient;
WebLocalFrame* localFrame = root->createLocalChild(WebTreeScopeType::Document, "", WebSandboxFlags::None, &localFrameClient, nullptr);
// Finally, make sure an embedder triggered load in the local frame swapped
// back in works.
registerMockedHttpURLLoad("send_beacon.html");
registerMockedHttpURLLoad("reload_post.html"); // url param to sendBeacon()
FrameTestHelpers::loadFrame(localFrame, m_baseURL + "send_beacon.html");
view->close();
}
class OverscrollWebViewClient : public FrameTestHelpers::TestWebViewClient { class OverscrollWebViewClient : public FrameTestHelpers::TestWebViewClient {
public: public:
MOCK_METHOD4(didOverscroll, void(const WebFloatSize&, const WebFloatSize&, const WebFloatPoint&, const WebFloatSize&)); MOCK_METHOD4(didOverscroll, void(const WebFloatSize&, const WebFloatSize&, const WebFloatPoint&, const WebFloatSize&));
......
<!DOCTYPE html>
<html>
<head>
<script>
navigator.sendBeacon('/reload_post.html', 'bacon');
</script>
</head>
<body>
</body>
</html>
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