Diff
Modified: trunk/Source/WebCore/ChangeLog (156624 => 156625)
--- trunk/Source/WebCore/ChangeLog 2013-09-30 03:45:30 UTC (rev 156624)
+++ trunk/Source/WebCore/ChangeLog 2013-09-30 04:36:35 UTC (rev 156625)
@@ -1,3 +1,56 @@
+2013-09-29 Sam Weinig <s...@webkit.org>
+
+ Cleanup PageThrottler and PageConsole a bit
+ https://bugs.webkit.org/show_bug.cgi?id=122085
+
+ Reviewed by Anders Carlsson.
+
+ * html/HTMLMediaElement.h:
+ * loader/FrameLoader.cpp:
+ (WebCore::FrameLoader::completed):
+ * loader/FrameLoader.h:
+ * loader/SubresourceLoader.cpp:
+ (WebCore::SubresourceLoader::checkForHTTPStatusCodeError):
+ (WebCore::SubresourceLoader::didFinishLoading):
+ (WebCore::SubresourceLoader::didFail):
+ (WebCore::SubresourceLoader::willCancel):
+ * loader/SubresourceLoader.h:
+ Store the PageActivityAssertionToken as a std::unique_ptr.
+
+ * page/Page.cpp:
+ (WebCore::Page::Page):
+ Use createOwned and pass this by reference for the PageThrottler and PageConsole.
+ (WebCore::Page::~Page):
+ Remove unnecessary clearing of an OwnPtr that is about to be destroyed.
+ * page/Page.h:
+ Make m_pageThrottler const and return it as a reference.
+
+ * page/PageActivityAssertionToken.cpp:
+ (WebCore::PageActivityAssertionToken::PageActivityAssertionToken):
+ (WebCore::PageActivityAssertionToken::~PageActivityAssertionToken):
+ * page/PageActivityAssertionToken.h:
+ Take the PageThrottler by reference in the constructor. It is never null.
+
+ * page/PageConsole.cpp:
+ (WebCore::PageConsole::PageConsole):
+ (WebCore::PageConsole::~PageConsole):
+ (WebCore::PageConsole::addMessage):
+ * page/PageConsole.h:
+ Pass and store the Page as a reference and remove an extraneous null check. Remove
+ the create function.
+
+ * page/PageThrottler.cpp:
+ (WebCore::PageThrottler::PageThrottler):
+ (WebCore::PageThrottler::~PageThrottler):
+ (WebCore::PageThrottler::createActivityToken):
+ (WebCore::PageThrottler::throttlePage):
+ (WebCore::PageThrottler::unthrottlePage):
+ (WebCore::PageThrottler::addActivityToken):
+ (WebCore::PageThrottler::removeActivityToken):
+ * page/PageThrottler.h:
+ Pass and store the Page as a reference. Move the creation of PageActivityAssertionToken here
+ to aid encapsulation.
+
2013-09-29 Darin Adler <da...@apple.com>
Try to fix Windows build.
Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (156624 => 156625)
--- trunk/Source/WebCore/html/HTMLMediaElement.h 2013-09-30 03:45:30 UTC (rev 156624)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h 2013-09-30 04:36:35 UTC (rev 156625)
@@ -781,7 +781,7 @@
OwnPtr<AudioSessionManagerToken> m_audioSessionManagerToken;
#endif
- OwnPtr<PageActivityAssertionToken> m_activityToken;
+ std::unique_ptr<PageActivityAssertionToken> m_activityToken;
size_t m_reportedExtraMemoryCost;
#if ENABLE(MEDIA_CONTROLS_SCRIPT)
Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (156624 => 156625)
--- trunk/Source/WebCore/loader/FrameLoader.cpp 2013-09-30 03:45:30 UTC (rev 156624)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp 2013-09-30 04:36:35 UTC (rev 156625)
@@ -1101,7 +1101,7 @@
if (m_frame.view())
m_frame.view()->maintainScrollPositionAtAnchor(0);
- m_activityAssertion.clear();
+ m_activityAssertion = nullptr;
}
void FrameLoader::started()
Modified: trunk/Source/WebCore/loader/FrameLoader.h (156624 => 156625)
--- trunk/Source/WebCore/loader/FrameLoader.h 2013-09-30 03:45:30 UTC (rev 156624)
+++ trunk/Source/WebCore/loader/FrameLoader.h 2013-09-30 04:36:35 UTC (rev 156625)
@@ -447,7 +447,7 @@
URL m_previousURL;
RefPtr<HistoryItem> m_requestedHistoryItem;
- OwnPtr<PageActivityAssertionToken> m_activityAssertion;
+ std::unique_ptr<PageActivityAssertionToken> m_activityAssertion;
};
// This function is called by createWindow() in JSDOMWindowBase.cpp, for example, for
Modified: trunk/Source/WebCore/loader/SubresourceLoader.cpp (156624 => 156625)
--- trunk/Source/WebCore/loader/SubresourceLoader.cpp 2013-09-30 03:45:30 UTC (rev 156624)
+++ trunk/Source/WebCore/loader/SubresourceLoader.cpp 2013-09-30 04:36:35 UTC (rev 156625)
@@ -260,7 +260,7 @@
return false;
m_state = Finishing;
- m_activityAssertion.clear();
+ m_activityAssertion = nullptr;
m_resource->error(CachedResource::LoadError);
cancel();
return true;
@@ -278,7 +278,7 @@
Ref<SubresourceLoader> protect(*this);
CachedResourceHandle<CachedResource> protectResource(m_resource);
m_state = Finishing;
- m_activityAssertion.clear();
+ m_activityAssertion = nullptr;
m_resource->setLoadFinishTime(finishTime);
m_resource->finishLoading(resourceData());
@@ -303,7 +303,7 @@
Ref<SubresourceLoader> protect(*this);
CachedResourceHandle<CachedResource> protectResource(m_resource);
m_state = Finishing;
- m_activityAssertion.clear();
+ m_activityAssertion = nullptr;
if (m_resource->resourceToRevalidate())
memoryCache()->revalidationFailed(m_resource);
m_resource->setResourceError(error);
@@ -326,7 +326,7 @@
Ref<SubresourceLoader> protect(*this);
m_state = Finishing;
- m_activityAssertion.clear();
+ m_activityAssertion = nullptr;
if (m_resource->resourceToRevalidate())
memoryCache()->revalidationFailed(m_resource);
m_resource->setResourceError(error);
Modified: trunk/Source/WebCore/loader/SubresourceLoader.h (156624 => 156625)
--- trunk/Source/WebCore/loader/SubresourceLoader.h 2013-09-30 03:45:30 UTC (rev 156624)
+++ trunk/Source/WebCore/loader/SubresourceLoader.h 2013-09-30 04:36:35 UTC (rev 156625)
@@ -102,7 +102,7 @@
bool m_loadingMultipartContent;
SubresourceLoaderState m_state;
OwnPtr<RequestCountTracker> m_requestCountTracker;
- OwnPtr<PageActivityAssertionToken> m_activityAssertion;
+ std::unique_ptr<PageActivityAssertionToken> m_activityAssertion;
};
}
Modified: trunk/Source/WebCore/page/Page.cpp (156624 => 156625)
--- trunk/Source/WebCore/page/Page.cpp 2013-09-30 03:45:30 UTC (rev 156624)
+++ trunk/Source/WebCore/page/Page.cpp 2013-09-30 04:36:35 UTC (rev 156625)
@@ -185,8 +185,8 @@
#endif
, m_alternativeTextClient(pageClients.alternativeTextClient)
, m_scriptedAnimationsSuspended(false)
- , m_pageThrottler(PageThrottler::create(this))
- , m_console(PageConsole::create(this))
+ , m_pageThrottler(createOwned<PageThrottler>(*this))
+ , m_console(createOwned<PageConsole>(*this))
, m_lastSpatialNavigationCandidatesCount(0) // NOTE: Only called from Internals for Spatial Navigation testing.
, m_framesHandlingBeforeUnloadEvent(0)
{
@@ -235,8 +235,6 @@
#ifndef NDEBUG
pageCounter.decrement();
#endif
-
- m_pageThrottler.clear();
}
ArenaSize Page::renderTreeSize() const
@@ -1505,9 +1503,9 @@
m_seenMediaEngines.clear();
}
-PassOwnPtr<PageActivityAssertionToken> Page::createActivityToken()
+std::unique_ptr<PageActivityAssertionToken> Page::createActivityToken()
{
- return adoptPtr(new PageActivityAssertionToken(m_pageThrottler.get()));
+ return m_pageThrottler->createActivityToken();
}
#if ENABLE(HIDDEN_PAGE_DOM_TIMER_THROTTLING)
Modified: trunk/Source/WebCore/page/Page.h (156624 => 156625)
--- trunk/Source/WebCore/page/Page.h 2013-09-30 03:45:30 UTC (rev 156624)
+++ trunk/Source/WebCore/page/Page.h 2013-09-30 04:36:35 UTC (rev 156625)
@@ -395,8 +395,8 @@
void sawMediaEngine(const String& engineName);
void resetSeenMediaEngines();
- PageThrottler* pageThrottler() { return m_pageThrottler.get(); }
- PassOwnPtr<PageActivityAssertionToken> createActivityToken();
+ PageThrottler& pageThrottler() { return *m_pageThrottler; }
+ std::unique_ptr<PageActivityAssertionToken> createActivityToken();
PageConsole& console() { return *m_console; }
@@ -546,8 +546,7 @@
AlternativeTextClient* m_alternativeTextClient;
bool m_scriptedAnimationsSuspended;
- OwnPtr<PageThrottler> m_pageThrottler;
-
+ const OwnPtr<PageThrottler> m_pageThrottler;
const OwnPtr<PageConsole> m_console;
HashSet<String> m_seenPlugins;
Modified: trunk/Source/WebCore/page/PageActivityAssertionToken.cpp (156624 => 156625)
--- trunk/Source/WebCore/page/PageActivityAssertionToken.cpp 2013-09-30 03:45:30 UTC (rev 156624)
+++ trunk/Source/WebCore/page/PageActivityAssertionToken.cpp 2013-09-30 04:36:35 UTC (rev 156625)
@@ -30,17 +30,16 @@
namespace WebCore {
-PageActivityAssertionToken::PageActivityAssertionToken(PageThrottler* throttler)
- :m_throttler(throttler)
+PageActivityAssertionToken::PageActivityAssertionToken(PageThrottler& throttler)
+ : m_throttler(&throttler)
{
- if (m_throttler)
- m_throttler->addActivityToken(this);
+ m_throttler->addActivityToken(*this);
}
PageActivityAssertionToken::~PageActivityAssertionToken()
{
if (m_throttler)
- m_throttler->removeActivityToken(this);
+ m_throttler->removeActivityToken(*this);
}
void PageActivityAssertionToken::invalidate()
@@ -48,6 +47,6 @@
m_throttler = 0;
}
-}
+} // namespace WebCore
Modified: trunk/Source/WebCore/page/PageActivityAssertionToken.h (156624 => 156625)
--- trunk/Source/WebCore/page/PageActivityAssertionToken.h 2013-09-30 03:45:30 UTC (rev 156624)
+++ trunk/Source/WebCore/page/PageActivityAssertionToken.h 2013-09-30 04:36:35 UTC (rev 156625)
@@ -35,17 +35,15 @@
class PageActivityAssertionToken {
WTF_MAKE_NONCOPYABLE(PageActivityAssertionToken);
public:
+ PageActivityAssertionToken(PageThrottler&);
~PageActivityAssertionToken();
void invalidate();
private:
- friend class Page;
- PageActivityAssertionToken(PageThrottler*);
-
PageThrottler* m_throttler;
};
-}
+} // namespace WebCore
#endif // PageActivityAssertionToken_h
Modified: trunk/Source/WebCore/page/PageConsole.cpp (156624 => 156625)
--- trunk/Source/WebCore/page/PageConsole.cpp 2013-09-30 03:45:30 UTC (rev 156624)
+++ trunk/Source/WebCore/page/PageConsole.cpp 2013-09-30 04:36:35 UTC (rev 156625)
@@ -55,9 +55,14 @@
int muteCount = 0;
}
-PageConsole::PageConsole(Page* page) : m_page(page) { }
+PageConsole::PageConsole(Page& page)
+ : m_page(page)
+{
+}
-PageConsole::~PageConsole() { }
+PageConsole::~PageConsole()
+{
+}
void PageConsole::printSourceURLAndLine(const String& sourceURL, unsigned lineNumber)
{
@@ -161,24 +166,20 @@
if (muteCount && source != ConsoleAPIMessageSource)
return;
- Page* page = this->page();
- if (!page)
- return;
-
if (callStack)
- InspectorInstrumentation::addMessageToConsole(page, source, LogMessageType, level, message, callStack, requestIdentifier);
+ InspectorInstrumentation::addMessageToConsole(&m_page, source, LogMessageType, level, message, callStack, requestIdentifier);
else
- InspectorInstrumentation::addMessageToConsole(page, source, LogMessageType, level, message, url, lineNumber, columnNumber, state, requestIdentifier);
+ InspectorInstrumentation::addMessageToConsole(&m_page, source, LogMessageType, level, message, url, lineNumber, columnNumber, state, requestIdentifier);
if (source == CSSMessageSource)
return;
- if (page->settings().privateBrowsingEnabled())
+ if (m_page.settings().privateBrowsingEnabled())
return;
- page->chrome().client().addMessageToConsole(source, level, message, lineNumber, columnNumber, url);
+ m_page.chrome().client().addMessageToConsole(source, level, message, lineNumber, columnNumber, url);
- if (!page->settings().logsPageMessagesToSystemConsoleEnabled() && !shouldPrintExceptions())
+ if (!m_page.settings().logsPageMessagesToSystemConsoleEnabled() && !shouldPrintExceptions())
return;
printSourceURLAndLine(url, lineNumber);
Modified: trunk/Source/WebCore/page/PageConsole.h (156624 => 156625)
--- trunk/Source/WebCore/page/PageConsole.h 2013-09-30 03:45:30 UTC (rev 156624)
+++ trunk/Source/WebCore/page/PageConsole.h 2013-09-30 04:36:35 UTC (rev 156625)
@@ -31,10 +31,13 @@
#include "ConsoleTypes.h"
#include "ScriptCallStack.h"
-#include "ScriptState.h"
#include <wtf/Forward.h>
#include <wtf/PassOwnPtr.h>
+namespace JSC {
+class ExecState;
+}
+
namespace WebCore {
class Document;
@@ -42,8 +45,8 @@
class PageConsole {
public:
- static PassOwnPtr<PageConsole> create(Page* page) { return adoptPtr(new PageConsole(page)); }
- virtual ~PageConsole();
+ PageConsole(Page&);
+ ~PageConsole();
static void printSourceURLAndLine(const String& sourceURL, unsigned lineNumber);
static void printMessageSourceAndLevelPrefix(MessageSource, MessageLevel);
@@ -59,11 +62,7 @@
static void setShouldPrintExceptions(bool);
private:
- PageConsole(Page*);
-
- Page* page() { return m_page; };
-
- Page* m_page;
+ Page& m_page;
};
} // namespace WebCore
Modified: trunk/Source/WebCore/page/PageThrottler.cpp (156624 => 156625)
--- trunk/Source/WebCore/page/PageThrottler.cpp 2013-09-30 03:45:30 UTC (rev 156624)
+++ trunk/Source/WebCore/page/PageThrottler.cpp 2013-09-30 04:36:35 UTC (rev 156625)
@@ -31,42 +31,48 @@
#include "MainFrame.h"
#include "Page.h"
#include "PageActivityAssertionToken.h"
+#include <wtf/StdLibExtras.h>
namespace WebCore {
static const double kThrottleHysteresisSeconds = 2.0;
-PageThrottler::PageThrottler(Page* page)
+PageThrottler::PageThrottler(Page& page)
: m_page(page)
, m_throttleState(PageNotThrottledState)
, m_throttleHysteresisTimer(this, &PageThrottler::throttleHysteresisTimerFired)
{
- m_page->chrome().client().incrementActivePageCount();
+ m_page.chrome().client().incrementActivePageCount();
}
PageThrottler::~PageThrottler()
{
setThrottled(false);
- for (HashSet<PageActivityAssertionToken*>::iterator i = m_activityTokens.begin(); i != m_activityTokens.end(); ++i)
- (*i)->invalidate();
+ for (auto it = m_activityTokens.begin(), end = m_activityTokens.end(); it != end; ++it)
+ (*it)->invalidate();
if (m_throttleState != PageThrottledState)
- m_page->chrome().client().decrementActivePageCount();
+ m_page.chrome().client().decrementActivePageCount();
}
+std::unique_ptr<PageActivityAssertionToken> PageThrottler::createActivityToken()
+{
+ return std::make_unique<PageActivityAssertionToken>(*this);
+}
+
void PageThrottler::throttlePage()
{
m_throttleState = PageThrottledState;
- m_page->chrome().client().decrementActivePageCount();
+ m_page.chrome().client().decrementActivePageCount();
- for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
+ for (Frame* frame = &m_page.mainFrame(); frame; frame = frame->tree().traverseNext()) {
if (frame->document())
frame->document()->scriptedAnimationControllerSetThrottled(true);
}
- m_page->throttleTimers();
+ m_page.throttleTimers();
}
void PageThrottler::unthrottlePage()
@@ -78,14 +84,14 @@
return;
if (oldState == PageThrottledState)
- m_page->chrome().client().incrementActivePageCount();
+ m_page.chrome().client().incrementActivePageCount();
- for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
+ for (Frame* frame = &m_page.mainFrame(); frame; frame = frame->tree().traverseNext()) {
if (frame->document())
frame->document()->scriptedAnimationControllerSetThrottled(false);
}
- m_page->unthrottleTimers();
+ m_page.unthrottleTimers();
}
void PageThrottler::setThrottled(bool isThrottled)
@@ -128,11 +134,11 @@
throttlePage();
}
-void PageThrottler::addActivityToken(PageActivityAssertionToken* token)
+void PageThrottler::addActivityToken(PageActivityAssertionToken& token)
{
- ASSERT(token && !m_activityTokens.contains(token));
+ ASSERT(!m_activityTokens.contains(&token));
- m_activityTokens.add(token);
+ m_activityTokens.add(&token);
// If we've already got events that block throttling we can return early
if (m_activityTokens.size() > 1)
@@ -148,11 +154,11 @@
stopThrottleHysteresisTimer();
}
-void PageThrottler::removeActivityToken(PageActivityAssertionToken* token)
+void PageThrottler::removeActivityToken(PageActivityAssertionToken& token)
{
- ASSERT(token && m_activityTokens.contains(token));
+ ASSERT(m_activityTokens.contains(&token));
- m_activityTokens.remove(token);
+ m_activityTokens.remove(&token);
if (m_activityTokens.size())
return;
Modified: trunk/Source/WebCore/page/PageThrottler.h (156624 => 156625)
--- trunk/Source/WebCore/page/PageThrottler.h 2013-09-30 03:45:30 UTC (rev 156624)
+++ trunk/Source/WebCore/page/PageThrottler.h 2013-09-30 04:36:35 UTC (rev 156625)
@@ -39,11 +39,11 @@
class PageThrottler {
public:
- static PassOwnPtr<PageThrottler> create(Page* page)
- {
- return adoptPtr(new PageThrottler(page));
- }
+ PageThrottler(Page&);
+ ~PageThrottler();
+ std::unique_ptr<PageActivityAssertionToken> createActivityToken();
+
bool shouldThrottleAnimations() const { return m_throttleState != PageNotThrottledState; }
bool shouldThrottleTimers() const { return m_throttleState != PageNotThrottledState; }
@@ -51,8 +51,6 @@
void reportInterestingEvent();
- ~PageThrottler();
-
private:
enum PageThrottleState {
PageNotThrottledState,
@@ -61,19 +59,17 @@
};
friend class PageActivityAssertionToken;
- void addActivityToken(PageActivityAssertionToken*);
- void removeActivityToken(PageActivityAssertionToken*);
+ void addActivityToken(PageActivityAssertionToken&);
+ void removeActivityToken(PageActivityAssertionToken&);
- PageThrottler(Page*);
void startThrottleHysteresisTimer();
void stopThrottleHysteresisTimer();
void throttleHysteresisTimerFired(Timer<PageThrottler>*);
- Page* m_page;
-
void throttlePage();
void unthrottlePage();
+ Page& m_page;
PageThrottleState m_throttleState;
Timer<PageThrottler> m_throttleHysteresisTimer;
HashSet<PageActivityAssertionToken*> m_activityTokens;