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

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

Issue 2666363002: Convert GuestViewBase to use the new navigation callbacks. (Closed)
Patch Set: Created 3 years, 10 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 | « components/guest_view/browser/guest_view_base.h ('k') | no next file » | 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 <utility> 7 #include <utility>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "components/guest_view/browser/guest_view_event.h" 13 #include "components/guest_view/browser/guest_view_event.h"
14 #include "components/guest_view/browser/guest_view_manager.h" 14 #include "components/guest_view/browser/guest_view_manager.h"
15 #include "components/guest_view/common/guest_view_constants.h" 15 #include "components/guest_view/common/guest_view_constants.h"
16 #include "components/guest_view/common/guest_view_messages.h" 16 #include "components/guest_view/common/guest_view_messages.h"
17 #include "components/zoom/page_zoom.h" 17 #include "components/zoom/page_zoom.h"
18 #include "components/zoom/zoom_controller.h" 18 #include "components/zoom/zoom_controller.h"
19 #include "content/public/browser/navigation_details.h" 19 #include "content/public/browser/navigation_handle.h"
20 #include "content/public/browser/render_frame_host.h" 20 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/render_process_host.h" 21 #include "content/public/browser/render_process_host.h"
22 #include "content/public/browser/render_view_host.h" 22 #include "content/public/browser/render_view_host.h"
23 #include "content/public/browser/render_widget_host.h" 23 #include "content/public/browser/render_widget_host.h"
24 #include "content/public/browser/render_widget_host_view.h" 24 #include "content/public/browser/render_widget_host_view.h"
25 #include "content/public/browser/site_instance.h" 25 #include "content/public/browser/site_instance.h"
26 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
27 #include "content/public/common/page_zoom.h" 27 #include "content/public/common/page_zoom.h"
28 #include "content/public/common/url_constants.h" 28 #include "content/public/common/url_constants.h"
29 #include "third_party/WebKit/public/platform/WebGestureEvent.h" 29 #include "third_party/WebKit/public/platform/WebGestureEvent.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 guest_(guest) {} 63 guest_(guest) {}
64 64
65 ~OwnerContentsObserver() override {} 65 ~OwnerContentsObserver() override {}
66 66
67 // WebContentsObserver implementation. 67 // WebContentsObserver implementation.
68 void WebContentsDestroyed() override { 68 void WebContentsDestroyed() override {
69 // If the embedder is destroyed then destroy the guest. 69 // If the embedder is destroyed then destroy the guest.
70 Destroy(); 70 Destroy();
71 } 71 }
72 72
73 void DidNavigateMainFrame( 73 void DidFinishNavigation(
74 const content::LoadCommittedDetails& details, 74 content::NavigationHandle* navigation_handle) override {
75 const content::FrameNavigateParams& params) override {
76 // If the embedder navigates to a different page then destroy the guest. 75 // If the embedder navigates to a different page then destroy the guest.
77 if (details.is_navigation_to_different_page()) 76 if (!navigation_handle->IsInMainFrame() ||
78 Destroy(); 77 !navigation_handle->HasCommitted() ||
78 navigation_handle->IsSamePage()) {
79 return;
80 }
81
82 Destroy();
79 } 83 }
80 84
81 void RenderProcessGone(base::TerminationStatus status) override { 85 void RenderProcessGone(base::TerminationStatus status) override {
82 if (destroyed_) 86 if (destroyed_)
83 return; 87 return;
84 // If the embedder process is destroyed, then destroy the guest. 88 // If the embedder process is destroyed, then destroy the guest.
85 Destroy(); 89 Destroy();
86 } 90 }
87 91
88 void DidToggleFullscreenModeForTab(bool entered_fullscreen, 92 void DidToggleFullscreenModeForTab(bool entered_fullscreen,
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 const base::DictionaryValue& create_params, 218 const base::DictionaryValue& create_params,
215 WebContents* guest_web_contents) { 219 WebContents* guest_web_contents) {
216 DCHECK(guest_web_contents); 220 DCHECK(guest_web_contents);
217 221
218 // Create a ZoomController to allow the guest's contents to be zoomed. 222 // Create a ZoomController to allow the guest's contents to be zoomed.
219 // Do this before adding the GuestView as a WebContents Observer so that 223 // Do this before adding the GuestView as a WebContents Observer so that
220 // the GuestView and its derived classes can re-configure the ZoomController 224 // the GuestView and its derived classes can re-configure the ZoomController
221 // after the latter has handled WebContentsObserver events (observers are 225 // after the latter has handled WebContentsObserver events (observers are
222 // notified of events in the same order they are added as observers). For 226 // notified of events in the same order they are added as observers). For
223 // example, GuestViewBase may wish to put its guest into isolated zoom mode 227 // example, GuestViewBase may wish to put its guest into isolated zoom mode
224 // in DidNavigateMainFrame, but since ZoomController always resets to default 228 // in DidFinishNavigation, but since ZoomController always resets to default
225 // zoom mode on this event, GuestViewBase would need to do so after 229 // zoom mode on this event, GuestViewBase would need to do so after
226 // ZoomController::DidNavigateMainFrame has completed. 230 // ZoomController::DidFinishNavigation has completed.
227 zoom::ZoomController::CreateForWebContents(guest_web_contents); 231 zoom::ZoomController::CreateForWebContents(guest_web_contents);
228 232
229 // At this point, we have just created the guest WebContents, we need to add 233 // At this point, we have just created the guest WebContents, we need to add
230 // an observer to the owner WebContents. This observer will be responsible 234 // an observer to the owner WebContents. This observer will be responsible
231 // for destroying the guest WebContents if the owner goes away. 235 // for destroying the guest WebContents if the owner goes away.
232 owner_contents_observer_.reset( 236 owner_contents_observer_.reset(
233 new OwnerContentsObserver(this, owner_web_contents_)); 237 new OwnerContentsObserver(this, owner_web_contents_));
234 238
235 WebContentsObserver::Observe(guest_web_contents); 239 WebContentsObserver::Observe(guest_web_contents);
236 guest_web_contents->SetDelegate(this); 240 guest_web_contents->SetDelegate(this);
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 // being destroyed. web_contents() is still valid at this point. 602 // being destroyed. web_contents() is still valid at this point.
599 // TODO(fsamuel): This allows for reentrant code into WebContents during 603 // TODO(fsamuel): This allows for reentrant code into WebContents during
600 // destruction. This could potentially lead to bugs. Perhaps we should get rid 604 // destruction. This could potentially lead to bugs. Perhaps we should get rid
601 // of this? 605 // of this?
602 GuestDestroyed(); 606 GuestDestroyed();
603 607
604 // Self-destruct. 608 // Self-destruct.
605 delete this; 609 delete this;
606 } 610 }
607 611
608 void GuestViewBase::DidNavigateMainFrame( 612 void GuestViewBase::DidFinishNavigation(
609 const content::LoadCommittedDetails& details, 613 content::NavigationHandle* navigation_handle) {
610 const content::FrameNavigateParams& params) { 614 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted())
615 return;
616
611 if (attached() && ZoomPropagatesFromEmbedderToGuest()) 617 if (attached() && ZoomPropagatesFromEmbedderToGuest())
612 SetGuestZoomLevelToMatchEmbedder(); 618 SetGuestZoomLevelToMatchEmbedder();
613 } 619 }
614 620
615 void GuestViewBase::ActivateContents(WebContents* web_contents) { 621 void GuestViewBase::ActivateContents(WebContents* web_contents) {
616 if (!attached() || !embedder_web_contents()->GetDelegate()) 622 if (!attached() || !embedder_web_contents()->GetDelegate())
617 return; 623 return;
618 624
619 embedder_web_contents()->GetDelegate()->ActivateContents( 625 embedder_web_contents()->GetDelegate()->ActivateContents(
620 embedder_web_contents()); 626 embedder_web_contents());
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 926
921 void GuestViewBase::UpdateGuestSize(const gfx::Size& new_size, 927 void GuestViewBase::UpdateGuestSize(const gfx::Size& new_size,
922 bool due_to_auto_resize) { 928 bool due_to_auto_resize) {
923 if (due_to_auto_resize) 929 if (due_to_auto_resize)
924 GuestSizeChangedDueToAutoSize(guest_size_, new_size); 930 GuestSizeChangedDueToAutoSize(guest_size_, new_size);
925 DispatchOnResizeEvent(guest_size_, new_size); 931 DispatchOnResizeEvent(guest_size_, new_size);
926 guest_size_ = new_size; 932 guest_size_ = new_size;
927 } 933 }
928 934
929 } // namespace guest_view 935 } // namespace guest_view
OLDNEW
« no previous file with comments | « components/guest_view/browser/guest_view_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698