You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
2.2 KiB

#include "SCRIPTElement.h"
#include "../components/DocumentComponent.h"
#include "../../WebResource.h"
#include "../../Log.h"
std::unique_ptr<Component> SCRIPTElement::renderer(const ElementRenderRequest &request) {
TagNode *tagNode = dynamic_cast<TagNode*>(request.node.get());
if (tagNode) {
//std::cout << "SCRIPTElement::renderer - start" << std::endl;
bool gotSource = false;
std::map<std::string, std::string>::const_iterator srcPair = tagNode->properties.find("src");
std::string source = "";
if (srcPair != tagNode->properties.end()) {
//std::cout << "SCRIPTElement::renderer - src: " << srcPair->second << std::endl;
URL uRequest = URL(srcPair->second);
//std::cout << "SCRIPTElement::renderer - srcURL: " << uRequest << std::endl;
//std::cout << "SCRIPTElement::renderer - bseURL: " << request.docComponent->currentURL << std::endl;
// ok download this URL
URL uScriptSrc = request.docComponent->currentURL.merge(uRequest);
//std::cout << "SCRIPTElement::renderer - Canonical: " << uScriptSrc << std::endl;
// download URL
WebResource res = getWebResource(uScriptSrc);
if (res.resourceType == ResourceType::INVALID) {
logError() << "SCRIPTElement::renderer - Invalid resource type: " << res.raw << std::endl;
} else {
//std::cout << "body: " << res.raw << std::endl;
//std::cout << "type: " << res.resourceType << std::endl;
source = res.raw;
gotSource = true;
}
}
if (request.node->children.size()) {
TextNode *textNode = dynamic_cast<TextNode*>(request.node->children.front().get());
if (textNode) {
//std::cout << "SCRIPTElement::renderer - source: " << textNode->text << std::endl;
source = textNode->text;
gotSource = true;
}
}
if (!gotSource) {
std::cout << "SCRIPTElement::renderer - no source!" << std::endl;
return nullptr;
}
// parse JS
//std::cout << "SCRIPTElement::renderer - source: " << source << std::endl;
}
return nullptr;
}