Changeset 128921 in webkit


Ignore:
Timestamp:
Sep 18, 2012 12:26:13 PM (12 years ago)
Author:
yoli@rim.com
Message:

[BlackBerry] Popup page should reference the client with a weak pointer
https://bugs.webkit.org/show_bug.cgi?id=97028

Reviewed by Rob Buis.

RIM PR# 209847.
Internally reviewed by Mike Fenton.

Store the pointer in a ref-coutned shared object, and clear the pointer
when the client is going to be destroyed, so it won't be accessed by
the JS function afterwards.

  • WebCoreSupport/PagePopupBlackBerry.cpp:

(WebCore::PagePopupBlackBerry::PagePopupBlackBerry):
(WebCore::PagePopupBlackBerry::~PagePopupBlackBerry):
(WebCore::PagePopupBlackBerry::init):
(WebCore::setValueAndClosePopupCallback):
(WebCore::popUpExtensionFinalize):
(WebCore::PagePopupBlackBerry::installDOMFunction):
(WebCore::PagePopupBlackBerry::closePopup):

  • WebCoreSupport/PagePopupBlackBerry.h:

(PagePopupBlackBerry):
(SharedClientPointer):
(WebCore::PagePopupBlackBerry::SharedClientPointer::SharedClientPointer):
(WebCore::PagePopupBlackBerry::SharedClientPointer::clear):
(WebCore::PagePopupBlackBerry::SharedClientPointer::get):

Location:
trunk/Source/WebKit/blackberry
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/blackberry/ChangeLog

    r128858 r128921  
     12012-09-18  Yong Li  <yoli@rim.com>
     2
     3        [BlackBerry] Popup page should reference the client with a weak pointer
     4        https://bugs.webkit.org/show_bug.cgi?id=97028
     5
     6        Reviewed by Rob Buis.
     7
     8        RIM PR# 209847.
     9        Internally reviewed by Mike Fenton.
     10
     11        Store the pointer in a ref-coutned shared object, and clear the pointer
     12        when the client is going to be destroyed, so it won't be accessed by
     13        the JS function afterwards.
     14
     15        * WebCoreSupport/PagePopupBlackBerry.cpp:
     16        (WebCore::PagePopupBlackBerry::PagePopupBlackBerry):
     17        (WebCore::PagePopupBlackBerry::~PagePopupBlackBerry):
     18        (WebCore::PagePopupBlackBerry::init):
     19        (WebCore::setValueAndClosePopupCallback):
     20        (WebCore::popUpExtensionFinalize):
     21        (WebCore::PagePopupBlackBerry::installDOMFunction):
     22        (WebCore::PagePopupBlackBerry::closePopup):
     23        * WebCoreSupport/PagePopupBlackBerry.h:
     24        (PagePopupBlackBerry):
     25        (SharedClientPointer):
     26        (WebCore::PagePopupBlackBerry::SharedClientPointer::SharedClientPointer):
     27        (WebCore::PagePopupBlackBerry::SharedClientPointer::clear):
     28        (WebCore::PagePopupBlackBerry::SharedClientPointer::get):
     29
    1302012-09-18  Arvid Nilsson  <anilsson@rim.com>
    231
  • trunk/Source/WebKit/blackberry/WebCoreSupport/PagePopupBlackBerry.cpp

    r128767 r128921  
    5151    : m_webPagePrivate(webPage)
    5252    , m_client(adoptPtr(client))
     53    , m_sharedClientPointer(adoptRef(new PagePopupBlackBerry::SharedClientPointer(client)))
    5354{
    5455    m_rect = IntRect(rect.x(), rect.y() - URL_BAR_HEIGHT, client->contentSize().width(), client->contentSize().height());
     
    5758PagePopupBlackBerry::~PagePopupBlackBerry()
    5859{
     60    ASSERT(!m_sharedClientPointer->get());
    5961}
    6062
     
    6870    generateHTML(webpage);
    6971
    70     installDomFunction(webpage->d->mainFrame());
     72    installDOMFunction(webpage->d->mainFrame());
    7173
    7274    return true;
     
    108110    JSObjectRef popUpObject = JSValueToObject(context,
    109111            arguments[argumentCount - 1], 0);
    110     PagePopupClient* client =
    111             reinterpret_cast<PagePopupClient*>(JSObjectGetPrivate(popUpObject));
     112    PagePopupBlackBerry::SharedClientPointer* client = reinterpret_cast<PagePopupBlackBerry::SharedClientPointer*>(JSObjectGetPrivate(popUpObject));
    112113
    113     ASSERT(client);
    114     client->setValueAndClosePopup(0, strArgs.data());
     114    // Check the weak pointer as the owner page may have destroyed the popup.
     115    if (client->get())
     116        client->get()->setValueAndClosePopup(0, strArgs.data());
    115117
    116118    return jsRetVal;
     
    125127static void popUpExtensionFinalize(JSObjectRef object)
    126128{
    127     UNUSED_PARAM(object);
     129    // Clear the reference. See installDOMFunction().
     130    PagePopupBlackBerry::SharedClientPointer* client = reinterpret_cast<PagePopupBlackBerry::SharedClientPointer*>(JSObjectGetPrivate(object));
     131    client->deref();
    128132}
    129133
     
    139143};
    140144
    141 void PagePopupBlackBerry::installDomFunction(Frame* frame)
     145void PagePopupBlackBerry::installDOMFunction(Frame* frame)
    142146{
    143147    JSDOMWindow* window = toJSDOMWindow(frame, mainThreadNormalWorld());
     
    166170
    167171    JSObjectRef clientClassObject = JSObjectMake(context, clientClass, 0);
    168     JSObjectSetPrivate(clientClassObject, reinterpret_cast<void*>(m_client.get()));
     172
     173    // Add a reference. See popUpExtensionFinalize.
     174    m_sharedClientPointer->ref();
     175    JSObjectSetPrivate(clientClassObject, m_sharedClientPointer.get());
    169176
    170177    String name("popUp");
     
    179186void PagePopupBlackBerry::closePopup()
    180187{
     188    // Prevent the popup page from accessing the client.
     189    m_sharedClientPointer->clear();
     190
    181191    m_client->didClosePopup();
    182192    m_webPagePrivate->client()->closePopupWebView();
  • trunk/Source/WebKit/blackberry/WebCoreSupport/PagePopupBlackBerry.h

    r126338 r128921  
    2222#include "IntRect.h"
    2323#include "PagePopup.h"
     24#include <wtf/RefCounted.h>
     25#include <wtf/RefPtr.h>
    2426
    2527
     
    4547    bool init(BlackBerry::WebKit::WebPage*);
    4648    void closePopup();
    47     void installDomFunction(Frame*);
    4849    void setRect();
    49     void generateHTML(BlackBerry::WebKit::WebPage*);
     50
     51    class SharedClientPointer : public RefCounted<SharedClientPointer> {
     52    public:
     53        explicit SharedClientPointer(PagePopupClient* client) : m_client(client) { }
     54        void clear() { m_client = 0; }
     55        PagePopupClient* get() const { return m_client; }
     56    private:
     57        PagePopupClient* m_client;
     58    };
    5059
    5160private:
     61    void generateHTML(BlackBerry::WebKit::WebPage*);
     62    void installDOMFunction(Frame*);
     63
    5264    BlackBerry::WebKit::WebPagePrivate* m_webPagePrivate;
    5365    OwnPtr<PagePopupClient> m_client;
     66    RefPtr<SharedClientPointer> m_sharedClientPointer;
    5467    IntRect m_rect;
    5568};
Note: See TracChangeset for help on using the changeset viewer.