summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-26 03:16:00 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-26 03:16:00 +0000
commitd474bf8ae4d09569fccefd06d35e0e4e98745e43 (patch)
tree753d0a19e56f9b58b1cd964db9017e11be712098
parentc9e4738d4185a072c560f1c072516c7381d3c54a (diff)
downloadchromium_src-d474bf8ae4d09569fccefd06d35e0e4e98745e43.zip
chromium_src-d474bf8ae4d09569fccefd06d35e0e4e98745e43.tar.gz
chromium_src-d474bf8ae4d09569fccefd06d35e0e4e98745e43.tar.bz2
file_manager: Split the open with browser stuff into a set of separate files
This is a reland of r219281, which was reverted for breaking the tree. Yet another meaty stuff from the kitchen sink file file_manager_util.cc BUG=270469 TEST=none R=kinaba@chromium.org Review URL: https://codereview.chromium.org/22886013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219494 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/extensions/file_manager/file_browser_handlers.cc1
-rw-r--r--chrome/browser/chromeos/extensions/file_manager/file_manager_util.cc199
-rw-r--r--chrome/browser/chromeos/extensions/file_manager/file_manager_util.h17
-rw-r--r--chrome/browser/chromeos/extensions/file_manager/open_with_browser.cc226
-rw-r--r--chrome/browser/chromeos/extensions/file_manager/open_with_browser.h38
-rw-r--r--chrome/browser/chromeos/extensions/file_manager/private_api_strings.cc1
-rw-r--r--chrome/browser/chromeos/extensions/file_manager/private_api_tasks.cc1
-rw-r--r--chrome/chrome_browser_chromeos.gypi2
8 files changed, 269 insertions, 216 deletions
diff --git a/chrome/browser/chromeos/extensions/file_manager/file_browser_handlers.cc b/chrome/browser/chromeos/extensions/file_manager/file_browser_handlers.cc
index 889d933..f39281e 100644
--- a/chrome/browser/chromeos/extensions/file_manager/file_browser_handlers.cc
+++ b/chrome/browser/chromeos/extensions/file_manager/file_browser_handlers.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/chromeos/extensions/file_manager/app_id.h"
#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
#include "chrome/browser/chromeos/extensions/file_manager/fileapi_util.h"
+#include "chrome/browser/chromeos/extensions/file_manager/open_with_browser.h"
#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
#include "chrome/browser/extensions/event_router.h"
#include "chrome/browser/extensions/extension_host.h"
diff --git a/chrome/browser/chromeos/extensions/file_manager/file_manager_util.cc b/chrome/browser/chromeos/extensions/file_manager/file_manager_util.cc
index 48702c4..107d99f 100644
--- a/chrome/browser/chromeos/extensions/file_manager/file_manager_util.cc
+++ b/chrome/browser/chromeos/extensions/file_manager/file_manager_util.cc
@@ -5,29 +5,18 @@
#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
#include "base/bind.h"
-#include "base/command_line.h"
#include "base/logging.h"
-#include "base/metrics/histogram.h"
-#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
-#include "base/threading/sequenced_worker_pool.h"
-#include "chrome/browser/chromeos/drive/drive.pb.h"
-#include "chrome/browser/chromeos/drive/drive_integration_service.h"
-#include "chrome/browser/chromeos/drive/file_system.h"
-#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/extensions/file_manager/app_id.h"
#include "chrome/browser/chromeos/extensions/file_manager/file_browser_handlers.h"
#include "chrome/browser/chromeos/extensions/file_manager/file_tasks.h"
#include "chrome/browser/chromeos/extensions/file_manager/fileapi_util.h"
#include "chrome/browser/chromeos/extensions/file_manager/url_util.h"
#include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
-#include "chrome/browser/extensions/crx_installer.h"
-#include "chrome/browser/extensions/extension_install_prompt.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/google_apis/task_util.h"
-#include "chrome/browser/plugins/plugin_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
@@ -36,21 +25,12 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/simple_message_box.h"
-#include "chrome/common/chrome_paths.h"
-#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/file_browser_handlers/file_browser_handler.h"
-#include "chrome/common/url_constants.h"
-#include "chromeos/chromeos_switches.h"
#include "content/public/browser/browser_thread.h"
-#include "content/public/browser/plugin_service.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/user_metrics.h"
-#include "content/public/common/pepper_plugin_info.h"
-#include "content/public/common/webplugininfo.h"
#include "grit/generated_resources.h"
-#include "net/base/escape.h"
#include "net/base/mime_util.h"
-#include "net/base/net_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "webkit/browser/fileapi/file_system_backend.h"
#include "webkit/browser/fileapi/file_system_context.h"
@@ -59,7 +39,6 @@
using content::BrowserContext;
using content::BrowserThread;
-using content::PluginService;
using content::UserMetricsAction;
using extensions::Extension;
using extensions::app_file_handler_util::FindFileHandlersForFiles;
@@ -70,79 +49,6 @@ namespace file_manager {
namespace util {
namespace {
-const base::FilePath::CharType kCRXExtension[] = FILE_PATH_LITERAL(".crx");
-const base::FilePath::CharType kPdfExtension[] = FILE_PATH_LITERAL(".pdf");
-const base::FilePath::CharType kSwfExtension[] = FILE_PATH_LITERAL(".swf");
-
-// List of file extensions viewable in the browser.
-const base::FilePath::CharType* kFileExtensionsViewableInBrowser[] = {
-#if defined(GOOGLE_CHROME_BUILD)
- FILE_PATH_LITERAL(".pdf"),
- FILE_PATH_LITERAL(".swf"),
-#endif
- FILE_PATH_LITERAL(".bmp"),
- FILE_PATH_LITERAL(".jpg"),
- FILE_PATH_LITERAL(".jpeg"),
- FILE_PATH_LITERAL(".png"),
- FILE_PATH_LITERAL(".webp"),
- FILE_PATH_LITERAL(".gif"),
- FILE_PATH_LITERAL(".txt"),
- FILE_PATH_LITERAL(".html"),
- FILE_PATH_LITERAL(".htm"),
- FILE_PATH_LITERAL(".mhtml"),
- FILE_PATH_LITERAL(".mht"),
- FILE_PATH_LITERAL(".svg"),
-};
-
-// Returns true if |file_path| is viewable in the browser (ex. HTML file).
-bool IsViewableInBrowser(const base::FilePath& file_path) {
- for (size_t i = 0; i < arraysize(kFileExtensionsViewableInBrowser); i++) {
- if (file_path.MatchesExtension(kFileExtensionsViewableInBrowser[i]))
- return true;
- }
- return false;
-}
-
-bool IsPepperPluginEnabled(Profile* profile,
- const base::FilePath& plugin_path) {
- content::PepperPluginInfo* pepper_info =
- PluginService::GetInstance()->GetRegisteredPpapiPluginInfo(plugin_path);
- if (!pepper_info)
- return false;
-
- scoped_refptr<PluginPrefs> plugin_prefs = PluginPrefs::GetForProfile(profile);
- if (!plugin_prefs.get())
- return false;
-
- return plugin_prefs->IsPluginEnabled(pepper_info->ToWebPluginInfo());
-}
-
-bool IsPdfPluginEnabled(Profile* profile) {
- base::FilePath plugin_path;
- PathService::Get(chrome::FILE_PDF_PLUGIN, &plugin_path);
- return IsPepperPluginEnabled(profile, plugin_path);
-}
-
-bool IsFlashPluginEnabled(Profile* profile) {
- base::FilePath plugin_path(
- CommandLine::ForCurrentProcess()->GetSwitchValueNative(
- switches::kPpapiFlashPath));
- if (plugin_path.empty())
- PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &plugin_path);
- return IsPepperPluginEnabled(profile, plugin_path);
-}
-
-void OpenNewTab(Profile* profile, const GURL& url) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- Browser* browser = chrome::FindOrCreateTabbedBrowser(
- profile ? profile : ProfileManager::GetDefaultProfileOrOffTheRecord(),
- chrome::HOST_DESKTOP_TYPE_ASH);
- chrome::AddSelectedTabWithURL(browser, url, content::PAGE_TRANSITION_LINK);
- // If the current browser is not tabbed then the new tab will be created
- // in a different browser. Make sure it is visible.
- browser->window()->Show();
-}
-
// Shows a warning message box saying that the file could not be opened.
void ShowWarningMessageBox(Profile* profile, const base::FilePath& file_path) {
// TODO: if FindOrCreateTabbedBrowser creates a new browser the returned
@@ -159,32 +65,6 @@ void ShowWarningMessageBox(Profile* profile, const base::FilePath& file_path) {
chrome::MESSAGE_BOX_TYPE_WARNING);
}
-void InstallCRX(Browser* browser, const base::FilePath& file_path) {
- ExtensionService* service =
- extensions::ExtensionSystem::Get(browser->profile())->extension_service();
- CHECK(service);
-
- scoped_refptr<extensions::CrxInstaller> installer(
- extensions::CrxInstaller::Create(
- service,
- scoped_ptr<ExtensionInstallPrompt>(new ExtensionInstallPrompt(
- browser->profile(), NULL, NULL))));
- installer->set_error_on_unsupported_requirements(true);
- installer->set_is_gallery_install(false);
- installer->set_allow_silent_install(false);
- installer->InstallCrx(file_path);
-}
-
-// Called when a crx file on Drive was downloaded.
-void OnCRXDownloadCallback(Browser* browser,
- drive::FileError error,
- const base::FilePath& file,
- scoped_ptr<drive::ResourceEntry> entry) {
- if (error != drive::FILE_ERROR_OK)
- return;
- InstallCRX(browser, file);
-}
-
// Grants file system access to the file manager.
bool GrantFileSystemAccessToFileBrowser(Profile* profile) {
// The file manager always runs in the site for its extension id, so that
@@ -379,16 +259,6 @@ bool OpenFileWithHandler(Profile* profile, const base::FilePath& file_path) {
return OpenFileWithFileBrowserHandler(profile, file_path, *handler, url);
}
-// Reads the alternate URL from a GDoc file. When it fails, returns a file URL
-// for |file_path| as fallback.
-// Note that an alternate url is a URL to open a hosted document.
-GURL ReadUrlFromGDocOnBlockingPool(const base::FilePath& file_path) {
- GURL url = drive::util::ReadUrlFromGDocFile(file_path);
- if (url.is_empty())
- url = net::FilePathToFileURL(file_path);
- return url;
-}
-
// Used to implement OpenItem().
void ContinueOpenItem(Profile* profile,
const base::FilePath& file_path,
@@ -502,75 +372,6 @@ void ShowItemInFolder(const base::FilePath& file_path) {
OpenFileManagerWithInternalActionId(file_path, "select");
}
-bool OpenFileWithBrowser(Browser* browser, const base::FilePath& file_path) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
- Profile* profile = browser->profile();
- // For things supported natively by the browser, we should open it
- // in a tab.
- if (IsViewableInBrowser(file_path) ||
- ShouldBeOpenedWithPlugin(profile, file_path.Extension())) {
- GURL page_url = net::FilePathToFileURL(file_path);
- // Override drive resource to point to internal handler instead of file URL.
- if (drive::util::IsUnderDriveMountPoint(file_path)) {
- page_url = drive::util::FilePathToDriveURL(
- drive::util::ExtractDrivePath(file_path));
- }
- OpenNewTab(profile, page_url);
- return true;
- }
-
- if (drive::util::HasGDocFileExtension(file_path)) {
- if (drive::util::IsUnderDriveMountPoint(file_path)) {
- // The file is on Google Docs. Open with drive URL.
- GURL url = drive::util::FilePathToDriveURL(
- drive::util::ExtractDrivePath(file_path));
- OpenNewTab(profile, url);
- } else {
- // The file is local (downloaded from an attachment or otherwise copied).
- // Parse the file to extract the Docs url and open this url.
- base::PostTaskAndReplyWithResult(
- BrowserThread::GetBlockingPool(),
- FROM_HERE,
- base::Bind(&ReadUrlFromGDocOnBlockingPool, file_path),
- base::Bind(&OpenNewTab, static_cast<Profile*>(NULL)));
- }
- return true;
- }
-
- if (file_path.MatchesExtension(kCRXExtension)) {
- if (drive::util::IsUnderDriveMountPoint(file_path)) {
- drive::DriveIntegrationService* integration_service =
- drive::DriveIntegrationServiceFactory::GetForProfile(profile);
- if (!integration_service)
- return false;
- integration_service->file_system()->GetFileByPath(
- drive::util::ExtractDrivePath(file_path),
- base::Bind(&OnCRXDownloadCallback, browser));
- } else {
- InstallCRX(browser, file_path);
- }
- return true;
- }
-
- // Failed to open the file of unknown type.
- LOG(WARNING) << "Unknown file type: " << file_path.value();
- return false;
-}
-
-// If a bundled plugin is enabled, we should open pdf/swf files in a tab.
-bool ShouldBeOpenedWithPlugin(
- Profile* profile,
- const base::FilePath::StringType& file_extension) {
- const base::FilePath file_path =
- base::FilePath::FromUTF8Unsafe("dummy").AddExtension(file_extension);
- if (file_path.MatchesExtension(kPdfExtension))
- return IsPdfPluginEnabled(profile);
- if (file_path.MatchesExtension(kSwfExtension))
- return IsFlashPluginEnabled(profile);
- return false;
-}
-
std::string GetMimeTypeForPath(const base::FilePath& file_path) {
const base::FilePath::StringType file_extension =
StringToLowerASCII(file_path.Extension());
diff --git a/chrome/browser/chromeos/extensions/file_manager/file_manager_util.h b/chrome/browser/chromeos/extensions/file_manager/file_manager_util.h
index 681ef4c..0db5399 100644
--- a/chrome/browser/chromeos/extensions/file_manager/file_manager_util.h
+++ b/chrome/browser/chromeos/extensions/file_manager/file_manager_util.h
@@ -42,23 +42,6 @@ void OpenItem(const base::FilePath& file_path);
// |file_path|, with the item selected.
void ShowItemInFolder(const base::FilePath& file_path);
-// Opens the file specified by |file_path| with the browser. This function takes
-// care of the following intricacies:
-//
-// - If the file is a Drive hosted document, the hosted document will be
-// opened in the browser by extracting the right URL for the file.
-// - If the file is a CRX file, the CRX file will be installed.
-// - If the file is on Drive, the file will be downloaded from Drive as
-// needed.
-//
-// Returns false if failed to open. This happens if the file type is unknown.
-bool OpenFileWithBrowser(Browser* browser, const base::FilePath& file_path);
-
-// Checks whether a pepper plugin for |file_extension| is enabled.
-bool ShouldBeOpenedWithPlugin(
- Profile* profile,
- const base::FilePath::StringType& file_extension);
-
// Returns the MIME type of |file_path|. Returns "" if the MIME type is
// unknown.
std::string GetMimeTypeForPath(const base::FilePath& file_path);
diff --git a/chrome/browser/chromeos/extensions/file_manager/open_with_browser.cc b/chrome/browser/chromeos/extensions/file_manager/open_with_browser.cc
new file mode 100644
index 0000000..ea51561
--- /dev/null
+++ b/chrome/browser/chromeos/extensions/file_manager/open_with_browser.cc
@@ -0,0 +1,226 @@
+// Copyright 2013 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.
+
+#include "chrome/browser/chromeos/extensions/file_manager/open_with_browser.h"
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "base/threading/sequenced_worker_pool.h"
+#include "chrome/browser/chromeos/drive/drive.pb.h"
+#include "chrome/browser/chromeos/drive/drive_integration_service.h"
+#include "chrome/browser/chromeos/drive/file_system.h"
+#include "chrome/browser/chromeos/drive/file_system_util.h"
+#include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
+#include "chrome/browser/extensions/crx_installer.h"
+#include "chrome/browser/extensions/extension_install_prompt.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/plugins/plugin_prefs.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/browser_tabstrip.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/simple_message_box.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/chrome_switches.h"
+#include "chromeos/chromeos_switches.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/plugin_service.h"
+#include "content/public/common/pepper_plugin_info.h"
+#include "content/public/common/webplugininfo.h"
+#include "net/base/net_util.h"
+
+using content::BrowserThread;
+using content::PluginService;
+
+namespace file_manager {
+namespace util {
+namespace {
+
+const base::FilePath::CharType kCRXExtension[] = FILE_PATH_LITERAL(".crx");
+const base::FilePath::CharType kPdfExtension[] = FILE_PATH_LITERAL(".pdf");
+const base::FilePath::CharType kSwfExtension[] = FILE_PATH_LITERAL(".swf");
+
+// List of file extensions viewable in the browser.
+const base::FilePath::CharType* kFileExtensionsViewableInBrowser[] = {
+#if defined(GOOGLE_CHROME_BUILD)
+ FILE_PATH_LITERAL(".pdf"),
+ FILE_PATH_LITERAL(".swf"),
+#endif
+ FILE_PATH_LITERAL(".bmp"),
+ FILE_PATH_LITERAL(".jpg"),
+ FILE_PATH_LITERAL(".jpeg"),
+ FILE_PATH_LITERAL(".png"),
+ FILE_PATH_LITERAL(".webp"),
+ FILE_PATH_LITERAL(".gif"),
+ FILE_PATH_LITERAL(".txt"),
+ FILE_PATH_LITERAL(".html"),
+ FILE_PATH_LITERAL(".htm"),
+ FILE_PATH_LITERAL(".mhtml"),
+ FILE_PATH_LITERAL(".mht"),
+ FILE_PATH_LITERAL(".svg"),
+};
+
+// Returns true if |file_path| is viewable in the browser (ex. HTML file).
+bool IsViewableInBrowser(const base::FilePath& file_path) {
+ for (size_t i = 0; i < arraysize(kFileExtensionsViewableInBrowser); i++) {
+ if (file_path.MatchesExtension(kFileExtensionsViewableInBrowser[i]))
+ return true;
+ }
+ return false;
+}
+
+bool IsPepperPluginEnabled(Profile* profile,
+ const base::FilePath& plugin_path) {
+ content::PepperPluginInfo* pepper_info =
+ PluginService::GetInstance()->GetRegisteredPpapiPluginInfo(plugin_path);
+ if (!pepper_info)
+ return false;
+
+ scoped_refptr<PluginPrefs> plugin_prefs = PluginPrefs::GetForProfile(profile);
+ if (!plugin_prefs.get())
+ return false;
+
+ return plugin_prefs->IsPluginEnabled(pepper_info->ToWebPluginInfo());
+}
+
+bool IsPdfPluginEnabled(Profile* profile) {
+ base::FilePath plugin_path;
+ PathService::Get(chrome::FILE_PDF_PLUGIN, &plugin_path);
+ return IsPepperPluginEnabled(profile, plugin_path);
+}
+
+bool IsFlashPluginEnabled(Profile* profile) {
+ base::FilePath plugin_path(
+ CommandLine::ForCurrentProcess()->GetSwitchValueNative(
+ switches::kPpapiFlashPath));
+ if (plugin_path.empty())
+ PathService::Get(chrome::FILE_PEPPER_FLASH_PLUGIN, &plugin_path);
+ return IsPepperPluginEnabled(profile, plugin_path);
+}
+
+void OpenNewTab(Profile* profile, const GURL& url) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ Browser* browser = chrome::FindOrCreateTabbedBrowser(
+ profile ? profile : ProfileManager::GetDefaultProfileOrOffTheRecord(),
+ chrome::HOST_DESKTOP_TYPE_ASH);
+ chrome::AddSelectedTabWithURL(browser, url, content::PAGE_TRANSITION_LINK);
+ // If the current browser is not tabbed then the new tab will be created
+ // in a different browser. Make sure it is visible.
+ browser->window()->Show();
+}
+
+void InstallCRX(Browser* browser, const base::FilePath& file_path) {
+ ExtensionService* service =
+ extensions::ExtensionSystem::Get(browser->profile())->extension_service();
+ CHECK(service);
+
+ scoped_refptr<extensions::CrxInstaller> installer(
+ extensions::CrxInstaller::Create(
+ service,
+ scoped_ptr<ExtensionInstallPrompt>(new ExtensionInstallPrompt(
+ browser->profile(), NULL, NULL))));
+ installer->set_error_on_unsupported_requirements(true);
+ installer->set_is_gallery_install(false);
+ installer->set_allow_silent_install(false);
+ installer->InstallCrx(file_path);
+}
+
+// Called when a crx file on Drive was downloaded.
+void OnCRXDownloadCallback(Browser* browser,
+ drive::FileError error,
+ const base::FilePath& file,
+ scoped_ptr<drive::ResourceEntry> entry) {
+ if (error != drive::FILE_ERROR_OK)
+ return;
+ InstallCRX(browser, file);
+}
+
+// Reads the alternate URL from a GDoc file. When it fails, returns a file URL
+// for |file_path| as fallback.
+// Note that an alternate url is a URL to open a hosted document.
+GURL ReadUrlFromGDocOnBlockingPool(const base::FilePath& file_path) {
+ GURL url = drive::util::ReadUrlFromGDocFile(file_path);
+ if (url.is_empty())
+ url = net::FilePathToFileURL(file_path);
+ return url;
+}
+
+} // namespace
+
+bool OpenFileWithBrowser(Browser* browser, const base::FilePath& file_path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ Profile* profile = browser->profile();
+ // For things supported natively by the browser, we should open it
+ // in a tab.
+ if (IsViewableInBrowser(file_path) ||
+ ShouldBeOpenedWithPlugin(profile, file_path.Extension())) {
+ GURL page_url = net::FilePathToFileURL(file_path);
+ // Override drive resource to point to internal handler instead of file URL.
+ if (drive::util::IsUnderDriveMountPoint(file_path)) {
+ page_url = drive::util::FilePathToDriveURL(
+ drive::util::ExtractDrivePath(file_path));
+ }
+ OpenNewTab(profile, page_url);
+ return true;
+ }
+
+ if (drive::util::HasGDocFileExtension(file_path)) {
+ if (drive::util::IsUnderDriveMountPoint(file_path)) {
+ // The file is on Google Docs. Open with drive URL.
+ GURL url = drive::util::FilePathToDriveURL(
+ drive::util::ExtractDrivePath(file_path));
+ OpenNewTab(profile, url);
+ } else {
+ // The file is local (downloaded from an attachment or otherwise copied).
+ // Parse the file to extract the Docs url and open this url.
+ base::PostTaskAndReplyWithResult(
+ BrowserThread::GetBlockingPool(),
+ FROM_HERE,
+ base::Bind(&ReadUrlFromGDocOnBlockingPool, file_path),
+ base::Bind(&OpenNewTab, static_cast<Profile*>(NULL)));
+ }
+ return true;
+ }
+
+ if (file_path.MatchesExtension(kCRXExtension)) {
+ if (drive::util::IsUnderDriveMountPoint(file_path)) {
+ drive::DriveIntegrationService* integration_service =
+ drive::DriveIntegrationServiceFactory::GetForProfile(profile);
+ if (!integration_service)
+ return false;
+ integration_service->file_system()->GetFileByPath(
+ drive::util::ExtractDrivePath(file_path),
+ base::Bind(&OnCRXDownloadCallback, browser));
+ } else {
+ InstallCRX(browser, file_path);
+ }
+ return true;
+ }
+
+ // Failed to open the file of unknown type.
+ LOG(WARNING) << "Unknown file type: " << file_path.value();
+ return false;
+}
+
+// If a bundled plugin is enabled, we should open pdf/swf files in a tab.
+bool ShouldBeOpenedWithPlugin(
+ Profile* profile,
+ const base::FilePath::StringType& file_extension) {
+ const base::FilePath file_path =
+ base::FilePath::FromUTF8Unsafe("dummy").AddExtension(file_extension);
+ if (file_path.MatchesExtension(kPdfExtension))
+ return IsPdfPluginEnabled(profile);
+ if (file_path.MatchesExtension(kSwfExtension))
+ return IsFlashPluginEnabled(profile);
+ return false;
+}
+
+} // namespace util
+} // namespace file_manager
diff --git a/chrome/browser/chromeos/extensions/file_manager/open_with_browser.h b/chrome/browser/chromeos/extensions/file_manager/open_with_browser.h
new file mode 100644
index 0000000..dfcdc05
--- /dev/null
+++ b/chrome/browser/chromeos/extensions/file_manager/open_with_browser.h
@@ -0,0 +1,38 @@
+// Copyright 2013 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.
+//
+// This file provides utilities for opening files with the browser.
+
+#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_OPEN_WITH_BROWSER_H_
+#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_OPEN_WITH_BROWSER_H_
+
+#include "base/files/file_path.h"
+
+class Browser;
+class Profile;
+
+namespace file_manager {
+namespace util {
+
+// Opens the file specified by |file_path| with the browser. This function takes
+// care of the following intricacies:
+//
+// - If the file is a Drive hosted document, the hosted document will be
+// opened in the browser by extracting the right URL for the file.
+// - If the file is a CRX file, the CRX file will be installed.
+// - If the file is on Drive, the file will be downloaded from Drive as
+// needed.
+//
+// Returns false if failed to open. This happens if the file type is unknown.
+bool OpenFileWithBrowser(Browser* browser, const base::FilePath& file_path);
+
+// Checks whether a pepper plugin for |file_extension| is enabled.
+bool ShouldBeOpenedWithPlugin(
+ Profile* profile,
+ const base::FilePath::StringType& file_extension);
+
+} // namespace util
+} // namespace file_manager
+
+#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_OPEN_WITH_BROWSER_H_
diff --git a/chrome/browser/chromeos/extensions/file_manager/private_api_strings.cc b/chrome/browser/chromeos/extensions/file_manager/private_api_strings.cc
index fe21f77..864bf06 100644
--- a/chrome/browser/chromeos/extensions/file_manager/private_api_strings.cc
+++ b/chrome/browser/chromeos/extensions/file_manager/private_api_strings.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/extensions/file_manager/private_api_strings.h"
#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
+#include "chrome/browser/chromeos/extensions/file_manager/open_with_browser.h"
#include "chrome/browser/chromeos/system/statistics_provider.h"
#include "grit/app_locale_settings.h"
#include "grit/generated_resources.h"
diff --git a/chrome/browser/chromeos/extensions/file_manager/private_api_tasks.cc b/chrome/browser/chromeos/extensions/file_manager/private_api_tasks.cc
index 2456b40..27c2188 100644
--- a/chrome/browser/chromeos/extensions/file_manager/private_api_tasks.cc
+++ b/chrome/browser/chromeos/extensions/file_manager/private_api_tasks.cc
@@ -9,6 +9,7 @@
#include "chrome/browser/chromeos/extensions/file_manager/file_browser_handlers.h"
#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
#include "chrome/browser/chromeos/extensions/file_manager/file_tasks.h"
+#include "chrome/browser/chromeos/extensions/file_manager/open_with_browser.h"
#include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
#include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi
index c162cd1..eaaba93 100644
--- a/chrome/chrome_browser_chromeos.gypi
+++ b/chrome/chrome_browser_chromeos.gypi
@@ -340,6 +340,8 @@
'browser/chromeos/extensions/file_manager/fileapi_util.h',
'browser/chromeos/extensions/file_manager/mounted_disk_monitor.cc',
'browser/chromeos/extensions/file_manager/mounted_disk_monitor.h',
+ 'browser/chromeos/extensions/file_manager/open_with_browser.cc',
+ 'browser/chromeos/extensions/file_manager/open_with_browser.h',
'browser/chromeos/extensions/file_manager/url_util.cc',
'browser/chromeos/extensions/file_manager/url_util.h',
'browser/chromeos/extensions/file_manager/zip_file_creator.cc',