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

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

Powered by Google App Engine
This is Rietveld 408576698