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

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

Issue 424463003: Basic Mojo message header validation for JavaScript. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make claimRange() consistent with isValidRange() Created 6 years, 5 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
« no previous file with comments | « extensions/renderer/dispatcher.cc ('k') | mojo/public/js/bindings/constants.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/js/bindings/codec.js
diff --git a/mojo/public/js/bindings/codec.js b/mojo/public/js/bindings/codec.js
index dca6009071d01a724845d27d8f2dfa9b3f969bc5..9365dd2fba12105eba61b6ea65725e542bb66a4c 100644
--- a/mojo/public/js/bindings/codec.js
+++ b/mojo/public/js/bindings/codec.js
@@ -17,6 +17,10 @@ define("mojo/public/js/bindings/codec", [
return size + (kAlignment - (size % kAlignment)) % kAlignment;
}
+ function isAligned(offset) {
+ return offset >= 0 && (offset % kAlignment) === 0;
+ }
+
// Constants ----------------------------------------------------------------
var kArrayHeaderSize = 8;
@@ -24,6 +28,9 @@ define("mojo/public/js/bindings/codec", [
var kMessageHeaderSize = 16;
var kMessageWithRequestIDHeaderSize = 24;
+ var kStructHeaderNumBytesOffset = 0;
+ var kStructHeaderNumFieldsOffset = 4;
+
// Decoder ------------------------------------------------------------------
function Decoder(buffer, handles, base) {
@@ -141,7 +148,7 @@ define("mojo/public/js/bindings/codec", [
var val = new Array(numberOfElements);
var byte;
for (var i = 0; i < numberOfElements; ++i) {
- if (i % 8 == 0)
+ if (i % 8 === 0)
byte = this.readUint8();
val[i] = (byte & (1 << i % 8)) ? true : false;
}
@@ -352,29 +359,44 @@ define("mojo/public/js/bindings/codec", [
// Message ------------------------------------------------------------------
+ var kMessageNameOffset = kStructHeaderSize;
+ var kMessageFlagsOffset = kMessageNameOffset + 4;
+ var kMessageRequestIDOffset = kMessageFlagsOffset + 4;
+
var kMessageExpectsResponse = 1 << 0;
var kMessageIsResponse = 1 << 1;
- // Skip over num_bytes, num_fields, and message_name.
- var kFlagsOffset = 4 + 4 + 4;
-
- // Skip over num_bytes, num_fields, message_name, and flags.
- var kRequestIDOffset = 4 + 4 + 4 + 4;
-
function Message(buffer, handles) {
this.buffer = buffer;
this.handles = handles;
}
- Message.prototype.setRequestID = function(requestID) {
- // TODO(darin): Verify that space was reserved for this field!
- this.buffer.setUint64(kRequestIDOffset, requestID);
+ Message.prototype.getHeaderNumBytes = function() {
+ return this.buffer.getUint32(kStructHeaderNumBytesOffset);
+ };
+
+ Message.prototype.getHeaderNumFields = function() {
+ return this.buffer.getUint32(kStructHeaderNumFieldsOffset);
};
Message.prototype.getFlags = function() {
- return this.buffer.getUint32(kFlagsOffset);
+ return this.buffer.getUint32(kMessageFlagsOffset);
};
+ Message.prototype.isResponse = function() {
+ return (this.getFlags() & kMessageIsResponse) != 0;
+ };
+
+ Message.prototype.expectsResponse = function() {
+ return (this.getFlags() & kMessageExpectsResponse) != 0;
+ };
+
+ Message.prototype.setRequestID = function(requestID) {
+ // TODO(darin): Verify that space was reserved for this field!
+ this.buffer.setUint64(kMessageRequestIDOffset, requestID);
+ };
+
+
// MessageBuilder -----------------------------------------------------------
function MessageBuilder(messageName, payloadSize) {
@@ -666,6 +688,7 @@ define("mojo/public/js/bindings/codec", [
var exports = {};
exports.align = align;
+ exports.isAligned = isAligned;
exports.Message = Message;
exports.MessageBuilder = MessageBuilder;
exports.MessageWithRequestIDBuilder = MessageWithRequestIDBuilder;
@@ -673,6 +696,7 @@ define("mojo/public/js/bindings/codec", [
exports.kArrayHeaderSize = kArrayHeaderSize;
exports.kStructHeaderSize = kStructHeaderSize;
exports.kMessageHeaderSize = kMessageHeaderSize;
+ exports.kMessageWithRequestIDHeaderSize = kMessageWithRequestIDHeaderSize;
exports.kMessageExpectsResponse = kMessageExpectsResponse;
exports.kMessageIsResponse = kMessageIsResponse;
exports.Int8 = Int8;
« no previous file with comments | « extensions/renderer/dispatcher.cc ('k') | mojo/public/js/bindings/constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698