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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest.cc

Issue 11093080: <webview>: First stab at implementing media permission request for guests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use correct base for upload. Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "content/browser/browser_plugin/browser_plugin_guest.h" 5 #include "content/browser/browser_plugin/browser_plugin_guest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h" 10 #include "content/browser/browser_plugin/browser_plugin_guest_helper.h"
11 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" 11 #include "content/browser/browser_plugin/browser_plugin_host_factory.h"
12 #include "content/browser/renderer_host/render_view_host_impl.h" 12 #include "content/browser/renderer_host/render_view_host_impl.h"
13 #include "content/browser/renderer_host/render_widget_host_impl.h" 13 #include "content/browser/renderer_host/render_widget_host_impl.h"
14 #include "content/browser/web_contents/web_contents_impl.h" 14 #include "content/browser/web_contents/web_contents_impl.h"
15 #include "content/common/browser_plugin_messages.h" 15 #include "content/common/browser_plugin_messages.h"
16 #include "content/common/view_messages.h" 16 #include "content/common/view_messages.h"
17 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/notification_types.h" 18 #include "content/public/browser/notification_types.h"
19 #include "content/public/browser/render_process_host.h" 19 #include "content/public/browser/render_process_host.h"
20 #include "content/public/browser/render_widget_host_view.h" 20 #include "content/public/browser/render_widget_host_view.h"
21 #include "content/public/browser/resource_request_details.h" 21 #include "content/public/browser/resource_request_details.h"
22 #include "content/public/browser/user_metrics.h" 22 #include "content/public/browser/user_metrics.h"
23 #include "content/public/common/media_stream_request.h"
23 #include "content/public/common/result_codes.h" 24 #include "content/public/common/result_codes.h"
24 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" 25 #include "content/browser/browser_plugin/browser_plugin_host_factory.h"
25 #include "net/base/net_errors.h" 26 #include "net/base/net_errors.h"
26 #include "ui/surface/transport_dib.h" 27 #include "ui/surface/transport_dib.h"
27 #include "webkit/glue/resource_type.h" 28 #include "webkit/glue/resource_type.h"
28 29
29 namespace content { 30 namespace content {
30 31
31 // static 32 // static
32 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL; 33 BrowserPluginHostFactory* BrowserPluginGuest::factory_ = NULL;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 return true; 125 return true;
125 } 126 }
126 127
127 void BrowserPluginGuest::RendererUnresponsive(WebContents* source) { 128 void BrowserPluginGuest::RendererUnresponsive(WebContents* source) {
128 base::ProcessHandle process_handle = 129 base::ProcessHandle process_handle =
129 web_contents()->GetRenderProcessHost()->GetHandle(); 130 web_contents()->GetRenderProcessHost()->GetHandle();
130 base::KillProcess(process_handle, RESULT_CODE_HUNG, false); 131 base::KillProcess(process_handle, RESULT_CODE_HUNG, false);
131 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Hung")); 132 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Hung"));
132 } 133 }
133 134
135 void BrowserPluginGuest::RequestMediaAccessPermission(
136 WebContents* web_contents,
137 const content::MediaStreamRequest* request,
138 const content::MediaResponseCallback& callback) {
139 static int request_count = 0;
140 int request_id = request_count++;
141 media_requests_map_.insert(
142 std::make_pair(request_id,
143 std::make_pair(*request, callback)));
144
145 SendMessageToEmbedder(new BrowserPluginMsg_RequestMediaAccess(instance_id(),
146 request_id));
147 }
148
134 void BrowserPluginGuest::SetIsAcceptingTouchEvents(bool accept) { 149 void BrowserPluginGuest::SetIsAcceptingTouchEvents(bool accept) {
135 SendMessageToEmbedder( 150 SendMessageToEmbedder(
136 new BrowserPluginMsg_ShouldAcceptTouchEvents(instance_id(), accept)); 151 new BrowserPluginMsg_ShouldAcceptTouchEvents(instance_id(), accept));
137 } 152 }
138 153
139 void BrowserPluginGuest::SetVisibility(bool embedder_visible, bool visible) { 154 void BrowserPluginGuest::SetVisibility(bool embedder_visible, bool visible) {
140 visible_ = visible; 155 visible_ = visible;
141 if (embedder_visible && visible) 156 if (embedder_visible && visible)
142 web_contents()->WasShown(); 157 web_contents()->WasShown();
143 else 158 else
144 web_contents()->WasHidden(); 159 web_contents()->WasHidden();
145 } 160 }
146 161
147 WebContents* BrowserPluginGuest::GetWebContents() { 162 WebContents* BrowserPluginGuest::GetWebContents() {
148 return web_contents(); 163 return web_contents();
149 } 164 }
150 165
151 void BrowserPluginGuest::Terminate() { 166 void BrowserPluginGuest::Terminate() {
152 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Terminate")); 167 RecordAction(UserMetricsAction("BrowserPlugin.Guest.Terminate"));
153 base::ProcessHandle process_handle = 168 base::ProcessHandle process_handle =
154 web_contents()->GetRenderProcessHost()->GetHandle(); 169 web_contents()->GetRenderProcessHost()->GetHandle();
155 base::KillProcess(process_handle, RESULT_CODE_KILLED, false); 170 base::KillProcess(process_handle, RESULT_CODE_KILLED, false);
156 } 171 }
157 172
173 void BrowserPluginGuest::AllowMediaAccess(WebContents* embedder_web_contents,
174 int request_id,
175 bool allow) {
176 MediaStreamRequestsMap::iterator media_request_iter =
177 media_requests_map_.find(request_id);
178 if (media_request_iter == media_requests_map_.end()) {
179 LOG(INFO) << "Not a valid request id";
180 return;
181 }
182 const content::MediaStreamRequest& request = media_request_iter->second.first;
183 const content::MediaResponseCallback& callback =
184 media_request_iter->second.second;
185
186 if (allow) {
187 WebContentsImpl* embedder_web_contents_impl = static_cast<
188 WebContentsImpl*>(embedder_web_contents);
189 // Re-route the request to the embedder's WebContents, the guest gets the
190 // permission this way.
191 embedder_web_contents_impl->RequestMediaAccessPermission(
192 &request, callback);
193 } else {
194 // Deny the request.
195 callback.Run(content::MediaStreamDevices());
196 }
197 media_requests_map_.erase(media_request_iter);
198 }
199
158 void BrowserPluginGuest::SetDamageBuffer( 200 void BrowserPluginGuest::SetDamageBuffer(
159 TransportDIB* damage_buffer, 201 TransportDIB* damage_buffer,
160 #if defined(OS_WIN) 202 #if defined(OS_WIN)
161 int damage_buffer_size, 203 int damage_buffer_size,
162 #endif 204 #endif
163 const gfx::Size& damage_view_size, 205 const gfx::Size& damage_view_size,
164 float scale_factor) { 206 float scale_factor) {
165 // Sanity check: Verify that we've correctly shared the damage buffer memory 207 // Sanity check: Verify that we've correctly shared the damage buffer memory
166 // between the embedder and browser processes. 208 // between the embedder and browser processes.
167 DCHECK(*static_cast<unsigned int*>(damage_buffer->memory()) == 0xdeadbeef); 209 DCHECK(*static_cast<unsigned int*>(damage_buffer->memory()) == 0xdeadbeef);
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 break; 464 break;
423 } 465 }
424 } 466 }
425 467
426 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { 468 void BrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) {
427 DCHECK(embedder_render_process_host()); 469 DCHECK(embedder_render_process_host());
428 embedder_render_process_host()->Send(msg); 470 embedder_render_process_host()->Send(msg);
429 } 471 }
430 472
431 } // namespace content 473 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698