#ifndef InspectorCSSAgent_h
#define InspectorCSSAgent_h
#include "core/css/CSSSelector.h"
#include "core/dom/SecurityContext.h"
#include "core/frame/csp/ContentSecurityPolicy.h"
#include "core/inspector/InspectorBaseAgent.h"
#include "core/inspector/InspectorDOMAgent.h"
#include "core/inspector/InspectorStyleSheet.h"
#include "platform/JSONValues.h"
#include "wtf/HashCountedSet.h"
#include "wtf/HashMap.h"
#include "wtf/HashSet.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefPtr.h"
#include "wtf/Vector.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
struct CSSParserString;
class CSSRule;
class CSSRuleList;
class CSSStyleRule;
class CSSStyleSheet;
class Document;
class Element;
class InspectorFrontend;
class InspectorResourceAgent;
class InstrumentingAgents;
class MediaList;
class Node;
class NodeList;
class PlatformFontUsage;
class RenderText;
class StyleResolver;
class InspectorCSSAgent FINAL
: public InspectorBaseAgent<InspectorCSSAgent>
, public InspectorDOMAgent::DOMListener
, public InspectorBackendDispatcher::CSSCommandHandler
, public InspectorStyleSheetBase::Listener {
WTF_MAKE_NONCOPYABLE(InspectorCSSAgent);
public:
enum MediaListSource {
MediaListSourceLinkedSheet,
MediaListSourceInlineSheet,
MediaListSourceMediaRule,
MediaListSourceImportRule
};
enum StyleSheetsUpdateType {
InitialFrontendLoad = 0,
ExistingFrontendRefresh,
};
class InlineStyleOverrideScope {
public:
InlineStyleOverrideScope(SecurityContext* context)
: m_contentSecurityPolicy(context->contentSecurityPolicy())
{
m_contentSecurityPolicy->setOverrideAllowInlineStyle(true);
}
~InlineStyleOverrideScope()
{
m_contentSecurityPolicy->setOverrideAllowInlineStyle(false);
}
private:
ContentSecurityPolicy* m_contentSecurityPolicy;
};
static CSSStyleRule* asCSSStyleRule(CSSRule*);
static PassOwnPtr<InspectorCSSAgent> create(InspectorDOMAgent* domAgent, InspectorPageAgent* pageAgent, InspectorResourceAgent* resourceAgent)
{
return adoptPtr(new InspectorCSSAgent(domAgent, pageAgent, resourceAgent));
}
virtual ~InspectorCSSAgent();
bool forcePseudoState(Element*, CSSSelector::PseudoType);
virtual void setFrontend(InspectorFrontend*) OVERRIDE;
virtual void clearFrontend() OVERRIDE;
virtual void discardAgent() OVERRIDE;
virtual void didCommitLoadForMainFrame() OVERRIDE;
virtual void restore() OVERRIDE;
virtual void flushPendingFrontendMessages() OVERRIDE;
virtual void enable(ErrorString*, PassRefPtr<EnableCallback>) OVERRIDE;
virtual void disable(ErrorString*) OVERRIDE;
void reset();
void mediaQueryResultChanged();
void willMutateRules();
void didMutateRules(CSSStyleSheet*);
void willMutateStyle();
void didMutateStyle(CSSStyleDeclaration*, bool);
void activeStyleSheetsUpdated(Document*);
void documentDetached(Document*);
virtual void getComputedStyleForNode(ErrorString*, int nodeId, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> >&) OVERRIDE;
virtual void getPlatformFontsForNode(ErrorString*, int nodeId, String* cssFamilyName, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::PlatformFontUsage> >&) OVERRIDE;
virtual void getInlineStylesForNode(ErrorString*, int nodeId, RefPtr<TypeBuilder::CSS::CSSStyle>& inlineStyle, RefPtr<TypeBuilder::CSS::CSSStyle>& attributes) OVERRIDE;
virtual void getMatchedStylesForNode(ErrorString*, int nodeId, const bool* includePseudo, const bool* includeInherited, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> >& matchedCSSRules, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::PseudoIdMatches> >&, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::InheritedStyleEntry> >& inheritedEntries) OVERRIDE;
virtual void getStyleSheetText(ErrorString*, const String& styleSheetId, String* result) OVERRIDE;
virtual void setStyleSheetText(ErrorString*, const String& styleSheetId, const String& text) OVERRIDE;
virtual void setPropertyText(ErrorString*, const String& styleSheetId, const RefPtr<JSONObject>& range, const String& text, RefPtr<TypeBuilder::CSS::CSSStyle>& result) OVERRIDE;
virtual void setRuleSelector(ErrorString*, const RefPtr<JSONObject>& ruleId, const String& selector, RefPtr<TypeBuilder::CSS::CSSRule>& result) OVERRIDE;
virtual void createStyleSheet(ErrorString*, const String& frameId, TypeBuilder::CSS::StyleSheetId* outStyleSheetId) OVERRIDE;
virtual void addRule(ErrorString*, const String& styleSheetId, const String& selector, RefPtr<TypeBuilder::CSS::CSSRule>& result) OVERRIDE;
virtual void forcePseudoState(ErrorString*, int nodeId, const RefPtr<JSONArray>& forcedPseudoClasses) OVERRIDE;
PassRefPtr<TypeBuilder::CSS::CSSMedia> buildMediaObject(const MediaList*, MediaListSource, const String&, CSSStyleSheet*);
PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSMedia> > buildMediaListChain(CSSRule*);
private:
class StyleSheetAction;
class SetStyleSheetTextAction;
class SetPropertyTextAction;
class SetRuleSelectorAction;
class AddRuleAction;
class EnableResourceClient;
InspectorCSSAgent(InspectorDOMAgent*, InspectorPageAgent*, InspectorResourceAgent*);
typedef HashMap<String, RefPtr<InspectorStyleSheet> > IdToInspectorStyleSheet;
typedef HashMap<String, RefPtr<InspectorStyleSheetForInlineStyle> > IdToInspectorStyleSheetForInlineStyle;
typedef HashMap<Node*, RefPtr<InspectorStyleSheetForInlineStyle> > NodeToInspectorStyleSheet;
typedef HashMap<int, unsigned> NodeIdToForcedPseudoState;
void wasEnabled(PassRefPtr<EnableCallback>);
void resetNonPersistentData();
InspectorStyleSheetForInlineStyle* asInspectorStyleSheet(Element* element);
Element* elementForId(ErrorString*, int nodeId);
void collectAllStyleSheets(Vector<InspectorStyleSheet*>&);
void collectAllDocumentStyleSheets(Document*, Vector<CSSStyleSheet*>&);
void collectStyleSheets(CSSStyleSheet*, Vector<CSSStyleSheet*>&);
void updateActiveStyleSheets(Document*, StyleSheetsUpdateType);
void setActiveStyleSheets(Document*, const Vector<CSSStyleSheet*>&, StyleSheetsUpdateType);
void collectPlatformFontsForRenderer(RenderText*, HashCountedSet<String>*);
InspectorStyleSheet* bindStyleSheet(CSSStyleSheet*);
String unbindStyleSheet(InspectorStyleSheet*);
InspectorStyleSheet* viaInspectorStyleSheet(Document*, bool createIfAbsent);
InspectorStyleSheet* assertInspectorStyleSheetForId(ErrorString*, const String&);
InspectorStyleSheetBase* assertStyleSheetForId(ErrorString*, const String&);
TypeBuilder::CSS::StyleSheetOrigin::Enum detectOrigin(CSSStyleSheet* pageStyleSheet, Document* ownerDocument);
bool styleSheetEditInProgress() const { return m_styleSheetsPendingMutation || m_styleDeclarationPendingMutation || m_isSettingStyleSheetText; }
PassRefPtr<TypeBuilder::CSS::CSSRule> buildObjectForRule(CSSStyleRule*);
PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > buildArrayForMatchedRuleList(CSSRuleList*, Element*);
PassRefPtr<TypeBuilder::CSS::CSSStyle> buildObjectForAttributesStyle(Element*);
virtual void didRemoveDocument(Document*) OVERRIDE;
virtual void didRemoveDOMNode(Node*) OVERRIDE;
virtual void didModifyDOMAttr(Element*) OVERRIDE;
virtual void styleSheetChanged(InspectorStyleSheetBase*) OVERRIDE;
virtual void willReparseStyleSheet() OVERRIDE;
virtual void didReparseStyleSheet() OVERRIDE;
void resetPseudoStates();
InspectorFrontend::CSS* m_frontend;
InspectorDOMAgent* m_domAgent;
InspectorPageAgent* m_pageAgent;
InspectorResourceAgent* m_resourceAgent;
IdToInspectorStyleSheet m_idToInspectorStyleSheet;
IdToInspectorStyleSheetForInlineStyle m_idToInspectorStyleSheetForInlineStyle;
HashMap<CSSStyleSheet*, RefPtr<InspectorStyleSheet> > m_cssStyleSheetToInspectorStyleSheet;
typedef HashMap<Document*, OwnPtr<HashSet<CSSStyleSheet*> > > DocumentStyleSheets;
DocumentStyleSheets m_documentToCSSStyleSheets;
HashSet<Document*> m_invalidatedDocuments;
NodeToInspectorStyleSheet m_nodeToInspectorStyleSheet;
HashMap<RefPtr<Document>, RefPtr<InspectorStyleSheet> > m_documentToViaInspectorStyleSheet;
NodeIdToForcedPseudoState m_nodeIdToForcedPseudoState;
RefPtrWillBePersistent<CSSStyleSheet> m_inspectorUserAgentStyleSheet;
int m_lastStyleSheetId;
int m_styleSheetsPendingMutation;
bool m_styleDeclarationPendingMutation;
bool m_creatingViaInspectorStyleSheet;
bool m_isSettingStyleSheetText;
friend class EnableResourceClient;
friend class StyleSheetBinder;
};
}
#endif