static JSValueRef getResourceDocumentNode(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/) { JSValueRef undefined = JSValueMakeUndefined(ctx); InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject)); if (!argumentCount || argumentCount > 1 || !controller) return undefined; JSValueRef identifierValue = arguments[0]; if (!JSValueIsNumber(ctx, identifierValue)) return undefined; unsigned long identifier = static_cast<unsigned long>(JSValueToNumber(ctx, identifierValue, 0)); RefPtr<InspectorResource> resource = controller->resources().get(identifier); ASSERT(resource); if (!resource) return undefined; FrameLoader* frameLoader = resource->loader->frameLoader(); if (!frameLoader) return undefined; Document* document = frameLoader->frame()->document(); if (!document) return undefined; if (document->isPluginDocument() || document->isImageDocument()) return undefined; KJS::JSLock lock; JSValueRef documentValue = toRef(toJS(toJS(controller->scriptContext()), document)); return documentValue; }
Type type() const { if (requestURL == loader->requestURL()) return Doc; FrameLoader* frameLoader = loader->frameLoader(); if (!frameLoader) return Other; if (requestURL == frameLoader->iconURL()) return Image; Document* doc = frameLoader->frame()->document(); if (!doc) return Other; CachedResource* cachedResource = doc->docLoader()->cachedResource(requestURL.url()); if (!cachedResource) return Other; switch (cachedResource->type()) { case CachedResource::ImageResource: return Image; case CachedResource::CSSStyleSheet: #if ENABLE(XSLT) case CachedResource::XSLStyleSheet: #endif return Stylesheet; case CachedResource::Script: return Script; default: return Other; } }
Frame* ResourceLoader::getFrame() { Frame* retVal = NULL; FrameLoader* pFrameLoader = frameLoader(); if(pFrameLoader != NULL) { retVal = pFrameLoader->frame(); } return retVal; }
static JSValueRef addSourceToFrame(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* /*exception*/) { JSValueRef undefined = JSValueMakeUndefined(ctx); InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject)); if (argumentCount < 2 || !controller) return undefined; JSValueRef identifierValue = arguments[0]; if (!JSValueIsNumber(ctx, identifierValue)) return undefined; unsigned long identifier = static_cast<unsigned long>(JSValueToNumber(ctx, identifierValue, 0)); RefPtr<InspectorResource> resource = controller->resources().get(identifier); ASSERT(resource); if (!resource) return undefined; RefPtr<SharedBuffer> buffer; if (resource->requestURL == resource->loader->requestURL()) buffer = resource->loader->mainResourceData(); else { FrameLoader* frameLoader = resource->loader->frameLoader(); if (!frameLoader) return undefined; Document* doc = frameLoader->frame()->document(); if (!doc) return undefined; CachedResource* cachedResource = doc->docLoader()->cachedResource(resource->requestURL.url()); if (!cachedResource) return undefined; buffer = cachedResource->data(); } if (!buffer) return undefined; String textEncodingName = resource->loader->overrideEncoding(); if (!textEncodingName) textEncodingName = resource->textEncodingName; TextEncoding encoding(textEncodingName); if (!encoding.isValid()) encoding = WindowsLatin1Encoding(); String sourceString = encoding.decode(buffer->data(), buffer->size()); Node* node = toNode(toJS(arguments[1])); ASSERT(node); if (!node) return undefined; if (!node->attached()) { ASSERT_NOT_REACHED(); return undefined; } ASSERT(node->isElementNode()); if (!node->isElementNode()) return undefined; Element* element = static_cast<Element*>(node); ASSERT(element->isFrameOwnerElement()); if (!element->isFrameOwnerElement()) return undefined; HTMLFrameOwnerElement* frameOwner = static_cast<HTMLFrameOwnerElement*>(element); ASSERT(frameOwner->contentFrame()); if (!frameOwner->contentFrame()) return undefined; FrameLoader* loader = frameOwner->contentFrame()->loader(); loader->setResponseMIMEType(resource->mimeType); loader->begin(); loader->write(sourceString); loader->end(); return undefined; }