| 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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 | 436 |
| 437 void WebViewGuest::HandleKeyboardEvent( | 437 void WebViewGuest::HandleKeyboardEvent( |
| 438 WebContents* source, | 438 WebContents* source, |
| 439 const content::NativeWebKeyboardEvent& event) { | 439 const content::NativeWebKeyboardEvent& event) { |
| 440 if (HandleKeyboardShortcuts(event)) | 440 if (HandleKeyboardShortcuts(event)) |
| 441 return; | 441 return; |
| 442 | 442 |
| 443 GuestViewBase::HandleKeyboardEvent(source, event); | 443 GuestViewBase::HandleKeyboardEvent(source, event); |
| 444 } | 444 } |
| 445 | 445 |
| 446 bool WebViewGuest::PreHandleGestureEvent(content::WebContents* source, |
| 447 const blink::WebGestureEvent& event) { |
| 448 return !allow_scaling_ && GuestViewBase::PreHandleGestureEvent(source, event); |
| 449 } |
| 450 |
| 446 void WebViewGuest::LoadProgressChanged(content::WebContents* source, | 451 void WebViewGuest::LoadProgressChanged(content::WebContents* source, |
| 447 double progress) { | 452 double progress) { |
| 448 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 453 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 449 args->SetString(guestview::kUrl, web_contents()->GetURL().spec()); | 454 args->SetString(guestview::kUrl, web_contents()->GetURL().spec()); |
| 450 args->SetDouble(webview::kProgress, progress); | 455 args->SetDouble(webview::kProgress, progress); |
| 451 DispatchEventToView( | 456 DispatchEventToView( |
| 452 new GuestViewBase::Event(webview::kEventLoadProgress, args.Pass())); | 457 new GuestViewBase::Event(webview::kEventLoadProgress, args.Pass())); |
| 453 } | 458 } |
| 454 | 459 |
| 455 void WebViewGuest::LoadAbort(bool is_top_level, | 460 void WebViewGuest::LoadAbort(bool is_top_level, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 } | 636 } |
| 632 | 637 |
| 633 WebViewGuest::WebViewGuest(content::WebContents* owner_web_contents) | 638 WebViewGuest::WebViewGuest(content::WebContents* owner_web_contents) |
| 634 : GuestView<WebViewGuest>(owner_web_contents), | 639 : GuestView<WebViewGuest>(owner_web_contents), |
| 635 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID), | 640 rules_registry_id_(RulesRegistryService::kInvalidRulesRegistryID), |
| 636 find_helper_(this), | 641 find_helper_(this), |
| 637 is_overriding_user_agent_(false), | 642 is_overriding_user_agent_(false), |
| 638 guest_opaque_(true), | 643 guest_opaque_(true), |
| 639 javascript_dialog_helper_(this), | 644 javascript_dialog_helper_(this), |
| 640 current_zoom_factor_(1.0), | 645 current_zoom_factor_(1.0), |
| 646 allow_scaling_(false), |
| 641 weak_ptr_factory_(this) { | 647 weak_ptr_factory_(this) { |
| 642 web_view_guest_delegate_.reset( | 648 web_view_guest_delegate_.reset( |
| 643 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); | 649 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); |
| 644 } | 650 } |
| 645 | 651 |
| 646 WebViewGuest::~WebViewGuest() { | 652 WebViewGuest::~WebViewGuest() { |
| 647 } | 653 } |
| 648 | 654 |
| 649 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 655 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
| 650 content::RenderFrameHost* render_frame_host, | 656 content::RenderFrameHost* render_frame_host, |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 std::string user_agent_override; | 965 std::string user_agent_override; |
| 960 params.GetString(webview::kParameterUserAgentOverride, &user_agent_override); | 966 params.GetString(webview::kParameterUserAgentOverride, &user_agent_override); |
| 961 SetUserAgentOverride(user_agent_override); | 967 SetUserAgentOverride(user_agent_override); |
| 962 | 968 |
| 963 bool allow_transparency = false; | 969 bool allow_transparency = false; |
| 964 params.GetBoolean(webview::kAttributeAllowTransparency, &allow_transparency); | 970 params.GetBoolean(webview::kAttributeAllowTransparency, &allow_transparency); |
| 965 // We need to set the background opaque flag after navigation to ensure that | 971 // We need to set the background opaque flag after navigation to ensure that |
| 966 // there is a RenderWidgetHostView available. | 972 // there is a RenderWidgetHostView available. |
| 967 SetAllowTransparency(allow_transparency); | 973 SetAllowTransparency(allow_transparency); |
| 968 | 974 |
| 975 bool allow_scaling = false; |
| 976 params.GetBoolean(webview::kAttributeAllowScaling, &allow_scaling); |
| 977 SetAllowScaling(allow_scaling); |
| 978 |
| 969 bool is_pending_new_window = false; | 979 bool is_pending_new_window = false; |
| 970 if (GetOpener()) { | 980 if (GetOpener()) { |
| 971 // We need to do a navigation here if the target URL has changed between | 981 // We need to do a navigation here if the target URL has changed between |
| 972 // the time the WebContents was created and the time it was attached. | 982 // the time the WebContents was created and the time it was attached. |
| 973 // We also need to do an initial navigation if a RenderView was never | 983 // We also need to do an initial navigation if a RenderView was never |
| 974 // created for the new window in cases where there is no referrer. | 984 // created for the new window in cases where there is no referrer. |
| 975 auto it = GetOpener()->pending_new_windows_.find(this); | 985 auto it = GetOpener()->pending_new_windows_.find(this); |
| 976 if (it != GetOpener()->pending_new_windows_.end()) { | 986 if (it != GetOpener()->pending_new_windows_.end()) { |
| 977 const NewWindowInfo& new_window_info = it->second; | 987 const NewWindowInfo& new_window_info = it->second; |
| 978 if (new_window_info.changed || !web_contents()->HasOpener()) | 988 if (new_window_info.changed || !web_contents()->HasOpener()) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 web_contents() | 1047 web_contents() |
| 1038 ->GetRenderViewHost() | 1048 ->GetRenderViewHost() |
| 1039 ->GetView() | 1049 ->GetView() |
| 1040 ->SetBackgroundColorToDefault(); | 1050 ->SetBackgroundColorToDefault(); |
| 1041 } else { | 1051 } else { |
| 1042 web_contents()->GetRenderViewHost()->GetView()->SetBackgroundColor( | 1052 web_contents()->GetRenderViewHost()->GetView()->SetBackgroundColor( |
| 1043 SK_ColorTRANSPARENT); | 1053 SK_ColorTRANSPARENT); |
| 1044 } | 1054 } |
| 1045 } | 1055 } |
| 1046 | 1056 |
| 1057 void WebViewGuest::SetAllowScaling(bool allow) { |
| 1058 allow_scaling_ = allow; |
| 1059 } |
| 1060 |
| 1047 bool WebViewGuest::LoadDataWithBaseURL(const std::string& data_url, | 1061 bool WebViewGuest::LoadDataWithBaseURL(const std::string& data_url, |
| 1048 const std::string& base_url, | 1062 const std::string& base_url, |
| 1049 const std::string& virtual_url, | 1063 const std::string& virtual_url, |
| 1050 std::string* error) { | 1064 std::string* error) { |
| 1051 // Make GURLs from URLs. | 1065 // Make GURLs from URLs. |
| 1052 const GURL data_gurl = GURL(data_url); | 1066 const GURL data_gurl = GURL(data_url); |
| 1053 const GURL base_gurl = GURL(base_url); | 1067 const GURL base_gurl = GURL(base_url); |
| 1054 const GURL virtual_gurl = GURL(virtual_url); | 1068 const GURL virtual_gurl = GURL(virtual_url); |
| 1055 | 1069 |
| 1056 // Check that the provided URLs are valid. | 1070 // Check that the provided URLs are valid. |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), | 1232 WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), |
| 1219 new_window_instance_id); | 1233 new_window_instance_id); |
| 1220 if (!guest) | 1234 if (!guest) |
| 1221 return; | 1235 return; |
| 1222 | 1236 |
| 1223 if (!allow) | 1237 if (!allow) |
| 1224 guest->Destroy(); | 1238 guest->Destroy(); |
| 1225 } | 1239 } |
| 1226 | 1240 |
| 1227 } // namespace extensions | 1241 } // namespace extensions |
| OLD | NEW |