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

Side by Side Diff: extensions/browser/guest_view/guest_view_base.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/guest_view_base.h" 5 #include "extensions/browser/guest_view/guest_view_base.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "components/ui/zoom/zoom_controller.h"
9 #include "content/public/browser/navigation_details.h" 10 #include "content/public/browser/navigation_details.h"
10 #include "content/public/browser/render_frame_host.h" 11 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/browser/render_process_host.h" 12 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/render_view_host.h" 13 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/url_constants.h" 15 #include "content/public/common/url_constants.h"
15 #include "extensions/browser/api/extensions_api_client.h" 16 #include "extensions/browser/api/extensions_api_client.h"
16 #include "extensions/browser/event_router.h" 17 #include "extensions/browser/event_router.h"
17 #include "extensions/browser/extension_registry.h" 18 #include "extensions/browser/extension_registry.h"
18 #include "extensions/browser/guest_view/app_view/app_view_guest.h" 19 #include "extensions/browser/guest_view/app_view/app_view_guest.h"
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 owner_lifetime_observer_.reset( 203 owner_lifetime_observer_.reset(
203 new OwnerLifetimeObserver(this, owner_web_contents_)); 204 new OwnerLifetimeObserver(this, owner_web_contents_));
204 205
205 WebContentsObserver::Observe(guest_web_contents); 206 WebContentsObserver::Observe(guest_web_contents);
206 guest_web_contents->SetDelegate(this); 207 guest_web_contents->SetDelegate(this);
207 webcontents_guestview_map.Get().insert( 208 webcontents_guestview_map.Get().insert(
208 std::make_pair(guest_web_contents, this)); 209 std::make_pair(guest_web_contents, this));
209 GuestViewManager::FromBrowserContext(browser_context_)-> 210 GuestViewManager::FromBrowserContext(browser_context_)->
210 AddGuest(guest_instance_id_, guest_web_contents); 211 AddGuest(guest_instance_id_, guest_web_contents);
211 212
213 // Create a zoom controller for the guest contents give it access to
214 // GetZoomLevel() and and SetZoomLevel() in WebViewGuest.
Fady Samuel 2014/12/09 20:09:46 This comment is no longer correct as this code liv
wjmaclean 2014/12/09 20:50:04 Done.
215 // TODO(wjmaclean): Verify that |guest_web_contents| is the right value to
216 // pass here.
Fady Samuel 2014/12/09 20:09:46 This looks right to me.
wjmaclean 2014/12/09 20:50:04 Acknowledged.
217 ui_zoom::ZoomController::CreateForWebContents(guest_web_contents);
218
212 // Give the derived class an opportunity to perform additional initialization. 219 // Give the derived class an opportunity to perform additional initialization.
213 DidInitialize(); 220 DidInitialize();
214 } 221 }
215 222
216 void GuestViewBase::SetAutoSize(bool enabled, 223 void GuestViewBase::SetAutoSize(bool enabled,
217 const gfx::Size& min_size, 224 const gfx::Size& min_size,
218 const gfx::Size& max_size) { 225 const gfx::Size& max_size) {
219 min_auto_size_ = min_size; 226 min_auto_size_ = min_size;
220 min_auto_size_.SetToMin(max_size); 227 min_auto_size_.SetToMin(max_size);
221 max_auto_size_ = max_size; 228 max_auto_size_ = max_size;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 return NULL; 298 return NULL;
292 299
293 return GuestViewBase::FromWebContents(guest_web_contents); 300 return GuestViewBase::FromWebContents(guest_web_contents);
294 } 301 }
295 302
296 // static 303 // static
297 bool GuestViewBase::IsGuest(WebContents* web_contents) { 304 bool GuestViewBase::IsGuest(WebContents* web_contents) {
298 return !!GuestViewBase::FromWebContents(web_contents); 305 return !!GuestViewBase::FromWebContents(web_contents);
299 } 306 }
300 307
308 void GuestViewBase::EmbedderWillBeDestroyed() {
309 ui_zoom::ZoomController* zoom_controller =
310 ui_zoom::ZoomController::FromWebContents(embedder_web_contents());
311 if (!zoom_controller)
312 return;
313 zoom_controller->RemoveObserver(this);
314 }
315
301 bool GuestViewBase::IsAutoSizeSupported() const { 316 bool GuestViewBase::IsAutoSizeSupported() const {
302 return false; 317 return false;
303 } 318 }
304 319
305 bool GuestViewBase::IsDragAndDropEnabled() const { 320 bool GuestViewBase::IsDragAndDropEnabled() const {
306 return false; 321 return false;
307 } 322 }
308 323
309 void GuestViewBase::DidAttach(int guest_proxy_routing_id) { 324 void GuestViewBase::DidAttach(int guest_proxy_routing_id) {
310 opener_lifetime_observer_.reset(); 325 opener_lifetime_observer_.reset();
311 326
327 // Any zoom events from the embedder should be relayed to the guest.
328 ui_zoom::ZoomController* zoom_controller =
329 ui_zoom::ZoomController::FromWebContents(embedder_web_contents());
330 if (zoom_controller) {
331 // Listen to the embedder's zoom changes.
332 zoom_controller->AddObserver(this);
333 // Set the guest's initial zoom level to be equal to the embedder's.
334 ui_zoom::ZoomController::FromWebContents(web_contents())
335 ->SetZoomLevel(zoom_controller->GetZoomLevel());
336 }
337
312 // Give the derived class an opportunity to perform some actions. 338 // Give the derived class an opportunity to perform some actions.
313 DidAttachToEmbedder(); 339 DidAttachToEmbedder();
314 340
315 // Inform the associated GuestViewContainer that the contentWindow is ready. 341 // Inform the associated GuestViewContainer that the contentWindow is ready.
316 embedder_web_contents()->Send(new ExtensionMsg_GuestAttached( 342 embedder_web_contents()->Send(new ExtensionMsg_GuestAttached(
317 embedder_web_contents()->GetMainFrame()->GetRoutingID(), 343 embedder_web_contents()->GetMainFrame()->GetRoutingID(),
318 element_instance_id_, 344 element_instance_id_,
319 guest_proxy_routing_id)); 345 guest_proxy_routing_id));
320 346
321 SendQueuedEvents(); 347 SendQueuedEvents();
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 bool GuestViewBase::PreHandleGestureEvent(content::WebContents* source, 504 bool GuestViewBase::PreHandleGestureEvent(content::WebContents* source,
479 const blink::WebGestureEvent& event) { 505 const blink::WebGestureEvent& event) {
480 return event.type == blink::WebGestureEvent::GesturePinchBegin || 506 return event.type == blink::WebGestureEvent::GesturePinchBegin ||
481 event.type == blink::WebGestureEvent::GesturePinchUpdate || 507 event.type == blink::WebGestureEvent::GesturePinchUpdate ||
482 event.type == blink::WebGestureEvent::GesturePinchEnd; 508 event.type == blink::WebGestureEvent::GesturePinchEnd;
483 } 509 }
484 510
485 GuestViewBase::~GuestViewBase() { 511 GuestViewBase::~GuestViewBase() {
486 } 512 }
487 513
514 void GuestViewBase::OnZoomChanged(
515 const ui_zoom::ZoomController::ZoomChangedEventData& data) {
516 ui_zoom::ZoomController::FromWebContents(web_contents())
Fady Samuel 2014/12/09 20:09:46 It would be nice to add a comment here that updati
wjmaclean 2014/12/09 20:50:04 Done.
517 ->SetZoomLevel(data.new_zoom_level);
518 }
519
488 void GuestViewBase::DispatchEventToEmbedder(Event* event) { 520 void GuestViewBase::DispatchEventToEmbedder(Event* event) {
489 scoped_ptr<Event> event_ptr(event); 521 scoped_ptr<Event> event_ptr(event);
490 522
491 if (!attached()) { 523 if (!attached()) {
492 pending_events_.push_back(linked_ptr<Event>(event_ptr.release())); 524 pending_events_.push_back(linked_ptr<Event>(event_ptr.release()));
493 return; 525 return;
494 } 526 }
495 527
496 EventFilteringInfo info; 528 EventFilteringInfo info;
497 info.SetInstanceID(view_instance_id_); 529 info.SetInstanceID(view_instance_id_);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 566
535 // static 567 // static
536 void GuestViewBase::RegisterGuestViewTypes() { 568 void GuestViewBase::RegisterGuestViewTypes() {
537 AppViewGuest::Register(); 569 AppViewGuest::Register();
538 ExtensionOptionsGuest::Register(); 570 ExtensionOptionsGuest::Register();
539 MimeHandlerViewGuest::Register(); 571 MimeHandlerViewGuest::Register();
540 WebViewGuest::Register(); 572 WebViewGuest::Register();
541 } 573 }
542 574
543 } // namespace extensions 575 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698