Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ANDROID_WEBVIEW_NATIVE_PERMISSION_PERMISSION_REQUEST_HANDLER_H | 5 #ifndef ANDROID_WEBVIEW_NATIVE_PERMISSION_PERMISSION_REQUEST_HANDLER_H |
| 6 #define ANDROID_WEBVIEW_NATIVE_PERMISSION_PERMISSION_REQUEST_HANDLER_H | 6 #define ANDROID_WEBVIEW_NATIVE_PERMISSION_PERMISSION_REQUEST_HANDLER_H |
| 7 | 7 |
| 8 #include <map> | |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 12 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 13 | 14 |
| 14 namespace android_webview { | 15 namespace android_webview { |
| 15 | 16 |
| 16 class AwPermissionRequest; | 17 class AwPermissionRequest; |
| 17 class AwPermissionRequestDelegate; | 18 class AwPermissionRequestDelegate; |
| 18 class PermissionRequestHandlerClient; | 19 class PermissionRequestHandlerClient; |
| 19 | 20 |
| 20 // This class is used to send the permission requests, or cancel ongoing | 21 // This class is used to send the permission requests, or cancel ongoing |
| 21 // requests. | 22 // requests. |
| 22 // It is owned by AwContents and has 1x1 mapping to AwContents. All methods | 23 // It is owned by AwContents and has 1x1 mapping to AwContents. All methods |
| 23 // are running on UI thread. | 24 // are running on UI thread. |
| 24 class PermissionRequestHandler { | 25 class PermissionRequestHandler { |
| 25 public: | 26 public: |
| 26 PermissionRequestHandler(PermissionRequestHandlerClient* aw_contents); | 27 PermissionRequestHandler(PermissionRequestHandlerClient* aw_contents); |
| 27 virtual ~PermissionRequestHandler(); | 28 virtual ~PermissionRequestHandler(); |
| 28 | 29 |
| 29 // Send the given |request| to PermissionRequestHandlerClient. | 30 // Send the given |request| to PermissionRequestHandlerClient. |
| 30 void SendRequest(scoped_ptr<AwPermissionRequestDelegate> request); | 31 void SendRequest(scoped_ptr<AwPermissionRequestDelegate> request); |
| 31 | 32 |
| 32 // Cancel the ongoing request initiated by |origin| for accessing |resources|. | 33 // Cancel the ongoing request initiated by |origin| for accessing |resources|. |
| 33 void CancelRequest(const GURL& origin, int64 resources); | 34 void CancelRequest(const GURL& origin, int64 resources); |
| 34 | 35 |
| 36 // Allow |origin| to access the |resources|. | |
| 37 void PreauthorizePermission(const GURL& origin, int64 resources); | |
| 38 | |
| 35 private: | 39 private: |
| 36 friend class TestPermissionRequestHandler; | 40 friend class TestPermissionRequestHandler; |
| 37 | 41 |
| 38 typedef std::vector<base::WeakPtr<AwPermissionRequest> >::iterator | 42 typedef std::vector<base::WeakPtr<AwPermissionRequest> >::iterator |
| 39 RequestIterator; | 43 RequestIterator; |
| 40 | 44 |
| 41 // Return the request initiated by |origin| for accessing |resources|. | 45 // Return the request initiated by |origin| for accessing |resources|. |
| 42 RequestIterator FindRequest(const GURL& origin, int64 resources); | 46 RequestIterator FindRequest(const GURL& origin, int64 resources); |
| 43 | 47 |
| 44 // Cancel the given request. | 48 // Cancel the given request. |
| 45 void CancelRequest(RequestIterator i); | 49 void CancelRequest(RequestIterator i); |
| 46 | 50 |
| 47 // Remove the invalid requests from requests_. | 51 // Remove the invalid requests from requests_. |
| 48 void PruneRequests(); | 52 void PruneRequests(); |
| 49 | 53 |
| 54 // Return true if |origin| were preauthorized to access |resources|. | |
| 55 bool Preauthorized(const GURL& origin, int64 resources); | |
|
mkosiba (inactive)
2014/05/07 17:25:50
nit: IsPreauthorized?
michaelbai
2014/05/07 19:22:25
I prefer the short name.
On 2014/05/07 17:25:50,
| |
| 56 | |
| 50 PermissionRequestHandlerClient* client_; | 57 PermissionRequestHandlerClient* client_; |
| 51 | 58 |
| 52 // A list of ongoing requests. | 59 // A list of ongoing requests. |
| 53 std::vector<base::WeakPtr<AwPermissionRequest> > requests_; | 60 std::vector<base::WeakPtr<AwPermissionRequest> > requests_; |
| 54 | 61 |
| 62 std::map<std::string, int64> preauthorized_permission_; | |
| 63 | |
| 55 DISALLOW_COPY_AND_ASSIGN(PermissionRequestHandler); | 64 DISALLOW_COPY_AND_ASSIGN(PermissionRequestHandler); |
| 56 }; | 65 }; |
| 57 | 66 |
| 58 } // namespace android_webivew | 67 } // namespace android_webivew |
| 59 | 68 |
| 60 #endif // ANDROID_WEBVIEW_NATIVE_PERMISSION_PERMISSION_REQUEST_HANDLER_H | 69 #endif // ANDROID_WEBVIEW_NATIVE_PERMISSION_PERMISSION_REQUEST_HANDLER_H |
| OLD | NEW |