1 /* 2 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2012 Motorola Mobility Inc. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #include "config.h" 28 29 #include "core/html/DOMURL.h" 30 31 #include "core/dom/ScriptExecutionContext.h" 32 #include "core/fileapi/Blob.h" 33 #include "core/fileapi/BlobURL.h" 34 #include "core/html/PublicURLManager.h" 35 #include "core/loader/cache/MemoryCache.h" 36 #include "weborigin/KURL.h" 37 #include "wtf/MainThread.h" 38 39 namespace WebCore { 40 41 String DOMURL::createObjectURL(ScriptExecutionContext* scriptExecutionContext, Blob* blob) 42 { 43 if (!scriptExecutionContext || !blob) 44 return String(); 45 return createPublicURL(scriptExecutionContext, blob); 46 } 47 48 String DOMURL::createPublicURL(ScriptExecutionContext* scriptExecutionContext, URLRegistrable* registrable) 49 { 50 KURL publicURL = BlobURL::createPublicURL(scriptExecutionContext->securityOrigin()); 51 if (publicURL.isEmpty()) 52 return String(); 53 54 scriptExecutionContext->publicURLManager().registerURL(scriptExecutionContext->securityOrigin(), publicURL, registrable); 55 56 return publicURL.string(); 57 } 58 59 void DOMURL::revokeObjectURL(ScriptExecutionContext* scriptExecutionContext, const String& urlString) 60 { 61 if (!scriptExecutionContext) 62 return; 63 64 KURL url(KURL(), urlString); 65 MemoryCache::removeURLFromCache(scriptExecutionContext, url); 66 scriptExecutionContext->publicURLManager().revoke(url); 67 } 68 69 } // namespace WebCore 70