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 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1395 // Called by generated binding code if no value cached or isAttributeDirty() ret urns true | 1395 // Called by generated binding code if no value cached or isAttributeDirty() ret urns true |
1396 ScriptValue Object::attribute(ScriptExecutionContext* context) | 1396 ScriptValue Object::attribute(ScriptExecutionContext* context) |
1397 { | 1397 { |
1398 m_attributeDirty = false; | 1398 m_attributeDirty = false; |
1399 return convertDataToScriptValue(m_data); | 1399 return convertDataToScriptValue(m_data); |
1400 } | 1400 } |
1401 ``` | 1401 ``` |
1402 | 1402 |
1403 ### [CheckSecurity] _(i, m, a)_ | 1403 ### [CheckSecurity] _(i, m, a)_ |
1404 | 1404 |
1405 ### [DoNotCheckSecurity] _(m, a)_ | 1405 Summary: Check whether a given access is allowed or not in terms of the |
1406 | 1406 same-origin security policy. |
1407 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. | |
1408 | |
1409 If the security check is necessary, you should specify `[CheckSecurity]`. | |
1410 | 1407 |
1411 *** note | 1408 *** note |
1412 This is very important for security. | 1409 It is very important to use this attribute for interfaces and properties that |
1410 are exposed cross-origin! | |
1413 *** | 1411 *** |
1414 | 1412 |
1415 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). | 1413 Usage for interfaces: `[CheckSecurity=Receiver]` enables a security check for |
1416 | 1414 all methods of an interface. The security check verifies that the caller still |
dcheng
2016/11/02 09:07:41
I need to figure out what's going on here tomorrow
Yuki
2016/11/02 09:43:49
Based on the old (i.e. current) implementation, Wi
| |
1417 * `[DoNotCheckSecurity]` on a method disables the security check for the method. | 1415 has access to the receiver object of the method when it is invoked. This is |
1418 * `[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. | 1416 security-critical for interfaces that can be returned cross-origin, such as the |
1419 * `[DoNotCheckSecurity=Setter]` on an attribute disables the security check for a setter of the attribute, but not the getter. | 1417 Location or Window interface. |
1420 | 1418 |
1421 ```webidl | 1419 ```webidl |
1422 [ | 1420 [ |
1423 CheckSecurity=Frame, | 1421 CheckSecurity=Receiver, |
1424 ] interface DOMWindow { | 1422 ] interface DOMWindow { |
1425 attribute DOMString str1; | 1423 Selection? getSelection(); |
1426 [DoNotCheckSecurity] attribute DOMString str2; | |
1427 [DoNotCheckSecurity=Setter] attribute DOMString str3; | |
1428 void func1(); | |
1429 [DoNotCheckSecurity] void func2(); | |
1430 }; | 1424 }; |
1431 ``` | 1425 ``` |
1432 | 1426 |
1433 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. | 1427 Forgetting this attribute would make it possible to cache a method reference and |
1428 invoke it on a cross-origin object: | |
1434 | 1429 |
1435 `[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]`: | 1430 ```js |
1431 var iframe = document.body.appendChild(document.createElement('iframe')); | |
1432 var addEventListenerMethod = iframe.contentWindow.addEventListener; | |
1433 iframe.src = 'https://example.com'; | |
1434 iframe.onload = function () { | |
1435 addEventListenerMethod('pointermove', function (event) { | |
1436 event.target.ownerDocument.body.innerText = 'Text from a different origin.'; | |
1437 }); | |
1438 }; | |
dcheng
2016/11/02 09:07:41
I added some examples, because I didn't initially
| |
1439 ``` | |
1440 | |
1441 Usage for attributes and methods: `[CheckSecurity=ReturnValue]` enables a | |
1442 security check on that property. The security check verifies that the caller is | |
1443 allowed to access the returned value. If access is denied, the return value will | |
1444 be `undefined` and an exception will be raised. In practice, attribute uses are | |
1445 all `[readonly]`, and method uses are all `[RaisesException]`. | |
1436 | 1446 |
1437 ```webidl | 1447 ```webidl |
1438 [CheckSecurity=Node] readonly attribute Document contentDocument; | 1448 [CheckSecurity=ReturnValue] readonly attribute Document contentDocument; |
1439 [CheckSecurity=Node] SVGDocument getSVGDocument(); | 1449 [CheckSecurity=ReturnValue] SVGDocument getSVGDocument(); |
1440 ``` | 1450 ``` |
1441 | 1451 |
1442 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. | 1452 This is important because cross-origin access is not transitive. For example, if |
1453 `window` and `window.parent` are cross-origin, access to `window.parent` is | |
1454 allowed, but access to `window.parent.document` is not. | |
1455 | |
1456 ### [CrossOrigin] _(m, a)_ | |
1457 | |
1458 Summary: Allows cross-origin access to an attribute or method. Used for | |
1459 implementing [CrossOriginProperties] from the spec in Location.idl and | |
1460 Window.idl. | |
1461 | |
1462 Usage for methods: | |
1463 ```webidl | |
1464 [CrossOrigin] void blur(); | |
1465 ``` | |
1466 | |
1467 Note that setting this attribute on a method will disable [security | |
1468 checks](CheckSecurity), since this method can be invoked cross-origin. | |
1469 | |
1470 Usage for attributes: | |
1471 ```webidl | |
1472 [CrossOrigin] readonly attribute unsigned long length; | |
1473 ``` | |
1474 With no arguments, defaults to allowing cross-origin reads, but | |
1475 not cross-origin writes. | |
1476 | |
1477 ```webidl``` | |
1478 [CrossOrigin=Setter] attribute DOMString href; | |
1479 ``` | |
1480 With `Setter`, allows cross-origin writes, but not cross-origin reads. This is | |
1481 used for the `Location.href` attribute: cross-origin writes to this attribute | |
1482 are allowed, since it navigates the browsing context, but allowing cross-origin | |
1483 reads would leak cross-origin information. | |
1484 | |
1485 ```webidl``` | |
1486 [CrossOrigin=(Getter,Setter)] readonly attribute Location location; | |
1487 ``` | |
1488 With both `Getter` and `Setter`, allows both cross-origin reads and cross-origin | |
1489 writes. This is used for the `Window.location` attribute. | |
1443 | 1490 |
1444 ### [CustomConstructor] _(i)_ | 1491 ### [CustomConstructor] _(i)_ |
1445 | 1492 |
1446 Summary: They allow you to write custom bindings for constructors. | 1493 Summary: They allow you to write custom bindings for constructors. |
1447 | 1494 |
1448 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. | 1495 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. |
1449 | 1496 |
1450 ```webidl | 1497 ```webidl |
1451 [ | 1498 [ |
1452 CustomConstructor(float x, float y, optional DOMString str), | 1499 CustomConstructor(float x, float y, optional DOMString str), |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1605 Copyright (C) 2009 Apple Inc. All rights reserved. | 1652 Copyright (C) 2009 Apple Inc. All rights reserved. |
1606 | 1653 |
1607 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | 1654 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
1608 | 1655 |
1609 1. Redistributions of source code must retain the above copyright notice, this l ist of conditions and the following disclaimer. | 1656 1. Redistributions of source code must retain the above copyright notice, this l ist of conditions and the following disclaimer. |
1610 | 1657 |
1611 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. | 1658 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. |
1612 | 1659 |
1613 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. | 1660 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. |
1614 *** | 1661 *** |
1662 | |
1663 [CrossOriginProperties]: https://html.spec.whatwg.org/multipage/browsers.html#cr ossoriginproperties-(-o-) | |
dcheng
2016/11/02 09:07:41
I think this is more readable than having all the
| |
OLD | NEW |