Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Unified Diff: content/browser/permissions/permission_service_impl.cc

Issue 722153003: Implement basic mojo Permission service and use it for Geolocation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/permissions/permission_service_impl.cc
diff --git a/content/browser/permissions/permission_service_impl.cc b/content/browser/permissions/permission_service_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..260d823e77531eedf5f615871b70b1e8a94241a3
--- /dev/null
+++ b/content/browser/permissions/permission_service_impl.cc
@@ -0,0 +1,137 @@
+// Copyright 2014 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 "content/browser/permissions/permission_service_impl.h"
+
+#include "content/browser/geolocation/geolocation_provider_impl.h"
+#include "content/public/browser/content_browser_client.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/render_process_host.h"
+
+namespace content {
+
+namespace {
+
+PermissionType PermissionNameToPermissionType(PermissionName name) {
+ switch(name) {
+ case PERMISSION_NAME_GEOLOCATION:
+ return PERMISSION_GEOLOCATION;
+ }
+
+ NOTREACHED();
+ return PERMISSION_NUM;
+}
+
+} // anonymous namespace
+
+PermissionServiceImpl::PendingRequest::PendingRequest(PermissionType permission,
+ const GURL& origin)
+ : permission(permission),
+ origin(origin) {
+}
+
+void PermissionServiceImpl::Create(
+ scoped_ptr<PermissionServiceContext> context,
+ mojo::InterfaceRequest<PermissionService> request) {
+ mojo::BindToRequest(new PermissionServiceImpl(context.Pass()), &request);
+}
+
+PermissionServiceImpl::PermissionServiceImpl(
+ scoped_ptr<PermissionServiceContext> context)
+ : context_(context.Pass())
+ , weak_factory_(this) {
nasko 2014/11/14 00:42:50 Another instance of the comma on new line :).
mlamouri (slow - plz ping) 2014/11/14 11:37:11 Damn coding style :)
+ context_->set_service(this);
+}
+
+PermissionServiceImpl::~PermissionServiceImpl() {
+}
+
+void PermissionServiceImpl::RequestPermission(
+ PermissionPtr permission,
+ const mojo::String& origin,
+ const mojo::Callback<void(PermissionStatus)>& callback) {
+ if (!context_->render_frame_host()) {
+ // There is no way to show a UI so the call will simply return the current
+ // permission.
+ HasPermission(permission.Clone(), origin, callback);
+ return;
+ }
+
+ PermissionType permission_type =
+ PermissionNameToPermissionType(permission->name);
+ int request_id = pending_requests_.Add(
+ new PendingRequest(permission_type, GURL(origin)));
+
+ GetContentClient()->browser()->RequestPermission(
+ permission_type,
+ context_->web_contents(),
+ request_id,
+ GURL(origin),
+ true, // TODO(mlamouri): should be removed, see http://crbug.com/423770
+ base::Bind(&PermissionServiceImpl::OnRequestPermissionResponse,
+ weak_factory_.GetWeakPtr(),
+ callback,
+ request_id));
+}
+
+void PermissionServiceImpl::OnRequestPermissionResponse(
+ const mojo::Callback<void(PermissionStatus)>& callback,
+ int request_id,
+ bool allowed) {
+ // TODO(mlamouri): we might want a generic way to handle those things.
+ if (allowed &&
+ pending_requests_.Lookup(request_id)->permission ==
+ PERMISSION_GEOLOCATION) {
+ GeolocationProviderImpl::GetInstance()->UserDidOptIntoLocationServices();
+ }
+
+ pending_requests_.Remove(request_id);
+
+ // TODO(mlamouri): for now, we only get a boolean back, but we would ideally
+ // need a ContentSetting, see http://crbug.com/432978
+ callback.Run(allowed ? PERMISSION_STATUS_GRANTED : PERMISSION_STATUS_ASK);
+}
+
+void PermissionServiceImpl::CancelPendingRequests() {
+ DCHECK(context_->web_contents());
+
+ for (RequestsMap::Iterator<PendingRequest> it(&pending_requests_);
+ !it.IsAtEnd(); it.Advance()) {
+ GetContentClient()->browser()->CancelPermissionRequest(
+ it.GetCurrentValue()->permission,
+ context_->web_contents(),
+ it.GetCurrentKey(),
+ it.GetCurrentValue()->origin);
+ }
+
+ pending_requests_.Clear();
+}
+
+void PermissionServiceImpl::RevokePermission(
qsr 2014/11/14 09:20:26 I wouldn't add those methods in the mojom until yo
mlamouri (slow - plz ping) 2014/11/14 11:37:11 Done. Except for HasPermission() because I use tha
qsr 2014/11/14 11:49:27 If you use it, shouldn't you implement it? With th
+ PermissionPtr permission,
+ const mojo::String& origin,
+ const mojo::Callback<void(PermissionStatus)>& callback) {
+ NOTIMPLEMENTED();
+}
+
+void PermissionServiceImpl::HasPermission(
+ PermissionPtr permission,
+ const mojo::String& origin,
+ const mojo::Callback<void(PermissionStatus)>& callback) {
+ NOTIMPLEMENTED();
+}
+
+void PermissionServiceImpl::StartObserving(
+ PermissionPtr permission,
+ const mojo::String& origin) {
+ NOTIMPLEMENTED();
+}
+
+void PermissionServiceImpl::StopObserving(
+ PermissionPtr permission,
+ const mojo::String& origin) {
+ NOTIMPLEMENTED();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698