2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright 2014 The Chromium Authors. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #include "core/page/InjectedStyleSheets.h"
24 #include "core/dom/Document.h"
25 #include "core/dom/StyleEngine.h"
26 #include "core/frame/LocalFrame.h"
27 #include "core/page/Page.h"
28 #include "wtf/HashSet.h"
33 InjectedStyleSheets& InjectedStyleSheets::instance()
35 DEFINE_STATIC_LOCAL(InjectedStyleSheets, instance, ());
39 void InjectedStyleSheets::add(const String& source, const Vector<String>& whitelist, StyleInjectionTarget injectIn)
41 m_entries.append(adoptPtr(new InjectedStyleSheetEntry(source, whitelist, injectIn)));
42 invalidateInjectedStyleSheetCacheInAllFrames();
45 void InjectedStyleSheets::removeAll()
48 invalidateInjectedStyleSheetCacheInAllFrames();
51 void InjectedStyleSheets::invalidateInjectedStyleSheetCacheInAllFrames()
53 // Clear our cached sheets and have them just reparse.
54 const HashSet<Page*>& pages = Page::ordinaryPages();
55 for (const Page* page : pages) {
56 for (Frame* frame = page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
57 if (frame->isLocalFrame())
58 toLocalFrame(frame)->document()->styleEngine()->invalidateInjectedStyleSheetCache();