| OLD | NEW |
| 1 // Copyright (c) 2009 The chrome Authors. All rights reserved. | 1 // Copyright (c) 2009 The chrome 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; | 10 var chrome; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 function validate(args, schemas) { | 44 function validate(args, schemas) { |
| 45 if (args.length > schemas.length) | 45 if (args.length > schemas.length) |
| 46 throw new Error("Too many arguments."); | 46 throw new Error("Too many arguments."); |
| 47 | 47 |
| 48 for (var i = 0; i < schemas.length; i++) { | 48 for (var i = 0; i < schemas.length; i++) { |
| 49 if (i in args && args[i] !== null && args[i] !== undefined) { | 49 if (i in args && args[i] !== null && args[i] !== undefined) { |
| 50 var validator = new chrome.JSONSchemaValidator(); | 50 var validator = new chrome.JSONSchemaValidator(); |
| 51 validator.validate(args[i], schemas[i]); | 51 validator.validate(args[i], schemas[i]); |
| 52 if (validator.errors.length == 0) | 52 if (validator.errors.length == 0) |
| 53 continue; | 53 continue; |
| 54 | 54 |
| 55 var message = "Invalid value for argument " + i + ". "; | 55 var message = "Invalid value for argument " + i + ". "; |
| 56 for (var i = 0, err; err = validator.errors[i]; i++) { | 56 for (var i = 0, err; err = validator.errors[i]; i++) { |
| 57 if (err.path) { | 57 if (err.path) { |
| 58 message += "Property '" + err.path + "': "; | 58 message += "Property '" + err.path + "': "; |
| 59 } | 59 } |
| 60 message += err.message; | 60 message += err.message; |
| 61 message = message.substring(0, message.length - 1); | 61 message = message.substring(0, message.length - 1); |
| 62 message += ", "; | 62 message += ", "; |
| 63 } | 63 } |
| 64 message = message.substring(0, message.length - 2); | 64 message = message.substring(0, message.length - 2); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 76 // instead and hold one per-context. See the way event_bindings.js works. | 76 // instead and hold one per-context. See the way event_bindings.js works. |
| 77 var callbacks = []; | 77 var callbacks = []; |
| 78 chrome.handleResponse_ = function(requestId, name, success, response, error) { | 78 chrome.handleResponse_ = function(requestId, name, success, response, error) { |
| 79 try { | 79 try { |
| 80 if (!success) { | 80 if (!success) { |
| 81 if (!error) | 81 if (!error) |
| 82 error = "Unknown error." | 82 error = "Unknown error." |
| 83 console.error("Error during " + name + ": " + error); | 83 console.error("Error during " + name + ": " + error); |
| 84 return; | 84 return; |
| 85 } | 85 } |
| 86 | 86 |
| 87 if (callbacks[requestId]) { | 87 if (callbacks[requestId]) { |
| 88 if (response) { | 88 if (response) { |
| 89 callbacks[requestId](JSON.parse(response)); | 89 callbacks[requestId](JSON.parse(response)); |
| 90 } else { | 90 } else { |
| 91 callbacks[requestId](); | 91 callbacks[requestId](); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 } finally { | 94 } finally { |
| 95 delete callbacks[requestId]; | 95 delete callbacks[requestId]; |
| 96 } | 96 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 118 | 118 |
| 119 chrome.windows.get = function(windowId, callback) { | 119 chrome.windows.get = function(windowId, callback) { |
| 120 validate(arguments, arguments.callee.params); | 120 validate(arguments, arguments.callee.params); |
| 121 sendRequest(GetWindow, windowId, callback); | 121 sendRequest(GetWindow, windowId, callback); |
| 122 }; | 122 }; |
| 123 | 123 |
| 124 chrome.windows.get.params = [ | 124 chrome.windows.get.params = [ |
| 125 chrome.types.pInt, | 125 chrome.types.pInt, |
| 126 chrome.types.fun | 126 chrome.types.fun |
| 127 ]; | 127 ]; |
| 128 | 128 |
| 129 chrome.windows.getCurrent = function(callback) { | 129 chrome.windows.getCurrent = function(callback) { |
| 130 validate(arguments, arguments.callee.params); | 130 validate(arguments, arguments.callee.params); |
| 131 sendRequest(GetCurrentWindow, null, callback); | 131 sendRequest(GetCurrentWindow, null, callback); |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 chrome.windows.getCurrent.params = [ | 134 chrome.windows.getCurrent.params = [ |
| 135 chrome.types.fun | 135 chrome.types.fun |
| 136 ]; | 136 ]; |
| 137 | 137 |
| 138 chrome.windows.getLastFocused = function(callback) { | 138 chrome.windows.getLastFocused = function(callback) { |
| 139 validate(arguments, arguments.callee.params); | 139 validate(arguments, arguments.callee.params); |
| 140 sendRequest(GetLastFocusedWindow, null, callback); | 140 sendRequest(GetLastFocusedWindow, null, callback); |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 chrome.windows.getLastFocused.params = [ | 143 chrome.windows.getLastFocused.params = [ |
| 144 chrome.types.fun | 144 chrome.types.fun |
| 145 ]; | 145 ]; |
| 146 | 146 |
| 147 chrome.windows.getAll = function(populate, callback) { | 147 chrome.windows.getAll = function(populate, callback) { |
| 148 validate(arguments, arguments.callee.params); | 148 validate(arguments, arguments.callee.params); |
| 149 sendRequest(GetAllWindows, populate, callback); | 149 sendRequest(GetAllWindows, populate, callback); |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 chrome.windows.getAll.params = [ | 152 chrome.windows.getAll.params = [ |
| 153 chrome.types.optBool, | 153 chrome.types.optBool, |
| 154 chrome.types.fun | 154 chrome.types.fun |
| 155 ]; | 155 ]; |
| 156 | 156 |
| 157 chrome.windows.create = function(createData, callback) { | 157 chrome.windows.create = function(createData, callback) { |
| 158 validate(arguments, arguments.callee.params); | 158 validate(arguments, arguments.callee.params); |
| 159 sendRequest(CreateWindow, createData, callback); | 159 sendRequest(CreateWindow, createData, callback); |
| 160 }; | 160 }; |
| 161 chrome.windows.create.params = [ | 161 chrome.windows.create.params = [ |
| 162 { | 162 { |
| 163 type: "object", | 163 type: "object", |
| 164 properties: { | 164 properties: { |
| 165 url: chrome.types.optStr, | 165 url: chrome.types.optStr, |
| 166 left: chrome.types.optInt, | 166 left: chrome.types.optInt, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 193 | 193 |
| 194 chrome.windows.remove = function(windowId, callback) { | 194 chrome.windows.remove = function(windowId, callback) { |
| 195 validate(arguments, arguments.callee.params); | 195 validate(arguments, arguments.callee.params); |
| 196 sendRequest(RemoveWindow, windowId, callback); | 196 sendRequest(RemoveWindow, windowId, callback); |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 chrome.windows.remove.params = [ | 199 chrome.windows.remove.params = [ |
| 200 chrome.types.pInt, | 200 chrome.types.pInt, |
| 201 chrome.types.optFun | 201 chrome.types.optFun |
| 202 ]; | 202 ]; |
| 203 | 203 |
| 204 // sends (windowId). | 204 // sends (windowId). |
| 205 // *WILL* be followed by tab-attached AND then tab-selection-changed. | 205 // *WILL* be followed by tab-attached AND then tab-selection-changed. |
| 206 chrome.windows.onCreated = new chrome.Event("window-created"); | 206 chrome.windows.onCreated = new chrome.Event("window-created"); |
| 207 | 207 |
| 208 // sends (windowId). | 208 // sends (windowId). |
| 209 // *WILL* be preceded by sequences of tab-removed AND then | 209 // *WILL* be preceded by sequences of tab-removed AND then |
| 210 // tab-selection-changed -- one for each tab that was contained in the window | 210 // tab-selection-changed -- one for each tab that was contained in the window |
| 211 // that closed | 211 // that closed |
| 212 chrome.windows.onRemoved = new chrome.Event("window-removed"); | 212 chrome.windows.onRemoved = new chrome.Event("window-removed"); |
| 213 | 213 |
| 214 // sends (windowId). | 214 // sends (windowId). |
| 215 chrome.windows.onFocusChanged = | 215 chrome.windows.onFocusChanged = |
| 216 new chrome.Event("window-focus-changed"); | 216 new chrome.Event("window-focus-changed"); |
| 217 | 217 |
| 218 //---------------------------------------------------------------------------- | 218 //---------------------------------------------------------------------------- |
| 219 | 219 |
| 220 // Tabs | 220 // Tabs |
| 221 chrome.tabs = {}; | 221 chrome.tabs = {}; |
| 222 | 222 |
| 223 chrome.tabs.get = function(tabId, callback) { | 223 chrome.tabs.get = function(tabId, callback) { |
| 224 validate(arguments, arguments.callee.params); | 224 validate(arguments, arguments.callee.params); |
| 225 sendRequest(GetTab, tabId, callback); | 225 sendRequest(GetTab, tabId, callback); |
| 226 }; | 226 }; |
| 227 | 227 |
| 228 chrome.tabs.get.params = [ | 228 chrome.tabs.get.params = [ |
| 229 chrome.types.pInt, | 229 chrome.types.pInt, |
| 230 chrome.types.fun | 230 chrome.types.fun |
| 231 ]; | 231 ]; |
| 232 | 232 |
| 233 chrome.tabs.getSelected = function(windowId, callback) { | 233 chrome.tabs.getSelected = function(windowId, callback) { |
| 234 validate(arguments, arguments.callee.params); | 234 validate(arguments, arguments.callee.params); |
| 235 sendRequest(GetSelectedTab, windowId, callback); | 235 sendRequest(GetSelectedTab, windowId, callback); |
| 236 }; | 236 }; |
| 237 | 237 |
| 238 chrome.tabs.getSelected.params = [ | 238 chrome.tabs.getSelected.params = [ |
| 239 chrome.types.optPInt, | 239 chrome.types.optPInt, |
| 240 chrome.types.fun | 240 chrome.types.fun |
| 241 ]; | 241 ]; |
| 242 | 242 |
| 243 chrome.tabs.getAllInWindow = function(windowId, callback) { | 243 chrome.tabs.getAllInWindow = function(windowId, callback) { |
| 244 validate(arguments, arguments.callee.params); | 244 validate(arguments, arguments.callee.params); |
| 245 sendRequest(GetAllTabsInWindow, windowId, callback); | 245 sendRequest(GetAllTabsInWindow, windowId, callback); |
| 246 }; | 246 }; |
| 247 | 247 |
| 248 chrome.tabs.getAllInWindow.params = [ | 248 chrome.tabs.getAllInWindow.params = [ |
| 249 chrome.types.optPInt, | 249 chrome.types.optPInt, |
| 250 chrome.types.fun | 250 chrome.types.fun |
| 251 ]; | 251 ]; |
| 252 | 252 |
| 253 chrome.tabs.create = function(tab, callback) { | 253 chrome.tabs.create = function(tab, callback) { |
| 254 validate(arguments, arguments.callee.params); | 254 validate(arguments, arguments.callee.params); |
| 255 sendRequest(CreateTab, tab, callback); | 255 sendRequest(CreateTab, tab, callback); |
| 256 }; | 256 }; |
| 257 | 257 |
| 258 chrome.tabs.create.params = [ | 258 chrome.tabs.create.params = [ |
| 259 { | 259 { |
| 260 type: "object", | 260 type: "object", |
| 261 properties: { | 261 properties: { |
| 262 windowId: chrome.types.optPInt, | 262 windowId: chrome.types.optPInt, |
| 263 index: chrome.types.optPInt, | 263 index: chrome.types.optPInt, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 294 chrome.types.pInt, | 294 chrome.types.pInt, |
| 295 { | 295 { |
| 296 type: "object", | 296 type: "object", |
| 297 properties: { | 297 properties: { |
| 298 windowId: chrome.types.optPInt, | 298 windowId: chrome.types.optPInt, |
| 299 index: chrome.types.pInt | 299 index: chrome.types.pInt |
| 300 } | 300 } |
| 301 }, | 301 }, |
| 302 chrome.types.optFun | 302 chrome.types.optFun |
| 303 ]; | 303 ]; |
| 304 | 304 |
| 305 chrome.tabs.remove = function(tabId, callback) { | 305 chrome.tabs.remove = function(tabId, callback) { |
| 306 validate(arguments, arguments.callee.params); | 306 validate(arguments, arguments.callee.params); |
| 307 sendRequest(RemoveTab, tabId, callback); | 307 sendRequest(RemoveTab, tabId, callback); |
| 308 }; | 308 }; |
| 309 | 309 |
| 310 chrome.tabs.remove.params = [ | 310 chrome.tabs.remove.params = [ |
| 311 chrome.types.pInt, | 311 chrome.types.pInt, |
| 312 chrome.types.optFun | 312 chrome.types.optFun |
| 313 ]; | 313 ]; |
| 314 | 314 |
| 315 // Sends ({Tab}). | 315 // Sends ({Tab}). |
| 316 // Will *NOT* be followed by tab-attached - it is implied. | 316 // Will *NOT* be followed by tab-attached - it is implied. |
| 317 // *MAY* be followed by tab-selection-changed. | 317 // *MAY* be followed by tab-selection-changed. |
| 318 chrome.tabs.onCreated = new chrome.Event("tab-created"); | 318 chrome.tabs.onCreated = new chrome.Event("tab-created"); |
| 319 | 319 |
| 320 // Sends (tabId, {ChangedProps}). | 320 // Sends (tabId, {ChangedProps}). |
| 321 chrome.tabs.onUpdated = new chrome.Event("tab-updated"); | 321 chrome.tabs.onUpdated = new chrome.Event("tab-updated"); |
| 322 | 322 |
| 323 // Sends (tabId, {windowId, fromIndex, toIndex}). | 323 // Sends (tabId, {windowId, fromIndex, toIndex}). |
| 324 // Tabs can only "move" within a window. | 324 // Tabs can only "move" within a window. |
| 325 chrome.tabs.onMoved = new chrome.Event("tab-moved"); | 325 chrome.tabs.onMoved = new chrome.Event("tab-moved"); |
| 326 | 326 |
| 327 // Sends (tabId, {windowId}). | 327 // Sends (tabId, {windowId}). |
| 328 chrome.tabs.onSelectionChanged = | 328 chrome.tabs.onSelectionChanged = |
| 329 new chrome.Event("tab-selection-changed"); | 329 new chrome.Event("tab-selection-changed"); |
| 330 | 330 |
| 331 // Sends (tabId, {newWindowId, newPosition}). | 331 // Sends (tabId, {newWindowId, newPosition}). |
| 332 // *MAY* be followed by tab-selection-changed. | 332 // *MAY* be followed by tab-selection-changed. |
| 333 chrome.tabs.onAttached = new chrome.Event("tab-attached"); | 333 chrome.tabs.onAttached = new chrome.Event("tab-attached"); |
| 334 | 334 |
| 335 // Sends (tabId, {oldWindowId, oldPosition}). | 335 // Sends (tabId, {oldWindowId, oldPosition}). |
| 336 // *WILL* be followed by tab-selection-changed. | 336 // *WILL* be followed by tab-selection-changed. |
| 337 chrome.tabs.onDetached = new chrome.Event("tab-detached"); | 337 chrome.tabs.onDetached = new chrome.Event("tab-detached"); |
| 338 | 338 |
| 339 // Sends (tabId). | 339 // Sends (tabId). |
| 340 // *WILL* be followed by tab-selection-changed. | 340 // *WILL* be followed by tab-selection-changed. |
| 341 // Will *NOT* be followed or preceded by tab-detached. | 341 // Will *NOT* be followed or preceded by tab-detached. |
| 342 chrome.tabs.onRemoved = new chrome.Event("tab-removed"); | 342 chrome.tabs.onRemoved = new chrome.Event("tab-removed"); |
| 343 | 343 |
| 344 //---------------------------------------------------------------------------- | 344 //---------------------------------------------------------------------------- |
| 345 | 345 |
| 346 // PageActions. | 346 // PageActions. |
| 347 chrome.pageActions = {}; | 347 chrome.pageActions = {}; |
| 348 | 348 |
| 349 chrome.pageActions.enableForTab = function(pageActionId, action) { | 349 chrome.pageActions.enableForTab = function(pageActionId, action) { |
| 350 validate(arguments, arguments.callee.params); | 350 validate(arguments, arguments.callee.params); |
| 351 sendRequest(EnablePageAction, [pageActionId, action]); | 351 sendRequest(EnablePageAction, [pageActionId, action]); |
| 352 } | 352 } |
| 353 | 353 |
| 354 chrome.pageActions.enableForTab.params = [ | 354 chrome.pageActions.enableForTab.params = [ |
| 355 chrome.types.str, | 355 chrome.types.str, |
| 356 { | 356 { |
| 357 type: "object", | 357 type: "object", |
| 358 properties: { | 358 properties: { |
| 359 tabId: chrome.types.pInt, | 359 tabId: chrome.types.pInt, |
| 360 url: chrome.types.str | 360 url: chrome.types.str |
| 361 }, | 361 }, |
| 362 optional: false | 362 optional: false |
| 363 } | 363 } |
| 364 ]; | 364 ]; |
| 365 | 365 |
| 366 // Sends ({pageActionId, tabId, tabUrl}). | 366 // Sends ({pageActionId, tabId, tabUrl}). |
| 367 chrome.pageActions.onExecute = | 367 chrome.pageActions.onExecute = |
| 368 new chrome.Event("page-action-executed"); | 368 new chrome.Event("page-action-executed"); |
| 369 | 369 |
| 370 //---------------------------------------------------------------------------- | 370 //---------------------------------------------------------------------------- |
| 371 // Bookmarks | 371 // Bookmarks |
| 372 chrome.bookmarks = {}; | 372 chrome.bookmarks = {}; |
| 373 | 373 |
| 374 chrome.bookmarks.get = function(ids, callback) { | 374 chrome.bookmarks.get = function(ids, callback) { |
| 375 validate(arguments, arguments.callee.params); | 375 validate(arguments, arguments.callee.params); |
| 376 sendRequest(GetBookmarks, ids, callback); | 376 sendRequest(GetBookmarks, ids, callback); |
| 377 }; | 377 }; |
| 378 | 378 |
| 379 chrome.bookmarks.get.params = [ | 379 chrome.bookmarks.get.params = [ |
| 380 chrome.types.singleOrListOf(chrome.types.pInt), | 380 chrome.types.singleOrListOf(chrome.types.pInt), |
| 381 chrome.types.fun | 381 chrome.types.fun |
| 382 ]; | 382 ]; |
| 383 | 383 |
| 384 chrome.bookmarks.getChildren = function(id, callback) { | 384 chrome.bookmarks.getChildren = function(id, callback) { |
| 385 validate(arguments, arguments.callee.params); | 385 validate(arguments, arguments.callee.params); |
| 386 sendRequest(GetBookmarkChildren, id, callback); | 386 sendRequest(GetBookmarkChildren, id, callback); |
| 387 }; | 387 }; |
| 388 | 388 |
| 389 chrome.bookmarks.getChildren.params = [ | 389 chrome.bookmarks.getChildren.params = [ |
| 390 chrome.types.pInt, | 390 chrome.types.pInt, |
| 391 chrome.types.fun | 391 chrome.types.fun |
| 392 ]; | 392 ]; |
| 393 | 393 |
| 394 chrome.bookmarks.getTree = function(callback) { | 394 chrome.bookmarks.getTree = function(callback) { |
| 395 validate(arguments, arguments.callee.params); | 395 validate(arguments, arguments.callee.params); |
| 396 sendRequest(GetBookmarkTree, null, callback); | 396 sendRequest(GetBookmarkTree, null, callback); |
| 397 }; | 397 }; |
| 398 | 398 |
| 399 // TODO(erikkay): allow it to take an optional id as a starting point | 399 // TODO(erikkay): allow it to take an optional id as a starting point |
| 400 // BUG=13727 | 400 // BUG=13727 |
| 401 chrome.bookmarks.getTree.params = [ | 401 chrome.bookmarks.getTree.params = [ |
| 402 chrome.types.fun | 402 chrome.types.fun |
| 403 ]; | 403 ]; |
| 404 | 404 |
| 405 chrome.bookmarks.search = function(query, callback) { | 405 chrome.bookmarks.search = function(query, callback) { |
| 406 validate(arguments, arguments.callee.params); | 406 validate(arguments, arguments.callee.params); |
| 407 sendRequest(SearchBookmarks, query, callback); | 407 sendRequest(SearchBookmarks, query, callback); |
| 408 }; | 408 }; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 | 490 |
| 491 // Sends ({parentId, index}) | 491 // Sends ({parentId, index}) |
| 492 chrome.bookmarks.onRemoved = new chrome.Event("bookmark-removed"); | 492 chrome.bookmarks.onRemoved = new chrome.Event("bookmark-removed"); |
| 493 | 493 |
| 494 // Sends (id, object) where object has list of properties that have changed. | 494 // Sends (id, object) where object has list of properties that have changed. |
| 495 // Currently, this only ever includes 'title'. | 495 // Currently, this only ever includes 'title'. |
| 496 chrome.bookmarks.onChanged = new chrome.Event("bookmark-changed"); | 496 chrome.bookmarks.onChanged = new chrome.Event("bookmark-changed"); |
| 497 | 497 |
| 498 // Sends (id, {parentId, index, oldParentId, oldIndex}) | 498 // Sends (id, {parentId, index, oldParentId, oldIndex}) |
| 499 chrome.bookmarks.onMoved = new chrome.Event("bookmark-moved"); | 499 chrome.bookmarks.onMoved = new chrome.Event("bookmark-moved"); |
| 500 | 500 |
| 501 // Sends (id, [childrenIds]) | 501 // Sends (id, [childrenIds]) |
| 502 chrome.bookmarks.onChildrenReordered = | 502 chrome.bookmarks.onChildrenReordered = |
| 503 new chrome.Event("bookmark-children-reordered"); | 503 new chrome.Event("bookmark-children-reordered"); |
| 504 | 504 |
| 505 | 505 |
| 506 //---------------------------------------------------------------------------- | 506 //---------------------------------------------------------------------------- |
| 507 | 507 |
| 508 // Self. | 508 // Self. |
| 509 chrome.self = chrome.self || {}; | 509 chrome.self = chrome.self || {}; |
| 510 chrome.self.onConnect = new chrome.Event("channel-connect"); | 510 chrome.self.onConnect = new chrome.Event("channel-connect"); |
| 511 | 511 |
| 512 // Register | 512 // Register |
| 513 chrome.self.register_ = function() { | 513 chrome.onLoad_.addListener(function() { |
| 514 var extensionId = RegisterExtension(); | 514 var extensionId = RegisterExtension(); |
| 515 window.addEventListener('unload', function() { | 515 chrome.onUnload_.addListener(function() { |
| 516 UnregisterExtension(extensionId); }, false); | 516 UnregisterExtension(extensionId); |
| 517 delete chrome.self.register_; | 517 }); |
| 518 } | 518 }); |
| 519 | 519 |
| 520 chrome.self.getViews = function() { | 520 chrome.self.getViews = function() { |
| 521 return GetViews(); | 521 return GetViews(); |
| 522 } | 522 } |
| 523 })(); | 523 })(); |
| 524 | 524 |
| OLD | NEW |