Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: chrome/browser/extensions/api/desktop_capture/desktop_capture_api.cc

Issue 186133005: Adds extension name to the screencast notification bar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/desktop_capture/desktop_capture_api.h" 5 #include "chrome/browser/extensions/api/desktop_capture/desktop_capture_api.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/extensions/extension_tab_util.h" 9 #include "chrome/browser/extensions/extension_tab_util.h"
10 #include "chrome/browser/media/desktop_media_list_ash.h" 10 #include "chrome/browser/media/desktop_media_list_ash.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 scoped_ptr<api::desktop_capture::ChooseDesktopMedia::Params> params = 80 scoped_ptr<api::desktop_capture::ChooseDesktopMedia::Params> params =
81 api::desktop_capture::ChooseDesktopMedia::Params::Create(*args_); 81 api::desktop_capture::ChooseDesktopMedia::Params::Create(*args_);
82 EXTENSION_FUNCTION_VALIDATE(params.get()); 82 EXTENSION_FUNCTION_VALIDATE(params.get());
83 83
84 DesktopCaptureRequestsRegistry::GetInstance()->AddRequest( 84 DesktopCaptureRequestsRegistry::GetInstance()->AddRequest(
85 render_view_host()->GetProcess()->GetID(), request_id_, this); 85 render_view_host()->GetProcess()->GetID(), request_id_, this);
86 86
87 gfx::NativeWindow parent_window; 87 gfx::NativeWindow parent_window;
88 content::RenderViewHost* render_view; 88 content::RenderViewHost* render_view;
89 base::string16 target_name;
89 if (params->target_tab) { 90 if (params->target_tab) {
90 if (!params->target_tab->url) { 91 if (!params->target_tab->url) {
91 error_ = kNoUrlError; 92 error_ = kNoUrlError;
92 return false; 93 return false;
93 } 94 }
94 origin_ = GURL(*(params->target_tab->url)).GetOrigin(); 95 origin_ = GURL(*(params->target_tab->url)).GetOrigin();
96 target_name = base::UTF8ToUTF16(origin_.spec());
95 97
96 if (!params->target_tab->id) { 98 if (!params->target_tab->id) {
97 error_ = kNoTabIdError; 99 error_ = kNoTabIdError;
98 return false; 100 return false;
99 } 101 }
100 102
101 content::WebContents* web_contents = NULL; 103 content::WebContents* web_contents = NULL;
102 if (!ExtensionTabUtil::GetTabById(*(params->target_tab->id), GetProfile(), 104 if (!ExtensionTabUtil::GetTabById(*(params->target_tab->id), GetProfile(),
103 true, NULL, NULL, &web_contents, NULL)) { 105 true, NULL, NULL, &web_contents, NULL)) {
104 error_ = kInvalidTabIdError; 106 error_ = kInvalidTabIdError;
105 return false; 107 return false;
106 } 108 }
107 109
108 GURL current_origin_ = 110 GURL current_origin_ =
109 web_contents->GetLastCommittedURL().GetOrigin(); 111 web_contents->GetLastCommittedURL().GetOrigin();
110 if (current_origin_ != origin_) { 112 if (current_origin_ != origin_) {
111 error_ = kTabUrlChangedError; 113 error_ = kTabUrlChangedError;
112 return false; 114 return false;
113 } 115 }
114 116
115 // Register to be notified when the tab is closed. 117 // Register to be notified when the tab is closed.
116 Observe(web_contents); 118 Observe(web_contents);
117 119
118 render_view = web_contents->GetRenderViewHost(); 120 render_view = web_contents->GetRenderViewHost();
119 parent_window = web_contents->GetView()->GetTopLevelNativeWindow(); 121 parent_window = web_contents->GetView()->GetTopLevelNativeWindow();
120 } else { 122 } else {
121 origin_ = GetExtension()->url(); 123 origin_ = GetExtension()->url();
124 target_name = base::UTF8ToUTF16(GetExtension()->name());
122 render_view = render_view_host(); 125 render_view = render_view_host();
123 parent_window = 126 parent_window =
124 GetAssociatedWebContents()->GetView()->GetTopLevelNativeWindow(); 127 GetAssociatedWebContents()->GetView()->GetTopLevelNativeWindow();
125 } 128 }
126 render_process_id_ = render_view->GetProcess()->GetID(); 129 render_process_id_ = render_view->GetProcess()->GetID();
127 render_view_id_ = render_view->GetRoutingID(); 130 render_view_id_ = render_view->GetRoutingID();
128 131
129 bool show_screens = false; 132 bool show_screens = false;
130 bool show_windows = false; 133 bool show_windows = false;
131 134
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 #else 191 #else
189 error_ = "Desktop Capture API is not yet implemented for this platform."; 192 error_ = "Desktop Capture API is not yet implemented for this platform.";
190 return false; 193 return false;
191 #endif 194 #endif
192 } 195 }
193 DesktopMediaPicker::DoneCallback callback = base::Bind( 196 DesktopMediaPicker::DoneCallback callback = base::Bind(
194 &DesktopCaptureChooseDesktopMediaFunction::OnPickerDialogResults, this); 197 &DesktopCaptureChooseDesktopMediaFunction::OnPickerDialogResults, this);
195 198
196 picker_->Show(parent_window, parent_window, 199 picker_->Show(parent_window, parent_window,
197 base::UTF8ToUTF16(GetExtension()->name()), 200 base::UTF8ToUTF16(GetExtension()->name()),
201 target_name,
198 media_list.Pass(), callback); 202 media_list.Pass(), callback);
199 return true; 203 return true;
200 } 204 }
201 205
202 void DesktopCaptureChooseDesktopMediaFunction::WebContentsDestroyed( 206 void DesktopCaptureChooseDesktopMediaFunction::WebContentsDestroyed(
203 content::WebContents* web_contents) { 207 content::WebContents* web_contents) {
204 Cancel(); 208 Cancel();
205 } 209 }
206 210
207 void DesktopCaptureChooseDesktopMediaFunction::OnPickerDialogResults( 211 void DesktopCaptureChooseDesktopMediaFunction::OnPickerDialogResults(
208 content::DesktopMediaID source) { 212 content::DesktopMediaID source) {
209 std::string result; 213 std::string result;
210 if (source.type != content::DesktopMediaID::TYPE_NONE) { 214 if (source.type != content::DesktopMediaID::TYPE_NONE) {
211 DesktopStreamsRegistry* registry = 215 DesktopStreamsRegistry* registry =
212 MediaCaptureDevicesDispatcher::GetInstance()-> 216 MediaCaptureDevicesDispatcher::GetInstance()->
213 GetDesktopStreamsRegistry(); 217 GetDesktopStreamsRegistry();
214 result = registry->RegisterStream( 218 result = registry->RegisterStream(
215 render_process_id_, render_view_id_, origin_, source); 219 render_process_id_,
220 render_view_id_,
221 origin_,
222 source,
223 GetExtension()->name());
216 } 224 }
217 225
218 SetResult(new base::StringValue(result)); 226 SetResult(new base::StringValue(result));
219 SendResponse(true); 227 SendResponse(true);
220 } 228 }
221 229
222 DesktopCaptureRequestsRegistry::RequestId::RequestId(int process_id, 230 DesktopCaptureRequestsRegistry::RequestId::RequestId(int process_id,
223 int request_id) 231 int request_id)
224 : process_id(process_id), 232 : process_id(process_id),
225 request_id(request_id) { 233 request_id(request_id) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 280
273 void DesktopCaptureRequestsRegistry::CancelRequest(int process_id, 281 void DesktopCaptureRequestsRegistry::CancelRequest(int process_id,
274 int request_id) { 282 int request_id) {
275 RequestsMap::iterator it = requests_.find(RequestId(process_id, request_id)); 283 RequestsMap::iterator it = requests_.find(RequestId(process_id, request_id));
276 if (it != requests_.end()) 284 if (it != requests_.end())
277 it->second->Cancel(); 285 it->second->Cancel();
278 } 286 }
279 287
280 288
281 } // namespace extensions 289 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/extensions/api/desktop_capture/desktop_capture_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698