Commit 3fffa882 authored by Jay Harris's avatar Jay Harris Committed by Commit Bot

Exposes a function for getting a Promise<LaunchParams> on Window.

In future, this will allow applications to query information about how
they were launched. Currently, the promise is hard coded to resolve to
{ cause: 'default', files: [] }.

The mojom security review requires that new services be as complete as
possible, hence the stubbing that is going on here
https://chromium.googlesource.com/chromium/src/+/master/docs/security/mojo.md#Do-not-define-unused-or-unimplemented-things
(a previous CL was rejected due to having an incomplete mojo service: https://chromium-review.googlesource.com/c/chromium/src/+/1597516).

This CL is a part of file-handling
https://github.com/WICG/file-handling/blob/master/EXPLAINER.md

Bug: 829689
Change-Id: I03d07d47b5b4c29d8367f465a34e439262e37dd4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1621418Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Jay Harris <harrisjay@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666604}
parent 0f211ef7
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/badging/badge_manager.h" #include "chrome/browser/badging/badge_manager.h"
...@@ -80,6 +82,8 @@ ...@@ -80,6 +82,8 @@
#include "net/dns/mock_host_resolver.h" #include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/request_handler_util.h" #include "net/test/embedded_test_server/request_handler_util.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/manifest/manifest.h"
#include "third_party/blink/public/mojom/renderer_preferences.mojom.h" #include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
#include "ui/base/clipboard/clipboard.h" #include "ui/base/clipboard/clipboard.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -917,6 +921,69 @@ IN_PROC_BROWSER_TEST_P(HostedAppTest, InScopeHttpUrlsDisplayAppTitle) { ...@@ -917,6 +921,69 @@ IN_PROC_BROWSER_TEST_P(HostedAppTest, InScopeHttpUrlsDisplayAppTitle) {
app_browser->GetWindowTitleForCurrentTab(false)); app_browser->GetWindowTitleForCurrentTab(false));
} }
class HostedAppFileHandlingTest : public HostedAppTest {
public:
HostedAppFileHandlingTest() {
scoped_feature_list_.InitWithFeatures(
{blink::features::kNativeFileSystemAPI,
blink::features::kFileHandlingAPI},
{});
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
IN_PROC_BROWSER_TEST_P(HostedAppFileHandlingTest, PWAsCanViewLaunchParams) {
ASSERT_TRUE(https_server()->Start());
GURL url = GetSecureAppURL();
WebApplicationInfo web_app_info;
web_app_info.app_url = url;
web_app_info.scope = url.GetWithoutFilename();
web_app_info.title = base::ASCIIToUTF16("A Hosted App");
web_app_info.file_handler = blink::Manifest::FileHandler();
web_app_info.file_handler->action =
GURL(https_server()->GetURL("app.com", "/ssl/blank_page.html"));
{
std::vector<blink::Manifest::FileFilter> filters;
blink::Manifest::FileFilter text = {
base::ASCIIToUTF16("text"),
{base::ASCIIToUTF16(".txt"), base::ASCIIToUTF16("text/*")}};
filters.push_back(text);
web_app_info.file_handler->files = std::move(filters);
}
const extensions::Extension* app = InstallBookmarkApp(web_app_info);
AppLaunchParams params(browser()->profile(), app,
extensions::LaunchContainer::LAUNCH_CONTAINER_WINDOW,
WindowOpenDisposition::NEW_WINDOW,
extensions::AppLaunchSource::SOURCE_FILE_HANDLER);
content::TestNavigationObserver navigation_observer(
web_app_info.file_handler->action);
navigation_observer.StartWatchingNewWebContents();
content::WebContents* web_contents =
OpenApplicationWindow(params, web_app_info.file_handler->action);
navigation_observer.Wait();
base::Value expected(base::Value::Type::DICTIONARY);
expected.SetStringKey("cause", "default");
expected.SetIntKey("length", 0);
EXPECT_EQ(expected,
content::EvalJsWithManualReply(
web_contents,
"getLaunchParams().then(params => {"
"domAutomationController.send({ cause: params.cause, length: "
"params.files.length });"
"});"));
}
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
class HostedAppBadgingTest : public HostedAppTest { class HostedAppBadgingTest : public HostedAppTest {
public: public:
...@@ -2908,6 +2975,11 @@ INSTANTIATE_TEST_SUITE_P( ...@@ -2908,6 +2975,11 @@ INSTANTIATE_TEST_SUITE_P(
HostedAppSitePerProcessTest, HostedAppSitePerProcessTest,
::testing::Values(AppType::HOSTED_APP)); ::testing::Values(AppType::HOSTED_APP));
INSTANTIATE_TEST_SUITE_P(
/* no prefix */,
HostedAppFileHandlingTest,
::testing::Values(AppType::BOOKMARK_APP));
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
/* no prefix */, /* no prefix */,
......
...@@ -440,8 +440,11 @@ void SetIndividualRuntimeFeatures( ...@@ -440,8 +440,11 @@ void SetIndividualRuntimeFeatures(
if (command_line.HasSwitch(switches::kEnableAccessibilityObjectModel)) if (command_line.HasSwitch(switches::kEnableAccessibilityObjectModel))
WebRuntimeFeatures::EnableAccessibilityObjectModel(true); WebRuntimeFeatures::EnableAccessibilityObjectModel(true);
if (base::FeatureList::IsEnabled(blink::features::kNativeFileSystemAPI)) if (base::FeatureList::IsEnabled(blink::features::kNativeFileSystemAPI)) {
WebRuntimeFeatures::EnableFeatureFromString("NativeFileSystem", true); WebRuntimeFeatures::EnableFeatureFromString("NativeFileSystem", true);
if (base::FeatureList::IsEnabled(blink::features::kFileHandlingAPI))
WebRuntimeFeatures::EnableFeatureFromString("FileHandling", true);
}
if (base::FeatureList::IsEnabled( if (base::FeatureList::IsEnabled(
blink::features::kForbidSyncXHRInPageDismissal)) { blink::features::kForbidSyncXHRInPageDismissal)) {
......
...@@ -118,6 +118,7 @@ target("jumbo_" + modules_target_type, "modules") { ...@@ -118,6 +118,7 @@ target("jumbo_" + modules_target_type, "modules") {
"//third_party/blink/renderer/modules/installation", "//third_party/blink/renderer/modules/installation",
"//third_party/blink/renderer/modules/installedapp", "//third_party/blink/renderer/modules/installedapp",
"//third_party/blink/renderer/modules/keyboard", "//third_party/blink/renderer/modules/keyboard",
"//third_party/blink/renderer/modules/launch",
"//third_party/blink/renderer/modules/locks", "//third_party/blink/renderer/modules/locks",
"//third_party/blink/renderer/modules/manifest", "//third_party/blink/renderer/modules/manifest",
"//third_party/blink/renderer/modules/media_capabilities", "//third_party/blink/renderer/modules/media_capabilities",
......
# Copyright 2019 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.
import("//third_party/blink/renderer/modules/modules.gni")
blink_modules_sources("launch") {
sources = [
"dom_window_launch_params.cc",
"dom_window_launch_params.h",
"launch_params.cc",
"launch_params.h",
]
deps = [
"//third_party/blink/renderer/modules/filesystem",
]
}
harrisjay@chromium.org
# TEAM: web-apps-platform-team@chromium.org
# COMPONENT: UI->Browser->WebAppInstalls
\ No newline at end of file
# Launch Events API
This directory contains the renderer side implementation of the client window [launch event API](https://github.com/WICG/sw-launch/blob/master/explainer.md).
> Note: This API is under active development, and is a work in progress.
## APIs in this Directory
This API consists of the following parts:
- `LaunchParams`: These are the parameters that the renderer was launched with. Currently, only file launches are supported but this will be extended in the future.
- `getLaunchParams`: An entry point for getting the cause of a launch from a client window.
\ No newline at end of file
// Copyright 2019 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 "third_party/blink/renderer/modules/launch/dom_window_launch_params.h"
#include "base/bind.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/task/post_task.h"
#include "mojo/public/cpp/bindings/associated_interface_ptr.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/mojom/native_file_system/native_file_system_directory_handle.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/modules/launch/launch_params.h"
#include "third_party/blink/renderer/modules/native_file_system/native_file_system_handle.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/heap/visitor.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
namespace blink {
const char DOMWindowLaunchParams::kSupplementName[] = "DOMWindowLaunchParams";
DOMWindowLaunchParams::DOMWindowLaunchParams(ExecutionContext* context) {}
DOMWindowLaunchParams::~DOMWindowLaunchParams() = default;
ScriptPromise DOMWindowLaunchParams::getLaunchParams(ScriptState* script_state,
LocalDOMWindow& window) {
if (!base::FeatureList::IsEnabled(blink::features::kNativeFileSystemAPI) ||
!base::FeatureList::IsEnabled(blink::features::kFileHandlingAPI)) {
return ScriptPromise::RejectWithDOMException(
script_state,
MakeGarbageCollected<DOMException>(DOMExceptionCode::kAbortError));
}
return FromState(script_state, &window)->GetLaunchParams(script_state);
}
ScriptPromise DOMWindowLaunchParams::GetLaunchParams(
ScriptState* script_state) {
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
ScriptPromise resolver_result = resolver->Promise();
// Immediately resolve the promise if the launch params are already known.
// TODO(crbug.com/829689): Getting the launch params from the browser will be
// asynchronous, so it will be possible that the |launch_params_| have not
// been initialized. Once a launch service has been created, a list of
// unresolved promises should be stored, so they can be resolved once the
// service has responded to a request for launch params.
resolver->Resolve(launch_params_);
return resolver_result;
}
void DOMWindowLaunchParams::Trace(blink::Visitor* visitor) {
visitor->Trace(launch_params_);
Supplement<LocalDOMWindow>::Trace(visitor);
}
// static
DOMWindowLaunchParams* DOMWindowLaunchParams::FromState(
ScriptState* script_state,
LocalDOMWindow* window) {
ExecutionContext* context = ExecutionContext::From(script_state);
DOMWindowLaunchParams* supplement =
Supplement<LocalDOMWindow>::From<DOMWindowLaunchParams>(window);
if (!supplement) {
supplement = MakeGarbageCollected<DOMWindowLaunchParams>(context);
ProvideTo(*window, supplement);
// TODO(crbug.com/829689): When a service is created for getting launch
// params from the browser process, use that instead of hard coding the
// launch params.
supplement->launch_params_ = MakeGarbageCollected<LaunchParams>(
"default", HeapVector<Member<NativeFileSystemHandle>>());
}
return supplement;
}
} // namespace blink
// Copyright 2019 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.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_LAUNCH_DOM_WINDOW_LAUNCH_PARAMS_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_LAUNCH_DOM_WINDOW_LAUNCH_PARAMS_H_
#include "third_party/blink/renderer/modules/launch/launch_params.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/heap/heap_allocator.h"
#include "third_party/blink/renderer/platform/supplementable.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
class LocalDOMWindow;
class ScriptPromiseResolver;
class ExecutionContext;
class ScriptPromiseResolver;
class Visitor;
class DOMWindowLaunchParams final
: public GarbageCollectedFinalized<DOMWindowLaunchParams>,
public Supplement<LocalDOMWindow> {
USING_GARBAGE_COLLECTED_MIXIN(DOMWindowLaunchParams);
public:
static const char kSupplementName[];
explicit DOMWindowLaunchParams(ExecutionContext*);
~DOMWindowLaunchParams();
// IDL Interface.
static ScriptPromise getLaunchParams(ScriptState*, LocalDOMWindow&);
ScriptPromise GetLaunchParams(ScriptState*);
void Trace(blink::Visitor*) override;
private:
static DOMWindowLaunchParams* FromState(ScriptState*, LocalDOMWindow* window);
Member<LaunchParams> launch_params_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_LAUNCH_DOM_WINDOW_LAUNCH_PARAMS_H_
// Copyright 2019 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.
// TODO(crbug.com/829689): Add link to spec once complete.
// Explainer: https://github.com/WICG/file-handling/blob/master/explainer.md
[
ImplementedAs=DOMWindowLaunchParams,
RuntimeEnabled=FileHandling
] partial interface Window {
[CallWith=ScriptState]
Promise<LaunchParams> getLaunchParams();
};
// Copyright 2019 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 "third_party/blink/renderer/modules/launch/launch_params.h"
#include "third_party/blink/renderer/modules/native_file_system/native_file_system_handle.h"
#include "third_party/blink/renderer/platform/heap/visitor.h"
namespace blink {
LaunchParams::LaunchParams(String cause,
HeapVector<Member<NativeFileSystemHandle>> files)
: cause_(cause), files_(files) {}
LaunchParams::~LaunchParams() = default;
void LaunchParams::Trace(blink::Visitor* visitor) {
visitor->Trace(files_);
ScriptWrappable::Trace(visitor);
}
} // namespace blink
// Copyright 2019 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
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_LAUNCH_LAUNCH_PARAMS_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_LAUNCH_LAUNCH_PARAMS_H_
#include "third_party/blink/renderer/modules/native_file_system/native_file_system_handle.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/heap/heap_allocator.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
class Visitor;
class LaunchParams final : public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO();
public:
LaunchParams(String cause, HeapVector<Member<NativeFileSystemHandle>> files);
~LaunchParams() override;
// LaunchParams IDL interface.
const String& cause() { return cause_; }
const HeapVector<Member<NativeFileSystemHandle>>& files() { return files_; }
void Trace(blink::Visitor*) override;
private:
String cause_;
HeapVector<Member<NativeFileSystemHandle>> files_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_LAUNCH_LAUNCH_PARAMS_H_
// Copyright 2019 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.
// TODO(crbug.com/829689): Add link to spec once complete.
// Explainer: https://github.com/WICG/file-handling/blob/master/explainer.md
[RuntimeEnabled=FileHandling] interface LaunchParams {
readonly attribute DOMString cause;
[SameObject]
readonly attribute FrozenArray<FileSystemBaseHandle> files;
};
...@@ -151,6 +151,7 @@ modules_idl_files = ...@@ -151,6 +151,7 @@ modules_idl_files =
"filesystem/file_writer_sync.idl", "filesystem/file_writer_sync.idl",
"filesystem/metadata.idl", "filesystem/metadata.idl",
"filesystem/metadata_callback.idl", "filesystem/metadata_callback.idl",
"launch/launch_params.idl",
"gamepad/gamepad.idl", "gamepad/gamepad.idl",
"gamepad/gamepad_axis_event.idl", "gamepad/gamepad_axis_event.idl",
"gamepad/gamepad_button.idl", "gamepad/gamepad_button.idl",
...@@ -898,6 +899,7 @@ modules_dependency_idl_files = ...@@ -898,6 +899,7 @@ modules_dependency_idl_files =
"filesystem/html_input_element_file_system.idl", "filesystem/html_input_element_file_system.idl",
"filesystem/shared_worker_global_scope_file_system.idl", "filesystem/shared_worker_global_scope_file_system.idl",
"filesystem/window_file_system.idl", "filesystem/window_file_system.idl",
"launch/dom_window_launch_params.idl",
"gamepad/navigator_gamepad.idl", "gamepad/navigator_gamepad.idl",
"geolocation/navigator_geolocation.idl", "geolocation/navigator_geolocation.idl",
"hid/navigator_hid.idl", "hid/navigator_hid.idl",
......
...@@ -599,6 +599,10 @@ ...@@ -599,6 +599,10 @@
name: "FetchMetadataDestination", name: "FetchMetadataDestination",
status: "experimental" status: "experimental"
}, },
{
name: "FileHandling",
depends_on: ["NativeFileSystem"]
},
{ {
name: "FileSystem", name: "FileSystem",
status: "stable", status: "stable",
......
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