| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This script contains privileged chrome extension related javascript APIs. | 5 // This script contains privileged chrome extension related javascript APIs. |
| 6 // It is loaded by pages whose URL has the chrome-extension protocol. | 6 // It is loaded by pages whose URL has the chrome-extension protocol. |
| 7 | 7 |
| 8 var chrome = chrome || {}; | 8 var chrome = chrome || {}; |
| 9 (function() { | 9 (function() { |
| 10 native function GetExtensionAPIDefinition(); | 10 native function GetExtensionAPIDefinition(); |
| 11 native function StartRequest(); | 11 native function StartRequest(); |
| 12 native function GetChromeHidden(); |
| 13 native function GetNextRequestId(); |
| 14 native function Print(); |
| 15 |
| 12 native function GetCurrentPageActions(extensionId); | 16 native function GetCurrentPageActions(extensionId); |
| 13 native function GetExtensionViews(); | 17 native function GetExtensionViews(); |
| 14 native function GetChromeHidden(); | |
| 15 native function GetNextRequestId(); | |
| 16 native function GetNextContextMenuId(); | 18 native function GetNextContextMenuId(); |
| 17 native function GetNextTtsEventId(); | 19 native function GetNextTtsEventId(); |
| 18 native function OpenChannelToTab(); | 20 native function OpenChannelToTab(); |
| 19 native function GetRenderViewId(); | 21 native function GetRenderViewId(); |
| 20 native function SetIconCommon(); | 22 native function SetIconCommon(); |
| 21 native function GetUniqueSubEventName(eventName); | 23 native function GetUniqueSubEventName(eventName); |
| 22 native function GetLocalFileSystem(name, path); | 24 native function GetLocalFileSystem(name, path); |
| 23 native function DecodeJPEG(jpeg_image); | 25 native function DecodeJPEG(jpeg_image); |
| 24 native function Print(); | |
| 25 | 26 |
| 26 var chromeHidden = GetChromeHidden(); | 27 var chromeHidden = GetChromeHidden(); |
| 27 | 28 |
| 28 if (!chrome) | 29 if (!chrome) |
| 29 chrome = {}; | 30 chrome = {}; |
| 30 | 31 |
| 31 function forEach(dict, f) { | 32 function forEach(dict, f) { |
| 32 for (key in dict) { | 33 for (key in dict) { |
| 33 if (dict.hasOwnProperty(key)) | 34 if (dict.hasOwnProperty(key)) |
| 34 f(key, dict[key]); | 35 f(key, dict[key]); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 124 } |
| 124 } | 125 } |
| 125 } finally { | 126 } finally { |
| 126 delete requests[requestId]; | 127 delete requests[requestId]; |
| 127 delete chrome.extension.lastError; | 128 delete chrome.extension.lastError; |
| 128 } | 129 } |
| 129 | 130 |
| 130 return undefined; | 131 return undefined; |
| 131 }; | 132 }; |
| 132 | 133 |
| 133 chromeHidden.setViewType = function(type) { | |
| 134 var modeClass = "chrome-" + type; | |
| 135 var className = document.documentElement.className; | |
| 136 if (className && className.length) { | |
| 137 var classes = className.split(" "); | |
| 138 var new_classes = []; | |
| 139 classes.forEach(function(cls) { | |
| 140 if (cls.indexOf("chrome-") != 0) { | |
| 141 new_classes.push(cls); | |
| 142 } | |
| 143 }); | |
| 144 new_classes.push(modeClass); | |
| 145 document.documentElement.className = new_classes.join(" "); | |
| 146 } else { | |
| 147 document.documentElement.className = modeClass; | |
| 148 } | |
| 149 }; | |
| 150 | |
| 151 function prepareRequest(args, argSchemas) { | 134 function prepareRequest(args, argSchemas) { |
| 152 var request = {}; | 135 var request = {}; |
| 153 var argCount = args.length; | 136 var argCount = args.length; |
| 154 | 137 |
| 155 // Look for callback param. | 138 // Look for callback param. |
| 156 if (argSchemas.length > 0 && | 139 if (argSchemas.length > 0 && |
| 157 args.length == argSchemas.length && | 140 args.length == argSchemas.length && |
| 158 argSchemas[argSchemas.length - 1].type == "function") { | 141 argSchemas[argSchemas.length - 1].type == "function") { |
| 159 request.callback = args[argSchemas.length - 1]; | 142 request.callback = args[argSchemas.length - 1]; |
| 160 request.callbackSchema = argSchemas[argSchemas.length - 1]; | 143 request.callbackSchema = argSchemas[argSchemas.length - 1]; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 var nativeFunction = opt_args.nativeFunction || StartRequest; | 177 var nativeFunction = opt_args.nativeFunction || StartRequest; |
| 195 | 178 |
| 196 var requestId = GetNextRequestId(); | 179 var requestId = GetNextRequestId(); |
| 197 requests[requestId] = request; | 180 requests[requestId] = request; |
| 198 var hasCallback = | 181 var hasCallback = |
| 199 (request.callback || opt_args.customCallback) ? true : false; | 182 (request.callback || opt_args.customCallback) ? true : false; |
| 200 return nativeFunction(functionName, sargs, requestId, hasCallback, | 183 return nativeFunction(functionName, sargs, requestId, hasCallback, |
| 201 opt_args.forIOThread); | 184 opt_args.forIOThread); |
| 202 } | 185 } |
| 203 | 186 |
| 204 // Helper function for positioning pop-up windows relative to DOM objects. | |
| 205 // Returns the absolute position of the given element relative to the hosting | |
| 206 // browser frame. | |
| 207 function findAbsolutePosition(domElement) { | |
| 208 var left = domElement.offsetLeft; | |
| 209 var top = domElement.offsetTop; | |
| 210 | |
| 211 // Ascend through the parent hierarchy, taking into account object nesting | |
| 212 // and scoll positions. | |
| 213 for (var parentElement = domElement.offsetParent; parentElement; | |
| 214 parentElement = parentElement.offsetParent) { | |
| 215 left += parentElement.offsetLeft; | |
| 216 top += parentElement.offsetTop; | |
| 217 | |
| 218 left -= parentElement.scrollLeft; | |
| 219 top -= parentElement.scrollTop; | |
| 220 } | |
| 221 | |
| 222 return { | |
| 223 top: top, | |
| 224 left: left | |
| 225 }; | |
| 226 } | |
| 227 | |
| 228 // Returns the coordiates of the rectangle encompassing the domElement, | |
| 229 // in browser coordinates relative to the frame hosting the element. | |
| 230 function getAbsoluteRect(domElement) { | |
| 231 var rect = findAbsolutePosition(domElement); | |
| 232 rect.width = domElement.offsetWidth || 0; | |
| 233 rect.height = domElement.offsetHeight || 0; | |
| 234 return rect; | |
| 235 } | |
| 236 | |
| 237 // --- Setup additional api's not currently handled in common/extensions/api | 187 // --- Setup additional api's not currently handled in common/extensions/api |
| 238 | 188 |
| 239 // WebRequestEvent object. This is used for special webRequest events with | 189 // WebRequestEvent object. This is used for special webRequest events with |
| 240 // extra parameters. Each invocation of addListener creates a new named | 190 // extra parameters. Each invocation of addListener creates a new named |
| 241 // sub-event. That sub-event is associated with the extra parameters in the | 191 // sub-event. That sub-event is associated with the extra parameters in the |
| 242 // browser process, so that only it is dispatched when the main event occurs | 192 // browser process, so that only it is dispatched when the main event occurs |
| 243 // matching the extra parameters. | 193 // matching the extra parameters. |
| 244 // | 194 // |
| 245 // Example: | 195 // Example: |
| 246 // chrome.webRequest.onBeforeRequest.addListener( | 196 // chrome.webRequest.onBeforeRequest.addListener( |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 // Setup Events | 653 // Setup Events |
| 704 if (apiDef.events) { | 654 if (apiDef.events) { |
| 705 apiDef.events.forEach(function(eventDef) { | 655 apiDef.events.forEach(function(eventDef) { |
| 706 // Module events may have been defined earlier by hand. Don't clobber | 656 // Module events may have been defined earlier by hand. Don't clobber |
| 707 // them. | 657 // them. |
| 708 if (module[eventDef.name]) | 658 if (module[eventDef.name]) |
| 709 return; | 659 return; |
| 710 | 660 |
| 711 var eventName = apiDef.namespace + "." + eventDef.name; | 661 var eventName = apiDef.namespace + "." + eventDef.name; |
| 712 if (apiDef.namespace == "experimental.webRequest") { | 662 if (apiDef.namespace == "experimental.webRequest") { |
| 713 // WebRequest events have a special structure. | |
| 714 module[eventDef.name] = new chrome.WebRequestEvent(eventName, | 663 module[eventDef.name] = new chrome.WebRequestEvent(eventName, |
| 715 eventDef.parameters, eventDef.extraParameters); | 664 eventDef.parameters, eventDef.extraParameters); |
| 716 } else { | 665 } else { |
| 717 module[eventDef.name] = new chrome.Event(eventName, | 666 module[eventDef.name] = new chrome.Event(eventName, |
| 718 eventDef.parameters); | 667 eventDef.parameters); |
| 719 } | 668 } |
| 720 }); | 669 }); |
| 721 } | 670 } |
| 722 | 671 |
| 723 function addProperties(m, def) { | 672 function addProperties(m, def) { |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 | 1017 |
| 1069 if (!chrome.tts) | 1018 if (!chrome.tts) |
| 1070 chrome.tts = {}; | 1019 chrome.tts = {}; |
| 1071 | 1020 |
| 1072 if (!chrome.ttsEngine) | 1021 if (!chrome.ttsEngine) |
| 1073 chrome.ttsEngine = {}; | 1022 chrome.ttsEngine = {}; |
| 1074 | 1023 |
| 1075 if (!chrome.experimental.downloads) | 1024 if (!chrome.experimental.downloads) |
| 1076 chrome.experimental.downloads = {}; | 1025 chrome.experimental.downloads = {}; |
| 1077 })(); | 1026 })(); |
| OLD | NEW |