mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Fix native image recreated on layout even if the view is not resized
Add InspectorBackendCommands.ts that is generated based on the API exposed by the web inspector frontend. Add implementation for the network domain and call events in the http-request module so that inspector frontend could visualize the network requests made by the module Fix tslint and doc comments
This commit is contained in:
2841
debugger/InspectorBackendCommands.ts
Normal file
2841
debugger/InspectorBackendCommands.ts
Normal file
File diff suppressed because it is too large
Load Diff
103
debugger/debugger.ts
Normal file
103
debugger/debugger.ts
Normal file
@ -0,0 +1,103 @@
|
||||
import definition = require("./InspectorBackendCommands");
|
||||
import http_request = require("http/http-request");
|
||||
|
||||
var resources_datas = [];
|
||||
|
||||
@definition.DomainDispatcher("Network")
|
||||
export class NetworkDomainDebugger implements definition.NetworkDomain.NetworkDomainDispatcher {
|
||||
private events: definition.NetworkDomain.NetworkFrontend;
|
||||
|
||||
constructor(dispatchMessage: (message: String) => void) {
|
||||
this.events = new definition.NetworkDomain.NetworkFrontend(dispatchMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables network tracking, network events will now be delivered to the client.
|
||||
*/
|
||||
enable(): void {
|
||||
http_request.domainDebugger = {
|
||||
"events": this.events,
|
||||
"resource_datas": resources_datas
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables network tracking, prevents network events from being sent to the client.
|
||||
*/
|
||||
disable(): void {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies whether to always send extra HTTP headers with the requests from this page.
|
||||
*/
|
||||
setExtraHTTPHeaders(params: definition.NetworkDomain.SetExtraHTTPHeadersMethodArguments): void {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns content served for the given request.
|
||||
*/
|
||||
getResponseBody(params: definition.NetworkDomain.GetResponseBodyMethodArguments): { body: string, base64Encoded: boolean } {
|
||||
var resource_data = resources_datas[params.requestId];
|
||||
var body = resource_data.hasTextContent ? NSString.alloc().initWithDataEncoding(resource_data.data, 4).toString() :
|
||||
resource_data.data.base64EncodedStringWithOptions(0);
|
||||
|
||||
if(resource_data) {
|
||||
return {
|
||||
body: body,
|
||||
base64Encoded: !resource_data.hasTextContent
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether clearing browser cache is supported.
|
||||
*/
|
||||
canClearBrowserCache(): { result: boolean } {
|
||||
return {
|
||||
result: false
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears browser cache.
|
||||
*/
|
||||
clearBrowserCache(): void {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether clearing browser cookies is supported.
|
||||
*/
|
||||
canClearBrowserCookies(): { result: boolean } {
|
||||
return {
|
||||
result: false
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears browser cookies.
|
||||
*/
|
||||
clearBrowserCookies(): void {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles ignoring cache for each request. If <code>true</code>, cache will not be used.
|
||||
*/
|
||||
setCacheDisabled(params: definition.NetworkDomain.SetCacheDisabledMethodArguments): void {
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a resource in the context of a frame on the inspected page without cross origin checks.
|
||||
*/
|
||||
loadResource(params: definition.NetworkDomain.LoadResourceMethodArguments): { content: string, mimeType: string, status: number } {
|
||||
return {
|
||||
content: "",
|
||||
mimeType: "",
|
||||
status: 200
|
||||
}
|
||||
}
|
||||
}
|
2
debugger/package.json
Normal file
2
debugger/package.json
Normal file
@ -0,0 +1,2 @@
|
||||
{ "name" : "debugger",
|
||||
"main" : "debugger.js" }
|
1
http/http-request.d.ts
vendored
1
http/http-request.d.ts
vendored
@ -3,5 +3,6 @@
|
||||
declare module "http/http-request" {
|
||||
import http = require("http");
|
||||
|
||||
export var domainDebugger: any;
|
||||
export var request: (options: http.HttpRequestOptions) => Promise<http.HttpResponse>;
|
||||
}
|
||||
|
@ -1,15 +1,26 @@
|
||||
/**
|
||||
* iOS specific http request implementation.
|
||||
*/
|
||||
|
||||
declare var __inspectorTimestamp;
|
||||
import http = require("http");
|
||||
|
||||
import * as types from "utils/types";
|
||||
import * as imageSourceModule from "image-source";
|
||||
import * as utilsModule from "utils/utils";
|
||||
import * as fsModule from "file-system";
|
||||
|
||||
import resource_data = require("./resource-data");
|
||||
import debuggerDomains = require("./../debugger/debugger");
|
||||
|
||||
var GET = "GET";
|
||||
var USER_AGENT_HEADER = "User-Agent";
|
||||
var USER_AGENT = "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25";
|
||||
var sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration();
|
||||
var queue = NSOperationQueue.mainQueue();
|
||||
var session = NSURLSession.sessionWithConfigurationDelegateDelegateQueue(sessionConfig, null, queue);
|
||||
|
||||
export var domainDebugger: any;
|
||||
|
||||
var utils: typeof utilsModule;
|
||||
function ensureUtils() {
|
||||
@ -29,10 +40,14 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
|
||||
return new Promise<http.HttpResponse>((resolve, reject) => {
|
||||
|
||||
try {
|
||||
var sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration();
|
||||
var queue = NSOperationQueue.mainQueue();
|
||||
var session = NSURLSession.sessionWithConfigurationDelegateDelegateQueue(
|
||||
sessionConfig, null, queue);
|
||||
// var sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration();
|
||||
// var queue = NSOperationQueue.mainQueue();
|
||||
// var session = NSURLSession.sessionWithConfigurationDelegateDelegateQueue(
|
||||
// sessionConfig, null, queue);
|
||||
|
||||
var requestId = Math.random().toString();
|
||||
var resourceData = new resource_data.ResourceData(requestId);
|
||||
domainDebugger.resource_datas[requestId] = resourceData;
|
||||
|
||||
var urlRequest = NSMutableURLRequest.requestWithURL(
|
||||
NSURL.URLWithString(options.url));
|
||||
@ -73,6 +88,27 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
|
||||
}
|
||||
}
|
||||
|
||||
domainDebugger.resource_datas[requestId].mimeType = response.MIMEType;
|
||||
domainDebugger.resource_datas[requestId].data = data;
|
||||
var debugResponse = {
|
||||
// Response URL. This URL can be different from CachedResource.url in case of redirect.
|
||||
url: options.url,
|
||||
// HTTP response status code.
|
||||
status: response.statusCode,
|
||||
// HTTP response status text.
|
||||
statusText: NSHTTPURLResponse.localizedStringForStatusCode(response.statusCode),
|
||||
// HTTP response headers.
|
||||
headers: headers,
|
||||
// HTTP response headers text.
|
||||
mimeType: response.MIMEType,
|
||||
fromDiskCache: false
|
||||
}
|
||||
|
||||
// Loader Identifier is hardcoded in the runtime and should be the same string
|
||||
// __inspectorTimestamp is provided by the runtime and returns a frontend friendly timestamp
|
||||
domainDebugger.events.responseReceived(requestId, "NativeScriptMainFrameIdentifier", "Loader Identifier", __inspectorTimestamp(), exports.domainDebugger.resource_datas[requestId].resourceType, debugResponse);
|
||||
domainDebugger.events.loadingFinished(requestId, __inspectorTimestamp());
|
||||
|
||||
resolve({
|
||||
content: {
|
||||
raw: data,
|
||||
@ -126,6 +162,16 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
|
||||
}
|
||||
});
|
||||
|
||||
if(options.url) {
|
||||
var request = {
|
||||
url: options.url,
|
||||
method: "GET",
|
||||
headers: options.headers
|
||||
};
|
||||
|
||||
domainDebugger.events.requestWillBeSent(requestId, "NativeScriptMainFrameIdentifier", "Loader Identifier", options.url, request, __inspectorTimestamp(), { type: 'Script' });
|
||||
}
|
||||
|
||||
dataTask.resume();
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
|
83
http/resource-data.ts
Normal file
83
http/resource-data.ts
Normal file
@ -0,0 +1,83 @@
|
||||
var documentTypeByMimeType = [];
|
||||
documentTypeByMimeType["text/xml"] = "Document";
|
||||
documentTypeByMimeType["text/plain"] = "Document";
|
||||
documentTypeByMimeType["text/html"] = "Document";
|
||||
documentTypeByMimeType["application/xml"] = "Document";
|
||||
documentTypeByMimeType["application/xhtml+xml"] = "Document";
|
||||
documentTypeByMimeType["text/css"] = "Stylesheet";
|
||||
documentTypeByMimeType["text/javascript"] = "Script";
|
||||
documentTypeByMimeType["text/ecmascript"] = "Script";
|
||||
documentTypeByMimeType["application/javascript"] = "Script";
|
||||
documentTypeByMimeType["application/ecmascript"] = "Script";
|
||||
documentTypeByMimeType["application/x-javascript"] = "Script";
|
||||
documentTypeByMimeType["application/json"] = "Script";
|
||||
documentTypeByMimeType["application/x-json"] = "Script";
|
||||
documentTypeByMimeType["text/x-javascript"] = "Script";
|
||||
documentTypeByMimeType["text/x-json"] = "Script";
|
||||
documentTypeByMimeType["text/typescript"] = "Script";
|
||||
|
||||
export class ResourceData {
|
||||
|
||||
private _requestID: string;
|
||||
private _resourceType: string;
|
||||
private _data: any;
|
||||
private _mimeType: string;
|
||||
|
||||
constructor(requestID: string) {
|
||||
this._requestID = requestID;
|
||||
}
|
||||
|
||||
get mimeType(): string {
|
||||
return this._mimeType;
|
||||
}
|
||||
|
||||
set mimeType(value: string) {
|
||||
if (this._mimeType !== value) {
|
||||
this._mimeType = value;
|
||||
|
||||
var resourceType = "Other";
|
||||
|
||||
if (this._mimeType in documentTypeByMimeType) {
|
||||
resourceType = documentTypeByMimeType[this._mimeType];
|
||||
}
|
||||
|
||||
if(this._mimeType.indexOf("image/") !== -1) {
|
||||
resourceType = "Image";
|
||||
}
|
||||
|
||||
if (this._mimeType.indexOf("font/") !== -1) {
|
||||
resourceType = "Font";
|
||||
}
|
||||
|
||||
this._resourceType = resourceType;
|
||||
}
|
||||
}
|
||||
|
||||
get requestID(): string {
|
||||
return this._requestID;
|
||||
}
|
||||
|
||||
get hasTextContent(): boolean {
|
||||
return [ "Document", "Stylesheet", "Script", "XHR" ].indexOf(this._resourceType) !== -1;
|
||||
}
|
||||
|
||||
get data(): any {
|
||||
return this._data;
|
||||
}
|
||||
|
||||
set data(value: any) {
|
||||
if (this._data !== value) {
|
||||
this._data = value;
|
||||
}
|
||||
}
|
||||
|
||||
get resourceType() {
|
||||
return this._resourceType;
|
||||
}
|
||||
|
||||
set resourceType(value: string) {
|
||||
if (this._resourceType !== value) {
|
||||
this._resourceType = value;
|
||||
}
|
||||
}
|
||||
}
|
@ -421,6 +421,8 @@
|
||||
"data/observable/observable.ts",
|
||||
"data/virtual-array/virtual-array.d.ts",
|
||||
"data/virtual-array/virtual-array.ts",
|
||||
"debugger/InspectorBackendCommands.ts",
|
||||
"debugger/debugger.ts",
|
||||
"declarations.android.d.ts",
|
||||
"declarations.d.ts",
|
||||
"declarations.ios.d.ts",
|
||||
@ -445,6 +447,7 @@
|
||||
"http/http-request.ios.ts",
|
||||
"http/http.d.ts",
|
||||
"http/http.ts",
|
||||
"http/resource-data.ts",
|
||||
"image-source/image-source-common.ts",
|
||||
"image-source/image-source.android.ts",
|
||||
"image-source/image-source.d.ts",
|
||||
|
Reference in New Issue
Block a user