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

Side by Side Diff: chrome/browser/guestview/webview/webview_guest.cc

Issue 235733002: <webview>: Move media request to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_geolocation_to_chrome
Patch Set: Fixed rebase Created 6 years, 8 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/guestview/webview/webview_guest.h" 5 #include "chrome/browser/guestview/webview/webview_guest.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/extensions/api/web_request/web_request_api.h" 10 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
(...skipping 14 matching lines...) Expand all
25 #include "content/public/browser/notification_details.h" 25 #include "content/public/browser/notification_details.h"
26 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/notification_source.h" 27 #include "content/public/browser/notification_source.h"
28 #include "content/public/browser/notification_types.h" 28 #include "content/public/browser/notification_types.h"
29 #include "content/public/browser/render_process_host.h" 29 #include "content/public/browser/render_process_host.h"
30 #include "content/public/browser/resource_request_details.h" 30 #include "content/public/browser/resource_request_details.h"
31 #include "content/public/browser/site_instance.h" 31 #include "content/public/browser/site_instance.h"
32 #include "content/public/browser/storage_partition.h" 32 #include "content/public/browser/storage_partition.h"
33 #include "content/public/browser/user_metrics.h" 33 #include "content/public/browser/user_metrics.h"
34 #include "content/public/browser/web_contents.h" 34 #include "content/public/browser/web_contents.h"
35 #include "content/public/browser/web_contents_delegate.h"
36 #include "content/public/common/media_stream_request.h"
35 #include "content/public/common/page_zoom.h" 37 #include "content/public/common/page_zoom.h"
36 #include "content/public/common/result_codes.h" 38 #include "content/public/common/result_codes.h"
37 #include "content/public/common/stop_find_action.h" 39 #include "content/public/common/stop_find_action.h"
38 #include "extensions/common/constants.h" 40 #include "extensions/common/constants.h"
39 #include "net/base/net_errors.h" 41 #include "net/base/net_errors.h"
40 #include "third_party/WebKit/public/web/WebFindOptions.h" 42 #include "third_party/WebKit/public/web/WebFindOptions.h"
41 43
42 #if defined(ENABLE_PLUGINS) 44 #if defined(ENABLE_PLUGINS)
43 #include "chrome/browser/guestview/webview/plugin_permission_helper.h" 45 #include "chrome/browser/guestview/webview/plugin_permission_helper.h"
44 #endif 46 #endif
(...skipping 25 matching lines...) Expand all
70 break; 72 break;
71 } 73 }
72 NOTREACHED() << "Unknown Termination Status."; 74 NOTREACHED() << "Unknown Termination Status.";
73 return "unknown"; 75 return "unknown";
74 } 76 }
75 77
76 static std::string PermissionTypeToString(BrowserPluginPermissionType type) { 78 static std::string PermissionTypeToString(BrowserPluginPermissionType type) {
77 switch (type) { 79 switch (type) {
78 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: 80 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD:
79 return webview::kPermissionTypeDownload; 81 return webview::kPermissionTypeDownload;
80 case BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA:
81 return webview::kPermissionTypeMedia;
82 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: 82 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW:
83 return webview::kPermissionTypeNewWindow; 83 return webview::kPermissionTypeNewWindow;
84 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: 84 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK:
85 return webview::kPermissionTypePointerLock; 85 return webview::kPermissionTypePointerLock;
86 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: 86 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
87 return webview::kPermissionTypeDialog; 87 return webview::kPermissionTypeDialog;
88 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: 88 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN:
89 NOTREACHED(); 89 NOTREACHED();
90 break; 90 break;
91 default: { 91 default: {
92 WebViewPermissionType webview = static_cast<WebViewPermissionType>(type); 92 WebViewPermissionType webview = static_cast<WebViewPermissionType>(type);
93 switch (webview) { 93 switch (webview) {
94 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: 94 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION:
95 return webview::kPermissionTypeGeolocation; 95 return webview::kPermissionTypeGeolocation;
96 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: 96 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
97 return webview::kPermissionTypeLoadPlugin; 97 return webview::kPermissionTypeLoadPlugin;
98 case WEB_VIEW_PERMISSION_TYPE_MEDIA:
99 return webview::kPermissionTypeMedia;
98 } 100 }
99 NOTREACHED(); 101 NOTREACHED();
100 } 102 }
101 } 103 }
102 return std::string(); 104 return std::string();
103 } 105 }
104 106
105 void RemoveWebViewEventListenersOnIOThread( 107 void RemoveWebViewEventListenersOnIOThread(
106 void* profile, 108 void* profile,
107 const std::string& extension_id, 109 const std::string& extension_id,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 if (allow) { 190 if (allow) {
189 // Note that |allow| == true means the embedder explicitly allowed the 191 // Note that |allow| == true means the embedder explicitly allowed the
190 // request. For some requests they might still fail. An example of such 192 // request. For some requests they might still fail. An example of such
191 // scenario would be: an embedder allows geolocation request but doesn't 193 // scenario would be: an embedder allows geolocation request but doesn't
192 // have geolocation access on its own. 194 // have geolocation access on its own.
193 switch (info.permission_type) { 195 switch (info.permission_type) {
194 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: 196 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD:
195 content::RecordAction( 197 content::RecordAction(
196 UserMetricsAction("BrowserPlugin.PermissionAllow.Download")); 198 UserMetricsAction("BrowserPlugin.PermissionAllow.Download"));
197 break; 199 break;
198 case BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA:
199 content::RecordAction(
200 UserMetricsAction("BrowserPlugin.PermissionAllow.Media"));
201 break;
202 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: 200 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK:
203 content::RecordAction( 201 content::RecordAction(
204 UserMetricsAction("BrowserPlugin.PermissionAllow.PointerLock")); 202 UserMetricsAction("BrowserPlugin.PermissionAllow.PointerLock"));
205 break; 203 break;
206 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: 204 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW:
207 content::RecordAction( 205 content::RecordAction(
208 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow")); 206 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow"));
209 break; 207 break;
210 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: 208 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
211 content::RecordAction( 209 content::RecordAction(
212 UserMetricsAction("BrowserPlugin.PermissionAllow.JSDialog")); 210 UserMetricsAction("BrowserPlugin.PermissionAllow.JSDialog"));
213 break; 211 break;
214 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: 212 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN:
215 break; 213 break;
216 default: { 214 default: {
217 WebViewPermissionType webview_permission_type = 215 WebViewPermissionType webview_permission_type =
218 static_cast<WebViewPermissionType>(info.permission_type); 216 static_cast<WebViewPermissionType>(info.permission_type);
219 switch (webview_permission_type) { 217 switch (webview_permission_type) {
220 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: 218 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION:
221 content::RecordAction( 219 content::RecordAction(
222 UserMetricsAction("WebView.PermissionAllow.Geolocation")); 220 UserMetricsAction("WebView.PermissionAllow.Geolocation"));
223 break; 221 break;
224 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: 222 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
225 content::RecordAction( 223 content::RecordAction(
226 UserMetricsAction("WebView.Guest.PermissionAllow.PluginLoad")); 224 UserMetricsAction("WebView.Guest.PermissionAllow.PluginLoad"));
225 case WEB_VIEW_PERMISSION_TYPE_MEDIA:
226 content::RecordAction(
227 UserMetricsAction("WebView.PermissionAllow.Media"));
227 break; 228 break;
228 default: 229 default:
229 break; 230 break;
230 } 231 }
231 } 232 }
232 } 233 }
233 } else { 234 } else {
234 switch (info.permission_type) { 235 switch (info.permission_type) {
235 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD: 236 case BROWSER_PLUGIN_PERMISSION_TYPE_DOWNLOAD:
236 content::RecordAction( 237 content::RecordAction(
237 UserMetricsAction("BrowserPlugin.PermissionDeny.Download")); 238 UserMetricsAction("BrowserPlugin.PermissionDeny.Download"));
238 break; 239 break;
239 case BROWSER_PLUGIN_PERMISSION_TYPE_MEDIA:
240 content::RecordAction(
241 UserMetricsAction("BrowserPlugin.PermissionDeny.Media"));
242 break;
243 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK: 240 case BROWSER_PLUGIN_PERMISSION_TYPE_POINTER_LOCK:
244 content::RecordAction( 241 content::RecordAction(
245 UserMetricsAction("BrowserPlugin.PermissionDeny.PointerLock")); 242 UserMetricsAction("BrowserPlugin.PermissionDeny.PointerLock"));
246 break; 243 break;
247 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW: 244 case BROWSER_PLUGIN_PERMISSION_TYPE_NEW_WINDOW:
248 content::RecordAction( 245 content::RecordAction(
249 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow")); 246 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow"));
250 break; 247 break;
251 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG: 248 case BROWSER_PLUGIN_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
252 content::RecordAction( 249 content::RecordAction(
253 UserMetricsAction("BrowserPlugin.PermissionDeny.JSDialog")); 250 UserMetricsAction("BrowserPlugin.PermissionDeny.JSDialog"));
254 break; 251 break;
255 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN: 252 case BROWSER_PLUGIN_PERMISSION_TYPE_UNKNOWN:
256 break; 253 break;
257 default: { 254 default: {
258 WebViewPermissionType webview_permission_type = 255 WebViewPermissionType webview_permission_type =
259 static_cast<WebViewPermissionType>(info.permission_type); 256 static_cast<WebViewPermissionType>(info.permission_type);
260 switch (webview_permission_type) { 257 switch (webview_permission_type) {
261 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION: 258 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION:
262 content::RecordAction( 259 content::RecordAction(
263 UserMetricsAction("WebView.PermissionDeny.Geolocation")); 260 UserMetricsAction("WebView.PermissionDeny.Geolocation"));
264 break; 261 break;
265 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN: 262 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
266 content::RecordAction( 263 content::RecordAction(
267 UserMetricsAction("WebView.Guest.PermissionDeny.PluginLoad")); 264 UserMetricsAction("WebView.Guest.PermissionDeny.PluginLoad"));
265 case WEB_VIEW_PERMISSION_TYPE_MEDIA:
266 content::RecordAction(
267 UserMetricsAction("WebView.PermissionDeny.Media"));
268 break; 268 break;
269 default: 269 default:
270 break; 270 break;
271 } 271 }
272 } 272 }
273 } 273 }
274 } 274 }
275 } 275 }
276 276
277 void WebViewGuest::Attach(WebContents* embedder_web_contents, 277 void WebViewGuest::Attach(WebContents* embedder_web_contents,
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 int request_id = RemoveBridgeID(bridge_id); 583 int request_id = RemoveBridgeID(bridge_id);
584 RequestMap::iterator request_itr = 584 RequestMap::iterator request_itr =
585 pending_permission_requests_.find(request_id); 585 pending_permission_requests_.find(request_id);
586 586
587 if (request_itr == pending_permission_requests_.end()) 587 if (request_itr == pending_permission_requests_.end())
588 return; 588 return;
589 589
590 pending_permission_requests_.erase(request_itr); 590 pending_permission_requests_.erase(request_itr);
591 } 591 }
592 592
593 void WebViewGuest::OnWebViewMediaPermissionResponse(
594 const content::MediaStreamRequest& request,
595 const content::MediaResponseCallback& callback,
596 bool allow,
597 const std::string& user_input) {
598 if (!allow || !attached()) {
599 // Deny the request.
600 callback.Run(content::MediaStreamDevices(),
601 content::MEDIA_DEVICE_INVALID_STATE,
602 scoped_ptr<content::MediaStreamUI>());
603 return;
604 }
605 if (!embedder_web_contents()->GetDelegate())
606 return;
607
608 embedder_web_contents()->GetDelegate()->
609 RequestMediaAccessPermission(embedder_web_contents(), request, callback);
610 }
611
593 WebViewGuest::SetPermissionResult WebViewGuest::SetPermission( 612 WebViewGuest::SetPermissionResult WebViewGuest::SetPermission(
594 int request_id, 613 int request_id,
595 PermissionResponseAction action, 614 PermissionResponseAction action,
596 const std::string& user_input) { 615 const std::string& user_input) {
597 RequestMap::iterator request_itr = 616 RequestMap::iterator request_itr =
598 pending_permission_requests_.find(request_id); 617 pending_permission_requests_.find(request_id);
599 618
600 if (request_itr == pending_permission_requests_.end()) 619 if (request_itr == pending_permission_requests_.end())
601 return SET_PERMISSION_INVALID; 620 return SET_PERMISSION_INVALID;
602 621
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 void WebViewGuest::SizeChanged(const gfx::Size& old_size, 847 void WebViewGuest::SizeChanged(const gfx::Size& old_size,
829 const gfx::Size& new_size) { 848 const gfx::Size& new_size) {
830 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 849 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
831 args->SetInteger(webview::kOldHeight, old_size.height()); 850 args->SetInteger(webview::kOldHeight, old_size.height());
832 args->SetInteger(webview::kOldWidth, old_size.width()); 851 args->SetInteger(webview::kOldWidth, old_size.width());
833 args->SetInteger(webview::kNewHeight, new_size.height()); 852 args->SetInteger(webview::kNewHeight, new_size.height());
834 args->SetInteger(webview::kNewWidth, new_size.width()); 853 args->SetInteger(webview::kNewWidth, new_size.width());
835 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass())); 854 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass()));
836 } 855 }
837 856
857 void WebViewGuest::RequestMediaAccessPermission(
858 const content::MediaStreamRequest& request,
859 const content::MediaResponseCallback& callback) {
860 base::DictionaryValue request_info;
861 request_info.Set(
862 guestview::kUrl,
863 base::Value::CreateStringValue(request.security_origin.spec()));
864 RequestPermission(static_cast<BrowserPluginPermissionType>(
865 WEB_VIEW_PERMISSION_TYPE_MEDIA),
866 request_info,
867 base::Bind(&WebViewGuest::OnWebViewMediaPermissionResponse,
868 base::Unretained(this),
869 request,
870 callback),
871 false /* allowed_by_default */);
872 }
873
838 #if defined(OS_CHROMEOS) 874 #if defined(OS_CHROMEOS)
839 void WebViewGuest::OnAccessibilityStatusChanged( 875 void WebViewGuest::OnAccessibilityStatusChanged(
840 const chromeos::AccessibilityStatusEventDetails& details) { 876 const chromeos::AccessibilityStatusEventDetails& details) {
841 if (details.notification_type == chromeos::ACCESSIBILITY_MANAGER_SHUTDOWN) { 877 if (details.notification_type == chromeos::ACCESSIBILITY_MANAGER_SHUTDOWN) {
842 accessibility_subscription_.reset(); 878 accessibility_subscription_.reset();
843 } else if (details.notification_type == 879 } else if (details.notification_type ==
844 chromeos::ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK) { 880 chromeos::ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK) {
845 if (details.enabled) 881 if (details.enabled)
846 InjectChromeVoxIfNeeded(guest_web_contents()->GetRenderViewHost()); 882 InjectChromeVoxIfNeeded(guest_web_contents()->GetRenderViewHost());
847 else 883 else
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 const PermissionResponseCallback& callback, 968 const PermissionResponseCallback& callback,
933 BrowserPluginPermissionType permission_type, 969 BrowserPluginPermissionType permission_type,
934 bool allowed_by_default) 970 bool allowed_by_default)
935 : callback(callback), 971 : callback(callback),
936 permission_type(permission_type), 972 permission_type(permission_type),
937 allowed_by_default(allowed_by_default) { 973 allowed_by_default(allowed_by_default) {
938 } 974 }
939 975
940 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() { 976 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() {
941 } 977 }
OLDNEW
« no previous file with comments | « chrome/browser/guestview/webview/webview_guest.h ('k') | chrome/browser/guestview/webview/webview_permission_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698