| Index: extensions/browser/api/display_source/display_source_api.cc
|
| diff --git a/extensions/browser/api/display_source/display_source_api.cc b/extensions/browser/api/display_source/display_source_api.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9b8ef5c1eeb9ff794c9069f42764d8567fb549c3
|
| --- /dev/null
|
| +++ b/extensions/browser/api/display_source/display_source_api.cc
|
| @@ -0,0 +1,101 @@
|
| +// Copyright 2015 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 "extensions/browser/api/display_source/display_source_api.h"
|
| +#include "extensions/browser/api/display_source/display_source_connection_delegate_factory.h"
|
| +#include "extensions/common/api/display_source.h"
|
| +
|
| +namespace extensions {
|
| +
|
| +namespace {
|
| +
|
| +const char kErrorNotSupported[] = "Not supported";
|
| +const char kErrorInvalidArguments[] = "Invalid arguments";
|
| +
|
| +} // namespace
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// DisplaySourceGetAvailableSinksFunction
|
| +
|
| +DisplaySourceGetAvailableSinksFunction::
|
| + ~DisplaySourceGetAvailableSinksFunction() {}
|
| +
|
| +ExtensionFunction::ResponseAction
|
| +DisplaySourceGetAvailableSinksFunction::Run() {
|
| + if (!args_->empty()) {
|
| + return RespondNow(Error(kErrorInvalidArguments));
|
| + }
|
| +
|
| + DisplaySourceConnectionDelegate* delegate =
|
| + DisplaySourceConnectionDelegateFactory::GetForBrowserContext(
|
| + browser_context());
|
| + if (!delegate) {
|
| + return RespondNow(Error(kErrorNotSupported));
|
| + }
|
| +
|
| + auto success_callback = base::Bind(
|
| + &DisplaySourceGetAvailableSinksFunction::OnGetSinksCompleted, this);
|
| + auto failure_callback = base::Bind(
|
| + &DisplaySourceGetAvailableSinksFunction::OnGetSinksFailed, this);
|
| + delegate->GetAvailableSinks(success_callback, failure_callback);
|
| +
|
| + return RespondLater();
|
| +}
|
| +
|
| +void DisplaySourceGetAvailableSinksFunction::OnGetSinksCompleted(
|
| + const SinkInfoList& sinks) {
|
| + scoped_ptr<base::ListValue> result =
|
| + api::display_source::GetAvailableSinks::Results::Create(sinks);
|
| + Respond(ArgumentList(result.Pass()));
|
| +}
|
| +
|
| +void DisplaySourceGetAvailableSinksFunction::OnGetSinksFailed(
|
| + const std::string& reason) {
|
| + Respond(Error(reason));
|
| +}
|
| +
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// DisplaySourceRequestAuthenticationFunction
|
| +
|
| +DisplaySourceRequestAuthenticationFunction::
|
| + ~DisplaySourceRequestAuthenticationFunction() {}
|
| +
|
| +ExtensionFunction::ResponseAction
|
| +DisplaySourceRequestAuthenticationFunction::Run() {
|
| + scoped_ptr<api::display_source::RequestAuthentication::Params> params(
|
| + api::display_source::RequestAuthentication::Params::Create(*args_));
|
| + if (!params) {
|
| + return RespondNow(Error(kErrorInvalidArguments));
|
| + }
|
| +
|
| + DisplaySourceConnectionDelegate* delegate =
|
| + DisplaySourceConnectionDelegateFactory::GetForBrowserContext(
|
| + browser_context());
|
| + if (!delegate) {
|
| + return RespondNow(Error(kErrorNotSupported));
|
| + }
|
| +
|
| + auto success_callback = base::Bind(
|
| + &DisplaySourceRequestAuthenticationFunction::OnRequestAuthCompleted,
|
| + this);
|
| + auto failure_callback = base::Bind(
|
| + &DisplaySourceRequestAuthenticationFunction::OnRequestAuthFailed, this);
|
| + delegate->RequestAuthentication(params->sink_id, success_callback,
|
| + failure_callback);
|
| + return RespondLater();
|
| +}
|
| +
|
| +void DisplaySourceRequestAuthenticationFunction::OnRequestAuthCompleted(
|
| + const AuthInfo& auth_info) {
|
| + scoped_ptr<base::ListValue> result =
|
| + api::display_source::RequestAuthentication::Results::Create(auth_info);
|
| + Respond(ArgumentList(result.Pass()));
|
| +}
|
| +
|
| +void DisplaySourceRequestAuthenticationFunction::OnRequestAuthFailed(
|
| + const std::string& reason) {
|
| + Respond(Error(reason));
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|