OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 GetCurrentPageActions(extensionId); | 12 native function GetCurrentPageActions(extensionId); |
13 native function GetExtensionViews(); | 13 native function GetExtensionViews(); |
14 native function GetChromeHidden(); | 14 native function GetChromeHidden(); |
15 native function GetNextRequestId(); | 15 native function GetNextRequestId(); |
16 native function OpenChannelToTab(); | 16 native function OpenChannelToTab(); |
17 native function GetRenderViewId(); | 17 native function GetRenderViewId(); |
18 native function GetPopupParentWindow(); | |
19 native function GetPopupView(); | |
20 native function SetIconCommon(); | 18 native function SetIconCommon(); |
21 native function IsExtensionProcess(); | 19 native function IsExtensionProcess(); |
22 native function IsIncognitoProcess(); | 20 native function IsIncognitoProcess(); |
23 | 21 |
24 var chromeHidden = GetChromeHidden(); | 22 var chromeHidden = GetChromeHidden(); |
25 | 23 |
26 // These bindings are for the extension process only. Since a chrome-extension | 24 // These bindings are for the extension process only. Since a chrome-extension |
27 // URL can be loaded in an iframe of a regular renderer, we check here to | 25 // URL can be loaded in an iframe of a regular renderer, we check here to |
28 // ensure we don't expose the APIs in that case. | 26 // ensure we don't expose the APIs in that case. |
29 if (!IsExtensionProcess()) { | 27 if (!IsExtensionProcess()) { |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 } | 247 } |
250 | 248 |
251 function setupToolstripEvents(renderViewId) { | 249 function setupToolstripEvents(renderViewId) { |
252 chrome.toolstrip = chrome.toolstrip || {}; | 250 chrome.toolstrip = chrome.toolstrip || {}; |
253 chrome.toolstrip.onExpanded = | 251 chrome.toolstrip.onExpanded = |
254 new chrome.Event("toolstrip.onExpanded." + renderViewId); | 252 new chrome.Event("toolstrip.onExpanded." + renderViewId); |
255 chrome.toolstrip.onCollapsed = | 253 chrome.toolstrip.onCollapsed = |
256 new chrome.Event("toolstrip.onCollapsed." + renderViewId); | 254 new chrome.Event("toolstrip.onCollapsed." + renderViewId); |
257 } | 255 } |
258 | 256 |
259 function setupPopupEvents(renderViewId) { | |
260 chrome.experimental.popup = chrome.experimental.popup || {}; | |
261 chrome.experimental.popup.onClosed = | |
262 new chrome.Event("experimental.popup.onClosed." + renderViewId); | |
263 } | |
264 | |
265 function setupHiddenContextMenuEvent(extensionId) { | 257 function setupHiddenContextMenuEvent(extensionId) { |
266 chromeHidden.contextMenus = {}; | 258 chromeHidden.contextMenus = {}; |
267 chromeHidden.contextMenus.nextId = 1; | 259 chromeHidden.contextMenus.nextId = 1; |
268 chromeHidden.contextMenus.handlers = {}; | 260 chromeHidden.contextMenus.handlers = {}; |
269 var eventName = "contextMenus"; | 261 var eventName = "contextMenus"; |
270 chromeHidden.contextMenus.event = new chrome.Event(eventName); | 262 chromeHidden.contextMenus.event = new chrome.Event(eventName); |
271 chromeHidden.contextMenus.ensureListenerSetup = function() { | 263 chromeHidden.contextMenus.ensureListenerSetup = function() { |
272 if (chromeHidden.contextMenus.listening) { | 264 if (chromeHidden.contextMenus.listening) { |
273 return; | 265 return; |
274 } | 266 } |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 var functions = ["onPageEvent", "onTabClose"]; | 538 var functions = ["onPageEvent", "onTabClose"]; |
547 functions.forEach(function(name) { | 539 functions.forEach(function(name) { |
548 // Event disambiguation is handled by name munging. See | 540 // Event disambiguation is handled by name munging. See |
549 // chrome/browser/extensions/extension_devtools_events.h for the C++ | 541 // chrome/browser/extensions/extension_devtools_events.h for the C++ |
550 // equivalent of this logic. | 542 // equivalent of this logic. |
551 tabIdProxy[name] = new chrome.Event("devtools." + tabId + "." + name); | 543 tabIdProxy[name] = new chrome.Event("devtools." + tabId + "." + name); |
552 }); | 544 }); |
553 return tabIdProxy; | 545 return tabIdProxy; |
554 }; | 546 }; |
555 | 547 |
556 apiFunctions["experimental.popup.show"].handleRequest = | |
557 function(url, showDetails, callback) { | |
558 // Second argument is a transform from HTMLElement to Rect. | |
559 var internalSchema = [ | |
560 this.definition.parameters[0], | |
561 { | |
562 type: "object", | |
563 name: "showDetails", | |
564 properties: { | |
565 domAnchor: { | |
566 type: "object", | |
567 properties: { | |
568 top: { type: "integer", minimum: 0 }, | |
569 left: { type: "integer", minimum: 0 }, | |
570 width: { type: "integer", minimum: 0 }, | |
571 height: { type: "integer", minimum: 0 } | |
572 } | |
573 }, | |
574 giveFocus: { | |
575 type: "boolean", | |
576 optional: true | |
577 }, | |
578 borderStyle: { | |
579 type: "string", | |
580 optional: true, | |
581 enum: ["bubble", "rectangle"] | |
582 }, | |
583 maxSize: { | |
584 type: "object", | |
585 optional: true, | |
586 properties: { | |
587 width: { | |
588 type: "integer", optional: true, minimum: 32 | |
589 }, | |
590 height: { | |
591 type: "integer", optional: true, minimum: 32 | |
592 } | |
593 } | |
594 } | |
595 } | |
596 }, | |
597 this.definition.parameters[2] | |
598 ]; | |
599 return sendRequest(this.name, | |
600 [url, | |
601 { | |
602 domAnchor: getAbsoluteRect(showDetails.relativeTo), | |
603 giveFocus: showDetails.giveFocus, | |
604 borderStyle: showDetails.borderStyle, | |
605 maxSize: showDetails.maxSize | |
606 }, | |
607 callback], | |
608 internalSchema); | |
609 }; | |
610 | |
611 apiFunctions["experimental.extension.getPopupView"].handleRequest = | |
612 function() { | |
613 return GetPopupView(); | |
614 }; | |
615 | |
616 apiFunctions["experimental.popup.getParentWindow"].handleRequest = | |
617 function() { | |
618 return GetPopupParentWindow(); | |
619 }; | |
620 | |
621 var canvas; | 548 var canvas; |
622 function setIconCommon(details, name, parameters, actionType, iconSize, | 549 function setIconCommon(details, name, parameters, actionType, iconSize, |
623 nativeFunction) { | 550 nativeFunction) { |
624 if ("iconIndex" in details) { | 551 if ("iconIndex" in details) { |
625 sendRequest(name, [details], parameters); | 552 sendRequest(name, [details], parameters); |
626 } else if ("imageData" in details) { | 553 } else if ("imageData" in details) { |
627 // Verify that this at least looks like an ImageData element. | 554 // Verify that this at least looks like an ImageData element. |
628 // Unfortunately, we cannot use instanceof because the ImageData | 555 // Unfortunately, we cannot use instanceof because the ImageData |
629 // constructor is not public. | 556 // constructor is not public. |
630 // | 557 // |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 } | 714 } |
788 return [requestId, suggestions]; | 715 return [requestId, suggestions]; |
789 }; | 716 }; |
790 | 717 |
791 if (chrome.test) { | 718 if (chrome.test) { |
792 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; | 719 chrome.test.getApiDefinitions = GetExtensionAPIDefinition; |
793 } | 720 } |
794 | 721 |
795 setupPageActionEvents(extensionId); | 722 setupPageActionEvents(extensionId); |
796 setupToolstripEvents(GetRenderViewId()); | 723 setupToolstripEvents(GetRenderViewId()); |
797 setupPopupEvents(GetRenderViewId()); | |
798 setupHiddenContextMenuEvent(extensionId); | 724 setupHiddenContextMenuEvent(extensionId); |
799 setupOmniboxEvents(); | 725 setupOmniboxEvents(); |
800 setupTtsEvents(); | 726 setupTtsEvents(); |
801 }); | 727 }); |
802 | 728 |
803 if (!chrome.experimental) | 729 if (!chrome.experimental) |
804 chrome.experimental = {}; | 730 chrome.experimental = {}; |
805 | 731 |
806 if (!chrome.experimental.accessibility) | 732 if (!chrome.experimental.accessibility) |
807 chrome.experimental.accessibility = {}; | 733 chrome.experimental.accessibility = {}; |
808 | 734 |
809 if (!chrome.experimental.tts) | 735 if (!chrome.experimental.tts) |
810 chrome.experimental.tts = {}; | 736 chrome.experimental.tts = {}; |
811 })(); | 737 })(); |
OLD | NEW |