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

Unified Diff: android_webview/native/permission/permission_request_handler.cc

Issue 274443002: Implement PreauthorizePermission (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 months 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: android_webview/native/permission/permission_request_handler.cc
diff --git a/android_webview/native/permission/permission_request_handler.cc b/android_webview/native/permission/permission_request_handler.cc
index 08b7431b4934dc0664c59c0d71fb98703f9da635..da9b75bb09998ad66b3d9733d0f1bd192393c5de 100644
--- a/android_webview/native/permission/permission_request_handler.cc
+++ b/android_webview/native/permission/permission_request_handler.cc
@@ -26,6 +26,11 @@ PermissionRequestHandler::~PermissionRequestHandler() {
void PermissionRequestHandler::SendRequest(
scoped_ptr<AwPermissionRequestDelegate> request) {
+ if (Preauthorized(request->GetOrigin(), request->GetResources())) {
+ request->NotifyRequestResult(true);
+ return;
+ }
michaelbai 2014/05/06 23:09:50 Note, the all resources will passed to permission
+
AwPermissionRequest* aw_request = new AwPermissionRequest(request.Pass());
requests_.push_back(
base::WeakPtr<AwPermissionRequest>(aw_request->GetWeakPtr()));
@@ -45,6 +50,18 @@ void PermissionRequestHandler::CancelRequest(const GURL& origin,
}
}
+void PermissionRequestHandler::PreauthorizePermission(const GURL& origin,
+ int64 resources) {
+ if (!resources)
+ return;
+
+ std::string key = origin.GetOrigin().spec();
+ if (key.empty())
mkosiba (inactive) 2014/05/07 17:25:50 ok, so if we get here the user managed to create a
michaelbai 2014/05/07 19:22:25 Done.
+ return;
+
+ preauthorized_permission_[key] |= resources;
benm (inactive) 2014/05/07 17:01:21 I think you need to initialise this mapped value i
michaelbai 2014/05/07 19:22:25 In this case, the default value is 0, we can use i
+}
+
PermissionRequestHandler::RequestIterator
PermissionRequestHandler::FindRequest(const GURL& origin,
int64 resources) {
@@ -77,4 +94,11 @@ void PermissionRequestHandler::PruneRequests() {
}
}
+bool PermissionRequestHandler::Preauthorized(const GURL& origin,
+ int64 resources) {
+ std::map<std::string, int64>::iterator i =
+ preauthorized_permission_.find(origin.GetOrigin().spec());
mkosiba (inactive) 2014/05/07 17:25:50 I'm paranoid so I'd suggest doing the same thing y
michaelbai 2014/05/07 19:22:25 I would like to make you happy, but I need to chec
+ return (resources & i->second) == resources;
mkosiba (inactive) 2014/05/07 17:25:50 what if we don't find the origin in the map? you'l
michaelbai 2014/05/07 19:22:25 Oops, I were checking it there, it was removed wit
+}
+
} // namespace android_webivew

Powered by Google App Engine
This is Rietveld 408576698