Commit 3b4f6629 authored by dgozman@chromium.org's avatar dgozman@chromium.org

[filebrowser] Introduce "Open" action for supported file types (e.g. pdf).

BUG=chromium-os:26538,chromium-os:26539
TEST=See bug.

Review URL: http://codereview.chromium.org/9395077

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124975 0039d316-1c4b-4281-b951-d872f2087c98
parent 29173400
...@@ -9962,6 +9962,13 @@ Some features may be unavailable. Please check that the profile exists and you ...@@ -9962,6 +9962,13 @@ Some features may be unavailable. Please check that the profile exists and you
Format device Format device
</message> </message>
<message name="IDS_FILE_BROWSER_OPEN_ACTION" desc="Title of the action for opening contents of the file.">
Open
</message>
<message name="IDS_FILE_BROWSER_INSTALL_CRX" desc="Title of the action for installing extension from CRX file.">
Open
</message>
<message name="IDS_FILE_BROWSER_GALLERY" desc="Title of the action to open the Gallery."> <message name="IDS_FILE_BROWSER_GALLERY" desc="Title of the action to open the Gallery.">
View and Edit View and Edit
</message> </message>
......
...@@ -1781,6 +1781,9 @@ bool FileDialogStringsFunction::RunImpl() { ...@@ -1781,6 +1781,9 @@ bool FileDialogStringsFunction::RunImpl() {
SET_STRING(IDS_FILE_BROWSER, MOUNT_ARCHIVE); SET_STRING(IDS_FILE_BROWSER, MOUNT_ARCHIVE);
SET_STRING(IDS_FILE_BROWSER, FORMAT_DEVICE); SET_STRING(IDS_FILE_BROWSER, FORMAT_DEVICE);
SET_STRING(IDS_FILE_BROWSER, OPEN_ACTION);
SET_STRING(IDS_FILE_BROWSER, INSTALL_CRX);
SET_STRING(IDS_FILE_BROWSER, GALLERY); SET_STRING(IDS_FILE_BROWSER, GALLERY);
SET_STRING(IDS_FILE_BROWSER, GALLERY_EDIT); SET_STRING(IDS_FILE_BROWSER, GALLERY_EDIT);
SET_STRING(IDS_FILE_BROWSER, GALLERY_SHARE); SET_STRING(IDS_FILE_BROWSER, GALLERY_SHARE);
...@@ -1912,6 +1915,10 @@ bool FileDialogStringsFunction::RunImpl() { ...@@ -1912,6 +1915,10 @@ bool FileDialogStringsFunction::RunImpl() {
SET_STRING(IDS_FILE_BROWSER, ENQUEUE); SET_STRING(IDS_FILE_BROWSER, ENQUEUE);
#undef SET_STRING #undef SET_STRING
dict->SetString("PDF_VIEW_ENABLED",
file_manager_util::ShouldBeOpenedWithPdfPlugin(".pdf") ?
"true" : "false");
ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict); ChromeURLDataManager::DataSource::SetFontAndTextDirection(dict);
dict->SetString("PLAY_MEDIA", dict->SetString("PLAY_MEDIA",
......
...@@ -122,29 +122,6 @@ bool IsCRXFile(const char* file_extension) { ...@@ -122,29 +122,6 @@ bool IsCRXFile(const char* file_extension) {
return base::strcasecmp(file_extension, kCRXExtension) == 0; return base::strcasecmp(file_extension, kCRXExtension) == 0;
} }
// If pdf plugin is enabled, we should open pdf files in a tab.
bool ShouldBeOpenedWithPdfPlugin(const char* file_extension) {
if (base::strcasecmp(file_extension, kPdfExtension) != 0)
return false;
Browser* browser = BrowserList::GetLastActive();
if (!browser)
return false;
FilePath pdf_path;
PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path);
webkit::WebPluginInfo plugin;
if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin))
return false;
PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile());
if (!plugin_prefs)
return false;
return plugin_prefs->IsPluginEnabled(plugin);
}
// Returns index |ext| has in the |array|. If there is no |ext| in |array|, last // Returns index |ext| has in the |array|. If there is no |ext| in |array|, last
// element's index is return (last element should have irrelevant value). // element's index is return (last element should have irrelevant value).
int UMAExtensionIndex(const char *file_extension, int UMAExtensionIndex(const char *file_extension,
...@@ -468,4 +445,27 @@ void InstallCRX(Profile* profile, const FilePath& full_path) { ...@@ -468,4 +445,27 @@ void InstallCRX(Profile* profile, const FilePath& full_path) {
installer->InstallCrx(full_path); installer->InstallCrx(full_path);
} }
// If pdf plugin is enabled, we should open pdf files in a tab.
bool ShouldBeOpenedWithPdfPlugin(const char* file_extension) {
if (base::strcasecmp(file_extension, kPdfExtension) != 0)
return false;
Browser* browser = BrowserList::GetLastActive();
if (!browser)
return false;
FilePath pdf_path;
PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path);
webkit::WebPluginInfo plugin;
if (!PluginService::GetInstance()->GetPluginInfoByPath(pdf_path, &plugin))
return false;
PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(browser->profile());
if (!plugin_prefs)
return false;
return plugin_prefs->IsPluginEnabled(plugin);
}
} // namespace file_manager_util } // namespace file_manager_util
...@@ -66,6 +66,8 @@ bool TryViewingFile(const FilePath& file); ...@@ -66,6 +66,8 @@ bool TryViewingFile(const FilePath& file);
void InstallCRX(Profile* profile, const FilePath& full_path); void InstallCRX(Profile* profile, const FilePath& full_path);
bool ShouldBeOpenedWithPdfPlugin(const char* file_extension);
} // namespace file_manager_util } // namespace file_manager_util
#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_UTIL_H_ #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_UTIL_H_
...@@ -2164,6 +2164,7 @@ FileManager.prototype = { ...@@ -2164,6 +2164,7 @@ FileManager.prototype = {
FileManager.prototype.onTasksFound_ = function(selection, tasksList) { FileManager.prototype.onTasksFound_ = function(selection, tasksList) {
this.taskItems_.clear(); this.taskItems_.clear();
var tasksCount = 0;
for (var i = 0; i < tasksList.length; i++) { for (var i = 0; i < tasksList.length; i++) {
var task = tasksList[i]; var task = tasksList[i];
...@@ -2185,15 +2186,30 @@ FileManager.prototype = { ...@@ -2185,15 +2186,30 @@ FileManager.prototype = {
} else if (task_parts[1] == 'gallery') { } else if (task_parts[1] == 'gallery') {
task.iconUrl = task.iconUrl =
chrome.extension.getURL('images/icon_preview_16x16.png'); chrome.extension.getURL('images/icon_preview_16x16.png');
task.title = str('GALLERY'); task.title = str('OPEN_ACTION');
task.allTasks = tasksList; task.allTasks = tasksList;
this.galleryTask_ = task; } else if (task_parts[1] == 'view-pdf') {
// Do not render this task if disabled.
if (str('PDF_VIEW_ENABLED') == 'false') continue;
task.iconUrl =
chrome.extension.getURL('images/icon_preview_16x16.png');
task.title = str('OPEN_ACTION');
} else if (task_parts[1] == 'view-txt') {
task.iconUrl =
chrome.extension.getURL('images/icon_preview_16x16.png');
task.title = str('OPEN_ACTION');
} else if (task_parts[1] == 'install-crx') {
// TODO(dgozman): change to the right icon.
task.iconUrl =
chrome.extension.getURL('images/icon_preview_16x16.png');
task.title = str('INSTALL_CRX');
} }
} }
this.renderTaskItem_(task); this.renderTaskItem_(task);
tasksCount++;
} }
this.taskItems_.visible = tasksList.length > 0; this.taskItems_.visible = tasksCount > 0;
selection.tasksList = tasksList; selection.tasksList = tasksList;
if (selection.dispatchDefault) { if (selection.dispatchDefault) {
...@@ -2445,6 +2461,8 @@ FileManager.prototype = { ...@@ -2445,6 +2461,8 @@ FileManager.prototype = {
} }
} }
this.openGallery_(urls, noGallery); this.openGallery_(urls, noGallery);
} else if (id == 'view-pdf' || id == 'view-txt' || id == 'install-crx') {
chrome.fileBrowserPrivate.viewFiles(urls, 'default', function() {});
} }
}; };
......
...@@ -322,6 +322,9 @@ chrome.fileBrowserPrivate = { ...@@ -322,6 +322,9 @@ chrome.fileBrowserPrivate = {
MOUNT_ARCHIVE: 'Open', MOUNT_ARCHIVE: 'Open',
FORMAT_DEVICE: 'Format device', FORMAT_DEVICE: 'Format device',
OPEN_ACTION: 'Open',
INSTALL_CRX: 'Open',
GALLERY: 'View and Edit', GALLERY: 'View and Edit',
GALLERY_EDIT: 'Edit', GALLERY_EDIT: 'Edit',
GALLERY_SHARE: 'Share', GALLERY_SHARE: 'Share',
......
...@@ -55,9 +55,34 @@ ...@@ -55,9 +55,34 @@
"filesystem:*.zip" "filesystem:*.zip"
] ]
}, },
{
"id": "view-pdf",
"default_title": "__MSG_OPEN_ACTION__",
"default_icon": "images/icon_preview_16x16.png",
"file_filters": [
"filesystem:*.pdf"
]
},
{
"id": "view-txt",
"default_title": "__MSG_OPEN_ACTION__",
"default_icon": "images/icon_preview_16x16.png",
"file_filters": [
"filesystem:*.txt"
]
},
{
"id": "install-crx",
"default_title": "__MSG_INSTALL_CRX__",
// TODO(dgozman): replace to the right icon.
"default_icon": "images/icon_preview_16x16.png",
"file_filters": [
"filesystem:*.crx"
]
},
{ {
"id": "gallery", "id": "gallery",
"default_title": "__MSG_GALLERY__", "default_title": "__MSG_OPEN_ACTION__",
"default_icon": "images/icon_preview_16x16.png", "default_icon": "images/icon_preview_16x16.png",
"file_filters": [ "file_filters": [
// Image formats // Image formats
......
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