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