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

Side by Side Diff: chrome/browser/guest_view/web_view/web_view_guest.cc

Issue 347113002: Refactor PluginPermissionHelper as WebViewPermissionHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/guest_view/web_view/web_view_guest.h" 5 #include "chrome/browser/guest_view/web_view/web_view_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 "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
12 #include "chrome/browser/extensions/api/web_request/web_request_api.h" 11 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
13 #include "chrome/browser/extensions/api/web_view/web_view_internal_api.h" 12 #include "chrome/browser/extensions/api/web_view/web_view_internal_api.h"
14 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" 13 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
15 #include "chrome/browser/extensions/menu_manager.h" 14 #include "chrome/browser/extensions/menu_manager.h"
16 #include "chrome/browser/extensions/script_executor.h" 15 #include "chrome/browser/extensions/script_executor.h"
17 #include "chrome/browser/favicon/favicon_tab_helper.h" 16 #include "chrome/browser/favicon/favicon_tab_helper.h"
18 #include "chrome/browser/geolocation/geolocation_permission_context.h"
19 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
20 #include "chrome/browser/guest_view/guest_view_constants.h" 17 #include "chrome/browser/guest_view/guest_view_constants.h"
21 #include "chrome/browser/guest_view/guest_view_manager.h" 18 #include "chrome/browser/guest_view/guest_view_manager.h"
22 #include "chrome/browser/guest_view/web_view/web_view_constants.h" 19 #include "chrome/browser/guest_view/web_view/web_view_constants.h"
20 #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h"
23 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" 21 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h"
24 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h" 22 #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h"
25 #include "chrome/browser/renderer_context_menu/context_menu_delegate.h" 23 #include "chrome/browser/renderer_context_menu/context_menu_delegate.h"
26 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" 24 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
27 #include "chrome/browser/ui/pdf/pdf_tab_helper.h" 25 #include "chrome/browser/ui/pdf/pdf_tab_helper.h"
28 #include "chrome/browser/ui/zoom/zoom_controller.h" 26 #include "chrome/browser/ui/zoom/zoom_controller.h"
29 #include "chrome/common/chrome_version_info.h" 27 #include "chrome/common/chrome_version_info.h"
30 #include "chrome/common/render_messages.h" 28 #include "chrome/common/render_messages.h"
31 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/child_process_security_policy.h" 30 #include "content/public/browser/child_process_security_policy.h"
(...skipping 25 matching lines...) Expand all
58 56
59 #if defined(ENABLE_PRINTING) 57 #if defined(ENABLE_PRINTING)
60 #if defined(ENABLE_FULL_PRINTING) 58 #if defined(ENABLE_FULL_PRINTING)
61 #include "chrome/browser/printing/print_preview_message_handler.h" 59 #include "chrome/browser/printing/print_preview_message_handler.h"
62 #include "chrome/browser/printing/print_view_manager.h" 60 #include "chrome/browser/printing/print_view_manager.h"
63 #else 61 #else
64 #include "chrome/browser/printing/print_view_manager_basic.h" 62 #include "chrome/browser/printing/print_view_manager_basic.h"
65 #endif // defined(ENABLE_FULL_PRINTING) 63 #endif // defined(ENABLE_FULL_PRINTING)
66 #endif // defined(ENABLE_PRINTING) 64 #endif // defined(ENABLE_PRINTING)
67 65
68 #if defined(ENABLE_PLUGINS) && !defined(OS_ANDROID)
69 #include "chrome/browser/guest_view/web_view/plugin_permission_helper.h"
70 #endif
71
72 #if defined(OS_CHROMEOS) 66 #if defined(OS_CHROMEOS)
73 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" 67 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
74 #endif 68 #endif
75 69
76 using base::UserMetricsAction; 70 using base::UserMetricsAction;
77 using content::RenderFrameHost; 71 using content::RenderFrameHost;
78 using content::ResourceType; 72 using content::ResourceType;
79 using content::WebContents; 73 using content::WebContents;
80 74
81 namespace { 75 namespace {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 return "killed"; 108 return "killed";
115 case base::TERMINATION_STATUS_PROCESS_CRASHED: 109 case base::TERMINATION_STATUS_PROCESS_CRASHED:
116 return "crashed"; 110 return "crashed";
117 case base::TERMINATION_STATUS_MAX_ENUM: 111 case base::TERMINATION_STATUS_MAX_ENUM:
118 break; 112 break;
119 } 113 }
120 NOTREACHED() << "Unknown Termination Status."; 114 NOTREACHED() << "Unknown Termination Status.";
121 return "unknown"; 115 return "unknown";
122 } 116 }
123 117
124 static std::string PermissionTypeToString(WebViewPermissionType type) {
125 switch (type) {
126 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD:
127 return webview::kPermissionTypeDownload;
128 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM:
129 return webview::kPermissionTypeFileSystem;
130 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION:
131 return webview::kPermissionTypeGeolocation;
132 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
133 return webview::kPermissionTypeDialog;
134 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
135 return webview::kPermissionTypeLoadPlugin;
136 case WEB_VIEW_PERMISSION_TYPE_MEDIA:
137 return webview::kPermissionTypeMedia;
138 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW:
139 return webview::kPermissionTypeNewWindow;
140 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK:
141 return webview::kPermissionTypePointerLock;
142 default:
143 NOTREACHED();
144 return std::string();
145 }
146 }
147
148 std::string GetStoragePartitionIdFromSiteURL(const GURL& site_url) { 118 std::string GetStoragePartitionIdFromSiteURL(const GURL& site_url) {
149 const std::string& partition_id = site_url.query(); 119 const std::string& partition_id = site_url.query();
150 bool persist_storage = site_url.path().find("persist") != std::string::npos; 120 bool persist_storage = site_url.path().find("persist") != std::string::npos;
151 return (persist_storage ? webview::kPersistPrefix : "") + partition_id; 121 return (persist_storage ? webview::kPersistPrefix : "") + partition_id;
152 } 122 }
153 123
154 void RemoveWebViewEventListenersOnIOThread( 124 void RemoveWebViewEventListenersOnIOThread(
155 void* profile, 125 void* profile,
156 const std::string& extension_id, 126 const std::string& extension_id,
157 int embedder_process_id, 127 int embedder_process_id,
158 int view_instance_id) { 128 int view_instance_id) {
159 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 129 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
160 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( 130 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners(
161 profile, 131 profile,
162 extension_id, 132 extension_id,
163 embedder_process_id, 133 embedder_process_id,
164 view_instance_id); 134 view_instance_id);
165 } 135 }
166 136
167 void AttachWebViewHelpers(WebContents* contents) {
168 // Create a zoom controller for the guest contents give it access to
169 // GetZoomLevel() and and SetZoomLevel() in WebViewGuest.
170 // TODO(wjmaclean) This currently uses the same HostZoomMap as the browser
171 // context, but we eventually want to isolate the guest contents from zoom
172 // changes outside the guest (e.g. in the main browser), so we should
173 // create a separate HostZoomMap for the guest.
174 ZoomController::CreateForWebContents(contents);
175
176 FaviconTabHelper::CreateForWebContents(contents);
177 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
178 contents);
179 #if defined(ENABLE_PLUGINS) && !defined(OS_ANDROID)
180 PluginPermissionHelper::CreateForWebContents(contents);
181 #endif
182 #if defined(ENABLE_PRINTING)
183 #if defined(ENABLE_FULL_PRINTING)
184 printing::PrintViewManager::CreateForWebContents(contents);
185 printing::PrintPreviewMessageHandler::CreateForWebContents(contents);
186 #else
187 printing::PrintViewManagerBasic::CreateForWebContents(contents);
188 #endif // defined(ENABLE_FULL_PRINTING)
189 #endif // defined(ENABLE_PRINTING)
190 PDFTabHelper::CreateForWebContents(contents);
191 }
192
193 void ParsePartitionParam(const base::DictionaryValue& create_params, 137 void ParsePartitionParam(const base::DictionaryValue& create_params,
194 std::string* storage_partition_id, 138 std::string* storage_partition_id,
195 bool* persist_storage) { 139 bool* persist_storage) {
196 std::string partition_str; 140 std::string partition_str;
197 if (!create_params.GetString(webview::kStoragePartitionId, &partition_str)) { 141 if (!create_params.GetString(webview::kStoragePartitionId, &partition_str)) {
198 return; 142 return;
199 } 143 }
200 144
201 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on 145 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on
202 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely 146 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely
(...skipping 15 matching lines...) Expand all
218 *persist_storage = false; 162 *persist_storage = false;
219 } 163 }
220 } 164 }
221 165
222 } // namespace 166 } // namespace
223 167
224 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context, 168 WebViewGuest::WebViewGuest(content::BrowserContext* browser_context,
225 int guest_instance_id) 169 int guest_instance_id)
226 : GuestView<WebViewGuest>(browser_context, guest_instance_id), 170 : GuestView<WebViewGuest>(browser_context, guest_instance_id),
227 pending_context_menu_request_id_(0), 171 pending_context_menu_request_id_(0),
228 next_permission_request_id_(0),
229 is_overriding_user_agent_(false), 172 is_overriding_user_agent_(false),
230 main_frame_id_(0), 173 main_frame_id_(0),
231 chromevox_injected_(false), 174 chromevox_injected_(false),
232 current_zoom_factor_(1.0), 175 current_zoom_factor_(1.0),
233 find_helper_(this), 176 find_helper_(this),
234 javascript_dialog_helper_(this) { 177 javascript_dialog_helper_(this) {
235 } 178 }
236 179
237 // static 180 // static
238 bool WebViewGuest::GetGuestPartitionConfigForSite( 181 bool WebViewGuest::GetGuestPartitionConfigForSite(
(...skipping 24 matching lines...) Expand all
263 // static 206 // static
264 int WebViewGuest::GetViewInstanceId(WebContents* contents) { 207 int WebViewGuest::GetViewInstanceId(WebContents* contents) {
265 WebViewGuest* guest = FromWebContents(contents); 208 WebViewGuest* guest = FromWebContents(contents);
266 if (!guest) 209 if (!guest)
267 return guestview::kInstanceIDNone; 210 return guestview::kInstanceIDNone;
268 211
269 return guest->view_instance_id(); 212 return guest->view_instance_id();
270 } 213 }
271 214
272 // static 215 // static
273 void WebViewGuest::RecordUserInitiatedUMA(const PermissionResponseInfo& info,
274 bool allow) {
275 if (allow) {
276 // Note that |allow| == true means the embedder explicitly allowed the
277 // request. For some requests they might still fail. An example of such
278 // scenario would be: an embedder allows geolocation request but doesn't
279 // have geolocation access on its own.
280 switch (info.permission_type) {
281 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD:
282 content::RecordAction(
283 UserMetricsAction("WebView.PermissionAllow.Download"));
284 break;
285 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM:
286 content::RecordAction(
287 UserMetricsAction("WebView.PermissionAllow.FileSystem"));
288 break;
289 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION:
290 content::RecordAction(
291 UserMetricsAction("WebView.PermissionAllow.Geolocation"));
292 break;
293 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
294 content::RecordAction(
295 UserMetricsAction("WebView.PermissionAllow.JSDialog"));
296 break;
297 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
298 content::RecordAction(
299 UserMetricsAction("WebView.Guest.PermissionAllow.PluginLoad"));
300 case WEB_VIEW_PERMISSION_TYPE_MEDIA:
301 content::RecordAction(
302 UserMetricsAction("WebView.PermissionAllow.Media"));
303 break;
304 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW:
305 content::RecordAction(
306 UserMetricsAction("BrowserPlugin.PermissionAllow.NewWindow"));
307 break;
308 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK:
309 content::RecordAction(
310 UserMetricsAction("WebView.PermissionAllow.PointerLock"));
311 break;
312 default:
313 break;
314 }
315 } else {
316 switch (info.permission_type) {
317 case WEB_VIEW_PERMISSION_TYPE_DOWNLOAD:
318 content::RecordAction(
319 UserMetricsAction("WebView.PermissionDeny.Download"));
320 break;
321 case WEB_VIEW_PERMISSION_TYPE_FILESYSTEM:
322 content::RecordAction(
323 UserMetricsAction("WebView.PermissionDeny.FileSystem"));
324 break;
325 case WEB_VIEW_PERMISSION_TYPE_GEOLOCATION:
326 content::RecordAction(
327 UserMetricsAction("WebView.PermissionDeny.Geolocation"));
328 break;
329 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG:
330 content::RecordAction(
331 UserMetricsAction("WebView.PermissionDeny.JSDialog"));
332 break;
333 case WEB_VIEW_PERMISSION_TYPE_LOAD_PLUGIN:
334 content::RecordAction(
335 UserMetricsAction("WebView.Guest.PermissionDeny.PluginLoad"));
336 break;
337 case WEB_VIEW_PERMISSION_TYPE_MEDIA:
338 content::RecordAction(
339 UserMetricsAction("WebView.PermissionDeny.Media"));
340 break;
341 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW:
342 content::RecordAction(
343 UserMetricsAction("BrowserPlugin.PermissionDeny.NewWindow"));
344 break;
345 case WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK:
346 content::RecordAction(
347 UserMetricsAction("WebView.PermissionDeny.PointerLock"));
348 break;
349 default:
350 break;
351 }
352 }
353 }
354
355 // static
356 scoped_ptr<base::ListValue> WebViewGuest::MenuModelToValue( 216 scoped_ptr<base::ListValue> WebViewGuest::MenuModelToValue(
357 const ui::SimpleMenuModel& menu_model) { 217 const ui::SimpleMenuModel& menu_model) {
358 scoped_ptr<base::ListValue> items(new base::ListValue()); 218 scoped_ptr<base::ListValue> items(new base::ListValue());
359 for (int i = 0; i < menu_model.GetItemCount(); ++i) { 219 for (int i = 0; i < menu_model.GetItemCount(); ++i) {
360 base::DictionaryValue* item_value = new base::DictionaryValue(); 220 base::DictionaryValue* item_value = new base::DictionaryValue();
361 // TODO(lazyboy): We need to expose some kind of enum equivalent of 221 // TODO(lazyboy): We need to expose some kind of enum equivalent of
362 // |command_id| instead of plain integers. 222 // |command_id| instead of plain integers.
363 item_value->SetInteger(webview::kMenuItemCommandId, 223 item_value->SetInteger(webview::kMenuItemCommandId,
364 menu_model.GetCommandIdAt(i)); 224 menu_model.GetCommandIdAt(i));
365 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); 225 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i));
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 chromeos::AccessibilityManager::Get(); 346 chromeos::AccessibilityManager::Get();
487 CHECK(accessibility_manager); 347 CHECK(accessibility_manager);
488 accessibility_subscription_ = accessibility_manager->RegisterCallback( 348 accessibility_subscription_ = accessibility_manager->RegisterCallback(
489 base::Bind(&WebViewGuest::OnAccessibilityStatusChanged, 349 base::Bind(&WebViewGuest::OnAccessibilityStatusChanged,
490 base::Unretained(this))); 350 base::Unretained(this)));
491 #endif 351 #endif
492 352
493 AttachWebViewHelpers(guest_web_contents()); 353 AttachWebViewHelpers(guest_web_contents());
494 } 354 }
495 355
356 void WebViewGuest::AttachWebViewHelpers(WebContents* contents) {
357 // Create a zoom controller for the guest contents give it access to
358 // GetZoomLevel() and and SetZoomLevel() in WebViewGuest.
359 // TODO(wjmaclean) This currently uses the same HostZoomMap as the browser
360 // context, but we eventually want to isolate the guest contents from zoom
361 // changes outside the guest (e.g. in the main browser), so we should
362 // create a separate HostZoomMap for the guest.
363 ZoomController::CreateForWebContents(contents);
364
365 FaviconTabHelper::CreateForWebContents(contents);
366 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
367 contents);
368 #if defined(ENABLE_PRINTING)
369 #if defined(ENABLE_FULL_PRINTING)
370 printing::PrintViewManager::CreateForWebContents(contents);
371 printing::PrintPreviewMessageHandler::CreateForWebContents(contents);
372 #else
373 printing::PrintViewManagerBasic::CreateForWebContents(contents);
374 #endif // defined(ENABLE_FULL_PRINTING)
375 #endif // defined(ENABLE_PRINTING)
376 PDFTabHelper::CreateForWebContents(contents);
377 web_view_permission_helper_.reset(new WebViewPermissionHelper(this));
378 }
496 379
497 void WebViewGuest::DidStopLoading() { 380 void WebViewGuest::DidStopLoading() {
498 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 381 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
499 DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); 382 DispatchEventToEmbedder(
383 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass()));
500 } 384 }
501 385
502 void WebViewGuest::EmbedderDestroyed() { 386 void WebViewGuest::EmbedderDestroyed() {
503 // TODO(fsamuel): WebRequest event listeners for <webview> should survive 387 // TODO(fsamuel): WebRequest event listeners for <webview> should survive
504 // reparenting of a <webview> within a single embedder. Right now, we keep 388 // reparenting of a <webview> within a single embedder. Right now, we keep
505 // around the browser state for the listener for the lifetime of the embedder. 389 // around the browser state for the listener for the lifetime of the embedder.
506 // Ideally, the lifetime of the listeners should match the lifetime of the 390 // Ideally, the lifetime of the listeners should match the lifetime of the
507 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move 391 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move
508 // the call to RemoveWebViewEventListenersOnIOThread back to 392 // the call to RemoveWebViewEventListenersOnIOThread back to
509 // WebViewGuest::WebContentsDestroyed. 393 // WebViewGuest::WebContentsDestroyed.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 int32 level, 425 int32 level,
542 const base::string16& message, 426 const base::string16& message,
543 int32 line_no, 427 int32 line_no,
544 const base::string16& source_id) { 428 const base::string16& source_id) {
545 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 429 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
546 // Log levels are from base/logging.h: LogSeverity. 430 // Log levels are from base/logging.h: LogSeverity.
547 args->SetInteger(webview::kLevel, level); 431 args->SetInteger(webview::kLevel, level);
548 args->SetString(webview::kMessage, message); 432 args->SetString(webview::kMessage, message);
549 args->SetInteger(webview::kLine, line_no); 433 args->SetInteger(webview::kLine, line_no);
550 args->SetString(webview::kSourceId, source_id); 434 args->SetString(webview::kSourceId, source_id);
551 DispatchEvent( 435 DispatchEventToEmbedder(
552 new GuestViewBase::Event(webview::kEventConsoleMessage, args.Pass())); 436 new GuestViewBase::Event(webview::kEventConsoleMessage, args.Pass()));
553 return true; 437 return true;
554 } 438 }
555 439
556 void WebViewGuest::CloseContents(WebContents* source) { 440 void WebViewGuest::CloseContents(WebContents* source) {
557 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 441 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
558 DispatchEvent(new GuestViewBase::Event(webview::kEventClose, args.Pass())); 442 DispatchEventToEmbedder(
443 new GuestViewBase::Event(webview::kEventClose, args.Pass()));
559 } 444 }
560 445
561 void WebViewGuest::FindReply(WebContents* source, 446 void WebViewGuest::FindReply(WebContents* source,
562 int request_id, 447 int request_id,
563 int number_of_matches, 448 int number_of_matches,
564 const gfx::Rect& selection_rect, 449 const gfx::Rect& selection_rect,
565 int active_match_ordinal, 450 int active_match_ordinal,
566 bool final_update) { 451 bool final_update) {
567 find_helper_.FindReply(request_id, number_of_matches, selection_rect, 452 find_helper_.FindReply(request_id, number_of_matches, selection_rect,
568 active_match_ordinal, final_update); 453 active_match_ordinal, final_update);
569 } 454 }
570 455
571 bool WebViewGuest::HandleContextMenu( 456 bool WebViewGuest::HandleContextMenu(
572 const content::ContextMenuParams& params) { 457 const content::ContextMenuParams& params) {
573 ContextMenuDelegate* menu_delegate = 458 ContextMenuDelegate* menu_delegate =
574 ContextMenuDelegate::FromWebContents(guest_web_contents()); 459 ContextMenuDelegate::FromWebContents(guest_web_contents());
575 DCHECK(menu_delegate); 460 DCHECK(menu_delegate);
576 461
577 pending_menu_ = menu_delegate->BuildMenu(guest_web_contents(), params); 462 pending_menu_ = menu_delegate->BuildMenu(guest_web_contents(), params);
578 463
579 // Pass it to embedder. 464 // Pass it to embedder.
580 int request_id = ++pending_context_menu_request_id_; 465 int request_id = ++pending_context_menu_request_id_;
581 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 466 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
582 scoped_ptr<base::ListValue> items = 467 scoped_ptr<base::ListValue> items =
583 MenuModelToValue(pending_menu_->menu_model()); 468 MenuModelToValue(pending_menu_->menu_model());
584 args->Set(webview::kContextMenuItems, items.release()); 469 args->Set(webview::kContextMenuItems, items.release());
585 args->SetInteger(webview::kRequestId, request_id); 470 args->SetInteger(webview::kRequestId, request_id);
586 DispatchEvent(new GuestViewBase::Event(webview::kEventContextMenu, 471 DispatchEventToEmbedder(
587 args.Pass())); 472 new GuestViewBase::Event(webview::kEventContextMenu, args.Pass()));
588 return true; 473 return true;
589 } 474 }
590 475
591 void WebViewGuest::HandleKeyboardEvent( 476 void WebViewGuest::HandleKeyboardEvent(
592 WebContents* source, 477 WebContents* source,
593 const content::NativeWebKeyboardEvent& event) { 478 const content::NativeWebKeyboardEvent& event) {
594 if (!attached()) 479 if (!attached())
595 return; 480 return;
596 481
597 if (HandleKeyboardShortcuts(event)) 482 if (HandleKeyboardShortcuts(event))
598 return; 483 return;
599 484
600 // Send the unhandled keyboard events back to the embedder to reprocess them. 485 // Send the unhandled keyboard events back to the embedder to reprocess them.
601 // TODO(fsamuel): This introduces the possibility of out-of-order keyboard 486 // TODO(fsamuel): This introduces the possibility of out-of-order keyboard
602 // events because the guest may be arbitrarily delayed when responding to 487 // events because the guest may be arbitrarily delayed when responding to
603 // keyboard events. In that time, the embedder may have received and processed 488 // keyboard events. In that time, the embedder may have received and processed
604 // additional key events. This needs to be fixed as soon as possible. 489 // additional key events. This needs to be fixed as soon as possible.
605 // See http://crbug.com/229882. 490 // See http://crbug.com/229882.
606 embedder_web_contents()->GetDelegate()->HandleKeyboardEvent( 491 embedder_web_contents()->GetDelegate()->HandleKeyboardEvent(
607 web_contents(), event); 492 web_contents(), event);
608 } 493 }
609 494
610 void WebViewGuest::LoadProgressChanged(content::WebContents* source, 495 void WebViewGuest::LoadProgressChanged(content::WebContents* source,
611 double progress) { 496 double progress) {
612 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 497 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
613 args->SetString(guestview::kUrl, guest_web_contents()->GetURL().spec()); 498 args->SetString(guestview::kUrl, guest_web_contents()->GetURL().spec());
614 args->SetDouble(webview::kProgress, progress); 499 args->SetDouble(webview::kProgress, progress);
615 DispatchEvent( 500 DispatchEventToEmbedder(
616 new GuestViewBase::Event(webview::kEventLoadProgress, args.Pass())); 501 new GuestViewBase::Event(webview::kEventLoadProgress, args.Pass()));
617 } 502 }
618 503
619 void WebViewGuest::LoadAbort(bool is_top_level, 504 void WebViewGuest::LoadAbort(bool is_top_level,
620 const GURL& url, 505 const GURL& url,
621 const std::string& error_type) { 506 const std::string& error_type) {
622 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 507 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
623 args->SetBoolean(guestview::kIsTopLevel, is_top_level); 508 args->SetBoolean(guestview::kIsTopLevel, is_top_level);
624 args->SetString(guestview::kUrl, url.possibly_invalid_spec()); 509 args->SetString(guestview::kUrl, url.possibly_invalid_spec());
625 args->SetString(guestview::kReason, error_type); 510 args->SetString(guestview::kReason, error_type);
626 DispatchEvent( 511 DispatchEventToEmbedder(
627 new GuestViewBase::Event(webview::kEventLoadAbort, args.Pass())); 512 new GuestViewBase::Event(webview::kEventLoadAbort, args.Pass()));
628 } 513 }
629 514
630 void WebViewGuest::OnUpdateFrameName(bool is_top_level, 515 void WebViewGuest::OnUpdateFrameName(bool is_top_level,
631 const std::string& name) { 516 const std::string& name) {
632 if (!is_top_level) 517 if (!is_top_level)
633 return; 518 return;
634 519
635 if (name_ == name) 520 if (name_ == name)
636 return; 521 return;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 params.user_gesture, 560 params.user_gesture,
676 new_guest->guest_web_contents()); 561 new_guest->guest_web_contents());
677 } 562 }
678 563
679 // TODO(fsamuel): Find a reliable way to test the 'responsive' and 564 // TODO(fsamuel): Find a reliable way to test the 'responsive' and
680 // 'unresponsive' events. 565 // 'unresponsive' events.
681 void WebViewGuest::RendererResponsive(content::WebContents* source) { 566 void WebViewGuest::RendererResponsive(content::WebContents* source) {
682 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 567 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
683 args->SetInteger(webview::kProcessId, 568 args->SetInteger(webview::kProcessId,
684 guest_web_contents()->GetRenderProcessHost()->GetID()); 569 guest_web_contents()->GetRenderProcessHost()->GetID());
685 DispatchEvent( 570 DispatchEventToEmbedder(
686 new GuestViewBase::Event(webview::kEventResponsive, args.Pass())); 571 new GuestViewBase::Event(webview::kEventResponsive, args.Pass()));
687 } 572 }
688 573
689 void WebViewGuest::RendererUnresponsive(content::WebContents* source) { 574 void WebViewGuest::RendererUnresponsive(content::WebContents* source) {
690 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 575 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
691 args->SetInteger(webview::kProcessId, 576 args->SetInteger(webview::kProcessId,
692 guest_web_contents()->GetRenderProcessHost()->GetID()); 577 guest_web_contents()->GetRenderProcessHost()->GetID());
693 DispatchEvent( 578 DispatchEventToEmbedder(
694 new GuestViewBase::Event(webview::kEventUnresponsive, args.Pass())); 579 new GuestViewBase::Event(webview::kEventUnresponsive, args.Pass()));
695 } 580 }
696 581
697 void WebViewGuest::Observe(int type, 582 void WebViewGuest::Observe(int type,
698 const content::NotificationSource& source, 583 const content::NotificationSource& source,
699 const content::NotificationDetails& details) { 584 const content::NotificationDetails& details) {
700 switch (type) { 585 switch (type) {
701 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: { 586 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: {
702 DCHECK_EQ(content::Source<WebContents>(source).ptr(), 587 DCHECK_EQ(content::Source<WebContents>(source).ptr(),
703 guest_web_contents()); 588 guest_web_contents());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 guest_web_contents()->GetController().GoToOffset(relative_index); 628 guest_web_contents()->GetController().GoToOffset(relative_index);
744 } 629 }
745 630
746 void WebViewGuest::Reload() { 631 void WebViewGuest::Reload() {
747 // TODO(fsamuel): Don't check for repost because we don't want to show 632 // TODO(fsamuel): Don't check for repost because we don't want to show
748 // Chromium's repost warning. We might want to implement a separate API 633 // Chromium's repost warning. We might want to implement a separate API
749 // for registering a callback if a repost is about to happen. 634 // for registering a callback if a repost is about to happen.
750 guest_web_contents()->GetController().Reload(false); 635 guest_web_contents()->GetController().Reload(false);
751 } 636 }
752 637
753 void WebViewGuest::RequestFileSystemPermission(
754 const GURL& url,
755 bool allowed_by_default,
756 const base::Callback<void(bool)>& callback) {
757 base::DictionaryValue request_info;
758 request_info.Set(guestview::kUrl, new base::StringValue(url.spec()));
759 RequestPermission(
760 WEB_VIEW_PERMISSION_TYPE_FILESYSTEM,
761 request_info,
762 base::Bind(&WebViewGuest::OnWebViewFileSystemPermissionResponse,
763 base::Unretained(this),
764 callback),
765 allowed_by_default);
766 }
767
768 void WebViewGuest::OnWebViewFileSystemPermissionResponse(
769 const base::Callback<void(bool)>& callback,
770 bool allow,
771 const std::string& user_input) {
772 callback.Run(allow && attached());
773 }
774
775 void WebViewGuest::RequestGeolocationPermission(
776 int bridge_id,
777 const GURL& requesting_frame,
778 bool user_gesture,
779 const base::Callback<void(bool)>& callback) {
780 base::DictionaryValue request_info;
781 request_info.Set(guestview::kUrl,
782 new base::StringValue(requesting_frame.spec()));
783 request_info.Set(guestview::kUserGesture,
784 base::Value::CreateBooleanValue(user_gesture));
785
786 // It is safe to hold an unretained pointer to WebViewGuest because this
787 // callback is called from WebViewGuest::SetPermission.
788 const PermissionResponseCallback permission_callback =
789 base::Bind(&WebViewGuest::OnWebViewGeolocationPermissionResponse,
790 base::Unretained(this),
791 bridge_id,
792 user_gesture,
793 callback);
794 int request_id = RequestPermission(
795 WEB_VIEW_PERMISSION_TYPE_GEOLOCATION,
796 request_info,
797 permission_callback,
798 false /* allowed_by_default */);
799 bridge_id_to_request_id_map_[bridge_id] = request_id;
800 }
801
802 void WebViewGuest::OnWebViewGeolocationPermissionResponse(
803 int bridge_id,
804 bool user_gesture,
805 const base::Callback<void(bool)>& callback,
806 bool allow,
807 const std::string& user_input) {
808 // The <webview> embedder has allowed the permission. We now need to make sure
809 // that the embedder has geolocation permission.
810 RemoveBridgeID(bridge_id);
811
812 if (!allow || !attached()) {
813 callback.Run(false);
814 return;
815 }
816
817 Profile* profile = Profile::FromBrowserContext(browser_context());
818 GeolocationPermissionContextFactory::GetForProfile(profile)->
819 RequestGeolocationPermission(
820 embedder_web_contents(),
821 // The geolocation permission request here is not initiated
822 // through WebGeolocationPermissionRequest. We are only interested
823 // in the fact whether the embedder/app has geolocation
824 // permission. Therefore we use an invalid |bridge_id|.
825 -1,
826 embedder_web_contents()->GetLastCommittedURL(),
827 user_gesture,
828 callback,
829 NULL);
830 }
831
832 void WebViewGuest::CancelGeolocationPermissionRequest(int bridge_id) {
833 int request_id = RemoveBridgeID(bridge_id);
834 RequestMap::iterator request_itr =
835 pending_permission_requests_.find(request_id);
836
837 if (request_itr == pending_permission_requests_.end())
838 return;
839
840 pending_permission_requests_.erase(request_itr);
841 }
842
843 void WebViewGuest::OnWebViewMediaPermissionResponse(
844 const content::MediaStreamRequest& request,
845 const content::MediaResponseCallback& callback,
846 bool allow,
847 const std::string& user_input) {
848 if (!allow || !attached()) {
849 // Deny the request.
850 callback.Run(content::MediaStreamDevices(),
851 content::MEDIA_DEVICE_INVALID_STATE,
852 scoped_ptr<content::MediaStreamUI>());
853 return;
854 }
855 if (!embedder_web_contents()->GetDelegate())
856 return;
857
858 embedder_web_contents()->GetDelegate()->
859 RequestMediaAccessPermission(embedder_web_contents(), request, callback);
860 }
861
862 void WebViewGuest::OnWebViewDownloadPermissionResponse(
863 const base::Callback<void(bool)>& callback,
864 bool allow,
865 const std::string& user_input) {
866 callback.Run(allow && attached());
867 }
868
869 void WebViewGuest::OnWebViewPointerLockPermissionResponse(
870 const base::Callback<void(bool)>& callback,
871 bool allow,
872 const std::string& user_input) {
873 callback.Run(allow && attached());
874 }
875
876 WebViewGuest::SetPermissionResult WebViewGuest::SetPermission(
877 int request_id,
878 PermissionResponseAction action,
879 const std::string& user_input) {
880 RequestMap::iterator request_itr =
881 pending_permission_requests_.find(request_id);
882
883 if (request_itr == pending_permission_requests_.end())
884 return SET_PERMISSION_INVALID;
885
886 const PermissionResponseInfo& info = request_itr->second;
887 bool allow = (action == ALLOW) ||
888 ((action == DEFAULT) && info.allowed_by_default);
889
890 info.callback.Run(allow, user_input);
891
892 // Only record user initiated (i.e. non-default) actions.
893 if (action != DEFAULT)
894 RecordUserInitiatedUMA(info, allow);
895
896 pending_permission_requests_.erase(request_itr);
897
898 return allow ? SET_PERMISSION_ALLOWED : SET_PERMISSION_DENIED;
899 }
900
901 void WebViewGuest::SetUserAgentOverride( 638 void WebViewGuest::SetUserAgentOverride(
902 const std::string& user_agent_override) { 639 const std::string& user_agent_override) {
903 if (!attached()) 640 if (!attached())
904 return; 641 return;
905 is_overriding_user_agent_ = !user_agent_override.empty(); 642 is_overriding_user_agent_ = !user_agent_override.empty();
906 if (is_overriding_user_agent_) { 643 if (is_overriding_user_agent_) {
907 content::RecordAction(UserMetricsAction("WebView.Guest.OverrideUA")); 644 content::RecordAction(UserMetricsAction("WebView.Guest.OverrideUA"));
908 } 645 }
909 guest_web_contents()->SetUserAgentOverride(user_agent_override); 646 guest_web_contents()->SetUserAgentOverride(user_agent_override);
910 } 647 }
(...skipping 26 matching lines...) Expand all
937 removal_mask, 674 removal_mask,
938 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL, 675 content::StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL,
939 GURL(), 676 GURL(),
940 content::StoragePartition::OriginMatcherFunction(), 677 content::StoragePartition::OriginMatcherFunction(),
941 remove_since, 678 remove_since,
942 base::Time::Now(), 679 base::Time::Now(),
943 callback); 680 callback);
944 return true; 681 return true;
945 } 682 }
946 683
947 // static
948 void WebViewGuest::FileSystemAccessedAsync(int render_process_id,
949 int render_frame_id,
950 int request_id,
951 const GURL& url,
952 bool blocked_by_policy) {
953 WebViewGuest* guest =
954 WebViewGuest::FromFrameID(render_process_id, render_frame_id);
955 DCHECK(guest);
956 guest->RequestFileSystemPermission(
957 url,
958 !blocked_by_policy,
959 base::Bind(&WebViewGuest::FileSystemAccessedAsyncResponse,
960 render_process_id,
961 render_frame_id,
962 request_id,
963 url));
964 }
965
966 // static
967 void WebViewGuest::FileSystemAccessedAsyncResponse(int render_process_id,
968 int render_frame_id,
969 int request_id,
970 const GURL& url,
971 bool allowed) {
972 TabSpecificContentSettings::FileSystemAccessed(
973 render_process_id, render_frame_id, url, !allowed);
974 content::RenderFrameHost* render_frame_host =
975 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
976 if (!render_frame_host)
977 return;
978 render_frame_host->Send(
979 new ChromeViewMsg_RequestFileSystemAccessAsyncResponse(
980 render_frame_id, request_id, allowed));
981 }
982
983 // static
984 void WebViewGuest::FileSystemAccessedSync(int render_process_id,
985 int render_frame_id,
986 const GURL& url,
987 bool blocked_by_policy,
988 IPC::Message* reply_msg) {
989 WebViewGuest* guest =
990 WebViewGuest::FromFrameID(render_process_id, render_frame_id);
991 DCHECK(guest);
992 guest->RequestFileSystemPermission(
993 url,
994 !blocked_by_policy,
995 base::Bind(&WebViewGuest::FileSystemAccessedSyncResponse,
996 render_process_id,
997 render_frame_id,
998 url,
999 reply_msg));
1000 }
1001
1002 // static
1003 void WebViewGuest::FileSystemAccessedSyncResponse(int render_process_id,
1004 int render_frame_id,
1005 const GURL& url,
1006 IPC::Message* reply_msg,
1007 bool allowed) {
1008 TabSpecificContentSettings::FileSystemAccessed(
1009 render_process_id, render_frame_id, url, !allowed);
1010 ChromeViewHostMsg_RequestFileSystemAccessSync::WriteReplyParams(reply_msg,
1011 allowed);
1012 content::RenderFrameHost* render_frame_host =
1013 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
1014 if (!render_frame_id)
1015 return;
1016 render_frame_host->Send(reply_msg);
1017 }
1018
1019 WebViewGuest::~WebViewGuest() { 684 WebViewGuest::~WebViewGuest() {
1020 } 685 }
1021 686
1022 void WebViewGuest::DidCommitProvisionalLoadForFrame( 687 void WebViewGuest::DidCommitProvisionalLoadForFrame(
1023 content::RenderFrameHost* render_frame_host, 688 content::RenderFrameHost* render_frame_host,
1024 const GURL& url, 689 const GURL& url,
1025 content::PageTransition transition_type) { 690 content::PageTransition transition_type) {
1026 find_helper_.CancelAllFindSessions(); 691 find_helper_.CancelAllFindSessions();
1027 692
1028 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 693 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1029 args->SetString(guestview::kUrl, url.spec()); 694 args->SetString(guestview::kUrl, url.spec());
1030 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); 695 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent());
1031 args->SetInteger(webview::kInternalCurrentEntryIndex, 696 args->SetInteger(webview::kInternalCurrentEntryIndex,
1032 guest_web_contents()->GetController().GetCurrentEntryIndex()); 697 guest_web_contents()->GetController().GetCurrentEntryIndex());
1033 args->SetInteger(webview::kInternalEntryCount, 698 args->SetInteger(webview::kInternalEntryCount,
1034 guest_web_contents()->GetController().GetEntryCount()); 699 guest_web_contents()->GetController().GetEntryCount());
1035 args->SetInteger(webview::kInternalProcessId, 700 args->SetInteger(webview::kInternalProcessId,
1036 guest_web_contents()->GetRenderProcessHost()->GetID()); 701 guest_web_contents()->GetRenderProcessHost()->GetID());
1037 DispatchEvent( 702 DispatchEventToEmbedder(
1038 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); 703 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass()));
1039 704
1040 // Update the current zoom factor for the new page. 705 // Update the current zoom factor for the new page.
1041 ZoomController* zoom_controller = 706 ZoomController* zoom_controller =
1042 ZoomController::FromWebContents(guest_web_contents()); 707 ZoomController::FromWebContents(guest_web_contents());
1043 DCHECK(zoom_controller); 708 DCHECK(zoom_controller);
1044 current_zoom_factor_ = zoom_controller->GetZoomLevel(); 709 current_zoom_factor_ = zoom_controller->GetZoomLevel();
1045 710
1046 if (!render_frame_host->GetParent()) { 711 if (!render_frame_host->GetParent()) {
1047 chromevox_injected_ = false; 712 chromevox_injected_ = false;
(...skipping 14 matching lines...) Expand all
1062 } 727 }
1063 728
1064 void WebViewGuest::DidStartProvisionalLoadForFrame( 729 void WebViewGuest::DidStartProvisionalLoadForFrame(
1065 content::RenderFrameHost* render_frame_host, 730 content::RenderFrameHost* render_frame_host,
1066 const GURL& validated_url, 731 const GURL& validated_url,
1067 bool is_error_page, 732 bool is_error_page,
1068 bool is_iframe_srcdoc) { 733 bool is_iframe_srcdoc) {
1069 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 734 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1070 args->SetString(guestview::kUrl, validated_url.spec()); 735 args->SetString(guestview::kUrl, validated_url.spec());
1071 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); 736 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent());
1072 DispatchEvent( 737 DispatchEventToEmbedder(
1073 new GuestViewBase::Event(webview::kEventLoadStart, args.Pass())); 738 new GuestViewBase::Event(webview::kEventLoadStart, args.Pass()));
1074 } 739 }
1075 740
1076 void WebViewGuest::DocumentLoadedInFrame( 741 void WebViewGuest::DocumentLoadedInFrame(
1077 int64 frame_id, 742 int64 frame_id,
1078 content::RenderViewHost* render_view_host) { 743 content::RenderViewHost* render_view_host) {
1079 if (frame_id == main_frame_id_) 744 if (frame_id == main_frame_id_)
1080 InjectChromeVoxIfNeeded(render_view_host); 745 InjectChromeVoxIfNeeded(render_view_host);
1081 } 746 }
1082 747
1083 bool WebViewGuest::OnMessageReceived(const IPC::Message& message, 748 bool WebViewGuest::OnMessageReceived(const IPC::Message& message,
1084 RenderFrameHost* render_frame_host) { 749 RenderFrameHost* render_frame_host) {
1085 bool handled = true; 750 bool handled = true;
1086 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message) 751 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message)
1087 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_UpdateFrameName, OnUpdateFrameName) 752 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_UpdateFrameName, OnUpdateFrameName)
1088 IPC_MESSAGE_UNHANDLED(handled = false) 753 IPC_MESSAGE_UNHANDLED(handled = false)
1089 IPC_END_MESSAGE_MAP() 754 IPC_END_MESSAGE_MAP()
1090 return handled; 755 return handled;
1091 } 756 }
1092 757
1093 void WebViewGuest::RenderProcessGone(base::TerminationStatus status) { 758 void WebViewGuest::RenderProcessGone(base::TerminationStatus status) {
1094 // Cancel all find sessions in progress. 759 // Cancel all find sessions in progress.
1095 find_helper_.CancelAllFindSessions(); 760 find_helper_.CancelAllFindSessions();
1096 761
1097 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 762 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1098 args->SetInteger(webview::kProcessId, 763 args->SetInteger(webview::kProcessId,
1099 guest_web_contents()->GetRenderProcessHost()->GetID()); 764 guest_web_contents()->GetRenderProcessHost()->GetID());
1100 args->SetString(webview::kReason, TerminationStatusToString(status)); 765 args->SetString(webview::kReason, TerminationStatusToString(status));
1101 DispatchEvent(new GuestViewBase::Event(webview::kEventExit, args.Pass())); 766 DispatchEventToEmbedder(
767 new GuestViewBase::Event(webview::kEventExit, args.Pass()));
1102 } 768 }
1103 769
1104 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { 770 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) {
1105 if (!attached()) 771 if (!attached())
1106 return; 772 return;
1107 content::NavigationController& controller = 773 content::NavigationController& controller =
1108 guest_web_contents()->GetController(); 774 guest_web_contents()->GetController();
1109 content::NavigationEntry* entry = controller.GetVisibleEntry(); 775 content::NavigationEntry* entry = controller.GetVisibleEntry();
1110 if (!entry) 776 if (!entry)
1111 return; 777 return;
1112 entry->SetIsOverridingUserAgent(!user_agent.empty()); 778 entry->SetIsOverridingUserAgent(!user_agent.empty());
1113 guest_web_contents()->GetController().Reload(false); 779 guest_web_contents()->GetController().Reload(false);
1114 } 780 }
1115 781
1116 void WebViewGuest::RenderViewReady() { 782 void WebViewGuest::RenderViewReady() {
1117 // The guest RenderView should always live in an isolated guest process. 783 // The guest RenderView should always live in an isolated guest process.
1118 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); 784 CHECK(guest_web_contents()->GetRenderProcessHost()->IsIsolatedGuest());
1119 Send(new ChromeViewMsg_SetName(guest_web_contents()->GetRoutingID(), name_)); 785 Send(new ChromeViewMsg_SetName(guest_web_contents()->GetRoutingID(), name_));
1120 } 786 }
1121 787
1122 void WebViewGuest::ReportFrameNameChange(const std::string& name) { 788 void WebViewGuest::ReportFrameNameChange(const std::string& name) {
1123 name_ = name; 789 name_ = name;
1124 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 790 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1125 args->SetString(webview::kName, name); 791 args->SetString(webview::kName, name);
1126 DispatchEvent( 792 DispatchEventToEmbedder(
1127 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); 793 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass()));
1128 } 794 }
1129 795
1130 void WebViewGuest::LoadHandlerCalled() { 796 void WebViewGuest::LoadHandlerCalled() {
1131 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 797 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1132 DispatchEvent( 798 DispatchEventToEmbedder(
1133 new GuestViewBase::Event(webview::kEventContentLoad, args.Pass())); 799 new GuestViewBase::Event(webview::kEventContentLoad, args.Pass()));
1134 } 800 }
1135 801
1136 void WebViewGuest::LoadRedirect(const GURL& old_url, 802 void WebViewGuest::LoadRedirect(const GURL& old_url,
1137 const GURL& new_url, 803 const GURL& new_url,
1138 bool is_top_level) { 804 bool is_top_level) {
1139 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 805 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1140 args->SetBoolean(guestview::kIsTopLevel, is_top_level); 806 args->SetBoolean(guestview::kIsTopLevel, is_top_level);
1141 args->SetString(webview::kNewURL, new_url.spec()); 807 args->SetString(webview::kNewURL, new_url.spec());
1142 args->SetString(webview::kOldURL, old_url.spec()); 808 args->SetString(webview::kOldURL, old_url.spec());
1143 DispatchEvent( 809 DispatchEventToEmbedder(
1144 new GuestViewBase::Event(webview::kEventLoadRedirect, args.Pass())); 810 new GuestViewBase::Event(webview::kEventLoadRedirect, args.Pass()));
1145 } 811 }
1146 812
1147 void WebViewGuest::PushWebViewStateToIOThread() { 813 void WebViewGuest::PushWebViewStateToIOThread() {
1148 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); 814 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL();
1149 std::string partition_domain; 815 std::string partition_domain;
1150 std::string partition_id; 816 std::string partition_id;
1151 bool in_memory; 817 bool in_memory;
1152 if (!GetGuestPartitionConfigForSite( 818 if (!GetGuestPartitionConfigForSite(
1153 site_url, &partition_domain, &partition_id, &in_memory)) { 819 site_url, &partition_domain, &partition_id, &in_memory)) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 create_params); 861 create_params);
1196 } 862 }
1197 863
1198 void WebViewGuest::SizeChanged(const gfx::Size& old_size, 864 void WebViewGuest::SizeChanged(const gfx::Size& old_size,
1199 const gfx::Size& new_size) { 865 const gfx::Size& new_size) {
1200 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 866 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1201 args->SetInteger(webview::kOldHeight, old_size.height()); 867 args->SetInteger(webview::kOldHeight, old_size.height());
1202 args->SetInteger(webview::kOldWidth, old_size.width()); 868 args->SetInteger(webview::kOldWidth, old_size.width());
1203 args->SetInteger(webview::kNewHeight, new_size.height()); 869 args->SetInteger(webview::kNewHeight, new_size.height());
1204 args->SetInteger(webview::kNewWidth, new_size.width()); 870 args->SetInteger(webview::kNewWidth, new_size.width());
1205 DispatchEvent( 871 DispatchEventToEmbedder(
1206 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); 872 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass()));
1207 } 873 }
1208 874
1209 void WebViewGuest::RequestMediaAccessPermission( 875 void WebViewGuest::RequestMediaAccessPermission(
1210 content::WebContents* source, 876 content::WebContents* source,
1211 const content::MediaStreamRequest& request, 877 const content::MediaStreamRequest& request,
1212 const content::MediaResponseCallback& callback) { 878 const content::MediaResponseCallback& callback) {
1213 base::DictionaryValue request_info; 879 web_view_permission_helper_->RequestMediaAccessPermission(source,
1214 request_info.Set(guestview::kUrl, 880 request,
1215 new base::StringValue(request.security_origin.spec())); 881 callback);
1216 RequestPermission(WEB_VIEW_PERMISSION_TYPE_MEDIA,
1217 request_info,
1218 base::Bind(&WebViewGuest::OnWebViewMediaPermissionResponse,
1219 base::Unretained(this),
1220 request,
1221 callback),
1222 false /* allowed_by_default */);
1223 } 882 }
1224 883
1225 void WebViewGuest::CanDownload( 884 void WebViewGuest::CanDownload(
1226 content::RenderViewHost* render_view_host, 885 content::RenderViewHost* render_view_host,
1227 const GURL& url, 886 const GURL& url,
1228 const std::string& request_method, 887 const std::string& request_method,
1229 const base::Callback<void(bool)>& callback) { 888 const base::Callback<void(bool)>& callback) {
1230 base::DictionaryValue request_info; 889 web_view_permission_helper_->CanDownload(render_view_host,
1231 request_info.Set(guestview::kUrl, new base::StringValue(url.spec())); 890 url,
1232 RequestPermission( 891 request_method,
1233 WEB_VIEW_PERMISSION_TYPE_DOWNLOAD, 892 callback);
1234 request_info,
1235 base::Bind(&WebViewGuest::OnWebViewDownloadPermissionResponse,
1236 base::Unretained(this),
1237 callback),
1238 false /* allowed_by_default */);
1239 } 893 }
1240 894
1241 void WebViewGuest::RequestPointerLockPermission( 895 void WebViewGuest::RequestPointerLockPermission(
1242 bool user_gesture, 896 bool user_gesture,
1243 bool last_unlocked_by_target, 897 bool last_unlocked_by_target,
1244 const base::Callback<void(bool)>& callback) { 898 const base::Callback<void(bool)>& callback) {
1245 base::DictionaryValue request_info; 899 web_view_permission_helper_->RequestPointerLockPermission(
1246 request_info.Set(guestview::kUserGesture, 900 user_gesture,
1247 base::Value::CreateBooleanValue(user_gesture)); 901 last_unlocked_by_target,
1248 request_info.Set(webview::kLastUnlockedBySelf, 902 callback);
1249 base::Value::CreateBooleanValue(last_unlocked_by_target));
1250 request_info.Set(guestview::kUrl,
1251 new base::StringValue(
1252 guest_web_contents()->GetLastCommittedURL().spec()));
1253
1254 RequestPermission(
1255 WEB_VIEW_PERMISSION_TYPE_POINTER_LOCK,
1256 request_info,
1257 base::Bind(&WebViewGuest::OnWebViewPointerLockPermissionResponse,
1258 base::Unretained(this),
1259 callback),
1260 false /* allowed_by_default */);
1261 } 903 }
1262 904
1263 void WebViewGuest::WillAttachToEmbedder() { 905 void WebViewGuest::WillAttachToEmbedder() {
1264 // We must install the mapping from guests to WebViews prior to resuming 906 // We must install the mapping from guests to WebViews prior to resuming
1265 // suspended resource loads so that the WebRequest API will catch resource 907 // suspended resource loads so that the WebRequest API will catch resource
1266 // requests. 908 // requests.
1267 PushWebViewStateToIOThread(); 909 PushWebViewStateToIOThread();
1268 } 910 }
1269 911
1270 content::JavaScriptDialogManager* 912 content::JavaScriptDialogManager*
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 chromeos::AccessibilityManager* manager = 986 chromeos::AccessibilityManager* manager =
1345 chromeos::AccessibilityManager::Get(); 987 chromeos::AccessibilityManager::Get();
1346 if (manager && manager->IsSpokenFeedbackEnabled()) { 988 if (manager && manager->IsSpokenFeedbackEnabled()) {
1347 manager->InjectChromeVox(render_view_host); 989 manager->InjectChromeVox(render_view_host);
1348 chromevox_injected_ = true; 990 chromevox_injected_ = true;
1349 } 991 }
1350 } 992 }
1351 #endif 993 #endif
1352 } 994 }
1353 995
1354 int WebViewGuest::RemoveBridgeID(int bridge_id) {
1355 std::map<int, int>::iterator bridge_itr =
1356 bridge_id_to_request_id_map_.find(bridge_id);
1357 if (bridge_itr == bridge_id_to_request_id_map_.end())
1358 return webview::kInvalidPermissionRequestID;
1359
1360 int request_id = bridge_itr->second;
1361 bridge_id_to_request_id_map_.erase(bridge_itr);
1362 return request_id;
1363 }
1364
1365 int WebViewGuest::RequestPermission(
1366 WebViewPermissionType permission_type,
1367 const base::DictionaryValue& request_info,
1368 const PermissionResponseCallback& callback,
1369 bool allowed_by_default) {
1370 // If there are too many pending permission requests then reject this request.
1371 if (pending_permission_requests_.size() >=
1372 webview::kMaxOutstandingPermissionRequests) {
1373 // Let the stack unwind before we deny the permission request so that
1374 // objects held by the permission request are not destroyed immediately
1375 // after creation. This is to allow those same objects to be accessed again
1376 // in the same scope without fear of use after freeing.
1377 base::MessageLoop::current()->PostTask(
1378 FROM_HERE,
1379 base::Bind(&PermissionResponseCallback::Run,
1380 base::Owned(new PermissionResponseCallback(callback)),
1381 allowed_by_default,
1382 std::string()));
1383 return webview::kInvalidPermissionRequestID;
1384 }
1385
1386 int request_id = next_permission_request_id_++;
1387 pending_permission_requests_[request_id] =
1388 PermissionResponseInfo(callback, permission_type, allowed_by_default);
1389 scoped_ptr<base::DictionaryValue> args(request_info.DeepCopy());
1390 args->SetInteger(webview::kRequestId, request_id);
1391 switch (permission_type) {
1392 case WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW: {
1393 DispatchEvent(
1394 new GuestViewBase::Event(webview::kEventNewWindow, args.Pass()));
1395 break;
1396 }
1397 case WEB_VIEW_PERMISSION_TYPE_JAVASCRIPT_DIALOG: {
1398 DispatchEvent(
1399 new GuestViewBase::Event(webview::kEventDialog, args.Pass()));
1400 break;
1401 }
1402 default: {
1403 args->SetString(webview::kPermission,
1404 PermissionTypeToString(permission_type));
1405 DispatchEvent(new GuestViewBase::Event(webview::kEventPermissionRequest,
1406 args.Pass()));
1407 break;
1408 }
1409 }
1410 return request_id;
1411 }
1412
1413 bool WebViewGuest::HandleKeyboardShortcuts( 996 bool WebViewGuest::HandleKeyboardShortcuts(
1414 const content::NativeWebKeyboardEvent& event) { 997 const content::NativeWebKeyboardEvent& event) {
1415 if (event.type != blink::WebInputEvent::RawKeyDown) 998 if (event.type != blink::WebInputEvent::RawKeyDown)
1416 return false; 999 return false;
1417 1000
1418 // If the user hits the escape key without any modifiers then unlock the 1001 // If the user hits the escape key without any modifiers then unlock the
1419 // mouse if necessary. 1002 // mouse if necessary.
1420 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) && 1003 if ((event.windowsKeyCode == ui::VKEY_ESCAPE) &&
1421 !(event.modifiers & blink::WebInputEvent::InputModifiers)) { 1004 !(event.modifiers & blink::WebInputEvent::InputModifiers)) {
1422 return guest_web_contents()->GotResponseToLockMouseRequest(false); 1005 return guest_web_contents()->GotResponseToLockMouseRequest(false);
(...skipping 20 matching lines...) Expand all
1443 1026
1444 if (event.windowsKeyCode == ui::VKEY_BROWSER_FORWARD) { 1027 if (event.windowsKeyCode == ui::VKEY_BROWSER_FORWARD) {
1445 Go(1); 1028 Go(1);
1446 return true; 1029 return true;
1447 } 1030 }
1448 #endif 1031 #endif
1449 1032
1450 return false; 1033 return false;
1451 } 1034 }
1452 1035
1453 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo()
1454 : permission_type(WEB_VIEW_PERMISSION_TYPE_UNKNOWN),
1455 allowed_by_default(false) {
1456 }
1457
1458 WebViewGuest::PermissionResponseInfo::PermissionResponseInfo(
1459 const PermissionResponseCallback& callback,
1460 WebViewPermissionType permission_type,
1461 bool allowed_by_default)
1462 : callback(callback),
1463 permission_type(permission_type),
1464 allowed_by_default(allowed_by_default) {
1465 }
1466
1467 WebViewGuest::PermissionResponseInfo::~PermissionResponseInfo() {
1468 }
1469
1470 void WebViewGuest::ShowContextMenu(int request_id, 1036 void WebViewGuest::ShowContextMenu(int request_id,
1471 const MenuItemVector* items) { 1037 const MenuItemVector* items) {
1472 if (!pending_menu_.get()) 1038 if (!pending_menu_.get())
1473 return; 1039 return;
1474 1040
1475 // Make sure this was the correct request. 1041 // Make sure this was the correct request.
1476 if (request_id != pending_context_menu_request_id_) 1042 if (request_id != pending_context_menu_request_id_)
1477 return; 1043 return;
1478 1044
1479 // TODO(lazyboy): Implement. 1045 // TODO(lazyboy): Implement.
(...skipping 15 matching lines...) Expand all
1495 void WebViewGuest::SetZoom(double zoom_factor) { 1061 void WebViewGuest::SetZoom(double zoom_factor) {
1496 ZoomController* zoom_controller = 1062 ZoomController* zoom_controller =
1497 ZoomController::FromWebContents(guest_web_contents()); 1063 ZoomController::FromWebContents(guest_web_contents());
1498 DCHECK(zoom_controller); 1064 DCHECK(zoom_controller);
1499 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); 1065 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor);
1500 zoom_controller->SetZoomLevel(zoom_level); 1066 zoom_controller->SetZoomLevel(zoom_level);
1501 1067
1502 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 1068 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1503 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); 1069 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_);
1504 args->SetDouble(webview::kNewZoomFactor, zoom_factor); 1070 args->SetDouble(webview::kNewZoomFactor, zoom_factor);
1505 DispatchEvent( 1071 DispatchEventToEmbedder(
1506 new GuestViewBase::Event(webview::kEventZoomChange, args.Pass())); 1072 new GuestViewBase::Event(webview::kEventZoomChange, args.Pass()));
1507 1073
1508 current_zoom_factor_ = zoom_factor; 1074 current_zoom_factor_ = zoom_factor;
1509 } 1075 }
1510 1076
1511 void WebViewGuest::AddNewContents(content::WebContents* source, 1077 void WebViewGuest::AddNewContents(content::WebContents* source,
1512 content::WebContents* new_contents, 1078 content::WebContents* new_contents,
1513 WindowOpenDisposition disposition, 1079 WindowOpenDisposition disposition,
1514 const gfx::Rect& initial_pos, 1080 const gfx::Rect& initial_pos,
1515 bool user_gesture, 1081 bool user_gesture,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 base::Value::CreateIntegerValue( 1176 base::Value::CreateIntegerValue(
1611 guest->GetGuestInstanceID())); 1177 guest->GetGuestInstanceID()));
1612 // We pass in partition info so that window-s created through newwindow 1178 // We pass in partition info so that window-s created through newwindow
1613 // API can use it to set their partition attribute. 1179 // API can use it to set their partition attribute.
1614 request_info.Set(webview::kStoragePartitionId, 1180 request_info.Set(webview::kStoragePartitionId,
1615 new base::StringValue(storage_partition_id)); 1181 new base::StringValue(storage_partition_id));
1616 request_info.Set( 1182 request_info.Set(
1617 webview::kWindowOpenDisposition, 1183 webview::kWindowOpenDisposition,
1618 new base::StringValue(WindowOpenDispositionToString(disposition))); 1184 new base::StringValue(WindowOpenDispositionToString(disposition)));
1619 1185
1620 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW, 1186 web_view_permission_helper_->
1621 request_info, 1187 RequestPermission(WEB_VIEW_PERMISSION_TYPE_NEW_WINDOW,
1622 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse, 1188 request_info,
1623 base::Unretained(this), 1189 base::Bind(&WebViewGuest::OnWebViewNewWindowResponse,
1624 guest->GetGuestInstanceID()), 1190 base::Unretained(this),
1625 false /* allowed_by_default */); 1191 guest->GetGuestInstanceID()),
1192 false /* allowed_by_default */);
1626 } 1193 }
1627 1194
1628 void WebViewGuest::DestroyUnattachedWindows() { 1195 void WebViewGuest::DestroyUnattachedWindows() {
1629 // Destroy() reaches in and removes the WebViewGuest from its opener's 1196 // Destroy() reaches in and removes the WebViewGuest from its opener's
1630 // pending_new_windows_ set. To avoid mutating the set while iterating, we 1197 // pending_new_windows_ set. To avoid mutating the set while iterating, we
1631 // create a copy of the pending new windows set and iterate over the copy. 1198 // create a copy of the pending new windows set and iterate over the copy.
1632 PendingWindowMap pending_new_windows(pending_new_windows_); 1199 PendingWindowMap pending_new_windows(pending_new_windows_);
1633 // Clean up unattached new windows opened by this guest. 1200 // Clean up unattached new windows opened by this guest.
1634 for (PendingWindowMap::const_iterator it = pending_new_windows.begin(); 1201 for (PendingWindowMap::const_iterator it = pending_new_windows.begin();
1635 it != pending_new_windows.end(); ++it) { 1202 it != pending_new_windows.end(); ++it) {
(...skipping 21 matching lines...) Expand all
1657 bool allow, 1224 bool allow,
1658 const std::string& user_input) { 1225 const std::string& user_input) {
1659 WebViewGuest* guest = 1226 WebViewGuest* guest =
1660 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); 1227 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id);
1661 if (!guest) 1228 if (!guest)
1662 return; 1229 return;
1663 1230
1664 if (!allow) 1231 if (!allow)
1665 guest->Destroy(); 1232 guest->Destroy();
1666 } 1233 }
OLDNEW
« no previous file with comments | « chrome/browser/guest_view/web_view/web_view_guest.h ('k') | chrome/browser/guest_view/web_view/web_view_permission_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698