| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2012 Motorola Mobility Inc. | 3 * Copyright (C) 2012 Motorola Mobility Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| 11 * 2. Redistributions in binary form must reproduce the above copyright | 11 * 2. Redistributions in binary form must reproduce the above copyright |
| 12 * notice, this list of conditions and the following disclaimer in the | 12 * notice, this list of conditions and the following disclaimer in the |
| 13 * documentation and/or other materials provided with the distribution. | 13 * documentation and/or other materials provided with the distribution. |
| 14 * | 14 * |
| 15 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 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 | 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 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 | 18 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 | |
| 29 #include "core/html/DOMURL.h" | 28 #include "core/html/DOMURL.h" |
| 30 | 29 |
| 30 #include "bindings/v8/ExceptionMessages.h" |
| 31 #include "bindings/v8/ExceptionState.h" |
| 32 #include "core/dom/ExceptionCode.h" |
| 31 #include "core/dom/ScriptExecutionContext.h" | 33 #include "core/dom/ScriptExecutionContext.h" |
| 32 #include "core/fetch/MemoryCache.h" | 34 #include "core/fetch/MemoryCache.h" |
| 33 #include "core/fileapi/Blob.h" | 35 #include "core/fileapi/Blob.h" |
| 34 #include "core/fileapi/BlobURL.h" | 36 #include "core/fileapi/BlobURL.h" |
| 35 #include "core/html/PublicURLManager.h" | 37 #include "core/html/PublicURLManager.h" |
| 36 #include "weborigin/KURL.h" | 38 #include "weborigin/SecurityOrigin.h" |
| 37 #include "wtf/MainThread.h" | 39 #include "wtf/MainThread.h" |
| 38 | 40 |
| 39 namespace WebCore { | 41 namespace WebCore { |
| 40 | 42 |
| 43 DOMURL::DOMURL(const String& url, const KURL& base, ExceptionState& es) |
| 44 { |
| 45 ScriptWrappable::init(this); |
| 46 if (!base.isValid()) |
| 47 es.throwDOMException(SyntaxError, ExceptionMessages::failedToConstruct("
URL", "Invalid base URL")); |
| 48 |
| 49 m_url = KURL(base, url); |
| 50 if (!m_url.isValid()) |
| 51 es.throwDOMException(SyntaxError, ExceptionMessages::failedToConstruct("
URL", "Invalid URL")); |
| 52 } |
| 53 |
| 54 void DOMURL::setInput(const String& value) |
| 55 { |
| 56 KURL url(blankURL(), value); |
| 57 if (url.isValid()) { |
| 58 m_url = url; |
| 59 m_input = String(); |
| 60 } else { |
| 61 m_url = KURL(); |
| 62 m_input = value; |
| 63 } |
| 64 } |
| 65 |
| 41 String DOMURL::createObjectURL(ScriptExecutionContext* scriptExecutionContext, B
lob* blob) | 66 String DOMURL::createObjectURL(ScriptExecutionContext* scriptExecutionContext, B
lob* blob) |
| 42 { | 67 { |
| 43 if (!scriptExecutionContext || !blob) | 68 if (!scriptExecutionContext || !blob) |
| 44 return String(); | 69 return String(); |
| 45 return createPublicURL(scriptExecutionContext, blob); | 70 return createPublicURL(scriptExecutionContext, blob); |
| 46 } | 71 } |
| 47 | 72 |
| 48 String DOMURL::createPublicURL(ScriptExecutionContext* scriptExecutionContext, U
RLRegistrable* registrable) | 73 String DOMURL::createPublicURL(ScriptExecutionContext* scriptExecutionContext, U
RLRegistrable* registrable) |
| 49 { | 74 { |
| 50 KURL publicURL = BlobURL::createPublicURL(scriptExecutionContext->securityOr
igin()); | 75 KURL publicURL = BlobURL::createPublicURL(scriptExecutionContext->securityOr
igin()); |
| 51 if (publicURL.isEmpty()) | 76 if (publicURL.isEmpty()) |
| 52 return String(); | 77 return String(); |
| 53 | 78 |
| 54 scriptExecutionContext->publicURLManager().registerURL(scriptExecutionContex
t->securityOrigin(), publicURL, registrable); | 79 scriptExecutionContext->publicURLManager().registerURL(scriptExecutionContex
t->securityOrigin(), publicURL, registrable); |
| 55 | 80 |
| 56 return publicURL.string(); | 81 return publicURL.string(); |
| 57 } | 82 } |
| 58 | 83 |
| 59 void DOMURL::revokeObjectURL(ScriptExecutionContext* scriptExecutionContext, con
st String& urlString) | 84 void DOMURL::revokeObjectURL(ScriptExecutionContext* scriptExecutionContext, con
st String& urlString) |
| 60 { | 85 { |
| 61 if (!scriptExecutionContext) | 86 if (!scriptExecutionContext) |
| 62 return; | 87 return; |
| 63 | 88 |
| 64 KURL url(KURL(), urlString); | 89 KURL url(KURL(), urlString); |
| 65 MemoryCache::removeURLFromCache(scriptExecutionContext, url); | 90 MemoryCache::removeURLFromCache(scriptExecutionContext, url); |
| 66 scriptExecutionContext->publicURLManager().revoke(url); | 91 scriptExecutionContext->publicURLManager().revoke(url); |
| 67 } | 92 } |
| 68 | 93 |
| 69 } // namespace WebCore | 94 } // namespace WebCore |
| OLD | NEW |