Index: chrome/browser/extensions/api/desktop_capture/desktop_capture_api.cc |
diff --git a/chrome/browser/extensions/api/desktop_capture/desktop_capture_api.cc b/chrome/browser/extensions/api/desktop_capture/desktop_capture_api.cc |
index 91f5c768c201b7200ceb5ba0ea0f956d1da82e10..9db5b2b72fda86da0057c1d4809e9da9d8b6fe49 100644 |
--- a/chrome/browser/extensions/api/desktop_capture/desktop_capture_api.cc |
+++ b/chrome/browser/extensions/api/desktop_capture/desktop_capture_api.cc |
@@ -52,9 +52,7 @@ void DesktopCaptureChooseDesktopMediaFunction::SetPickerFactoryForTests( |
} |
DesktopCaptureChooseDesktopMediaFunction:: |
- DesktopCaptureChooseDesktopMediaFunction() |
- : render_process_id_(0), |
- render_view_id_(0) { |
+ DesktopCaptureChooseDesktopMediaFunction() { |
} |
DesktopCaptureChooseDesktopMediaFunction:: |
@@ -90,9 +88,12 @@ bool DesktopCaptureChooseDesktopMediaFunction::RunAsync() { |
DesktopCaptureRequestsRegistry::GetInstance()->AddRequest( |
render_view_host()->GetProcess()->GetID(), request_id_, this); |
+ // |web_contents_for_stream| is the WebContents for which the stream is |
+ // created. On the other hand, |web_contents_for_picker| is used to determine |
+ // where to show the picker's UI. |
+ content::WebContents* web_contents_for_stream = NULL; |
gfx::NativeWindow parent_window = NULL; |
- content::RenderViewHost* render_view = NULL; |
- content::WebContents* web_contents = NULL; |
+ content::WebContents* web_contents_for_picker = NULL; |
Sergey Ulanov
2014/07/09 18:06:24
The same WebContents should be used for both picke
miu
2014/07/09 23:28:04
Done. However, I should point out I wasn't actual
|
base::string16 target_name; |
if (params->target_tab) { |
if (!params->target_tab->url) { |
@@ -115,32 +116,32 @@ bool DesktopCaptureChooseDesktopMediaFunction::RunAsync() { |
return false; |
} |
- if (!ExtensionTabUtil::GetTabById(*(params->target_tab->id), GetProfile(), |
- true, NULL, NULL, &web_contents, NULL)) { |
+ if (!ExtensionTabUtil::GetTabById( |
+ *(params->target_tab->id), GetProfile(), true, NULL, NULL, |
+ &web_contents_for_stream, NULL)) { |
error_ = kInvalidTabIdError; |
return false; |
} |
+ DCHECK(web_contents_for_stream); |
GURL current_origin_ = |
- web_contents->GetLastCommittedURL().GetOrigin(); |
+ web_contents_for_stream->GetLastCommittedURL().GetOrigin(); |
if (current_origin_ != origin_) { |
error_ = kTabUrlChangedError; |
return false; |
} |
- // Register to be notified when the tab is closed. |
- Observe(web_contents); |
- |
- render_view = web_contents->GetRenderViewHost(); |
- parent_window = web_contents->GetTopLevelNativeWindow(); |
+ web_contents_for_picker = web_contents_for_stream; |
+ parent_window = web_contents_for_picker->GetTopLevelNativeWindow(); |
} else { |
origin_ = GetExtension()->url(); |
target_name = base::UTF8ToUTF16(GetExtension()->name()); |
- render_view = render_view_host(); |
- |
- web_contents = GetAssociatedWebContents(); |
- if (web_contents) { |
- parent_window = web_contents->GetTopLevelNativeWindow(); |
+ web_contents_for_stream = |
+ content::WebContents::FromRenderViewHost(render_view_host()); |
+ DCHECK(web_contents_for_stream); |
+ web_contents_for_picker = GetAssociatedWebContents(); |
Sergey Ulanov
2014/07/09 18:06:24
I think this will always return the same WebConten
miu
2014/07/09 23:28:04
It doesn't. The DesktopCaptureApiTest.ChooseDeskt
|
+ if (web_contents_for_picker) { |
+ parent_window = web_contents_for_picker->GetTopLevelNativeWindow(); |
} else { |
#if defined(USE_ASH) |
if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) |
@@ -149,8 +150,8 @@ bool DesktopCaptureChooseDesktopMediaFunction::RunAsync() { |
} |
} |
- render_process_id_ = render_view->GetProcess()->GetID(); |
- render_view_id_ = render_view->GetRoutingID(); |
+ // Register to be notified when the tab is closed. |
+ Observe(web_contents_for_stream); |
bool show_screens = false; |
bool show_windows = false; |
@@ -219,7 +220,7 @@ bool DesktopCaptureChooseDesktopMediaFunction::RunAsync() { |
DesktopMediaPicker::DoneCallback callback = base::Bind( |
&DesktopCaptureChooseDesktopMediaFunction::OnPickerDialogResults, this); |
- picker_->Show(web_contents, |
+ picker_->Show(web_contents_for_picker, |
parent_window, parent_window, |
base::UTF8ToUTF16(GetExtension()->name()), |
target_name, |
@@ -234,13 +235,13 @@ void DesktopCaptureChooseDesktopMediaFunction::WebContentsDestroyed() { |
void DesktopCaptureChooseDesktopMediaFunction::OnPickerDialogResults( |
content::DesktopMediaID source) { |
std::string result; |
- if (source.type != content::DesktopMediaID::TYPE_NONE) { |
+ if (source.type != content::DesktopMediaID::TYPE_NONE && |
+ web_contents()) { |
DesktopStreamsRegistry* registry = |
MediaCaptureDevicesDispatcher::GetInstance()-> |
GetDesktopStreamsRegistry(); |
result = registry->RegisterStream( |
- render_process_id_, |
- render_view_id_, |
+ web_contents(), |
origin_, |
source, |
GetExtension()->name()); |