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

Side by Side Diff: components/guest_view/browser/guest_view_base.cc

Issue 1307243002: Cleanup content:: prefixes in GuestView files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months 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
« no previous file with comments | « no previous file | extensions/browser/guest_view/app_view/app_view_guest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/guest_view/browser/guest_view_base.h" 5 #include "components/guest_view/browser/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/guest_view/browser/guest_view_event.h" 9 #include "components/guest_view/browser/guest_view_event.h"
10 #include "components/guest_view/browser/guest_view_manager.h" 10 #include "components/guest_view/browser/guest_view_manager.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 } 43 }
44 SetSizeParams::~SetSizeParams() { 44 SetSizeParams::~SetSizeParams() {
45 } 45 }
46 46
47 // This observer ensures that the GuestViewBase destroys itself when its 47 // This observer ensures that the GuestViewBase destroys itself when its
48 // embedder goes away. It also tracks when the embedder's fullscreen is 48 // embedder goes away. It also tracks when the embedder's fullscreen is
49 // toggled so the guest can change itself accordingly. 49 // toggled so the guest can change itself accordingly.
50 class GuestViewBase::OwnerContentsObserver : public WebContentsObserver { 50 class GuestViewBase::OwnerContentsObserver : public WebContentsObserver {
51 public: 51 public:
52 OwnerContentsObserver(GuestViewBase* guest, 52 OwnerContentsObserver(GuestViewBase* guest,
53 content::WebContents* embedder_web_contents) 53 WebContents* embedder_web_contents)
54 : WebContentsObserver(embedder_web_contents), 54 : WebContentsObserver(embedder_web_contents),
55 is_fullscreen_(false), 55 is_fullscreen_(false),
56 destroyed_(false), 56 destroyed_(false),
57 guest_(guest) {} 57 guest_(guest) {}
58 58
59 ~OwnerContentsObserver() override {} 59 ~OwnerContentsObserver() override {}
60 60
61 // WebContentsObserver implementation. 61 // WebContentsObserver implementation.
62 void WebContentsDestroyed() override { 62 void WebContentsDestroyed() override {
63 // If the embedder is destroyed then destroy the guest. 63 // If the embedder is destroyed then destroy the guest.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // If the opener is destroyed then destroy the guest. 133 // If the opener is destroyed then destroy the guest.
134 guest_->Destroy(); 134 guest_->Destroy();
135 } 135 }
136 136
137 private: 137 private:
138 GuestViewBase* guest_; 138 GuestViewBase* guest_;
139 139
140 DISALLOW_COPY_AND_ASSIGN(OpenerLifetimeObserver); 140 DISALLOW_COPY_AND_ASSIGN(OpenerLifetimeObserver);
141 }; 141 };
142 142
143 GuestViewBase::GuestViewBase(content::WebContents* owner_web_contents) 143 GuestViewBase::GuestViewBase(WebContents* owner_web_contents)
144 : owner_web_contents_(owner_web_contents), 144 : owner_web_contents_(owner_web_contents),
145 browser_context_(owner_web_contents->GetBrowserContext()), 145 browser_context_(owner_web_contents->GetBrowserContext()),
146 guest_instance_id_( 146 guest_instance_id_(GuestViewManager::FromBrowserContext(browser_context_)
147 GuestViewManager::FromBrowserContext(browser_context_)-> 147 ->GetNextInstanceID()),
148 GetNextInstanceID()),
149 view_instance_id_(kInstanceIDNone), 148 view_instance_id_(kInstanceIDNone),
150 element_instance_id_(kInstanceIDNone), 149 element_instance_id_(kInstanceIDNone),
151 initialized_(false), 150 initialized_(false),
152 is_being_destroyed_(false), 151 is_being_destroyed_(false),
153 guest_host_(nullptr), 152 guest_host_(nullptr),
154 auto_size_enabled_(false), 153 auto_size_enabled_(false),
155 is_full_page_plugin_(false), 154 is_full_page_plugin_(false),
156 guest_proxy_routing_id_(MSG_ROUTING_NONE), 155 guest_proxy_routing_id_(MSG_ROUTING_NONE),
157 weak_ptr_factory_(this) { 156 weak_ptr_factory_(this) {
158 owner_host_ = GuestViewManager::FromBrowserContext(browser_context_)-> 157 owner_host_ = GuestViewManager::FromBrowserContext(browser_context_)->
(...skipping 19 matching lines...) Expand all
178 scoped_ptr<base::DictionaryValue> params(create_params.DeepCopy()); 177 scoped_ptr<base::DictionaryValue> params(create_params.DeepCopy());
179 CreateWebContents(create_params, 178 CreateWebContents(create_params,
180 base::Bind(&GuestViewBase::CompleteInit, 179 base::Bind(&GuestViewBase::CompleteInit,
181 weak_ptr_factory_.GetWeakPtr(), 180 weak_ptr_factory_.GetWeakPtr(),
182 base::Passed(&params), 181 base::Passed(&params),
183 callback)); 182 callback));
184 } 183 }
185 184
186 void GuestViewBase::InitWithWebContents( 185 void GuestViewBase::InitWithWebContents(
187 const base::DictionaryValue& create_params, 186 const base::DictionaryValue& create_params,
188 content::WebContents* guest_web_contents) { 187 WebContents* guest_web_contents) {
189 DCHECK(guest_web_contents); 188 DCHECK(guest_web_contents);
190 189
191 // Create a ZoomController to allow the guest's contents to be zoomed. 190 // Create a ZoomController to allow the guest's contents to be zoomed.
192 // Do this before adding the GuestView as a WebContents Observer so that 191 // Do this before adding the GuestView as a WebContents Observer so that
193 // the GuestView and its derived classes can re-configure the ZoomController 192 // the GuestView and its derived classes can re-configure the ZoomController
194 // after the latter has handled WebContentsObserver events (observers are 193 // after the latter has handled WebContentsObserver events (observers are
195 // notified of events in the same order they are added as observers). For 194 // notified of events in the same order they are added as observers). For
196 // example, GuestViewBase may wish to put its guest into isolated zoom mode 195 // example, GuestViewBase may wish to put its guest into isolated zoom mode
197 // in DidNavigateMainFrame, but since ZoomController always resets to default 196 // in DidNavigateMainFrame, but since ZoomController always resets to default
198 // zoom mode on this event, GuestViewBase would need to do so after 197 // zoom mode on this event, GuestViewBase would need to do so after
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 return it == guest_map->end() ? nullptr : it->second; 328 return it == guest_map->end() ? nullptr : it->second;
330 } 329 }
331 330
332 // static 331 // static
333 GuestViewBase* GuestViewBase::From(int owner_process_id, 332 GuestViewBase* GuestViewBase::From(int owner_process_id,
334 int guest_instance_id) { 333 int guest_instance_id) {
335 auto host = content::RenderProcessHost::FromID(owner_process_id); 334 auto host = content::RenderProcessHost::FromID(owner_process_id);
336 if (!host) 335 if (!host)
337 return nullptr; 336 return nullptr;
338 337
339 content::WebContents* guest_web_contents = 338 WebContents* guest_web_contents =
340 GuestViewManager::FromBrowserContext( 339 GuestViewManager::FromBrowserContext(host->GetBrowserContext())
341 host->GetBrowserContext())-> 340 ->GetGuestByInstanceIDSafely(guest_instance_id, owner_process_id);
342 GetGuestByInstanceIDSafely(guest_instance_id, owner_process_id);
343 if (!guest_web_contents) 341 if (!guest_web_contents)
344 return nullptr; 342 return nullptr;
345 343
346 return GuestViewBase::FromWebContents(guest_web_contents); 344 return GuestViewBase::FromWebContents(guest_web_contents);
347 } 345 }
348 346
349 // static 347 // static
350 WebContents* GuestViewBase::GetTopLevelWebContents(WebContents* web_contents) { 348 WebContents* GuestViewBase::GetTopLevelWebContents(WebContents* web_contents) {
351 while (GuestViewBase* guest = FromWebContents(web_contents)) 349 while (GuestViewBase* guest = FromWebContents(web_contents))
352 web_contents = guest->owner_web_contents(); 350 web_contents = guest->owner_web_contents();
(...skipping 10 matching lines...) Expand all
363 } 361 }
364 362
365 bool GuestViewBase::IsPreferredSizeModeEnabled() const { 363 bool GuestViewBase::IsPreferredSizeModeEnabled() const {
366 return false; 364 return false;
367 } 365 }
368 366
369 bool GuestViewBase::ZoomPropagatesFromEmbedderToGuest() const { 367 bool GuestViewBase::ZoomPropagatesFromEmbedderToGuest() const {
370 return true; 368 return true;
371 } 369 }
372 370
373 content::WebContents* GuestViewBase::CreateNewGuestWindow( 371 WebContents* GuestViewBase::CreateNewGuestWindow(
374 const content::WebContents::CreateParams& create_params) { 372 const WebContents::CreateParams& create_params) {
375 auto guest_manager = GuestViewManager::FromBrowserContext(browser_context()); 373 auto guest_manager = GuestViewManager::FromBrowserContext(browser_context());
376 return guest_manager->CreateGuestWithWebContentsParams( 374 return guest_manager->CreateGuestWithWebContentsParams(
377 GetViewType(), 375 GetViewType(),
378 owner_web_contents(), 376 owner_web_contents(),
379 create_params); 377 create_params);
380 } 378 }
381 379
382 void GuestViewBase::DidAttach(int guest_proxy_routing_id) { 380 void GuestViewBase::DidAttach(int guest_proxy_routing_id) {
383 DCHECK(guest_proxy_routing_id_ == MSG_ROUTING_NONE || 381 DCHECK(guest_proxy_routing_id_ == MSG_ROUTING_NONE ||
384 guest_proxy_routing_id == guest_proxy_routing_id_); 382 guest_proxy_routing_id == guest_proxy_routing_id_);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 return; 486 return;
489 } 487 }
490 opener_ = base::WeakPtr<GuestViewBase>(); 488 opener_ = base::WeakPtr<GuestViewBase>();
491 opener_lifetime_observer_.reset(); 489 opener_lifetime_observer_.reset();
492 } 490 }
493 491
494 void GuestViewBase::SetGuestHost(content::GuestHost* guest_host) { 492 void GuestViewBase::SetGuestHost(content::GuestHost* guest_host) {
495 guest_host_ = guest_host; 493 guest_host_ = guest_host;
496 } 494 }
497 495
498 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents, 496 void GuestViewBase::WillAttach(WebContents* embedder_web_contents,
499 int element_instance_id, 497 int element_instance_id,
500 bool is_full_page_plugin, 498 bool is_full_page_plugin,
501 const base::Closure& callback) { 499 const base::Closure& callback) {
502 // Stop tracking the old embedder's zoom level. 500 // Stop tracking the old embedder's zoom level.
503 if (owner_web_contents()) 501 if (owner_web_contents())
504 StopTrackingEmbedderZoomLevel(); 502 StopTrackingEmbedderZoomLevel();
505 503
506 if (owner_web_contents_ != embedder_web_contents) { 504 if (owner_web_contents_ != embedder_web_contents) {
507 DCHECK_EQ(owner_contents_observer_->web_contents(), owner_web_contents_); 505 DCHECK_EQ(owner_contents_observer_->web_contents(), owner_web_contents_);
508 owner_web_contents_ = embedder_web_contents; 506 owner_web_contents_ = embedder_web_contents;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 } 592 }
595 593
596 void GuestViewBase::DeactivateContents(WebContents* web_contents) { 594 void GuestViewBase::DeactivateContents(WebContents* web_contents) {
597 if (!attached() || !embedder_web_contents()->GetDelegate()) 595 if (!attached() || !embedder_web_contents()->GetDelegate())
598 return; 596 return;
599 597
600 embedder_web_contents()->GetDelegate()->DeactivateContents( 598 embedder_web_contents()->GetDelegate()->DeactivateContents(
601 embedder_web_contents()); 599 embedder_web_contents());
602 } 600 }
603 601
604 void GuestViewBase::ContentsMouseEvent(content::WebContents* source, 602 void GuestViewBase::ContentsMouseEvent(WebContents* source,
605 const gfx::Point& location, 603 const gfx::Point& location,
606 bool motion) { 604 bool motion) {
607 if (!attached() || !embedder_web_contents()->GetDelegate()) 605 if (!attached() || !embedder_web_contents()->GetDelegate())
608 return; 606 return;
609 607
610 embedder_web_contents()->GetDelegate()->ContentsMouseEvent( 608 embedder_web_contents()->GetDelegate()->ContentsMouseEvent(
611 embedder_web_contents(), location, motion); 609 embedder_web_contents(), location, motion);
612 } 610 }
613 611
614 void GuestViewBase::ContentsZoomChange(bool zoom_in) { 612 void GuestViewBase::ContentsZoomChange(bool zoom_in) {
615 ui_zoom::PageZoom::Zoom( 613 ui_zoom::PageZoom::Zoom(
616 embedder_web_contents(), 614 embedder_web_contents(),
617 zoom_in ? content::PAGE_ZOOM_IN : content::PAGE_ZOOM_OUT); 615 zoom_in ? content::PAGE_ZOOM_IN : content::PAGE_ZOOM_OUT);
618 } 616 }
619 617
620 void GuestViewBase::HandleKeyboardEvent( 618 void GuestViewBase::HandleKeyboardEvent(
621 WebContents* source, 619 WebContents* source,
622 const content::NativeWebKeyboardEvent& event) { 620 const content::NativeWebKeyboardEvent& event) {
623 if (!attached()) 621 if (!attached())
624 return; 622 return;
625 623
626 // Send the keyboard events back to the embedder to reprocess them. 624 // Send the keyboard events back to the embedder to reprocess them.
627 embedder_web_contents()->GetDelegate()-> 625 embedder_web_contents()->GetDelegate()->
628 HandleKeyboardEvent(embedder_web_contents(), event); 626 HandleKeyboardEvent(embedder_web_contents(), event);
629 } 627 }
630 628
631 void GuestViewBase::LoadingStateChanged(content::WebContents* source, 629 void GuestViewBase::LoadingStateChanged(WebContents* source,
632 bool to_different_document) { 630 bool to_different_document) {
633 if (!attached() || !embedder_web_contents()->GetDelegate()) 631 if (!attached() || !embedder_web_contents()->GetDelegate())
634 return; 632 return;
635 633
636 embedder_web_contents()->GetDelegate()->LoadingStateChanged( 634 embedder_web_contents()->GetDelegate()->LoadingStateChanged(
637 embedder_web_contents(), to_different_document); 635 embedder_web_contents(), to_different_document);
638 } 636 }
639 637
640 content::ColorChooser* GuestViewBase::OpenColorChooser( 638 content::ColorChooser* GuestViewBase::OpenColorChooser(
641 WebContents* web_contents, 639 WebContents* web_contents,
(...skipping 12 matching lines...) Expand all
654 return; 652 return;
655 653
656 embedder_web_contents()->GetDelegate()->RunFileChooser(web_contents, params); 654 embedder_web_contents()->GetDelegate()->RunFileChooser(web_contents, params);
657 } 655 }
658 656
659 bool GuestViewBase::ShouldFocusPageAfterCrash() { 657 bool GuestViewBase::ShouldFocusPageAfterCrash() {
660 // Focus is managed elsewhere. 658 // Focus is managed elsewhere.
661 return false; 659 return false;
662 } 660 }
663 661
664 bool GuestViewBase::PreHandleGestureEvent(content::WebContents* source, 662 bool GuestViewBase::PreHandleGestureEvent(WebContents* source,
665 const blink::WebGestureEvent& event) { 663 const blink::WebGestureEvent& event) {
666 return event.type == blink::WebGestureEvent::GesturePinchBegin || 664 return event.type == blink::WebGestureEvent::GesturePinchBegin ||
667 event.type == blink::WebGestureEvent::GesturePinchUpdate || 665 event.type == blink::WebGestureEvent::GesturePinchUpdate ||
668 event.type == blink::WebGestureEvent::GesturePinchEnd; 666 event.type == blink::WebGestureEvent::GesturePinchEnd;
669 } 667 }
670 668
671 void GuestViewBase::UpdatePreferredSize( 669 void GuestViewBase::UpdatePreferredSize(WebContents* target_web_contents,
672 content::WebContents* target_web_contents, 670 const gfx::Size& pref_size) {
673 const gfx::Size& pref_size) {
674 // In theory it's not necessary to check IsPreferredSizeModeEnabled() because 671 // In theory it's not necessary to check IsPreferredSizeModeEnabled() because
675 // there will only be events if it was enabled in the first place. However, 672 // there will only be events if it was enabled in the first place. However,
676 // something else may have turned on preferred size mode, so double check. 673 // something else may have turned on preferred size mode, so double check.
677 DCHECK_EQ(web_contents(), target_web_contents); 674 DCHECK_EQ(web_contents(), target_web_contents);
678 if (IsPreferredSizeModeEnabled()) { 675 if (IsPreferredSizeModeEnabled()) {
679 OnPreferredSizeChanged(pref_size); 676 OnPreferredSizeChanged(pref_size);
680 } 677 }
681 } 678 }
682 679
683 void GuestViewBase::UpdateTargetURL(content::WebContents* source, 680 void GuestViewBase::UpdateTargetURL(WebContents* source, const GURL& url) {
684 const GURL& url) {
685 if (!attached() || !embedder_web_contents()->GetDelegate()) 681 if (!attached() || !embedder_web_contents()->GetDelegate())
686 return; 682 return;
687 683
688 embedder_web_contents()->GetDelegate()->UpdateTargetURL( 684 embedder_web_contents()->GetDelegate()->UpdateTargetURL(
689 embedder_web_contents(), url); 685 embedder_web_contents(), url);
690 } 686 }
691 687
692 bool GuestViewBase::ShouldResumeRequestsForCreatedWindow() { 688 bool GuestViewBase::ShouldResumeRequestsForCreatedWindow() {
693 return false; 689 return false;
694 } 690 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 while (!pending_events_.empty()) { 736 while (!pending_events_.empty()) {
741 linked_ptr<GuestViewEvent> event_ptr = pending_events_.front(); 737 linked_ptr<GuestViewEvent> event_ptr = pending_events_.front();
742 pending_events_.pop_front(); 738 pending_events_.pop_front();
743 event_ptr.release()->Dispatch(this, view_instance_id_); 739 event_ptr.release()->Dispatch(this, view_instance_id_);
744 } 740 }
745 } 741 }
746 742
747 void GuestViewBase::CompleteInit( 743 void GuestViewBase::CompleteInit(
748 scoped_ptr<base::DictionaryValue> create_params, 744 scoped_ptr<base::DictionaryValue> create_params,
749 const WebContentsCreatedCallback& callback, 745 const WebContentsCreatedCallback& callback,
750 content::WebContents* guest_web_contents) { 746 WebContents* guest_web_contents) {
751 if (!guest_web_contents) { 747 if (!guest_web_contents) {
752 // The derived class did not create a WebContents so this class serves no 748 // The derived class did not create a WebContents so this class serves no
753 // purpose. Let's self-destruct. 749 // purpose. Let's self-destruct.
754 delete this; 750 delete this;
755 callback.Run(nullptr); 751 callback.Run(nullptr);
756 return; 752 return;
757 } 753 }
758 InitWithWebContents(*create_params, guest_web_contents); 754 InitWithWebContents(*create_params, guest_web_contents);
759 callback.Run(guest_web_contents); 755 callback.Run(guest_web_contents);
760 } 756 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 844
849 auto embedder_zoom_controller = 845 auto embedder_zoom_controller =
850 ui_zoom::ZoomController::FromWebContents(owner_web_contents()); 846 ui_zoom::ZoomController::FromWebContents(owner_web_contents());
851 // Chrome Apps do not have a ZoomController. 847 // Chrome Apps do not have a ZoomController.
852 if (!embedder_zoom_controller) 848 if (!embedder_zoom_controller)
853 return; 849 return;
854 embedder_zoom_controller->RemoveObserver(this); 850 embedder_zoom_controller->RemoveObserver(this);
855 } 851 }
856 852
857 } // namespace guest_view 853 } // namespace guest_view
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/guest_view/app_view/app_view_guest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698