| Index: chrome/browser/extensions/api/tab_capture/tab_capture_api.cc
|
| diff --git a/chrome/browser/extensions/api/tab_capture/tab_capture_api.cc b/chrome/browser/extensions/api/tab_capture/tab_capture_api.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6c23802bb765fa785803bce75da53788be9b57ff
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/tab_capture/tab_capture_api.cc
|
| @@ -0,0 +1,116 @@
|
| +// Copyright (c) 2012 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.
|
| +
|
| +// Implements the Chrome Extensions Tab Capture API.
|
| +
|
| +#include "chrome/browser/extensions/api/tab_capture/tab_capture_api.h"
|
| +
|
| +#include "base/platform_file.h"
|
| +#include "base/stringprintf.h"
|
| +#include "base/values.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/extensions/extension_service.h"
|
| +#include "chrome/browser/extensions/browser_event_router.h"
|
| +#include "chrome/browser/extensions/event_names.h"
|
| +#include "chrome/browser/extensions/extension_tab_id_map.h"
|
| +#include "chrome/browser/extensions/api/tab_capture/tab_capture_event_router.h"
|
| +
|
| +namespace TabCapture = extensions::api::experimental_tab_capture;
|
| +namespace GetTabMedia = TabCapture::GetTabMedia;
|
| +namespace GetCapturedTabs = TabCapture::GetCapturedTabs;
|
| +
|
| +namespace extensions {
|
| +
|
| +namespace {
|
| +
|
| +const char kErrorTabIdNotFound[] = "Could not find the specified tab.";
|
| +
|
| +} // namespace
|
| +
|
| +TabCaptureAsyncApiFunction::TabCaptureAsyncApiFunction() {
|
| +}
|
| +
|
| +TabCaptureAsyncApiFunction::~TabCaptureAsyncApiFunction() {
|
| +}
|
| +
|
| +bool TabCaptureAsyncApiFunction::Respond() {
|
| + return error_.empty();
|
| +}
|
| +
|
| +TabCaptureGetTabMediaFunction::TabCaptureGetTabMediaFunction() {
|
| +}
|
| +
|
| +TabCaptureGetTabMediaFunction::~TabCaptureGetTabMediaFunction() {
|
| +}
|
| +
|
| +bool TabCaptureGetTabMediaFunction::Prepare() {
|
| + params_ = GetTabMedia::Params::Create(*args_);
|
| + EXTENSION_FUNCTION_VALIDATE(params_.get());
|
| + return true;
|
| +}
|
| +
|
| +void TabCaptureGetTabMediaFunction::Work() {
|
| + ExtensionTabIdMap* tab_id_map = ExtensionTabIdMap::GetInstance();
|
| + int render_process_id = -1;
|
| + int routing_id = -1;
|
| + if (!tab_id_map ||
|
| + !params_->tab_id.get() ||
|
| + !tab_id_map->GetProcessAndRoutingId(*params_->tab_id.get(),
|
| + &render_process_id,
|
| + &routing_id)) {
|
| + error_ = kErrorTabIdNotFound;
|
| + SendResponse(false);
|
| + SetResult(NULL);
|
| + }
|
| +
|
| + bool audio = false;
|
| + bool video = false;
|
| + if (params_->options.get()) {
|
| + if (params_->options->audio.get()) {
|
| + audio = *params_->options->audio.get();
|
| + }
|
| + if (params_->options->video.get()) {
|
| + video = *params_->options->video.get();
|
| + }
|
| + }
|
| +
|
| + base::DictionaryValue* result = new base::DictionaryValue();
|
| + result->SetString("deviceId", base::StringPrintf("%i:%i:%i",
|
| + *params_->tab_id.get(),
|
| + render_process_id,
|
| + routing_id));
|
| + result->SetBoolean("options.audio", audio);
|
| + result->SetBoolean("options.video", video);
|
| +
|
| + SetResult(result);
|
| +}
|
| +
|
| +TabCaptureGetCapturedTabsFunction::TabCaptureGetCapturedTabsFunction() {
|
| +}
|
| +
|
| +TabCaptureGetCapturedTabsFunction::~TabCaptureGetCapturedTabsFunction() {
|
| +}
|
| +
|
| +bool TabCaptureGetCapturedTabsFunction::Prepare() {
|
| + return true;
|
| +}
|
| +
|
| +void TabCaptureGetCapturedTabsFunction::Work() {
|
| + std::map<int, tab_capture::TabCaptureState> capture_states = profile()->
|
| + GetExtensionService()->tab_capture_event_router()->GetCapturedTabs();
|
| +
|
| + base::ListValue *list = new base::ListValue();
|
| + for (std::map<int, tab_capture::TabCaptureState>::iterator it =
|
| + capture_states.begin(); it != capture_states.end(); it++) {
|
| + scoped_ptr<tab_capture::CaptureInfo> info(new tab_capture::CaptureInfo());
|
| + info->tab_id = it->first;
|
| + info->status = it->second;
|
| + list->Append(info->ToValue().release());
|
| + }
|
| +
|
| + SetResult(list);
|
| + SendResponse(true);
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|