Adopt more uses OwnPtr/OwnArray in WebKit2.
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Aug 2010 01:49:15 +0000 (01:49 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Aug 2010 01:49:15 +0000 (01:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=44728

Reviewed by Darin Adler.

Also clears up weird create vs. adoption semantics. Now both create
and adopt both don't ref their pointers, adoption is just about the
buffer.

* Shared/ImmutableArray.cpp:
(WebKit::ImmutableArray::ImmutableArray):
(WebKit::ImmutableArray::~ImmutableArray):
* Shared/ImmutableArray.h:
(WebKit::ImmutableArray::adopt):
* Shared/ImmutableDictionary.cpp:
(WebKit::ImmutableDictionary::keys):
* Shared/WebData.h:
* UIProcess/API/mac/PageClientImpl.h:
* UIProcess/API/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::create):
* UIProcess/API/mac/WKView.mm:
(-[WKView initWithFrame:pageNamespaceRef:]):
(-[WKView _switchToDrawingAreaTypeIfNecessary:DrawingAreaProxy::]):
* UIProcess/API/qt/qgraphicswkview.cpp:
(QGraphicsWKView::QGraphicsWKView):
* UIProcess/API/qt/qwkpage.cpp:
(QWKPagePrivate::init):
* UIProcess/API/qt/qwkpage_p.h:
* UIProcess/ChunkedUpdateDrawingAreaProxy.cpp:
(WebKit::ChunkedUpdateDrawingAreaProxy::create):
* UIProcess/ChunkedUpdateDrawingAreaProxy.h:
* UIProcess/LayerBackedDrawingAreaProxy.cpp:
(WebKit::LayerBackedDrawingAreaProxy::create):
* UIProcess/LayerBackedDrawingAreaProxy.h:
* UIProcess/WebBackForwardList.cpp:
(WebKit::WebBackForwardList::backListAsImmutableArrayWithLimit):
(WebKit::WebBackForwardList::forwardListAsImmutableArrayWithLimit):
* UIProcess/WebContext.cpp:
(WebKit::PostMessageEncoder::PostMessageDecoder::decode):
* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::PostMessageEncoder::PostMessageDecoder::decode):
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::createPopupMenu):
(WebKit::WebChromeClient::createSearchPopupMenu):
* WebProcess/WebCoreSupport/WebPopupMenu.cpp:
(WebKit::WebPopupMenu::create):
* WebProcess/WebCoreSupport/WebPopupMenu.h:
* WebProcess/WebCoreSupport/WebSearchPopupMenu.cpp:
(WebKit::WebSearchPopupMenu::create):
(WebKit::WebSearchPopupMenu::WebSearchPopupMenu):
* WebProcess/WebCoreSupport/WebSearchPopupMenu.h:
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::childFrames):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):
(WebKit::WebPage::close):
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::corePage):
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performDefaultBehaviorForKeyEvent):
* WebProcess/WebPage/win/WebPageWin.cpp:
(WebKit::WebPage::performDefaultBehaviorForKeyEvent):

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

28 files changed:
WebKit2/ChangeLog
WebKit2/Shared/ImmutableArray.cpp
WebKit2/Shared/ImmutableArray.h
WebKit2/Shared/ImmutableDictionary.cpp
WebKit2/Shared/WebData.h
WebKit2/UIProcess/API/mac/PageClientImpl.h
WebKit2/UIProcess/API/mac/PageClientImpl.mm
WebKit2/UIProcess/API/mac/WKView.mm
WebKit2/UIProcess/API/qt/qgraphicswkview.cpp
WebKit2/UIProcess/API/qt/qwkpage.cpp
WebKit2/UIProcess/API/qt/qwkpage_p.h
WebKit2/UIProcess/ChunkedUpdateDrawingAreaProxy.cpp
WebKit2/UIProcess/ChunkedUpdateDrawingAreaProxy.h
WebKit2/UIProcess/LayerBackedDrawingAreaProxy.cpp
WebKit2/UIProcess/LayerBackedDrawingAreaProxy.h
WebKit2/UIProcess/WebBackForwardList.cpp
WebKit2/UIProcess/WebContext.cpp
WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp
WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp
WebKit2/WebProcess/WebCoreSupport/WebPopupMenu.cpp
WebKit2/WebProcess/WebCoreSupport/WebPopupMenu.h
WebKit2/WebProcess/WebCoreSupport/WebSearchPopupMenu.cpp
WebKit2/WebProcess/WebCoreSupport/WebSearchPopupMenu.h
WebKit2/WebProcess/WebPage/WebFrame.cpp
WebKit2/WebProcess/WebPage/WebPage.cpp
WebKit2/WebProcess/WebPage/WebPage.h
WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
WebKit2/WebProcess/WebPage/win/WebPageWin.cpp

index 51e275c..15cf3dc 100644 (file)
@@ -1,3 +1,68 @@
+2010-08-26  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Darin Adler.
+
+        Adopt more uses OwnPtr/OwnArray in WebKit2.
+        https://bugs.webkit.org/show_bug.cgi?id=44728
+
+        Also clears up weird create vs. adoption semantics. Now both create
+        and adopt both don't ref their pointers, adoption is just about the
+        buffer.
+
+        * Shared/ImmutableArray.cpp:
+        (WebKit::ImmutableArray::ImmutableArray):
+        (WebKit::ImmutableArray::~ImmutableArray):
+        * Shared/ImmutableArray.h:
+        (WebKit::ImmutableArray::adopt):
+        * Shared/ImmutableDictionary.cpp:
+        (WebKit::ImmutableDictionary::keys):
+        * Shared/WebData.h:
+        * UIProcess/API/mac/PageClientImpl.h:
+        * UIProcess/API/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::create):
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView initWithFrame:pageNamespaceRef:]):
+        (-[WKView _switchToDrawingAreaTypeIfNecessary:DrawingAreaProxy::]):
+        * UIProcess/API/qt/qgraphicswkview.cpp:
+        (QGraphicsWKView::QGraphicsWKView):
+        * UIProcess/API/qt/qwkpage.cpp:
+        (QWKPagePrivate::init):
+        * UIProcess/API/qt/qwkpage_p.h:
+        * UIProcess/ChunkedUpdateDrawingAreaProxy.cpp:
+        (WebKit::ChunkedUpdateDrawingAreaProxy::create):
+        * UIProcess/ChunkedUpdateDrawingAreaProxy.h:
+        * UIProcess/LayerBackedDrawingAreaProxy.cpp:
+        (WebKit::LayerBackedDrawingAreaProxy::create):
+        * UIProcess/LayerBackedDrawingAreaProxy.h:
+        * UIProcess/WebBackForwardList.cpp:
+        (WebKit::WebBackForwardList::backListAsImmutableArrayWithLimit):
+        (WebKit::WebBackForwardList::forwardListAsImmutableArrayWithLimit):
+        * UIProcess/WebContext.cpp:
+        (WebKit::PostMessageEncoder::PostMessageDecoder::decode):
+        * WebProcess/InjectedBundle/InjectedBundle.cpp:
+        (WebKit::PostMessageEncoder::PostMessageDecoder::decode):
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::createPopupMenu):
+        (WebKit::WebChromeClient::createSearchPopupMenu):
+        * WebProcess/WebCoreSupport/WebPopupMenu.cpp:
+        (WebKit::WebPopupMenu::create):
+        * WebProcess/WebCoreSupport/WebPopupMenu.h:
+        * WebProcess/WebCoreSupport/WebSearchPopupMenu.cpp:
+        (WebKit::WebSearchPopupMenu::create):
+        (WebKit::WebSearchPopupMenu::WebSearchPopupMenu):
+        * WebProcess/WebCoreSupport/WebSearchPopupMenu.h:
+        * WebProcess/WebPage/WebFrame.cpp:
+        (WebKit::WebFrame::childFrames):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::WebPage):
+        (WebKit::WebPage::close):
+        * WebProcess/WebPage/WebPage.h:
+        (WebKit::WebPage::corePage):
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::performDefaultBehaviorForKeyEvent):
+        * WebProcess/WebPage/win/WebPageWin.cpp:
+        (WebKit::WebPage::performDefaultBehaviorForKeyEvent):
+
 2010-08-26  Alexey Proskuryakov  <ap@apple.com>
 
         Reviewed by Sam Weinig.
index 049e4c1..af73f2f 100644 (file)
@@ -34,15 +34,13 @@ ImmutableArray::ImmutableArray()
 }
 
 ImmutableArray::ImmutableArray(APIObject** entries, size_t size)
-    : m_entries(new APIObject*[size])
+    : m_entries(adoptArrayPtr(new APIObject*[size]))
     , m_size(size)
 {
-    memcpy(m_entries, entries, m_size);
-    for (size_t i = 0; i < m_size; ++i)
-        m_entries[i]->ref();
+    memcpy(m_entries.get(), entries, m_size);
 }
 
-ImmutableArray::ImmutableArray(APIObject** entries, size_t size, AdoptTag)
+ImmutableArray::ImmutableArray(PassOwnArrayPtr<APIObject*> entries, size_t size)
     : m_entries(entries)
     , m_size(size)
 {
@@ -55,7 +53,6 @@ ImmutableArray::~ImmutableArray()
 
     for (size_t i = 0; i < m_size; ++i)
         m_entries[i]->deref();
-    delete [] m_entries;
 }
 
 } // namespace WebKit
index db1f6bf..fa3a357 100644 (file)
@@ -27,6 +27,8 @@
 #define ImmutableArray_h
 
 #include "APIObject.h"
+#include <wtf/OwnArrayPtr.h>
+#include <wtf/PassOwnArrayPtr.h>
 #include <wtf/PassRefPtr.h>
 
 namespace WebKit {
@@ -45,10 +47,11 @@ public:
     {
         return adoptRef(new ImmutableArray(entries, size));
     }
-    static PassRefPtr<ImmutableArray> adopt(APIObject** entries, size_t size)
+    static PassRefPtr<ImmutableArray> adopt(PassOwnArrayPtr<APIObject*> entries, size_t size)
     {
-        return adoptRef(new ImmutableArray(entries, size, Adopt));
+        return adoptRef(new ImmutableArray(entries, size));
     }
+
     ~ImmutableArray();
 
     template<typename T>
@@ -60,12 +63,11 @@ public:
 private:
     ImmutableArray();
     ImmutableArray(APIObject** entries, size_t size);
-    enum AdoptTag { Adopt };
-    ImmutableArray(APIObject** entries, size_t size, AdoptTag);
+    ImmutableArray(PassOwnArrayPtr<APIObject*> entries, size_t size);
 
     virtual Type type() const { return APIType; }
 
-    APIObject** m_entries;
+    OwnArrayPtr<APIObject*> m_entries;
     size_t m_size;
 };
 
index facc4ad..223461b 100644 (file)
@@ -49,14 +49,14 @@ PassRefPtr<ImmutableArray> ImmutableDictionary::keys() const
         return ImmutableArray::create();
 
     size_t size = m_map.size();
-    APIObject** array = new APIObject*[size];
+    OwnArrayPtr<APIObject*> array = adoptArrayPtr(new APIObject*[size]);
 
     MapType::const_iterator::Keys it = m_map.begin().keys();
     MapType::const_iterator::Keys end = m_map.end().keys();
     for (unsigned i = 0; it != end; ++it, ++i)
         array[i] = WebString::create(*it).releaseRef();
 
-    return ImmutableArray::adopt(array, size);
+    return ImmutableArray::adopt(array.release(), size);
 }
 
 } // namespace WebKit
index dfe1ada..789b965 100644 (file)
@@ -27,7 +27,7 @@
 #define WebData_h
 
 #include "APIObject.h"
-#include <wtf/PassRefPtr.h>
+#include <wtf/Forward.h>
 #include <wtf/Vector.h>
 
 namespace WebKit {
index 7186601..1ff36bb 100644 (file)
@@ -38,10 +38,12 @@ NSString* nsStringFromWebCoreString(const WTF::String&);
 
 class PageClientImpl : public PageClient {
 public:
-    PageClientImpl(WKView*);
+    static PassOwnPtr<PageClientImpl> create(WKView*);
     virtual ~PageClientImpl();
 
 private:
+    PageClientImpl(WKView*);
+
     virtual void processDidExit();
     virtual void processDidRevive();
     virtual void takeFocus(bool direction);
index bea9f7b..b612e4b 100644 (file)
@@ -30,6 +30,7 @@
 #import "WKViewInternal.h"
 #import <WebCore/Cursor.h>
 #import <WebCore/FoundationExtras.h>
+#import <wtf/PassOwnPtr.h>
 #import <wtf/text/WTFString.h>
 
 using namespace WebCore;
@@ -41,6 +42,11 @@ NSString* nsStringFromWebCoreString(const WTF::String& string)
     return string.impl() ? HardAutorelease(WKStringCopyCFString(0, toRef(string.impl()))) : @"";
 }
 
+PassOwnPtr<PageClientImpl> PageClientImpl::create(WKView* wkView)
+{
+    return adoptPtr(new PageClientImpl(wkView));
+}
+
 PageClientImpl::PageClientImpl(WKView* wkView)
     : m_wkView(wkView)
 {
index c799686..813df61 100644 (file)
@@ -85,10 +85,10 @@ using namespace WebCore;
 
     _data = [[WKViewData alloc] init];
 
-    _data->_pageClient.set(new PageClientImpl(self));
+    _data->_pageClient = PageClientImpl::create(self);
     _data->_page = toWK(pageNamespaceRef)->createWebPage();
     _data->_page->setPageClient(_data->_pageClient.get());
-    _data->_page->initializeWebPage(IntSize(frame.size), new ChunkedUpdateDrawingAreaProxy(self));
+    _data->_page->initializeWebPage(IntSize(frame.size), ChunkedUpdateDrawingAreaProxy::create(self));
     _data->_page->setIsInWindow([self window]);
 
     return self;
@@ -531,11 +531,11 @@ static bool isViewVisible(NSView *view)
         case DrawingAreaProxy::None:
             break;
         case DrawingAreaProxy::ChunkedUpdateDrawingAreaType: {
-            newDrawingArea = new ChunkedUpdateDrawingAreaProxy(self);
+            newDrawingArea = ChunkedUpdateDrawingAreaProxy::create(self);
             break;
         }
         case DrawingAreaProxy::LayerBackedDrawingAreaType: {
-            newDrawingArea = new LayerBackedDrawingAreaProxy(self);
+            newDrawingArea = LayerBackedDrawingAreaProxy::create(self);
             break;
         }
     }
index 02580ad..0d8d7cf 100644 (file)
@@ -55,10 +55,9 @@ QGraphicsWKView::QGraphicsWKView(WKPageNamespaceRef pageNamespaceRef, BackingSto
 {
     setFocusPolicy(Qt::StrongFocus);
     setAcceptHoverEvents(true);
-    DrawingAreaProxy* drawingAreaProxy = new ChunkedUpdateDrawingAreaProxy(this);
 
     d->page = new QWKPage(pageNamespaceRef);
-    d->page->d->init(size().toSize(), drawingAreaProxy);
+    d->page->d->init(size().toSize(), ChunkedUpdateDrawingAreaProxy::create(this));
     connect(d->page, SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString)));
     connect(d->page, SIGNAL(loadStarted()), this, SIGNAL(loadStarted()));
     connect(d->page, SIGNAL(loadFinished(bool)), this, SIGNAL(loadFinished(bool)));
index d10de69..875f2d2 100644 (file)
@@ -55,7 +55,7 @@ QWKPagePrivate::~QWKPagePrivate()
     page->close();
 }
 
-void QWKPagePrivate::init(const QSize& viewportSize, DrawingAreaProxy* proxy)
+void QWKPagePrivate::init(const QSize& viewportSize, PassOwnPtr<DrawingAreaProxy> proxy)
 {
     page->initializeWebPage(IntSize(viewportSize), proxy);
 }
index 98d4efe..01ed102 100644 (file)
@@ -26,8 +26,9 @@
 #include "qwkpage.h"
 #include "WebPageNamespace.h"
 #include "WebPageProxy.h"
-#include <QBasicTimer>
+#include <wtf/PassOwnPtr.h>
 #include <wtf/RefPtr.h>
+#include <QBasicTimer>
 #include <QGraphicsView>
 #include <QKeyEvent>
 
@@ -38,7 +39,7 @@ public:
 
     static QWKPagePrivate* get(QWKPage* page) { return page->d; }
 
-    void init(const QSize& viewportSize, WebKit::DrawingAreaProxy*);
+    void init(const QSize& viewportSize, WTF::PassOwnPtr<WebKit::DrawingAreaProxy>);
 
     // PageClient
 #if USE(ACCELERATED_COMPOSITING)
index 14763de..ead9bd1 100644 (file)
@@ -37,6 +37,11 @@ using namespace WebCore;
 
 namespace WebKit {
 
+PassOwnPtr<ChunkedUpdateDrawingAreaProxy> ChunkedUpdateDrawingAreaProxy::create(PlatformWebView* webView)
+{
+    return adoptPtr(new ChunkedUpdateDrawingAreaProxy(webView));
+}
+
 ChunkedUpdateDrawingAreaProxy::ChunkedUpdateDrawingAreaProxy(PlatformWebView* webView)
     : DrawingAreaProxy(ChunkedUpdateDrawingAreaType)
     , m_isWaitingForDidSetFrameNotification(false)
index 68b0dab..78f1bd0 100644 (file)
@@ -57,7 +57,8 @@ typedef QGraphicsWKView PlatformWebView;
 
 class ChunkedUpdateDrawingAreaProxy : public DrawingAreaProxy {
 public:
-    ChunkedUpdateDrawingAreaProxy(PlatformWebView*);
+    static PassOwnPtr<ChunkedUpdateDrawingAreaProxy> create(PlatformWebView*);
+
     virtual ~ChunkedUpdateDrawingAreaProxy();
 
     // The DrawingAreaProxy should never be decoded itself. Instead, the DrawingArea should be decoded.
@@ -67,6 +68,8 @@ public:
     }
 
 private:
+    ChunkedUpdateDrawingAreaProxy(PlatformWebView*);
+
     WebPageProxy* page();
 
     // DrawingAreaProxy
index 86bb394..05c806c 100644 (file)
@@ -37,6 +37,11 @@ using namespace WebCore;
 
 namespace WebKit {
 
+PassOwnPtr<LayerBackedDrawingAreaProxy> LayerBackedDrawingAreaProxy::create(PlatformWebView* webView)
+{
+    return adoptPtr(new LayerBackedDrawingAreaProxy(webView));
+}
+
 LayerBackedDrawingAreaProxy::LayerBackedDrawingAreaProxy(PlatformWebView* webView)
     : DrawingAreaProxy(LayerBackedDrawingAreaType)
     , m_isWaitingForDidSetFrameNotification(false)
index 0877c35..70651da 100644 (file)
@@ -55,10 +55,12 @@ typedef WebView PlatformWebView;
 
 class LayerBackedDrawingAreaProxy : public DrawingAreaProxy {
 public:
-    LayerBackedDrawingAreaProxy(PlatformWebView*);
+    static PassOwnPtr<LayerBackedDrawingAreaProxy> create(PlatformWebView*);
     virtual ~LayerBackedDrawingAreaProxy();
 
 private:
+    LayerBackedDrawingAreaProxy(PlatformWebView*);
+
     WebPageProxy* page();
 
     // DrawingAreaProxy
index 886a960..7e71c03 100644 (file)
@@ -173,7 +173,7 @@ PassRefPtr<ImmutableArray> WebBackForwardList::backListAsImmutableArrayWithLimit
     if (!size)
         return ImmutableArray::create();
 
-    APIObject** array = new APIObject*[size];
+    OwnArrayPtr<APIObject*> array = adoptArrayPtr(new APIObject*[size]);
     ASSERT(backListSize >= size);
     for (unsigned i = backListSize - size, j = 0; i < backListSize; ++i, ++j) {
         APIObject* item = m_entries[i].get();
@@ -181,7 +181,7 @@ PassRefPtr<ImmutableArray> WebBackForwardList::backListAsImmutableArrayWithLimit
         array[j] = item;
     }
 
-    return ImmutableArray::adopt(array, size);
+    return ImmutableArray::adopt(array.release(), size);
 }
 
 PassRefPtr<ImmutableArray> WebBackForwardList::forwardListAsImmutableArrayWithLimit(unsigned limit)
@@ -190,7 +190,7 @@ PassRefPtr<ImmutableArray> WebBackForwardList::forwardListAsImmutableArrayWithLi
     if (!size)
         return ImmutableArray::create();
 
-    APIObject** array = new APIObject*[size];
+    OwnArrayPtr<APIObject*> array = adoptArrayPtr(new APIObject*[size]);
     unsigned last = m_current + size;
     ASSERT(last < m_entries.size());
     for (unsigned i = m_current + 1, j = 0; i <= last; ++i, ++j) {
@@ -199,7 +199,7 @@ PassRefPtr<ImmutableArray> WebBackForwardList::forwardListAsImmutableArrayWithLi
         array[j] = item;
     }
 
-    return ImmutableArray::adopt(array, size);
+    return ImmutableArray::adopt(array.release(), size);
 }
 
 } // namespace WebKit
index 783e06a..3ab3c43 100644 (file)
@@ -127,9 +127,7 @@ public:
             if (!decoder->decode(size))
                 return false;
             
-            OwnArrayPtr<APIObject*> array;
-            array.set(new APIObject*[size]);
-            
+            OwnArrayPtr<APIObject*> array = adoptArrayPtr(new APIObject*[size]);
             for (size_t i = 0; i < size; ++i) {
                 APIObject* element;
                 PostMessageDecoder messageCoder(&element, coder.m_context);
@@ -138,7 +136,7 @@ public:
                 array[i] = element;
             }
 
-            *(coder.m_root) = ImmutableArray::create(array.release().leakPtr(), size).leakRef();
+            *(coder.m_root) = ImmutableArray::adopt(array.release(), size).leakRef();
             break;
         }
         case APIObject::TypeString: {
index bad24c7..02eb32c 100644 (file)
@@ -122,10 +122,8 @@ public:
             uint64_t size;
             if (!decoder->decode(size))
                 return false;
-            
-            OwnArrayPtr<APIObject*> array;
-            array.set(new APIObject*[size]);
-            
+
+            OwnArrayPtr<APIObject*> array = adoptArrayPtr(new APIObject*[size]);
             for (size_t i = 0; i < size; ++i) {
                 APIObject* element;
                 PostMessageDecoder messageCoder(&element);
@@ -134,7 +132,7 @@ public:
                 array[i] = element;
             }
 
-            *(coder.m_root) = ImmutableArray::create(array.release().leakPtr(), size).leakRef();
+            *(coder.m_root) = ImmutableArray::adopt(array.release(), size).leakRef();
             break;
         }
         case APIObject::TypeString: {
index 6c22c62..1281a66 100644 (file)
@@ -501,12 +501,12 @@ bool WebChromeClient::selectItemWritingDirectionIsNatural()
 
 PassRefPtr<WebCore::PopupMenu> WebChromeClient::createPopupMenu(WebCore::PopupMenuClient* client) const
 {
-    return adoptRef(new WebPopupMenu(client));
+    return WebPopupMenu::create(client);
 }
 
 PassRefPtr<WebCore::SearchPopupMenu> WebChromeClient::createSearchPopupMenu(WebCore::PopupMenuClient* client) const
 {
-    return adoptRef(new WebSearchPopupMenu(client));
+    return WebSearchPopupMenu::create(client);
 }
 
 PassOwnPtr<HTMLParserQuirks> WebChromeClient::createHTMLParserQuirks()
index d2f7d32..a2c22a2 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -17,6 +18,7 @@
  * Boston, MA 02110-1301, USA.
  *
  */
+
 #include "WebPopupMenu.h"
 
 #include <WebCore/FrameView.h>
 
 namespace WebKit {
 
+PassRefPtr<WebPopupMenu> WebPopupMenu::create(WebCore::PopupMenuClient* client)
+{
+    return adoptRef(new WebPopupMenu(client));
+}
+
 WebPopupMenu::WebPopupMenu(WebCore::PopupMenuClient* client)
     : m_popupClient(client)
 {
@@ -52,4 +59,4 @@ void WebPopupMenu::updateFromElement()
 {
 }
 
-}
+} // namespace WebKit
index e2ea3a1..e7267be 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -22,6 +23,7 @@
 #define WebPopupMenu_h
 
 #include <WebCore/PopupMenu.h>
+#include <wtf/Forward.h>
 
 namespace WebCore {
 class PopupMenuClient;
@@ -31,7 +33,7 @@ namespace WebKit {
 
 class WebPopupMenu : public WebCore::PopupMenu {
 public:
-    WebPopupMenu(WebCore::PopupMenuClient*);
+    static PassRefPtr<WebPopupMenu> create(WebCore::PopupMenuClient*);
     ~WebPopupMenu();
 
     virtual void show(const WebCore::IntRect&, WebCore::FrameView*, int index);
@@ -40,9 +42,11 @@ public:
     virtual void disconnectClient();
 
 private:
+    WebPopupMenu(WebCore::PopupMenuClient*);
+
     WebCore::PopupMenuClient* m_popupClient;
 };
 
-}
+} // namespace WebKit
 
 #endif // WebPopupMenu_h
index 98a8c27..7da2c5a 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
 
 namespace WebKit {
 
+PassRefPtr<WebSearchPopupMenu> WebSearchPopupMenu::create(WebCore::PopupMenuClient* client)
+{
+    return adoptRef(new WebSearchPopupMenu(client));
+}
+
 WebSearchPopupMenu::WebSearchPopupMenu(WebCore::PopupMenuClient* client)
-    : m_popup(adoptRef(new WebPopupMenu(client)))
+    : m_popup(WebPopupMenu::create(client))
 {
 }
 
@@ -46,4 +52,4 @@ bool WebSearchPopupMenu::enabled()
     return false;
 }
 
-}
+} // namespace WebKit
index bd0e8a8..7346dcb 100644 (file)
 #ifndef WebSearchPopupMenu_h
 #define WebSearchPopupMenu_h
 
-#include <WebCore/SearchPopupMenu.h>
 #include "WebPopupMenu.h"
+#include <WebCore/SearchPopupMenu.h>
 
 namespace WebKit {
 
 class WebSearchPopupMenu : public WebCore::SearchPopupMenu {
 public:
-    WebSearchPopupMenu(WebCore::PopupMenuClient*);
+    static PassRefPtr<WebSearchPopupMenu> create(WebCore::PopupMenuClient*);
 
     virtual WebCore::PopupMenu* popupMenu();
     virtual void saveRecentSearches(const WTF::AtomicString& name, const Vector<WTF::String>& searchItems);
@@ -36,6 +36,8 @@ public:
     virtual bool enabled();
 
 private:
+    WebSearchPopupMenu(WebCore::PopupMenuClient*);
+
     RefPtr<WebPopupMenu> m_popup;
 };
 
index 276e4ce..a1b8cae 100644 (file)
@@ -224,7 +224,7 @@ PassRefPtr<ImmutableArray> WebFrame::childFrames()
     if (!size)
         return ImmutableArray::create();
 
-    APIObject** array = new APIObject*[size];
+    OwnArrayPtr<APIObject*> array = adoptArrayPtr(new APIObject*[size]);
     unsigned i = 0;
     for (Frame* child = m_coreFrame->tree()->firstChild(); child; child = child->tree()->nextSibling(), ++i) {
         WebFrame* webFrame = static_cast<WebFrameLoaderClient*>(child->loader()->client())->webFrame();
@@ -232,7 +232,7 @@ PassRefPtr<ImmutableArray> WebFrame::childFrames()
         array[i] = webFrame;
     }
 
-    return ImmutableArray::adopt(array, size);
+    return ImmutableArray::adopt(array.release(), size);
 }
 
 unsigned WebFrame::numberOfActiveAnimations()
index 8fbd032..2cc69ec 100644 (file)
@@ -91,7 +91,7 @@ WebPage::WebPage(uint64_t pageID, const IntSize& viewSize, const WebPreferencesS
     pageClients.dragClient = new WebDragClient(this);
     pageClients.inspectorClient = new WebInspectorClient(this);
     pageClients.backForwardControllerClient = new WebBackForwardControllerClient(this);
-    m_page = new Page(pageClients);
+    m_page = adoptPtr(new Page(pageClients));
 
     m_page->settings()->setJavaScriptEnabled(store.javaScriptEnabled);
     m_page->settings()->setLoadsImagesAutomatically(store.loadsImagesAutomatically);
@@ -215,8 +215,7 @@ void WebPage::close()
 
     m_mainFrame->coreFrame()->loader()->detachFromParent();
 
-    delete m_page;
-    m_page = 0;
+    m_page.clear();
 
     WebProcess::shared().removeWebPage(m_pageID);
 }
index 67671af..5912286 100644 (file)
@@ -40,6 +40,7 @@
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
 #include <wtf/text/WTFString.h>
+
 #if ENABLE(TOUCH_EVENTS)
 #include <WebCore/PlatformTouchEvent.h>
 #endif
@@ -78,7 +79,7 @@ public:
 
     void close();
 
-    WebCore::Page* corePage() const { return m_page; }
+    WebCore::Page* corePage() const { return m_page.get(); }
     uint64_t pageID() const { return m_pageID; }
 
     void setSize(const WebCore::IntSize&);
@@ -164,7 +165,7 @@ private:
     void didReceivePolicyDecision(WebFrame*, uint64_t listenerID, WebCore::PolicyAction policyAction);
     void setCustomUserAgent(const WTF::String&);
 
-    WebCore::Page* m_page;
+    OwnPtr<WebCore::Page> m_page;
     RefPtr<WebFrame> m_mainFrame;
 
     String m_customUserAgent;
index c3f0165..6150d8d 100644 (file)
@@ -202,45 +202,45 @@ bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboard
         break;
     case VK_SPACE:
         if (keyboardEvent.shiftKey())
-            scroll(m_page, ScrollUp, ScrollByPage);
+            scroll(m_page.get(), ScrollUp, ScrollByPage);
         else
-            scroll(m_page, ScrollDown, ScrollByPage);
+            scroll(m_page.get(), ScrollDown, ScrollByPage);
         break;
     case VK_PRIOR:
-        scroll(m_page, ScrollUp, ScrollByPage);
+        scroll(m_page.get(), ScrollUp, ScrollByPage);
         break;
     case VK_NEXT:
-        scroll(m_page, ScrollDown, ScrollByPage);
+        scroll(m_page.get(), ScrollDown, ScrollByPage);
         break;
     case VK_HOME:
-        scroll(m_page, ScrollUp, ScrollByDocument);
-        scroll(m_page, ScrollLeft, ScrollByDocument);
+        scroll(m_page.get(), ScrollUp, ScrollByDocument);
+        scroll(m_page.get(), ScrollLeft, ScrollByDocument);
         break;
     case VK_END:
-        scroll(m_page, ScrollDown, ScrollByDocument);
-        scroll(m_page, ScrollLeft, ScrollByDocument);
+        scroll(m_page.get(), ScrollDown, ScrollByDocument);
+        scroll(m_page.get(), ScrollLeft, ScrollByDocument);
         break;
     case VK_UP:
         if (keyboardEvent.shiftKey())
             return false;
         if (keyboardEvent.metaKey()) {
-            scroll(m_page, ScrollUp, ScrollByDocument);
-            scroll(m_page, ScrollLeft, ScrollByDocument);
+            scroll(m_page.get(), ScrollUp, ScrollByDocument);
+            scroll(m_page.get(), ScrollLeft, ScrollByDocument);
         } else if (keyboardEvent.altKey() || keyboardEvent.controlKey())
-            scroll(m_page, ScrollUp, ScrollByPage);
+            scroll(m_page.get(), ScrollUp, ScrollByPage);
         else
-            scroll(m_page, ScrollUp, ScrollByLine);
+            scroll(m_page.get(), ScrollUp, ScrollByLine);
         break;
     case VK_DOWN:
         if (keyboardEvent.shiftKey())
             return false;
         if (keyboardEvent.metaKey()) {
-            scroll(m_page, ScrollDown, ScrollByDocument);
-            scroll(m_page, ScrollLeft, ScrollByDocument);
+            scroll(m_page.get(), ScrollDown, ScrollByDocument);
+            scroll(m_page.get(), ScrollLeft, ScrollByDocument);
         } else if (keyboardEvent.altKey() || keyboardEvent.controlKey())
-            scroll(m_page, ScrollDown, ScrollByPage);
+            scroll(m_page.get(), ScrollDown, ScrollByPage);
         else
-            scroll(m_page, ScrollDown, ScrollByLine);
+            scroll(m_page.get(), ScrollDown, ScrollByLine);
         break;
     case VK_LEFT:
         if (keyboardEvent.shiftKey())
@@ -249,9 +249,9 @@ bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboard
             m_page->goBack();
         else {
             if (keyboardEvent.altKey()  | keyboardEvent.controlKey())
-                scroll(m_page, ScrollLeft, ScrollByPage);
+                scroll(m_page.get(), ScrollLeft, ScrollByPage);
             else
-                scroll(m_page, ScrollLeft, ScrollByLine);
+                scroll(m_page.get(), ScrollLeft, ScrollByLine);
         }
         break;
     case VK_RIGHT:
@@ -261,9 +261,9 @@ bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboard
             m_page->goForward();
         else {
             if (keyboardEvent.altKey() || keyboardEvent.controlKey())
-                scroll(m_page, ScrollRight, ScrollByPage);
+                scroll(m_page.get(), ScrollRight, ScrollByPage);
             else
-                scroll(m_page, ScrollRight, ScrollByLine);
+                scroll(m_page.get(), ScrollRight, ScrollByLine);
         }
         break;
     default:
index ddf8d35..f5ac858 100644 (file)
@@ -200,33 +200,33 @@ bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboard
         break;
     case VK_SPACE:
         if (keyboardEvent.shiftKey())
-            scroll(m_page, ScrollUp, ScrollByPage);
+            scroll(m_page.get(), ScrollUp, ScrollByPage);
         else
-            scroll(m_page, ScrollDown, ScrollByPage);
+            scroll(m_page.get(), ScrollDown, ScrollByPage);
         break;
     case VK_LEFT:
-        scroll(m_page, ScrollLeft, ScrollByLine);
+        scroll(m_page.get(), ScrollLeft, ScrollByLine);
         break;
     case VK_RIGHT:
-        scroll(m_page, ScrollRight, ScrollByLine);
+        scroll(m_page.get(), ScrollRight, ScrollByLine);
         break;
     case VK_UP:
-        scroll(m_page, ScrollUp, ScrollByLine);
+        scroll(m_page.get(), ScrollUp, ScrollByLine);
         break;
     case VK_DOWN:
-        scroll(m_page, ScrollDown, ScrollByLine);
+        scroll(m_page.get(), ScrollDown, ScrollByLine);
         break;
     case VK_HOME:
-        scroll(m_page, ScrollUp, ScrollByDocument);
+        scroll(m_page.get(), ScrollUp, ScrollByDocument);
         break;
     case VK_END:
-        scroll(m_page, ScrollDown, ScrollByDocument);
+        scroll(m_page.get(), ScrollDown, ScrollByDocument);
         break;
     case VK_PRIOR:
-        scroll(m_page, ScrollUp, ScrollByPage);
+        scroll(m_page.get(), ScrollUp, ScrollByPage);
         break;
     case VK_NEXT:
-        scroll(m_page, ScrollDown, ScrollByPage);
+        scroll(m_page.get(), ScrollDown, ScrollByPage);
         break;
     default:
         return false;