Remove origins from the PermissionService interface messages.
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_site_isolation
Change-Id: I392aa805b7d62816624cd944113c2132832dcf09
Bug: 779444
Reviewed-on: https://chromium-review.googlesource.com/706883
Commit-Queue: Sam McNally <sammc@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523033}
diff --git a/content/browser/permissions/permission_service_context.cc b/content/browser/permissions/permission_service_context.cc
index e4f237e..e115a1a 100644
--- a/content/browser/permissions/permission_service_context.cc
+++ b/content/browser/permissions/permission_service_context.cc
@@ -72,7 +72,16 @@
void PermissionServiceContext::CreateService(
blink::mojom::PermissionServiceRequest request) {
- services_.AddBinding(std::make_unique<PermissionServiceImpl>(this),
+ DCHECK(render_frame_host_);
+ services_.AddBinding(std::make_unique<PermissionServiceImpl>(
+ this, render_frame_host_->GetLastCommittedOrigin()),
+ std::move(request));
+}
+
+void PermissionServiceContext::CreateServiceForWorker(
+ blink::mojom::PermissionServiceRequest request,
+ const url::Origin& origin) {
+ services_.AddBinding(std::make_unique<PermissionServiceImpl>(this, origin),
std::move(request));
}
diff --git a/content/browser/permissions/permission_service_context.h b/content/browser/permissions/permission_service_context.h
index 0fa8254..9aaf008 100644
--- a/content/browser/permissions/permission_service_context.h
+++ b/content/browser/permissions/permission_service_context.h
@@ -33,6 +33,8 @@
~PermissionServiceContext() override;
void CreateService(blink::mojom::PermissionServiceRequest request);
+ void CreateServiceForWorker(blink::mojom::PermissionServiceRequest request,
+ const url::Origin& origin);
void CreateSubscription(PermissionType permission_type,
const url::Origin& origin,
@@ -51,6 +53,10 @@
private:
class PermissionSubscription;
+ void CreateServiceForWorkerImpl(
+ blink::mojom::PermissionServiceRequest request,
+ const url::Origin& origin);
+
// WebContentsObserver
void RenderFrameHostChanged(RenderFrameHost* old_host,
RenderFrameHost* new_host) override;
diff --git a/content/browser/permissions/permission_service_impl.cc b/content/browser/permissions/permission_service_impl.cc
index 97e3e8b..14a128a0 100644
--- a/content/browser/permissions/permission_service_impl.cc
+++ b/content/browser/permissions/permission_service_impl.cc
@@ -173,8 +173,9 @@
std::vector<PermissionStatus> results_;
};
-PermissionServiceImpl::PermissionServiceImpl(PermissionServiceContext* context)
- : context_(context), weak_factory_(this) {}
+PermissionServiceImpl::PermissionServiceImpl(PermissionServiceContext* context,
+ const url::Origin& origin)
+ : context_(context), origin_(origin), weak_factory_(this) {}
PermissionServiceImpl::~PermissionServiceImpl() {
BrowserContext* browser_context = context_->GetBrowserContext();
@@ -196,19 +197,17 @@
void PermissionServiceImpl::RequestPermission(
PermissionDescriptorPtr permission,
- const url::Origin& origin,
bool user_gesture,
PermissionStatusCallback callback) {
std::vector<PermissionDescriptorPtr> permissions;
permissions.push_back(std::move(permission));
- RequestPermissions(std::move(permissions), origin, user_gesture,
+ RequestPermissions(std::move(permissions), user_gesture,
base::BindOnce(&PermissionRequestResponseCallbackWrapper,
base::Passed(&callback)));
}
void PermissionServiceImpl::RequestPermissions(
std::vector<PermissionDescriptorPtr> permissions,
- const url::Origin& origin,
bool user_gesture,
RequestPermissionsCallback callback) {
// This condition is valid if the call is coming from a ChildThread instead of
@@ -226,7 +225,7 @@
!browser_context->GetPermissionManager()) {
std::vector<PermissionStatus> result(permissions.size());
for (size_t i = 0; i < permissions.size(); ++i)
- result[i] = GetPermissionStatus(permissions[i], origin);
+ result[i] = GetPermissionStatus(permissions[i]);
std::move(callback).Run(result);
return;
}
@@ -248,7 +247,7 @@
int pending_request_id = pending_requests_.Add(std::move(pending_request));
int id = browser_context->GetPermissionManager()->RequestPermissions(
- request_types, context_->render_frame_host(), origin.GetURL(),
+ request_types, context_->render_frame_host(), origin_.GetURL(),
user_gesture,
base::Bind(&PermissionServiceImpl::OnRequestPermissionsResponse,
weak_factory_.GetWeakPtr(), pending_request_id));
@@ -285,19 +284,16 @@
}
void PermissionServiceImpl::HasPermission(PermissionDescriptorPtr permission,
- const url::Origin& origin,
PermissionStatusCallback callback) {
- std::move(callback).Run(GetPermissionStatus(permission, origin));
+ std::move(callback).Run(GetPermissionStatus(permission));
}
void PermissionServiceImpl::RevokePermission(
PermissionDescriptorPtr permission,
- const url::Origin& origin,
PermissionStatusCallback callback) {
PermissionType permission_type =
PermissionDescriptorToPermissionType(permission);
- PermissionStatus status =
- GetPermissionStatusFromType(permission_type, origin);
+ PermissionStatus status = GetPermissionStatusFromType(permission_type);
// Resetting the permission should only be possible if the permission is
// already granted.
@@ -306,36 +302,33 @@
return;
}
- ResetPermissionStatus(permission_type, origin);
+ ResetPermissionStatus(permission_type);
- std::move(callback).Run(GetPermissionStatusFromType(permission_type, origin));
+ std::move(callback).Run(GetPermissionStatusFromType(permission_type));
}
void PermissionServiceImpl::AddPermissionObserver(
PermissionDescriptorPtr permission,
- const url::Origin& origin,
PermissionStatus last_known_status,
PermissionObserverPtr observer) {
- PermissionStatus current_status = GetPermissionStatus(permission, origin);
+ PermissionStatus current_status = GetPermissionStatus(permission);
if (current_status != last_known_status) {
observer->OnPermissionStatusChange(current_status);
last_known_status = current_status;
}
context_->CreateSubscription(PermissionDescriptorToPermissionType(permission),
- origin, std::move(observer));
+ origin_, std::move(observer));
}
PermissionStatus PermissionServiceImpl::GetPermissionStatus(
- const PermissionDescriptorPtr& permission,
- const url::Origin& origin) {
+ const PermissionDescriptorPtr& permission) {
return GetPermissionStatusFromType(
- PermissionDescriptorToPermissionType(permission), origin);
+ PermissionDescriptorToPermissionType(permission));
}
PermissionStatus PermissionServiceImpl::GetPermissionStatusFromType(
- PermissionType type,
- const url::Origin& origin) {
+ PermissionType type) {
BrowserContext* browser_context = context_->GetBrowserContext();
if (!browser_context)
return PermissionStatus::DENIED;
@@ -349,16 +342,15 @@
return PermissionStatus::DENIED;
}
- GURL requesting_origin(origin.Serialize());
- // If the embedding_origin is empty we'll use |origin| instead.
+ GURL requesting_origin(origin_.GetURL());
+ // If the embedding_origin is empty we'll use |origin_| instead.
GURL embedding_origin = context_->GetEmbeddingOrigin();
return browser_context->GetPermissionManager()->GetPermissionStatus(
type, requesting_origin,
embedding_origin.is_empty() ? requesting_origin : embedding_origin);
}
-void PermissionServiceImpl::ResetPermissionStatus(PermissionType type,
- const url::Origin& origin) {
+void PermissionServiceImpl::ResetPermissionStatus(PermissionType type) {
BrowserContext* browser_context = context_->GetBrowserContext();
if (!browser_context)
return;
@@ -366,8 +358,8 @@
if (!browser_context->GetPermissionManager())
return;
- GURL requesting_origin(origin.Serialize());
- // If the embedding_origin is empty we'll use |origin| instead.
+ GURL requesting_origin(origin_.GetURL());
+ // If the embedding_origin is empty we'll use |origin_| instead.
GURL embedding_origin = context_->GetEmbeddingOrigin();
browser_context->GetPermissionManager()->ResetPermission(
type, requesting_origin,
diff --git a/content/browser/permissions/permission_service_impl.h b/content/browser/permissions/permission_service_impl.h
index 6782648..6e0c9bc 100644
--- a/content/browser/permissions/permission_service_impl.h
+++ b/content/browser/permissions/permission_service_impl.h
@@ -28,7 +28,8 @@
class CONTENT_EXPORT PermissionServiceImpl
: public blink::mojom::PermissionService {
public:
- PermissionServiceImpl(PermissionServiceContext* context);
+ PermissionServiceImpl(PermissionServiceContext* context,
+ const url::Origin& origin);
~PermissionServiceImpl() override;
private:
@@ -42,23 +43,18 @@
// blink::mojom::PermissionService.
void HasPermission(blink::mojom::PermissionDescriptorPtr permission,
- const url::Origin& origin,
PermissionStatusCallback callback) override;
void RequestPermission(blink::mojom::PermissionDescriptorPtr permission,
- const url::Origin& origin,
bool user_gesture,
PermissionStatusCallback callback) override;
void RequestPermissions(
std::vector<blink::mojom::PermissionDescriptorPtr> permissions,
- const url::Origin& origin,
bool user_gesture,
RequestPermissionsCallback callback) override;
void RevokePermission(blink::mojom::PermissionDescriptorPtr permission,
- const url::Origin& origin,
PermissionStatusCallback callback) override;
void AddPermissionObserver(
blink::mojom::PermissionDescriptorPtr permission,
- const url::Origin& origin,
blink::mojom::PermissionStatus last_known_status,
blink::mojom::PermissionObserverPtr observer) override;
@@ -67,16 +63,15 @@
const std::vector<blink::mojom::PermissionStatus>& result);
blink::mojom::PermissionStatus GetPermissionStatus(
- const blink::mojom::PermissionDescriptorPtr& permission,
- const url::Origin& origin);
+ const blink::mojom::PermissionDescriptorPtr& permission);
blink::mojom::PermissionStatus GetPermissionStatusFromType(
- PermissionType type,
- const url::Origin& origin);
- void ResetPermissionStatus(PermissionType type, const url::Origin& origin);
+ PermissionType type);
+ void ResetPermissionStatus(PermissionType type);
RequestsMap pending_requests_;
// context_ owns |this|.
PermissionServiceContext* context_;
+ const url::Origin origin_;
base::WeakPtrFactory<PermissionServiceImpl> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(PermissionServiceImpl);
diff --git a/content/browser/permissions/permission_service_impl_unittest.cc b/content/browser/permissions/permission_service_impl_unittest.cc
index 23ecc12..79ac72a 100644
--- a/content/browser/permissions/permission_service_impl_unittest.cc
+++ b/content/browser/permissions/permission_service_impl_unittest.cc
@@ -68,7 +68,8 @@
->SetPermissionManager(std::make_unique<TestPermissionManager>());
NavigateAndCommit(origin_.GetURL());
service_context_.reset(new PermissionServiceContext(main_rfh()));
- service_impl_.reset(new PermissionServiceImpl(service_context_.get()));
+ service_impl_.reset(
+ new PermissionServiceImpl(service_context_.get(), origin_));
}
void TearDown() override {
@@ -95,7 +96,7 @@
base::Bind(&PermissionServiceImplTest::PermissionStatusCallback,
base::Unretained(this));
service_impl_->HasPermission(CreatePermissionDescriptor(permission),
- origin_, callback);
+ callback);
EXPECT_EQ(1u, last_permission_statuses_.size());
return last_permission_statuses_[0];
}
@@ -108,7 +109,7 @@
base::Callback<void(const std::vector<PermissionStatus>&)> callback =
base::Bind(&PermissionServiceImplTest::RequestPermissionsCallback,
base::Unretained(this));
- service_impl_->RequestPermissions(std::move(descriptors), origin_,
+ service_impl_->RequestPermissions(std::move(descriptors),
/*user_gesture=*/false, callback);
EXPECT_EQ(permissions.size(), last_permission_statuses_.size());
return last_permission_statuses_;
diff --git a/content/browser/renderer_interface_binders.cc b/content/browser/renderer_interface_binders.cc
index bb4e016..eecfa5e 100644
--- a/content/browser/renderer_interface_binders.cc
+++ b/content/browser/renderer_interface_binders.cc
@@ -122,7 +122,7 @@
RenderProcessHost* host, const url::Origin& origin) {
static_cast<RenderProcessHostImpl*>(host)
->permission_service_context()
- .CreateService(std::move(request));
+ .CreateServiceForWorker(std::move(request), origin);
}));
parameterized_binder_registry_.AddInterface(base::BindRepeating(
[](blink::mojom::LockManagerRequest request, RenderProcessHost* host,
diff --git a/content/renderer/media/media_permission_dispatcher.cc b/content/renderer/media/media_permission_dispatcher.cc
index eeb8742b..91af4d0 100644
--- a/content/renderer/media/media_permission_dispatcher.cc
+++ b/content/renderer/media/media_permission_dispatcher.cc
@@ -68,6 +68,7 @@
OnConnectionError();
}
+// TODO(crbug.com/793684): |security_origin| is no longer used; remove it.
void MediaPermissionDispatcher::HasPermission(
Type type,
const GURL& security_origin,
@@ -88,11 +89,11 @@
GetPermissionService()->HasPermission(
MediaPermissionTypeToPermissionDescriptor(type),
- url::Origin::Create(security_origin),
base::BindOnce(&MediaPermissionDispatcher::OnPermissionStatus, weak_ptr_,
request_id));
}
+// TODO(crbug.com/793684): |security_origin| is no longer used; remove it.
void MediaPermissionDispatcher::RequestPermission(
Type type,
const GURL& security_origin,
@@ -113,7 +114,6 @@
GetPermissionService()->RequestPermission(
MediaPermissionTypeToPermissionDescriptor(type),
- url::Origin::Create(security_origin),
blink::WebUserGestureIndicator::IsProcessingUserGesture(),
base::BindOnce(&MediaPermissionDispatcher::OnPermissionStatus, weak_ptr_,
request_id));
diff --git a/third_party/WebKit/Source/modules/accessibility/AXObjectCacheImpl.cpp b/third_party/WebKit/Source/modules/accessibility/AXObjectCacheImpl.cpp
index 73ff2f2..215b275 100644
--- a/third_party/WebKit/Source/modules/accessibility/AXObjectCacheImpl.cpp
+++ b/third_party/WebKit/Source/modules/accessibility/AXObjectCacheImpl.cpp
@@ -1247,7 +1247,6 @@
permission_service_->AddPermissionObserver(
CreatePermissionDescriptor(
mojom::blink::PermissionName::ACCESSIBILITY_EVENTS),
- document_->GetExecutionContext()->GetSecurityOrigin(),
accessibility_event_permission_, std::move(observer));
}
@@ -1270,7 +1269,6 @@
permission_service_->RequestPermission(
CreatePermissionDescriptor(
mojom::blink::PermissionName::ACCESSIBILITY_EVENTS),
- document_->GetExecutionContext()->GetSecurityOrigin(),
Frame::HasTransientUserActivation(document_->GetFrame()),
WTF::Bind(&AXObjectCacheImpl::OnPermissionStatusChange,
WrapPersistent(this)));
diff --git a/third_party/WebKit/Source/modules/notifications/NotificationManager.cpp b/third_party/WebKit/Source/modules/notifications/NotificationManager.cpp
index 7bc802f..962d417 100644
--- a/third_party/WebKit/Source/modules/notifications/NotificationManager.cpp
+++ b/third_party/WebKit/Source/modules/notifications/NotificationManager.cpp
@@ -80,7 +80,6 @@
Document* doc = ToDocumentOrNull(context);
permission_service_->RequestPermission(
CreatePermissionDescriptor(mojom::blink::PermissionName::NOTIFICATIONS),
- context->GetSecurityOrigin(),
Frame::HasTransientUserActivation(doc ? doc->GetFrame() : nullptr),
WTF::Bind(&NotificationManager::OnPermissionRequestComplete,
WrapPersistent(this), WrapPersistent(resolver),
diff --git a/third_party/WebKit/Source/modules/permissions/PermissionStatus.cpp b/third_party/WebKit/Source/modules/permissions/PermissionStatus.cpp
index de7fb2a..00243d58 100644
--- a/third_party/WebKit/Source/modules/permissions/PermissionStatus.cpp
+++ b/third_party/WebKit/Source/modules/permissions/PermissionStatus.cpp
@@ -93,9 +93,8 @@
mojom::blink::PermissionServicePtr service;
ConnectToPermissionService(GetExecutionContext(),
mojo::MakeRequest(&service));
- service->AddPermissionObserver(descriptor_->Clone(),
- GetExecutionContext()->GetSecurityOrigin(),
- status_, std::move(observer));
+ service->AddPermissionObserver(descriptor_->Clone(), status_,
+ std::move(observer));
}
void PermissionStatus::StopListening() {
diff --git a/third_party/WebKit/Source/modules/permissions/Permissions.cpp b/third_party/WebKit/Source/modules/permissions/Permissions.cpp
index 2b1c534..ceb0e41a 100644
--- a/third_party/WebKit/Source/modules/permissions/Permissions.cpp
+++ b/third_party/WebKit/Source/modules/permissions/Permissions.cpp
@@ -171,7 +171,6 @@
PermissionDescriptorPtr descriptor_copy = descriptor->Clone();
GetService(ExecutionContext::From(script_state))
.HasPermission(std::move(descriptor),
- ExecutionContext::From(script_state)->GetSecurityOrigin(),
WTF::Bind(&Permissions::TaskComplete, WrapPersistent(this),
WrapPersistent(resolver),
WTF::Passed(std::move(descriptor_copy))));
@@ -198,7 +197,7 @@
Frame* frame = doc ? doc->GetFrame() : nullptr;
GetService(ExecutionContext::From(script_state))
.RequestPermission(
- std::move(descriptor), context->GetSecurityOrigin(),
+ std::move(descriptor),
Frame::HasTransientUserActivation(frame,
true /* checkIfMainThread */),
WTF::Bind(&Permissions::TaskComplete, WrapPersistent(this),
@@ -224,7 +223,6 @@
GetService(ExecutionContext::From(script_state))
.RevokePermission(
std::move(descriptor),
- ExecutionContext::From(script_state)->GetSecurityOrigin(),
WTF::Bind(&Permissions::TaskComplete, WrapPersistent(this),
WrapPersistent(resolver),
WTF::Passed(std::move(descriptor_copy))));
@@ -277,7 +275,7 @@
Frame* frame = doc ? doc->GetFrame() : nullptr;
GetService(ExecutionContext::From(script_state))
.RequestPermissions(
- std::move(internal_permissions), context->GetSecurityOrigin(),
+ std::move(internal_permissions),
Frame::HasTransientUserActivation(frame,
true /* checkIfMainThread */),
WTF::Bind(&Permissions::BatchTaskComplete, WrapPersistent(this),
diff --git a/third_party/WebKit/Source/modules/quota/StorageManager.cpp b/third_party/WebKit/Source/modules/quota/StorageManager.cpp
index 885a28c9..d663ab1 100644
--- a/third_party/WebKit/Source/modules/quota/StorageManager.cpp
+++ b/third_party/WebKit/Source/modules/quota/StorageManager.cpp
@@ -82,7 +82,6 @@
GetPermissionService(ExecutionContext::From(script_state))
.RequestPermission(
CreatePermissionDescriptor(PermissionName::DURABLE_STORAGE),
- ExecutionContext::From(script_state)->GetSecurityOrigin(),
Frame::HasTransientUserActivation(doc ? doc->GetFrame() : nullptr),
WTF::Bind(&StorageManager::PermissionRequestComplete,
WrapPersistent(this), WrapPersistent(resolver)));
@@ -106,7 +105,6 @@
GetPermissionService(ExecutionContext::From(script_state))
.HasPermission(
CreatePermissionDescriptor(PermissionName::DURABLE_STORAGE),
- ExecutionContext::From(script_state)->GetSecurityOrigin(),
WTF::Bind(&StorageManager::PermissionRequestComplete,
WrapPersistent(this), WrapPersistent(resolver)));
return promise;
diff --git a/third_party/WebKit/Source/modules/webmidi/MIDIAccessInitializer.cpp b/third_party/WebKit/Source/modules/webmidi/MIDIAccessInitializer.cpp
index 58e9df7..d401dce 100644
--- a/third_party/WebKit/Source/modules/webmidi/MIDIAccessInitializer.cpp
+++ b/third_party/WebKit/Source/modules/webmidi/MIDIAccessInitializer.cpp
@@ -44,7 +44,6 @@
Document* doc = ToDocumentOrNull(GetExecutionContext());
permission_service_->RequestPermission(
CreateMidiPermissionDescriptor(options_.hasSysex() && options_.sysex()),
- GetExecutionContext()->GetSecurityOrigin(),
Frame::HasTransientUserActivation(doc ? doc->GetFrame() : nullptr),
WTF::Bind(&MIDIAccessInitializer::OnPermissionsUpdated,
WrapPersistent(this)));
diff --git a/third_party/WebKit/public/platform/modules/permissions/permission.mojom b/third_party/WebKit/public/platform/modules/permissions/permission.mojom
index bf271f3..88b2758 100644
--- a/third_party/WebKit/public/platform/modules/permissions/permission.mojom
+++ b/third_party/WebKit/public/platform/modules/permissions/permission.mojom
@@ -5,7 +5,6 @@
module blink.mojom;
import "third_party/WebKit/public/platform/modules/permissions/permission_status.mojom";
-import "url/mojo/origin.mojom";
enum PermissionName {
GEOLOCATION,
@@ -52,20 +51,16 @@
// methods to check, request, and revoke permissions. It also allows a client to
// start listening to permission changes.
interface PermissionService {
- HasPermission(PermissionDescriptor permission, url.mojom.Origin origin)
- => (PermissionStatus status);
- RequestPermission(PermissionDescriptor permission, url.mojom.Origin origin,
- bool user_gesture)
- => (PermissionStatus status);
- RequestPermissions(array<PermissionDescriptor> permission, url.mojom.Origin origin,
- bool user_gesture)
- => (array<PermissionStatus> statuses);
- RevokePermission(PermissionDescriptor permission, url.mojom.Origin origin)
- => (PermissionStatus status);
- // Subscribes |observer| to updates about changes to |origin|'s access to
- // |permission|. Closing the pipe will cancel the subscription.
+ HasPermission(PermissionDescriptor permission) => (PermissionStatus status);
+ RequestPermission(PermissionDescriptor permission, bool user_gesture)
+ => (PermissionStatus status);
+ RequestPermissions(array<PermissionDescriptor> permission, bool user_gesture)
+ => (array<PermissionStatus> statuses);
+ RevokePermission(PermissionDescriptor permission)
+ => (PermissionStatus status);
+ // Subscribes |observer| to updates about changes to the current origin's
+ // access to |permission|. Closing the pipe will cancel the subscription.
AddPermissionObserver(PermissionDescriptor permission,
- url.mojom.Origin origin,
PermissionStatus last_known_status,
PermissionObserver observer);
};