Commit cd4ce0de authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

Convert WebTestHostMsg_SetPermission to Mojo

This CL migrates the legacy SetPermission IPC message
to the new Mojo defined in WebTestClient interface.

Bug: 1039247
Change-Id: If6534315b0d1c66dea500c29a17f3ff2d515634d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2037178
Commit-Queue: Gyuyoung Kim <gyuyoung@igalia.com>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739396}
parent 8ee798dd
...@@ -101,4 +101,55 @@ void WebTestClientImpl::ResetPermissions() { ...@@ -101,4 +101,55 @@ void WebTestClientImpl::ResetPermissions() {
->ResetPermissions(); ->ResetPermissions();
} }
void WebTestClientImpl::SetPermission(const std::string& name,
blink::mojom::PermissionStatus status,
const GURL& origin,
const GURL& embedding_origin) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
content::PermissionType type;
if (name == "midi") {
type = PermissionType::MIDI;
} else if (name == "midi-sysex") {
type = PermissionType::MIDI_SYSEX;
} else if (name == "push-messaging" || name == "notifications") {
type = PermissionType::NOTIFICATIONS;
} else if (name == "geolocation") {
type = PermissionType::GEOLOCATION;
} else if (name == "protected-media-identifier") {
type = PermissionType::PROTECTED_MEDIA_IDENTIFIER;
} else if (name == "background-sync") {
type = PermissionType::BACKGROUND_SYNC;
} else if (name == "accessibility-events") {
type = PermissionType::ACCESSIBILITY_EVENTS;
} else if (name == "clipboard-read-write") {
type = PermissionType::CLIPBOARD_READ_WRITE;
} else if (name == "clipboard-sanitized-write") {
type = PermissionType::CLIPBOARD_SANITIZED_WRITE;
} else if (name == "payment-handler") {
type = PermissionType::PAYMENT_HANDLER;
} else if (name == "accelerometer" || name == "gyroscope" ||
name == "magnetometer" || name == "ambient-light-sensor") {
type = PermissionType::SENSORS;
} else if (name == "background-fetch") {
type = PermissionType::BACKGROUND_FETCH;
} else if (name == "periodic-background-sync") {
type = PermissionType::PERIODIC_BACKGROUND_SYNC;
} else if (name == "wake-lock-screen") {
type = PermissionType::WAKE_LOCK_SCREEN;
} else if (name == "wake-lock-system") {
type = PermissionType::WAKE_LOCK_SYSTEM;
} else if (name == "nfc") {
type = PermissionType::NFC;
} else {
NOTREACHED();
type = PermissionType::NOTIFICATIONS;
}
WebTestContentBrowserClient::Get()
->GetWebTestBrowserContext()
->GetWebTestPermissionManager()
->SetPermission(type, status, origin, embedding_origin);
}
} // namespace content } // namespace content
...@@ -34,6 +34,10 @@ class WebTestClientImpl : public mojom::WebTestClient { ...@@ -34,6 +34,10 @@ class WebTestClientImpl : public mojom::WebTestClient {
void SimulateWebContentIndexDelete(const std::string& id) override; void SimulateWebContentIndexDelete(const std::string& id) override;
void BlockThirdPartyCookies(bool block) override; void BlockThirdPartyCookies(bool block) override;
void ResetPermissions() override; void ResetPermissions() override;
void SetPermission(const std::string& name,
blink::mojom::PermissionStatus status,
const GURL& origin,
const GURL& embedding_origin) override;
}; };
} // namespace content } // namespace content
......
...@@ -76,7 +76,6 @@ WebTestMessageFilter::OverrideTaskRunnerForMessage( ...@@ -76,7 +76,6 @@ WebTestMessageFilter::OverrideTaskRunnerForMessage(
case WebTestHostMsg_ClearAllDatabases::ID: case WebTestHostMsg_ClearAllDatabases::ID:
return database_tracker_->task_runner(); return database_tracker_->task_runner();
case WebTestHostMsg_SimulateWebNotificationClick::ID: case WebTestHostMsg_SimulateWebNotificationClick::ID:
case WebTestHostMsg_SetPermission::ID:
case WebTestHostMsg_WebTestRuntimeFlagsChanged::ID: case WebTestHostMsg_WebTestRuntimeFlagsChanged::ID:
case WebTestHostMsg_InitiateCaptureDump::ID: case WebTestHostMsg_InitiateCaptureDump::ID:
case WebTestHostMsg_DeleteAllCookies::ID: case WebTestHostMsg_DeleteAllCookies::ID:
...@@ -98,7 +97,6 @@ bool WebTestMessageFilter::OnMessageReceived(const IPC::Message& message) { ...@@ -98,7 +97,6 @@ bool WebTestMessageFilter::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(WebTestHostMsg_SimulateWebNotificationClick, IPC_MESSAGE_HANDLER(WebTestHostMsg_SimulateWebNotificationClick,
OnSimulateWebNotificationClick) OnSimulateWebNotificationClick)
IPC_MESSAGE_HANDLER(WebTestHostMsg_DeleteAllCookies, OnDeleteAllCookies) IPC_MESSAGE_HANDLER(WebTestHostMsg_DeleteAllCookies, OnDeleteAllCookies)
IPC_MESSAGE_HANDLER(WebTestHostMsg_SetPermission, OnSetPermission)
IPC_MESSAGE_HANDLER(WebTestHostMsg_WebTestRuntimeFlagsChanged, IPC_MESSAGE_HANDLER(WebTestHostMsg_WebTestRuntimeFlagsChanged,
OnWebTestRuntimeFlagsChanged) OnWebTestRuntimeFlagsChanged)
IPC_MESSAGE_HANDLER(WebTestHostMsg_InitiateCaptureDump, IPC_MESSAGE_HANDLER(WebTestHostMsg_InitiateCaptureDump,
...@@ -169,58 +167,6 @@ void WebTestMessageFilter::OnDeleteAllCookies() { ...@@ -169,58 +167,6 @@ void WebTestMessageFilter::OnDeleteAllCookies() {
base::BindOnce([](uint32_t) {})); base::BindOnce([](uint32_t) {}));
} }
void WebTestMessageFilter::OnSetPermission(
const std::string& name,
blink::mojom::PermissionStatus status,
const GURL& origin,
const GURL& embedding_origin) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
content::PermissionType type;
if (name == "midi") {
type = PermissionType::MIDI;
} else if (name == "midi-sysex") {
type = PermissionType::MIDI_SYSEX;
} else if (name == "push-messaging" || name == "notifications") {
type = PermissionType::NOTIFICATIONS;
} else if (name == "geolocation") {
type = PermissionType::GEOLOCATION;
} else if (name == "protected-media-identifier") {
type = PermissionType::PROTECTED_MEDIA_IDENTIFIER;
} else if (name == "background-sync") {
type = PermissionType::BACKGROUND_SYNC;
} else if (name == "accessibility-events") {
type = PermissionType::ACCESSIBILITY_EVENTS;
} else if (name == "clipboard-read-write") {
type = PermissionType::CLIPBOARD_READ_WRITE;
} else if (name == "clipboard-sanitized-write") {
type = PermissionType::CLIPBOARD_SANITIZED_WRITE;
} else if (name == "payment-handler") {
type = PermissionType::PAYMENT_HANDLER;
} else if (name == "accelerometer" || name == "gyroscope" ||
name == "magnetometer" || name == "ambient-light-sensor") {
type = PermissionType::SENSORS;
} else if (name == "background-fetch") {
type = PermissionType::BACKGROUND_FETCH;
} else if (name == "periodic-background-sync") {
type = PermissionType::PERIODIC_BACKGROUND_SYNC;
} else if (name == "wake-lock-screen") {
type = PermissionType::WAKE_LOCK_SCREEN;
} else if (name == "wake-lock-system") {
type = PermissionType::WAKE_LOCK_SYSTEM;
} else if (name == "nfc") {
type = PermissionType::NFC;
} else {
NOTREACHED();
type = PermissionType::NOTIFICATIONS;
}
WebTestContentBrowserClient::Get()
->GetWebTestBrowserContext()
->GetWebTestPermissionManager()
->SetPermission(type, status, origin, embedding_origin);
}
void WebTestMessageFilter::OnWebTestRuntimeFlagsChanged( void WebTestMessageFilter::OnWebTestRuntimeFlagsChanged(
const base::DictionaryValue& changed_web_test_runtime_flags) { const base::DictionaryValue& changed_web_test_runtime_flags) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
......
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "services/network/public/mojom/cookie_manager.mojom.h" #include "services/network/public/mojom/cookie_manager.mojom.h"
#include "third_party/blink/public/mojom/permissions/permission_status.mojom-forward.h"
class GURL;
namespace base { namespace base {
class DictionaryValue; class DictionaryValue;
...@@ -69,10 +66,6 @@ class WebTestMessageFilter : public BrowserMessageFilter { ...@@ -69,10 +66,6 @@ class WebTestMessageFilter : public BrowserMessageFilter {
const base::Optional<int>& action_index, const base::Optional<int>& action_index,
const base::Optional<base::string16>& reply); const base::Optional<base::string16>& reply);
void OnDeleteAllCookies(); void OnDeleteAllCookies();
void OnSetPermission(const std::string& name,
blink::mojom::PermissionStatus status,
const GURL& origin,
const GURL& embedding_origin);
void OnWebTestRuntimeFlagsChanged( void OnWebTestRuntimeFlagsChanged(
const base::DictionaryValue& changed_web_test_runtime_flags); const base::DictionaryValue& changed_web_test_runtime_flags);
void OnInitiateCaptureDump(bool capture_navigation_history, void OnInitiateCaptureDump(bool capture_navigation_history,
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
module content.mojom; module content.mojom;
import "third_party/blink/public/mojom/permissions/permission_status.mojom";
import "url/mojom/url.mojom";
// Web test messages sent from the renderer process to the browser. // Web test messages sent from the renderer process to the browser.
interface WebTestClient { interface WebTestClient {
// Start to inspect a secondary window. // Start to inspect a secondary window.
...@@ -28,4 +31,11 @@ interface WebTestClient { ...@@ -28,4 +31,11 @@ interface WebTestClient {
// Reset all permissions of WebTestPermissionManager. // Reset all permissions of WebTestPermissionManager.
ResetPermissions(); ResetPermissions();
// Sets the permission for |name| to |status| when queried or requested in
// |origin| from |embedding_origin|.
SetPermission(string name,
blink.mojom.PermissionStatus status,
url.mojom.Url origin,
url.mojom.Url embedding_origin);
}; };
...@@ -33,11 +33,6 @@ IPC_MESSAGE_ROUTED3(WebTestHostMsg_SimulateWebNotificationClick, ...@@ -33,11 +33,6 @@ IPC_MESSAGE_ROUTED3(WebTestHostMsg_SimulateWebNotificationClick,
base::Optional<int> /* action_index */, base::Optional<int> /* action_index */,
base::Optional<base::string16> /* reply */) base::Optional<base::string16> /* reply */)
IPC_MESSAGE_ROUTED0(WebTestHostMsg_DeleteAllCookies) IPC_MESSAGE_ROUTED0(WebTestHostMsg_DeleteAllCookies)
IPC_MESSAGE_ROUTED4(WebTestHostMsg_SetPermission,
std::string /* name */,
blink::mojom::PermissionStatus /* status */,
GURL /* origin */,
GURL /* embedding_origin */)
IPC_MESSAGE_ROUTED2(WebTestHostMsg_InitiateCaptureDump, IPC_MESSAGE_ROUTED2(WebTestHostMsg_InitiateCaptureDump,
bool /* should dump navigation history */, bool /* should dump navigation history */,
bool /* should dump pixels */) bool /* should dump pixels */)
......
...@@ -624,9 +624,8 @@ void BlinkTestRunner::SetPermission(const std::string& name, ...@@ -624,9 +624,8 @@ void BlinkTestRunner::SetPermission(const std::string& name,
const std::string& value, const std::string& value,
const GURL& origin, const GURL& origin,
const GURL& embedding_origin) { const GURL& embedding_origin) {
Send(new WebTestHostMsg_SetPermission(routing_id(), name, GetWebTestClientRemote().SetPermission(name, blink::ToPermissionStatus(value),
blink::ToPermissionStatus(value), origin, embedding_origin);
origin, embedding_origin));
} }
void BlinkTestRunner::ResetPermissions() { void BlinkTestRunner::ResetPermissions() {
......
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