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" | |
34 #include "net/base/mime_util.h" | 32 #include "net/base/mime_util.h" |
35 #include "net/base/net_util.h" | 33 #include "net/base/net_util.h" |
36 #include "url/gurl.h" | 34 #include "url/gurl.h" |
37 | 35 |
38 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
39 #include "chrome/browser/chromeos/drive/file_errors.h" | 37 #include "chrome/browser/chromeos/drive/file_errors.h" |
40 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 38 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
41 #include "chrome/browser/chromeos/drive/file_system_util.h" | 39 #include "chrome/browser/chromeos/drive/file_system_util.h" |
42 #include "chrome/browser/chromeos/login/user_manager.h" | 40 #include "chrome/browser/chromeos/login/user_manager.h" |
43 #endif | 41 #endif |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // If the file doesn't exist, or is a directory, launch with no launch data. | 174 // If the file doesn't exist, or is a directory, launch with no launch data. |
177 if (!base::PathExists(file_path_) || | 175 if (!base::PathExists(file_path_) || |
178 base::DirectoryExists(file_path_)) { | 176 base::DirectoryExists(file_path_)) { |
179 LOG(WARNING) << "No file exists with path " << file_path_.value(); | 177 LOG(WARNING) << "No file exists with path " << file_path_.value(); |
180 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 178 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
181 &PlatformAppPathLauncher::LaunchWithNoLaunchData, this)); | 179 &PlatformAppPathLauncher::LaunchWithNoLaunchData, this)); |
182 return; | 180 return; |
183 } | 181 } |
184 | 182 |
185 std::string mime_type; | 183 std::string mime_type; |
186 if (!net::GetMimeTypeFromFile(file_path_, &mime_type)) { | 184 if (!net::GetMimeTypeFromFile(file_path_, &mime_type)) |
187 // If MIME type of the file can't be determined by its path, | 185 mime_type = kFallbackMimeType; |
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 } | |
201 | 186 |
202 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 187 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
203 &PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type)); | 188 &PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type)); |
204 } | 189 } |
205 | 190 |
206 #if defined(OS_CHROMEOS) | 191 #if defined(OS_CHROMEOS) |
207 void GetMimeTypeAndLaunchForDriveFile() { | 192 void GetMimeTypeAndLaunchForDriveFile() { |
208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
209 | 194 |
210 drive::FileSystemInterface* file_system = | 195 drive::FileSystemInterface* file_system = |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 void LaunchPlatformAppWithUrl(Profile* profile, | 390 void LaunchPlatformAppWithUrl(Profile* profile, |
406 const Extension* extension, | 391 const Extension* extension, |
407 const std::string& handler_id, | 392 const std::string& handler_id, |
408 const GURL& url, | 393 const GURL& url, |
409 const GURL& referrer_url) { | 394 const GURL& referrer_url) { |
410 AppEventRouter::DispatchOnLaunchedEventWithUrl( | 395 AppEventRouter::DispatchOnLaunchedEventWithUrl( |
411 profile, extension, handler_id, url, referrer_url); | 396 profile, extension, handler_id, url, referrer_url); |
412 } | 397 } |
413 | 398 |
414 } // namespace apps | 399 } // namespace apps |
OLD | NEW |