| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 // Request permission to show the new window. | 529 // Request permission to show the new window. |
| 525 RequestNewWindowPermission(params.disposition, gfx::Rect(), | 530 RequestNewWindowPermission(params.disposition, gfx::Rect(), |
| 526 params.user_gesture, | 531 params.user_gesture, |
| 527 new_guest->guest_web_contents()); | 532 new_guest->guest_web_contents()); |
| 528 | 533 |
| 529 return new_guest; | 534 return new_guest; |
| 530 } | 535 } |
| 531 | 536 |
| 532 // TODO(fsamuel): Find a reliable way to test the 'responsive' and | 537 // TODO(fsamuel): Find a reliable way to test the 'responsive' and |
| 533 // 'unresponsive' events. | 538 // 'unresponsive' events. |
| 534 void WebViewGuest::RendererResponsive() { | 539 void WebViewGuest::RendererResponsive(content::WebContents* source) { |
| 535 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 540 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 536 args->SetInteger(webview::kProcessId, | 541 args->SetInteger(webview::kProcessId, |
| 537 guest_web_contents()->GetRenderProcessHost()->GetID()); | 542 guest_web_contents()->GetRenderProcessHost()->GetID()); |
| 538 DispatchEvent( | 543 DispatchEvent( |
| 539 new GuestViewBase::Event(webview::kEventResponsive, args.Pass())); | 544 new GuestViewBase::Event(webview::kEventResponsive, args.Pass())); |
| 540 } | 545 } |
| 541 | 546 |
| 542 void WebViewGuest::RendererUnresponsive() { | 547 void WebViewGuest::RendererUnresponsive(content::WebContents* source) { |
| 543 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 548 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 544 args->SetInteger(webview::kProcessId, | 549 args->SetInteger(webview::kProcessId, |
| 545 guest_web_contents()->GetRenderProcessHost()->GetID()); | 550 guest_web_contents()->GetRenderProcessHost()->GetID()); |
| 546 DispatchEvent( | 551 DispatchEvent( |
| 547 new GuestViewBase::Event(webview::kEventUnresponsive, args.Pass())); | 552 new GuestViewBase::Event(webview::kEventUnresponsive, args.Pass())); |
| 548 } | 553 } |
| 549 | 554 |
| 550 void WebViewGuest::Observe(int type, | 555 void WebViewGuest::Observe(int type, |
| 551 const content::NotificationSource& source, | 556 const content::NotificationSource& source, |
| 552 const content::NotificationDetails& details) { | 557 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()); | 977 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 973 args->SetInteger(webview::kOldHeight, old_size.height()); | 978 args->SetInteger(webview::kOldHeight, old_size.height()); |
| 974 args->SetInteger(webview::kOldWidth, old_size.width()); | 979 args->SetInteger(webview::kOldWidth, old_size.width()); |
| 975 args->SetInteger(webview::kNewHeight, new_size.height()); | 980 args->SetInteger(webview::kNewHeight, new_size.height()); |
| 976 args->SetInteger(webview::kNewWidth, new_size.width()); | 981 args->SetInteger(webview::kNewWidth, new_size.width()); |
| 977 DispatchEvent( | 982 DispatchEvent( |
| 978 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); | 983 new GuestViewBase::Event(webview::kEventSizeChanged, args.Pass())); |
| 979 } | 984 } |
| 980 | 985 |
| 981 void WebViewGuest::RequestMediaAccessPermission( | 986 void WebViewGuest::RequestMediaAccessPermission( |
| 987 content::WebContents* source, |
| 982 const content::MediaStreamRequest& request, | 988 const content::MediaStreamRequest& request, |
| 983 const content::MediaResponseCallback& callback) { | 989 const content::MediaResponseCallback& callback) { |
| 984 base::DictionaryValue request_info; | 990 base::DictionaryValue request_info; |
| 985 request_info.Set( | 991 request_info.Set( |
| 986 guestview::kUrl, | 992 guestview::kUrl, |
| 987 base::Value::CreateStringValue(request.security_origin.spec())); | 993 base::Value::CreateStringValue(request.security_origin.spec())); |
| 988 RequestPermission(WEB_VIEW_PERMISSION_TYPE_MEDIA, | 994 RequestPermission(WEB_VIEW_PERMISSION_TYPE_MEDIA, |
| 989 request_info, | 995 request_info, |
| 990 base::Bind(&WebViewGuest::OnWebViewMediaPermissionResponse, | 996 base::Bind(&WebViewGuest::OnWebViewMediaPermissionResponse, |
| 991 base::Unretained(this), | 997 base::Unretained(this), |
| 992 request, | 998 request, |
| 993 callback), | 999 callback), |
| 994 false /* allowed_by_default */); | 1000 false /* allowed_by_default */); |
| 995 } | 1001 } |
| 996 | 1002 |
| 997 void WebViewGuest::CanDownload( | 1003 void WebViewGuest::CanDownload( |
| 1004 content::RenderViewHost* render_view_host, |
| 1005 const GURL& url, |
| 998 const std::string& request_method, | 1006 const std::string& request_method, |
| 999 const GURL& url, | |
| 1000 const base::Callback<void(bool)>& callback) { | 1007 const base::Callback<void(bool)>& callback) { |
| 1001 base::DictionaryValue request_info; | 1008 base::DictionaryValue request_info; |
| 1002 request_info.Set( | 1009 request_info.Set( |
| 1003 guestview::kUrl, | 1010 guestview::kUrl, |
| 1004 base::Value::CreateStringValue(url.spec())); | 1011 base::Value::CreateStringValue(url.spec())); |
| 1005 RequestPermission( | 1012 RequestPermission( |
| 1006 WEB_VIEW_PERMISSION_TYPE_DOWNLOAD, | 1013 WEB_VIEW_PERMISSION_TYPE_DOWNLOAD, |
| 1007 request_info, | 1014 request_info, |
| 1008 base::Bind(&WebViewGuest::OnWebViewDownloadPermissionResponse, | 1015 base::Bind(&WebViewGuest::OnWebViewDownloadPermissionResponse, |
| 1009 base::Unretained(this), | 1016 base::Unretained(this), |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1404 bool allow, | 1411 bool allow, |
| 1405 const std::string& user_input) { | 1412 const std::string& user_input) { |
| 1406 WebViewGuest* guest = | 1413 WebViewGuest* guest = |
| 1407 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1414 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1408 if (!guest) | 1415 if (!guest) |
| 1409 return; | 1416 return; |
| 1410 | 1417 |
| 1411 if (!allow) | 1418 if (!allow) |
| 1412 guest->Destroy(); | 1419 guest->Destroy(); |
| 1413 } | 1420 } |
| OLD | NEW |