Commit 34c2914b authored by Shik Chen's avatar Shik Chen Committed by Commit Bot

CCA: Import comlink library for WebWorker communication

Bug: 1058325
Test: Open CCA and check there is no error in console.
Change-Id: I1a5d944da3d6e2b266112601e436d08ee2ff0f3c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2108245Reviewed-by: default avatarWei Lee <wtlee@chromium.org>
Commit-Queue: Shik Chen <shik@chromium.org>
Auto-Submit: Shik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751276}
parent e92f78cf
google-analytics-bundle.js google-analytics-bundle.js
comlink.js
...@@ -140,6 +140,7 @@ copy("chrome_camera_app_js_device") { ...@@ -140,6 +140,7 @@ copy("chrome_camera_app_js_device") {
copy("chrome_camera_app_js_lib") { copy("chrome_camera_app_js_lib") {
sources = [ sources = [
"src/js/lib/comlink.js",
"src/js/lib/google-analytics-bundle.js", "src/js/lib/google-analytics-bundle.js",
] ]
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<structure name="IDR_CAMERA_CAMERA3_DEVICE_INFO_JS" file="src/js/device/camera3_device_info.js" type="chrome_html" /> <structure name="IDR_CAMERA_CAMERA3_DEVICE_INFO_JS" file="src/js/device/camera3_device_info.js" type="chrome_html" />
<structure name="IDR_CAMERA_CAMERA_JS" file="src/js/views/camera.js" type="chrome_html" /> <structure name="IDR_CAMERA_CAMERA_JS" file="src/js/views/camera.js" type="chrome_html" />
<structure name="IDR_CAMERA_CAMERA_INTENT_JS" file="src/js/views/camera_intent.js" type="chrome_html" /> <structure name="IDR_CAMERA_CAMERA_INTENT_JS" file="src/js/views/camera_intent.js" type="chrome_html" />
<structure name="IDR_CAMERA_COMLINK_JS" file="src/js/lib/comlink.js" type="chrome_html" />
<structure name="IDR_CAMERA_CONSTRAINTS_PREFERRER_JS" file="src/js/device/constraints_preferrer.js" type="chrome_html" /> <structure name="IDR_CAMERA_CONSTRAINTS_PREFERRER_JS" file="src/js/device/constraints_preferrer.js" type="chrome_html" />
<structure name="IDR_CAMERA_CHROME_HELPER_JS" file="src/js/mojo/chrome_helper.js" type="chrome_html" /> <structure name="IDR_CAMERA_CHROME_HELPER_JS" file="src/js/mojo/chrome_helper.js" type="chrome_html" />
<structure name="IDR_CAMERA_CHROME_UTIL_JS" file="src/js/chrome_util.js" type="chrome_html" /> <structure name="IDR_CAMERA_CHROME_UTIL_JS" file="src/js/chrome_util.js" type="chrome_html" />
......
# google-analytics-bundle.js # google-analytics-bundle.js
From https://github.com/googlearchive/chrome-platform-analytics * [Project Page](https://github.com/googlearchive/chrome-platform-analytics)
# comlink.js
* [Project Page](https://github.com/GoogleChromeLabs/comlink)
* The minified ES module build is get from [unpkg](https://unpkg.com/comlink@4.2.0/dist/esm/comlink.min.js).
// Copyright 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/* eslint-disable */
const e=Symbol("Comlink.proxy"),t=Symbol("Comlink.endpoint"),n=Symbol("Comlink.releaseProxy"),r=new WeakSet,a=new Map([["proxy",{canHandle:t=>t&&t[e],serialize(e){const{port1:t,port2:n}=new MessageChannel;return s(e,t),[n,[n]]},deserialize:e=>(e.start(),i(e))}],["throw",{canHandle:e=>r.has(e),serialize(e){const t=e instanceof Error;let n=e;return t&&(n={isError:t,message:e.message,stack:e.stack}),[n,[]]},deserialize(e){if(e.isError)throw Object.assign(new Error,e);throw e}}]]);function s(e,t=self){t.addEventListener("message",(function n(a){if(!a||!a.data)return;const{id:i,type:c,path:u}=Object.assign({path:[]},a.data),p=(a.data.argumentList||[]).map(h);let m;try{const t=u.slice(0,-1).reduce((e,t)=>e[t],e),n=u.reduce((e,t)=>e[t],e);switch(c){case 0:m=n;break;case 1:t[u.slice(-1)[0]]=h(a.data.value),m=!0;break;case 2:m=n.apply(t,p);break;case 3:m=d(new n(...p));break;case 4:{const{port1:t,port2:n}=new MessageChannel;s(e,n),m=l(t,[t])}break;case 5:m=void 0}}catch(e){m=e,r.add(e)}Promise.resolve(m).catch(e=>(r.add(e),e)).then(e=>{const[r,a]=g(e);t.postMessage(Object.assign(Object.assign({},r),{id:i}),a),5===c&&(t.removeEventListener("message",n),o(t))})})),t.start&&t.start()}function o(e){(function(e){return"MessagePort"===e.constructor.name})(e)&&e.close()}function i(e,r){return function e(r,a=[],s=function(){}){let i=!1;const p=new Proxy(s,{get(t,s){if(c(i),s===n)return()=>f(r,{type:5,path:a.map(e=>e.toString())}).then(()=>{o(r),i=!0});if("then"===s){if(0===a.length)return{then:()=>p};const e=f(r,{type:0,path:a.map(e=>e.toString())}).then(h);return e.then.bind(e)}return e(r,[...a,s])},set(e,t,n){c(i);const[s,o]=g(n);return f(r,{type:1,path:[...a,t].map(e=>e.toString()),value:s},o).then(h)},apply(n,s,o){c(i);const p=a[a.length-1];if(p===t)return f(r,{type:4}).then(h);if("bind"===p)return e(r,a.slice(0,-1));const[l,d]=u(o);return f(r,{type:2,path:a.map(e=>e.toString()),argumentList:l},d).then(h)},construct(e,t){c(i);const[n,s]=u(t);return f(r,{type:3,path:a.map(e=>e.toString()),argumentList:n},s).then(h)}});return p}(e,[],r)}function c(e){if(e)throw new Error("Proxy has been released and is not useable")}function u(e){const t=e.map(g);return[t.map(e=>e[0]),(n=t.map(e=>e[1]),Array.prototype.concat.apply([],n))];var n}const p=new WeakMap;function l(e,t){return p.set(e,t),e}function d(t){return Object.assign(t,{[e]:!0})}function m(e,t=self,n="*"){return{postMessage:(t,r)=>e.postMessage(t,n,r),addEventListener:t.addEventListener.bind(t),removeEventListener:t.removeEventListener.bind(t)}}function g(e){for(const[t,n]of a)if(n.canHandle(e)){const[r,a]=n.serialize(e);return[{type:3,name:t,value:r},a]}return[{type:0,value:e},p.get(e)||[]]}function h(e){switch(e.type){case 3:return a.get(e.name).deserialize(e.value);case 0:return e.value}}function f(e,t,n){return new Promise(r=>{const a=new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-");e.addEventListener("message",(function t(n){n.data&&n.data.id&&n.data.id===a&&(e.removeEventListener("message",t),r(n.data))})),e.start&&e.start(),e.postMessage(Object.assign({id:a},t),n)})}export{t as createEndpoint,s as expose,d as proxy,e as proxyMarker,n as releaseProxy,l as transfer,a as transferHandlers,m as windowEndpoint,i as wrap};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment