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