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

Side by Side Diff: extensions/browser/guest_view/web_view/web_view_guest.cc

Issue 984963004: <webview>: Implement fullscreen permission for html5 element.requestFullscreen() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tmptmptmp
Patch Set: Clean up for review. 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/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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 web_view_guest_delegate_->OnAttachWebViewHelpers(contents); 314 web_view_guest_delegate_->OnAttachWebViewHelpers(contents);
315 web_view_permission_helper_.reset(new WebViewPermissionHelper(this)); 315 web_view_permission_helper_.reset(new WebViewPermissionHelper(this));
316 } 316 }
317 317
318 void WebViewGuest::DidStopLoading() { 318 void WebViewGuest::DidStopLoading() {
319 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 319 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
320 DispatchEventToView( 320 DispatchEventToView(
321 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); 321 new GuestViewBase::Event(webview::kEventLoadStop, args.Pass()));
322 } 322 }
323 323
324 void WebViewGuest::EmbedderFullscreenToggled(bool entered_fullscreen) {
325 is_embedder_fullscreen_ = entered_fullscreen;
326 // If the embedder has got out of fullscreen, we get out of fullscreen
327 // mode as well.
328 if (!entered_fullscreen)
329 SetFullscreenState(false);
330 }
331
324 void WebViewGuest::EmbedderWillBeDestroyed() { 332 void WebViewGuest::EmbedderWillBeDestroyed() {
325 // Clean up rules registries for the webview. 333 // Clean up rules registries for the webview.
326 RulesRegistryService::Get(browser_context()) 334 RulesRegistryService::Get(browser_context())
327 ->RemoveRulesRegistriesByID(rules_registry_id_); 335 ->RemoveRulesRegistriesByID(rules_registry_id_);
328 WebViewKey key(owner_web_contents()->GetRenderProcessHost()->GetID(), 336 WebViewKey key(owner_web_contents()->GetRenderProcessHost()->GetID(),
329 view_instance_id()); 337 view_instance_id());
330 web_view_key_to_id_map.Get().erase(key); 338 web_view_key_to_id_map.Get().erase(key);
331 339
332 content::BrowserThread::PostTask( 340 content::BrowserThread::PostTask(
333 content::BrowserThread::IO, 341 content::BrowserThread::IO,
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 641
634 WebViewGuest::WebViewGuest(content::WebContents* owner_web_contents) 642 WebViewGuest::WebViewGuest(content::WebContents* owner_web_contents)
635 : GuestView<WebViewGuest>(owner_web_contents), 643 : GuestView<WebViewGuest>(owner_web_contents),
636 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID), 644 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID),
637 find_helper_(this), 645 find_helper_(this),
638 is_overriding_user_agent_(false), 646 is_overriding_user_agent_(false),
639 guest_opaque_(true), 647 guest_opaque_(true),
640 javascript_dialog_helper_(this), 648 javascript_dialog_helper_(this),
641 current_zoom_factor_(1.0), 649 current_zoom_factor_(1.0),
642 allow_scaling_(false), 650 allow_scaling_(false),
651 is_guest_fullscreen_(false),
652 is_embedder_fullscreen_(false),
653 last_fullscreen_permission_was_allowed_by_embedder_(false),
643 weak_ptr_factory_(this) { 654 weak_ptr_factory_(this) {
644 web_view_guest_delegate_.reset( 655 web_view_guest_delegate_.reset(
645 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); 656 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this));
646 } 657 }
647 658
648 WebViewGuest::~WebViewGuest() { 659 WebViewGuest::~WebViewGuest() {
649 } 660 }
650 661
651 void WebViewGuest::DidCommitProvisionalLoadForFrame( 662 void WebViewGuest::DidCommitProvisionalLoadForFrame(
652 content::RenderFrameHost* render_frame_host, 663 content::RenderFrameHost* render_frame_host,
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 content::WebContents* new_contents) { 1162 content::WebContents* new_contents) {
1152 auto guest = WebViewGuest::FromWebContents(new_contents); 1163 auto guest = WebViewGuest::FromWebContents(new_contents);
1153 CHECK(guest); 1164 CHECK(guest);
1154 guest->SetOpener(this); 1165 guest->SetOpener(this);
1155 std::string guest_name = base::UTF16ToUTF8(frame_name); 1166 std::string guest_name = base::UTF16ToUTF8(frame_name);
1156 guest->name_ = guest_name; 1167 guest->name_ = guest_name;
1157 pending_new_windows_.insert( 1168 pending_new_windows_.insert(
1158 std::make_pair(guest, NewWindowInfo(target_url, guest_name))); 1169 std::make_pair(guest, NewWindowInfo(target_url, guest_name)));
1159 } 1170 }
1160 1171
1172 void WebViewGuest::EnterFullscreenModeForTab(content::WebContents* web_contents,
1173 const GURL& origin) {
1174 // Ask the embedder for permission.
1175 base::DictionaryValue request_info;
1176 request_info.SetString(webview::kOrigin, origin.spec());
1177 web_view_permission_helper_->RequestPermission(
1178 WEB_VIEW_PERMISSION_TYPE_FULLSCREEN, request_info,
1179 base::Bind(&WebViewGuest::OnFullscreenPermissionDecided,
1180 weak_ptr_factory_.GetWeakPtr(), origin),
1181 false /* allowed_by_default */);
1182
1183 // TODO(lazyboy): Right now the guest immediately goes fullscreen within its
1184 // bounds. If the embedder denies the permission then we will see a flicker.
1185 // Once we have the ability to "cancel" a renderer/ fullscreen request:
1186 // http://crbug.com/466854 this won't be necessary and we should be
1187 // Calling SetFullscreenState(true) once the embedder allowed the request.
1188 // Otherwise we would cancel renderer/ fullscreen if the embedder denied.
1189 SetFullscreenState(true);
1190 }
1191
1192 void WebViewGuest::ExitFullscreenModeForTab(
1193 content::WebContents* web_contents) {
1194 SetFullscreenState(false);
1195 }
1196
1197 bool WebViewGuest::IsFullscreenForTabOrPending(
1198 const content::WebContents* web_contents) const {
1199 return is_guest_fullscreen_;
1200 }
1201
1161 void WebViewGuest::LoadURLWithParams(const GURL& url, 1202 void WebViewGuest::LoadURLWithParams(const GURL& url,
1162 const content::Referrer& referrer, 1203 const content::Referrer& referrer,
1163 ui::PageTransition transition_type, 1204 ui::PageTransition transition_type,
1164 bool force_navigation) { 1205 bool force_navigation) {
1165 // Do not allow navigating a guest to schemes other than known safe schemes. 1206 // Do not allow navigating a guest to schemes other than known safe schemes.
1166 // This will block the embedder trying to load unwanted schemes, e.g. 1207 // This will block the embedder trying to load unwanted schemes, e.g.
1167 // chrome://. 1208 // chrome://.
1168 bool scheme_is_blocked = 1209 bool scheme_is_blocked =
1169 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( 1210 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme(
1170 url.scheme()) && 1211 url.scheme()) &&
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 auto guest = 1298 auto guest =
1258 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), 1299 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(),
1259 new_window_instance_id); 1300 new_window_instance_id);
1260 if (!guest) 1301 if (!guest)
1261 return; 1302 return;
1262 1303
1263 if (!allow) 1304 if (!allow)
1264 guest->Destroy(); 1305 guest->Destroy();
1265 } 1306 }
1266 1307
1308 void WebViewGuest::OnFullscreenPermissionDecided(
1309 const GURL& origin,
1310 bool allowed,
1311 const std::string& user_input) {
1312 last_fullscreen_permission_was_allowed_by_embedder_ = allowed;
1313 SetFullscreenState(allowed);
1314 }
1315
1316 void WebViewGuest::SetFullscreenState(bool is_fullscreen) {
1317 bool was_fullscren = is_guest_fullscreen_;
Fady Samuel 2015/03/13 01:43:06 typo: was_fullscreen.
lazyboy 2015/03/13 16:27:02 Done.
1318 if (was_fullscren != is_fullscreen) {
Fady Samuel 2015/03/13 01:43:07 Early exit preferred.
lazyboy 2015/03/13 16:27:02 Done.
1319 is_guest_fullscreen_ = is_fullscreen;
1320 // If the embedder went fullscreen because of us, it should exit fullscreen
1321 // when we exit fullscreen.
1322 if (was_fullscren && last_fullscreen_permission_was_allowed_by_embedder_ &&
1323 is_embedder_fullscreen_) {
Fady Samuel 2015/03/13 01:43:07 This is really hard to read. Can we make this a he
lazyboy 2015/03/13 16:27:02 Done.
1324 // Dispatch a message so we can call document.webkitCancelFullscreen()
1325 // on the embedder.
1326 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
1327 DispatchEventToView(
1328 new GuestViewBase::Event(webview::kEventExitFullscreen, args.Pass()));
1329 }
1330 web_contents()->GetRenderViewHost()->WasResized();
Fady Samuel 2015/03/13 01:43:07 What is the purpose of this line? Add a comment?
lazyboy 2015/03/13 16:27:02 Ah, thanks. I had that comment initially, but lost
1331 }
1332 }
1333
1267 } // namespace extensions 1334 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698