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

Side by Side Diff: chrome/renderer/resources/extensions/gcm_custom_bindings.js

Issue 141433030: [GCM] Updating the list of restricted keys for GCM API messages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing code reviews from jianli@ and kalman@, fixing a typo in error messages" Created 6 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Custom binding for the GCM API. 5 // Custom binding for the GCM API.
6 6
7 var binding = require('binding').Binding.create('gcm'); 7 var binding = require('binding').Binding.create('gcm');
8 var forEach = require('utils').forEach; 8 var forEach = require('utils').forEach;
9 9
10 binding.registerCustomHook(function(bindingsAPI) { 10 binding.registerCustomHook(function(bindingsAPI) {
11 var apiFunctions = bindingsAPI.apiFunctions; 11 var apiFunctions = bindingsAPI.apiFunctions;
12 var gcm = bindingsAPI.compiledApi; 12 var gcm = bindingsAPI.compiledApi;
13 13
14 apiFunctions.setUpdateArgumentsPostValidate( 14 apiFunctions.setUpdateArgumentsPostValidate(
15 'send', function(message, callback) { 15 'send', function(message, callback) {
16 // Validate message.data. 16 // Validate message.data.
17 var payloadSize = 0; 17 var payloadSize = 0;
18 forEach(message.data, function(property, value) { 18 forEach(message.data, function(property, value) {
19 if (property.length == 0) 19 if (property.length == 0)
20 throw new Error("One of data keys is empty."); 20 throw new Error("One of data keys is empty.");
21 21
22 var lowerCasedProperty = property.toLowerCase();
22 // Issue an error for forbidden prefixes of property names. 23 // Issue an error for forbidden prefixes of property names.
23 if (property.indexOf("goog.") == 0 || 24 if (lowerCasedProperty.indexOf("goog.") == 0 ||
24 property.indexOf("google") == 0) { 25 lowerCasedProperty.indexOf("google") == 0 ||
26 property.indexOf("collapse_key") == 0) {
25 throw new Error("Invalid data key: " + property); 27 throw new Error("Invalid data key: " + property);
26 } 28 }
27 29
28 payloadSize += property.length + value.length; 30 payloadSize += property.length + value.length;
29 }); 31 });
30 32
31 if (payloadSize > gcm.MAX_MESSAGE_SIZE) 33 if (payloadSize > gcm.MAX_MESSAGE_SIZE)
32 throw new Error("Payload exceeded allowed size limit. Payload size is: " 34 throw new Error("Payload exceeded allowed size limit. Payload size is: "
33 + payloadSize); 35 + payloadSize);
34 36
35 if (payloadSize == 0) 37 if (payloadSize == 0)
36 throw new Error("No data to send."); 38 throw new Error("No data to send.");
37 39
38 return arguments; 40 return arguments;
39 }); 41 });
40 }); 42 });
41 43
42 exports.binding = binding.generate(); 44 exports.binding = binding.generate();
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/gcm.json ('k') | chrome/test/data/extensions/api_test/gcm/events/on_send_error.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698