Chromium Code Reviews| 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 NavigateGuest(src, false /* force_navigation */); | 328 NavigateGuest(src, false /* force_navigation */); |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 | 331 |
| 332 bool allow_transparency = false; | 332 bool allow_transparency = false; |
| 333 attach_params()->GetBoolean(webview::kAttributeAllowTransparency, | 333 attach_params()->GetBoolean(webview::kAttributeAllowTransparency, |
| 334 &allow_transparency); | 334 &allow_transparency); |
| 335 // We need to set the background opaque flag after navigation to ensure that | 335 // We need to set the background opaque flag after navigation to ensure that |
| 336 // there is a RenderWidgetHostView available. | 336 // there is a RenderWidgetHostView available. |
| 337 SetAllowTransparency(allow_transparency); | 337 SetAllowTransparency(allow_transparency); |
| 338 | |
| 339 if (web_view_guest_delegate_) | |
| 340 web_view_guest_delegate_->OnDidAttachToEmbedder(); | |
| 341 } | 338 } |
| 342 | 339 |
| 343 void WebViewGuest::DidInitialize() { | 340 void WebViewGuest::DidInitialize() { |
| 344 script_executor_.reset( | 341 script_executor_.reset( |
| 345 new ScriptExecutor(web_contents(), &script_observers_)); | 342 new ScriptExecutor(web_contents(), &script_observers_)); |
| 346 | 343 |
| 347 notification_registrar_.Add(this, | 344 notification_registrar_.Add(this, |
| 348 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 345 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 349 content::Source<WebContents>(web_contents())); | 346 content::Source<WebContents>(web_contents())); |
| 350 | 347 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 363 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); | 360 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); |
| 364 } | 361 } |
| 365 | 362 |
| 366 void WebViewGuest::DidStopLoading() { | 363 void WebViewGuest::DidStopLoading() { |
| 367 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 364 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 368 DispatchEventToEmbedder( | 365 DispatchEventToEmbedder( |
| 369 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); | 366 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); |
| 370 } | 367 } |
| 371 | 368 |
| 372 void WebViewGuest::EmbedderWillBeDestroyed() { | 369 void WebViewGuest::EmbedderWillBeDestroyed() { |
| 373 if (web_view_guest_delegate_) | 370 GuestViewBase::EmbedderWillBeDestroyed(); |
|
Fady Samuel
2014/12/09 21:41:42
This should no longer be necessary, I think??
wjmaclean
2014/12/09 22:12:37
Done.
| |
| 374 web_view_guest_delegate_->OnEmbedderWillBeDestroyed(); | |
| 375 | 371 |
| 376 // Clean up rules registries for the webview. | 372 // Clean up rules registries for the webview. |
| 377 RulesRegistryService::Get(browser_context()) | 373 RulesRegistryService::Get(browser_context()) |
| 378 ->RemoveRulesRegistriesByID(rules_registry_id_); | 374 ->RemoveRulesRegistriesByID(rules_registry_id_); |
| 379 WebViewKey key(owner_render_process_id(), view_instance_id()); | 375 WebViewKey key(owner_render_process_id(), view_instance_id()); |
| 380 web_view_key_to_id_map.Get().erase(key); | 376 web_view_key_to_id_map.Get().erase(key); |
| 381 | 377 |
| 382 content::BrowserThread::PostTask( | 378 content::BrowserThread::PostTask( |
| 383 content::BrowserThread::IO, | 379 content::BrowserThread::IO, |
| 384 FROM_HERE, | 380 FROM_HERE, |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 610 resource_redirect_details->new_url, | 606 resource_redirect_details->new_url, |
| 611 is_top_level); | 607 is_top_level); |
| 612 break; | 608 break; |
| 613 } | 609 } |
| 614 default: | 610 default: |
| 615 NOTREACHED() << "Unexpected notification sent."; | 611 NOTREACHED() << "Unexpected notification sent."; |
| 616 break; | 612 break; |
| 617 } | 613 } |
| 618 } | 614 } |
| 619 | 615 |
| 620 double WebViewGuest::GetZoom() { | |
| 621 if (!web_view_guest_delegate_) | |
| 622 return 1.0; | |
| 623 return web_view_guest_delegate_->GetZoom(); | |
| 624 } | |
| 625 | |
| 626 void WebViewGuest::StartFinding( | 616 void WebViewGuest::StartFinding( |
| 627 const base::string16& search_text, | 617 const base::string16& search_text, |
| 628 const blink::WebFindOptions& options, | 618 const blink::WebFindOptions& options, |
| 629 scoped_refptr<WebViewInternalFindFunction> find_function) { | 619 scoped_refptr<WebViewInternalFindFunction> find_function) { |
| 630 find_helper_.Find(web_contents(), search_text, options, find_function); | 620 find_helper_.Find(web_contents(), search_text, options, find_function); |
| 631 } | 621 } |
| 632 | 622 |
| 633 void WebViewGuest::StopFinding(content::StopFindAction action) { | 623 void WebViewGuest::StopFinding(content::StopFindAction action) { |
| 634 find_helper_.CancelAllFindSessions(); | 624 find_helper_.CancelAllFindSessions(); |
| 635 web_contents()->StopFinding(action); | 625 web_contents()->StopFinding(action); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 content::WebContents* owner_web_contents, | 692 content::WebContents* owner_web_contents, |
| 703 int guest_instance_id) | 693 int guest_instance_id) |
| 704 : GuestView<WebViewGuest>(browser_context, | 694 : GuestView<WebViewGuest>(browser_context, |
| 705 owner_web_contents, | 695 owner_web_contents, |
| 706 guest_instance_id), | 696 guest_instance_id), |
| 707 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID), | 697 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID), |
| 708 find_helper_(this), | 698 find_helper_(this), |
| 709 is_overriding_user_agent_(false), | 699 is_overriding_user_agent_(false), |
| 710 guest_opaque_(true), | 700 guest_opaque_(true), |
| 711 javascript_dialog_helper_(this), | 701 javascript_dialog_helper_(this), |
| 702 current_zoom_factor_(1.0), | |
| 712 weak_ptr_factory_(this) { | 703 weak_ptr_factory_(this) { |
| 713 web_view_guest_delegate_.reset( | 704 web_view_guest_delegate_.reset( |
| 714 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); | 705 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); |
| 715 } | 706 } |
| 716 | 707 |
| 717 WebViewGuest::~WebViewGuest() { | 708 WebViewGuest::~WebViewGuest() { |
| 718 } | 709 } |
| 719 | 710 |
| 720 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 711 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
| 721 content::RenderFrameHost* render_frame_host, | 712 content::RenderFrameHost* render_frame_host, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 735 args->SetInteger(webview::kInternalCurrentEntryIndex, | 726 args->SetInteger(webview::kInternalCurrentEntryIndex, |
| 736 web_contents()->GetController().GetCurrentEntryIndex()); | 727 web_contents()->GetController().GetCurrentEntryIndex()); |
| 737 args->SetInteger(webview::kInternalEntryCount, | 728 args->SetInteger(webview::kInternalEntryCount, |
| 738 web_contents()->GetController().GetEntryCount()); | 729 web_contents()->GetController().GetEntryCount()); |
| 739 args->SetInteger(webview::kInternalProcessId, | 730 args->SetInteger(webview::kInternalProcessId, |
| 740 web_contents()->GetRenderProcessHost()->GetID()); | 731 web_contents()->GetRenderProcessHost()->GetID()); |
| 741 DispatchEventToEmbedder( | 732 DispatchEventToEmbedder( |
| 742 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); | 733 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); |
| 743 | 734 |
| 744 find_helper_.CancelAllFindSessions(); | 735 find_helper_.CancelAllFindSessions(); |
| 736 | |
| 737 // Update the current zoom factor for the new page. | |
| 738 ui_zoom::ZoomController* zoom_controller = | |
| 739 ui_zoom::ZoomController::FromWebContents(web_contents()); | |
| 740 DCHECK(zoom_controller); | |
| 741 current_zoom_factor_ = | |
| 742 content::ZoomLevelToZoomFactor(zoom_controller->GetZoomLevel()); | |
| 743 | |
| 745 if (web_view_guest_delegate_) { | 744 if (web_view_guest_delegate_) { |
| 746 web_view_guest_delegate_->OnDidCommitProvisionalLoadForFrame( | 745 web_view_guest_delegate_->OnDidCommitProvisionalLoadForFrame( |
| 747 !render_frame_host->GetParent()); | 746 !render_frame_host->GetParent()); |
| 748 } | 747 } |
| 749 } | 748 } |
| 750 | 749 |
| 751 void WebViewGuest::DidFailProvisionalLoad( | 750 void WebViewGuest::DidFailProvisionalLoad( |
| 752 content::RenderFrameHost* render_frame_host, | 751 content::RenderFrameHost* render_frame_host, |
| 753 const GURL& validated_url, | 752 const GURL& validated_url, |
| 754 int error_code, | 753 int error_code, |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1055 | 1054 |
| 1056 void WebViewGuest::SetName(const std::string& name) { | 1055 void WebViewGuest::SetName(const std::string& name) { |
| 1057 if (name_ == name) | 1056 if (name_ == name) |
| 1058 return; | 1057 return; |
| 1059 name_ = name; | 1058 name_ = name; |
| 1060 | 1059 |
| 1061 Send(new ExtensionMsg_SetFrameName(routing_id(), name_)); | 1060 Send(new ExtensionMsg_SetFrameName(routing_id(), name_)); |
| 1062 } | 1061 } |
| 1063 | 1062 |
| 1064 void WebViewGuest::SetZoom(double zoom_factor) { | 1063 void WebViewGuest::SetZoom(double zoom_factor) { |
| 1065 if (web_view_guest_delegate_) | 1064 ui_zoom::ZoomController* zoom_controller = |
| 1066 web_view_guest_delegate_->OnSetZoom(zoom_factor); | 1065 ui_zoom::ZoomController::FromWebContents(web_contents()); |
| 1066 DCHECK(zoom_controller); | |
| 1067 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); | |
| 1068 zoom_controller->SetZoomLevel(zoom_level); | |
| 1069 | |
| 1070 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | |
| 1071 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); | |
| 1072 args->SetDouble(webview::kNewZoomFactor, zoom_factor); | |
| 1073 DispatchEventToEmbedder( | |
| 1074 new GuestViewBase::Event(webview::kEventZoomChange, args.Pass())); | |
| 1075 current_zoom_factor_ = zoom_factor; | |
| 1067 } | 1076 } |
| 1068 | 1077 |
| 1069 void WebViewGuest::SetAllowTransparency(bool allow) { | 1078 void WebViewGuest::SetAllowTransparency(bool allow) { |
| 1070 if (guest_opaque_ != allow) | 1079 if (guest_opaque_ != allow) |
| 1071 return; | 1080 return; |
| 1072 | 1081 |
| 1073 guest_opaque_ = !allow; | 1082 guest_opaque_ = !allow; |
| 1074 if (!web_contents()->GetRenderViewHost()->GetView()) | 1083 if (!web_contents()->GetRenderViewHost()->GetView()) |
| 1075 return; | 1084 return; |
| 1076 | 1085 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1260 WebViewGuest* guest = | 1269 WebViewGuest* guest = |
| 1261 WebViewGuest::From(owner_render_process_id(), new_window_instance_id); | 1270 WebViewGuest::From(owner_render_process_id(), new_window_instance_id); |
| 1262 if (!guest) | 1271 if (!guest) |
| 1263 return; | 1272 return; |
| 1264 | 1273 |
| 1265 if (!allow) | 1274 if (!allow) |
| 1266 guest->Destroy(); | 1275 guest->Destroy(); |
| 1267 } | 1276 } |
| 1268 | 1277 |
| 1269 } // namespace extensions | 1278 } // namespace extensions |
| OLD | NEW |