Title: [198468] trunk/Source/WebKit2
Revision
198468
Author
[email protected]
Date
2016-03-19 00:17:41 -0700 (Sat, 19 Mar 2016)

Log Message

https://bugs.webkit.org/show_bug.cgi?id=155664
Consider to cap the size of session history data.

In iOS, if the total history entries data exceeds a threshold (2MB at the moment), don't
accumulate more data into the session state blob.

Patch by Yongjun Zhang <[email protected]> on 2016-03-19
Reviewed by Darin Adler.

* UIProcess/mac/LegacySessionStateCoding.cpp:
(WebKit::encodeSessionHistory): Stop encoding further history entries data into session state
    if the total size exceed 2MB in iOS.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (198467 => 198468)


--- trunk/Source/WebKit2/ChangeLog	2016-03-19 05:05:02 UTC (rev 198467)
+++ trunk/Source/WebKit2/ChangeLog	2016-03-19 07:17:41 UTC (rev 198468)
@@ -1,3 +1,17 @@
+2016-03-19  Yongjun Zhang  <[email protected]>
+
+        https://bugs.webkit.org/show_bug.cgi?id=155664
+        Consider to cap the size of session history data.
+
+        In iOS, if the total history entries data exceeds a threshold (2MB at the moment), don't
+        accumulate more data into the session state blob.
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/mac/LegacySessionStateCoding.cpp:
+        (WebKit::encodeSessionHistory): Stop encoding further history entries data into session state
+            if the total size exceed 2MB in iOS.
+
 2016-03-18  Alex Christensen  <[email protected]>
 
         Give NSURLSessionConfiguration information about parent process

Modified: trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.cpp (198467 => 198468)


--- trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.cpp	2016-03-19 05:05:02 UTC (rev 198467)
+++ trunk/Source/WebKit2/UIProcess/mac/LegacySessionStateCoding.cpp	2016-03-19 07:17:41 UTC (rev 198468)
@@ -59,6 +59,13 @@
 // Session history entry data.
 const uint32_t sessionHistoryEntryDataVersion = 2;
 
+// Maximum size for subframe session data.
+#if PLATFORM(IOS)
+static const uint32_t maximumSessionStateDataSize = 2 * 1024 * 1024;
+#else
+static const uint32_t maximumSessionStateDataSize = std::numeric_limits<uint32_t>::max();
+#endif
+
 template<typename T> void isValidEnum(T);
 
 class HistoryEntryDataEncoder {
@@ -421,23 +428,37 @@
         return createDictionary({ { sessionHistoryVersionKey, sessionHistoryVersionNumber.get() } });
 
     auto entries = adoptCF(CFArrayCreateMutable(kCFAllocatorDefault, backForwardListState.items.size(), &kCFTypeArrayCallBacks));
+    size_t totalDataSize = 0;
 
     for (const auto& item : backForwardListState.items) {
         auto url = ""
         auto title = item.pageState.title.createCFString();
         auto originalURL = item.pageState.mainFrameState.originalURLString.createCFString();
-        auto data = ""
+        auto data = "" <= maximumSessionStateDataSize ? encodeSessionHistoryEntryData(item.pageState.mainFrameState) : nullptr;
         auto shouldOpenExternalURLsPolicyValue = static_cast<uint64_t>(item.pageState.shouldOpenExternalURLsPolicy);
         auto shouldOpenExternalURLsPolicy = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &shouldOpenExternalURLsPolicyValue));
 
-        auto entryDictionary = createDictionary({
-            { sessionHistoryEntryURLKey, url.get() },
-            { sessionHistoryEntryTitleKey, title.get() },
-            { sessionHistoryEntryOriginalURLKey, originalURL.get() },
-            { sessionHistoryEntryDataKey, data.get() },
-            { sessionHistoryEntryShouldOpenExternalURLsPolicyKey, shouldOpenExternalURLsPolicy.get() },
-        });
+        RetainPtr<CFDictionaryRef> entryDictionary;
 
+        if (data) {
+            totalDataSize += CFDataGetLength(data.get());
+
+            entryDictionary = createDictionary({
+                { sessionHistoryEntryURLKey, url.get() },
+                { sessionHistoryEntryTitleKey, title.get() },
+                { sessionHistoryEntryOriginalURLKey, originalURL.get() },
+                { sessionHistoryEntryDataKey, data.get() },
+                { sessionHistoryEntryShouldOpenExternalURLsPolicyKey, shouldOpenExternalURLsPolicy.get() },
+            });
+        } else {
+            entryDictionary = createDictionary({
+                { sessionHistoryEntryURLKey, url.get() },
+                { sessionHistoryEntryTitleKey, title.get() },
+                { sessionHistoryEntryOriginalURLKey, originalURL.get() },
+                { sessionHistoryEntryShouldOpenExternalURLsPolicyKey, shouldOpenExternalURLsPolicy.get() },
+            });
+        }
+
         CFArrayAppendValue(entries.get(), entryDictionary.get());
     }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to