OLD | NEW |
1 # Blink IDL Extended Attributes | 1 # Blink IDL Extended Attributes |
2 | 2 |
3 [TOC] | 3 [TOC] |
4 | 4 |
5 ## Introduction | 5 ## Introduction |
6 | 6 |
7 The main interest in extended attributes are their _semantics_: Blink implements
many more extended attributes than the Web IDL standard, to specify various beh
avior. | 7 The main interest in extended attributes are their _semantics_: Blink implements
many more extended attributes than the Web IDL standard, to specify various beh
avior. |
8 | 8 |
9 The authoritative list of allowed extended attributes and values is [bindings/ID
LExtendedAttributes.txt](https://code.google.com/p/chromium/codesearch#chromium/
src/third_party/WebKit/Source/bindings/IDLExtendedAttributes.txt). This is compl
ete but not necessarily precise (there may be unused extended attributes or valu
es), since validation is run on build, but coverage isn't checked. | 9 The authoritative list of allowed extended attributes and values is [bindings/ID
LExtendedAttributes.txt](https://code.google.com/p/chromium/codesearch#chromium/
src/third_party/WebKit/Source/bindings/IDLExtendedAttributes.txt). This is compl
ete but not necessarily precise (there may be unused extended attributes or valu
es), since validation is run on build, but coverage isn't checked. |
10 | 10 |
(...skipping 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 // Called by generated binding code if no value cached or isAttributeDirty() ret
urns true | 1381 // Called by generated binding code if no value cached or isAttributeDirty() ret
urns true |
1382 ScriptValue Object::attribute(ExecutionContext* context) | 1382 ScriptValue Object::attribute(ExecutionContext* context) |
1383 { | 1383 { |
1384 m_attributeDirty = false; | 1384 m_attributeDirty = false; |
1385 return convertDataToScriptValue(m_data); | 1385 return convertDataToScriptValue(m_data); |
1386 } | 1386 } |
1387 ``` | 1387 ``` |
1388 | 1388 |
1389 ### [CheckSecurity] _(i, m, a)_ | 1389 ### [CheckSecurity] _(i, m, a)_ |
1390 | 1390 |
1391 ### [DoNotCheckSecurity] _(m, a)_ | 1391 Summary: Check whether a given access is allowed or not in terms of the |
1392 | 1392 same-origin security policy. |
1393 Summary: Check whether a given access is allowed or not, in terms of the same-or
igin security policy. Used in Location.idl, Window.idl, and a few HTML*Element.i
dl. | |
1394 | |
1395 If the security check is necessary, you should specify `[CheckSecurity]`. | |
1396 | 1393 |
1397 *** note | 1394 *** note |
1398 This is very important for security. | 1395 It is very important to use this attribute for interfaces and properties that |
| 1396 are exposed cross-origin! |
1399 *** | 1397 *** |
1400 | 1398 |
1401 Usage: `[CheckSecurity=Frame]` can be specified on interfaces, which enables a _
frame_ security check for all members (methods and attributes) of the interface.
This can then be selectively disabled with `[DoNotCheckSecurity]`; this is only
done in Location.idl and Window.idl. On attributes, `[DoNotCheckSecurity]` take
s an optional identifier, as `[DoNotCheckSecurity=Setter]` (used only one place,
Location.href, since setting `href` _changes_ the page, which is ok, but readin
g `href` leaks information). | 1399 Usage for interfaces: `[CheckSecurity=Receiver]` enables a security check for |
1402 | 1400 all methods of an interface. The security check verifies that the caller still |
1403 * `[DoNotCheckSecurity]` on a method disables the security check for the method. | 1401 has access to the receiver object of the method when it is invoked. This is |
1404 * `[DoNotCheckSecurity]` on an attribute disables the security check for a gette
r and setter of the attribute; for read only attributes this is just the getter. | 1402 security-critical for interfaces that can be returned cross-origin, such as the |
1405 * `[DoNotCheckSecurity=Setter]` on an attribute disables the security check for
a setter of the attribute, but not the getter. | 1403 Location or Window interface. |
1406 | 1404 |
1407 ```webidl | 1405 ```webidl |
1408 [ | 1406 [ |
1409 CheckSecurity=Frame, | 1407 CheckSecurity=Receiver, |
1410 ] interface DOMWindow { | 1408 ] interface DOMWindow { |
1411 attribute DOMString str1; | 1409 Selection? getSelection(); |
1412 [DoNotCheckSecurity] attribute DOMString str2; | |
1413 [DoNotCheckSecurity=Setter] attribute DOMString str3; | |
1414 void func1(); | |
1415 [DoNotCheckSecurity] void func2(); | |
1416 }; | 1410 }; |
1417 ``` | 1411 ``` |
1418 | 1412 |
1419 Consider the case where you access `window.parent` from inside an iframe that co
mes from a different origin. While it is allowed to access window.parent, it is
not allowed to access `window.parent.document`. In such cases, you need to speci
fy `[CheckSecurity]` in order to check whether a given DOM object is allowed to
access the attribute or method, in terms of the same-origin security policy. | 1413 Forgetting this attribute would make it possible to cache a method reference and |
| 1414 invoke it on a cross-origin object: |
1420 | 1415 |
1421 `[CheckSecurity=Node]` can be specified on methods and attributes, which enables
a _node_ security check on that member. In practice all attribute uses are read
only, and method uses all also have `[RaisesException]`: | 1416 ```js |
| 1417 var iframe = document.body.appendChild(document.createElement('iframe')); |
| 1418 var addEventListenerMethod = iframe.contentWindow.addEventListener; |
| 1419 iframe.src = 'https://example.com'; |
| 1420 iframe.onload = function () { |
| 1421 addEventListenerMethod('pointermove', function (event) { |
| 1422 event.target.ownerDocument.body.innerText = 'Text from a different origin.'; |
| 1423 }); |
| 1424 }; |
| 1425 ``` |
| 1426 |
| 1427 Usage for attributes and methods: `[CheckSecurity=ReturnValue]` enables a |
| 1428 security check on that property. The security check verifies that the caller is |
| 1429 allowed to access the returned value. If access is denied, the return value will |
| 1430 be `undefined` and an exception will be raised. In practice, attribute uses are |
| 1431 all `[readonly]`, and method uses are all `[RaisesException]`. |
1422 | 1432 |
1423 ```webidl | 1433 ```webidl |
1424 [CheckSecurity=Node] readonly attribute Document contentDocument; | 1434 [CheckSecurity=ReturnValue] readonly attribute Document contentDocument; |
1425 [CheckSecurity=Node] SVGDocument getSVGDocument(); | 1435 [CheckSecurity=ReturnValue] SVGDocument getSVGDocument(); |
1426 ``` | 1436 ``` |
1427 | 1437 |
1428 In terms of the same-origin security policy, node.contentDocument should return
undefined if the parent frame and the child frame are from different origins. | 1438 This is important because cross-origin access is not transitive. For example, if |
| 1439 `window` and `window.parent` are cross-origin, access to `window.parent` is |
| 1440 allowed, but access to `window.parent.document` is not. |
| 1441 |
| 1442 ### [CrossOrigin] _(m, a)_ |
| 1443 |
| 1444 Summary: Allows cross-origin access to an attribute or method. Used for |
| 1445 implementing [CrossOriginProperties] from the spec in Location.idl and |
| 1446 Window.idl. |
| 1447 |
| 1448 Usage for methods: |
| 1449 ```webidl |
| 1450 [CrossOrigin] void blur(); |
| 1451 ``` |
| 1452 |
| 1453 Note that setting this attribute on a method will disable [security |
| 1454 checks](#_CheckSecurity_i_m_a_), since this method can be invoked cross-origin. |
| 1455 |
| 1456 Usage for attributes: |
| 1457 ```webidl |
| 1458 [CrossOrigin] readonly attribute unsigned long length; |
| 1459 ``` |
| 1460 With no arguments, defaults to allowing cross-origin reads, but |
| 1461 not cross-origin writes. |
| 1462 |
| 1463 ```webidl |
| 1464 [CrossOrigin=Setter] attribute DOMString href; |
| 1465 ``` |
| 1466 With `Setter`, allows cross-origin writes, but not cross-origin reads. This is |
| 1467 used for the `Location.href` attribute: cross-origin writes to this attribute |
| 1468 are allowed, since it navigates the browsing context, but allowing cross-origin |
| 1469 reads would leak cross-origin information. |
| 1470 |
| 1471 ```webidl |
| 1472 [CrossOrigin=(Getter,Setter)] readonly attribute Location location; |
| 1473 ``` |
| 1474 With both `Getter` and `Setter`, allows both cross-origin reads and cross-origin |
| 1475 writes. This is used for the `Window.location` attribute. |
1429 | 1476 |
1430 ### [CustomConstructor] _(i)_ | 1477 ### [CustomConstructor] _(i)_ |
1431 | 1478 |
1432 Summary: They allow you to write custom bindings for constructors. | 1479 Summary: They allow you to write custom bindings for constructors. |
1433 | 1480 |
1434 Usage: They can be specified on interfaces. _Strongly discouraged._ As with `[Cu
stom]`, it is generally better to modify the code generator. Incompatible with `
[Constructor]` – you cannot mix custom constructors and generated constructors. | 1481 Usage: They can be specified on interfaces. _Strongly discouraged._ As with `[Cu
stom]`, it is generally better to modify the code generator. Incompatible with `
[Constructor]` – you cannot mix custom constructors and generated constructors. |
1435 | 1482 |
1436 ```webidl | 1483 ```webidl |
1437 [ | 1484 [ |
1438 CustomConstructor(float x, float y, optional DOMString str), | 1485 CustomConstructor(float x, float y, optional DOMString str), |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1622 Copyright (C) 2009 Apple Inc. All rights reserved. | 1669 Copyright (C) 2009 Apple Inc. All rights reserved. |
1623 | 1670 |
1624 Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met: | 1671 Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met: |
1625 | 1672 |
1626 1. Redistributions of source code must retain the above copyright notice, this l
ist of conditions and the following disclaimer. | 1673 1. Redistributions of source code must retain the above copyright notice, this l
ist of conditions and the following disclaimer. |
1627 | 1674 |
1628 2. Redistributions in binary form must reproduce the above copyright notice, thi
s list of conditions and the following disclaimer in the documentation and/or ot
her materials provided with the distribution. | 1675 2. Redistributions in binary form must reproduce the above copyright notice, thi
s list of conditions and the following disclaimer in the documentation and/or ot
her materials provided with the distribution. |
1629 | 1676 |
1630 THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS “AS IS” AND ANY EXP
RESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIE
S OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, I
NCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMI
TED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFI
TS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHE
THER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
BILITY OF SUCH DAMAGE. | 1677 THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS “AS IS” AND ANY EXP
RESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIE
S OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, I
NCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMI
TED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFI
TS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHE
THER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
BILITY OF SUCH DAMAGE. |
1631 *** | 1678 *** |
| 1679 |
| 1680 [CrossOriginProperties]: https://html.spec.whatwg.org/multipage/browsers.html#cr
ossoriginproperties-(-o-) |
OLD | NEW |