diff options
author | rkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-06 07:12:48 +0000 |
---|---|---|
committer | rkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-06 07:12:48 +0000 |
commit | eead82943f187117b73d9d3fd8169b31f184a527 (patch) | |
tree | 9aff0e893203a0cd1b16af9c43a6f3ccdf93b5be /chrome/browser/resources/feedback.js | |
parent | a69d7afa15c08f361189aee67d7783db2f43a10f (diff) | |
download | chromium_src-eead82943f187117b73d9d3fd8169b31f184a527.zip chromium_src-eead82943f187117b73d9d3fd8169b31f184a527.tar.gz chromium_src-eead82943f187117b73d9d3fd8169b31f184a527.tar.bz2 |
Allow extensions to attach a file when invoking the feedback page.
This is specifically for the QuickOffice extension at the moment but any extension can use this functionality. By providing a "filePath" query parameter pointing to a local path on ChromeOS, an extension can provide an option to attach a file with the feedback report. By default this option is unchecked.
If a bogus path is given, when sending the report, we simply send no attachment.
R=jhawkins@chromium.org
BUG=169982
Review URL: https://chromiumcodereview.appspot.com/12221002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180921 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources/feedback.js')
-rw-r--r-- | chrome/browser/resources/feedback.js | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/chrome/browser/resources/feedback.js b/chrome/browser/resources/feedback.js index e42b879..b17cc19 100644 --- a/chrome/browser/resources/feedback.js +++ b/chrome/browser/resources/feedback.js @@ -16,6 +16,7 @@ savedThumbnailIds['current-screenshots'] = ''; savedThumbnailIds['saved-screenshots'] = ''; var categoryTag = ''; +var filePath = ''; var forceDisableScreenshots = false; @@ -24,6 +25,19 @@ var attachFileBinaryData = ''; var lastReader = null; /** + * Returns the base filename for a given path. Handles only Unix style paths. + * @param {string} path The path to return the basename for. + * @return {string} Basename for the path. + */ +function getBaseName(path) { + lastSeparator = path.lastIndexOf('/'); + if (lastSeparator == -1) + return ''; + else + return path.substr(lastSeparator + 1); +} + +/** * Selects an image thumbnail in the specified div. * @param {string} divId The id of the div to search in. * @param {string} thumbnailId The id of the thumbnail to search for. @@ -174,10 +188,15 @@ function sendReport() { } if ($('attach-file-checkbox') && - $('attach-file-checkbox').checked && - attachFileBinaryData) { - reportArray = reportArray.concat( - [$('attach-file').files[0].name, btoa(attachFileBinaryData)]); + $('attach-file-checkbox').checked) { + if (attachFileBinaryData) { + reportArray = reportArray.concat( + [$('attach-file').files[0].name, btoa(attachFileBinaryData)]); + } + } else if ($('attach-file-custom-checkbox') && + $('attach-file-custom-checkbox').checked) { + if (filePath) + reportArray = reportArray.concat([filePath, '']); } // open the landing page in a new tab, sendReport will close this one. @@ -284,6 +303,7 @@ function load() { 'description': '', 'categoryTag': '', 'customPageUrl': '', + 'filePath': '', }; var queryPos = window.location.hash.indexOf('?'); if (queryPos !== -1) { @@ -304,7 +324,7 @@ function load() { // If a page url is spcified in the parameters, override the default page url. if (parameters['customPageUrl'] != '') { $('page-url-text').value = parameters['customPageUrl']; - // and disable the page image, since it doesn't make sense on a custum url. + // and disable the page image, since it doesn't make sense on a custom url. $('screenshot-checkbox').checked = false; forceDisableScreenshots = true; } @@ -312,6 +332,30 @@ function load() { // Pick up the category tag (for most cases this will be an empty string) categoryTag = parameters['categoryTag']; + // Pick up the file path for the attached file (only user for this at the + // moment is the quick office extension). + filePath = parameters['filePath']; + + if (filePath != '') { + var baseName = getBaseName(filePath); + if (baseName) { + // Don't let the user choose another file, we were invoked by an + // extension already providing us the file, this report should only + // attach that file, or no file at all. + $('attach-file-container').hidden = true; + + // Set our filename and unhide the "Attach this file" span. + $('attach-file-custom-name').textContent = baseName; + $('attach-file-custom-container').hidden = false; + // No screenshots if we're being invoked by an extension - screenshot was + // never taken. + $('screenshot-checkbox').checked = false; + forceDisableScreenshots = true; + } else { + filePath = ''; + } + } + chrome.send('getDialogDefaults'); chrome.send('refreshCurrentScreenshot'); } |