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

Side by Side Diff: chrome/renderer/resources/renderer_extension_bindings.js

Issue 115681: switch to using native JSON object (Closed)
Patch Set: all in one Created 11 years, 6 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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 // ----------------------------------------------------------------------------- 5 // -----------------------------------------------------------------------------
6 // NOTE: If you change this file you need to touch renderer_resources.grd to 6 // NOTE: If you change this file you need to touch renderer_resources.grd to
7 // have your change take effect. 7 // have your change take effect.
8 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
9 9
10 var chrome = chrome || {}; 10 var chrome = chrome || {};
(...skipping 15 matching lines...) Expand all
26 // when there are no more listeners. 26 // when there are no more listeners.
27 }; 27 };
28 28
29 // Map of port IDs to port object. 29 // Map of port IDs to port object.
30 chrome.Port.ports_ = {}; 30 chrome.Port.ports_ = {};
31 31
32 // Called by native code when a channel has been opened to this context. 32 // Called by native code when a channel has been opened to this context.
33 chrome.Port.dispatchOnConnect_ = function(portId, tab) { 33 chrome.Port.dispatchOnConnect_ = function(portId, tab) {
34 var port = new chrome.Port(portId); 34 var port = new chrome.Port(portId);
35 if (tab) { 35 if (tab) {
36 tab = goog.json.parse(tab); 36 tab = JSON.parse(tab);
37 } 37 }
38 port.tab = tab; 38 port.tab = tab;
39 chrome.Event.dispatch_("channel-connect", [port]); 39 chrome.Event.dispatch_("channel-connect", [port]);
40 }; 40 };
41 41
42 // Called by native code when a message has been sent to the given port. 42 // Called by native code when a message has been sent to the given port.
43 chrome.Port.dispatchOnMessage_ = function(msg, portId) { 43 chrome.Port.dispatchOnMessage_ = function(msg, portId) {
44 var port = chrome.Port.ports_[portId]; 44 var port = chrome.Port.ports_[portId];
45 if (port) { 45 if (port) {
46 if (msg) { 46 if (msg) {
47 msg = goog.json.parse(msg); 47 msg = JSON.parse(msg);
48 } 48 }
49 port.onMessage.dispatch(msg, port); 49 port.onMessage.dispatch(msg, port);
50 } 50 }
51 }; 51 };
52 52
53 // Sends a message asynchronously to the context on the other end of this 53 // Sends a message asynchronously to the context on the other end of this
54 // port. 54 // port.
55 chrome.Port.prototype.postMessage = function(msg) { 55 chrome.Port.prototype.postMessage = function(msg) {
56 PostMessage(this.portId_, goog.json.serialize(msg)); 56 // JSON.stringify doesn't support a root object which is undefined.
57 if (msg === undefined)
58 msg = null;
59 PostMessage(this.portId_, JSON.stringify(msg));
57 }; 60 };
58 61
59 // Extension object. 62 // Extension object.
60 chrome.Extension = function(id) { 63 chrome.Extension = function(id) {
61 this.id_ = id; 64 this.id_ = id;
62 }; 65 };
63 66
64 // Opens a message channel to the extension. Returns a Port for 67 // Opens a message channel to the extension. Returns a Port for
65 // message passing. 68 // message passing.
66 chrome.Extension.prototype.connect = function() { 69 chrome.Extension.prototype.connect = function() {
67 var portId = OpenChannelToExtension(this.id_); 70 var portId = OpenChannelToExtension(this.id_);
68 if (portId == -1) 71 if (portId == -1)
69 throw new Error("No such extension: '" + this.id_ + "'"); 72 throw new Error("No such extension: '" + this.id_ + "'");
70 return new chrome.Port(portId); 73 return new chrome.Port(portId);
71 }; 74 };
72 75
73 // Returns a resource URL that can be used to fetch a resource from this 76 // Returns a resource URL that can be used to fetch a resource from this
74 // extension. 77 // extension.
75 chrome.Extension.prototype.getURL = function(path) { 78 chrome.Extension.prototype.getURL = function(path) {
76 return "chrome-extension://" + this.id_ + "/" + path; 79 return "chrome-extension://" + this.id_ + "/" + path;
77 }; 80 };
78 })(); 81 })();
OLDNEW
« no previous file with comments | « chrome/renderer/resources/extension_process_bindings.js ('k') | chrome/test/render_view_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698