OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Motorola Mobility Inc. | 2 * Copyright (C) 2012 Motorola Mobility Inc. |
3 * Copyright (C) 2013 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2013 Google Inc. All Rights Reserved. |
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 #include "core/html/PublicURLManager.h" | 28 #include "core/html/PublicURLManager.h" |
29 | 29 |
| 30 #include "core/fetch/MemoryCache.h" |
30 #include "core/html/URLRegistry.h" | 31 #include "core/html/URLRegistry.h" |
31 #include "platform/weborigin/KURL.h" | 32 #include "platform/weborigin/KURL.h" |
| 33 #include "wtf/Vector.h" |
32 #include "wtf/text/StringHash.h" | 34 #include "wtf/text/StringHash.h" |
33 | 35 |
34 namespace WebCore { | 36 namespace WebCore { |
35 | 37 |
36 PassOwnPtr<PublicURLManager> PublicURLManager::create(ExecutionContext* context) | 38 PassOwnPtr<PublicURLManager> PublicURLManager::create(ExecutionContext* context) |
37 { | 39 { |
38 OwnPtr<PublicURLManager> publicURLManager(adoptPtr(new PublicURLManager(cont
ext))); | 40 OwnPtr<PublicURLManager> publicURLManager(adoptPtr(new PublicURLManager(cont
ext))); |
39 publicURLManager->suspendIfNeeded(); | 41 publicURLManager->suspendIfNeeded(); |
40 return publicURLManager.release(); | 42 return publicURLManager.release(); |
41 } | 43 } |
42 | 44 |
43 PublicURLManager::PublicURLManager(ExecutionContext* context) | 45 PublicURLManager::PublicURLManager(ExecutionContext* context) |
44 : ActiveDOMObject(context) | 46 : ActiveDOMObject(context) |
45 , m_isStopped(false) | 47 , m_isStopped(false) |
46 { | 48 { |
47 } | 49 } |
48 | 50 |
49 void PublicURLManager::registerURL(SecurityOrigin* origin, const KURL& url, URLR
egistrable* registrable) | 51 void PublicURLManager::registerURL(SecurityOrigin* origin, const KURL& url, URLR
egistrable* registrable, const String& uuid) |
50 { | 52 { |
51 if (m_isStopped) | 53 if (m_isStopped) |
52 return; | 54 return; |
53 | 55 |
54 RegistryURLMap::ValueType* found = m_registryToURL.add(®istrable->registr
y(), URLSet()).storedValue; | 56 RegistryURLMap::ValueType* found = m_registryToURL.add(®istrable->registr
y(), URLMap()).storedValue; |
55 found->key->registerURL(origin, url, registrable); | 57 found->key->registerURL(origin, url, registrable); |
56 found->value.add(url.string()); | 58 found->value.add(url.string(), uuid); |
57 } | 59 } |
58 | 60 |
59 void PublicURLManager::revoke(const KURL& url) | 61 void PublicURLManager::revoke(const KURL& url) |
60 { | 62 { |
61 for (RegistryURLMap::iterator i = m_registryToURL.begin(); i != m_registryTo
URL.end(); ++i) { | 63 for (RegistryURLMap::iterator i = m_registryToURL.begin(); i != m_registryTo
URL.end(); ++i) { |
62 if (i->value.contains(url.string())) { | 64 if (i->value.contains(url.string())) { |
63 i->key->unregisterURL(url); | 65 i->key->unregisterURL(url); |
64 i->value.remove(url.string()); | 66 i->value.remove(url.string()); |
65 break; | 67 break; |
66 } | 68 } |
67 } | 69 } |
68 } | 70 } |
69 | 71 |
| 72 void PublicURLManager::revoke(const String& uuid) |
| 73 { |
| 74 // A linear scan; revoking by UUID is assumed rare. |
| 75 Vector<String> urlsToRemove; |
| 76 for (RegistryURLMap::iterator i = m_registryToURL.begin(); i != m_registryTo
URL.end(); ++i) { |
| 77 URLRegistry* registry = i->key; |
| 78 URLMap& registeredURLs = i->value; |
| 79 for (URLMap::iterator j = registeredURLs.begin(); j != registeredURLs.en
d(); ++j) { |
| 80 if (uuid == j->value) { |
| 81 KURL url(ParsedURLString, j->key); |
| 82 MemoryCache::removeURLFromCache(executionContext(), url); |
| 83 registry->unregisterURL(url); |
| 84 urlsToRemove.append(j->key); |
| 85 } |
| 86 } |
| 87 for (unsigned j = 0; j < urlsToRemove.size(); j++) |
| 88 registeredURLs.remove(urlsToRemove[j]); |
| 89 urlsToRemove.clear(); |
| 90 } |
| 91 } |
| 92 |
70 void PublicURLManager::stop() | 93 void PublicURLManager::stop() |
71 { | 94 { |
72 if (m_isStopped) | 95 if (m_isStopped) |
73 return; | 96 return; |
74 | 97 |
75 m_isStopped = true; | 98 m_isStopped = true; |
76 for (RegistryURLMap::iterator i = m_registryToURL.begin(); i != m_registryTo
URL.end(); ++i) { | 99 for (RegistryURLMap::iterator i = m_registryToURL.begin(); i != m_registryTo
URL.end(); ++i) { |
77 for (URLSet::iterator j = i->value.begin(); j != i->value.end(); ++j) | 100 for (URLMap::iterator j = i->value.begin(); j != i->value.end(); ++j) |
78 i->key->unregisterURL(KURL(ParsedURLString, *j)); | 101 i->key->unregisterURL(KURL(ParsedURLString, j->key)); |
79 } | 102 } |
80 | 103 |
81 m_registryToURL.clear(); | 104 m_registryToURL.clear(); |
82 } | 105 } |
83 | 106 |
84 } | 107 } |
OLD | NEW |