Chromium Code Reviews| 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..a497e60d83dd67803a2fe7f52d6c8edc79b4086c |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/tab_capture/tab_capture_api.cc |
| @@ -0,0 +1,115 @@ |
| +// 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" |
|
Alpha Left Google
2012/10/04 20:52:01
Fix order of include.
justinlin
2012/10/08 09:58:31
Done.
|
| +#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; |
| + SetResult(base::Value::CreateIntegerValue(0)); |
| + return; |
| + } |
| + |
| + 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()-> |
|
Alpha Left Google
2012/10/04 20:52:01
Is there a typedef for this map?
justinlin
2012/10/08 09:58:31
Done.
|
| + GetExtensionService()->tab_capture_event_router()->GetCapturedTabs(); |
| + |
| + base::ListValue *list = new base::ListValue(); |
| + for (std::map<int, tab_capture::TabCaptureState>::iterator it = |
|
Alpha Left Google
2012/10/04 20:52:01
Same here, better if there's a typedef for this ta
justinlin
2012/10/08 09:58:31
Done.
|
| + 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 |