OLD | NEW |
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/debug/stack_trace.h" | 7 #include "base/debug/stack_trace.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 348 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
349 scoped_ptr<base::ListValue> items = | 349 scoped_ptr<base::ListValue> items = |
350 MenuModelToValue(pending_menu_->menu_model()); | 350 MenuModelToValue(pending_menu_->menu_model()); |
351 args->Set(webview::kContextMenuItems, items.release()); | 351 args->Set(webview::kContextMenuItems, items.release()); |
352 args->SetInteger(webview::kRequestId, request_id); | 352 args->SetInteger(webview::kRequestId, request_id); |
353 DispatchEvent(new GuestViewBase::Event(webview::kEventContextMenu, | 353 DispatchEvent(new GuestViewBase::Event(webview::kEventContextMenu, |
354 args.Pass())); | 354 args.Pass())); |
355 return true; | 355 return true; |
356 } | 356 } |
357 | 357 |
358 void WebViewGuest::AddMessageToConsole(int32 level, | 358 bool WebViewGuest::AddMessageToConsole(WebContents* source, |
| 359 int32 level, |
359 const base::string16& message, | 360 const base::string16& message, |
360 int32 line_no, | 361 int32 line_no, |
361 const base::string16& source_id) { | 362 const base::string16& source_id) { |
362 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 363 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
363 // Log levels are from base/logging.h: LogSeverity. | 364 // Log levels are from base/logging.h: LogSeverity. |
364 args->SetInteger(webview::kLevel, level); | 365 args->SetInteger(webview::kLevel, level); |
365 args->SetString(webview::kMessage, message); | 366 args->SetString(webview::kMessage, message); |
366 args->SetInteger(webview::kLine, line_no); | 367 args->SetInteger(webview::kLine, line_no); |
367 args->SetString(webview::kSourceId, source_id); | 368 args->SetString(webview::kSourceId, source_id); |
368 DispatchEvent( | 369 DispatchEvent( |
369 new GuestViewBase::Event(webview::kEventConsoleMessage, args.Pass())); | 370 new GuestViewBase::Event(webview::kEventConsoleMessage, args.Pass())); |
| 371 return true; |
370 } | 372 } |
371 | 373 |
372 void WebViewGuest::Close() { | 374 void WebViewGuest::CloseContents(WebContents* source) { |
373 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 375 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
374 DispatchEvent(new GuestViewBase::Event(webview::kEventClose, args.Pass())); | 376 DispatchEvent(new GuestViewBase::Event(webview::kEventClose, args.Pass())); |
375 } | 377 } |
376 | 378 |
377 void WebViewGuest::DidAttach() { | 379 void WebViewGuest::DidAttach() { |
378 if (GetOpener()) { | 380 if (GetOpener()) { |
379 // We need to do a navigation here if the target URL has changed between | 381 // We need to do a navigation here if the target URL has changed between |
380 // the time the WebContents was created and the time it was attached. | 382 // the time the WebContents was created and the time it was attached. |
381 // We also need to do an initial navigation if a RenderView was never | 383 // We also need to do an initial navigation if a RenderView was never |
382 // created for the new window in cases where there is no referrer. | 384 // created for the new window in cases where there is no referrer. |
(...skipping 28 matching lines...) Expand all Loading... |
411 content::BrowserThread::PostTask( | 413 content::BrowserThread::PostTask( |
412 content::BrowserThread::IO, | 414 content::BrowserThread::IO, |
413 FROM_HERE, | 415 FROM_HERE, |
414 base::Bind( | 416 base::Bind( |
415 &RemoveWebViewEventListenersOnIOThread, | 417 &RemoveWebViewEventListenersOnIOThread, |
416 browser_context(), embedder_extension_id(), | 418 browser_context(), embedder_extension_id(), |
417 embedder_render_process_id(), | 419 embedder_render_process_id(), |
418 view_instance_id())); | 420 view_instance_id())); |
419 } | 421 } |
420 | 422 |
421 void WebViewGuest::FindReply(int request_id, | 423 void WebViewGuest::FindReply(WebContents* source, |
| 424 int request_id, |
422 int number_of_matches, | 425 int number_of_matches, |
423 const gfx::Rect& selection_rect, | 426 const gfx::Rect& selection_rect, |
424 int active_match_ordinal, | 427 int active_match_ordinal, |
425 bool final_update) { | 428 bool final_update) { |
426 find_helper_.FindReply(request_id, number_of_matches, selection_rect, | 429 find_helper_.FindReply(request_id, number_of_matches, selection_rect, |
427 active_match_ordinal, final_update); | 430 active_match_ordinal, final_update); |
428 } | 431 } |
429 | 432 |
430 void WebViewGuest::GuestProcessGone(base::TerminationStatus status) { | 433 void WebViewGuest::GuestProcessGone(base::TerminationStatus status) { |
431 // Cancel all find sessions in progress. | 434 // Cancel all find sessions in progress. |
432 find_helper_.CancelAllFindSessions(); | 435 find_helper_.CancelAllFindSessions(); |
433 | 436 |
434 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 437 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
435 args->SetInteger(webview::kProcessId, | 438 args->SetInteger(webview::kProcessId, |
436 guest_web_contents()->GetRenderProcessHost()->GetID()); | 439 guest_web_contents()->GetRenderProcessHost()->GetID()); |
437 args->SetString(webview::kReason, TerminationStatusToString(status)); | 440 args->SetString(webview::kReason, TerminationStatusToString(status)); |
438 DispatchEvent(new GuestViewBase::Event(webview::kEventExit, args.Pass())); | 441 DispatchEvent(new GuestViewBase::Event(webview::kEventExit, args.Pass())); |
439 } | 442 } |
440 | 443 |
441 void WebViewGuest::HandleKeyboardEvent( | 444 void WebViewGuest::HandleKeyboardEvent( |
| 445 WebContents* source, |
442 const content::NativeWebKeyboardEvent& event) { | 446 const content::NativeWebKeyboardEvent& event) { |
443 if (!attached()) | 447 if (!attached()) |
444 return; | 448 return; |
445 | 449 |
446 if (HandleKeyboardShortcuts(event)) | 450 if (HandleKeyboardShortcuts(event)) |
447 return; | 451 return; |
448 | 452 |
449 // Send the unhandled keyboard events back to the embedder to reprocess them. | 453 // Send the unhandled keyboard events back to the embedder to reprocess them. |
450 // TODO(fsamuel): This introduces the possibility of out-of-order keyboard | 454 // TODO(fsamuel): This introduces the possibility of out-of-order keyboard |
451 // events because the guest may be arbitrarily delayed when responding to | 455 // events because the guest may be arbitrarily delayed when responding to |
452 // keyboard events. In that time, the embedder may have received and processed | 456 // keyboard events. In that time, the embedder may have received and processed |
453 // additional key events. This needs to be fixed as soon as possible. | 457 // additional key events. This needs to be fixed as soon as possible. |
454 // See http://crbug.com/229882. | 458 // See http://crbug.com/229882. |
455 embedder_web_contents()->GetDelegate()->HandleKeyboardEvent( | 459 embedder_web_contents()->GetDelegate()->HandleKeyboardEvent( |
456 web_contents(), event); | 460 web_contents(), event); |
457 } | 461 } |
458 | 462 |
459 bool WebViewGuest::IsDragAndDropEnabled() { | 463 bool WebViewGuest::IsDragAndDropEnabled() { |
460 return true; | 464 return true; |
461 } | 465 } |
462 | 466 |
463 void WebViewGuest::LoadProgressed(double progress) { | 467 void WebViewGuest::LoadProgressChanged(content::WebContents* source, |
| 468 double progress) { |
464 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 469 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
465 args->SetString(guestview::kUrl, guest_web_contents()->GetURL().spec()); | 470 args->SetString(guestview::kUrl, guest_web_contents()->GetURL().spec()); |
466 args->SetDouble(webview::kProgress, progress); | 471 args->SetDouble(webview::kProgress, progress); |
467 DispatchEvent( | 472 DispatchEvent( |
468 new GuestViewBase::Event(webview::kEventLoadProgress, args.Pass())); | 473 new GuestViewBase::Event(webview::kEventLoadProgress, args.Pass())); |
469 } | 474 } |
470 | 475 |
471 void WebViewGuest::LoadAbort(bool is_top_level, | 476 void WebViewGuest::LoadAbort(bool is_top_level, |
472 const GURL& url, | 477 const GURL& url, |
473 const std::string& error_type) { | 478 const std::string& error_type) { |
(...skipping 11 matching lines...) Expand all Loading... |
485 return; | 490 return; |
486 | 491 |
487 if (name_ == name) | 492 if (name_ == name) |
488 return; | 493 return; |
489 | 494 |
490 ReportFrameNameChange(name); | 495 ReportFrameNameChange(name); |
491 } | 496 } |
492 | 497 |
493 WebViewGuest* WebViewGuest::CreateNewGuestWindow( | 498 WebViewGuest* WebViewGuest::CreateNewGuestWindow( |
494 const content::OpenURLParams& params) { | 499 const content::OpenURLParams& params) { |
495 | |
496 GuestViewManager* guest_manager = | 500 GuestViewManager* guest_manager = |
497 GuestViewManager::FromBrowserContext(browser_context()); | 501 GuestViewManager::FromBrowserContext(browser_context()); |
498 // Allocate a new instance ID for the new guest. | 502 // Allocate a new instance ID for the new guest. |
499 int instance_id = guest_manager->GetNextInstanceID(); | 503 int instance_id = guest_manager->GetNextInstanceID(); |
500 | 504 |
501 // Set the attach params to use the same partition as the opener. | 505 // Set the attach params to use the same partition as the opener. |
502 // We pull the partition information from the site's URL, which is of the | 506 // We pull the partition information from the site's URL, which is of the |
503 // form guest://site/{persist}?{partition_name}. | 507 // form guest://site/{persist}?{partition_name}. |
504 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); | 508 const GURL& site_url = guest_web_contents()->GetSiteInstance()->GetSiteURL(); |
505 | 509 |
(...skipping 18 matching lines...) Expand all Loading... |
524 // Request permission to show the new window. | 528 // Request permission to show the new window. |
525 RequestNewWindowPermission(params.disposition, gfx::Rect(), | 529 RequestNewWindowPermission(params.disposition, gfx::Rect(), |
526 params.user_gesture, | 530 params.user_gesture, |
527 new_guest->guest_web_contents()); | 531 new_guest->guest_web_contents()); |
528 | 532 |
529 return new_guest; | 533 return new_guest; |
530 } | 534 } |
531 | 535 |
532 // TODO(fsamuel): Find a reliable way to test the 'responsive' and | 536 // TODO(fsamuel): Find a reliable way to test the 'responsive' and |
533 // 'unresponsive' events. | 537 // 'unresponsive' events. |
534 void WebViewGuest::RendererResponsive() { | 538 void WebViewGuest::RendererResponsive(content::WebContents* source) { |
535 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 539 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
536 args->SetInteger(webview::kProcessId, | 540 args->SetInteger(webview::kProcessId, |
537 guest_web_contents()->GetRenderProcessHost()->GetID()); | 541 guest_web_contents()->GetRenderProcessHost()->GetID()); |
538 DispatchEvent( | 542 DispatchEvent( |
539 new GuestViewBase::Event(webview::kEventResponsive, args.Pass())); | 543 new GuestViewBase::Event(webview::kEventResponsive, args.Pass())); |
540 } | 544 } |
541 | 545 |
542 void WebViewGuest::RendererUnresponsive() { | 546 void WebViewGuest::RendererUnresponsive(content::WebContents* source) { |
543 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 547 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
544 args->SetInteger(webview::kProcessId, | 548 args->SetInteger(webview::kProcessId, |
545 guest_web_contents()->GetRenderProcessHost()->GetID()); | 549 guest_web_contents()->GetRenderProcessHost()->GetID()); |
546 DispatchEvent( | 550 DispatchEvent( |
547 new GuestViewBase::Event(webview::kEventUnresponsive, args.Pass())); | 551 new GuestViewBase::Event(webview::kEventUnresponsive, args.Pass())); |
548 } | 552 } |
549 | 553 |
550 void WebViewGuest::Observe(int type, | 554 void WebViewGuest::Observe(int type, |
551 const content::NotificationSource& source, | 555 const content::NotificationSource& source, |
552 const content::NotificationDetails& details) { | 556 const content::NotificationDetails& details) { |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 976 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
973 args->SetInteger(webview::kOldHeight, old_size.height()); | 977 args->SetInteger(webview::kOldHeight, old_size.height()); |
974 args->SetInteger(webview::kOldWidth, old_size.width()); | 978 args->SetInteger(webview::kOldWidth, old_size.width()); |
975 args->SetInteger(webview::kNewHeight, new_size.height()); | 979 args->SetInteger(webview::kNewHeight, new_size.height()); |
976 args->SetInteger(webview::kNewWidth, new_size.width()); | 980 args->SetInteger(webview::kNewWidth, new_size.width()); |
977 DispatchEvent( | 981 DispatchEvent( |
978 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); | 982 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); |
979 } | 983 } |
980 | 984 |
981 void WebViewGuest::RequestMediaAccessPermission( | 985 void WebViewGuest::RequestMediaAccessPermission( |
| 986 content::WebContents* source, |
982 const content::MediaStreamRequest& request, | 987 const content::MediaStreamRequest& request, |
983 const content::MediaResponseCallback& callback) { | 988 const content::MediaResponseCallback& callback) { |
984 base::DictionaryValue request_info; | 989 base::DictionaryValue request_info; |
985 request_info.Set( | 990 request_info.Set( |
986 guestview::kUrl, | 991 guestview::kUrl, |
987 base::Value::CreateStringValue(request.security_origin.spec())); | 992 base::Value::CreateStringValue(request.security_origin.spec())); |
988 RequestPermission(WEB_VIEW_PERMISSION_TYPE_MEDIA, | 993 RequestPermission(WEB_VIEW_PERMISSION_TYPE_MEDIA, |
989 request_info, | 994 request_info, |
990 base::Bind(&WebViewGuest::OnWebViewMediaPermissionResponse, | 995 base::Bind(&WebViewGuest::OnWebViewMediaPermissionResponse, |
991 base::Unretained(this), | 996 base::Unretained(this), |
992 request, | 997 request, |
993 callback), | 998 callback), |
994 false /* allowed_by_default */); | 999 false /* allowed_by_default */); |
995 } | 1000 } |
996 | 1001 |
997 void WebViewGuest::CanDownload( | 1002 void WebViewGuest::CanDownload( |
| 1003 content::RenderViewHost* render_view_host, |
| 1004 const GURL& url, |
998 const std::string& request_method, | 1005 const std::string& request_method, |
999 const GURL& url, | |
1000 const base::Callback<void(bool)>& callback) { | 1006 const base::Callback<void(bool)>& callback) { |
1001 base::DictionaryValue request_info; | 1007 base::DictionaryValue request_info; |
1002 request_info.Set( | 1008 request_info.Set( |
1003 guestview::kUrl, | 1009 guestview::kUrl, |
1004 base::Value::CreateStringValue(url.spec())); | 1010 base::Value::CreateStringValue(url.spec())); |
1005 RequestPermission( | 1011 RequestPermission( |
1006 WEB_VIEW_PERMISSION_TYPE_DOWNLOAD, | 1012 WEB_VIEW_PERMISSION_TYPE_DOWNLOAD, |
1007 request_info, | 1013 request_info, |
1008 base::Bind(&WebViewGuest::OnWebViewDownloadPermissionResponse, | 1014 base::Bind(&WebViewGuest::OnWebViewDownloadPermissionResponse, |
1009 base::Unretained(this), | 1015 base::Unretained(this), |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 bool allow, | 1410 bool allow, |
1405 const std::string& user_input) { | 1411 const std::string& user_input) { |
1406 WebViewGuest* guest = | 1412 WebViewGuest* guest = |
1407 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1413 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
1408 if (!guest) | 1414 if (!guest) |
1409 return; | 1415 return; |
1410 | 1416 |
1411 if (!allow) | 1417 if (!allow) |
1412 guest->Destroy(); | 1418 guest->Destroy(); |
1413 } | 1419 } |
OLD | NEW |