commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above |
| 12 | * copyright notice, this list of conditions and the following |
| 13 | * disclaimer in the documentation and/or other materials |
| 14 | * provided with the distribution. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY |
| 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE |
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
| 21 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 25 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
| 26 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | * SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #include "config.h" |
rniwa@webkit.org | 3fc452e | 2012-08-24 21:46:24 +0000 | [diff] [blame] | 31 | #include "NamedFlowCollection.h" |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 32 | |
rniwa@webkit.org | 3fc452e | 2012-08-24 21:46:24 +0000 | [diff] [blame] | 33 | #include "DOMNamedFlowCollection.h" |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 34 | #include "Document.h" |
commit-queue@webkit.org | 5c25fc4 | 2012-08-06 16:39:56 +0000 | [diff] [blame] | 35 | #include "InspectorInstrumentation.h" |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 36 | |
| 37 | #include <wtf/text/StringHash.h> |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 38 | |
| 39 | namespace WebCore { |
| 40 | |
commit-queue@webkit.org | 9aa692e | 2013-02-08 04:59:23 +0000 | [diff] [blame] | 41 | NamedFlowCollection::NamedFlowCollection(Document* document) |
| 42 | : ContextDestructionObserver(document) |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 43 | { |
| 44 | } |
| 45 | |
andersca@apple.com | c3523f8 | 2013-10-18 23:41:24 +0000 | [diff] [blame] | 46 | Vector<RefPtr<WebKitNamedFlow>> NamedFlowCollection::namedFlows() |
commit-queue@webkit.org | 6f85951 | 2012-07-20 12:34:58 +0000 | [diff] [blame] | 47 | { |
andersca@apple.com | c3523f8 | 2013-10-18 23:41:24 +0000 | [diff] [blame] | 48 | Vector<RefPtr<WebKitNamedFlow>> namedFlows; |
commit-queue@webkit.org | 6f85951 | 2012-07-20 12:34:58 +0000 | [diff] [blame] | 49 | |
| 50 | for (NamedFlowSet::iterator it = m_namedFlows.begin(); it != m_namedFlows.end(); ++it) { |
| 51 | if ((*it)->flowState() == WebKitNamedFlow::FlowStateNull) |
| 52 | continue; |
| 53 | |
commit-queue@webkit.org | e2bb32c | 2012-08-10 09:58:35 +0000 | [diff] [blame] | 54 | namedFlows.append(RefPtr<WebKitNamedFlow>(*it)); |
commit-queue@webkit.org | 6f85951 | 2012-07-20 12:34:58 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | return namedFlows; |
| 58 | } |
| 59 | |
rniwa@webkit.org | 3fc452e | 2012-08-24 21:46:24 +0000 | [diff] [blame] | 60 | WebKitNamedFlow* NamedFlowCollection::flowByName(const String& flowName) |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 61 | { |
| 62 | NamedFlowSet::iterator it = m_namedFlows.find<String, NamedFlowHashTranslator>(flowName); |
| 63 | if (it == m_namedFlows.end() || (*it)->flowState() == WebKitNamedFlow::FlowStateNull) |
mihnea@adobe.com | 7efa55e | 2014-09-22 14:47:53 +0000 | [diff] [blame] | 64 | return nullptr; |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 65 | |
| 66 | return *it; |
| 67 | } |
| 68 | |
akling@apple.com | 689f761 | 2014-12-14 08:21:05 +0000 | [diff] [blame] | 69 | Ref<WebKitNamedFlow> NamedFlowCollection::ensureFlowWithName(const String& flowName) |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 70 | { |
| 71 | NamedFlowSet::iterator it = m_namedFlows.find<String, NamedFlowHashTranslator>(flowName); |
| 72 | if (it != m_namedFlows.end()) { |
| 73 | WebKitNamedFlow* namedFlow = *it; |
| 74 | ASSERT(namedFlow->flowState() == WebKitNamedFlow::FlowStateNull); |
| 75 | |
akling@apple.com | a3c5984 | 2014-02-12 00:08:16 +0000 | [diff] [blame] | 76 | return *namedFlow; |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | RefPtr<WebKitNamedFlow> newFlow = WebKitNamedFlow::create(this, flowName); |
| 80 | m_namedFlows.add(newFlow.get()); |
| 81 | |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 82 | InspectorInstrumentation::didCreateNamedFlow(document(), *newFlow); |
commit-queue@webkit.org | 5c25fc4 | 2012-08-06 16:39:56 +0000 | [diff] [blame] | 83 | |
akling@apple.com | a3c5984 | 2014-02-12 00:08:16 +0000 | [diff] [blame] | 84 | return newFlow.releaseNonNull(); |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 85 | } |
| 86 | |
rniwa@webkit.org | 3fc452e | 2012-08-24 21:46:24 +0000 | [diff] [blame] | 87 | void NamedFlowCollection::discardNamedFlow(WebKitNamedFlow* namedFlow) |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 88 | { |
| 89 | // The document is not valid anymore so the collection will be destroyed anyway. |
commit-queue@webkit.org | 9aa692e | 2013-02-08 04:59:23 +0000 | [diff] [blame] | 90 | if (!document()) |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 91 | return; |
| 92 | |
| 93 | ASSERT(namedFlow->flowState() == WebKitNamedFlow::FlowStateNull); |
| 94 | ASSERT(m_namedFlows.contains(namedFlow)); |
| 95 | |
burg@cs.washington.edu | dbacfc1 | 2015-01-05 21:30:33 +0000 | [diff] [blame] | 96 | InspectorInstrumentation::willRemoveNamedFlow(document(), *namedFlow); |
apavlov@chromium.org | 5aecfe9 | 2012-09-07 14:00:11 +0000 | [diff] [blame] | 97 | |
commit-queue@webkit.org | 65563d4 | 2012-09-12 12:07:24 +0000 | [diff] [blame] | 98 | m_namedFlows.remove(namedFlow); |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 99 | } |
| 100 | |
commit-queue@webkit.org | 9aa692e | 2013-02-08 04:59:23 +0000 | [diff] [blame] | 101 | Document* NamedFlowCollection::document() const |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 102 | { |
commit-queue@webkit.org | 9aa692e | 2013-02-08 04:59:23 +0000 | [diff] [blame] | 103 | ScriptExecutionContext* context = ContextDestructionObserver::scriptExecutionContext(); |
cdumez@apple.com | b69c794 | 2014-09-29 22:23:20 +0000 | [diff] [blame] | 104 | return downcast<Document>(context); |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 105 | } |
commit-queue@webkit.org | 9aa692e | 2013-02-08 04:59:23 +0000 | [diff] [blame] | 106 | |
rniwa@webkit.org | 3fc452e | 2012-08-24 21:46:24 +0000 | [diff] [blame] | 107 | PassRefPtr<DOMNamedFlowCollection> NamedFlowCollection::createCSSOMSnapshot() |
| 108 | { |
commit-queue@webkit.org | d62fc83 | 2012-09-12 16:30:04 +0000 | [diff] [blame] | 109 | Vector<WebKitNamedFlow*> createdFlows; |
rniwa@webkit.org | 3fc452e | 2012-08-24 21:46:24 +0000 | [diff] [blame] | 110 | for (NamedFlowSet::iterator it = m_namedFlows.begin(); it != m_namedFlows.end(); ++it) |
| 111 | if ((*it)->flowState() == WebKitNamedFlow::FlowStateCreated) |
commit-queue@webkit.org | d62fc83 | 2012-09-12 16:30:04 +0000 | [diff] [blame] | 112 | createdFlows.append(*it); |
rniwa@webkit.org | 3fc452e | 2012-08-24 21:46:24 +0000 | [diff] [blame] | 113 | return DOMNamedFlowCollection::create(createdFlows); |
| 114 | } |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 115 | |
commit-queue@webkit.org | d62fc83 | 2012-09-12 16:30:04 +0000 | [diff] [blame] | 116 | // The HashFunctions object used by the HashSet to compare between NamedFlows. |
| 117 | // It is safe to set safeToCompareToEmptyOrDeleted because the HashSet will never contain null pointers or deleted values. |
| 118 | struct NamedFlowCollection::NamedFlowHashFunctions { |
| 119 | static unsigned hash(WebKitNamedFlow* key) { return DefaultHash<String>::Hash::hash(key->name()); } |
| 120 | static bool equal(WebKitNamedFlow* a, WebKitNamedFlow* b) { return a->name() == b->name(); } |
| 121 | static const bool safeToCompareToEmptyOrDeleted = true; |
| 122 | }; |
| 123 | |
| 124 | // The HashTranslator is used to lookup a NamedFlow in the set using a name. |
| 125 | struct NamedFlowCollection::NamedFlowHashTranslator { |
| 126 | static unsigned hash(const String& key) { return DefaultHash<String>::Hash::hash(key); } |
| 127 | static bool equal(WebKitNamedFlow* a, const String& b) { return a->name() == b; } |
| 128 | }; |
| 129 | |
commit-queue@webkit.org | 5323f76 | 2012-07-13 10:01:38 +0000 | [diff] [blame] | 130 | } // namespace WebCore |