Re: [w3c/payment-handler] Add ImageObject dictionary. (#174)

romandev commented on this pull request.



> @@ -695,6 +695,21 @@
             When called, this method executes the following steps:
           </p>
           <ol>
+            <li>If the <a data-lt="PaymentInstrument.icons">icons</a> member of
+            <var>details</var> is present, then for each <var>icon</var> in
+            <var>details</var>.<a data-lt="PaymentInstrument.icons">icons</a>:
+              <ol>
+                <li>If <var>icon</var>.<a data-lt="ImageObject.type">type</a>
+                is not a <a data-cite="#valid-mime-type">valid MIME type</a> or
+                the value of type is not a supported media format, then return
+                a <a>Promise</a> rejected with a <a>TypeError</a>.
+                </li>
+                <li>If <var>icon</var>.<a data-lt="ImageObject.sizes">sizes</a>
+                is not a <a data-lt="ImageObject.sizes">valid value</a>, then
+                return a <a>Promise</a> rejected with a <a>TypeError</a>.
+                </li>
+              </ol>
+            </li>

@ianbjacobs,

Sorry for delayed reply. I missed this comment.
IMHO, the following parsing step is enough to explain how the relative url should be resolved clearly.
 
> parsing image.src with the context object's relevant settings object's API base URL.
 
The ImageObject is used during PaymentInstrument.set().
BTW, the PaymentInstrument is an extension of ServiceWorkerRegistration.
So, we can access it in both of window global context and worker context but only need to consider which context the API is running on.

**"the context object's relevant settings object's API base URL"**

It means that..
If the top level window, then the base url is window's location url without filename.
If it is an iframe, then the base url is iframe's url without filename.
If it is a worker, then the base url is script_url without filename.

For example, we can run PaymentInstrument.set() in window global context.
```
<script>
// https://www.example.com/abcd/test.html
navigator.seviceWorker.register(...)
    ...
    .then(registration) {
        registration.paymentManager.paymentInstrument.set({
            name: "Test Pay",
            icons: {
                src: '../icon.png'    /* https://www.example.com/icon.png */
            }
        });
    }
</script>
```

If its context is iframe, no problems.
```
<!-- https://www.example.com/abcd/efgh/index.html -->
<iframe src="https://www.example.com/abcd/efgh/iframe.html"></iframe>
```
```
<script>
// This is an iframe: https://www.example.com/abcd/efgh/iframe.html
navigator.seviceWorker.register(...)
    ...
    .then(registration) {
        registration.paymentManager.paymentInstrument.set({
            name: "Test Pay",
            icons: {
                src: '../icon.png'    /* https://www.example.com/abcd/icon.png */
            }
        });
    }
</script>
```

In a case of worker context,
```
// https://www.example.com/abcd/efgh/sw/pay.js
registration.paymentManager.paymentInstrument.set({
    name: "Test Pay",
    icons: {
        src: '../icon.png'    /* https://www.example.com/abcd/efgh/icon.png */
    }
});
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/payment-handler/pull/174#discussion_r121707229

Received on Tuesday, 13 June 2017 15:10:57 UTC