Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: mojo/public/js/codec.js

Issue 2796253002: Associated Message Validation (Closed)
Patch Set: Formatting. Add braces to if statements in validateMessageHeader Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/js/codec.js
diff --git a/mojo/public/js/codec.js b/mojo/public/js/codec.js
index ce58a8cfd4aea874d6b752d9f8efe47f28268037..e1cc0fe343533ac8947d10a5bc6993769ecb9706 100644
--- a/mojo/public/js/codec.js
+++ b/mojo/public/js/codec.js
@@ -5,13 +5,15 @@
define("mojo/public/js/codec", [
"mojo/public/js/buffer",
"mojo/public/js/interface_types",
+ "mojo/public/js/lib/interface_endpoint_handle",
"mojo/public/js/unicode",
-], function(buffer, types, unicode) {
+], function(buffer, types, interfaceEndpointHandle, unicode) {
var kErrorUnsigned = "Passing negative value to unsigned";
var kErrorArray = "Passing non Array for array type";
var kErrorString = "Passing non String for string type";
var kErrorMap = "Passing non Map for map type";
+ var InterfaceEndpointHandle = interfaceEndpointHandle.InterfaceEndpointHandle;
// Memory -------------------------------------------------------------------
@@ -29,12 +31,14 @@ define("mojo/public/js/codec", [
var kArrayHeaderSize = 8;
var kStructHeaderSize = 8;
- var kMessageHeaderSize = 24;
- var kMessageWithRequestIDHeaderSize = 32;
+ var kMessageV0HeaderSize = 24;
+ var kMessageV1HeaderSize = 32;
+ var kMessageV2HeaderSize = 48;
var kMapStructPayloadSize = 16;
var kStructHeaderNumBytesOffset = 0;
var kStructHeaderVersionOffset = 4;
+ var kMessagePayloadInterfaceIdsPointerOffset = kMessageV2HeaderSize - 8;
yzshen1 2017/04/12 00:50:33 Please move this line to be below line 434
wangjimmy 2017/04/12 18:58:25 Done.
var kEncodedInvalidHandleValue = 0xFFFFFFFF;
@@ -457,6 +461,17 @@ define("mojo/public/js/codec", [
return this.buffer.getUint32(kMessageInterfaceIdOffset);
};
+ Message.prototype.getPayloadInterfaceIds = function() {
+ if (this.getHeaderVersion() < 2) {
+ return null;
+ }
+
+ var decoder = new Decoder(this.buffer, this.handles,
+ kMessagePayloadInterfaceIdsPointerOffset);
+ var payloadInterfaceIds = decoder.decodeArrayPointer(Uint32);
+ return payloadInterfaceIds;
+ };
+
Message.prototype.isResponse = function() {
return (this.getFlags() & kMessageIsResponse) != 0;
};
@@ -480,11 +495,11 @@ define("mojo/public/js/codec", [
function MessageBuilder(messageName, payloadSize) {
// Currently, we don't compute the payload size correctly ahead of time.
// Instead, we resize the buffer at the end.
- var numberOfBytes = kMessageHeaderSize + payloadSize;
+ var numberOfBytes = kMessageV0HeaderSize + payloadSize;
this.buffer = new buffer.Buffer(numberOfBytes);
this.handles = [];
- var encoder = this.createEncoder(kMessageHeaderSize);
- encoder.writeUint32(kMessageHeaderSize);
+ var encoder = this.createEncoder(kMessageV0HeaderSize);
+ encoder.writeUint32(kMessageV0HeaderSize);
encoder.writeUint32(0); // version.
encoder.writeUint32(0); // interface ID.
encoder.writeUint32(messageName);
@@ -518,11 +533,11 @@ define("mojo/public/js/codec", [
requestID) {
// Currently, we don't compute the payload size correctly ahead of time.
// Instead, we resize the buffer at the end.
- var numberOfBytes = kMessageWithRequestIDHeaderSize + payloadSize;
+ var numberOfBytes = kMessageV1HeaderSize + payloadSize;
this.buffer = new buffer.Buffer(numberOfBytes);
this.handles = [];
- var encoder = this.createEncoder(kMessageWithRequestIDHeaderSize);
- encoder.writeUint32(kMessageWithRequestIDHeaderSize);
+ var encoder = this.createEncoder(kMessageV1HeaderSize);
+ encoder.writeUint32(kMessageV1HeaderSize);
encoder.writeUint32(1); // version.
encoder.writeUint32(0); // interface ID.
encoder.writeUint32(messageName);
@@ -838,6 +853,17 @@ define("mojo/public/js/codec", [
NullableInterface.prototype = Object.create(Interface.prototype);
+ function AssociatedInterfacePtrInfo() {
+ }
+
+ AssociatedInterfacePtrInfo.prototype.encodedSize = 8;
+
+ function NullableAssociatedInterfacePtrInfo() {
+ }
+
+ NullableAssociatedInterfacePtrInfo.encodedSize =
+ AssociatedInterfacePtrInfo.encodedSize;
+
function InterfaceRequest() {
}
@@ -860,6 +886,17 @@ define("mojo/public/js/codec", [
NullableInterfaceRequest.encode = InterfaceRequest.encode;
+ function AssociatedInterfaceRequest() {
+ }
+
+ AssociatedInterfaceRequest.encodedSize = 4;
+
+ function NullableAssociatedInterfaceRequest() {
+ }
+
+ NullableAssociatedInterfaceRequest.encodedSize =
+ AssociatedInterfaceRequest.encodedSize;
+
function MapOf(keyClass, valueClass) {
this.keyClass = keyClass;
this.valueClass = valueClass;
@@ -892,8 +929,11 @@ define("mojo/public/js/codec", [
exports.kMapStructPayloadSize = kMapStructPayloadSize;
exports.kStructHeaderSize = kStructHeaderSize;
exports.kEncodedInvalidHandleValue = kEncodedInvalidHandleValue;
- exports.kMessageHeaderSize = kMessageHeaderSize;
- exports.kMessageWithRequestIDHeaderSize = kMessageWithRequestIDHeaderSize;
+ exports.kMessageV0HeaderSize = kMessageV0HeaderSize;
+ exports.kMessageV1HeaderSize = kMessageV1HeaderSize;
+ exports.kMessageV2HeaderSize = kMessageV2HeaderSize;
+ exports.kMessagePayloadInterfaceIdsPointerOffset =
yzshen1 2017/04/12 00:50:33 Is it necessary to export this value?
wangjimmy 2017/04/12 18:58:25 Yes, I use it as the offset for validateArrayPoint
+ kMessagePayloadInterfaceIdsPointerOffset;
exports.kMessageExpectsResponse = kMessageExpectsResponse;
exports.kMessageIsResponse = kMessageIsResponse;
exports.Int8 = Int8;
@@ -920,6 +960,12 @@ define("mojo/public/js/codec", [
exports.NullableInterface = NullableInterface;
exports.InterfaceRequest = InterfaceRequest;
exports.NullableInterfaceRequest = NullableInterfaceRequest;
+ exports.AssociatedInterfacePtrInfo = AssociatedInterfacePtrInfo;
+ exports.NullableAssociatedInterfacePtrInfo =
+ NullableAssociatedInterfacePtrInfo;
+ exports.AssociatedInterfaceRequest = AssociatedInterfaceRequest;
+ exports.NullableAssociatedInterfaceRequest =
+ NullableAssociatedInterfaceRequest;
exports.MapOf = MapOf;
exports.NullableMapOf = NullableMapOf;
return exports;

Powered by Google App Engine
This is Rietveld 408576698