| OLD | NEW |
| 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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 | 415 |
| 416 void WebViewGuest::GuestReady() { | 416 void WebViewGuest::GuestReady() { |
| 417 // The guest RenderView should always live in an isolated guest process. | 417 // The guest RenderView should always live in an isolated guest process. |
| 418 CHECK(web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); | 418 CHECK(web_contents()->GetRenderProcessHost()->IsIsolatedGuest()); |
| 419 Send(new ExtensionMsg_SetFrameName(web_contents()->GetRoutingID(), name_)); | 419 Send(new ExtensionMsg_SetFrameName(web_contents()->GetRoutingID(), name_)); |
| 420 | 420 |
| 421 // We don't want to accidentally set the opacity of an interstitial page. | 421 // We don't want to accidentally set the opacity of an interstitial page. |
| 422 // WebContents::GetRenderWidgetHostView will return the RWHV of an | 422 // WebContents::GetRenderWidgetHostView will return the RWHV of an |
| 423 // interstitial page if one is showing at this time. We only want opacity | 423 // interstitial page if one is showing at this time. We only want opacity |
| 424 // to apply to web pages. | 424 // to apply to web pages. |
| 425 if (guest_opaque_) { | 425 if (allow_transparency_) { |
| 426 web_contents()->GetRenderViewHost()->GetView()->SetBackgroundColor( |
| 427 SK_ColorTRANSPARENT); |
| 428 } else { |
| 426 web_contents() | 429 web_contents() |
| 427 ->GetRenderViewHost() | 430 ->GetRenderViewHost() |
| 428 ->GetView() | 431 ->GetView() |
| 429 ->SetBackgroundColorToDefault(); | 432 ->SetBackgroundColorToDefault(); |
| 430 } else { | |
| 431 web_contents()->GetRenderViewHost()->GetView()->SetBackgroundColor( | |
| 432 SK_ColorTRANSPARENT); | |
| 433 } | 433 } |
| 434 } | 434 } |
| 435 | 435 |
| 436 void WebViewGuest::GuestSizeChangedDueToAutoSize(const gfx::Size& old_size, | 436 void WebViewGuest::GuestSizeChangedDueToAutoSize(const gfx::Size& old_size, |
| 437 const gfx::Size& new_size) { | 437 const gfx::Size& new_size) { |
| 438 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 438 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 439 args->SetInteger(webview::kOldHeight, old_size.height()); | 439 args->SetInteger(webview::kOldHeight, old_size.height()); |
| 440 args->SetInteger(webview::kOldWidth, old_size.width()); | 440 args->SetInteger(webview::kOldWidth, old_size.width()); |
| 441 args->SetInteger(webview::kNewHeight, new_size.height()); | 441 args->SetInteger(webview::kNewHeight, new_size.height()); |
| 442 args->SetInteger(webview::kNewWidth, new_size.width()); | 442 args->SetInteger(webview::kNewWidth, new_size.width()); |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 | 714 |
| 715 ClearDataInternal(remove_since, removal_mask, callback); | 715 ClearDataInternal(remove_since, removal_mask, callback); |
| 716 return true; | 716 return true; |
| 717 } | 717 } |
| 718 | 718 |
| 719 WebViewGuest::WebViewGuest(content::WebContents* owner_web_contents) | 719 WebViewGuest::WebViewGuest(content::WebContents* owner_web_contents) |
| 720 : GuestView<WebViewGuest>(owner_web_contents), | 720 : GuestView<WebViewGuest>(owner_web_contents), |
| 721 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID), | 721 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID), |
| 722 find_helper_(this), | 722 find_helper_(this), |
| 723 is_overriding_user_agent_(false), | 723 is_overriding_user_agent_(false), |
| 724 guest_opaque_(true), | 724 allow_transparency_(false), |
| 725 javascript_dialog_helper_(this), | 725 javascript_dialog_helper_(this), |
| 726 allow_scaling_(false), | 726 allow_scaling_(false), |
| 727 is_guest_fullscreen_(false), | 727 is_guest_fullscreen_(false), |
| 728 is_embedder_fullscreen_(false), | 728 is_embedder_fullscreen_(false), |
| 729 last_fullscreen_permission_was_allowed_by_embedder_(false), | 729 last_fullscreen_permission_was_allowed_by_embedder_(false), |
| 730 weak_ptr_factory_(this) { | 730 weak_ptr_factory_(this) { |
| 731 web_view_guest_delegate_.reset( | 731 web_view_guest_delegate_.reset( |
| 732 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); | 732 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); |
| 733 } | 733 } |
| 734 | 734 |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 SetName(name); | 1011 SetName(name); |
| 1012 } | 1012 } |
| 1013 if (attached()) | 1013 if (attached()) |
| 1014 ReportFrameNameChange(name_); | 1014 ReportFrameNameChange(name_); |
| 1015 | 1015 |
| 1016 std::string user_agent_override; | 1016 std::string user_agent_override; |
| 1017 params.GetString(webview::kParameterUserAgentOverride, &user_agent_override); | 1017 params.GetString(webview::kParameterUserAgentOverride, &user_agent_override); |
| 1018 SetUserAgentOverride(user_agent_override); | 1018 SetUserAgentOverride(user_agent_override); |
| 1019 | 1019 |
| 1020 bool allow_transparency = false; | 1020 bool allow_transparency = false; |
| 1021 params.GetBoolean(webview::kAttributeAllowTransparency, &allow_transparency); | 1021 if (params.GetBoolean(webview::kAttributeAllowTransparency, |
| 1022 // We need to set the background opaque flag after navigation to ensure that | 1022 &allow_transparency)) { |
| 1023 // there is a RenderWidgetHostView available. | 1023 // We need to set the background opaque flag after navigation to ensure that |
| 1024 SetAllowTransparency(allow_transparency); | 1024 // there is a RenderWidgetHostView available. |
| 1025 SetAllowTransparency(allow_transparency); |
| 1026 } |
| 1025 | 1027 |
| 1026 bool allow_scaling = false; | 1028 bool allow_scaling = false; |
| 1027 params.GetBoolean(webview::kAttributeAllowScaling, &allow_scaling); | 1029 if (params.GetBoolean(webview::kAttributeAllowScaling, &allow_scaling)) |
| 1028 SetAllowScaling(allow_scaling); | 1030 SetAllowScaling(allow_scaling); |
| 1029 | 1031 |
| 1030 bool is_pending_new_window = false; | 1032 bool is_pending_new_window = false; |
| 1031 if (GetOpener()) { | 1033 if (GetOpener()) { |
| 1032 // We need to do a navigation here if the target URL has changed between | 1034 // We need to do a navigation here if the target URL has changed between |
| 1033 // the time the WebContents was created and the time it was attached. | 1035 // the time the WebContents was created and the time it was attached. |
| 1034 // We also need to do an initial navigation if a RenderView was never | 1036 // We also need to do an initial navigation if a RenderView was never |
| 1035 // created for the new window in cases where there is no referrer. | 1037 // created for the new window in cases where there is no referrer. |
| 1036 auto it = GetOpener()->pending_new_windows_.find(this); | 1038 auto it = GetOpener()->pending_new_windows_.find(this); |
| 1037 if (it != GetOpener()->pending_new_windows_.end()) { | 1039 if (it != GetOpener()->pending_new_windows_.end()) { |
| 1038 const NewWindowInfo& new_window_info = it->second; | 1040 const NewWindowInfo& new_window_info = it->second; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 DCHECK(zoom_controller); | 1077 DCHECK(zoom_controller); |
| 1076 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); | 1078 double zoom_level = content::ZoomFactorToZoomLevel(zoom_factor); |
| 1077 zoom_controller->SetZoomLevel(zoom_level); | 1079 zoom_controller->SetZoomLevel(zoom_level); |
| 1078 } | 1080 } |
| 1079 | 1081 |
| 1080 void WebViewGuest::SetZoomMode(ZoomController::ZoomMode zoom_mode) { | 1082 void WebViewGuest::SetZoomMode(ZoomController::ZoomMode zoom_mode) { |
| 1081 ZoomController::FromWebContents(web_contents())->SetZoomMode(zoom_mode); | 1083 ZoomController::FromWebContents(web_contents())->SetZoomMode(zoom_mode); |
| 1082 } | 1084 } |
| 1083 | 1085 |
| 1084 void WebViewGuest::SetAllowTransparency(bool allow) { | 1086 void WebViewGuest::SetAllowTransparency(bool allow) { |
| 1085 if (guest_opaque_ != allow) | 1087 if (allow_transparency_ == allow) |
| 1086 return; | 1088 return; |
| 1087 | 1089 |
| 1088 guest_opaque_ = !allow; | 1090 allow_transparency_ = allow; |
| 1089 if (!web_contents()->GetRenderViewHost()->GetView()) | 1091 if (!web_contents()->GetRenderViewHost()->GetView()) |
| 1090 return; | 1092 return; |
| 1091 | 1093 |
| 1092 if (guest_opaque_) { | 1094 if (allow_transparency_) { |
| 1095 web_contents()->GetRenderViewHost()->GetView()->SetBackgroundColor( |
| 1096 SK_ColorTRANSPARENT); |
| 1097 } else { |
| 1093 web_contents() | 1098 web_contents() |
| 1094 ->GetRenderViewHost() | 1099 ->GetRenderViewHost() |
| 1095 ->GetView() | 1100 ->GetView() |
| 1096 ->SetBackgroundColorToDefault(); | 1101 ->SetBackgroundColorToDefault(); |
| 1097 } else { | |
| 1098 web_contents()->GetRenderViewHost()->GetView()->SetBackgroundColor( | |
| 1099 SK_ColorTRANSPARENT); | |
| 1100 } | 1102 } |
| 1101 } | 1103 } |
| 1102 | 1104 |
| 1103 void WebViewGuest::SetAllowScaling(bool allow) { | 1105 void WebViewGuest::SetAllowScaling(bool allow) { |
| 1104 allow_scaling_ = allow; | 1106 allow_scaling_ = allow; |
| 1105 } | 1107 } |
| 1106 | 1108 |
| 1107 bool WebViewGuest::LoadDataWithBaseURL(const std::string& data_url, | 1109 bool WebViewGuest::LoadDataWithBaseURL(const std::string& data_url, |
| 1108 const std::string& base_url, | 1110 const std::string& base_url, |
| 1109 const std::string& virtual_url, | 1111 const std::string& virtual_url, |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1396 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1398 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 1397 DispatchEventToView( | 1399 DispatchEventToView( |
| 1398 new GuestViewBase::Event(webview::kEventExitFullscreen, args.Pass())); | 1400 new GuestViewBase::Event(webview::kEventExitFullscreen, args.Pass())); |
| 1399 } | 1401 } |
| 1400 // Since we changed fullscreen state, sending a Resize message ensures that | 1402 // Since we changed fullscreen state, sending a Resize message ensures that |
| 1401 // renderer/ sees the change. | 1403 // renderer/ sees the change. |
| 1402 web_contents()->GetRenderViewHost()->WasResized(); | 1404 web_contents()->GetRenderViewHost()->WasResized(); |
| 1403 } | 1405 } |
| 1404 | 1406 |
| 1405 } // namespace extensions | 1407 } // namespace extensions |
| OLD | NEW |