Title: [207308] trunk/Source/WebKit
Revision
207308
Author
ander...@apple.com
Date
2016-10-13 14:36:02 -0700 (Thu, 13 Oct 2016)

Log Message

Copy BackForwardList from WebCore to WebKit/win
https://bugs.webkit.org/show_bug.cgi?id=163360

Reviewed by Alex Christensen.

Source/WebKit:

This is the first step towards getting rid of BackForwardList in WebCore.

* PlatformWin.cmake:
Add new files.

Source/WebKit/win:

Use our local BackForwardList class instead of WebCore::BackForwardList.

* BackForwardList.cpp: Added.
* BackForwardList.h: Added.
* WebBackForwardList.h:
* WebView.cpp:
(WebView::initWithFrame):
(WebView::backForwardList):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (207307 => 207308)


--- trunk/Source/WebKit/ChangeLog	2016-10-13 21:08:02 UTC (rev 207307)
+++ trunk/Source/WebKit/ChangeLog	2016-10-13 21:36:02 UTC (rev 207308)
@@ -1,3 +1,15 @@
+2016-10-12  Anders Carlsson  <ander...@apple.com>
+
+        Copy BackForwardList from WebCore to WebKit/win
+        https://bugs.webkit.org/show_bug.cgi?id=163360
+
+        Reviewed by Alex Christensen.
+
+        This is the first step towards getting rid of BackForwardList in WebCore.
+
+        * PlatformWin.cmake:
+        Add new files.
+
 2016-10-11  Alex Christensen  <achristen...@webkit.org>
 
         Remove dead networking code

Modified: trunk/Source/WebKit/PlatformWin.cmake (207307 => 207308)


--- trunk/Source/WebKit/PlatformWin.cmake	2016-10-13 21:08:02 UTC (rev 207307)
+++ trunk/Source/WebKit/PlatformWin.cmake	2016-10-13 21:36:02 UTC (rev 207308)
@@ -144,6 +144,7 @@
     win/AccessibleDocument.cpp
     win/AccessibleImage.cpp
     win/AccessibleTextImpl.cpp
+    win/BackForwardList.cpp
     win/CFDictionaryPropertyBag.cpp
     win/DOMCSSClasses.cpp
     win/DOMCoreClasses.cpp

Added: trunk/Source/WebKit/win/BackForwardList.cpp (0 => 207308)


--- trunk/Source/WebKit/win/BackForwardList.cpp	                        (rev 0)
+++ trunk/Source/WebKit/win/BackForwardList.cpp	2016-10-13 21:36:02 UTC (rev 207308)
@@ -0,0 +1,267 @@
+/*
+ * Copyright (C) 2005, 2006 Apple Inc.  All rights reserved.
+ * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "WebKitDLL.h"
+#include "BackForwardList.h"
+
+#include <WebCore/Frame.h>
+#include <WebCore/FrameLoader.h>
+#include <WebCore/FrameLoaderClient.h>
+#include <WebCore/HistoryItem.h>
+#include <WebCore/Logging.h>
+#include <WebCore/Page.h>
+#include <WebCore/PageCache.h>
+#include <WebCore/SerializedScriptValue.h>
+
+static const unsigned DefaultCapacity = 100;
+static const unsigned NoCurrentItemIndex = UINT_MAX;
+
+using namespace WebCore;
+
+BackForwardList::BackForwardList()
+    : m_current(NoCurrentItemIndex)
+    , m_capacity(DefaultCapacity)
+    , m_closed(true)
+    , m_enabled(true)
+{
+}
+
+BackForwardList::~BackForwardList()
+{
+    ASSERT(m_closed);
+}
+
+void BackForwardList::addItem(Ref<HistoryItem>&& newItem)
+{
+    if (!m_capacity || !m_enabled)
+        return;
+    
+    // Toss anything in the forward list    
+    if (m_current != NoCurrentItemIndex) {
+        unsigned targetSize = m_current + 1;
+        while (m_entries.size() > targetSize) {
+            Ref<HistoryItem> item = m_entries.takeLast();
+            m_entryHash.remove(item.ptr());
+            PageCache::singleton().remove(item);
+        }
+    }
+
+    // Toss the first item if the list is getting too big, as long as we're not using it
+    // (or even if we are, if we only want 1 entry).
+    if (m_entries.size() == m_capacity && (m_current || m_capacity == 1)) {
+        Ref<HistoryItem> item = WTFMove(m_entries[0]);
+        m_entries.remove(0);
+        m_entryHash.remove(item.ptr());
+        PageCache::singleton().remove(item);
+        --m_current;
+    }
+
+    m_entryHash.add(newItem.ptr());
+    m_entries.insert(m_current + 1, WTFMove(newItem));
+    ++m_current;
+}
+
+void BackForwardList::goBack()
+{
+    ASSERT(m_current > 0);
+    if (m_current > 0) {
+        m_current--;
+    }
+}
+
+void BackForwardList::goForward()
+{
+    ASSERT(m_current < m_entries.size() - 1);
+    if (m_current < m_entries.size() - 1) {
+        m_current++;
+    }
+}
+
+void BackForwardList::goToItem(HistoryItem* item)
+{
+    if (!m_entries.size() || !item)
+        return;
+        
+    unsigned int index = 0;
+    for (; index < m_entries.size(); ++index)
+        if (m_entries[index].ptr() == item)
+            break;
+    if (index < m_entries.size()) {
+        m_current = index;
+    }
+}
+
+HistoryItem* BackForwardList::backItem()
+{
+    if (m_current && m_current != NoCurrentItemIndex)
+        return m_entries[m_current - 1].ptr();
+    return nullptr;
+}
+
+HistoryItem* BackForwardList::currentItem()
+{
+    if (m_current != NoCurrentItemIndex)
+        return m_entries[m_current].ptr();
+    return nullptr;
+}
+
+HistoryItem* BackForwardList::forwardItem()
+{
+    if (m_entries.size() && m_current < m_entries.size() - 1)
+        return m_entries[m_current + 1].ptr();
+    return nullptr;
+}
+
+void BackForwardList::backListWithLimit(int limit, Vector<Ref<HistoryItem>>& list)
+{
+    list.clear();
+    if (m_current != NoCurrentItemIndex) {
+        unsigned first = std::max(static_cast<int>(m_current) - limit, 0);
+        for (; first < m_current; ++first)
+            list.append(m_entries[first].get());
+    }
+}
+
+void BackForwardList::forwardListWithLimit(int limit, Vector<Ref<HistoryItem>>& list)
+{
+    ASSERT(limit > -1);
+    list.clear();
+    if (!m_entries.size())
+        return;
+        
+    unsigned lastEntry = m_entries.size() - 1;
+    if (m_current < lastEntry) {
+        int last = std::min(m_current + limit, lastEntry);
+        limit = m_current + 1;
+        for (; limit <= last; ++limit)
+            list.append(m_entries[limit].get());
+    }
+}
+
+int BackForwardList::capacity()
+{
+    return m_capacity;
+}
+
+void BackForwardList::setCapacity(int size)
+{    
+    while (size < static_cast<int>(m_entries.size())) {
+        Ref<HistoryItem> item = m_entries.takeLast();
+        m_entryHash.remove(item.ptr());
+        PageCache::singleton().remove(item);
+    }
+
+    if (!size)
+        m_current = NoCurrentItemIndex;
+    else if (m_current > m_entries.size() - 1) {
+        m_current = m_entries.size() - 1;
+    }
+    m_capacity = size;
+}
+
+bool BackForwardList::enabled()
+{
+    return m_enabled;
+}
+
+void BackForwardList::setEnabled(bool enabled)
+{
+    m_enabled = enabled;
+    if (!enabled) {
+        int capacity = m_capacity;
+        setCapacity(0);
+        setCapacity(capacity);
+    }
+}
+
+int BackForwardList::backListCount()
+{
+    return m_current == NoCurrentItemIndex ? 0 : m_current;
+}
+
+int BackForwardList::forwardListCount()
+{
+    return m_current == NoCurrentItemIndex ? 0 : (int)m_entries.size() - (m_current + 1);
+}
+
+HistoryItem* BackForwardList::itemAtIndex(int index)
+{
+    // Do range checks without doing math on index to avoid overflow.
+    if (index < -static_cast<int>(m_current))
+        return nullptr;
+    
+    if (index > forwardListCount())
+        return nullptr;
+        
+    return m_entries[index + m_current].ptr();
+}
+
+Vector<Ref<HistoryItem>>& BackForwardList::entries()
+{
+    return m_entries;
+}
+
+void BackForwardList::close()
+{
+    for (auto& item : m_entries)
+        PageCache::singleton().remove(item);
+    m_entries.clear();
+    m_entryHash.clear();
+    m_closed = true;
+}
+
+bool BackForwardList::closed()
+{
+    return m_closed;
+}
+
+void BackForwardList::removeItem(HistoryItem* item)
+{
+    if (!item)
+        return;
+    
+    for (unsigned i = 0; i < m_entries.size(); ++i) {
+        if (m_entries[i].ptr() == item) {
+            m_entries.remove(i);
+            m_entryHash.remove(item);
+            if (m_current == NoCurrentItemIndex || m_current < i)
+                break;
+            if (m_current > i)
+                m_current--;
+            else {
+                size_t count = m_entries.size();
+                if (m_current >= count)
+                    m_current = count ? count - 1 : NoCurrentItemIndex;
+            }
+            break;
+        }
+    }
+}
+
+bool BackForwardList::containsItem(HistoryItem* entry)
+{
+    return m_entryHash.contains(entry);
+}

Added: trunk/Source/WebKit/win/BackForwardList.h (0 => 207308)


--- trunk/Source/WebKit/win/BackForwardList.h	                        (rev 0)
+++ trunk/Source/WebKit/win/BackForwardList.h	2016-10-13 21:36:02 UTC (rev 207308)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2006, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
+ * Copyright (C) 2009 Google, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#pragma once
+
+#include <WebCore/BackForwardClient.h>
+#include <wtf/HashSet.h>
+#include <wtf/Vector.h>
+
+typedef Vector<Ref<WebCore::HistoryItem>> HistoryItemVector;
+typedef HashSet<RefPtr<WebCore::HistoryItem>> HistoryItemHashSet;
+
+class BackForwardList : public WebCore::BackForwardClient {
+public: 
+    static Ref<BackForwardList> create() { return adoptRef(*new BackForwardList()); }
+    virtual ~BackForwardList();
+
+    void addItem(Ref<WebCore::HistoryItem>&&) override;
+    void goBack();
+    void goForward();
+    void goToItem(WebCore::HistoryItem*) override;
+        
+    WebCore::HistoryItem* backItem();
+    WebCore::HistoryItem* currentItem();
+    WebCore::HistoryItem* forwardItem();
+    WebCore::HistoryItem* itemAtIndex(int) override;
+
+    void backListWithLimit(int, HistoryItemVector&);
+    void forwardListWithLimit(int, HistoryItemVector&);
+
+    int capacity();
+    void setCapacity(int);
+    bool enabled();
+    void setEnabled(bool);
+    int backListCount() override;
+    int forwardListCount() override;
+    bool containsItem(WebCore::HistoryItem*);
+
+    void close() override;
+    bool closed();
+
+    void removeItem(WebCore::HistoryItem*);
+    HistoryItemVector& entries();
+
+private:
+    explicit BackForwardList();
+
+    HistoryItemVector m_entries;
+    HistoryItemHashSet m_entryHash;
+    unsigned m_current;
+    unsigned m_capacity;
+    bool m_closed;
+    bool m_enabled;
+};

Modified: trunk/Source/WebKit/win/ChangeLog (207307 => 207308)


--- trunk/Source/WebKit/win/ChangeLog	2016-10-13 21:08:02 UTC (rev 207307)
+++ trunk/Source/WebKit/win/ChangeLog	2016-10-13 21:36:02 UTC (rev 207308)
@@ -1,3 +1,19 @@
+2016-10-12  Anders Carlsson  <ander...@apple.com>
+
+        Copy BackForwardList from WebCore to WebKit/win
+        https://bugs.webkit.org/show_bug.cgi?id=163360
+
+        Reviewed by Alex Christensen.
+
+        Use our local BackForwardList class instead of WebCore::BackForwardList.
+
+        * BackForwardList.cpp: Added.
+        * BackForwardList.h: Added.
+        * WebBackForwardList.h:
+        * WebView.cpp:
+        (WebView::initWithFrame):
+        (WebView::backForwardList):
+
 2016-10-13  Anders Carlsson  <ander...@apple.com>
 
         Get rid of the HistoryItemVector typedef

Modified: trunk/Source/WebKit/win/WebBackForwardList.cpp (207307 => 207308)


--- trunk/Source/WebKit/win/WebBackForwardList.cpp	2016-10-13 21:08:02 UTC (rev 207307)
+++ trunk/Source/WebKit/win/WebBackForwardList.cpp	2016-10-13 21:36:02 UTC (rev 207308)
@@ -26,11 +26,11 @@
 #include "WebKitDLL.h"
 #include "WebBackForwardList.h"
 
+#include "BackForwardList.h"
 #include "WebFrame.h"
 #include "WebKit.h"
 #include "WebPreferences.h"
 
-#include <WebCore/BackForwardList.h>
 #include <WebCore/COMPtr.h>
 #include <WebCore/HistoryItem.h>
 

Modified: trunk/Source/WebKit/win/WebBackForwardList.h (207307 => 207308)


--- trunk/Source/WebKit/win/WebBackForwardList.h	2016-10-13 21:08:02 UTC (rev 207307)
+++ trunk/Source/WebKit/win/WebBackForwardList.h	2016-10-13 21:36:02 UTC (rev 207308)
@@ -23,8 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef WebBackForwardList_H
-#define WebBackForwardList_H
+#pragma once
 
 #include "WebKit.h"
 
@@ -33,16 +32,14 @@
 #include <WTF/PassRefPtr.h>
 #include <WTF/RefPtr.h>
 
-namespace WebCore {
-    class BackForwardList;
-}
+class BackForwardList;
 
 class WebBackForwardList : public IWebBackForwardList, IWebBackForwardListPrivate
 {
 public:
-    static WebBackForwardList* createInstance(PassRefPtr<WebCore::BackForwardList>);
+    static WebBackForwardList* createInstance(PassRefPtr<BackForwardList>);
 protected:
-    WebBackForwardList(PassRefPtr<WebCore::BackForwardList>);
+    WebBackForwardList(PassRefPtr<BackForwardList>);
     ~WebBackForwardList();
 
 public:
@@ -73,7 +70,5 @@
 
 protected:
     ULONG m_refCount { 0 };
-    RefPtr<WebCore::BackForwardList> m_backForwardList;
+    RefPtr<BackForwardList> m_backForwardList;
 };
-
-#endif

Modified: trunk/Source/WebKit/win/WebView.cpp (207307 => 207308)


--- trunk/Source/WebKit/win/WebView.cpp	2016-10-13 21:08:02 UTC (rev 207307)
+++ trunk/Source/WebKit/win/WebView.cpp	2016-10-13 21:36:02 UTC (rev 207308)
@@ -27,7 +27,7 @@
 
 #include "WebView.h"
 
-#include "BackForwardController.h"
+#include "BackForwardList.h"
 #include "COMVariantSetter.h"
 #include "DOMCoreClasses.h"
 #include "FullscreenVideoController.h"
@@ -84,7 +84,6 @@
 #include <WebCore/ApplicationCacheStorage.h>
 #include <WebCore/BString.h>
 #include <WebCore/BackForwardController.h>
-#include <WebCore/BackForwardList.h>
 #include <WebCore/BitmapInfo.h>
 #include <WebCore/Chrome.h>
 #include <WebCore/ContextMenu.h>
@@ -3099,6 +3098,7 @@
     m_inspectorClient = new WebInspectorClient(this);
 
     PageConfiguration configuration(makeUniqueRef<WebEditorClient>(this), SocketProvider::create());
+    configuration.backForwardClient = BackForwardList::create();
     configuration.chromeClient = new WebChromeClient(this);
     configuration.contextMenuClient = new WebContextMenuClient(this);
     configuration.dragClient = new WebDragClient(this);
@@ -3430,7 +3430,7 @@
     if (!m_useBackForwardList)
         return E_FAIL;
  
-    *list = WebBackForwardList::createInstance(static_cast<WebCore::BackForwardList*>(m_page->backForward().client()));
+    *list = WebBackForwardList::createInstance(static_cast<BackForwardList*>(m_page->backForward().client()));
 
     return S_OK;
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to