| 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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 std::string user_agent_override; | 280 std::string user_agent_override; |
| 281 if (attach_params()->GetString(webview::kParameterUserAgentOverride, | 281 if (attach_params()->GetString(webview::kParameterUserAgentOverride, |
| 282 &user_agent_override)) { | 282 &user_agent_override)) { |
| 283 SetUserAgentOverride(user_agent_override); | 283 SetUserAgentOverride(user_agent_override); |
| 284 } else { | 284 } else { |
| 285 SetUserAgentOverride(""); | 285 SetUserAgentOverride(""); |
| 286 } | 286 } |
| 287 | 287 |
| 288 std::string src; | 288 std::string src; |
| 289 if (attach_params()->GetString(webview::kAttributeSrc, &src) && !src.empty()) | 289 if (attach_params()->GetString(webview::kAttributeSrc, &src) && !src.empty()) |
| 290 NavigateGuest(src); | 290 NavigateGuest(src, false /* force_navigation */); |
| 291 | 291 |
| 292 if (GetOpener()) { | 292 if (GetOpener()) { |
| 293 // We need to do a navigation here if the target URL has changed between | 293 // We need to do a navigation here if the target URL has changed between |
| 294 // the time the WebContents was created and the time it was attached. | 294 // the time the WebContents was created and the time it was attached. |
| 295 // We also need to do an initial navigation if a RenderView was never | 295 // We also need to do an initial navigation if a RenderView was never |
| 296 // created for the new window in cases where there is no referrer. | 296 // created for the new window in cases where there is no referrer. |
| 297 PendingWindowMap::iterator it = | 297 PendingWindowMap::iterator it = |
| 298 GetOpener()->pending_new_windows_.find(this); | 298 GetOpener()->pending_new_windows_.find(this); |
| 299 if (it != GetOpener()->pending_new_windows_.end()) { | 299 if (it != GetOpener()->pending_new_windows_.end()) { |
| 300 const NewWindowInfo& new_window_info = it->second; | 300 const NewWindowInfo& new_window_info = it->second; |
| 301 if (new_window_info.changed || !web_contents()->HasOpener()) | 301 if (new_window_info.changed || !web_contents()->HasOpener()) |
| 302 NavigateGuest(new_window_info.url.spec()); | 302 NavigateGuest(new_window_info.url.spec(), false /* force_navigation */); |
| 303 } else { | 303 } else { |
| 304 NOTREACHED(); | 304 NOTREACHED(); |
| 305 } | 305 } |
| 306 | 306 |
| 307 // Once a new guest is attached to the DOM of the embedder page, then the | 307 // Once a new guest is attached to the DOM of the embedder page, then the |
| 308 // lifetime of the new guest is no longer managed by the opener guest. | 308 // lifetime of the new guest is no longer managed by the opener guest. |
| 309 GetOpener()->pending_new_windows_.erase(this); | 309 GetOpener()->pending_new_windows_.erase(this); |
| 310 } | 310 } |
| 311 | 311 |
| 312 bool allow_transparency = false; | 312 bool allow_transparency = false; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 } | 397 } |
| 398 | 398 |
| 399 bool WebViewGuest::IsDragAndDropEnabled() const { | 399 bool WebViewGuest::IsDragAndDropEnabled() const { |
| 400 return true; | 400 return true; |
| 401 } | 401 } |
| 402 | 402 |
| 403 void WebViewGuest::WillDestroy() { | 403 void WebViewGuest::WillDestroy() { |
| 404 if (!attached() && GetOpener()) | 404 if (!attached() && GetOpener()) |
| 405 GetOpener()->pending_new_windows_.erase(this); | 405 GetOpener()->pending_new_windows_.erase(this); |
| 406 DestroyUnattachedWindows(); | 406 DestroyUnattachedWindows(); |
| 407 | |
| 408 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | |
| 409 DispatchEventToEmbedder( | |
| 410 new GuestViewBase::Event(webview::kEventPluginDestroyed, args.Pass())); | |
| 411 } | 407 } |
| 412 | 408 |
| 413 bool WebViewGuest::AddMessageToConsole(WebContents* source, | 409 bool WebViewGuest::AddMessageToConsole(WebContents* source, |
| 414 int32 level, | 410 int32 level, |
| 415 const base::string16& message, | 411 const base::string16& message, |
| 416 int32 line_no, | 412 int32 line_no, |
| 417 const base::string16& source_id) { | 413 const base::string16& source_id) { |
| 418 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 414 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 419 // Log levels are from base/logging.h: LogSeverity. | 415 // Log levels are from base/logging.h: LogSeverity. |
| 420 args->SetInteger(webview::kLevel, level); | 416 args->SetInteger(webview::kLevel, level); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); | 668 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); |
| 673 } | 669 } |
| 674 | 670 |
| 675 WebViewGuest::~WebViewGuest() { | 671 WebViewGuest::~WebViewGuest() { |
| 676 } | 672 } |
| 677 | 673 |
| 678 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 674 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
| 679 content::RenderFrameHost* render_frame_host, | 675 content::RenderFrameHost* render_frame_host, |
| 680 const GURL& url, | 676 const GURL& url, |
| 681 ui::PageTransition transition_type) { | 677 ui::PageTransition transition_type) { |
| 678 if (!render_frame_host->GetParent()) |
| 679 src_ = url; |
| 682 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 680 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 683 args->SetString(guestview::kUrl, url.spec()); | 681 args->SetString(guestview::kUrl, url.spec()); |
| 684 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); | 682 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); |
| 685 args->SetString(webview::kInternalBaseURLForDataURL, | 683 args->SetString(webview::kInternalBaseURLForDataURL, |
| 686 web_contents() | 684 web_contents() |
| 687 ->GetController() | 685 ->GetController() |
| 688 .GetLastCommittedEntry() | 686 .GetLastCommittedEntry() |
| 689 ->GetBaseURLForDataURL() | 687 ->GetBaseURLForDataURL() |
| 690 .spec()); | 688 .spec()); |
| 691 args->SetInteger(webview::kInternalCurrentEntryIndex, | 689 args->SetInteger(webview::kInternalCurrentEntryIndex, |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 content::ColorChooser* WebViewGuest::OpenColorChooser( | 889 content::ColorChooser* WebViewGuest::OpenColorChooser( |
| 892 WebContents* web_contents, | 890 WebContents* web_contents, |
| 893 SkColor color, | 891 SkColor color, |
| 894 const std::vector<content::ColorSuggestion>& suggestions) { | 892 const std::vector<content::ColorSuggestion>& suggestions) { |
| 895 if (!attached() || !embedder_web_contents()->GetDelegate()) | 893 if (!attached() || !embedder_web_contents()->GetDelegate()) |
| 896 return NULL; | 894 return NULL; |
| 897 return embedder_web_contents()->GetDelegate()->OpenColorChooser( | 895 return embedder_web_contents()->GetDelegate()->OpenColorChooser( |
| 898 web_contents, color, suggestions); | 896 web_contents, color, suggestions); |
| 899 } | 897 } |
| 900 | 898 |
| 901 void WebViewGuest::NavigateGuest(const std::string& src) { | 899 void WebViewGuest::NavigateGuest(const std::string& src, |
| 900 bool force_navigation) { |
| 901 if (src.empty()) |
| 902 return; |
| 903 |
| 902 GURL url = ResolveURL(src); | 904 GURL url = ResolveURL(src); |
| 903 | 905 |
| 904 // Do not allow navigating a guest to schemes other than known safe schemes. | 906 // Do not allow navigating a guest to schemes other than known safe schemes. |
| 905 // This will block the embedder trying to load unwanted schemes, e.g. | 907 // This will block the embedder trying to load unwanted schemes, e.g. |
| 906 // chrome://settings. | 908 // chrome://settings. |
| 907 bool scheme_is_blocked = | 909 bool scheme_is_blocked = |
| 908 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( | 910 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( |
| 909 url.scheme()) && | 911 url.scheme()) && |
| 910 !url.SchemeIs(url::kAboutScheme)) || | 912 !url.SchemeIs(url::kAboutScheme)) || |
| 911 url.SchemeIs(url::kJavaScriptScheme); | 913 url.SchemeIs(url::kJavaScriptScheme); |
| 912 if (scheme_is_blocked || !url.is_valid()) { | 914 if (scheme_is_blocked || !url.is_valid()) { |
| 913 LoadAbort(true /* is_top_level */, url, | 915 LoadAbort(true /* is_top_level */, url, |
| 914 net::ErrorToShortString(net::ERR_ABORTED)); | 916 net::ErrorToShortString(net::ERR_ABORTED)); |
| 915 return; | 917 return; |
| 916 } | 918 } |
| 919 if (!force_navigation && (src_ == url)) |
| 920 return; |
| 917 | 921 |
| 918 GURL validated_url(url); | 922 GURL validated_url(url); |
| 919 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); | 923 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); |
| 920 // As guests do not swap processes on navigation, only navigations to | 924 // As guests do not swap processes on navigation, only navigations to |
| 921 // normal web URLs are supported. No protocol handlers are installed for | 925 // normal web URLs are supported. No protocol handlers are installed for |
| 922 // other schemes (e.g., WebUI or extensions), and no permissions or bindings | 926 // other schemes (e.g., WebUI or extensions), and no permissions or bindings |
| 923 // can be granted to the guest process. | 927 // can be granted to the guest process. |
| 924 LoadURLWithParams(validated_url, | 928 LoadURLWithParams(validated_url, |
| 925 content::Referrer(), | 929 content::Referrer(), |
| 926 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 930 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 WebViewGuest* guest = | 1214 WebViewGuest* guest = |
| 1211 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1215 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1212 if (!guest) | 1216 if (!guest) |
| 1213 return; | 1217 return; |
| 1214 | 1218 |
| 1215 if (!allow) | 1219 if (!allow) |
| 1216 guest->Destroy(); | 1220 guest->Destroy(); |
| 1217 } | 1221 } |
| 1218 | 1222 |
| 1219 } // namespace extensions | 1223 } // namespace extensions |
| OLD | NEW |