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:
Panayot Cankov
2015-12-03 16:53:25 +02:00
parent dcd389e0de
commit 1ec28cbe98
7 changed files with 3083 additions and 4 deletions

File diff suppressed because it is too large Load Diff

103
debugger/debugger.ts Normal file
View 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
View File

@ -0,0 +1,2 @@
{ "name" : "debugger",
"main" : "debugger.js" }

View File

@ -3,5 +3,6 @@
declare module "http/http-request" { declare module "http/http-request" {
import http = require("http"); import http = require("http");
export var domainDebugger: any;
export var request: (options: http.HttpRequestOptions) => Promise<http.HttpResponse>; export var request: (options: http.HttpRequestOptions) => Promise<http.HttpResponse>;
} }

View File

@ -1,15 +1,26 @@
/** /**
* iOS specific http request implementation. * iOS specific http request implementation.
*/ */
declare var __inspectorTimestamp;
import http = require("http"); import http = require("http");
import * as types from "utils/types"; import * as types from "utils/types";
import * as imageSourceModule from "image-source"; import * as imageSourceModule from "image-source";
import * as utilsModule from "utils/utils"; import * as utilsModule from "utils/utils";
import * as fsModule from "file-system"; import * as fsModule from "file-system";
import resource_data = require("./resource-data");
import debuggerDomains = require("./../debugger/debugger");
var GET = "GET"; var GET = "GET";
var USER_AGENT_HEADER = "User-Agent"; 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 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; var utils: typeof utilsModule;
function ensureUtils() { function ensureUtils() {
@ -29,10 +40,14 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
return new Promise<http.HttpResponse>((resolve, reject) => { return new Promise<http.HttpResponse>((resolve, reject) => {
try { try {
var sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration(); // var sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration();
var queue = NSOperationQueue.mainQueue(); // var queue = NSOperationQueue.mainQueue();
var session = NSURLSession.sessionWithConfigurationDelegateDelegateQueue( // var session = NSURLSession.sessionWithConfigurationDelegateDelegateQueue(
sessionConfig, null, queue); // sessionConfig, null, queue);
var requestId = Math.random().toString();
var resourceData = new resource_data.ResourceData(requestId);
domainDebugger.resource_datas[requestId] = resourceData;
var urlRequest = NSMutableURLRequest.requestWithURL( var urlRequest = NSMutableURLRequest.requestWithURL(
NSURL.URLWithString(options.url)); 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({ resolve({
content: { content: {
raw: data, 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(); dataTask.resume();
} catch (ex) { } catch (ex) {
reject(ex); reject(ex);

83
http/resource-data.ts Normal file
View 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;
}
}
}

View File

@ -421,6 +421,8 @@
"data/observable/observable.ts", "data/observable/observable.ts",
"data/virtual-array/virtual-array.d.ts", "data/virtual-array/virtual-array.d.ts",
"data/virtual-array/virtual-array.ts", "data/virtual-array/virtual-array.ts",
"debugger/InspectorBackendCommands.ts",
"debugger/debugger.ts",
"declarations.android.d.ts", "declarations.android.d.ts",
"declarations.d.ts", "declarations.d.ts",
"declarations.ios.d.ts", "declarations.ios.d.ts",
@ -445,6 +447,7 @@
"http/http-request.ios.ts", "http/http-request.ios.ts",
"http/http.d.ts", "http/http.d.ts",
"http/http.ts", "http/http.ts",
"http/resource-data.ts",
"image-source/image-source-common.ts", "image-source/image-source-common.ts",
"image-source/image-source.android.ts", "image-source/image-source.android.ts",
"image-source/image-source.d.ts", "image-source/image-source.d.ts",