summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-30 06:16:12 +0000
committerzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-30 06:16:12 +0000
commit04152c3fc346cbbf0be4c710cd12c6c5aba4c8c4 (patch)
tree31c31959ec6cc6dd698f8946553b35ffed8dfc80
parent15ffba6db31d6ce298f8eaa1d2eb482102d0b06c (diff)
downloadchromium_src-04152c3fc346cbbf0be4c710cd12c6c5aba4c8c4.zip
chromium_src-04152c3fc346cbbf0be4c710cd12c6c5aba4c8c4.tar.gz
chromium_src-04152c3fc346cbbf0be4c710cd12c6c5aba4c8c4.tar.bz2
Open the default task on double-click if browser can't handle the file natively.
BUG=chromium-os:18400 TEST=double click on a file handed by an extension Review URL: http://codereview.chromium.org/8631003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112136 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/generated_resources.grd73
-rw-r--r--chrome/browser/extensions/extension_file_browser_private_api.cc16
-rw-r--r--chrome/browser/extensions/file_manager_util.cc38
-rw-r--r--chrome/browser/extensions/file_manager_util.h7
-rw-r--r--chrome/browser/platform_util_chromeos.cc2
-rw-r--r--chrome/browser/resources/file_manager/js/file_manager.js38
-rw-r--r--chrome/browser/resources/shared/css/dialogs.css10
-rw-r--r--chrome/browser/resources/shared/js/cr/ui/dialogs.js16
-rw-r--r--chrome/browser/ui/webui/active_downloads_ui.cc2
-rw-r--r--chrome/common/extensions/api/extension_api.json12
10 files changed, 121 insertions, 93 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 944c723..37e077f9 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -10095,6 +10095,19 @@ Keep your key file in a safe place. You will need it to create new versions of y
PDF document
</message>
+ <message name="IDS_FILE_BROWSER_ENQUEUE" desc="Enqueue file menu item used for media playback">
+ Enqueue
+ </message>
+ <message name="IDS_FILE_BROWSER_ERROR_VIEWING_FILE_TITLE" desc="Title of error message propmt when user attempts to open a non-supported file in file browser.">
+ <ph name="FILENAME">$1</ph>
+ </message>
+ <message name="IDS_FILE_BROWSER_ERROR_VIEWING_FILE" desc="Error message when user attempts to open a non-supported file in file browser.">
+ To view this file, convert it to a format that's viewable on the web. For example, you can upload it to Google Docs.
+ </message>
+ <message name="IDS_FILE_BROWSER_ERROR_UNKNOWN_FILE_TYPE" desc="Error message when user attempts to open a file of unknown type in file browser.">
+ <ph name="FILENAME">$1</ph> - Unknown file type.
+ </message>
+
<!-- Bookmark manager -->
<message name="IDS_BOOKMARK_MANAGER_TITLE" desc="Title of the bookmark manager window.">
Bookmark Manager
@@ -11508,66 +11521,6 @@ Keep your key file in a safe place. You will need it to create new versions of y
Access to local files on your machine is disabled by your administrator.
</message>
- <!-- Filebrowser Strings -->
- <message name="IDS_FILEBROWSER_TITLE" desc="Title of the filebrowser">
- Content Browser
- </message>
- <message name="IDS_FILEBROWSER_PAUSE" desc="Action which allows the user to pause a current download">
- pause
- </message>
- <message name="IDS_FILEBROWSER_RESUME" desc="Action which allows the user to resume a paused download">
- resume
- </message>
- <message name="IDS_FILEBROWSER_SCANNING" desc="Notification to the user that we have detected a device and are now mounting it">
- Scanning Device...
- </message>
- <message name="IDS_FILEBROWSER_CONFIRM_YES" desc="Confirm yes to a previous question.">
- Yes
- </message>
- <message name="IDS_FILEBROWSER_CONFIRM_CANCEL" desc="Cancel a previous question.">
- Cancel
- </message>
- <message name="IDS_FILEBROWSER_CONFIRM_DOWNLOAD" desc="Used to download a dangerous file.">
- Allow Download?
- </message>
- <message name="IDS_FILEBROWSER_PROMPT_FILENAME" desc="Prompts the user for a filename.">
- File name:
- </message>
- <message name="IDS_FILEBROWSER_SAVE" desc="Save button text">
- Save
- </message>
- <message name="IDS_FILEBROWSER_NEW_FOLDER" desc="New Folder Button">
- New Folder
- </message>
- <message name="IDS_FILEBROWSER_OPEN" desc="Open Button text">
- Open
- </message>
- <message name="IDS_FILEBROWSER_UPLOAD_EMAIL" desc="Upload to email menu item">
- Email
- </message>
- <message name="IDS_FILEBROWSER_DELETE" desc="Delete file menu item">
- Delete
- </message>
- <message name="IDS_FILEBROWSER_ENQUEUE" desc="Enqueue file menu item used for media playback">
- Enqueue
- </message>
- <message name="IDS_FILEBROWSER_ERROR_TITLE" desc="Title text of an error message prompt.">
- Error
- </message>
- <message name="IDS_FILEBROWSER_ERROR_VIEWING_FILE_TITLE" desc="Title of error message propmt when user attempts to open a non-supported file in file browser.">
- <ph name="FILENAME">$1</ph>
- </message>
- <message name="IDS_FILEBROWSER_ERROR_VIEWING_FILE" desc="Error message when user attempts to open a non-supported file in file browser.">
- To view this file, convert it to a format that's viewable on the web. For example, you can upload it to Google Docs.
- </message>
- <message name="IDS_FILEBROWSER_ERROR_UNKNOWN_FILE_TYPE" desc="Error message when user attempts to open a file of unknown type in file browser.">
- <ph name="FILENAME">$1</ph> - Unknown file type.
- </message>
- <message name="IDS_FILEBROWSER_SHOW_ALL_DOWNLOADS"
- desc="Link label shown at the bottom of the downloads panel">
- Show all downloads
- </message>
-
<!-- Status Area Strings (not ChromeOS specifc) -->
<message name="IDS_STATUSBAR_CLOCK_OPEN_OPTIONS_DIALOG" desc="The menu item in the clock menu button for opening the options dialog">
Open date and time options...
diff --git a/chrome/browser/extensions/extension_file_browser_private_api.cc b/chrome/browser/extensions/extension_file_browser_private_api.cc
index db22b12..7c36dae 100644
--- a/chrome/browser/extensions/extension_file_browser_private_api.cc
+++ b/chrome/browser/extensions/extension_file_browser_private_api.cc
@@ -1121,14 +1121,19 @@ void ViewFilesFunction::GetLocalPathsResponseOnUIThread(
const std::string& internal_task_id,
const FilePathList& files) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ bool success = true;
for (FilePathList::const_iterator iter = files.begin();
iter != files.end();
++iter) {
- file_manager_util::ViewItem(*iter,
- internal_task_id == kEnqueueTaskId ||
- // Start the first one, enqueue others.
- iter != files.begin());
+ bool handled = file_manager_util::TryViewingFile(*iter,
+ // Start the first one, enqueue others.
+ internal_task_id == kEnqueueTaskId || iter != files.begin());
+ // If there is no default browser-defined handler for viewing this type
+ // of file, try to see if we have any extension installed for it instead.
+ if (!handled && files.size() == 1)
+ success = false;
}
+ result_.reset(Value::CreateBooleanValue(success));
SendResponse(true);
}
@@ -1630,6 +1635,7 @@ bool FileDialogStringsFunction::RunImpl() {
SET_STRING(IDS_FILE_BROWSER, MANY_ENTRIES_SELECTED);
SET_STRING(IDS_FILE_BROWSER, PLAYBACK_ERROR);
+ SET_STRING(IDS_FILE_BROWSER, ERROR_VIEWING_FILE);
// MP3 metadata extractor plugin
SET_STRING(IDS_FILE_BROWSER, ID3_ALBUM); // TALB
@@ -1667,7 +1673,7 @@ bool FileDialogStringsFunction::RunImpl() {
SET_STRING(IDS_FILE_BROWSER, PLAIN_TEXT_FILE_TYPE);
SET_STRING(IDS_FILE_BROWSER, PDF_DOCUMENT_FILE_TYPE);
- SET_STRING(IDS_FILEBROWSER, ENQUEUE);
+ SET_STRING(IDS_FILE_BROWSER, ENQUEUE);
#undef SET_STRING
// TODO(serya): Create a new string in .grd file for this one in M13.
diff --git a/chrome/browser/extensions/file_manager_util.cc b/chrome/browser/extensions/file_manager_util.cc
index 180fd70..b3d344e 100644
--- a/chrome/browser/extensions/file_manager_util.cc
+++ b/chrome/browser/extensions/file_manager_util.cc
@@ -283,19 +283,28 @@ void ViewFolder(const FilePath& dir) {
browser->ShowSingletonTabRespectRef(GURL(url));
}
-void ViewItem(const FilePath& full_path, bool enqueue) {
- if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
- bool result = BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&ViewItem, full_path, enqueue));
- DCHECK(result);
- return;
+void ViewFile(const FilePath& full_path, bool enqueue) {
+ if (!TryViewingFile(full_path, enqueue)) {
+ Browser* browser = BrowserList::GetLastActive();
+ if (!browser)
+ return;
+ browser::ShowErrorBox(
+ browser->window()->GetNativeHandle(),
+ l10n_util::GetStringFUTF16(
+ IDS_FILE_BROWSER_ERROR_VIEWING_FILE_TITLE,
+ UTF8ToUTF16(full_path.BaseName().value())),
+ l10n_util::GetStringUTF16(
+ IDS_FILE_BROWSER_ERROR_VIEWING_FILE));
}
+}
+
+bool TryViewingFile(const FilePath& full_path, bool enqueue) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// There is nothing we can do if the browser is not present.
Browser* browser = BrowserList::GetLastActive();
if (!browser)
- return;
+ return true;
std::string ext = full_path.Extension();
// For things supported natively by the browser, we should open it
@@ -306,7 +315,7 @@ void ViewItem(const FilePath& full_path, bool enqueue) {
path = "file://";
path.append(net::EscapeUrlEncodedData(full_path.value(), false));
browser->AddSelectedTabWithURL(GURL(path), content::PAGE_TRANSITION_LINK);
- return;
+ return true;
}
#if defined(OS_CHROMEOS)
if (IsSupportedAVExtension(ext.data())) {
@@ -323,7 +332,7 @@ void ViewItem(const FilePath& full_path, bool enqueue) {
mediaplayer->PopupMediaPlayer(browser);
mediaplayer->ForcePlayMediaFile(browser->profile(), full_path);
}
- return;
+ return true;
}
#endif // OS_CHROMEOS
@@ -334,14 +343,7 @@ void ViewItem(const FilePath& full_path, bool enqueue) {
UMA_HISTOGRAM_ENUMERATION("FileBrowser.OpeningFileType",
extension_index,
arraysize(kUMATrackingExtensions) - 1);
-
- browser::ShowErrorBox(
- browser->window()->GetNativeHandle(),
- l10n_util::GetStringFUTF16(
- IDS_FILEBROWSER_ERROR_VIEWING_FILE_TITLE,
- UTF8ToUTF16(full_path.BaseName().value())),
- l10n_util::GetStringUTF16(
- IDS_FILEBROWSER_ERROR_VIEWING_FILE));
+ return false;
}
} // namespace file_manager_util
diff --git a/chrome/browser/extensions/file_manager_util.h b/chrome/browser/extensions/file_manager_util.h
index bf9f49d..e7184b6 100644
--- a/chrome/browser/extensions/file_manager_util.h
+++ b/chrome/browser/extensions/file_manager_util.h
@@ -49,7 +49,12 @@ GURL GetFileBrowserUrlWithParams(
// |dir|.
void ViewFolder(const FilePath& dir);
-void ViewItem(const FilePath& full_path, bool enqueue);
+// Opens file in the browser.
+void ViewFile(const FilePath& full_path, bool enqueue);
+
+// Tries to open |file| directly in the browser. Returns false if the browser
+// can't directly handle this type of file.
+bool TryViewingFile(const FilePath& file, bool enqueue);
} // namespace file_manager_util
diff --git a/chrome/browser/platform_util_chromeos.cc b/chrome/browser/platform_util_chromeos.cc
index cf860c5..de0bac4 100644
--- a/chrome/browser/platform_util_chromeos.cc
+++ b/chrome/browser/platform_util_chromeos.cc
@@ -59,7 +59,7 @@ void OpenItemOnFileThread(const FilePath& full_path) {
if (file_util::DirectoryExists(full_path))
callback = base::Bind(&file_manager_util::ViewFolder, full_path);
else
- callback = base::Bind(&file_manager_util::ViewItem, full_path, false);
+ callback = base::Bind(&file_manager_util::ViewFile, full_path, false);
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
}
diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js
index 4663ac0..7c0da76 100644
--- a/chrome/browser/resources/file_manager/js/file_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_manager.js
@@ -3743,6 +3743,7 @@ FileManager.prototype = {
if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/')
currentDirUrl += '/';
+ var self = this;
if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) {
// Save-as doesn't require a valid selection from the list, since
// we're going to take the filename from the text input.
@@ -3752,7 +3753,6 @@ FileManager.prototype = {
if (!this.validateFileName_(filename))
return;
- var self = this;
function resolveCallback(victim) {
if (victim instanceof FileError) {
// File does not exist. Closes the window and does not return.
@@ -3781,7 +3781,7 @@ FileManager.prototype = {
return;
}
- var ary = [];
+ var files = [];
var selectedIndexes = this.currentList_.selectionModel.selectedIndexes;
// All other dialog types require at least one selected list item.
@@ -3797,13 +3797,13 @@ FileManager.prototype = {
continue;
}
- ary.push(currentDirUrl + encodeURIComponent(entry.name));
+ files.push(currentDirUrl + encodeURIComponent(entry.name));
}
// Multi-file selection has no other restrictions.
if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) {
// Closes the window and does not return.
- this.selectFiles_(ary);
+ this.selectFiles_(files);
return;
}
@@ -3822,13 +3822,37 @@ FileManager.prototype = {
return;
}
}
- chrome.fileBrowserPrivate.viewFiles(ary, "default");
+ chrome.fileBrowserPrivate.viewFiles(files, "default", function(success) {
+ if (success || files.length != 1)
+ return;
+ // Run the default task if the browser wasn't able to handle viewing.
+ chrome.fileBrowserPrivate.getFileTasks(
+ files,
+ function(tasksList) {
+ // Run the top task from the list when double click can't
+ // be handled by the browser internally.
+ if (tasksList && tasksList.length == 1) {
+ var task = tasksList[0];
+ var task_parts = task.taskId.split('|');
+ if (task_parts[0] == self.getExtensionId_())
+ task.internal = true;
+
+ self.dispatchFileTask_(task, files);
+ } else {
+ var fileUrl = files[0];
+ self.alert.showWithTitle(
+ unescape(fileUrl.substr(fileUrl.lastIndexOf('/') + 1)),
+ str('ERROR_VIEWING_FILE'),
+ function() {});
+ }
+ });
+ });
// Window stays open.
return;
}
// Everything else must have exactly one.
- if (ary.length > 1)
+ if (files.length > 1)
throw new Error('Too many files selected!');
var selectedEntry = this.dataModel_.item(selectedIndexes[0]);
@@ -3842,7 +3866,7 @@ FileManager.prototype = {
}
// Closes the window and does not return.
- this.selectFile_(ary[0], this.getSelectedFilterIndex_(ary[0]));
+ this.selectFile_(files[0], this.getSelectedFilterIndex_(files[0]));
};
/**
diff --git a/chrome/browser/resources/shared/css/dialogs.css b/chrome/browser/resources/shared/css/dialogs.css
index 6e1bf2b..8973f06 100644
--- a/chrome/browser/resources/shared/css/dialogs.css
+++ b/chrome/browser/resources/shared/css/dialogs.css
@@ -39,6 +39,16 @@
padding: 15px;
}
+[hidden] {
+ display: none;
+}
+
+.cr-dialog-title {
+ font-weight: bold;
+ font-size: 120%;
+ padding-bottom: 10px;
+}
+
.cr-dialog-text {
padding-bottom: 10px;
}
diff --git a/chrome/browser/resources/shared/js/cr/ui/dialogs.js b/chrome/browser/resources/shared/js/cr/ui/dialogs.js
index 9aaf78c..5058ebb 100644
--- a/chrome/browser/resources/shared/js/cr/ui/dialogs.js
+++ b/chrome/browser/resources/shared/js/cr/ui/dialogs.js
@@ -44,6 +44,10 @@ cr.define('cr.ui.dialogs', function() {
this.frame_.className = 'cr-dialog-frame';
this.container_.appendChild(this.frame_);
+ this.title_ = doc.createElement('div');
+ this.title_.className = 'cr-dialog-title';
+ this.frame_.appendChild(this.title_);
+
this.text_ = doc.createElement('div');
this.text_.className = 'cr-dialog-text';
this.frame_.appendChild(this.text_);
@@ -110,12 +114,24 @@ cr.define('cr.ui.dialogs', function() {
};
BaseDialog.prototype.show = function(message, onOk, onCancel, onShow) {
+ this.showWithTitle(null, message, onOk, onCancel, onShow);
+ }
+
+ BaseDialog.prototype.showWithTitle = function(title, message,
+ onOk, onCancel, onShow) {
this.previousActiveElement_ = this.document_.activeElement;
this.parentNode_.appendChild(this.container_);
this.onOk_ = onOk;
this.onCancel_ = onCancel;
+ if (title) {
+ this.title_.textContent = title;
+ this.title_.hidden = false;
+ } else {
+ this.title_.textContent = "";
+ this.title_.hidden = true;
+ }
this.text_.textContent = message;
var top = (this.document_.body.clientHeight -
diff --git a/chrome/browser/ui/webui/active_downloads_ui.cc b/chrome/browser/ui/webui/active_downloads_ui.cc
index 8073cc3..8cfa5fe 100644
--- a/chrome/browser/ui/webui/active_downloads_ui.cc
+++ b/chrome/browser/ui/webui/active_downloads_ui.cc
@@ -83,7 +83,7 @@ ChromeWebUIDataSource* CreateActiveDownloadsUIHTMLSource() {
source->AddLocalizedString("showallfiles",
IDS_FILE_BROWSER_MORE_FILES);
source->AddLocalizedString("error_unknown_file_type",
- IDS_FILEBROWSER_ERROR_UNKNOWN_FILE_TYPE);
+ IDS_FILE_BROWSER_ERROR_UNKNOWN_FILE_TYPE);
FilePath default_download_path;
if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS,
diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json
index 53dd613..2854048 100644
--- a/chrome/common/extensions/api/extension_api.json
+++ b/chrome/common/extensions/api/extension_api.json
@@ -7616,6 +7616,18 @@
"name": "id",
"type": "string",
"description": "File browser handler id as for internal tasks."
+ },
+ {
+ "name": "callback",
+ "type": "function",
+ "optional": "false",
+ "parameters": [
+ {
+ "name" : "success",
+ "type": "boolean",
+ "description": "True if the selected files can be viewed by the browser."
+ }
+ ]
}
]
},