Commit c150aba7 authored by aa@chromium.org's avatar aa@chromium.org

2010-08-12 Aaron Boodman <aa@chromium.org>

        Reviewed by David Hyatt.

        Make the cascade level of "user" styles configurable
        https://bugs.webkit.org/show_bug.cgi?id=43457

        * WebCore.exp.in:
        * css/CSSStyleSelector.cpp:
        (WebCore::CSSStyleSelector::CSSStyleSelector):
        * dom/Document.cpp:
        (WebCore::Document::pageGroupUserSheets):
        * page/PageGroup.cpp:
        (WebCore::PageGroup::addUserStyleSheetToWorld):
        * page/PageGroup.h:
        * page/UserStyleSheet.h:
        (WebCore::UserStyleSheet::):
        (WebCore::UserStyleSheet::UserStyleSheet):
        (WebCore::UserStyleSheet::level):
2010-08-12  Aaron Boodman  <aa@chromium.org>

        Reviewed by David Hyatt.

        Make the cascade level of "user" styles configurable
        https://bugs.webkit.org/show_bug.cgi?id=43457

        * src/WebViewImpl.cpp:
        (WebKit::WebView::addUserStyleSheet):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@65273 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent d2525bb7
2010-08-12 Aaron Boodman <aa@chromium.org>
Reviewed by David Hyatt.
Make the cascade level of "user" styles configurable
https://bugs.webkit.org/show_bug.cgi?id=43457
* WebCore.exp.in:
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::CSSStyleSelector):
* dom/Document.cpp:
(WebCore::Document::pageGroupUserSheets):
* page/PageGroup.cpp:
(WebCore::PageGroup::addUserStyleSheetToWorld):
* page/PageGroup.h:
* page/UserStyleSheet.h:
(WebCore::UserStyleSheet::):
(WebCore::UserStyleSheet::UserStyleSheet):
(WebCore::UserStyleSheet::level):
2010-08-12 Jian Li <jianli@chromium.org> 2010-08-12 Jian Li <jianli@chromium.org>
Fix qt build break. Fix qt build break.
...@@ -820,7 +820,7 @@ __ZN7WebCore9PageGroup18addVisitedLinkHashEy ...@@ -820,7 +820,7 @@ __ZN7WebCore9PageGroup18addVisitedLinkHashEy
__ZN7WebCore9PageGroup20addUserScriptToWorldEPNS_15DOMWrapperWorldERKN3WTF6StringERKNS_4KURLENS3_10PassOwnPtrINS3_6VectorIS4_Lm0EEEEESD_NS_23UserScriptInjectionTimeENS_25UserContentInjectedFramesE __ZN7WebCore9PageGroup20addUserScriptToWorldEPNS_15DOMWrapperWorldERKN3WTF6StringERKNS_4KURLENS3_10PassOwnPtrINS3_6VectorIS4_Lm0EEEEESD_NS_23UserScriptInjectionTimeENS_25UserContentInjectedFramesE
__ZN7WebCore9PageGroup20removeAllUserContentEv __ZN7WebCore9PageGroup20removeAllUserContentEv
__ZN7WebCore9PageGroup21removeAllVisitedLinksEv __ZN7WebCore9PageGroup21removeAllVisitedLinksEv
__ZN7WebCore9PageGroup24addUserStyleSheetToWorldEPNS_15DOMWrapperWorldERKN3WTF6StringERKNS_4KURLENS3_10PassOwnPtrINS3_6VectorIS4_Lm0EEEEESD_NS_25UserContentInjectedFramesE __ZN7WebCore9PageGroup24addUserStyleSheetToWorldEPNS_15DOMWrapperWorldERKN3WTF6StringERKNS_4KURLENS3_10PassOwnPtrINS3_6VectorIS4_Lm0EEEEESD_NS_25UserContentInjectedFramesENS_14UserStyleSheet5LevelE
__ZN7WebCore9PageGroup25removeUserScriptFromWorldEPNS_15DOMWrapperWorldERKNS_4KURLE __ZN7WebCore9PageGroup25removeUserScriptFromWorldEPNS_15DOMWrapperWorldERKNS_4KURLE
__ZN7WebCore9PageGroup26removeUserScriptsFromWorldEPNS_15DOMWrapperWorldE __ZN7WebCore9PageGroup26removeUserScriptsFromWorldEPNS_15DOMWrapperWorldE
__ZN7WebCore9PageGroup26setShouldTrackVisitedLinksEb __ZN7WebCore9PageGroup26setShouldTrackVisitedLinksEb
......
...@@ -458,32 +458,37 @@ CSSStyleSelector::CSSStyleSelector(Document* doc, StyleSheetList* styleSheets, C ...@@ -458,32 +458,37 @@ CSSStyleSelector::CSSStyleSelector(Document* doc, StyleSheetList* styleSheets, C
m_medium = new MediaQueryEvaluator(view->mediaType(), view->frame(), m_rootDefaultStyle.get()); m_medium = new MediaQueryEvaluator(view->mediaType(), view->frame(), m_rootDefaultStyle.get());
} }
m_authorStyle = new CSSRuleSet();
// FIXME: This sucks! The user sheet is reparsed every time! // FIXME: This sucks! The user sheet is reparsed every time!
if (pageUserSheet || pageGroupUserSheets) { OwnPtr<CSSRuleSet> tempUserStyle(new CSSRuleSet);
m_userStyle = new CSSRuleSet(); if (pageUserSheet)
if (pageUserSheet) tempUserStyle->addRulesFromSheet(pageUserSheet, *m_medium, this);
m_userStyle->addRulesFromSheet(pageUserSheet, *m_medium, this); if (pageGroupUserSheets) {
if (pageGroupUserSheets) { unsigned length = pageGroupUserSheets->size();
unsigned length = pageGroupUserSheets->size(); for (unsigned i = 0; i < length; i++) {
for (unsigned i = 0; i < length; i++) if (pageGroupUserSheets->at(i)->isUserStyleSheet())
m_userStyle->addRulesFromSheet(pageGroupUserSheets->at(i).get(), *m_medium, this); tempUserStyle->addRulesFromSheet(pageGroupUserSheets->at(i).get(), *m_medium, this);
else
m_authorStyle->addRulesFromSheet(pageGroupUserSheets->at(i).get(), *m_medium, this);
} }
} }
// add stylesheets from document if (tempUserStyle->m_ruleCount > 0 || tempUserStyle->m_pageRuleCount > 0)
m_authorStyle = new CSSRuleSet(); m_userStyle = tempUserStyle.leakPtr();
// Add rules from elements like SVG's <font-face> // Add rules from elements like SVG's <font-face>
if (mappedElementSheet) if (mappedElementSheet)
m_authorStyle->addRulesFromSheet(mappedElementSheet, *m_medium, this); m_authorStyle->addRulesFromSheet(mappedElementSheet, *m_medium, this);
// add stylesheets from document
unsigned length = styleSheets->length(); unsigned length = styleSheets->length();
for (unsigned i = 0; i < length; i++) { for (unsigned i = 0; i < length; i++) {
StyleSheet* sheet = styleSheets->item(i); StyleSheet* sheet = styleSheets->item(i);
if (sheet->isCSSStyleSheet() && !sheet->disabled()) if (sheet->isCSSStyleSheet() && !sheet->disabled())
m_authorStyle->addRulesFromSheet(static_cast<CSSStyleSheet*>(sheet), *m_medium, this); m_authorStyle->addRulesFromSheet(static_cast<CSSStyleSheet*>(sheet), *m_medium, this);
} }
if (doc->renderer() && doc->renderer()->style()) if (doc->renderer() && doc->renderer()->style())
doc->renderer()->style()->font().update(fontSelector()); doc->renderer()->style()->font().update(fontSelector());
} }
......
...@@ -2225,7 +2225,7 @@ const Vector<RefPtr<CSSStyleSheet> >* Document::pageGroupUserSheets() const ...@@ -2225,7 +2225,7 @@ const Vector<RefPtr<CSSStyleSheet> >* Document::pageGroupUserSheets() const
if (!UserContentURLPattern::matchesPatterns(url(), sheet->whitelist(), sheet->blacklist())) if (!UserContentURLPattern::matchesPatterns(url(), sheet->whitelist(), sheet->blacklist()))
continue; continue;
RefPtr<CSSStyleSheet> parsedSheet = CSSStyleSheet::createInline(const_cast<Document*>(this), sheet->url()); RefPtr<CSSStyleSheet> parsedSheet = CSSStyleSheet::createInline(const_cast<Document*>(this), sheet->url());
parsedSheet->setIsUserStyleSheet(true); parsedSheet->setIsUserStyleSheet(sheet->level() == UserStyleSheet::UserLevel);
parsedSheet->parseString(sheet->source(), !inCompatMode()); parsedSheet->parseString(sheet->source(), !inCompatMode());
if (!m_pageGroupUserSheets) if (!m_pageGroupUserSheets)
m_pageGroupUserSheets.set(new Vector<RefPtr<CSSStyleSheet> >); m_pageGroupUserSheets.set(new Vector<RefPtr<CSSStyleSheet> >);
......
...@@ -236,11 +236,12 @@ void PageGroup::addUserScriptToWorld(DOMWrapperWorld* world, const String& sourc ...@@ -236,11 +236,12 @@ void PageGroup::addUserScriptToWorld(DOMWrapperWorld* world, const String& sourc
void PageGroup::addUserStyleSheetToWorld(DOMWrapperWorld* world, const String& source, const KURL& url, void PageGroup::addUserStyleSheetToWorld(DOMWrapperWorld* world, const String& source, const KURL& url,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist, PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
UserContentInjectedFrames injectedFrames) UserContentInjectedFrames injectedFrames,
UserStyleSheet::Level level)
{ {
ASSERT_ARG(world, world); ASSERT_ARG(world, world);
OwnPtr<UserStyleSheet> userStyleSheet(new UserStyleSheet(source, url, whitelist, blacklist, injectedFrames)); OwnPtr<UserStyleSheet> userStyleSheet(new UserStyleSheet(source, url, whitelist, blacklist, injectedFrames, level));
if (!m_userStyleSheets) if (!m_userStyleSheets)
m_userStyleSheets.set(new UserStyleSheetMap); m_userStyleSheets.set(new UserStyleSheetMap);
UserStyleSheetVector*& styleSheetsInWorld = m_userStyleSheets->add(world, 0).first->second; UserStyleSheetVector*& styleSheetsInWorld = m_userStyleSheets->add(world, 0).first->second;
......
...@@ -80,7 +80,8 @@ namespace WebCore { ...@@ -80,7 +80,8 @@ namespace WebCore {
UserScriptInjectionTime, UserContentInjectedFrames); UserScriptInjectionTime, UserContentInjectedFrames);
void addUserStyleSheetToWorld(DOMWrapperWorld*, const String& source, const KURL&, void addUserStyleSheetToWorld(DOMWrapperWorld*, const String& source, const KURL&,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist, PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
UserContentInjectedFrames); UserContentInjectedFrames,
UserStyleSheet::Level level = UserStyleSheet::UserLevel);
void removeUserScriptFromWorld(DOMWrapperWorld*, const KURL&); void removeUserScriptFromWorld(DOMWrapperWorld*, const KURL&);
void removeUserStyleSheetFromWorld(DOMWrapperWorld*, const KURL&); void removeUserStyleSheetFromWorld(DOMWrapperWorld*, const KURL&);
......
...@@ -37,14 +37,20 @@ namespace WebCore { ...@@ -37,14 +37,20 @@ namespace WebCore {
class UserStyleSheet : public Noncopyable { class UserStyleSheet : public Noncopyable {
public: public:
enum Level {
UserLevel,
AuthorLevel
};
UserStyleSheet(const String& source, const KURL& url, UserStyleSheet(const String& source, const KURL& url,
PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist, PassOwnPtr<Vector<String> > whitelist, PassOwnPtr<Vector<String> > blacklist,
UserContentInjectedFrames injectedFrames) UserContentInjectedFrames injectedFrames, Level level)
: m_source(source) : m_source(source)
, m_url(url) , m_url(url)
, m_whitelist(whitelist) , m_whitelist(whitelist)
, m_blacklist(blacklist) , m_blacklist(blacklist)
, m_injectedFrames(injectedFrames) , m_injectedFrames(injectedFrames)
, m_level(level)
{ {
} }
...@@ -53,6 +59,7 @@ public: ...@@ -53,6 +59,7 @@ public:
const Vector<String>* whitelist() const { return m_whitelist.get(); } const Vector<String>* whitelist() const { return m_whitelist.get(); }
const Vector<String>* blacklist() const { return m_blacklist.get(); } const Vector<String>* blacklist() const { return m_blacklist.get(); }
UserContentInjectedFrames injectedFrames() const { return m_injectedFrames; } UserContentInjectedFrames injectedFrames() const { return m_injectedFrames; }
Level level() const { return m_level; }
private: private:
String m_source; String m_source;
...@@ -60,6 +67,7 @@ private: ...@@ -60,6 +67,7 @@ private:
OwnPtr<Vector<String> > m_whitelist; OwnPtr<Vector<String> > m_whitelist;
OwnPtr<Vector<String> > m_blacklist; OwnPtr<Vector<String> > m_blacklist;
UserContentInjectedFrames m_injectedFrames; UserContentInjectedFrames m_injectedFrames;
Level m_level;
}; };
} // namespace WebCore } // namespace WebCore
......
2010-08-12 Aaron Boodman <aa@chromium.org>
Reviewed by David Hyatt.
Make the cascade level of "user" styles configurable
https://bugs.webkit.org/show_bug.cgi?id=43457
* src/WebViewImpl.cpp:
(WebKit::WebView::addUserStyleSheet):
2010-08-12 John Gregg <johnnyg@google.com> 2010-08-12 John Gregg <johnnyg@google.com>
Reviewed by Kent Tamura. Reviewed by Kent Tamura.
......
...@@ -1949,8 +1949,14 @@ void WebView::addUserStyleSheet(const WebString& sourceCode, ...@@ -1949,8 +1949,14 @@ void WebView::addUserStyleSheet(const WebString& sourceCode,
PageGroup* pageGroup = PageGroup::pageGroup(pageGroupName); PageGroup* pageGroup = PageGroup::pageGroup(pageGroupName);
RefPtr<DOMWrapperWorld> world(DOMWrapperWorld::create()); RefPtr<DOMWrapperWorld> world(DOMWrapperWorld::create());
// FIXME: Current callers always want the level to be "author". It probably makes sense to let
// callers specify this though, since in other cases the caller will probably want "user" level.
//
// FIXME: It would be nice to populate the URL correctly, instead of passing an empty URL.
pageGroup->addUserStyleSheetToWorld(world.get(), sourceCode, WebURL(), patterns.release(), 0, pageGroup->addUserStyleSheetToWorld(world.get(), sourceCode, WebURL(), patterns.release(), 0,
static_cast<UserContentInjectedFrames>(injectIn)); static_cast<UserContentInjectedFrames>(injectIn),
UserStyleSheet::AuthorLevel);
} }
void WebView::removeAllUserContent() void WebView::removeAllUserContent()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment