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 <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "content/public/browser/web_contents_observer.h" |
13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
14 | 15 |
15 namespace android_webview { | 16 namespace android_webview { |
16 | 17 |
17 class AwPermissionRequest; | 18 class AwPermissionRequest; |
18 class AwPermissionRequestDelegate; | 19 class AwPermissionRequestDelegate; |
19 class PermissionRequestHandlerClient; | 20 class PermissionRequestHandlerClient; |
20 | 21 |
21 // This class is used to send the permission requests, or cancel ongoing | 22 // This class is used to send the permission requests, or cancel ongoing |
22 // requests. | 23 // requests. |
23 // It is owned by AwContents and has 1x1 mapping to AwContents. All methods | 24 // It is owned by AwContents and has 1x1 mapping to AwContents. All methods |
24 // are running on UI thread. | 25 // are running on UI thread. |
25 class PermissionRequestHandler { | 26 class PermissionRequestHandler : public content::WebContentsObserver { |
26 public: | 27 public: |
27 PermissionRequestHandler(PermissionRequestHandlerClient* aw_contents); | 28 PermissionRequestHandler(PermissionRequestHandlerClient* client, |
| 29 content::WebContents* aw_contents); |
28 virtual ~PermissionRequestHandler(); | 30 virtual ~PermissionRequestHandler(); |
29 | 31 |
30 // Send the given |request| to PermissionRequestHandlerClient. | 32 // Send the given |request| to PermissionRequestHandlerClient. |
31 void SendRequest(scoped_ptr<AwPermissionRequestDelegate> request); | 33 void SendRequest(scoped_ptr<AwPermissionRequestDelegate> request); |
32 | 34 |
33 // Cancel the ongoing request initiated by |origin| for accessing |resources|. | 35 // Cancel the ongoing request initiated by |origin| for accessing |resources|. |
34 void CancelRequest(const GURL& origin, int64 resources); | 36 void CancelRequest(const GURL& origin, int64 resources); |
35 | 37 |
36 // Allow |origin| to access the |resources|. | 38 // Allow |origin| to access the |resources|. |
37 void PreauthorizePermission(const GURL& origin, int64 resources); | 39 void PreauthorizePermission(const GURL& origin, int64 resources); |
38 | 40 |
| 41 // WebContentsObserver |
| 42 virtual void NavigationEntryCommitted( |
| 43 const content::LoadCommittedDetails& load_details) OVERRIDE; |
| 44 |
39 private: | 45 private: |
40 friend class TestPermissionRequestHandler; | 46 friend class TestPermissionRequestHandler; |
41 | 47 |
42 typedef std::vector<base::WeakPtr<AwPermissionRequest> >::iterator | 48 typedef std::vector<base::WeakPtr<AwPermissionRequest> >::iterator |
43 RequestIterator; | 49 RequestIterator; |
44 | 50 |
45 // Return the request initiated by |origin| for accessing |resources|. | 51 // Return the request initiated by |origin| for accessing |resources|. |
46 RequestIterator FindRequest(const GURL& origin, int64 resources); | 52 RequestIterator FindRequest(const GURL& origin, int64 resources); |
47 | 53 |
48 // Cancel the given request. | 54 // Cancel the given request. |
49 void CancelRequest(RequestIterator i); | 55 void CancelRequest(RequestIterator i); |
50 | 56 |
| 57 void CancelAllRequests(); |
| 58 |
51 // Remove the invalid requests from requests_. | 59 // Remove the invalid requests from requests_. |
52 void PruneRequests(); | 60 void PruneRequests(); |
53 | 61 |
54 // Return true if |origin| were preauthorized to access |resources|. | 62 // Return true if |origin| were preauthorized to access |resources|. |
55 bool Preauthorized(const GURL& origin, int64 resources); | 63 bool Preauthorized(const GURL& origin, int64 resources); |
56 | 64 |
57 PermissionRequestHandlerClient* client_; | 65 PermissionRequestHandlerClient* client_; |
58 | 66 |
59 // A list of ongoing requests. | 67 // A list of ongoing requests. |
60 std::vector<base::WeakPtr<AwPermissionRequest> > requests_; | 68 std::vector<base::WeakPtr<AwPermissionRequest> > requests_; |
61 | 69 |
62 std::map<std::string, int64> preauthorized_permission_; | 70 std::map<std::string, int64> preauthorized_permission_; |
63 | 71 |
| 72 // The unique id of the active NavigationEntry of the WebContents that we were |
| 73 // opened for. Used to help expire on requests. |
| 74 int contents_unique_id_; |
| 75 |
64 DISALLOW_COPY_AND_ASSIGN(PermissionRequestHandler); | 76 DISALLOW_COPY_AND_ASSIGN(PermissionRequestHandler); |
65 }; | 77 }; |
66 | 78 |
67 } // namespace android_webivew | 79 } // namespace android_webivew |
68 | 80 |
69 #endif // ANDROID_WEBVIEW_NATIVE_PERMISSION_PERMISSION_REQUEST_HANDLER_H | 81 #endif // ANDROID_WEBVIEW_NATIVE_PERMISSION_PERMISSION_REQUEST_HANDLER_H |
OLD | NEW |