Commit a2dc6669 authored by tmdiep@chromium.org's avatar tmdiep@chromium.org

Ephemeral apps should not appear in ChromeOS file manager menus

Ephemeral apps should not be used to open files via the ChromeOS file
manager as they are not permanently installed.

BUG=391145
TEST=unit_tests

Review URL: https://codereview.chromium.org/381583007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282312 0039d316-1c4b-4281-b951-d872f2087c98
parent a8f068c0
......@@ -28,6 +28,7 @@
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/lazy_background_task_queue.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/manifest_handlers/background_info.h"
......@@ -115,6 +116,8 @@ FileBrowserHandlerList FindFileBrowserHandlersForURL(
if (profile->IsOffTheRecord() &&
!extensions::util::IsIncognitoEnabled(extension->id(), profile))
continue;
if (extensions::util::IsEphemeralApp(extension->id(), profile))
continue;
FileBrowserHandler::List* handler_list =
FileBrowserHandler::GetHandlers(extension);
......
......@@ -29,6 +29,7 @@
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_util.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension_set.h"
#include "google_apis/drive/gdata_wapi_parser.h"
......@@ -384,6 +385,10 @@ void FindFileHandlerTasks(
if (!extension->is_platform_app())
continue;
// Ephemeral apps cannot be file handlers.
if (extensions::util::IsEphemeralApp(extension->id(), profile))
continue;
if (profile->IsOffTheRecord() &&
!extensions::util::IsIncognitoEnabled(extension->id(), profile))
continue;
......
......@@ -22,6 +22,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension_builder.h"
#include "google_apis/drive/drive_api_parser.h"
......@@ -379,6 +380,7 @@ TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTasks) {
// % ruby -le 'print (0...32).to_a.map{(?a + rand(16)).chr}.join'
const char kFooId[] = "hhgbjpmdppecanaaogonaigmmifgpaph";
const char kBarId[] = "odlhccgofgkadkkhcmhgnhgahonahoca";
const char kEphemeralId[] = "opoomfdlbjcbjinalcjdjfoiikdeaoel";
// Foo.app can handle "text/plain" and "text/html".
extensions::ExtensionBuilder foo_app;
......@@ -429,6 +431,38 @@ TEST_F(FileManagerFileTasksComplexTest, FindFileHandlerTasks) {
bar_app.SetID(kBarId);
extension_service_->AddExtension(bar_app.Build().get());
// Ephemeral.app is an ephemeral app that can handle "text/plain".
// It should not ever be found as ephemeral apps cannot be file handlers.
extensions::ExtensionBuilder ephemeral_app;
ephemeral_app.SetManifest(
extensions::DictionaryBuilder()
.Set("name", "Ephemeral")
.Set("version", "1.0.0")
.Set("manifest_version", 2)
.Set("app",
extensions::DictionaryBuilder().Set(
"background",
extensions::DictionaryBuilder().Set(
"scripts",
extensions::ListBuilder().Append("background.js"))))
.Set("file_handlers",
extensions::DictionaryBuilder().Set(
"text",
extensions::DictionaryBuilder().Set("title", "Text").Set(
"types",
extensions::ListBuilder().Append("text/plain")))));
ephemeral_app.SetID(kEphemeralId);
scoped_refptr<extensions::Extension> built_ephemeral_app(
ephemeral_app.Build());
extension_service_->AddExtension(built_ephemeral_app.get());
extensions::ExtensionPrefs* extension_prefs =
extensions::ExtensionPrefs::Get(&test_profile_);
extension_prefs->OnExtensionInstalled(built_ephemeral_app.get(),
extensions::Extension::ENABLED,
syncer::StringOrdinal(),
extensions::kInstallFlagIsEphemeral,
std::string());
// Find apps for a "text/plain" file. Foo.app and Bar.app should be found.
PathAndMimeTypeSet path_mime_set;
path_mime_set.insert(
......@@ -483,6 +517,7 @@ TEST_F(FileManagerFileTasksComplexTest, FindFileBrowserHandlerTasks) {
// Copied from FindFileHandlerTasks test above.
const char kFooId[] = "hhgbjpmdppecanaaogonaigmmifgpaph";
const char kBarId[] = "odlhccgofgkadkkhcmhgnhgahonahoca";
const char kEphemeralId[] = "opoomfdlbjcbjinalcjdjfoiikdeaoel";
// Foo.app can handle ".txt" and ".html".
// This one is an extension, and has "file_browser_handlers"
......@@ -520,6 +555,35 @@ TEST_F(FileManagerFileTasksComplexTest, FindFileBrowserHandlerTasks) {
bar_app.SetID(kBarId);
extension_service_->AddExtension(bar_app.Build().get());
// Ephemeral.app is an ephemeral app that can handle ".txt".
// It should not ever be found as ephemeral apps cannot be file browser
// handlers.
extensions::ExtensionBuilder ephemeral_app;
ephemeral_app.SetManifest(
extensions::DictionaryBuilder()
.Set("name", "Ephemeral")
.Set("version", "1.0.0")
.Set("manifest_version", 2)
.Set("file_browser_handlers",
extensions::ListBuilder().Append(
extensions::DictionaryBuilder()
.Set("id", "open")
.Set("default_title", "open")
.Set("file_filters",
extensions::ListBuilder().Append(
"filesystem:*.txt")))));
ephemeral_app.SetID(kEphemeralId);
scoped_refptr<extensions::Extension> built_ephemeral_app(
ephemeral_app.Build());
extension_service_->AddExtension(built_ephemeral_app.get());
extensions::ExtensionPrefs* extension_prefs =
extensions::ExtensionPrefs::Get(&test_profile_);
extension_prefs->OnExtensionInstalled(built_ephemeral_app.get(),
extensions::Extension::ENABLED,
syncer::StringOrdinal(),
extensions::kInstallFlagIsEphemeral,
std::string());
// Find apps for a ".txt" file. Foo.app and Bar.app should be found.
std::vector<GURL> file_urls;
file_urls.push_back(GURL("filesystem:chrome-extension://id/dir/foo.txt"));
......
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