Task(ImageLoader* loader, UpdateFromElementBehavior updateBehavior) : m_loader(loader) , m_shouldBypassMainWorldCSP(shouldBypassMainWorldCSP(loader)) , m_updateBehavior(updateBehavior) , m_weakFactory(this) { v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); v8::HandleScope scope(isolate); // If we're invoked from C++ without a V8 context on the stack, we should // run the microtask in the context of the element's document's main world. if (ScriptState::hasCurrentScriptState(isolate)) m_scriptState = ScriptState::current(isolate); else m_scriptState = ScriptState::forMainWorld(loader->element()->document().frame()); }
StyleElement::ProcessingResult StyleElement::createSheet(Element& element, const String& text) { DCHECK(element.isConnected()); Document& document = element.document(); const ContentSecurityPolicy* csp = document.contentSecurityPolicy(); bool passesContentSecurityPolicyChecks = shouldBypassMainWorldCSP(element) || csp->allowStyleWithHash(text, ContentSecurityPolicy::InlineType::Block) || csp->allowInlineStyle(&element, document.url(), element.fastGetAttribute(HTMLNames::nonceAttr), m_startPosition.m_line, text); // Clearing the current sheet may remove the cache entry so create the new // sheet first CSSStyleSheet* newSheet = nullptr; // If type is empty or CSS, this is a CSS style sheet. const AtomicString& type = this->type(); if (isCSS(element, type) && passesContentSecurityPolicyChecks) { MediaQuerySet* mediaQueries = MediaQuerySet::create(media()); MediaQueryEvaluator screenEval("screen"); MediaQueryEvaluator printEval("print"); if (screenEval.eval(mediaQueries) || printEval.eval(mediaQueries)) { m_loading = true; TextPosition startPosition = m_startPosition == TextPosition::belowRangePosition() ? TextPosition::minimumPosition() : m_startPosition; newSheet = document.styleEngine().createSheet( element, text, startPosition, m_styleEngineContext); newSheet->setMediaQueries(mediaQueries); m_loading = false; } } if (m_sheet) clearSheet(element); m_sheet = newSheet; if (m_sheet) m_sheet->contents()->checkLoaded(); return passesContentSecurityPolicyChecks ? ProcessingSuccessful : ProcessingFatalError; }
Task(ImageLoader* loader, UpdateFromElementBehavior updateBehavior, ReferrerPolicy referrerPolicy) : m_loader(loader), m_shouldBypassMainWorldCSP(shouldBypassMainWorldCSP(loader)), m_updateBehavior(updateBehavior), m_weakFactory(this), m_referrerPolicy(referrerPolicy) { ExecutionContext& context = m_loader->element()->document(); InspectorInstrumentation::asyncTaskScheduled(&context, "Image", this); v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); v8::HandleScope scope(isolate); // If we're invoked from C++ without a V8 context on the stack, we should // run the microtask in the context of the element's document's main world. if (ScriptState::hasCurrentScriptState(isolate)) { m_scriptState = ScriptState::current(isolate); } else { m_scriptState = ScriptState::forMainWorld(loader->element()->document().frame()); DCHECK(m_scriptState); } m_requestURL = loader->imageSourceToKURL(loader->element()->imageSourceURL()); }