OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "apps/launcher.h" | 5 #include "apps/launcher.h" |
6 | 6 |
7 #include "apps/browser/api/app_runtime/app_runtime_api.h" | 7 #include "apps/browser/api/app_runtime/app_runtime_api.h" |
8 #include "apps/browser/file_handler_util.h" | 8 #include "apps/browser/file_handler_util.h" |
9 #include "apps/common/api/app_runtime.h" | 9 #include "apps/common/api/app_runtime.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "extensions/browser/event_router.h" | 23 #include "extensions/browser/event_router.h" |
24 #include "extensions/browser/extension_host.h" | 24 #include "extensions/browser/extension_host.h" |
25 #include "extensions/browser/extension_prefs.h" | 25 #include "extensions/browser/extension_prefs.h" |
26 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
27 #include "extensions/browser/lazy_background_task_queue.h" | 27 #include "extensions/browser/lazy_background_task_queue.h" |
28 #include "extensions/browser/process_manager.h" | 28 #include "extensions/browser/process_manager.h" |
29 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
30 #include "extensions/common/extension_messages.h" | 30 #include "extensions/common/extension_messages.h" |
31 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" | 31 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" |
| 32 #include "net/base/filename_util.h" |
| 33 #include "net/base/mime_sniffer.h" |
32 #include "net/base/mime_util.h" | 34 #include "net/base/mime_util.h" |
33 #include "net/base/net_util.h" | 35 #include "net/base/net_util.h" |
34 #include "url/gurl.h" | 36 #include "url/gurl.h" |
35 | 37 |
36 #if defined(OS_CHROMEOS) | 38 #if defined(OS_CHROMEOS) |
37 #include "chrome/browser/chromeos/drive/file_errors.h" | 39 #include "chrome/browser/chromeos/drive/file_errors.h" |
38 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 40 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
39 #include "chrome/browser/chromeos/drive/file_system_util.h" | 41 #include "chrome/browser/chromeos/drive/file_system_util.h" |
40 #include "chrome/browser/chromeos/login/user_manager.h" | 42 #include "chrome/browser/chromeos/login/user_manager.h" |
41 #endif | 43 #endif |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // If the file doesn't exist, or is a directory, launch with no launch data. | 176 // If the file doesn't exist, or is a directory, launch with no launch data. |
175 if (!base::PathExists(file_path_) || | 177 if (!base::PathExists(file_path_) || |
176 base::DirectoryExists(file_path_)) { | 178 base::DirectoryExists(file_path_)) { |
177 LOG(WARNING) << "No file exists with path " << file_path_.value(); | 179 LOG(WARNING) << "No file exists with path " << file_path_.value(); |
178 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 180 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
179 &PlatformAppPathLauncher::LaunchWithNoLaunchData, this)); | 181 &PlatformAppPathLauncher::LaunchWithNoLaunchData, this)); |
180 return; | 182 return; |
181 } | 183 } |
182 | 184 |
183 std::string mime_type; | 185 std::string mime_type; |
184 if (!net::GetMimeTypeFromFile(file_path_, &mime_type)) | 186 if (!net::GetMimeTypeFromFile(file_path_, &mime_type)) { |
185 mime_type = kFallbackMimeType; | 187 // If MIME type of the file can't be determined by its path, |
| 188 // try to sniff it by its content. |
| 189 std::vector<char> content(net::kMaxBytesToSniff); |
| 190 int bytes_read = base::ReadFile(file_path_, &content[0], content.size()); |
| 191 if (bytes_read >= 0) { |
| 192 net::SniffMimeType(&content[0], |
| 193 bytes_read, |
| 194 net::FilePathToFileURL(file_path_), |
| 195 std::string(), // type_hint (passes no hint) |
| 196 &mime_type); |
| 197 } |
| 198 if (mime_type.empty()) |
| 199 mime_type = kFallbackMimeType; |
| 200 } |
186 | 201 |
187 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 202 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
188 &PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type)); | 203 &PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type)); |
189 } | 204 } |
190 | 205 |
191 #if defined(OS_CHROMEOS) | 206 #if defined(OS_CHROMEOS) |
192 void GetMimeTypeAndLaunchForDriveFile() { | 207 void GetMimeTypeAndLaunchForDriveFile() { |
193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
194 | 209 |
195 drive::FileSystemInterface* file_system = | 210 drive::FileSystemInterface* file_system = |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 void LaunchPlatformAppWithUrl(Profile* profile, | 405 void LaunchPlatformAppWithUrl(Profile* profile, |
391 const Extension* extension, | 406 const Extension* extension, |
392 const std::string& handler_id, | 407 const std::string& handler_id, |
393 const GURL& url, | 408 const GURL& url, |
394 const GURL& referrer_url) { | 409 const GURL& referrer_url) { |
395 AppEventRouter::DispatchOnLaunchedEventWithUrl( | 410 AppEventRouter::DispatchOnLaunchedEventWithUrl( |
396 profile, extension, handler_id, url, referrer_url); | 411 profile, extension, handler_id, url, referrer_url); |
397 } | 412 } |
398 | 413 |
399 } // namespace apps | 414 } // namespace apps |
OLD | NEW |