Changeset 62696 in webkit


Ignore:
Timestamp:
Jul 7, 2010 1:55:37 PM (14 years ago)
Author:
Darin Adler
Message:

2010-07-07 Darin Adler <Darin Adler>

Reviewed by Adam Barth.

Turn on adoptRef assertion for RefCounted
https://bugs.webkit.org/show_bug.cgi?id=41547

  • wtf/CrossThreadRefCounted.h: Fixed include style. Includes of other WTF headers should use "" includes; consistent in most WTF headers. Added a call to relaxAdoptionRequirement.
  • wtf/RefCounted.h: Fixed include style. Removed LOOSE_REF_COUNTED. Added relaxAdoptionRequirement.

2010-07-07 Darin Adler <Darin Adler>

Reviewed by Adam Barth.

Turn on adoptRef assertion for RefCounted
https://bugs.webkit.org/show_bug.cgi?id=41547

The WebCore part of this fixes all the assertions I saw in testing.

  • html/FileReader.cpp: (WebCore::FileReader::readAsBinaryString): Added null checks. Callers from JavaScript can pass the wrong type, which becomes null. (WebCore::FileReader::readAsText): Ditto. (WebCore::FileReader::readAsDataURL): Ditto.
  • html/FileStreamClient.h: Removed unneeded include.
  • html/FileStreamProxy.cpp: (WebCore::FileStreamProxy::FileStreamProxy): Made inline and moved some of the code, including the ref, into the create function. (WebCore::FileStreamProxy::create): Moved some of the code from the constructor here. It's safe to ref once the object has been created and adopted.
  • html/FileStreamProxy.h: Changed create function to no longer be inlined. Also removed an unneeded include.
  • page/EventSource.cpp: (WebCore::EventSource::EventSource): Made inline, changed arguments and moved code that involves the need to ref this object into the create function. Also moved failure handling out there since it's cleaner to have a function that fails than a constructor. For example, the function can return 0. (WebCore::EventSource::create): Moved some of the code from the constructor here.
  • page/EventSource.h: Removed unneeded includes. Made the creation function non-inline. Changed the arguments to the constructor.
  • storage/StorageAreaSync.cpp: (WebCore::StorageAreaSync::StorageAreaSync): Made inline. Moved code that requires ref'ing this object out to the create function. (WebCore::StorageAreaSync::create): Moved some of the code from the constructor here.
  • storage/StorageAreaSync.h: Removed unneeded includes. Changed the type of one of the constructor arguments from String to const String&.
  • workers/SharedWorker.cpp: (WebCore::SharedWorker::SharedWorker): Made inline. Moved most of the setup code out of here into the create function. (WebCore::SharedWorker::create): Moved the code here.
  • workers/SharedWorker.h: Removed unneeded includes. Made the create function non-inline. Marked the toSharedWorker override private to catch people doing an unnecessary virtual function call if they already have a SharedWorker*.
  • workers/Worker.cpp: (WebCore::Worker::Worker): Made inline. Moved most of the setup code out of here into the create function. (WebCore::Worker::create): Moved the code here.
  • workers/Worker.h: Made the create function non-inline. Changed the arguments to the constructor.
Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r62689 r62696  
     12010-07-07  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Adam Barth.
     4
     5        Turn on adoptRef assertion for RefCounted
     6        https://bugs.webkit.org/show_bug.cgi?id=41547
     7
     8        * wtf/CrossThreadRefCounted.h: Fixed include style. Includes of other
     9        WTF headers should use "" includes; consistent in most WTF headers.
     10        Added a call to relaxAdoptionRequirement.
     11
     12        * wtf/RefCounted.h: Fixed include style. Removed LOOSE_REF_COUNTED.
     13        Added relaxAdoptionRequirement.
     14
    1152010-07-07  Anders Carlsson  <andersca@apple.com>
    216
  • trunk/JavaScriptCore/wtf/CrossThreadRefCounted.h

    r49160 r62696  
    11/*
    22 * Copyright (C) 2009 Google Inc. All rights reserved.
     3 * Copyright (C) 2010 Apple Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3233#define CrossThreadRefCounted_h
    3334
    34 #include <wtf/Noncopyable.h>
    35 #include <wtf/PassRefPtr.h>
    36 #include <wtf/RefCounted.h>
    37 #include <wtf/Threading.h>
     35#include "PassRefPtr.h"
     36#include "RefCounted.h"
     37#include "Threading.h"
    3838
    3939namespace WTF {
     
    7979#endif
    8080        {
     81            // We use RefCountedBase in an unusual way here, so get rid of the requirement
     82            // that adoptRef be called on it.
     83            m_refCounter.relaxAdoptionRequirement();
    8184        }
    8285
  • trunk/JavaScriptCore/wtf/RefCounted.h

    r62213 r62696  
    2222#define RefCounted_h
    2323
    24 #include <wtf/Assertions.h>
    25 #include <wtf/Noncopyable.h>
    26 
    27 // Remove this once we make all WebKit code compatible with stricter rules about RefCounted.
    28 #define LOOSE_REF_COUNTED
     24#include "Assertions.h"
     25#include "Noncopyable.h"
    2926
    3027namespace WTF {
     
    3835    {
    3936        ASSERT(!m_deletionHasBegun);
    40 #ifndef LOOSE_REF_COUNTED
    4137        ASSERT(!m_adoptionIsRequired);
    42 #endif
    4338        ++m_refCount;
    4439    }
     
    5550    }
    5651
     52    void relaxAdoptionRequirement()
     53    {
     54#ifndef NDEBUG
     55        ASSERT(!m_deletionHasBegun);
     56        ASSERT(m_adoptionIsRequired);
     57        m_adoptionIsRequired = false;
     58#endif
     59    }
     60
    5761protected:
    5862    RefCountedBase()
     
    6771    ~RefCountedBase()
    6872    {
    69 #ifndef LOOSE_REF_COUNTED
    7073        ASSERT(m_deletionHasBegun);
    7174        ASSERT(!m_adoptionIsRequired);
    72 #endif
    7375    }
    7476
     
    7779    {
    7880        ASSERT(!m_deletionHasBegun);
    79 #ifndef LOOSE_REF_COUNTED
    8081        ASSERT(!m_adoptionIsRequired);
    81 #endif
    8282
    8383        ASSERT(m_refCount > 0);
  • trunk/WebCore/ChangeLog

    r62694 r62696  
     12010-07-07  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Adam Barth.
     4
     5        Turn on adoptRef assertion for RefCounted
     6        https://bugs.webkit.org/show_bug.cgi?id=41547
     7
     8        The WebCore part of this fixes all the assertions I saw in testing.
     9
     10        * html/FileReader.cpp:
     11        (WebCore::FileReader::readAsBinaryString): Added null checks.
     12        Callers from JavaScript can pass the wrong type, which becomes null.
     13        (WebCore::FileReader::readAsText): Ditto.
     14        (WebCore::FileReader::readAsDataURL): Ditto.
     15
     16        * html/FileStreamClient.h: Removed unneeded include.
     17
     18        * html/FileStreamProxy.cpp:
     19        (WebCore::FileStreamProxy::FileStreamProxy): Made inline and moved
     20        some of the code, including the ref, into the create function.
     21        (WebCore::FileStreamProxy::create): Moved some of the code from
     22        the constructor here. It's safe to ref once the object has been
     23        created and adopted.
     24
     25        * html/FileStreamProxy.h: Changed create function to no longer be
     26        inlined. Also removed an unneeded include.
     27
     28        * page/EventSource.cpp:
     29        (WebCore::EventSource::EventSource): Made inline, changed arguments
     30        and moved code that involves the need to ref this object into the
     31        create function. Also moved failure handling out there since it's
     32        cleaner to have a function that fails than a constructor. For
     33        example, the function can return 0.
     34        (WebCore::EventSource::create): Moved some of the code from the
     35        constructor here.
     36
     37        * page/EventSource.h: Removed unneeded includes. Made the
     38        creation function non-inline. Changed the arguments to the constructor.
     39
     40        * storage/StorageAreaSync.cpp:
     41        (WebCore::StorageAreaSync::StorageAreaSync): Made inline. Moved
     42        code that requires ref'ing this object out to the create function.
     43        (WebCore::StorageAreaSync::create): Moved some of the code from the
     44        constructor here.
     45
     46        * storage/StorageAreaSync.h: Removed unneeded includes. Changed
     47        the type of one of the constructor arguments from String to
     48        const String&.
     49
     50        * workers/SharedWorker.cpp:
     51        (WebCore::SharedWorker::SharedWorker): Made inline. Moved most of
     52        the setup code out of here into the create function.
     53        (WebCore::SharedWorker::create): Moved the code here.
     54
     55        * workers/SharedWorker.h: Removed unneeded includes. Made the
     56        create function non-inline. Marked the toSharedWorker override private
     57        to catch people doing an unnecessary virtual function call if they
     58        already have a SharedWorker*.
     59
     60        * workers/Worker.cpp:
     61        (WebCore::Worker::Worker): Made inline. Moved most of the setup code
     62        out of here into the create function.
     63        (WebCore::Worker::create): Moved the code here.
     64
     65        * workers/Worker.h: Made the create function non-inline. Changed
     66        the arguments to the constructor.
     67
    1682010-07-07  Chris Fleizach  <cfleizach@apple.com>
    269
  • trunk/WebCore/html/FileReader.cpp

    r60799 r62696  
    8686void FileReader::readAsBinaryString(Blob* fileBlob)
    8787{
     88    if (!fileBlob)
     89        return;
     90
    8891    // FIXME: needs to handle non-file blobs.
    8992    LOG(FileAPI, "FileReader: reading as binary: %s\n", fileBlob->path().utf8().data());
     
    9497void FileReader::readAsText(Blob* fileBlob, const String& encoding)
    9598{
     99    if (!fileBlob)
     100        return;
     101
    96102    // FIXME: needs to handle non-file blobs.
    97103    LOG(FileAPI, "FileReader: reading as text: %s\n", fileBlob->path().utf8().data());
     
    104110void FileReader::readAsDataURL(File* file)
    105111{
     112    if (!file)
     113        return;
     114
    106115    LOG(FileAPI, "FileReader: reading as data URL: %s\n", file->path().utf8().data());
    107116
  • trunk/WebCore/html/FileStreamClient.h

    r57749 r62696  
    3535
    3636#include "ExceptionCode.h"
    37 #include <wtf/PassRefPtr.h>
    3837
    3938namespace WebCore {
  • trunk/WebCore/html/FileStreamProxy.cpp

    r59849 r62696  
    4545namespace WebCore {
    4646
    47 FileStreamProxy::FileStreamProxy(ScriptExecutionContext* context, FileStreamClient* client)
     47inline FileStreamProxy::FileStreamProxy(ScriptExecutionContext* context, FileStreamClient* client)
    4848    : m_context(context)
    4949    , m_client(client)
    5050    , m_stream(FileStream::create(this))
    5151{
    52     // Holds an extra ref so that the instance will not get deleted while there can be any tasks on the file thread.
    53     ref();
    54 
    55     fileThread()->postTask(createFileThreadTask(m_stream.get(), &FileStream::start));
     52}
     53
     54PassRefPtr<FileStreamProxy> FileStreamProxy::create(ScriptExecutionContext* context, FileStreamClient* client)
     55{
     56    RefPtr<FileStreamProxy> proxy = adoptRef(new FileStreamProxy(context, client));
     57
     58    // Hold an ref so that the instance will not get deleted while there are tasks on the file thread.
     59    // This is balanced by the deref in derefProxyOnContext below.
     60    proxy->ref();
     61
     62    proxy->fileThread()->postTask(createFileThreadTask(proxy->m_stream.get(), &FileStream::start));
     63
     64    return proxy.release();
    5665}
    5766
  • trunk/WebCore/html/FileStreamProxy.h

    r57749 r62696  
    11/*
    22 * Copyright (C) 2010 Google Inc.  All rights reserved.
     3 * Copyright (C) 2010 Apple Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3435#if ENABLE(FILE_READER) || ENABLE(FILE_WRITER)
    3536
    36 #include "ExceptionCode.h"
    3737#include "FileStreamClient.h"
    3838#include <wtf/PassRefPtr.h>
     
    5151class FileStreamProxy : public RefCounted<FileStreamProxy>, public FileStreamClient {
    5252public:
    53     static PassRefPtr<FileStreamProxy> create(ScriptExecutionContext* context, FileStreamClient* client)
    54     {
    55         return adoptRef(new FileStreamProxy(context, client));
    56     }
     53    static PassRefPtr<FileStreamProxy> create(ScriptExecutionContext*, FileStreamClient*);
    5754    virtual ~FileStreamProxy();
    5855
  • trunk/WebCore/page/EventSource.cpp

    r56035 r62696  
    22 * Copyright (C) 2009 Ericsson AB
    33 * All rights reserved.
     4 * Copyright (C) 2010 Apple Inc. All rights reserved.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    5455const unsigned long long EventSource::defaultReconnectDelay = 3000;
    5556
    56 EventSource::EventSource(const String& url, ScriptExecutionContext* context, ExceptionCode& ec)
     57inline EventSource::EventSource(const KURL& url, ScriptExecutionContext* context)
    5758    : ActiveDOMObject(context, this)
     59    , m_url(url)
    5860    , m_state(CONNECTING)
     61    , m_decoder(TextResourceDecoder::create("text/plain", "UTF-8"))
    5962    , m_reconnectTimer(this, &EventSource::reconnectTimerFired)
    6063    , m_discardTrailingNewline(false)
     
    6265    , m_requestInFlight(false)
    6366    , m_reconnectDelay(defaultReconnectDelay)
    64 {
    65     if (url.isEmpty() || !(m_url = context->completeURL(url)).isValid()) {
     67    , m_origin(context->securityOrigin()->toString())
     68{
     69}
     70
     71PassRefPtr<EventSource> EventSource::create(const String& url, ScriptExecutionContext* context, ExceptionCode& ec)
     72{
     73    if (url.isEmpty()) {
    6674        ec = SYNTAX_ERR;
    67         return;
    68     }
    69     // FIXME: should support cross-origin requests
    70     if (!scriptExecutionContext()->securityOrigin()->canRequest(m_url)) {
     75        return 0;
     76    }
     77
     78    KURL fullURL = context->completeURL(url);
     79    if (!fullURL.isValid()) {
     80        ec = SYNTAX_ERR;
     81        return 0;
     82    }
     83
     84    // FIXME: Should support at least some cross-origin requests.
     85    if (!context->securityOrigin()->canRequest(fullURL)) {
    7186        ec = SECURITY_ERR;
    72         return;
    73     }
    74 
    75     m_origin = scriptExecutionContext()->securityOrigin()->toString();
    76     m_decoder = TextResourceDecoder::create("text/plain", "UTF-8");
    77 
    78     setPendingActivity(this);
    79     connect();
     87        return 0;
     88    }
     89
     90    RefPtr<EventSource> source = adoptRef(new EventSource(fullURL, context));
     91
     92    source->setPendingActivity(source.get());
     93    source->connect();
     94
     95    return source.release();
    8096}
    8197
  • trunk/WebCore/page/EventSource.h

    r52891 r62696  
    22 * Copyright (C) 2009 Ericsson AB
    33 * All rights reserved.
     4 * Copyright (C) 2010 Apple Inc. All rights reserved.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    3637
    3738#include "ActiveDOMObject.h"
    38 #include "AtomicStringHash.h"
    39 #include "EventNames.h"
    4039#include "EventTarget.h"
    4140#include "KURL.h"
    4241#include "ThreadableLoaderClient.h"
    4342#include "Timer.h"
    44 
    45 #include <wtf/HashMap.h>
    46 #include <wtf/PassRefPtr.h>
    4743#include <wtf/RefPtr.h>
    4844#include <wtf/Vector.h>
     
    5753    class EventSource : public RefCounted<EventSource>, public EventTarget, private ThreadableLoaderClient, public ActiveDOMObject {
    5854    public:
    59         static PassRefPtr<EventSource> create(const String& url, ScriptExecutionContext* context, ExceptionCode& ec) { return adoptRef(new EventSource(url, context, ec)); }
     55        static PassRefPtr<EventSource> create(const String& url, ScriptExecutionContext*, ExceptionCode&);
    6056        virtual ~EventSource();
    6157
     
    8783
    8884    private:
    89         EventSource(const String& url, ScriptExecutionContext* context, ExceptionCode& ec);
     85        EventSource(const KURL&, ScriptExecutionContext*);
    9086
    9187        virtual void refEventTarget() { ref(); }
     
    9490        virtual EventTargetData* ensureEventTargetData();
    9591
    96         virtual void didReceiveResponse(const ResourceResponse& response);
     92        virtual void didReceiveResponse(const ResourceResponse&);
    9793        virtual void didReceiveData(const char* data, int length);
    9894        virtual void didFinishLoading(unsigned long);
    99         virtual void didFail(const ResourceError& error);
     95        virtual void didFail(const ResourceError&);
    10096        virtual void didFailRedirectCheck();
    10197
  • trunk/WebCore/storage/StorageAreaSync.cpp

    r61542 r62696  
    11/*
    2  * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2008, 2009, 2010 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5050static const int MaxiumItemsToSync = 100;
    5151
    52 PassRefPtr<StorageAreaSync> StorageAreaSync::create(PassRefPtr<StorageSyncManager> storageSyncManager, PassRefPtr<StorageAreaImpl> storageArea, String databaseIdentifier)
    53 {
    54     return adoptRef(new StorageAreaSync(storageSyncManager, storageArea, databaseIdentifier));
    55 }
    56 
    57 StorageAreaSync::StorageAreaSync(PassRefPtr<StorageSyncManager> storageSyncManager, PassRefPtr<StorageAreaImpl> storageArea, String databaseIdentifier)
     52inline StorageAreaSync::StorageAreaSync(PassRefPtr<StorageSyncManager> storageSyncManager, PassRefPtr<StorageAreaImpl> storageArea, const String& databaseIdentifier)
    5853    : m_syncTimer(this, &StorageAreaSync::syncTimerFired)
    5954    , m_itemsCleared(false)
     
    7166    ASSERT(m_storageArea);
    7267    ASSERT(m_syncManager);
     68}
     69
     70PassRefPtr<StorageAreaSync> StorageAreaSync::create(PassRefPtr<StorageSyncManager> storageSyncManager, PassRefPtr<StorageAreaImpl> storageArea, const String& databaseIdentifier)
     71{
     72    RefPtr<StorageAreaSync> area = adoptRef(new StorageAreaSync(storageSyncManager, storageArea, databaseIdentifier));
    7373
    7474    // FIXME: If it can't import, then the default WebKit behavior should be that of private browsing,
    75     // not silently ignoring it.  https://bugs.webkit.org/show_bug.cgi?id=25894
    76     if (!m_syncManager->scheduleImport(this))
    77         m_importComplete = true;
     75    // not silently ignoring it. https://bugs.webkit.org/show_bug.cgi?id=25894
     76    if (!area->m_syncManager->scheduleImport(area.get()))
     77        area->m_importComplete = true;
     78
     79    return area.release();
    7880}
    7981
  • trunk/WebCore/storage/StorageAreaSync.h

    r61542 r62696  
    11/*
    2  * Copyright (C) 2008, 2009 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2008, 2009, 2010 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929#if ENABLE(DOM_STORAGE)
    3030
    31 #include "PlatformString.h"
    3231#include "SQLiteDatabase.h"
    3332#include "StringHash.h"
     
    4342    class StorageAreaSync : public RefCounted<StorageAreaSync> {
    4443    public:
    45         static PassRefPtr<StorageAreaSync> create(PassRefPtr<StorageSyncManager> storageSyncManager, PassRefPtr<StorageAreaImpl> storageArea, String databaseIdentifier);
     44        static PassRefPtr<StorageAreaSync> create(PassRefPtr<StorageSyncManager>, PassRefPtr<StorageAreaImpl>, const String& databaseIdentifier);
    4645        ~StorageAreaSync();
    4746
     
    5352
    5453    private:
    55         StorageAreaSync(PassRefPtr<StorageSyncManager> storageSyncManager, PassRefPtr<StorageAreaImpl> storageArea, String databaseIdentifier);
     54        StorageAreaSync(PassRefPtr<StorageSyncManager>, PassRefPtr<StorageAreaImpl>, const String& databaseIdentifier);
    5655
    5756        void dispatchStorageEvent(const String& key, const String& oldValue, const String& newValue, Frame* sourceFrame);
  • trunk/WebCore/workers/SharedWorker.cpp

    r56404 r62696  
    11/*
    22 * Copyright (C) 2009 Google Inc. All rights reserved.
     3 * Copyright (C) 2010 Apple Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    4344namespace WebCore {
    4445
    45 SharedWorker::SharedWorker(const String& url, const String& name, ScriptExecutionContext* context, ExceptionCode& ec)
     46inline SharedWorker::SharedWorker(ScriptExecutionContext* context)
    4647    : AbstractWorker(context)
    4748{
    48     RefPtr<MessageChannel> channel = MessageChannel::create(scriptExecutionContext());
    49     m_port = channel->port1();
     49}
     50
     51PassRefPtr<SharedWorker> SharedWorker::create(const String& url, const String& name, ScriptExecutionContext* context, ExceptionCode& ec)
     52{
     53    RefPtr<SharedWorker> worker = adoptRef(new SharedWorker(context));
     54
     55    RefPtr<MessageChannel> channel = MessageChannel::create(context);
     56    worker->m_port = channel->port1();
    5057    OwnPtr<MessagePortChannel> remotePort = channel->port2()->disentangle(ec);
    51     ASSERT(!ec);
     58    ASSERT(remotePort);
    5259
    53     KURL scriptUrl = resolveURL(url, ec);
    54     if (ec)
    55         return;
    56     SharedWorkerRepository::connect(this, remotePort.release(), scriptUrl, name, ec);
     60    KURL scriptURL = worker->resolveURL(url, ec);
     61    if (scriptURL.isEmpty())
     62        return 0;
     63
     64    SharedWorkerRepository::connect(worker.get(), remotePort.release(), scriptURL, name, ec);
     65
    5766#if ENABLE(INSPECTOR)
    58     if (InspectorController* inspector = scriptExecutionContext()->inspectorController())
    59         inspector->didCreateWorker(asID(), scriptUrl.string(), true);
     67    if (InspectorController* inspector = context->inspectorController())
     68        inspector->didCreateWorker(worker->asID(), scriptURL.string(), true);
    6069#endif
     70
     71    return worker.release();
    6172}
    6273
  • trunk/WebCore/workers/SharedWorker.h

    r46845 r62696  
    11/*
    22 * Copyright (C) 2009 Google Inc. All rights reserved.
     3 * Copyright (C) 2010 Apple Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3435#include "AbstractWorker.h"
    3536
    36 #include <wtf/PassRefPtr.h>
    37 #include <wtf/RefPtr.h>
    38 
    3937#if ENABLE(SHARED_WORKERS)
    4038
     
    4341    class SharedWorker : public AbstractWorker {
    4442    public:
    45         static PassRefPtr<SharedWorker> create(const String& url, const String& name, ScriptExecutionContext* context, ExceptionCode& ec)
    46         {
    47             return adoptRef(new SharedWorker(url, name, context, ec));
    48         }
    49         ~SharedWorker();
     43        static PassRefPtr<SharedWorker> create(const String& url, const String& name, ScriptExecutionContext*, ExceptionCode&);
     44        virtual ~SharedWorker();
     45
    5046        MessagePort* port() const { return m_port.get(); }
    5147
     48    private:
     49        SharedWorker(ScriptExecutionContext*);
     50
    5251        virtual SharedWorker* toSharedWorker() { return this; }
    53 
    54     private:
    55         SharedWorker(const String& url, const String& name, ScriptExecutionContext*, ExceptionCode&);
    5652
    5753        RefPtr<MessagePort> m_port;
  • trunk/WebCore/workers/Worker.cpp

    r58647 r62696  
    11/*
    2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved.
    33 * Copyright (C) 2009 Google Inc. All Rights Reserved.
    44 *
     
    5151namespace WebCore {
    5252
    53 Worker::Worker(const String& url, ScriptExecutionContext* context, ExceptionCode& ec)
     53inline Worker::Worker(ScriptExecutionContext* context)
    5454    : AbstractWorker(context)
    5555    , m_contextProxy(WorkerContextProxy::create(this))
    5656{
    57     KURL scriptURL = resolveURL(url, ec);
    58     if (ec)
    59         return;
     57}
    6058
    61     m_scriptLoader = new WorkerScriptLoader(ResourceRequestBase::TargetIsWorker);
    62     m_scriptLoader->loadAsynchronously(scriptExecutionContext(), scriptURL, DenyCrossOriginRequests, this);
    63     setPendingActivity(this);  // The worker context does not exist while loading, so we must ensure that the worker object is not collected, as well as its event listeners.
     59PassRefPtr<Worker> Worker::create(const String& url, ScriptExecutionContext* context, ExceptionCode& ec)
     60{
     61    RefPtr<Worker> worker = adoptRef(new Worker(context));
     62
     63    KURL scriptURL = worker->resolveURL(url, ec);
     64    if (scriptURL.isEmpty())
     65        return 0;
     66
     67    worker->m_scriptLoader = adoptPtr(new WorkerScriptLoader(ResourceRequestBase::TargetIsWorker));
     68    worker->m_scriptLoader->loadAsynchronously(context, scriptURL, DenyCrossOriginRequests, worker.get());
     69
     70    // The worker context does not exist while loading, so we must ensure that the worker object is not collected, nor are its event listeners.
     71    worker->setPendingActivity(worker.get());
     72
    6473#if ENABLE(INSPECTOR)
    65     if (InspectorController* inspector = scriptExecutionContext()->inspectorController())
    66         inspector->didCreateWorker(asID(), scriptURL.string(), false);
     74    if (InspectorController* inspector = context->inspectorController())
     75        inspector->didCreateWorker(worker->asID(), scriptURL.string(), false);
    6776#endif
     77
     78    return worker.release();
    6879}
    6980
  • trunk/WebCore/workers/Worker.h

    r49734 r62696  
    11/*
    2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5454    class Worker : public AbstractWorker, private WorkerScriptLoaderClient {
    5555    public:
    56         static PassRefPtr<Worker> create(const String& url, ScriptExecutionContext* context, ExceptionCode& ec) { return adoptRef(new Worker(url, context, ec)); }
    57         ~Worker();
     56        static PassRefPtr<Worker> create(const String& url, ScriptExecutionContext*, ExceptionCode&);
     57        virtual ~Worker();
    5858
    5959        virtual Worker* toWorker() { return this; }
    6060
    61         void postMessage(PassRefPtr<SerializedScriptValue>, ExceptionCode&);
    62         void postMessage(PassRefPtr<SerializedScriptValue>, const MessagePortArray*, ExceptionCode&);
     61        void postMessage(PassRefPtr<SerializedScriptValue> message, ExceptionCode&);
     62        void postMessage(PassRefPtr<SerializedScriptValue> message, const MessagePortArray*, ExceptionCode&);
    6363        // FIXME: remove this when we update the ObjC bindings (bug #28774).
    6464        void postMessage(PassRefPtr<SerializedScriptValue> message, MessagePort*, ExceptionCode&);
     
    7373
    7474    private:
    75         Worker(const String&, ScriptExecutionContext*, ExceptionCode&);
     75        Worker(ScriptExecutionContext*);
    7676
    7777        virtual void notifyFinished();
Note: See TracChangeset for help on using the changeset viewer.