Index: third_party/WebKit/Source/core/page/Page.cpp |
diff --git a/third_party/WebKit/Source/core/page/Page.cpp b/third_party/WebKit/Source/core/page/Page.cpp |
index 6ed312c28645668efdf089e6a98768aae7dbaed9..c587b9c432764e6330589cf8235ef912fcdad5e3 100644 |
--- a/third_party/WebKit/Source/core/page/Page.cpp |
+++ b/third_party/WebKit/Source/core/page/Page.cpp |
@@ -50,6 +50,7 @@ |
#include "core/paint/PaintLayer.h" |
#include "platform/graphics/GraphicsLayer.h" |
#include "platform/plugins/PluginData.h" |
+#include "platform/text/CompressibleString.h" |
#include "public/platform/Platform.h" |
namespace blink { |
@@ -136,6 +137,7 @@ Page::Page(PageClients& pageClients) |
, m_isPainting(false) |
#endif |
, m_frameHost(FrameHost::create(*this)) |
+ , m_timerForCompressStrings(this, &Page::compressStrings) |
{ |
ASSERT(m_editorClient); |
@@ -363,6 +365,9 @@ void Page::visitedStateChanged(LinkHash linkHash) |
void Page::setVisibilityState(PageVisibilityState visibilityState, bool isInitialState) |
{ |
+ static const double waitingTimeBeforeCompressingString = 10; |
+ |
+ CompressibleStringImpl::setPageBackground(visibilityState == PageVisibilityStateHidden); |
if (m_visibilityState == visibilityState) |
return; |
m_visibilityState = visibilityState; |
@@ -372,6 +377,15 @@ void Page::setVisibilityState(PageVisibilityState visibilityState, bool isInitia |
if (!isInitialState && m_mainFrame && m_mainFrame->isLocalFrame()) |
deprecatedLocalMainFrame()->didChangeVisibilityState(); |
+ |
+ // Compress CompressibleStrings when 10 seconds have passed since the page |
+ // went to background. |
+ if (m_visibilityState == PageVisibilityStateHidden) { |
+ if (!m_timerForCompressStrings.isActive()) |
+ m_timerForCompressStrings.startOneShot(waitingTimeBeforeCompressingString, BLINK_FROM_HERE); |
+ } else if (m_timerForCompressStrings.isActive()) { |
+ m_timerForCompressStrings.stop(); |
+ } |
} |
PageVisibilityState Page::visibilityState() const |
@@ -584,6 +598,13 @@ void Page::willBeDestroyed() |
PageLifecycleNotifier::notifyContextDestroyed(); |
} |
+void Page::compressStrings(Timer<Page>* timer) |
+{ |
+ ASSERT_UNUSED(timer, timer == &m_timerForCompressStrings); |
+ if (m_visibilityState == PageVisibilityStateHidden) |
+ CompressibleStringImpl::compressAll(); |
+} |
+ |
Page::PageClients::PageClients() |
: chromeClient(nullptr) |
, contextMenuClient(nullptr) |