Commit 22bb0f8b authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

FilesApp add support for QuickView in test.html

Add support in chrome.fileManagerPrivate.getFileTasks to return
file task 'view-in-browser' for a single text file.  This is
required by QuickView to determine that a text file can be shown.

Change QuickView-related files to use iframe rather than webview.
Note that this change is only used for testing parts of the UI.
Production code is unchanged and still uses webview for security.

Put files_quick_view.html path in constants so that it can be
overriden in test to use version of file with iframe vs webview.


Bug: 813477
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I5b8666a646ce979a99f065aa44a5c802b5420a32
Reviewed-on: https://chromium-review.googlesource.com/968102
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Reviewed-by: default avatarSasha Morrissey <sashab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549093}
parent 267cce4c
......@@ -53,3 +53,9 @@ constants.LIST_CONTAINER_METADATA_PREFETCH_PROPERTY_NAMES = [
'shared',
'size',
];
/**
* Path for files_quick_view.html file. Allow override for testing.
* @type {string}
*/
constants.FILES_QUICK_VIEW_HTML = 'foreground/elements/files_quick_view.html';
......@@ -172,12 +172,11 @@ QuickViewController.prototype.init_ = function(quickView) {
*/
QuickViewController.prototype.createQuickView_ = function() {
return new Promise(function(resolve, reject) {
Polymer.Base.importHref(
'foreground/elements/files_quick_view.html', function() {
var quickView = document.querySelector('#quick-view');
i18nTemplate.process(quickView, loadTimeData);
resolve(quickView);
}, reject);
Polymer.Base.importHref(constants.FILES_QUICK_VIEW_HTML, function() {
var quickView = document.querySelector('#quick-view');
i18nTemplate.process(quickView, loadTimeData);
resolve(quickView);
}, reject);
});
};
......
......@@ -70,7 +70,17 @@ chrome.fileManagerPrivate = {
},
getFileTasks: (entries, callback) => {
// Returns FileTask[].
setTimeout(callback, 0, []);
var results = [];
// Support for view-in-browser on single text file used by QuickView.
if (entries.length == 1 &&
entries[0].metadata.contentMimeType == 'text/plain') {
results.push({
taskId: '|file|view-in-browser',
title: '__MSG_OPEN_ACTION__',
isDefault: true,
});
}
setTimeout(callback, 0, results);
},
getPreferences: (callback) => {
setTimeout(callback, 0, chrome.fileManagerPrivate.preferences_);
......
......@@ -14,6 +14,7 @@ loadTimeData.data = new Proxy(
CHROMEOS_RELEASE_BOARD: 'unknown',
COPY_ITEMS_REMAINING: 'Copying $1 items...',
DEFAULT_NEW_FOLDER_NAME: 'New Folder',
DEFAULT_TASK_LABEL: '(default)',
DELETE_FILE_NAME: 'Deleting "$1"...',
DOWNLOADS_DIRECTORY_LABEL: 'Downloads',
DATE_COLUMN_LABEL: 'Date modified',
......@@ -51,6 +52,9 @@ loadTimeData.data = new Proxy(
INSTALL_NEW_EXTENSION_LABEL: 'Install new from the webstore',
MANY_ENTRIES_SELECTED: '$1 items selected',
MANY_FILES_SELECTED: '$1 files selected',
METADATA_BOX_ALBUM_TITLE: 'Album',
METADATA_BOX_MEDIA_MIME_TYPE: 'Type',
METADATA_BOX_MODIFICATION_TIME: 'Modified time',
NAME_COLUMN_LABEL: 'Name',
OFFLINE_COLUMN_LABEL: 'Available offline',
OK_LABEL: 'OK',
......@@ -96,6 +100,10 @@ loadTimeData.data = new Proxy(
var autoConvert = [
/^CLOUD_IMPORT_/,
/^DRIVE_SHARE_TYPE_/,
/^METADATA_BOX_EXIF_/,
/^METADATA_BOX_FILE_/,
/^METADATA_BOX_MEDIA_/,
/^METADATA_BOX_/,
/^QUICK_VIEW_/,
/^SHORTCUT_/,
/_BUTTON_LABEL$/,
......
......@@ -7,6 +7,9 @@
// All testing functions in namespace 'test'.
var test = test || {};
// Update paths for testing.
constants.FILES_QUICK_VIEW_HTML = 'test/gen/elements/files_quick_view.html';
// Stores Blobs loaded from src/chrome/test/data/chromeos/file_manager.
test.DATA = {
'archive.zip': null,
......
......@@ -142,6 +142,35 @@ main_html = replaceline(main_html, 'foreground/js/main_scripts.js', [
('<link rel="import" href="../../../third_party/polymer/v1_0/'
'components-chromium/polymer/polymer.html">')] + scripts)
# Load QuickView in iframe rather than webview.
# Change references in files_quick_view.html to use updated
# files_safe_media.html which will use webview rather than iframe,
# and sets src directly on iframe.
for filename, substitutions in (
('elements/files_quick_view.html', (
('="files_icon', '="../../../foreground/elements/files_icon'),
('="files_metadata', '="../../../foreground/elements/files_metadata'),
('="files_tooltip', '="../../../foreground/elements/files_tooltip'),
('="files_quick', '="../../../foreground/elements/files_quick'),
('="icons', '="../../../foreground/elements/icons'),
('webview', 'iframe'),
)),
('elements/files_safe_media.html', (('webview', 'iframe'),)),
('elements/files_safe_media.js', (
("'webview'", "'iframe'"),
("'contentload'", "'load'"),
('this.webview_.contentWindow.postMessage(data, FILES_APP_ORIGIN);',
('this.webview_.contentWindow.content.type = this.type;'
'this.webview_.contentWindow.content.src = this.src;')),
)),
):
buf = read('foreground/' + filename)
for old, new in substitutions:
buf = buf.replace(old, new)
write('test/gen/' + filename, GENERATED_JS + buf)
main_html = replaceline(main_html, 'foreground/' + filename,
['<script src="test/gen/%s"></script>' % filename])
test_html = GENERATED_HTML + '\n'.join(main_html)
write('test.html', test_html)
......
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