Commit 92036afe authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Open hosted docs from DriveFS using the doc's URL.

Bug: 844294
Change-Id: I6f91d058e6c8bbd3dec574c2ac5b6ea1ae2b42b5
Reviewed-on: https://chromium-review.googlesource.com/1071489
Commit-Queue: Sam McNally <sammc@chromium.org>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561770}
parent 8215c75f
......@@ -13,6 +13,7 @@
#include "base/path_service.h"
#include "base/task_scheduler/post_task.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/file_manager/filesystem_api_util.h"
#include "chrome/browser/chromeos/fileapi/external_file_url_util.h"
#include "chrome/browser/plugins/plugin_prefs.h"
......@@ -25,6 +26,7 @@
#include "chrome/common/chrome_content_client.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chromeos/components/drivefs/mojom/drivefs.mojom.h"
#include "components/drive/drive_api_util.h"
#include "components/drive/file_system_core_util.h"
#include "content/public/browser/browser_thread.h"
......@@ -126,6 +128,32 @@ GURL ReadUrlFromGDocAsync(const base::FilePath& file_path) {
return url;
}
// Parse a local file to extract the Docs url and open this url.
void OpenGDocUrlFromFile(const base::FilePath& file_path, Profile* profile) {
base::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {base::MayBlock()},
base::BindOnce(&ReadUrlFromGDocAsync, file_path),
base::BindOnce(&OpenNewTab, profile));
}
// Open a hosted GDoc, from a path hosted in DriveFS.
void OpenHostedDriveFsFile(const base::FilePath& file_path,
Profile* profile,
drive::FileError error,
drivefs::mojom::FileMetadataPtr metadata) {
if (error != drive::FILE_ERROR_OK)
return;
if (!metadata->hosted) {
OpenGDocUrlFromFile(file_path, profile);
return;
}
GURL hosted_url(metadata->alternate_url);
if (!hosted_url.is_valid())
return;
OpenNewTab(profile, hosted_url);
}
} // namespace
bool OpenFileWithBrowser(Profile* profile,
......@@ -159,12 +187,17 @@ bool OpenFileWithBrowser(Profile* profile,
DCHECK(!url.is_empty());
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::PostTaskWithTraitsAndReplyWithResult(
FROM_HERE, {base::MayBlock()},
base::Bind(&ReadUrlFromGDocAsync, file_path),
base::Bind(&OpenNewTab, profile));
drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::FindForProfile(profile);
if (integration_service && integration_service->IsMounted() &&
integration_service->GetDriveFsInterface() &&
integration_service->GetMountPointPath().IsParent(file_path)) {
integration_service->GetDriveFsInterface()->GetMetadata(
file_path,
base::BindOnce(&OpenHostedDriveFsFile, file_path, profile));
return true;
}
OpenGDocUrlFromFile(file_path, profile);
}
return true;
}
......
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