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

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

Issue 984963004: <webview>: Implement fullscreen permission for html5 element.requestFullscreen() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tmptmptmp
Patch Set: Disable one test one test on mac with bug ref, use document.webkitIsFullScreen Created 5 years, 9 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
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/page_zoom.h" 9 #include "components/ui/zoom/page_zoom.h"
10 #include "components/ui/zoom/zoom_controller.h" 10 #include "components/ui/zoom/zoom_controller.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 66
67 GuestViewBase::Event::~Event() { 67 GuestViewBase::Event::~Event() {
68 } 68 }
69 69
70 scoped_ptr<base::DictionaryValue> GuestViewBase::Event::GetArguments() { 70 scoped_ptr<base::DictionaryValue> GuestViewBase::Event::GetArguments() {
71 return args_.Pass(); 71 return args_.Pass();
72 } 72 }
73 73
74 // This observer ensures that the GuestViewBase destroys itself when its 74 // This observer ensures that the GuestViewBase destroys itself when its
75 // embedder goes away. 75 // embedder goes away. It also tracks when the embedder's fullscreen is
76 class GuestViewBase::OwnerLifetimeObserver : public WebContentsObserver { 76 // toggled so the guest can change itself accordingly.
77 class GuestViewBase::OwnerContentsObserver : public WebContentsObserver {
77 public: 78 public:
78 OwnerLifetimeObserver(GuestViewBase* guest, 79 OwnerContentsObserver(GuestViewBase* guest,
79 content::WebContents* embedder_web_contents) 80 content::WebContents* embedder_web_contents)
80 : WebContentsObserver(embedder_web_contents), 81 : WebContentsObserver(embedder_web_contents),
82 is_fullscreen_(false),
81 destroyed_(false), 83 destroyed_(false),
82 guest_(guest) {} 84 guest_(guest) {}
83 85
84 ~OwnerLifetimeObserver() override {} 86 ~OwnerContentsObserver() override {}
85 87
86 // WebContentsObserver implementation. 88 // WebContentsObserver implementation.
87 void WebContentsDestroyed() override { 89 void WebContentsDestroyed() override {
88 // If the embedder is destroyed then destroy the guest. 90 // If the embedder is destroyed then destroy the guest.
89 Destroy(); 91 Destroy();
90 } 92 }
91 93
92 void DidNavigateMainFrame( 94 void DidNavigateMainFrame(
93 const content::LoadCommittedDetails& details, 95 const content::LoadCommittedDetails& details,
94 const content::FrameNavigateParams& params) override { 96 const content::FrameNavigateParams& params) override {
95 // If the embedder navigates to a different page then destroy the guest. 97 // If the embedder navigates to a different page then destroy the guest.
96 if (details.is_navigation_to_different_page()) 98 if (details.is_navigation_to_different_page())
97 Destroy(); 99 Destroy();
98 } 100 }
99 101
100 void RenderProcessGone(base::TerminationStatus status) override { 102 void RenderProcessGone(base::TerminationStatus status) override {
101 // If the embedder crashes, then destroy the guest. 103 // If the embedder crashes, then destroy the guest.
102 Destroy(); 104 Destroy();
103 } 105 }
104 106
107 void DidToggleFullscreenModeForTab(bool entered_fullscreen) override {
108 if (destroyed_)
109 return;
110
111 is_fullscreen_ = entered_fullscreen;
112 guest_->EmbedderFullscreenToggled(is_fullscreen_);
113 }
114
115 void MainFrameWasResized(bool width_changed) override {
116 if (destroyed_)
117 return;
118
119 if (!web_contents()->GetDelegate())
120 return;
121
122 bool current_fullscreen =
123 web_contents()->GetDelegate()->IsFullscreenForTabOrPending(
124 web_contents());
125 if (is_fullscreen_ && !current_fullscreen) {
126 is_fullscreen_ = false;
127 guest_->EmbedderFullscreenToggled(is_fullscreen_);
128 }
129 }
130
105 private: 131 private:
132 bool is_fullscreen_;
106 bool destroyed_; 133 bool destroyed_;
107 GuestViewBase* guest_; 134 GuestViewBase* guest_;
108 135
109 void Destroy() { 136 void Destroy() {
110 if (destroyed_) 137 if (destroyed_)
111 return; 138 return;
112 139
113 destroyed_ = true; 140 destroyed_ = true;
114 guest_->EmbedderWillBeDestroyed(); 141 guest_->EmbedderWillBeDestroyed();
115 guest_->Destroy(); 142 guest_->Destroy();
116 } 143 }
117 144
118 DISALLOW_COPY_AND_ASSIGN(OwnerLifetimeObserver); 145 DISALLOW_COPY_AND_ASSIGN(OwnerContentsObserver);
119 }; 146 };
120 147
121 // This observer ensures that the GuestViewBase destroys itself when its 148 // This observer ensures that the GuestViewBase destroys itself when its
122 // embedder goes away. 149 // embedder goes away.
123 class GuestViewBase::OpenerLifetimeObserver : public WebContentsObserver { 150 class GuestViewBase::OpenerLifetimeObserver : public WebContentsObserver {
124 public: 151 public:
125 OpenerLifetimeObserver(GuestViewBase* guest) 152 OpenerLifetimeObserver(GuestViewBase* guest)
126 : WebContentsObserver(guest->GetOpener()->web_contents()), 153 : WebContentsObserver(guest->GetOpener()->web_contents()),
127 guest_(guest) {} 154 guest_(guest) {}
128 155
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 } 229 }
203 230
204 void GuestViewBase::InitWithWebContents( 231 void GuestViewBase::InitWithWebContents(
205 const base::DictionaryValue& create_params, 232 const base::DictionaryValue& create_params,
206 content::WebContents* guest_web_contents) { 233 content::WebContents* guest_web_contents) {
207 DCHECK(guest_web_contents); 234 DCHECK(guest_web_contents);
208 235
209 // At this point, we have just created the guest WebContents, we need to add 236 // At this point, we have just created the guest WebContents, we need to add
210 // an observer to the owner WebContents. This observer will be responsible 237 // an observer to the owner WebContents. This observer will be responsible
211 // for destroying the guest WebContents if the owner goes away. 238 // for destroying the guest WebContents if the owner goes away.
212 owner_lifetime_observer_.reset( 239 owner_contents_observer_.reset(
213 new OwnerLifetimeObserver(this, owner_web_contents_)); 240 new OwnerContentsObserver(this, owner_web_contents_));
214 241
215 WebContentsObserver::Observe(guest_web_contents); 242 WebContentsObserver::Observe(guest_web_contents);
216 guest_web_contents->SetDelegate(this); 243 guest_web_contents->SetDelegate(this);
217 webcontents_guestview_map.Get().insert( 244 webcontents_guestview_map.Get().insert(
218 std::make_pair(guest_web_contents, this)); 245 std::make_pair(guest_web_contents, this));
219 GuestViewManager::FromBrowserContext(browser_context_)-> 246 GuestViewManager::FromBrowserContext(browser_context_)->
220 AddGuest(guest_instance_id_, guest_web_contents); 247 AddGuest(guest_instance_id_, guest_web_contents);
221 248
222 // Create a ZoomController to allow the guest's contents to be zoomed. 249 // Create a ZoomController to allow the guest's contents to be zoomed.
223 ui_zoom::ZoomController::CreateForWebContents(guest_web_contents); 250 ui_zoom::ZoomController::CreateForWebContents(guest_web_contents);
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 } 510 }
484 511
485 void GuestViewBase::SetGuestHost(content::GuestHost* guest_host) { 512 void GuestViewBase::SetGuestHost(content::GuestHost* guest_host) {
486 guest_host_ = guest_host; 513 guest_host_ = guest_host;
487 } 514 }
488 515
489 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents, 516 void GuestViewBase::WillAttach(content::WebContents* embedder_web_contents,
490 int element_instance_id, 517 int element_instance_id,
491 bool is_full_page_plugin) { 518 bool is_full_page_plugin) {
492 if (owner_web_contents_ != embedder_web_contents) { 519 if (owner_web_contents_ != embedder_web_contents) {
493 DCHECK_EQ(owner_lifetime_observer_->web_contents(), owner_web_contents_); 520 DCHECK_EQ(owner_contents_observer_->web_contents(), owner_web_contents_);
494 // Stop tracking the old embedder's zoom level. 521 // Stop tracking the old embedder's zoom level.
495 StopTrackingEmbedderZoomLevel(); 522 StopTrackingEmbedderZoomLevel();
496 owner_web_contents_ = embedder_web_contents; 523 owner_web_contents_ = embedder_web_contents;
497 owner_lifetime_observer_.reset( 524 owner_contents_observer_.reset(
498 new OwnerLifetimeObserver(this, embedder_web_contents)); 525 new OwnerContentsObserver(this, embedder_web_contents));
499 } 526 }
500 527
501 // Start tracking the new embedder's zoom level. 528 // Start tracking the new embedder's zoom level.
502 StartTrackingEmbedderZoomLevel(); 529 StartTrackingEmbedderZoomLevel();
503 element_instance_id_ = element_instance_id; 530 element_instance_id_ = element_instance_id;
504 is_full_page_plugin_ = is_full_page_plugin; 531 is_full_page_plugin_ = is_full_page_plugin;
505 532
506 WillAttachToEmbedder(); 533 WillAttachToEmbedder();
507 } 534 }
508 535
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 void GuestViewBase::RegisterGuestViewTypes() { 846 void GuestViewBase::RegisterGuestViewTypes() {
820 AppViewGuest::Register(); 847 AppViewGuest::Register();
821 ExtensionOptionsGuest::Register(); 848 ExtensionOptionsGuest::Register();
822 ExtensionViewGuest::Register(); 849 ExtensionViewGuest::Register();
823 MimeHandlerViewGuest::Register(); 850 MimeHandlerViewGuest::Register();
824 SurfaceWorkerGuest::Register(); 851 SurfaceWorkerGuest::Register();
825 WebViewGuest::Register(); 852 WebViewGuest::Register();
826 } 853 }
827 854
828 } // namespace extensions 855 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/guest_view/guest_view_base.h ('k') | extensions/browser/guest_view/web_view/web_view_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698