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.

SCRIPTElement.cpp 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "SCRIPTElement.h"
  2. #include "../components/DocumentComponent.h"
  3. #include "../../WebResource.h"
  4. #include "../../Log.h"
  5. std::unique_ptr<Component> SCRIPTElement::renderer(const ElementRenderRequest &request) {
  6. TagNode *tagNode = dynamic_cast<TagNode*>(request.node.get());
  7. if (tagNode) {
  8. //std::cout << "SCRIPTElement::renderer - start" << std::endl;
  9. bool gotSource = false;
  10. std::map<std::string, std::string>::const_iterator srcPair = tagNode->properties.find("src");
  11. std::string source = "";
  12. if (srcPair != tagNode->properties.end()) {
  13. //std::cout << "SCRIPTElement::renderer - src: " << srcPair->second << std::endl;
  14. URL uRequest = URL(srcPair->second);
  15. //std::cout << "SCRIPTElement::renderer - srcURL: " << uRequest << std::endl;
  16. //std::cout << "SCRIPTElement::renderer - bseURL: " << request.docComponent->currentURL << std::endl;
  17. // ok download this URL
  18. URL uScriptSrc = request.docComponent->currentURL.merge(uRequest);
  19. //std::cout << "SCRIPTElement::renderer - Canonical: " << uScriptSrc << std::endl;
  20. // download URL
  21. WebResource res = getWebResource(uScriptSrc);
  22. if (res.resourceType == ResourceType::INVALID) {
  23. logError() << "SCRIPTElement::renderer - Invalid resource type: " << res.raw << std::endl;
  24. } else {
  25. //std::cout << "body: " << res.raw << std::endl;
  26. //std::cout << "type: " << res.resourceType << std::endl;
  27. source = res.raw;
  28. gotSource = true;
  29. }
  30. }
  31. if (request.node->children.size()) {
  32. TextNode *textNode = dynamic_cast<TextNode*>(request.node->children.front().get());
  33. if (textNode) {
  34. //std::cout << "SCRIPTElement::renderer - source: " << textNode->text << std::endl;
  35. source = textNode->text;
  36. gotSource = true;
  37. }
  38. }
  39. if (!gotSource) {
  40. std::cout << "SCRIPTElement::renderer - no source!" << std::endl;
  41. return nullptr;
  42. }
  43. // parse JS
  44. //std::cout << "SCRIPTElement::renderer - source: " << source << std::endl;
  45. }
  46. return nullptr;
  47. }