OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 // Implements the Chrome Extensions Tab Capture API. | |
6 | |
7 #include "chrome/browser/extensions/api/tab_capture/tab_capture_api.h" | |
8 | |
9 #include "base/platform_file.h" | |
10 #include "base/stringprintf.h" | |
11 #include "base/values.h" | |
12 #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.
| |
13 #include "chrome/browser/extensions/extension_service.h" | |
14 #include "chrome/browser/extensions/browser_event_router.h" | |
15 #include "chrome/browser/extensions/event_names.h" | |
16 #include "chrome/browser/extensions/extension_tab_id_map.h" | |
17 #include "chrome/browser/extensions/api/tab_capture/tab_capture_event_router.h" | |
18 | |
19 namespace TabCapture = extensions::api::experimental_tab_capture; | |
20 namespace GetTabMedia = TabCapture::GetTabMedia; | |
21 namespace GetCapturedTabs = TabCapture::GetCapturedTabs; | |
22 | |
23 namespace extensions { | |
24 | |
25 namespace { | |
26 | |
27 const char kErrorTabIdNotFound[] = "Could not find the specified tab."; | |
28 | |
29 } // namespace | |
30 | |
31 TabCaptureAsyncApiFunction::TabCaptureAsyncApiFunction() { | |
32 } | |
33 | |
34 TabCaptureAsyncApiFunction::~TabCaptureAsyncApiFunction() { | |
35 } | |
36 | |
37 bool TabCaptureAsyncApiFunction::Respond() { | |
38 return error_.empty(); | |
39 } | |
40 | |
41 TabCaptureGetTabMediaFunction::TabCaptureGetTabMediaFunction() { | |
42 } | |
43 | |
44 TabCaptureGetTabMediaFunction::~TabCaptureGetTabMediaFunction() { | |
45 } | |
46 | |
47 bool TabCaptureGetTabMediaFunction::Prepare() { | |
48 params_ = GetTabMedia::Params::Create(*args_); | |
49 EXTENSION_FUNCTION_VALIDATE(params_.get()); | |
50 return true; | |
51 } | |
52 | |
53 void TabCaptureGetTabMediaFunction::Work() { | |
54 ExtensionTabIdMap* tab_id_map = ExtensionTabIdMap::GetInstance(); | |
55 int render_process_id = -1; | |
56 int routing_id = -1; | |
57 if (!tab_id_map || | |
58 !params_->tab_id.get() || | |
59 !tab_id_map->GetProcessAndRoutingId(*params_->tab_id.get(), | |
60 &render_process_id, | |
61 &routing_id)) { | |
62 error_ = kErrorTabIdNotFound; | |
63 SetResult(base::Value::CreateIntegerValue(0)); | |
64 return; | |
65 } | |
66 | |
67 bool audio = false; | |
68 bool video = false; | |
69 if (params_->options.get()) { | |
70 if (params_->options->audio.get()) { | |
71 audio = *params_->options->audio.get(); | |
72 } | |
73 if (params_->options->video.get()) { | |
74 video = *params_->options->video.get(); | |
75 } | |
76 } | |
77 | |
78 base::DictionaryValue* result = new base::DictionaryValue(); | |
79 result->SetString("deviceId", base::StringPrintf("%i:%i:%i", | |
80 *params_->tab_id.get(), | |
81 render_process_id, | |
82 routing_id)); | |
83 result->SetBoolean("options.audio", audio); | |
84 result->SetBoolean("options.video", video); | |
85 SetResult(result); | |
86 } | |
87 | |
88 TabCaptureGetCapturedTabsFunction::TabCaptureGetCapturedTabsFunction() { | |
89 } | |
90 | |
91 TabCaptureGetCapturedTabsFunction::~TabCaptureGetCapturedTabsFunction() { | |
92 } | |
93 | |
94 bool TabCaptureGetCapturedTabsFunction::Prepare() { | |
95 return true; | |
96 } | |
97 | |
98 void TabCaptureGetCapturedTabsFunction::Work() { | |
99 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.
| |
100 GetExtensionService()->tab_capture_event_router()->GetCapturedTabs(); | |
101 | |
102 base::ListValue *list = new base::ListValue(); | |
103 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.
| |
104 capture_states.begin(); it != capture_states.end(); it++) { | |
105 scoped_ptr<tab_capture::CaptureInfo> info(new tab_capture::CaptureInfo()); | |
106 info->tab_id = it->first; | |
107 info->status = it->second; | |
108 list->Append(info->ToValue().release()); | |
109 } | |
110 | |
111 SetResult(list); | |
112 SendResponse(true); | |
113 } | |
114 | |
115 } // namespace extensions | |
OLD | NEW |