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 #include "android_webview/native/permission/permission_request_handler.h" | 5 #include "android_webview/browser/permission/permission_request_handler.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "android_webview/native/permission/aw_permission_request.h" | 9 #include "android_webview/browser/permission/aw_permission_request.h" |
10 #include "android_webview/native/permission/aw_permission_request_delegate.h" | 10 #include "android_webview/browser/permission/aw_permission_request_delegate.h" |
11 #include "android_webview/native/permission/permission_request_handler_client.h" | 11 #include "android_webview/browser/permission/permission_request_handler_client.h
" |
12 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "content/public/browser/navigation_details.h" | 14 #include "content/public/browser/navigation_details.h" |
15 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 | 17 |
18 using base::android::ScopedJavaLocalRef; | 18 using base::android::ScopedJavaLocalRef; |
19 | 19 |
20 namespace android_webview { | 20 namespace android_webview { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 int GetLastCommittedEntryID(content::WebContents* web_contents) { | 24 int GetLastCommittedEntryID(content::WebContents* web_contents) { |
25 if (!web_contents) return 0; | 25 if (!web_contents) |
| 26 return 0; |
26 | 27 |
27 content::NavigationEntry* entry = | 28 content::NavigationEntry* entry = |
28 web_contents->GetController().GetLastCommittedEntry(); | 29 web_contents->GetController().GetLastCommittedEntry(); |
29 return entry ? entry->GetUniqueID() : 0; | 30 return entry ? entry->GetUniqueID() : 0; |
30 } | 31 } |
31 | 32 |
32 } // namespace | 33 } // namespace |
33 | 34 |
34 PermissionRequestHandler::PermissionRequestHandler( | 35 PermissionRequestHandler::PermissionRequestHandler( |
35 PermissionRequestHandlerClient* client, | 36 PermissionRequestHandlerClient* client, |
36 content::WebContents* web_contents) | 37 content::WebContents* web_contents) |
37 : content::WebContentsObserver(web_contents), | 38 : content::WebContentsObserver(web_contents), |
38 client_(client), | 39 client_(client), |
39 contents_unique_id_(GetLastCommittedEntryID(web_contents)) { | 40 contents_unique_id_(GetLastCommittedEntryID(web_contents)) {} |
40 } | |
41 | 41 |
42 PermissionRequestHandler::~PermissionRequestHandler() { | 42 PermissionRequestHandler::~PermissionRequestHandler() { |
43 CancelAllRequests(); | 43 CancelAllRequests(); |
44 } | 44 } |
45 | 45 |
46 void PermissionRequestHandler::SendRequest( | 46 void PermissionRequestHandler::SendRequest( |
47 std::unique_ptr<AwPermissionRequestDelegate> request) { | 47 std::unique_ptr<AwPermissionRequestDelegate> request) { |
48 if (Preauthorized(request->GetOrigin(), request->GetResources())) { | 48 if (Preauthorized(request->GetOrigin(), request->GetResources())) { |
49 request->NotifyRequestResult(true); | 49 request->NotifyRequestResult(true); |
50 return; | 50 return; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 ++i; | 129 ++i; |
130 } | 130 } |
131 } | 131 } |
132 | 132 |
133 bool PermissionRequestHandler::Preauthorized(const GURL& origin, | 133 bool PermissionRequestHandler::Preauthorized(const GURL& origin, |
134 int64_t resources) { | 134 int64_t resources) { |
135 std::map<std::string, int64_t>::iterator i = | 135 std::map<std::string, int64_t>::iterator i = |
136 preauthorized_permission_.find(origin.GetOrigin().spec()); | 136 preauthorized_permission_.find(origin.GetOrigin().spec()); |
137 | 137 |
138 return i != preauthorized_permission_.end() && | 138 return i != preauthorized_permission_.end() && |
139 (resources & i->second) == resources; | 139 (resources & i->second) == resources; |
140 } | 140 } |
141 | 141 |
142 } // namespace android_webivew | 142 } // namespace android_webivew |
OLD | NEW |