| 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 "extensions/browser/guest_view/web_view/web_view_permission_helper.h" | 5 #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/location.h" |
| 9 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "components/guest_view/browser/guest_view_event.h" | 13 #include "components/guest_view/browser/guest_view_event.h" |
| 11 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 12 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
| 13 #include "content/public/browser/user_metrics.h" | 16 #include "content/public/browser/user_metrics.h" |
| 14 #include "extensions/browser/api/extensions_api_client.h" | 17 #include "extensions/browser/api/extensions_api_client.h" |
| 15 #include "extensions/browser/guest_view/web_view/web_view_constants.h" | 18 #include "extensions/browser/guest_view/web_view/web_view_constants.h" |
| 16 #include "extensions/browser/guest_view/web_view/web_view_guest.h" | 19 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
| 17 #include "extensions/browser/guest_view/web_view/web_view_permission_helper_dele
gate.h" | 20 #include "extensions/browser/guest_view/web_view/web_view_permission_helper_dele
gate.h" |
| 18 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" | 21 #include "extensions/browser/guest_view/web_view/web_view_permission_types.h" |
| 19 | 22 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 const base::DictionaryValue& request_info, | 313 const base::DictionaryValue& request_info, |
| 311 const PermissionResponseCallback& callback, | 314 const PermissionResponseCallback& callback, |
| 312 bool allowed_by_default) { | 315 bool allowed_by_default) { |
| 313 // If there are too many pending permission requests then reject this request. | 316 // If there are too many pending permission requests then reject this request. |
| 314 if (pending_permission_requests_.size() >= | 317 if (pending_permission_requests_.size() >= |
| 315 webview::kMaxOutstandingPermissionRequests) { | 318 webview::kMaxOutstandingPermissionRequests) { |
| 316 // Let the stack unwind before we deny the permission request so that | 319 // Let the stack unwind before we deny the permission request so that |
| 317 // objects held by the permission request are not destroyed immediately | 320 // objects held by the permission request are not destroyed immediately |
| 318 // after creation. This is to allow those same objects to be accessed again | 321 // after creation. This is to allow those same objects to be accessed again |
| 319 // in the same scope without fear of use after freeing. | 322 // in the same scope without fear of use after freeing. |
| 320 base::MessageLoop::current()->PostTask( | 323 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 321 FROM_HERE, | 324 FROM_HERE, |
| 322 base::Bind(&PermissionResponseCallback::Run, | 325 base::Bind(&PermissionResponseCallback::Run, |
| 323 base::Owned(new PermissionResponseCallback(callback)), | 326 base::Owned(new PermissionResponseCallback(callback)), |
| 324 allowed_by_default, | 327 allowed_by_default, std::string())); |
| 325 std::string())); | |
| 326 return webview::kInvalidPermissionRequestID; | 328 return webview::kInvalidPermissionRequestID; |
| 327 } | 329 } |
| 328 | 330 |
| 329 int request_id = next_permission_request_id_++; | 331 int request_id = next_permission_request_id_++; |
| 330 pending_permission_requests_[request_id] = | 332 pending_permission_requests_[request_id] = |
| 331 PermissionResponseInfo(callback, permission_type, allowed_by_default); | 333 PermissionResponseInfo(callback, permission_type, allowed_by_default); |
| 332 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 334 std::unique_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 333 args->Set(webview::kRequestInfo, request_info.DeepCopy()); | 335 args->Set(webview::kRequestInfo, request_info.DeepCopy()); |
| 334 args->SetInteger(webview::kRequestId, request_id); | 336 args->SetInteger(webview::kRequestId, request_id); |
| 335 switch (permission_type) { | 337 switch (permission_type) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 allowed_by_default(allowed_by_default) { | 406 allowed_by_default(allowed_by_default) { |
| 405 } | 407 } |
| 406 | 408 |
| 407 WebViewPermissionHelper::PermissionResponseInfo::PermissionResponseInfo( | 409 WebViewPermissionHelper::PermissionResponseInfo::PermissionResponseInfo( |
| 408 const PermissionResponseInfo& other) = default; | 410 const PermissionResponseInfo& other) = default; |
| 409 | 411 |
| 410 WebViewPermissionHelper::PermissionResponseInfo::~PermissionResponseInfo() { | 412 WebViewPermissionHelper::PermissionResponseInfo::~PermissionResponseInfo() { |
| 411 } | 413 } |
| 412 | 414 |
| 413 } // namespace extensions | 415 } // namespace extensions |
| OLD | NEW |