Commit 239ef678 authored by Kuo Jen Wei's avatar Kuo Jen Wei Committed by Commit Bot

[CCA] Copy chrome://resources/js/assert.js to chrome_util.js

Currently, chrome resources domain is not accessible from packed crx CCA
signed with dev key. This CL is a workaround by copying those used
function to chrome_util.js.

Bug: b/144748372
Test: Both CCA and CCA installed from packed crx function normally.
Change-Id: I6329eaee53a1ba71fb3c9ea09c570b1437b2ebc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1925841
Commit-Queue: Kuo Jen Wei <inker@chromium.org>
Auto-Submit: Kuo Jen Wei <inker@chromium.org>
Reviewed-by: default avatarShik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#716945}
parent 1761758a
......@@ -113,6 +113,7 @@ copy("chrome_camera_app_images") {
copy("chrome_camera_app_js") {
sources = [
"src/js/background.js",
"src/js/chrome_util.js",
"src/js/gallerybutton.js",
"src/js/google-analytics-bundle.js",
"src/js/intent.js",
......
......@@ -20,6 +20,7 @@
<structure name="IDR_CAMERA_CAMERA_INTENT_JS" file="src/js/views/camera_intent.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_UTIL_JS" file="src/js/chrome_util.js" type="chrome_html" />
<structure name="IDR_CAMERA_DEVICE_OPERATOR_JS" file="src/js/mojo/device_operator.js" type="chrome_html" />
<structure name="IDR_CAMERA_DEVICE_INFO_UPDATER_JS" file="src/js/device/device_info_updater.js" type="chrome_html" />
<structure name="IDR_CAMERA_DIALOG_JS" file="src/js/views/dialog.js" type="chrome_html" />
......
......@@ -18,6 +18,7 @@ group("closure_compile") {
js_type_check("compile_resources") {
deps = [
":background",
":chrome_util",
":intent",
":metrics",
":nav",
......@@ -30,6 +31,9 @@ js_type_check("compile_resources") {
]
}
js_library("chrome_util") {
}
js_library("intent") {
deps = [
"mojo:chrome_helper",
......
// Copyright (c) 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
* @fileoverview Utility functions copied from chrome://resources/js.
* TODO(inker): Reference these functions directly from chrome://resources/js.
*/
/* eslint-disable */
/**
* Verify |condition| is truthy and return |condition| if so.
* @template T
* @param {T} condition A condition to check for truthiness. Note that this
* may be used to test whether a value is defined or not, and we don't want
* to force a cast to Boolean.
* @param {string=} opt_message A message to show on failure.
* @return {T} A non-null |condition|.
* @closurePrimitive {asserts.truthy}
*/
/* #export */ function assert(condition, opt_message) {
if (!condition) {
let message = 'Assertion failed';
if (opt_message) {
message = message + ': ' + opt_message;
}
const error = new Error(message);
const global = function() {
const thisOrSelf = this || self;
/** @type {boolean} */
thisOrSelf.traceAssertionsForTesting;
return thisOrSelf;
}();
if (global.traceAssertionsForTesting) {
console.warn(error.stack);
}
throw error;
}
return condition;
}
/**
* Call this from places in the code that should never be reached.
*
* For example, handling all the values of enum with a switch() like this:
*
* function getValueFromEnum(enum) {
* switch (enum) {
* case ENUM_FIRST_OF_TWO:
* return first
* case ENUM_LAST_OF_TWO:
* return last;
* }
* assertNotReached();
* return document;
* }
*
* This code should only be hit in the case of serious programmer error or
* unexpected input.
*
* @param {string=} opt_message A message to show when this is hit.
* @closurePrimitive {asserts.fail}
*/
/* #export */ function assertNotReached(opt_message) {
assert(false, opt_message || 'Unreachable code hit');
}
/**
* @param {*} value The value to check.
* @param {function(new: T, ...)} type A user-defined constructor.
* @param {string=} opt_message A message to show when this is hit.
* @return {T}
* @template T
*/
/* #export */ function assertInstanceof(value, type, opt_message) {
// We don't use assert immediately here so that we avoid constructing an error
// message if we don't have to.
if (!(value instanceof type)) {
assertNotReached(
opt_message ||
'Value ' + value + ' is not a[n] ' + (type.name || typeof type));
}
return value;
}
......@@ -22,8 +22,8 @@ js_type_check("compile_resources") {
js_library("layout") {
deps = [
"../..:chrome_util",
"../..:type",
"//ui/webui/resources/js:assert",
]
}
......
......@@ -25,7 +25,7 @@ cca.views.camera = cca.views.camera || {};
var Resolution = Resolution || {};
/**
* import {assert} from 'chrome://resources/js/assert.js';
* import {assert} from '../chrome_util.js';
*/
var assert = assert || {};
......
......@@ -21,8 +21,7 @@
"fileManagerPrivate",
"fileSystem.requestDownloads",
{"fileSystem": ["write", "directory"]},
"https://www.google-analytics.com/",
"chrome://resources/"
"https://www.google-analytics.com/"
],
"app": {
"background": {
......@@ -34,7 +33,6 @@
"js/intent.js",
"js/background.js"
]
},
"content_security_policy": "script-src 'self' chrome://resources;"
}
}
}
......@@ -9,7 +9,7 @@
<title>&#xfeff;</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../css/main.css">
<script src="chrome://resources/js/assert.js"></script>
<script src="../js/chrome_util.js"></script>
<script src="../js/browser_proxy/browser_proxy.js"></script>
<script src="../js/google-analytics-bundle.js"></script>
<script src="../js/type.js"></script>
......
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