Commit 9be0bad4 authored by sammc@chromium.org's avatar sammc@chromium.org

Treat unknown MIME type as application/octet-stream when launching apps.

Previously, if the MIME type of a file passed to a file handler of a
platform app, the app would be launched without the file, even if the
file handler accepted * or */*. With this change, a file with an unknown
MIME type is treated the same as one with a MIME type of
application/octet-stream.

BUG=219402
TEST=browser_test PlatformAppBrowserTest.LaunchNoType

Review URL: https://chromiumcodereview.appspot.com/14254002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194789 0039d316-1c4b-4281-b951-d872f2087c98
parent d7818465
...@@ -455,12 +455,12 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNoIntent) { ...@@ -455,12 +455,12 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchWithNoIntent) {
<< message_; << message_;
} }
// Tests that no launch data is sent through if the file MIME type cannot // Tests that launch data is sent through with the MIME type set to
// be read. // application/octet-stream if the file MIME type cannot be read.
IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoType) { IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, LaunchNoType) {
SetCommandLineArg("platform_apps/launch_files/test.unknownextension"); SetCommandLineArg("platform_apps/launch_files/test.unknownextension");
ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch_invalid")) ASSERT_TRUE(RunPlatformAppTest(
<< message_; "platform_apps/launch_application_octet_stream")) << message_;
} }
// Tests that no launch data is sent through if the file does not exist. // Tests that no launch data is sent through if the file does not exist.
......
...@@ -56,6 +56,8 @@ namespace extensions { ...@@ -56,6 +56,8 @@ namespace extensions {
namespace { namespace {
const char kFallbackMimeType[] = "application/octet-stream";
bool MakePathAbsolute(const base::FilePath& current_directory, bool MakePathAbsolute(const base::FilePath& current_directory,
base::FilePath* file_path) { base::FilePath* file_path) {
DCHECK(file_path); DCHECK(file_path);
...@@ -154,14 +156,8 @@ class PlatformAppPathLauncher ...@@ -154,14 +156,8 @@ class PlatformAppPathLauncher
} }
std::string mime_type; std::string mime_type;
// If we cannot obtain the MIME type, launch with no launch data. if (!net::GetMimeTypeFromFile(file_path_, &mime_type))
if (!net::GetMimeTypeFromFile(file_path_, &mime_type)) { mime_type = kFallbackMimeType;
LOG(WARNING) << "Could not obtain MIME type for "
<< file_path_.value();
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
&PlatformAppPathLauncher::LaunchWithNoLaunchData, this));
return;
}
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
&PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type)); &PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type));
...@@ -189,13 +185,12 @@ class PlatformAppPathLauncher ...@@ -189,13 +185,12 @@ class PlatformAppPathLauncher
drive::DriveFileType file_type) { drive::DriveFileType file_type) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (error != drive::DRIVE_FILE_OK || mime_type.empty() || if (error != drive::DRIVE_FILE_OK || file_type != drive::REGULAR_FILE) {
file_type != drive::REGULAR_FILE) {
LaunchWithNoLaunchData(); LaunchWithNoLaunchData();
return; return;
} }
LaunchWithMimeType(mime_type); LaunchWithMimeType(mime_type.empty() ? kFallbackMimeType : mime_type);
} }
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
......
{
"name": "Platform App Launch Test",
"version": "1",
"file_handlers": {
"unknown": {
"types": [
"application/octet-stream"
],
"title": "Test editor"
}
},
"app": {
"background": {
"scripts": ["test.js"]
}
}
}
// Copyright (c) 2012 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.
chrome.app.runtime.onLaunched.addListener(function (launchData) {
// Test that the id and items fields in FileEntry can be read.
chrome.test.runTests([
function testFileHandler() {
chrome.test.assertFalse(!launchData, "No launchData");
chrome.test.assertEq(typeof launchData.id, 'string',
"launchData.id not received");
chrome.test.assertEq(launchData.items.length, 1);
chrome.test.assertEq(launchData.items[0].type,
"application/octet-stream");
launchData.items[0].entry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
chrome.test.assertEq(
reader.result.indexOf("This is a test. Word."), 0);
chrome.test.succeed();
};
reader.onerror = function(e) {
chrome.test.fail("Error reading file contents.");
};
reader.readAsText(file);
});
}
]);
});
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