1 | /* |
2 | * Copyright (C) 2008 Apple Inc. 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 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "PageGroup.h" |
28 | |
29 | #include "DOMWrapperWorld.h" |
30 | #include "Document.h" |
31 | #include "Frame.h" |
32 | #include "Page.h" |
33 | #include "PageCache.h" |
34 | #include "StorageNamespace.h" |
35 | #include <JavaScriptCore/HeapInlines.h> |
36 | #include <JavaScriptCore/StructureInlines.h> |
37 | #include <wtf/StdLibExtras.h> |
38 | |
39 | #if ENABLE(VIDEO_TRACK) |
40 | #if PLATFORM(MAC) || HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK) |
41 | #include "CaptionUserPreferencesMediaAF.h" |
42 | #else |
43 | #include "CaptionUserPreferences.h" |
44 | #endif |
45 | #endif |
46 | |
47 | namespace WebCore { |
48 | |
49 | static unsigned getUniqueIdentifier() |
50 | { |
51 | static unsigned currentIdentifier = 0; |
52 | return ++currentIdentifier; |
53 | } |
54 | |
55 | // -------- |
56 | |
57 | PageGroup::PageGroup(const String& name) |
58 | : m_name(name) |
59 | , m_identifier(getUniqueIdentifier()) |
60 | { |
61 | } |
62 | |
63 | PageGroup::PageGroup(Page& page) |
64 | : m_identifier(getUniqueIdentifier()) |
65 | { |
66 | addPage(page); |
67 | } |
68 | |
69 | PageGroup::~PageGroup() = default; |
70 | |
71 | typedef HashMap<String, PageGroup*> PageGroupMap; |
72 | static PageGroupMap* pageGroups = nullptr; |
73 | |
74 | PageGroup* PageGroup::pageGroup(const String& groupName) |
75 | { |
76 | ASSERT(!groupName.isEmpty()); |
77 | |
78 | if (!pageGroups) |
79 | pageGroups = new PageGroupMap; |
80 | |
81 | PageGroupMap::AddResult result = pageGroups->add(groupName, nullptr); |
82 | |
83 | if (result.isNewEntry) { |
84 | ASSERT(!result.iterator->value); |
85 | result.iterator->value = new PageGroup(groupName); |
86 | } |
87 | |
88 | ASSERT(result.iterator->value); |
89 | return result.iterator->value; |
90 | } |
91 | |
92 | void PageGroup::addPage(Page& page) |
93 | { |
94 | ASSERT(!m_pages.contains(&page)); |
95 | m_pages.add(&page); |
96 | } |
97 | |
98 | void PageGroup::removePage(Page& page) |
99 | { |
100 | ASSERT(m_pages.contains(&page)); |
101 | m_pages.remove(&page); |
102 | } |
103 | |
104 | #if ENABLE(VIDEO_TRACK) |
105 | void PageGroup::captionPreferencesChanged() |
106 | { |
107 | for (auto& page : m_pages) |
108 | page->captionPreferencesChanged(); |
109 | PageCache::singleton().markPagesForCaptionPreferencesChanged(); |
110 | } |
111 | |
112 | CaptionUserPreferences& PageGroup::captionPreferences() |
113 | { |
114 | if (!m_captionPreferences) { |
115 | #if PLATFORM(MAC) || HAVE(MEDIA_ACCESSIBILITY_FRAMEWORK) |
116 | m_captionPreferences = std::make_unique<CaptionUserPreferencesMediaAF>(*this); |
117 | #else |
118 | m_captionPreferences = std::make_unique<CaptionUserPreferences>(*this); |
119 | #endif |
120 | } |
121 | |
122 | return *m_captionPreferences.get(); |
123 | } |
124 | #endif |
125 | |
126 | } // namespace WebCore |
127 | |