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 "extensions/browser/guest_view/web_view/web_view_guest.h" | 5 #include "extensions/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 "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 const GURL& url, | 468 const GURL& url, |
469 const std::string& error_type) { | 469 const std::string& error_type) { |
470 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 470 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
471 args->SetBoolean(guestview::kIsTopLevel, is_top_level); | 471 args->SetBoolean(guestview::kIsTopLevel, is_top_level); |
472 args->SetString(guestview::kUrl, url.possibly_invalid_spec()); | 472 args->SetString(guestview::kUrl, url.possibly_invalid_spec()); |
473 args->SetString(guestview::kReason, error_type); | 473 args->SetString(guestview::kReason, error_type); |
474 DispatchEventToView( | 474 DispatchEventToView( |
475 new GuestViewBase::Event(webview::kEventLoadAbort, args.Pass())); | 475 new GuestViewBase::Event(webview::kEventLoadAbort, args.Pass())); |
476 } | 476 } |
477 | 477 |
478 void WebViewGuest::OnFrameNameChanged(bool is_top_level, | |
479 const std::string& name) { | |
480 if (!is_top_level) | |
481 return; | |
482 | |
483 if (name_ == name) | |
484 return; | |
485 | |
486 ReportFrameNameChange(name); | |
487 } | |
488 | |
489 void WebViewGuest::CreateNewGuestWebViewWindow( | 478 void WebViewGuest::CreateNewGuestWebViewWindow( |
490 const content::OpenURLParams& params) { | 479 const content::OpenURLParams& params) { |
491 GuestViewManager* guest_manager = | 480 GuestViewManager* guest_manager = |
492 GuestViewManager::FromBrowserContext(browser_context()); | 481 GuestViewManager::FromBrowserContext(browser_context()); |
493 // Set the attach params to use the same partition as the opener. | 482 // Set the attach params to use the same partition as the opener. |
494 // We pull the partition information from the site's URL, which is of the | 483 // We pull the partition information from the site's URL, which is of the |
495 // form guest://site/{persist}?{partition_name}. | 484 // form guest://site/{persist}?{partition_name}. |
496 const GURL& site_url = web_contents()->GetSiteInstance()->GetSiteURL(); | 485 const GURL& site_url = web_contents()->GetSiteInstance()->GetSiteURL(); |
497 const std::string storage_partition_id = | 486 const std::string storage_partition_id = |
498 GetStoragePartitionIdFromSiteURL(site_url); | 487 GetStoragePartitionIdFromSiteURL(site_url); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 DispatchEventToView( | 707 DispatchEventToView( |
719 new GuestViewBase::Event(webview::kEventLoadStart, args.Pass())); | 708 new GuestViewBase::Event(webview::kEventLoadStart, args.Pass())); |
720 } | 709 } |
721 | 710 |
722 void WebViewGuest::DocumentLoadedInFrame( | 711 void WebViewGuest::DocumentLoadedInFrame( |
723 content::RenderFrameHost* render_frame_host) { | 712 content::RenderFrameHost* render_frame_host) { |
724 if (web_view_guest_delegate_) | 713 if (web_view_guest_delegate_) |
725 web_view_guest_delegate_->OnDocumentLoadedInFrame(render_frame_host); | 714 web_view_guest_delegate_->OnDocumentLoadedInFrame(render_frame_host); |
726 } | 715 } |
727 | 716 |
728 bool WebViewGuest::OnMessageReceived(const IPC::Message& message, | |
729 RenderFrameHost* render_frame_host) { | |
730 bool handled = true; | |
731 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message) | |
732 IPC_MESSAGE_HANDLER(ExtensionHostMsg_FrameNameChanged, OnFrameNameChanged) | |
733 IPC_MESSAGE_UNHANDLED(handled = false) | |
734 IPC_END_MESSAGE_MAP() | |
735 return handled; | |
736 } | |
737 | |
738 void WebViewGuest::RenderProcessGone(base::TerminationStatus status) { | 717 void WebViewGuest::RenderProcessGone(base::TerminationStatus status) { |
739 // Cancel all find sessions in progress. | 718 // Cancel all find sessions in progress. |
740 find_helper_.CancelAllFindSessions(); | 719 find_helper_.CancelAllFindSessions(); |
741 | 720 |
742 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 721 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
743 args->SetInteger(webview::kProcessId, | 722 args->SetInteger(webview::kProcessId, |
744 web_contents()->GetRenderProcessHost()->GetID()); | 723 web_contents()->GetRenderProcessHost()->GetID()); |
745 args->SetString(webview::kReason, TerminationStatusToString(status)); | 724 args->SetString(webview::kReason, TerminationStatusToString(status)); |
746 DispatchEventToView( | 725 DispatchEventToView( |
747 new GuestViewBase::Event(webview::kEventExit, args.Pass())); | 726 new GuestViewBase::Event(webview::kEventExit, args.Pass())); |
748 } | 727 } |
749 | 728 |
750 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { | 729 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { |
751 content::NavigationController& controller = web_contents()->GetController(); | 730 content::NavigationController& controller = web_contents()->GetController(); |
752 content::NavigationEntry* entry = controller.GetVisibleEntry(); | 731 content::NavigationEntry* entry = controller.GetVisibleEntry(); |
753 if (!entry) | 732 if (!entry) |
754 return; | 733 return; |
755 entry->SetIsOverridingUserAgent(!user_agent.empty()); | 734 entry->SetIsOverridingUserAgent(!user_agent.empty()); |
756 web_contents()->GetController().Reload(false); | 735 web_contents()->GetController().Reload(false); |
757 } | 736 } |
758 | 737 |
| 738 void WebViewGuest::FrameNameChanged(RenderFrameHost* render_frame_host, |
| 739 const std::string& name) { |
| 740 if (render_frame_host->GetParent()) |
| 741 return; |
| 742 |
| 743 if (name_ == name) |
| 744 return; |
| 745 |
| 746 ReportFrameNameChange(name); |
| 747 } |
| 748 |
759 void WebViewGuest::ReportFrameNameChange(const std::string& name) { | 749 void WebViewGuest::ReportFrameNameChange(const std::string& name) { |
760 name_ = name; | 750 name_ = name; |
761 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 751 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
762 args->SetString(webview::kName, name); | 752 args->SetString(webview::kName, name); |
763 DispatchEventToView( | 753 DispatchEventToView( |
764 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); | 754 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); |
765 } | 755 } |
766 | 756 |
767 void WebViewGuest::LoadHandlerCalled() { | 757 void WebViewGuest::LoadHandlerCalled() { |
768 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 758 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), | 1259 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), |
1270 new_window_instance_id); | 1260 new_window_instance_id); |
1271 if (!guest) | 1261 if (!guest) |
1272 return; | 1262 return; |
1273 | 1263 |
1274 if (!allow) | 1264 if (!allow) |
1275 guest->Destroy(); | 1265 guest->Destroy(); |
1276 } | 1266 } |
1277 | 1267 |
1278 } // namespace extensions | 1268 } // namespace extensions |
OLD | NEW |