Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / page / InjectedStyleSheets.cpp
1 /*
2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3  * Copyright 2014 The Chromium Authors. All rights reserved.
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 #include "config.h"
22 #include "core/page/InjectedStyleSheets.h"
23
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"
29
30 namespace blink {
31
32 // static
33 InjectedStyleSheets& InjectedStyleSheets::instance()
34 {
35     DEFINE_STATIC_LOCAL(InjectedStyleSheets, instance, ());
36     return instance;
37 }
38
39 void InjectedStyleSheets::add(const String& source, const Vector<String>& whitelist, StyleInjectionTarget injectIn)
40 {
41     m_entries.append(adoptPtr(new InjectedStyleSheetEntry(source, whitelist, injectIn)));
42     invalidateInjectedStyleSheetCacheInAllFrames();
43 }
44
45 void InjectedStyleSheets::removeAll()
46 {
47     m_entries.clear();
48     invalidateInjectedStyleSheetCacheInAllFrames();
49 }
50
51 void InjectedStyleSheets::invalidateInjectedStyleSheetCacheInAllFrames()
52 {
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();
59         }
60     }
61 }
62
63 } // namespace blink