Browse Source

support SCRIPT/LINK tags, make SCRIPT download JS source

master
Odilitime 5 years ago
parent
commit
a6d5d0feb6
  1. 4
      src/interfaces/components/ComponentBuilder.cpp
  2. 9
      src/interfaces/elements/LINKElement.cpp
  3. 12
      src/interfaces/elements/LINKElement.h
  4. 49
      src/interfaces/elements/SCRIPTElement.cpp
  5. 12
      src/interfaces/elements/SCRIPTElement.h

4
src/interfaces/components/ComponentBuilder.cpp

@ -12,6 +12,8 @@ @@ -12,6 +12,8 @@
#include "../elements/INPUTElement.h"
#include "../elements/BUTTONElement.h"
#include "../elements/TEXTAREAElement.h"
#include "../elements/SCRIPTElement.h"
#include "../elements/LINKElement.h"
#include "InputComponent.h"
#include "ButtonComponent.h"
@ -36,6 +38,8 @@ const std::unordered_map<std::string, std::shared_ptr<Element>> ComponentBuilder @@ -36,6 +38,8 @@ const std::unordered_map<std::string, std::shared_ptr<Element>> ComponentBuilder
{"textarea", std::make_shared<TEXTAREAElement>()},
{"button", std::make_shared<BUTTONElement>()},
{"b", std::make_shared<STRONGElement>()},
{"script", std::make_shared<SCRIPTElement>()},
{"link", std::make_shared<LINKElement>()},
{"i", std::make_shared<SPANElement>()}
};

9
src/interfaces/elements/LINKElement.cpp

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
#include "LINKElement.h"
std::unique_ptr<Component> LINKElement::renderer(const ElementRenderRequest &request) {
TagNode *tagNode = dynamic_cast<TagNode*>(request.node.get());
if (tagNode) {
}
return nullptr;
}

12
src/interfaces/elements/LINKElement.h

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
#ifndef LINKELEMENT_H
#define LINKELEMENT_H
#include "Element.h"
#include "../components/Component.h"
class LINKElement : public Element {
public:
virtual std::unique_ptr<Component> renderer(const ElementRenderRequest &request);
};
#endif

49
src/interfaces/elements/SCRIPTElement.cpp

@ -0,0 +1,49 @@ @@ -0,0 +1,49 @@
#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;
}

12
src/interfaces/elements/SCRIPTElement.h

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
#ifndef SCRIPTELEMENT_H
#define SCRIPTELEMENT_H
#include "Element.h"
#include "../components/Component.h"
class SCRIPTElement : public Element {
public:
virtual std::unique_ptr<Component> renderer(const ElementRenderRequest &request);
};
#endif
Loading…
Cancel
Save