Chromium Code Reviews| Index: extensions/browser/guest_view/web_view/web_view_guest.cc |
| diff --git a/extensions/browser/guest_view/web_view/web_view_guest.cc b/extensions/browser/guest_view/web_view/web_view_guest.cc |
| index b1ce1a53f8761a921e3bb86c59dc635545667b72..773e9fc8bce612150dc5c086c5caef56ab05c381 100644 |
| --- a/extensions/browser/guest_view/web_view/web_view_guest.cc |
| +++ b/extensions/browser/guest_view/web_view/web_view_guest.cc |
| @@ -321,6 +321,14 @@ void WebViewGuest::DidStopLoading() { |
| new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); |
| } |
| +void WebViewGuest::EmbedderFullscreenToggled(bool entered_fullscreen) { |
| + is_embedder_fullscreen_ = entered_fullscreen; |
| + // If the embedder has got out of fullscreen, we get out of fullscreen |
| + // mode as well. |
| + if (!entered_fullscreen) |
| + SetFullscreenState(false); |
| +} |
| + |
| void WebViewGuest::EmbedderWillBeDestroyed() { |
| // Clean up rules registries for the webview. |
| RulesRegistryService::Get(browser_context()) |
| @@ -640,6 +648,9 @@ WebViewGuest::WebViewGuest(content::WebContents* owner_web_contents) |
| javascript_dialog_helper_(this), |
| current_zoom_factor_(1.0), |
| allow_scaling_(false), |
| + is_guest_fullscreen_(false), |
| + is_embedder_fullscreen_(false), |
| + last_fullscreen_permission_was_allowed_by_embedder_(false), |
| weak_ptr_factory_(this) { |
| web_view_guest_delegate_.reset( |
| ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); |
| @@ -1158,6 +1169,36 @@ void WebViewGuest::WebContentsCreated(WebContents* source_contents, |
| std::make_pair(guest, NewWindowInfo(target_url, guest_name))); |
| } |
| +void WebViewGuest::EnterFullscreenModeForTab(content::WebContents* web_contents, |
| + const GURL& origin) { |
| + // Ask the embedder for permission. |
| + base::DictionaryValue request_info; |
| + request_info.SetString(webview::kOrigin, origin.spec()); |
| + web_view_permission_helper_->RequestPermission( |
| + WEB_VIEW_PERMISSION_TYPE_FULLSCREEN, request_info, |
| + base::Bind(&WebViewGuest::OnFullscreenPermissionDecided, |
| + weak_ptr_factory_.GetWeakPtr(), origin), |
| + false /* allowed_by_default */); |
| + |
| + // TODO(lazyboy): Right now the guest immediately goes fullscreen within its |
| + // bounds. If the embedder denies the permission then we will see a flicker. |
| + // Once we have the ability to "cancel" a renderer/ fullscreen request: |
| + // http://crbug.com/466854 this won't be necessary and we should be |
| + // Calling SetFullscreenState(true) once the embedder allowed the request. |
| + // Otherwise we would cancel renderer/ fullscreen if the embedder denied. |
| + SetFullscreenState(true); |
| +} |
| + |
| +void WebViewGuest::ExitFullscreenModeForTab( |
| + content::WebContents* web_contents) { |
| + SetFullscreenState(false); |
| +} |
| + |
| +bool WebViewGuest::IsFullscreenForTabOrPending( |
| + const content::WebContents* web_contents) const { |
| + return is_guest_fullscreen_; |
| +} |
| + |
| void WebViewGuest::LoadURLWithParams(const GURL& url, |
| const content::Referrer& referrer, |
| ui::PageTransition transition_type, |
| @@ -1264,4 +1305,30 @@ void WebViewGuest::OnWebViewNewWindowResponse( |
| guest->Destroy(); |
| } |
| +void WebViewGuest::OnFullscreenPermissionDecided( |
| + const GURL& origin, |
| + bool allowed, |
| + const std::string& user_input) { |
| + last_fullscreen_permission_was_allowed_by_embedder_ = allowed; |
| + SetFullscreenState(allowed); |
| +} |
| + |
| +void WebViewGuest::SetFullscreenState(bool is_fullscreen) { |
| + 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.
|
| + if (was_fullscren != is_fullscreen) { |
|
Fady Samuel
2015/03/13 01:43:07
Early exit preferred.
lazyboy
2015/03/13 16:27:02
Done.
|
| + is_guest_fullscreen_ = is_fullscreen; |
| + // If the embedder went fullscreen because of us, it should exit fullscreen |
| + // when we exit fullscreen. |
| + if (was_fullscren && last_fullscreen_permission_was_allowed_by_embedder_ && |
| + 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.
|
| + // Dispatch a message so we can call document.webkitCancelFullscreen() |
| + // on the embedder. |
| + scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| + DispatchEventToView( |
| + new GuestViewBase::Event(webview::kEventExitFullscreen, args.Pass())); |
| + } |
| + 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
|
| + } |
| +} |
| + |
| } // namespace extensions |