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

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

Issue 787813004: Move ZoomController out of ChromeWebViewGuestDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix attach logic in GuestViewBase::DidAttach(). Created 6 years 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 "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
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
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();
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
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() { 616 double WebViewGuest::GetZoom() {
Fady Samuel 2014/12/09 20:09:47 Now that this method is trivial I'd make this a si
wjmaclean 2014/12/09 20:50:04 Done.
621 if (!web_view_guest_delegate_) 617 return current_zoom_factor_;
622 return 1.0;
623 return web_view_guest_delegate_->GetZoom();
624 } 618 }
625 619
626 void WebViewGuest::StartFinding( 620 void WebViewGuest::StartFinding(
627 const base::string16& search_text, 621 const base::string16& search_text,
628 const blink::WebFindOptions& options, 622 const blink::WebFindOptions& options,
629 scoped_refptr<WebViewInternalFindFunction> find_function) { 623 scoped_refptr<WebViewInternalFindFunction> find_function) {
630 find_helper_.Find(web_contents(), search_text, options, find_function); 624 find_helper_.Find(web_contents(), search_text, options, find_function);
631 } 625 }
632 626
633 void WebViewGuest::StopFinding(content::StopFindAction action) { 627 void WebViewGuest::StopFinding(content::StopFindAction action) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 content::WebContents* owner_web_contents, 696 content::WebContents* owner_web_contents,
703 int guest_instance_id) 697 int guest_instance_id)
704 : GuestView<WebViewGuest>(browser_context, 698 : GuestView<WebViewGuest>(browser_context,
705 owner_web_contents, 699 owner_web_contents,
706 guest_instance_id), 700 guest_instance_id),
707 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID), 701 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID),
708 find_helper_(this), 702 find_helper_(this),
709 is_overriding_user_agent_(false), 703 is_overriding_user_agent_(false),
710 guest_opaque_(true), 704 guest_opaque_(true),
711 javascript_dialog_helper_(this), 705 javascript_dialog_helper_(this),
712 weak_ptr_factory_(this) { 706 weak_ptr_factory_(this),
707 current_zoom_factor_(1.0) {
Fady Samuel 2014/12/09 20:09:46 weak_ptr_factory_ must be the last member variable
wjmaclean 2014/12/09 20:50:04 Done.
713 web_view_guest_delegate_.reset( 708 web_view_guest_delegate_.reset(
714 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); 709 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this));
715 } 710 }
716 711
717 WebViewGuest::~WebViewGuest() { 712 WebViewGuest::~WebViewGuest() {
718 } 713 }
719 714
720 void WebViewGuest::DidCommitProvisionalLoadForFrame( 715 void WebViewGuest::DidCommitProvisionalLoadForFrame(
721 content::RenderFrameHost* render_frame_host, 716 content::RenderFrameHost* render_frame_host,
722 const GURL& url, 717 const GURL& url,
(...skipping 12 matching lines...) Expand all
735 args->SetInteger(webview::kInternalCurrentEntryIndex, 730 args->SetInteger(webview::kInternalCurrentEntryIndex,
736 web_contents()->GetController().GetCurrentEntryIndex()); 731 web_contents()->GetController().GetCurrentEntryIndex());
737 args->SetInteger(webview::kInternalEntryCount, 732 args->SetInteger(webview::kInternalEntryCount,
738 web_contents()->GetController().GetEntryCount()); 733 web_contents()->GetController().GetEntryCount());
739 args->SetInteger(webview::kInternalProcessId, 734 args->SetInteger(webview::kInternalProcessId,
740 web_contents()->GetRenderProcessHost()->GetID()); 735 web_contents()->GetRenderProcessHost()->GetID());
741 DispatchEventToEmbedder( 736 DispatchEventToEmbedder(
742 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass())); 737 new GuestViewBase::Event(webview::kEventLoadCommit, args.Pass()));
743 738
744 find_helper_.CancelAllFindSessions(); 739 find_helper_.CancelAllFindSessions();
740
741 // Update the current zoom factor for the new page.
742 ui_zoom::ZoomController* zoom_controller =
743 ui_zoom::ZoomController::FromWebContents(web_contents());
744 DCHECK(zoom_controller);
745 current_zoom_factor_ =
746 content::ZoomLevelToZoomFactor(zoom_controller->GetZoomLevel());
747
745 if (web_view_guest_delegate_) { 748 if (web_view_guest_delegate_) {
746 web_view_guest_delegate_->OnDidCommitProvisionalLoadForFrame( 749 web_view_guest_delegate_->OnDidCommitProvisionalLoadForFrame(
747 !render_frame_host->GetParent()); 750 !render_frame_host->GetParent());
748 } 751 }
749 } 752 }
750 753
751 void WebViewGuest::DidFailProvisionalLoad( 754 void WebViewGuest::DidFailProvisionalLoad(
752 content::RenderFrameHost* render_frame_host, 755 content::RenderFrameHost* render_frame_host,
753 const GURL& validated_url, 756 const GURL& validated_url,
754 int error_code, 757 int error_code,
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 1058
1056 void WebViewGuest::SetName(const std::string& name) { 1059 void WebViewGuest::SetName(const std::string& name) {
1057 if (name_ == name) 1060 if (name_ == name)
1058 return; 1061 return;
1059 name_ = name; 1062 name_ = name;
1060 1063
1061 Send(new ExtensionMsg_SetFrameName(routing_id(), name_)); 1064 Send(new ExtensionMsg_SetFrameName(routing_id(), name_));
1062 } 1065 }
1063 1066
1064 void WebViewGuest::SetZoom(double zoom_factor) { 1067 void WebViewGuest::SetZoom(double zoom_factor) {
1065 if (web_view_guest_delegate_) 1068 ui_zoom::ZoomController* zoom_controller =
1066 web_view_guest_delegate_->OnSetZoom(zoom_factor); 1069 ui_zoom:: ZoomController::FromWebContents(web_contents());
1070 DCHECK(zoom_controller);
1071 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor);
1072 zoom_controller->SetZoomLevel(zoom_level);
1073
1074 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1075 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_);
1076 args->SetDouble(webview::kNewZoomFactor, zoom_factor);
1077 DispatchEventToEmbedder(
1078 new GuestViewBase::Event(webview::kEventZoomChange, args.Pass()));
1079 current_zoom_factor_ = zoom_factor;
1067 } 1080 }
1068 1081
1069 void WebViewGuest::SetAllowTransparency(bool allow) { 1082 void WebViewGuest::SetAllowTransparency(bool allow) {
1070 if (guest_opaque_ != allow) 1083 if (guest_opaque_ != allow)
1071 return; 1084 return;
1072 1085
1073 guest_opaque_ = !allow; 1086 guest_opaque_ = !allow;
1074 if (!web_contents()->GetRenderViewHost()->GetView()) 1087 if (!web_contents()->GetRenderViewHost()->GetView())
1075 return; 1088 return;
1076 1089
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 WebViewGuest* guest = 1273 WebViewGuest* guest =
1261 WebViewGuest::From(owner_render_process_id(), new_window_instance_id); 1274 WebViewGuest::From(owner_render_process_id(), new_window_instance_id);
1262 if (!guest) 1275 if (!guest)
1263 return; 1276 return;
1264 1277
1265 if (!allow) 1278 if (!allow)
1266 guest->Destroy(); 1279 guest->Destroy();
1267 } 1280 }
1268 1281
1269 } // namespace extensions 1282 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698