| Index: components/web_restrictions/browser/web_restrictions_mojo_implementation.cc
|
| diff --git a/components/web_restrictions/browser/web_restrictions_mojo_implementation.cc b/components/web_restrictions/browser/web_restrictions_mojo_implementation.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..923ac54a3f80c1760377bfda2c0a586df9304146
|
| --- /dev/null
|
| +++ b/components/web_restrictions/browser/web_restrictions_mojo_implementation.cc
|
| @@ -0,0 +1,73 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "components/web_restrictions/browser/web_restrictions_mojo_implementation.h"
|
| +
|
| +#include <map>
|
| +#include <utility>
|
| +
|
| +#include "base/bind.h"
|
| +#include "components/web_restrictions/browser/web_restrictions_client.h"
|
| +
|
| +namespace web_restrictions {
|
| +
|
| +namespace {
|
| +
|
| +void ClientRequestPermissionCallback(
|
| + const mojom::WebRestrictions::RequestPermissionCallback& callback,
|
| + bool result) {
|
| + callback.Run(result);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +void WebRestrictionsMojoImplementation::Create(
|
| + WebRestrictionsClient* client,
|
| + mojo::InterfaceRequest<mojom::WebRestrictions> request) {
|
| + new WebRestrictionsMojoImplementation(client, std::move(request));
|
| +}
|
| +
|
| +WebRestrictionsMojoImplementation::WebRestrictionsMojoImplementation(
|
| + WebRestrictionsClient* client,
|
| + mojo::InterfaceRequest<mojom::WebRestrictions> request)
|
| + : binding_(this, std::move(request)), web_restrictions_client_(client) {}
|
| +
|
| +WebRestrictionsMojoImplementation::~WebRestrictionsMojoImplementation() {}
|
| +
|
| +void WebRestrictionsMojoImplementation::GetResult(
|
| + const mojo::String& url,
|
| + const GetResultCallback& callback) {
|
| + std::unique_ptr<const WebRestrictionsClientResult> web_restrictions_result(
|
| + web_restrictions_client_->GetCachedWebRestrictionsResult(url));
|
| + if (!web_restrictions_result) {
|
| + callback.Run(nullptr);
|
| + return;
|
| + }
|
| + mojom::ClientResultPtr result = mojom::ClientResult::New();
|
| + int columnCount = web_restrictions_result->GetColumnCount();
|
| + std::map<std::string, std::string> string_map;
|
| + std::map<std::string, int> int_map;
|
| + for (int i = 0; i < columnCount; i++) {
|
| + if (web_restrictions_result->IsString(i)) {
|
| + string_map[web_restrictions_result->GetColumnName(i)] =
|
| + web_restrictions_result->GetString(i);
|
| + } else {
|
| + int_map[web_restrictions_result->GetColumnName(i)] =
|
| + web_restrictions_result->GetInt(i);
|
| + }
|
| + }
|
| + result->stringParams =
|
| + mojo::Map<mojo::String, mojo::String>::From(string_map);
|
| + result->intParams = mojo::Map<mojo::String, int>::From(int_map);
|
| + callback.Run(std::move(result));
|
| +}
|
| +
|
| +void WebRestrictionsMojoImplementation::RequestPermission(
|
| + const mojo::String& url,
|
| + const mojom::WebRestrictions::RequestPermissionCallback& callback) {
|
| + web_restrictions_client_->RequestPermission(
|
| + url, base::Bind(&ClientRequestPermissionCallback, callback));
|
| +}
|
| +
|
| +} // namespace web_restrictions
|
|
|