OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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. |
| 4 |
| 5 #include "components/web_restrictions/browser/web_restrictions_mojo_implementati
on.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "components/web_restrictions/browser/web_restrictions_client.h" |
| 11 |
| 12 namespace web_restrictions { |
| 13 |
| 14 namespace { |
| 15 |
| 16 void ClientRequestPermissionCallback( |
| 17 const mojom::WebRestrictions::RequestPermissionCallback& callback, |
| 18 bool result) { |
| 19 callback.Run(result); |
| 20 } |
| 21 |
| 22 } // namespace |
| 23 |
| 24 void WebRestrictionsMojoImplementation::Create( |
| 25 WebRestrictionsClient* client, |
| 26 mojo::InterfaceRequest<mojom::WebRestrictions> request) { |
| 27 new WebRestrictionsMojoImplementation(client, std::move(request)); |
| 28 } |
| 29 |
| 30 WebRestrictionsMojoImplementation::WebRestrictionsMojoImplementation( |
| 31 WebRestrictionsClient* client, |
| 32 mojo::InterfaceRequest<mojom::WebRestrictions> request) |
| 33 : binding_(this, std::move(request)), web_restrictions_client_(client) {} |
| 34 |
| 35 WebRestrictionsMojoImplementation::~WebRestrictionsMojoImplementation() {} |
| 36 |
| 37 void WebRestrictionsMojoImplementation::GetResult( |
| 38 const std::string& url, |
| 39 const GetResultCallback& callback) { |
| 40 std::unique_ptr<const WebRestrictionsClientResult> web_restrictions_result( |
| 41 web_restrictions_client_->GetCachedWebRestrictionsResult(url)); |
| 42 mojom::ClientResultPtr result = mojom::ClientResult::New(); |
| 43 if (!web_restrictions_result) { |
| 44 callback.Run(std::move(result)); |
| 45 return; |
| 46 } |
| 47 int columnCount = web_restrictions_result->GetColumnCount(); |
| 48 for (int i = 0; i < columnCount; i++) { |
| 49 if (web_restrictions_result->IsString(i)) { |
| 50 result->stringParams[web_restrictions_result->GetColumnName(i)] = |
| 51 web_restrictions_result->GetString(i); |
| 52 } else { |
| 53 result->intParams[web_restrictions_result->GetColumnName(i)] = |
| 54 web_restrictions_result->GetInt(i); |
| 55 } |
| 56 } |
| 57 callback.Run(std::move(result)); |
| 58 } |
| 59 |
| 60 void WebRestrictionsMojoImplementation::RequestPermission( |
| 61 const std::string& url, |
| 62 const mojom::WebRestrictions::RequestPermissionCallback& callback) { |
| 63 web_restrictions_client_->RequestPermission( |
| 64 url, base::Bind(&ClientRequestPermissionCallback, callback)); |
| 65 } |
| 66 |
| 67 } // namespace web_restrictions |
OLD | NEW |