#include "apps/launcher.h"
-#include "apps/apps_client.h"
+#include "apps/browser/api/app_runtime/app_runtime_api.h"
+#include "apps/browser/file_handler_util.h"
+#include "apps/common/api/app_runtime.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
-#include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h"
#include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
#include "chrome/browser/extensions/api/file_system/file_system_api.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/extensions/api/app_runtime.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_messages.h"
#include "extensions/common/manifest_handlers/kiosk_mode_info.h"
+#include "net/base/filename_util.h"
+#include "net/base/mime_sniffer.h"
#include "net/base/mime_util.h"
#include "net/base/net_util.h"
#include "url/gurl.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#endif
-#if defined(OS_WIN)
-#include "win8/util/win8_util.h"
-#endif
-
-namespace app_runtime = extensions::api::app_runtime;
+namespace app_runtime = apps::api::app_runtime;
+using apps::file_handler_util::GrantedFileEntry;
using content::BrowserThread;
using extensions::app_file_handler_util::CheckWritableFiles;
using extensions::app_file_handler_util::FileHandlerForId;
using extensions::app_file_handler_util::FileHandlerCanHandleFile;
using extensions::app_file_handler_util::FirstFileHandlerForFile;
using extensions::app_file_handler_util::CreateFileEntry;
-using extensions::app_file_handler_util::GrantedFileEntry;
using extensions::app_file_handler_util::HasFileSystemWritePermission;
using extensions::EventRouter;
using extensions::Extension;
// load or obtain file launch data.
void LaunchPlatformAppWithNoData(Profile* profile, const Extension* extension) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- extensions::AppEventRouter::DispatchOnLaunchedEvent(profile, extension);
+ AppEventRouter::DispatchOnLaunchedEvent(profile, extension);
}
// Class to handle launching of platform apps to open a specific path.
}
std::string mime_type;
- if (!net::GetMimeTypeFromFile(file_path_, &mime_type))
- mime_type = kFallbackMimeType;
+ if (!net::GetMimeTypeFromFile(file_path_, &mime_type)) {
+ // If MIME type of the file can't be determined by its path,
+ // try to sniff it by its content.
+ std::vector<char> content(net::kMaxBytesToSniff);
+ int bytes_read = base::ReadFile(file_path_, &content[0], content.size());
+ if (bytes_read >= 0) {
+ net::SniffMimeType(&content[0],
+ bytes_read,
+ net::FilePathToFileURL(file_path_),
+ std::string(), // type_hint (passes no hint)
+ &mime_type);
+ }
+ if (mime_type.empty())
+ mime_type = kFallbackMimeType;
+ }
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
&PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type));
host->render_process_host()->GetID(),
file_path_,
false);
- extensions::AppEventRouter::DispatchOnLaunchedEventWithFileEntry(
+ AppEventRouter::DispatchOnLaunchedEventWithFileEntry(
profile_, extension_, handler_id_, mime_type, file_entry);
}
const Extension* extension,
const CommandLine& command_line,
const base::FilePath& current_directory) {
- if (!AppsClient::Get()->CheckAppLaunch(profile, extension))
- return;
-
// An app with "kiosk_only" should not be installed and launched
// outside of ChromeOS kiosk mode in the first place. This is a defensive
// check in case this scenario does occur.
}
void RestartPlatformApp(Profile* profile, const Extension* extension) {
-#if defined(OS_WIN)
- // On Windows 8's single window Metro mode we can not launch platform apps.
- // In restart we are just making sure launch doesn't slip through.
- if (win8::IsSingleWindowMetroMode())
- return;
-#endif
EventRouter* event_router = EventRouter::Get(profile);
bool listening_to_restart = event_router->
ExtensionHasEventListener(extension->id(),
app_runtime::OnRestarted::kEventName);
if (listening_to_restart) {
- extensions::AppEventRouter::DispatchOnRestartedEvent(profile, extension);
+ AppEventRouter::DispatchOnRestartedEvent(profile, extension);
return;
}
const std::string& handler_id,
const GURL& url,
const GURL& referrer_url) {
- extensions::AppEventRouter::DispatchOnLaunchedEventWithUrl(
+ AppEventRouter::DispatchOnLaunchedEventWithUrl(
profile, extension, handler_id, url, referrer_url);
}