Roll src/third_party/WebKit 46ff567:25f83be (svn 200502:200512)
[chromium-blink-merge.git] / android_webview / native / permission / permission_request_handler.h
blob37b0b714351c4546ace686363577ce2adfc1efd2
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
3 // found in the LICENSE file.
5 #ifndef ANDROID_WEBVIEW_NATIVE_PERMISSION_PERMISSION_REQUEST_HANDLER_H
6 #define ANDROID_WEBVIEW_NATIVE_PERMISSION_PERMISSION_REQUEST_HANDLER_H
8 #include <map>
9 #include <vector>
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "url/gurl.h"
16 namespace android_webview {
18 class AwPermissionRequest;
19 class AwPermissionRequestDelegate;
20 class PermissionRequestHandlerClient;
22 // This class is used to send the permission requests, or cancel ongoing
23 // requests.
24 // It is owned by AwContents and has 1x1 mapping to AwContents. All methods
25 // are running on UI thread.
26 class PermissionRequestHandler : public content::WebContentsObserver {
27 public:
28 PermissionRequestHandler(PermissionRequestHandlerClient* client,
29 content::WebContents* aw_contents);
30 ~PermissionRequestHandler() override;
32 // Send the given |request| to PermissionRequestHandlerClient.
33 void SendRequest(scoped_ptr<AwPermissionRequestDelegate> request);
35 // Cancel the ongoing request initiated by |origin| for accessing |resources|.
36 void CancelRequest(const GURL& origin, int64 resources);
38 // Allow |origin| to access the |resources|.
39 void PreauthorizePermission(const GURL& origin, int64 resources);
41 // WebContentsObserver
42 void NavigationEntryCommitted(
43 const content::LoadCommittedDetails& load_details) override;
45 private:
46 friend class TestPermissionRequestHandler;
48 typedef std::vector<base::WeakPtr<AwPermissionRequest> >::iterator
49 RequestIterator;
51 // Return the request initiated by |origin| for accessing |resources|.
52 RequestIterator FindRequest(const GURL& origin, int64 resources);
54 // Cancel the given request.
55 void CancelRequestInternal(RequestIterator i);
57 void CancelAllRequests();
59 // Remove the invalid requests from requests_.
60 void PruneRequests();
62 // Return true if |origin| were preauthorized to access |resources|.
63 bool Preauthorized(const GURL& origin, int64 resources);
65 PermissionRequestHandlerClient* client_;
67 // A list of ongoing requests.
68 std::vector<base::WeakPtr<AwPermissionRequest> > requests_;
70 std::map<std::string, int64> preauthorized_permission_;
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_;
76 DISALLOW_COPY_AND_ASSIGN(PermissionRequestHandler);
79 } // namespace android_webivew
81 #endif // ANDROID_WEBVIEW_NATIVE_PERMISSION_PERMISSION_REQUEST_HANDLER_H