Add to HistoryItem a way to know if its underlying CachedPage has expired.
authoralice.liu@apple.com <alice.liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Mar 2013 07:30:59 +0000 (07:30 +0000)
committeralice.liu@apple.com <alice.liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Mar 2013 07:30:59 +0000 (07:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=110652

Reviewed by Brady Eidson.

Source/WebCore:

* WebCore.exp.in: Added WebCore::HistoryItem::isInPageCache and hasCachedPageExpired.
* history/CachedPage.cpp: Add a data member, m_expirationTime, and a function, hasExpired().
* history/CachedPage.h:
* history/HistoryItem.cpp:
(WebCore::HistoryItem::hasCachedPageExpired): Added. returns m_cachedPage's expiration state.
* history/HistoryItem.h:
* history/PageCache.cpp:
(WebCore::PageCache::get):  Address the fixme about not using WebKitBackForwardCacheExpirationIntervalKey.
* page/Settings.in: Add backForwardCacheExpirationInterval to the automatically generated setters for Settings.

Source/WebKit/mac:

* History/WebHistoryItem.mm:
(-[WebHistoryItem _isInPageCache]): Added. Just calls and returns core imple's function.
(-[WebHistoryItem _hasCachedPageExpired]): Same thing.
* History/WebHistoryItemPrivate.h:
* WebView/WebPreferences.mm:
(-[WebPreferences _backForwardCacheExpirationInterval]): Address fixme, now that WebCore::Settings
has getters and setters with default value.
* WebView/WebView.mm:
(-[WebView _preferencesChanged:]): call setBackForwardCacheExpirationInterval similar to other settings.

Source/WebKit2:

Hook up hasCachedPageExpired in InjectedBundle's BackForwardListItem.
* WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.cpp:
(WKBundleBackForwardListItemHasCachedPageExpired):
* WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.h:
* WebProcess/InjectedBundle/InjectedBundleBackForwardListItem.h:
(WebKit::InjectedBundleBackForwardListItem::hasCachedPageExpired):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@145789 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/history/CachedPage.cpp
Source/WebCore/history/CachedPage.h
Source/WebCore/history/HistoryItem.cpp
Source/WebCore/history/HistoryItem.h
Source/WebCore/history/PageCache.cpp
Source/WebCore/page/Settings.in
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/History/WebHistoryItem.mm
Source/WebKit/mac/History/WebHistoryItemPrivate.h
Source/WebKit/mac/WebView/WebPreferences.mm
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.h
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleBackForwardListItem.h

index bc26279..8dcfd11 100644 (file)
@@ -1,3 +1,20 @@
+2013-03-14  Alice Liu  <alice.liu@apple.com>
+
+        Add to HistoryItem a way to know if its underlying CachedPage has expired.
+        https://bugs.webkit.org/show_bug.cgi?id=110652
+
+        Reviewed by Brady Eidson.
+
+        * WebCore.exp.in: Added WebCore::HistoryItem::isInPageCache and hasCachedPageExpired.
+        * history/CachedPage.cpp: Add a data member, m_expirationTime, and a function, hasExpired().
+        * history/CachedPage.h:
+        * history/HistoryItem.cpp:
+        (WebCore::HistoryItem::hasCachedPageExpired): Added. returns m_cachedPage's expiration state.
+        * history/HistoryItem.h:
+        * history/PageCache.cpp:
+        (WebCore::PageCache::get):  Address the fixme about not using WebKitBackForwardCacheExpirationIntervalKey. 
+        * page/Settings.in: Add backForwardCacheExpirationInterval to the automatically generated setters for Settings.
+
 2013-03-13  Ryosuke Niwa  <rniwa@webkit.org>
 
         Cannot select a canvas element at the beginning or the end of a document
index 3b6adcc..527d395 100644 (file)
@@ -1221,6 +1221,7 @@ __ZNK7WebCore11HistoryItem15pageScaleFactorEv
 __ZNK7WebCore11HistoryItem17originalURLStringEv
 __ZNK7WebCore11HistoryItem19childItemWithTargetERKN3WTF6StringE
 __ZNK7WebCore11HistoryItem20getTransientPropertyERKN3WTF6StringE
+__ZNK7WebCore11HistoryItem20hasCachedPageExpiredEv
 __ZNK7WebCore11HistoryItem21encodeBackForwardTreeERN3WTF7EncoderE
 __ZNK7WebCore11HistoryItem3urlEv
 __ZNK7WebCore11HistoryItem4copyEv
index d8f0ac4..28d03e5 100644 (file)
@@ -33,6 +33,7 @@
 #include "FrameView.h"
 #include "Node.h"
 #include "Page.h"
+#include "Settings.h"
 #include "VisitedLinkState.h"
 #include <wtf/CurrentTime.h>
 #include <wtf/RefCountedLeakCounter.h>
@@ -51,6 +52,7 @@ PassRefPtr<CachedPage> CachedPage::create(Page* page)
 
 CachedPage::CachedPage(Page* page)
     : m_timeStamp(currentTime())
+    , m_expirationTime(m_timeStamp + page->settings()->backForwardCacheExpirationInterval())
     , m_cachedMainFrame(CachedFrame::create(page->mainFrame()))
     , m_needStyleRecalcForVisitedLinks(false)
     , m_needsFullStyleRecalc(false)
@@ -114,4 +116,9 @@ void CachedPage::destroy()
     m_cachedMainFrame = 0;
 }
 
+bool CachedPage::hasExpired() const
+{
+    return currentTime() > m_expirationTime;
+}
+
 } // namespace WebCore
index e5866cf..118f94e 100644 (file)
@@ -48,6 +48,7 @@ public:
     DocumentLoader* documentLoader() const { return m_cachedMainFrame->documentLoader(); }
 
     double timeStamp() const { return m_timeStamp; }
+    bool hasExpired() const;
     
     CachedFrame* cachedMainFrame() { return m_cachedMainFrame.get(); }
 
@@ -58,6 +59,7 @@ private:
     CachedPage(Page*);
 
     double m_timeStamp;
+    double m_expirationTime;
     RefPtr<CachedFrame> m_cachedMainFrame;
     bool m_needStyleRecalcForVisitedLinks;
     bool m_needsFullStyleRecalc;
index 049ce5a..a5d9500 100644 (file)
@@ -230,6 +230,11 @@ const String& HistoryItem::alternateTitle() const
     return m_displayTitle;
 }
 
+bool HistoryItem::hasCachedPageExpired() const
+{
+    return m_cachedPage ? m_cachedPage->hasExpired() : false;
+}
+
 double HistoryItem::lastVisitedTime() const
 {
     return m_lastVisitedTime;
index 5db4d97..bece463 100644 (file)
@@ -102,6 +102,7 @@ public:
     const String& title() const;
     
     bool isInPageCache() const { return m_cachedPage; }
+    bool hasCachedPageExpired() const;
     
     double lastVisitedTime() const;
     
index 54f4694..5c1562a 100644 (file)
@@ -461,10 +461,7 @@ CachedPage* PageCache::get(HistoryItem* item)
         return 0;
 
     if (CachedPage* cachedPage = item->m_cachedPage.get()) {
-        // FIXME: 1800 should not be hardcoded, it should come from
-        // WebKitBackForwardCacheExpirationIntervalKey in WebKit.
-        // Or we should remove WebKitBackForwardCacheExpirationIntervalKey.
-        if (currentTime() - cachedPage->timeStamp() <= 1800)
+        if (!cachedPage->hasExpired())
             return cachedPage;
         
         LOG(PageCache, "Not restoring page for %s from back/forward cache because cache entry has expired", item->url().string().ascii().data());
index 286636c..1c490fd 100644 (file)
@@ -195,6 +195,8 @@ unifiedTextCheckerEnabled initial=defaultUnifiedTextCheckerEnabled
 
 logsPageMessagesToSystemConsoleEnabled initial=false
 
+backForwardCacheExpirationInterval type=double, initial=1800
+
 # Some apps could have a default video poster if it is not set.
 defaultVideoPosterURL type=String
 
index 699aedf..793fc62 100644 (file)
@@ -1,3 +1,20 @@
+2013-03-14  Alice Liu  <alice.liu@apple.com>
+
+        Add to HistoryItem a way to know if its underlying CachedPage has expired.
+        https://bugs.webkit.org/show_bug.cgi?id=110652
+
+        Reviewed by Brady Eidson.
+
+        * History/WebHistoryItem.mm:
+        (-[WebHistoryItem _isInPageCache]): Added. Just calls and returns core imple's function. 
+        (-[WebHistoryItem _hasCachedPageExpired]): Same thing. 
+        * History/WebHistoryItemPrivate.h:
+        * WebView/WebPreferences.mm:
+        (-[WebPreferences _backForwardCacheExpirationInterval]): Address fixme, now that WebCore::Settings
+        has getters and setters with default value.
+        * WebView/WebView.mm:
+        (-[WebView _preferencesChanged:]): call setBackForwardCacheExpirationInterval similar to other settings.
+
 2013-03-13  Rik Cabanier  <cabanier@adobe.com>
 
         create runtime flags for CSS Compositing
index aab73ae..28278f8 100644 (file)
@@ -620,4 +620,14 @@ WebHistoryItem *kit(HistoryItem* item)
     return coreItem->weeklyVisitCounts().size();
 }
 
+- (BOOL)_isInPageCache
+{
+    return core(_private)->isInPageCache();
+}
+
+- (BOOL)_hasCachedPageExpired
+{
+    return core(_private)->hasCachedPageExpired();
+}
+
 @end
index 0c079a7..affc74a 100644 (file)
@@ -64,4 +64,7 @@
 - (size_t)_getDailyVisitCounts:(const int**)counts;
 - (size_t)_getWeeklyVisitCounts:(const int**)counts;
 
+- (BOOL)_isInPageCache;
+- (BOOL)_hasCachedPageExpired;
+
 @end
index d532ece..0c1d863 100644 (file)
@@ -1079,8 +1079,7 @@ public:
 
 - (NSTimeInterval)_backForwardCacheExpirationInterval
 {
-    // FIXME: There's probably no good reason to read from the standard user defaults instead of self.
-    return (NSTimeInterval)[[NSUserDefaults standardUserDefaults] floatForKey:WebKitBackForwardCacheExpirationIntervalKey];
+    return (NSTimeInterval)[self _floatValueForKey:WebKitBackForwardCacheExpirationIntervalKey];
 }
 
 - (float)PDFScaleFactor
index 5dab667..762756e 100644 (file)
@@ -1488,6 +1488,7 @@ static bool needsSelfRetainWhileLoadingQuirk()
     settings->setDOMPasteAllowed([preferences isDOMPasteAllowed]);
     settings->setUsesPageCache([self usesPageCache]);
     settings->setPageCacheSupportsPlugins([preferences pageCacheSupportsPlugins]);
+    settings->setBackForwardCacheExpirationInterval([preferences _backForwardCacheExpirationInterval]);
     settings->setShowsURLsInToolTips([preferences showsURLsInToolTips]);
     settings->setShowsToolTipOverTruncatedText([preferences showsToolTipOverTruncatedText]);
     settings->setDeveloperExtrasEnabled([preferences developerExtrasEnabled]);
index 90270ca..d4acd80 100644 (file)
@@ -1,3 +1,17 @@
+2013-03-14  Alice Liu  <alice.liu@apple.com>
+
+        Add to HistoryItem a way to know if its underlying CachedPage has expired.
+        https://bugs.webkit.org/show_bug.cgi?id=110652
+
+        Reviewed by Brady Eidson.
+
+        Hook up hasCachedPageExpired in InjectedBundle's BackForwardListItem.
+        * WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.cpp:
+        (WKBundleBackForwardListItemHasCachedPageExpired):
+        * WebProcess/InjectedBundle/API/c/WKBundleBackForwardListItem.h:
+        * WebProcess/InjectedBundle/InjectedBundleBackForwardListItem.h:
+        (WebKit::InjectedBundleBackForwardListItem::hasCachedPageExpired):
+
 2013-03-13  Rik Cabanier  <cabanier@adobe.com>
 
         create runtime flags for CSS Compositing
index 4b32b34..3a49bbf 100644 (file)
@@ -72,6 +72,11 @@ bool WKBundleBackForwardListItemIsInPageCache(WKBundleBackForwardListItemRef ite
     return toImpl(itemRef)->isInPageCache();
 }
 
+bool WKBundleBackForwardListItemHasCachedPageExpired(WKBundleBackForwardListItemRef itemRef)
+{
+    return toImpl(itemRef)->hasCachedPageExpired();
+}
+
 WKArrayRef WKBundleBackForwardListItemCopyChildren(WKBundleBackForwardListItemRef itemRef)
 {
     return toAPI(toImpl(itemRef)->children().leakRef());
index e9475ac..5ad9abe 100644 (file)
@@ -44,6 +44,7 @@ WK_EXPORT WKStringRef WKBundleBackForwardListItemCopyTarget(WKBundleBackForwardL
 WK_EXPORT bool WKBundleBackForwardListItemIsTargetItem(WKBundleBackForwardListItemRef item);
 
 WK_EXPORT bool WKBundleBackForwardListItemIsInPageCache(WKBundleBackForwardListItemRef item);
+WK_EXPORT bool WKBundleBackForwardListItemHasCachedPageExpired(WKBundleBackForwardListItemRef item);
 
 WK_EXPORT WKArrayRef WKBundleBackForwardListItemCopyChildren(WKBundleBackForwardListItemRef item);
 
index da08fb7..677fbc8 100644 (file)
@@ -54,6 +54,7 @@ public:
     const String& target() const { return m_item->target(); }
     bool isTargetItem() const { return m_item->isTargetItem(); }
     bool isInPageCache() const { return m_item->isInPageCache(); }
+    bool hasCachedPageExpired() const { return m_item->hasCachedPageExpired(); }
 
     PassRefPtr<ImmutableArray> children() const;