109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)/* 209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Copyright (C) 2008 Apple Inc. All Rights Reserved. 309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Copyright 2014 The Chromium Authors. All rights reserved. 409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * 509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * This library is free software; you can redistribute it and/or 609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * modify it under the terms of the GNU Library General Public 709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * License as published by the Free Software Foundation; either 809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * version 2 of the License, or (at your option) any later version. 909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * 1009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * This library is distributed in the hope that it will be useful, 1109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * but WITHOUT ANY WARRANTY; without even the implied warranty of 1209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Library General Public License for more details. 1409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * 1509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * You should have received a copy of the GNU Library General Public License 1609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * along with this library; see the file COPYING.LIB. If not, write to 1709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 1809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Boston, MA 02110-1301, USA. 1909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) */ 2009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 2109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "config.h" 2209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/page/InjectedStyleSheets.h" 2309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 2409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/dom/Document.h" 2509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/dom/StyleEngine.h" 26d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/frame/LocalFrame.h" 2709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/page/Page.h" 2809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "wtf/HashSet.h" 2909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 30c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 3109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 3209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)// static 3309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)InjectedStyleSheets& InjectedStyleSheets::instance() 3409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 3509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) DEFINE_STATIC_LOCAL(InjectedStyleSheets, instance, ()); 3609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return instance; 3709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 3809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 3909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void InjectedStyleSheets::add(const String& source, const Vector<String>& whitelist, StyleInjectionTarget injectIn) 4009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 4109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) m_entries.append(adoptPtr(new InjectedStyleSheetEntry(source, whitelist, injectIn))); 4209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) invalidateInjectedStyleSheetCacheInAllFrames(); 4309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 4409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 4509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void InjectedStyleSheets::removeAll() 4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 4709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) m_entries.clear(); 4809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) invalidateInjectedStyleSheetCacheInAllFrames(); 4909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 5009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 5109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void InjectedStyleSheets::invalidateInjectedStyleSheetCacheInAllFrames() 5209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 5309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) // Clear our cached sheets and have them just reparse. 54d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) const HashSet<Page*>& pages = Page::ordinaryPages(); 5509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 5609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) HashSet<Page*>::const_iterator end = pages.end(); 5709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) for (HashSet<Page*>::const_iterator it = pages.begin(); it != end; ++it) { 58f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles) for (Frame* frame = (*it)->mainFrame(); frame; frame = frame->tree().traverseNext()) { 59f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles) if (frame->isLocalFrame()) 60f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles) toLocalFrame(frame)->document()->styleEngine()->invalidateInjectedStyleSheetCache(); 61f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles) } 6209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } 6309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 6409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 65c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 66