Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions runtime/src/main/jni/NetworkDomainCallbackHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <sstream>
#include "NetworkDomainCallbackHandlers.h"
#include "NativeScriptAssert.h"

using namespace tns;

Expand Down Expand Up @@ -48,14 +49,24 @@ void NetworkDomainCallbackHandlers::ResponseReceivedCallback(const v8::FunctionC
throw NativeScriptException("`response` parameter not in the correct format.");
}

auto responseJsonString = ArgConverter::ConvertToString(responseJson).c_str();
auto protocolResponseJson = protocol::parseJSON(responseJsonString);
auto responseJsonString = ArgConverter::ConvertToString(responseJson);
auto responseJsonCString = responseJsonString.c_str();
auto protocolResponseJson = protocol::parseJSON(responseJsonCString);

protocol::ErrorSupport errorSupport;

auto protocolResponseObj = protocol::Network::Response::parse(protocolResponseJson.get(),
&errorSupport);

auto errorString = errorSupport.errors().utf8();

if (!errorString.empty()) {
auto errorMessage = "Error while parsing debug `response` object. ";
DEBUG_WRITE_FORCE("%s Error: %s", errorMessage, errorString.c_str());

throw NativeScriptException(errorMessage + errorString);
}

auto requestIdString = ArgConverter::ConvertToString(requestId).c_str();
auto networkRequestData = new v8_inspector::utils::NetworkRequestData();
networkAgentInstance->m_responses.insert(std::make_pair(requestIdString, networkRequestData));
Expand Down Expand Up @@ -122,21 +133,31 @@ void NetworkDomainCallbackHandlers::RequestWillBeSentCallback(const v8::Function
throw NativeScriptException("`request` parameter not in the correct format.");
}

auto requestJsonString = ArgConverter::ConvertToString(requestJson).c_str();
auto protocolRequestJson = protocol::parseJSON(requestJsonString);
auto requestJsonString = ArgConverter::ConvertToString(requestJson);
auto requestJsonCString = requestJsonString.c_str();
auto protocolRequestJson = protocol::parseJSON(requestJsonCString);

protocol::ErrorSupport errorSupport;

auto protocolResponseObj = protocol::Network::Request::parse(protocolRequestJson.get(), &errorSupport);
auto protocolRequestObj = protocol::Network::Request::parse(protocolRequestJson.get(), &errorSupport);
auto initiator = protocol::Network::Initiator::create().setType(protocol::Network::Initiator::TypeEnum::Script).build();

auto errorString = errorSupport.errors().utf8();

if (!errorString.empty()) {
auto errorMessage = "Error while parsing debug `request` object. ";
DEBUG_WRITE_FORCE("%s Error: %s", errorMessage, errorString.c_str());

throw NativeScriptException(errorMessage + errorString);
}

protocol::Maybe<String16> type(ArgConverter::ConvertToString(typeArg).c_str());
protocol::Maybe<protocol::Network::Response> emptyRedirect;
networkAgentInstance->m_frontend.requestWillBeSent(ArgConverter::ConvertToString(requestId).c_str(),
FrameId,
LoaderId,
ArgConverter::ConvertToString(url).c_str(),
std::move(protocolResponseObj),
std::move(protocolRequestObj),
timeStamp,
std::move(initiator),
emptyRedirect,
Expand Down