| 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 std::string user_agent_override; | 266 std::string user_agent_override; |
| 267 if (attach_params()->GetString(webview::kParameterUserAgentOverride, | 267 if (attach_params()->GetString(webview::kParameterUserAgentOverride, |
| 268 &user_agent_override)) { | 268 &user_agent_override)) { |
| 269 SetUserAgentOverride(user_agent_override); | 269 SetUserAgentOverride(user_agent_override); |
| 270 } else { | 270 } else { |
| 271 SetUserAgentOverride(""); | 271 SetUserAgentOverride(""); |
| 272 } | 272 } |
| 273 | 273 |
| 274 std::string src; | 274 std::string src; |
| 275 if (attach_params()->GetString(webview::kAttributeSrc, &src) && !src.empty()) | 275 if (attach_params()->GetString(webview::kAttributeSrc, &src) && !src.empty()) |
| 276 NavigateGuest(src); | 276 NavigateGuest(src, false /* force_navigation */); |
| 277 | 277 |
| 278 if (GetOpener()) { | 278 if (GetOpener()) { |
| 279 // We need to do a navigation here if the target URL has changed between | 279 // We need to do a navigation here if the target URL has changed between |
| 280 // the time the WebContents was created and the time it was attached. | 280 // the time the WebContents was created and the time it was attached. |
| 281 // We also need to do an initial navigation if a RenderView was never | 281 // We also need to do an initial navigation if a RenderView was never |
| 282 // created for the new window in cases where there is no referrer. | 282 // created for the new window in cases where there is no referrer. |
| 283 PendingWindowMap::iterator it = | 283 PendingWindowMap::iterator it = |
| 284 GetOpener()->pending_new_windows_.find(this); | 284 GetOpener()->pending_new_windows_.find(this); |
| 285 if (it != GetOpener()->pending_new_windows_.end()) { | 285 if (it != GetOpener()->pending_new_windows_.end()) { |
| 286 const NewWindowInfo& new_window_info = it->second; | 286 const NewWindowInfo& new_window_info = it->second; |
| 287 if (new_window_info.changed || !web_contents()->HasOpener()) | 287 if (new_window_info.changed || !web_contents()->HasOpener()) |
| 288 NavigateGuest(new_window_info.url.spec()); | 288 NavigateGuest(new_window_info.url.spec(), false /* force_navigation */); |
| 289 } else { | 289 } else { |
| 290 NOTREACHED(); | 290 NOTREACHED(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 // Once a new guest is attached to the DOM of the embedder page, then the | 293 // Once a new guest is attached to the DOM of the embedder page, then the |
| 294 // lifetime of the new guest is no longer managed by the opener guest. | 294 // lifetime of the new guest is no longer managed by the opener guest. |
| 295 GetOpener()->pending_new_windows_.erase(this); | 295 GetOpener()->pending_new_windows_.erase(this); |
| 296 } | 296 } |
| 297 | 297 |
| 298 bool allow_transparency = false; | 298 bool allow_transparency = false; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 } | 376 } |
| 377 | 377 |
| 378 bool WebViewGuest::IsDragAndDropEnabled() const { | 378 bool WebViewGuest::IsDragAndDropEnabled() const { |
| 379 return true; | 379 return true; |
| 380 } | 380 } |
| 381 | 381 |
| 382 void WebViewGuest::WillDestroy() { | 382 void WebViewGuest::WillDestroy() { |
| 383 if (!attached() && GetOpener()) | 383 if (!attached() && GetOpener()) |
| 384 GetOpener()->pending_new_windows_.erase(this); | 384 GetOpener()->pending_new_windows_.erase(this); |
| 385 DestroyUnattachedWindows(); | 385 DestroyUnattachedWindows(); |
| 386 | |
| 387 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | |
| 388 DispatchEventToEmbedder( | |
| 389 new GuestViewBase::Event(webview::kEventPluginDestroyed, args.Pass())); | |
| 390 } | 386 } |
| 391 | 387 |
| 392 bool WebViewGuest::AddMessageToConsole(WebContents* source, | 388 bool WebViewGuest::AddMessageToConsole(WebContents* source, |
| 393 int32 level, | 389 int32 level, |
| 394 const base::string16& message, | 390 const base::string16& message, |
| 395 int32 line_no, | 391 int32 line_no, |
| 396 const base::string16& source_id) { | 392 const base::string16& source_id) { |
| 397 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 393 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 398 // Log levels are from base/logging.h: LogSeverity. | 394 // Log levels are from base/logging.h: LogSeverity. |
| 399 args->SetInteger(webview::kLevel, level); | 395 args->SetInteger(webview::kLevel, level); |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); | 647 ExtensionsAPIClient::Get()->CreateWebViewGuestDelegate(this)); |
| 652 } | 648 } |
| 653 | 649 |
| 654 WebViewGuest::~WebViewGuest() { | 650 WebViewGuest::~WebViewGuest() { |
| 655 } | 651 } |
| 656 | 652 |
| 657 void WebViewGuest::DidCommitProvisionalLoadForFrame( | 653 void WebViewGuest::DidCommitProvisionalLoadForFrame( |
| 658 content::RenderFrameHost* render_frame_host, | 654 content::RenderFrameHost* render_frame_host, |
| 659 const GURL& url, | 655 const GURL& url, |
| 660 ui::PageTransition transition_type) { | 656 ui::PageTransition transition_type) { |
| 657 if (!render_frame_host->GetParent()) |
| 658 src_ = url; |
| 661 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 659 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 662 args->SetString(guestview::kUrl, url.spec()); | 660 args->SetString(guestview::kUrl, url.spec()); |
| 663 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); | 661 args->SetBoolean(guestview::kIsTopLevel, !render_frame_host->GetParent()); |
| 664 args->SetString(webview::kInternalBaseURLForDataURL, | 662 args->SetString(webview::kInternalBaseURLForDataURL, |
| 665 web_contents() | 663 web_contents() |
| 666 ->GetController() | 664 ->GetController() |
| 667 .GetLastCommittedEntry() | 665 .GetLastCommittedEntry() |
| 668 ->GetBaseURLForDataURL() | 666 ->GetBaseURLForDataURL() |
| 669 .spec()); | 667 .spec()); |
| 670 args->SetInteger(webview::kInternalCurrentEntryIndex, | 668 args->SetInteger(webview::kInternalCurrentEntryIndex, |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 content::ColorChooser* WebViewGuest::OpenColorChooser( | 868 content::ColorChooser* WebViewGuest::OpenColorChooser( |
| 871 WebContents* web_contents, | 869 WebContents* web_contents, |
| 872 SkColor color, | 870 SkColor color, |
| 873 const std::vector<content::ColorSuggestion>& suggestions) { | 871 const std::vector<content::ColorSuggestion>& suggestions) { |
| 874 if (!attached() || !embedder_web_contents()->GetDelegate()) | 872 if (!attached() || !embedder_web_contents()->GetDelegate()) |
| 875 return NULL; | 873 return NULL; |
| 876 return embedder_web_contents()->GetDelegate()->OpenColorChooser( | 874 return embedder_web_contents()->GetDelegate()->OpenColorChooser( |
| 877 web_contents, color, suggestions); | 875 web_contents, color, suggestions); |
| 878 } | 876 } |
| 879 | 877 |
| 880 void WebViewGuest::NavigateGuest(const std::string& src) { | 878 void WebViewGuest::NavigateGuest(const std::string& src, |
| 879 bool force_navigation) { |
| 880 if (src.empty()) |
| 881 return; |
| 882 |
| 881 GURL url = ResolveURL(src); | 883 GURL url = ResolveURL(src); |
| 882 | 884 |
| 883 // Do not allow navigating a guest to schemes other than known safe schemes. | 885 // Do not allow navigating a guest to schemes other than known safe schemes. |
| 884 // This will block the embedder trying to load unwanted schemes, e.g. | 886 // This will block the embedder trying to load unwanted schemes, e.g. |
| 885 // chrome://settings. | 887 // chrome://settings. |
| 886 bool scheme_is_blocked = | 888 bool scheme_is_blocked = |
| 887 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( | 889 (!content::ChildProcessSecurityPolicy::GetInstance()->IsWebSafeScheme( |
| 888 url.scheme()) && | 890 url.scheme()) && |
| 889 !url.SchemeIs(url::kAboutScheme)) || | 891 !url.SchemeIs(url::kAboutScheme)) || |
| 890 url.SchemeIs(url::kJavaScriptScheme); | 892 url.SchemeIs(url::kJavaScriptScheme); |
| 891 if (scheme_is_blocked || !url.is_valid()) { | 893 if (scheme_is_blocked || !url.is_valid()) { |
| 892 LoadAbort(true /* is_top_level */, url, | 894 LoadAbort(true /* is_top_level */, url, |
| 893 net::ErrorToShortString(net::ERR_ABORTED)); | 895 net::ErrorToShortString(net::ERR_ABORTED)); |
| 894 return; | 896 return; |
| 895 } | 897 } |
| 898 if (!force_navigation && (src_ == url)) |
| 899 return; |
| 896 | 900 |
| 897 GURL validated_url(url); | 901 GURL validated_url(url); |
| 898 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); | 902 web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); |
| 899 // As guests do not swap processes on navigation, only navigations to | 903 // As guests do not swap processes on navigation, only navigations to |
| 900 // normal web URLs are supported. No protocol handlers are installed for | 904 // normal web URLs are supported. No protocol handlers are installed for |
| 901 // other schemes (e.g., WebUI or extensions), and no permissions or bindings | 905 // other schemes (e.g., WebUI or extensions), and no permissions or bindings |
| 902 // can be granted to the guest process. | 906 // can be granted to the guest process. |
| 903 LoadURLWithParams(validated_url, | 907 LoadURLWithParams(validated_url, |
| 904 content::Referrer(), | 908 content::Referrer(), |
| 905 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | 909 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 WebViewGuest* guest = | 1193 WebViewGuest* guest = |
| 1190 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1194 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1191 if (!guest) | 1195 if (!guest) |
| 1192 return; | 1196 return; |
| 1193 | 1197 |
| 1194 if (!allow) | 1198 if (!allow) |
| 1195 guest->Destroy(); | 1199 guest->Destroy(); |
| 1196 } | 1200 } |
| 1197 | 1201 |
| 1198 } // namespace extensions | 1202 } // namespace extensions |
| OLD | NEW |