Changeset 105486 in webkit


Ignore:
Timestamp:
Jan 20, 2012 12:00:11 AM (12 years ago)
Author:
arv@chromium.org
Message:

Source/WebCore: Migrate createObjectURL & revokeObjectURL to static (Class) methods.
https://bugs.webkit.org/show_bug.cgi?id=74386

Reviewed by Adam Barth.

Test: fast/dom/DOMURL/check-instanceof-domurl-functions.html
Already Existing -

fast/files/revoke-blob-url.html
fast/dom/window-domurl-crash.html
fast/files/apply-blob-url-to-img.html
fast/files/create-blob-url-crash.html
fast/files/workers/inline-worker-via-blob-url.html

  • html/DOMURL.cpp: Added HashMap for local static objects.

(WebCore::PublicURLManager::PublicURLManager):
(WebCore::PublicURLManager::contextDestroyed):
(WebCore::PublicURLManager::blobURLs):
(WebCore::PublicURLManager::streamURLs):
(WebCore::publicURLManagerMap):
(WebCore::publicURLManager):
(WebCore::publicBlobURLs):
(WebCore::publicStreamURLs):
(WebCore::DOMURL::createObjectURL): Changed to static.
(WebCore::DOMURL::revokeObjectURL): ditto.

  • html/DOMURL.h:

(WebCore::DOMURL::create):
(WebCore::DOMURL::~DOMURL):
(WebCore::DOMURL::DOMURL):

  • html/DOMURL.idl:
  • page/DOMWindow.cpp: Removed object initialization for DOMURL.
  • page/DOMWindow.h: ditto.
  • page/DOMWindow.idl: ditto.
  • workers/WorkerContext.cpp: ditto.
  • workers/WorkerContext.h: ditto.
  • workers/WorkerContext.idl: ditto.

LayoutTests: Migrate createObjectURL & revokeObjectURL to static (Class) methods
https://bugs.webkit.org/show_bug.cgi?id=74386

Reviewed by Adam Barth.

Added test to check if createObjectURL & revokeObjectURL are static functions.

  • fast/dom/DOMURL: Added.
  • fast/dom/DOMURL/check-instanceof-domurl-functions-expected.txt: Added.
  • fast/dom/DOMURL/check-instanceof-domurl-functions.html: Added.
Location:
trunk
Files:
3 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r105485 r105486  
     12012-01-19  Kaustubh Atrawalkar  <kaustubh@motorola.com>
     2
     3        Migrate createObjectURL & revokeObjectURL to static (Class) methods
     4        https://bugs.webkit.org/show_bug.cgi?id=74386
     5
     6        Reviewed by Adam Barth.
     7
     8        Added test to check if createObjectURL & revokeObjectURL are static functions.
     9
     10        * fast/dom/DOMURL: Added.
     11        * fast/dom/DOMURL/check-instanceof-domurl-functions-expected.txt: Added.
     12        * fast/dom/DOMURL/check-instanceof-domurl-functions.html: Added.
     13
    1142012-01-20  Alexandru Chiculita  <achicu@adobe.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r105485 r105486  
     12012-01-19  Kaustubh Atrawalkar  <kaustubh@motorola.com> & Erik Arvidsson  <arv@chromium.org>
     2
     3        Migrate createObjectURL & revokeObjectURL to static (Class) methods.
     4        https://bugs.webkit.org/show_bug.cgi?id=74386
     5
     6        Reviewed by Adam Barth.
     7
     8        Test: fast/dom/DOMURL/check-instanceof-domurl-functions.html
     9        Already Existing -
     10            fast/files/revoke-blob-url.html
     11            fast/dom/window-domurl-crash.html
     12            fast/files/apply-blob-url-to-img.html
     13            fast/files/create-blob-url-crash.html
     14            fast/files/workers/inline-worker-via-blob-url.html
     15
     16        * html/DOMURL.cpp: Added HashMap for local static objects.
     17        (WebCore::PublicURLManager::PublicURLManager):
     18        (WebCore::PublicURLManager::contextDestroyed):
     19        (WebCore::PublicURLManager::blobURLs):
     20        (WebCore::PublicURLManager::streamURLs):
     21        (WebCore::publicURLManagerMap):
     22        (WebCore::publicURLManager):
     23        (WebCore::publicBlobURLs):
     24        (WebCore::publicStreamURLs):
     25        (WebCore::DOMURL::createObjectURL): Changed to static.
     26        (WebCore::DOMURL::revokeObjectURL): ditto.
     27        * html/DOMURL.h:
     28        (WebCore::DOMURL::create):
     29        (WebCore::DOMURL::~DOMURL):
     30        (WebCore::DOMURL::DOMURL):
     31        * html/DOMURL.idl:
     32        * page/DOMWindow.cpp: Removed object initialization for DOMURL.
     33        * page/DOMWindow.h: ditto.
     34        * page/DOMWindow.idl: ditto.
     35        * workers/WorkerContext.cpp: ditto.
     36        * workers/WorkerContext.h: ditto.
     37        * workers/WorkerContext.idl: ditto.
     38
    1392012-01-20  Alexandru Chiculita  <achicu@adobe.com>
    240
  • trunk/Source/WebCore/html/DOMURL.cpp

    r98802 r105486  
    11/*
    22 * Copyright (C) 2011 Google Inc. All rights reserved.
     3 * Copyright (C) 2011 Motorola Mobility Inc.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2526
    2627#include "config.h"
     28#include "DOMURL.h"
     29
     30#include "ActiveDOMObject.h"
     31#include "KURL.h"
     32#include "SecurityOrigin.h"
     33#include <wtf/MainThread.h>
    2734
    2835#if ENABLE(BLOB)
    29 
    30 #include "DOMURL.h"
    31 
    3236#include "Blob.h"
    3337#include "BlobURL.h"
    34 #include "KURL.h"
    3538#include "ScriptExecutionContext.h"
    3639#include "ThreadableBlobRegistry.h"
    37 #include <wtf/MainThread.h>
    38 
     40#include <wtf/PassOwnPtr.h>
    3941#if ENABLE(MEDIA_STREAM)
    4042#include "MediaStream.h"
    4143#include "MediaStreamRegistry.h"
    4244#endif
     45#endif
    4346
    4447namespace WebCore {
    4548
    46 DOMURL::DOMURL(ScriptExecutionContext* scriptExecutionContext)
    47     : ContextDestructionObserver(scriptExecutionContext)
     49#if ENABLE(BLOB)
     50class PublicURLManager;
     51typedef HashMap<ScriptExecutionContext*, OwnPtr<PublicURLManager> > PublicURLManagerMap;
     52static PublicURLManagerMap& publicURLManagerMap();
     53
     54class PublicURLManager : public ContextDestructionObserver {
     55public:
     56    explicit PublicURLManager(ScriptExecutionContext* scriptExecutionContext)
     57        : ContextDestructionObserver(scriptExecutionContext) { }
     58
     59    virtual void contextDestroyed()
     60    {
     61        HashSet<String>::iterator blobURLsEnd = m_blobURLs.end();
     62        for (HashSet<String>::iterator iter = m_blobURLs.begin(); iter != blobURLsEnd; ++iter)
     63            ThreadableBlobRegistry::unregisterBlobURL(KURL(ParsedURLString, *iter));
     64
     65#if ENABLE(MEDIA_STREAM)
     66        HashSet<String>::iterator streamURLsEnd = m_streamURLs.end();
     67        for (HashSet<String>::iterator iter = m_streamURLs.begin(); iter != streamURLsEnd; ++iter)
     68            MediaStreamRegistry::registry().unregisterMediaStreamURL(KURL(ParsedURLString, *iter));
     69#endif
     70
     71        ScriptExecutionContext* context = scriptExecutionContext();
     72        ContextDestructionObserver::contextDestroyed();
     73        publicURLManagerMap().remove(context);
     74    }
     75
     76    HashSet<String>& blobURLs() { return m_blobURLs; }
     77#if ENABLE(MEDIA_STREAM)
     78    HashSet<String>& streamURLs() { return m_streamURLs; }
     79#endif
     80
     81private:
     82    HashSet<String> m_blobURLs;
     83#if ENABLE(MEDIA_STREAM)
     84    HashSet<String> m_streamURLs;
     85#endif
     86};
     87
     88static PublicURLManagerMap& publicURLManagerMap()
    4889{
     90    DEFINE_STATIC_LOCAL(PublicURLManagerMap, staticPublicURLManagers, ());
     91    return staticPublicURLManagers;
    4992}
    5093
    51 DOMURL::~DOMURL()
     94static PublicURLManager& publicURLManager(ScriptExecutionContext* scriptExecutionContext)
    5295{
     96    PublicURLManagerMap& map = publicURLManagerMap();
     97    OwnPtr<PublicURLManager>& manager = map.add(scriptExecutionContext, nullptr).first->second;
     98    if (!manager)
     99        manager = adoptPtr(new PublicURLManager(scriptExecutionContext));
     100    return *manager;
    53101}
    54102
    55 void DOMURL::contextDestroyed()
     103static HashSet<String>& publicBlobURLs(ScriptExecutionContext* scriptExecutionContext)
    56104{
    57     ContextDestructionObserver::contextDestroyed();
    58 
    59     HashSet<String>::iterator publicBlobURLsEnd = m_publicBlobURLs.end();
    60     for (HashSet<String>::iterator iter = m_publicBlobURLs.begin(); iter != publicBlobURLsEnd; ++iter)
    61         ThreadableBlobRegistry::unregisterBlobURL(KURL(ParsedURLString, *iter));
    62 
    63 #if ENABLE(MEDIA_STREAM)
    64     HashSet<String>::iterator publicStreamURLsEnd = m_publicStreamURLs.end();
    65     for (HashSet<String>::iterator iter = m_publicStreamURLs.begin(); iter != publicStreamURLsEnd; ++iter)
    66         MediaStreamRegistry::registry().unregisterMediaStreamURL(KURL(ParsedURLString, *iter));
    67 #endif
     105    return publicURLManager(scriptExecutionContext).blobURLs();
    68106}
    69107
    70108#if ENABLE(MEDIA_STREAM)
    71 String DOMURL::createObjectURL(MediaStream* stream)
     109static HashSet<String>& publicStreamURLs(ScriptExecutionContext* scriptExecutionContext)
    72110{
    73     if (!m_scriptExecutionContext || !stream)
     111    return publicURLManager(scriptExecutionContext).streamURLs();
     112}
     113
     114String DOMURL::createObjectURL(ScriptExecutionContext* scriptExecutionContext, MediaStream* stream)
     115{
     116    if (!scriptExecutionContext || !stream)
    74117        return String();
    75118
    76     KURL publicURL = BlobURL::createPublicURL(scriptExecutionContext()->securityOrigin());
     119    KURL publicURL = BlobURL::createPublicURL(scriptExecutionContext->securityOrigin());
    77120    if (publicURL.isEmpty())
    78121        return String();
     
    82125
    83126    MediaStreamRegistry::registry().registerMediaStreamURL(publicURL, stream);
    84     m_publicStreamURLs.add(publicURL.string());
     127    publicStreamURLs(scriptExecutionContext).add(publicURL.string());
    85128
    86129    return publicURL.string();
     
    88131#endif
    89132
    90 String DOMURL::createObjectURL(Blob* blob)
     133String DOMURL::createObjectURL(ScriptExecutionContext* scriptExecutionContext, Blob* blob)
    91134{
    92     if (!m_scriptExecutionContext || !blob)
     135    if (!scriptExecutionContext || !blob)
    93136        return String();
    94137
    95     KURL publicURL = BlobURL::createPublicURL(scriptExecutionContext()->securityOrigin());
     138    KURL publicURL = BlobURL::createPublicURL(scriptExecutionContext->securityOrigin());
    96139    if (publicURL.isEmpty())
    97140        return String();
    98141
    99142    ThreadableBlobRegistry::registerBlobURL(publicURL, blob->url());
    100     m_publicBlobURLs.add(publicURL.string());
     143    publicBlobURLs(scriptExecutionContext).add(publicURL.string());
    101144
    102145    return publicURL.string();
    103146}
    104147
    105 void DOMURL::revokeObjectURL(const String& urlString)
     148void DOMURL::revokeObjectURL(ScriptExecutionContext* scriptExecutionContext, const String& urlString)
    106149{
    107     if (!m_scriptExecutionContext)
     150    if (!scriptExecutionContext)
    108151        return;
    109152
    110153    KURL url(KURL(), urlString);
    111154
    112     if (m_publicBlobURLs.contains(url.string())) {
     155    HashSet<String>& blobURLs = publicBlobURLs(scriptExecutionContext);
     156    if (blobURLs.contains(url.string())) {
    113157        ThreadableBlobRegistry::unregisterBlobURL(url);
    114         m_publicBlobURLs.remove(url.string());
     158        blobURLs.remove(url.string());
    115159    }
    116 
    117160#if ENABLE(MEDIA_STREAM)
    118     if (m_publicStreamURLs.contains(url.string())) {
     161    HashSet<String>& streamURLs = publicStreamURLs(scriptExecutionContext);
     162    if (streamURLs.contains(url.string())) {
    119163        // FIXME: make sure of this assertion below. Raise a spec question if required.
    120164        // Since WebWorkers cannot obtain Stream objects, we should be on the main thread.
    121165        ASSERT(isMainThread());
    122166        MediaStreamRegistry::registry().unregisterMediaStreamURL(url);
    123         m_publicStreamURLs.remove(url.string());
     167        streamURLs.remove(url.string());
    124168    }
    125169#endif
    126170}
     171#endif // ENABLE(BLOB)
    127172
    128173} // namespace WebCore
    129174
    130 #endif // ENABLE(BLOB)
  • trunk/Source/WebCore/html/DOMURL.h

    r98802 r105486  
    11/*
    22 * Copyright (C) 2011 Google Inc. All rights reserved.
     3 * Copyright (C) 2011 Motorola Mobility Inc.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2728#define DOMURL_h
    2829
    29 #if ENABLE(BLOB)
    30 
    31 #include "ActiveDOMObject.h"
     30#include "KURL.h"
    3231#include "PlatformString.h"
    33 #include <wtf/HashSet.h>
    3432#include <wtf/PassRefPtr.h>
    3533#include <wtf/RefCounted.h>
     
    4139class ScriptExecutionContext;
    4240
    43 class DOMURL : public RefCounted<DOMURL>, public ContextDestructionObserver {
     41class DOMURL : public RefCounted<DOMURL> {
     42
    4443public:
    45     static PassRefPtr<DOMURL> create(ScriptExecutionContext* scriptExecutionContext) { return adoptRef(new DOMURL(scriptExecutionContext)); }
    46     ~DOMURL();
     44    static PassRefPtr<DOMURL> create() { return adoptRef(new DOMURL); }
    4745
     46#if ENABLE(BLOB)
     47    static void contextDestroyed(ScriptExecutionContext*);
     48
     49    static String createObjectURL(ScriptExecutionContext*, Blob*);
     50    static void revokeObjectURL(ScriptExecutionContext*, const String&);
    4851#if ENABLE(MEDIA_STREAM)
    49     String createObjectURL(MediaStream*);
     52    static String createObjectURL(ScriptExecutionContext*, MediaStream*);
    5053#endif
    51     String createObjectURL(Blob*);
    52     void revokeObjectURL(const String&);
    53 
    54 private:
    55     explicit DOMURL(ScriptExecutionContext*);
    56 
    57     virtual void contextDestroyed();
    58 
    59     HashSet<String> m_publicBlobURLs;
    60 #if ENABLE(MEDIA_STREAM)
    61     HashSet<String> m_publicStreamURLs;
    6254#endif
    6355};
     
    6557} // namespace WebCore
    6658
    67 #endif // ENABLE(BLOB)
    68 
    6959#endif // DOMURL_h
  • trunk/Source/WebCore/html/DOMURL.idl

    r93713 r105486  
    11/*
    22 * Copyright (C) 2011 Google Inc. All rights reserved.
     3 * Copyright (C) 2011 Motorola Mobility Inc.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2728    interface [
    2829        Conditional=BLOB,
    29         OmitConstructor,
    3030        GenerateNativeConverter,
    3131        GenerateToJS,
    32         NoStaticTables
     32        Constructor
    3333    ] DOMURL {
    3434#if defined(ENABLE_MEDIA_STREAM) && ENABLE_MEDIA_STREAM
    35         [ConvertNullStringTo=Undefined] DOMString createObjectURL(in MediaStream stream);
     35        static [ConvertNullStringTo=Undefined,CallWith=ScriptExecutionContext] DOMString createObjectURL(in MediaStream stream);
    3636#endif
    37         [ConvertNullStringTo=Undefined] DOMString createObjectURL(in Blob blob);
    38         void revokeObjectURL(in DOMString url);
     37        static [ConvertNullStringTo=Undefined,CallWith=ScriptExecutionContext] DOMString createObjectURL(in Blob blob);
     38        static [CallWith=ScriptExecutionContext] void revokeObjectURL(in DOMString url);
    3939    };
    4040}
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r105415 r105486  
    18931893}
    18941894
    1895 #if ENABLE(BLOB)
    1896 DOMURL* DOMWindow::webkitURL() const
    1897 {
    1898     if (!m_domURL && isCurrentlyDisplayedInFrame())
    1899         m_domURL = DOMURL::create(this->scriptExecutionContext());
    1900     return m_domURL.get();
    1901 }
    1902 #endif
    1903 
    19041895#if ENABLE(QUOTA)
    19051896StorageInfo* DOMWindow::webkitStorageInfo() const
  • trunk/Source/WebCore/page/DOMWindow.h

    r105395 r105486  
    352352        using RefCounted<DOMWindow>::deref;
    353353
    354 #if ENABLE(BLOB)
    355         DOMURL* webkitURL() const;
    356 #endif
    357 
    358354#if ENABLE(DEVICE_ORIENTATION)
    359355        DEFINE_ATTRIBUTE_EVENT_LISTENER(devicemotion);
  • trunk/Source/WebCore/page/DOMWindow.idl

    r105217 r105486  
    799799        attribute [Conditional=BLOB] WebKitBlobBuilderConstructor WebKitBlobBuilder;
    800800
    801         readonly attribute [Conditional=BLOB] DOMURL webkitURL;
     801        attribute [Conditional=BLOB] DOMURLConstructor webkitURL;
    802802
    803803#if defined(ENABLE_QUOTA) && ENABLE_QUOTA
  • trunk/Source/WebCore/workers/WorkerContext.cpp

    r105395 r105486  
    378378}
    379379
    380 #if ENABLE(BLOB)
    381 DOMURL* WorkerContext::webkitURL() const
    382 {
    383     if (!m_domURL)
    384         m_domURL = DOMURL::create(this->scriptExecutionContext());
    385     return m_domURL.get();
    386 }
    387 #endif
    388 
    389380#if ENABLE(FILE_SYSTEM)
    390381void WorkerContext::webkitRequestFileSystem(int type, long long size, PassRefPtr<FileSystemCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
  • trunk/Source/WebCore/workers/WorkerContext.h

    r104803 r105486  
    132132        virtual bool isJSExecutionForbidden() const;
    133133
    134 #if ENABLE(BLOB)
    135         DOMURL* webkitURL() const;
    136 #endif
    137 
    138134#if ENABLE(FILE_SYSTEM)
    139135        enum FileSystemType {
  • trunk/Source/WebCore/workers/WorkerContext.idl

    r104126 r105486  
    102102#endif
    103103
    104         readonly attribute [Conditional=BLOB] DOMURL webkitURL;
     104        attribute [Conditional=BLOB] DOMURLConstructor webkitURL;
    105105
    106106#if defined(ENABLE_FILE_SYSTEM) && ENABLE_FILE_SYSTEM
Note: See TracChangeset for help on using the changeset viewer.