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

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

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: windows interactive_ui_tests fix Created 7 years, 9 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 | Annotate | Revision Log
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 bindings for the notification API. 5 // Custom bindings for the notification API.
6 6
7 var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); 7 var binding = require('binding').Binding.create('experimental.notification');
8
8 var sendRequest = require('sendRequest').sendRequest; 9 var sendRequest = require('sendRequest').sendRequest;
9 var imageUtil = require('imageUtil'); 10 var imageUtil = require('imageUtil');
10 var lastError = require('lastError'); 11 var lastError = require('lastError');
12 var json = require('json');
11 13
12 function url_getter(context, key) { 14 function url_getter(context, key) {
13 var f = function() { 15 var f = function() {
14 return this[key]; 16 return this[key];
15 }; 17 };
16 return f.bind(context); 18 return f.bind(context);
17 } 19 }
18 20
19 function url_setter(context, key) { 21 function url_setter(context, key) {
20 var f = function(val) { 22 var f = function(val) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 94 }
93 callback(true); 95 callback(true);
94 } 96 }
95 }); 97 });
96 } 98 }
97 99
98 function genHandle(failure_function) { 100 function genHandle(failure_function) {
99 return function(id, input_notification_details, callback) { 101 return function(id, input_notification_details, callback) {
100 // TODO(dewittj): Remove this hack. This is used as a way to deep 102 // TODO(dewittj): Remove this hack. This is used as a way to deep
101 // copy a complex JSON object. 103 // copy a complex JSON object.
102 var notification_details = JSON.parse( 104 var notification_details = json.parse(
103 JSON.stringify(input_notification_details)); 105 json.stringify(input_notification_details));
104 var that = this; 106 var that = this;
105 replaceNotificationOptionURLs(notification_details, function(success) { 107 replaceNotificationOptionURLs(notification_details, function(success) {
106 if (success) { 108 if (success) {
107 sendRequest(that.name, 109 sendRequest(that.name,
108 [id, notification_details, callback], 110 [id, notification_details, callback],
109 that.definition.parameters); 111 that.definition.parameters);
110 return; 112 return;
111 } 113 }
112 lastError.set('Unable to download all specified images.'); 114 lastError.set('Unable to download all specified images.');
113 failure_function(callback, id); 115 failure_function(callback, id);
114 }); 116 });
115 }; 117 };
116 } 118 }
117 119
118 var handleCreate = genHandle(function(callback, id) { callback(id); }); 120 var handleCreate = genHandle(function(callback, id) { callback(id); });
119 var handleUpdate = genHandle(function(callback, id) { callback(false); }); 121 var handleUpdate = genHandle(function(callback, id) { callback(false); });
120 122
121 var experimentalNotificationCustomHook = function(bindingsAPI, extensionId) { 123 var experimentalNotificationCustomHook = function(bindingsAPI, extensionId) {
122 var apiFunctions = bindingsAPI.apiFunctions; 124 var apiFunctions = bindingsAPI.apiFunctions;
123 apiFunctions.setHandleRequest('create', handleCreate); 125 apiFunctions.setHandleRequest('create', handleCreate);
124 apiFunctions.setHandleRequest('update', handleCreate); 126 apiFunctions.setHandleRequest('update', handleCreate);
125 }; 127 };
126 128
127 chromeHidden.registerCustomHook('experimental.notification', 129 binding.registerCustomHook(experimentalNotificationCustomHook);
128 experimentalNotificationCustomHook); 130
131 exports.binding = binding.generate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698