| 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 "chrome/browser/guest_view/web_view/web_view_guest.h" | 5 #include "chrome/browser/guest_view/web_view/web_view_guest.h" |
| 6 | 6 |
| 7 #include "base/debug/stack_trace.h" | 7 #include "base/debug/stack_trace.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 12 #include "chrome/browser/extensions/api/web_request/web_request_api.h" |
| 13 #include "chrome/browser/extensions/api/webview/webview_api.h" | 13 #include "chrome/browser/extensions/api/webview/webview_api.h" |
| 14 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | 14 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
| 15 #include "chrome/browser/extensions/extension_renderer_state.h" | 15 #include "chrome/browser/extensions/extension_renderer_state.h" |
| 16 #include "chrome/browser/extensions/menu_manager.h" | 16 #include "chrome/browser/extensions/menu_manager.h" |
| 17 #include "chrome/browser/extensions/script_executor.h" | 17 #include "chrome/browser/extensions/script_executor.h" |
| 18 #include "chrome/browser/favicon/favicon_tab_helper.h" | 18 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 19 #include "chrome/browser/guest_view/guest_view_constants.h" | 19 #include "chrome/browser/guest_view/guest_view_constants.h" |
| 20 #include "chrome/browser/guest_view/guest_view_manager.h" | 20 #include "chrome/browser/guest_view/guest_view_manager.h" |
| 21 #include "chrome/browser/guest_view/web_view/web_view_constants.h" | 21 #include "chrome/browser/guest_view/web_view/web_view_constants.h" |
| 22 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" | 22 #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" |
| 23 #include "chrome/browser/renderer_context_menu/context_menu_delegate.h" | 23 #include "chrome/browser/renderer_context_menu/context_menu_delegate.h" |
| 24 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 24 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
| 25 #include "chrome/common/chrome_version_info.h" | 25 #include "chrome/common/chrome_version_info.h" |
| 26 #include "chrome/common/render_messages.h" |
| 26 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/child_process_security_policy.h" | 28 #include "content/public/browser/child_process_security_policy.h" |
| 28 #include "content/public/browser/geolocation_permission_context.h" | 29 #include "content/public/browser/geolocation_permission_context.h" |
| 29 #include "content/public/browser/native_web_keyboard_event.h" | 30 #include "content/public/browser/native_web_keyboard_event.h" |
| 30 #include "content/public/browser/navigation_entry.h" | 31 #include "content/public/browser/navigation_entry.h" |
| 31 #include "content/public/browser/notification_details.h" | 32 #include "content/public/browser/notification_details.h" |
| 32 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/browser/notification_source.h" | 34 #include "content/public/browser/notification_source.h" |
| 34 #include "content/public/browser/notification_types.h" | 35 #include "content/public/browser/notification_types.h" |
| 35 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
| 36 #include "content/public/browser/resource_request_details.h" | 37 #include "content/public/browser/resource_request_details.h" |
| 37 #include "content/public/browser/site_instance.h" | 38 #include "content/public/browser/site_instance.h" |
| 38 #include "content/public/browser/storage_partition.h" | 39 #include "content/public/browser/storage_partition.h" |
| 39 #include "content/public/browser/user_metrics.h" | 40 #include "content/public/browser/user_metrics.h" |
| 40 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
| 41 #include "content/public/browser/web_contents_delegate.h" | 42 #include "content/public/browser/web_contents_delegate.h" |
| 42 #include "content/public/common/media_stream_request.h" | 43 #include "content/public/common/media_stream_request.h" |
| 43 #include "content/public/common/page_zoom.h" | 44 #include "content/public/common/page_zoom.h" |
| 44 #include "content/public/common/result_codes.h" | 45 #include "content/public/common/result_codes.h" |
| 45 #include "content/public/common/stop_find_action.h" | 46 #include "content/public/common/stop_find_action.h" |
| 46 #include "content/public/common/url_constants.h" | 47 #include "content/public/common/url_constants.h" |
| 47 #include "extensions/common/constants.h" | 48 #include "extensions/common/constants.h" |
| 49 #include "ipc/ipc_message_macros.h" |
| 48 #include "net/base/net_errors.h" | 50 #include "net/base/net_errors.h" |
| 49 #include "third_party/WebKit/public/web/WebFindOptions.h" | 51 #include "third_party/WebKit/public/web/WebFindOptions.h" |
| 50 #include "ui/base/models/simple_menu_model.h" | 52 #include "ui/base/models/simple_menu_model.h" |
| 51 | 53 |
| 52 #if defined(ENABLE_PRINTING) | 54 #if defined(ENABLE_PRINTING) |
| 53 #if defined(ENABLE_FULL_PRINTING) | 55 #if defined(ENABLE_FULL_PRINTING) |
| 54 #include "chrome/browser/printing/print_preview_message_handler.h" | 56 #include "chrome/browser/printing/print_preview_message_handler.h" |
| 55 #include "chrome/browser/printing/print_view_manager.h" | 57 #include "chrome/browser/printing/print_view_manager.h" |
| 56 #else | 58 #else |
| 57 #include "chrome/browser/printing/print_view_manager_basic.h" | 59 #include "chrome/browser/printing/print_view_manager_basic.h" |
| 58 #endif // defined(ENABLE_FULL_PRINTING) | 60 #endif // defined(ENABLE_FULL_PRINTING) |
| 59 #endif // defined(ENABLE_PRINTING) | 61 #endif // defined(ENABLE_PRINTING) |
| 60 | 62 |
| 61 #if defined(ENABLE_PLUGINS) | 63 #if defined(ENABLE_PLUGINS) |
| 62 #include "chrome/browser/guest_view/web_view/plugin_permission_helper.h" | 64 #include "chrome/browser/guest_view/web_view/plugin_permission_helper.h" |
| 63 #endif | 65 #endif |
| 64 | 66 |
| 65 #if defined(OS_CHROMEOS) | 67 #if defined(OS_CHROMEOS) |
| 66 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 68 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 67 #endif | 69 #endif |
| 68 | 70 |
| 69 using base::UserMetricsAction; | 71 using base::UserMetricsAction; |
| 72 using content::RenderFrameHost; |
| 70 using content::WebContents; | 73 using content::WebContents; |
| 71 | 74 |
| 72 namespace { | 75 namespace { |
| 73 | 76 |
| 74 std::string WindowOpenDispositionToString( | 77 std::string WindowOpenDispositionToString( |
| 75 WindowOpenDisposition window_open_disposition) { | 78 WindowOpenDisposition window_open_disposition) { |
| 76 switch (window_open_disposition) { | 79 switch (window_open_disposition) { |
| 77 case IGNORE_ACTION: | 80 case IGNORE_ACTION: |
| 78 return "ignore"; | 81 return "ignore"; |
| 79 case SAVE_TO_DISK: | 82 case SAVE_TO_DISK: |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 item_value->SetInteger(webview::kMenuItemCommandId, | 306 item_value->SetInteger(webview::kMenuItemCommandId, |
| 304 menu_model.GetCommandIdAt(i)); | 307 menu_model.GetCommandIdAt(i)); |
| 305 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); | 308 item_value->SetString(webview::kMenuItemLabel, menu_model.GetLabelAt(i)); |
| 306 items->Append(item_value); | 309 items->Append(item_value); |
| 307 } | 310 } |
| 308 return items.Pass(); | 311 return items.Pass(); |
| 309 } | 312 } |
| 310 | 313 |
| 311 void WebViewGuest::Attach(WebContents* embedder_web_contents, | 314 void WebViewGuest::Attach(WebContents* embedder_web_contents, |
| 312 const base::DictionaryValue& args) { | 315 const base::DictionaryValue& args) { |
| 316 std::string name; |
| 317 args.GetString(webview::kName, &name); |
| 318 // If the guest window's name is empty, then the WebView tag's name is |
| 319 // assigned. Otherwise, the guest window's name takes precedence over the |
| 320 // WebView tag's name. |
| 321 if (name_.empty()) |
| 322 name_ = name; |
| 323 ReportFrameNameChange(name_); |
| 324 |
| 313 std::string user_agent_override; | 325 std::string user_agent_override; |
| 314 if (args.GetString(webview::kParameterUserAgentOverride, | 326 if (args.GetString(webview::kParameterUserAgentOverride, |
| 315 &user_agent_override)) { | 327 &user_agent_override)) { |
| 316 SetUserAgentOverride(user_agent_override); | 328 SetUserAgentOverride(user_agent_override); |
| 317 } else { | 329 } else { |
| 318 SetUserAgentOverride(""); | 330 SetUserAgentOverride(""); |
| 319 } | 331 } |
| 320 | 332 |
| 321 GuestViewBase::Attach(embedder_web_contents, args); | 333 GuestViewBase::Attach(embedder_web_contents, args); |
| 322 | 334 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 const GURL& url, | 472 const GURL& url, |
| 461 const std::string& error_type) { | 473 const std::string& error_type) { |
| 462 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 474 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 463 args->SetBoolean(guestview::kIsTopLevel, is_top_level); | 475 args->SetBoolean(guestview::kIsTopLevel, is_top_level); |
| 464 args->SetString(guestview::kUrl, url.possibly_invalid_spec()); | 476 args->SetString(guestview::kUrl, url.possibly_invalid_spec()); |
| 465 args->SetString(guestview::kReason, error_type); | 477 args->SetString(guestview::kReason, error_type); |
| 466 DispatchEvent( | 478 DispatchEvent( |
| 467 new GuestViewBase::Event(webview::kEventLoadAbort, args.Pass())); | 479 new GuestViewBase::Event(webview::kEventLoadAbort, args.Pass())); |
| 468 } | 480 } |
| 469 | 481 |
| 482 void WebViewGuest::OnUpdateFrameName(bool is_top_level, |
| 483 const std::string& name) { |
| 484 if (!is_top_level) |
| 485 return; |
| 486 |
| 487 if (name_ == name) |
| 488 return; |
| 489 |
| 490 ReportFrameNameChange(name); |
| 491 } |
| 492 |
| 470 WebViewGuest* WebViewGuest::CreateNewGuestWindow( | 493 WebViewGuest* WebViewGuest::CreateNewGuestWindow( |
| 471 const content::OpenURLParams& params) { | 494 const content::OpenURLParams& params) { |
| 472 | 495 |
| 473 GuestViewManager* guest_manager = | 496 GuestViewManager* guest_manager = |
| 474 GuestViewManager::FromBrowserContext(browser_context()); | 497 GuestViewManager::FromBrowserContext(browser_context()); |
| 475 // Allocate a new instance ID for the new guest. | 498 // Allocate a new instance ID for the new guest. |
| 476 int instance_id = guest_manager->GetNextInstanceID(); | 499 int instance_id = guest_manager->GetNextInstanceID(); |
| 477 | 500 |
| 478 // Set the attach params to use the same partition as the opener. | 501 // Set the attach params to use the same partition as the opener. |
| 479 // We pull the partition information from the site's URL, which is of the | 502 // We pull the partition information from the site's URL, which is of the |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 content::RenderViewHost* render_view_host) { | 855 content::RenderViewHost* render_view_host) { |
| 833 if (frame_id == main_frame_id_) | 856 if (frame_id == main_frame_id_) |
| 834 InjectChromeVoxIfNeeded(render_view_host); | 857 InjectChromeVoxIfNeeded(render_view_host); |
| 835 } | 858 } |
| 836 | 859 |
| 837 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { | 860 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { |
| 838 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 861 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 839 DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); | 862 DispatchEvent(new GuestViewBase::Event(webview::kEventLoadStop, args.Pass())); |
| 840 } | 863 } |
| 841 | 864 |
| 865 bool WebViewGuest::OnMessageReceived(const IPC::Message& message, |
| 866 RenderFrameHost* render_frame_host) { |
| 867 bool handled = true; |
| 868 IPC_BEGIN_MESSAGE_MAP(WebViewGuest, message) |
| 869 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_UpdateFrameName, OnUpdateFrameName) |
| 870 IPC_MESSAGE_UNHANDLED(handled = false) |
| 871 IPC_END_MESSAGE_MAP() |
| 872 return handled; |
| 873 } |
| 874 |
| 842 void WebViewGuest::WebContentsDestroyed() { | 875 void WebViewGuest::WebContentsDestroyed() { |
| 843 // Clean up custom context menu items for this guest. | 876 // Clean up custom context menu items for this guest. |
| 844 extensions::MenuManager* menu_manager = extensions::MenuManager::Get( | 877 extensions::MenuManager* menu_manager = extensions::MenuManager::Get( |
| 845 Profile::FromBrowserContext(browser_context())); | 878 Profile::FromBrowserContext(browser_context())); |
| 846 menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey( | 879 menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey( |
| 847 embedder_extension_id(), view_instance_id())); | 880 embedder_extension_id(), view_instance_id())); |
| 848 | 881 |
| 849 RemoveWebViewFromExtensionRendererState(web_contents()); | 882 RemoveWebViewFromExtensionRendererState(web_contents()); |
| 850 } | 883 } |
| 851 | 884 |
| 852 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { | 885 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { |
| 853 content::NavigationController& controller = | 886 content::NavigationController& controller = |
| 854 guest_web_contents()->GetController(); | 887 guest_web_contents()->GetController(); |
| 855 content::NavigationEntry* entry = controller.GetVisibleEntry(); | 888 content::NavigationEntry* entry = controller.GetVisibleEntry(); |
| 856 if (!entry) | 889 if (!entry) |
| 857 return; | 890 return; |
| 858 entry->SetIsOverridingUserAgent(!user_agent.empty()); | 891 entry->SetIsOverridingUserAgent(!user_agent.empty()); |
| 859 if (!attached()) { | 892 if (!attached()) { |
| 860 // We cannot reload now because all resource loads are suspended until | 893 // We cannot reload now because all resource loads are suspended until |
| 861 // attachment. | 894 // attachment. |
| 862 pending_reload_on_attachment_ = true; | 895 pending_reload_on_attachment_ = true; |
| 863 return; | 896 return; |
| 864 } | 897 } |
| 865 guest_web_contents()->GetController().Reload(false); | 898 guest_web_contents()->GetController().Reload(false); |
| 866 } | 899 } |
| 867 | 900 |
| 901 void WebViewGuest::RenderViewReady() { |
| 902 Send(new ChromeViewMsg_SetName(guest_web_contents()->GetRoutingID(), name_)); |
| 903 } |
| 904 |
| 905 void WebViewGuest::ReportFrameNameChange(const std::string& name) { |
| 906 name_ = name; |
| 907 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 908 args->SetString(webview::kName, name); |
| 909 DispatchEvent( |
| 910 new GuestViewBase::Event(webview::kEventFrameNameChanged, args.Pass())); |
| 911 } |
| 912 |
| 868 void WebViewGuest::LoadHandlerCalled() { | 913 void WebViewGuest::LoadHandlerCalled() { |
| 869 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 914 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| 870 DispatchEvent( | 915 DispatchEvent( |
| 871 new GuestViewBase::Event(webview::kEventContentLoad, args.Pass())); | 916 new GuestViewBase::Event(webview::kEventContentLoad, args.Pass())); |
| 872 } | 917 } |
| 873 | 918 |
| 874 void WebViewGuest::LoadRedirect(const GURL& old_url, | 919 void WebViewGuest::LoadRedirect(const GURL& old_url, |
| 875 const GURL& new_url, | 920 const GURL& new_url, |
| 876 bool is_top_level) { | 921 bool is_top_level) { |
| 877 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 922 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1198 return; | 1243 return; |
| 1199 | 1244 |
| 1200 // TODO(lazyboy): Implement. | 1245 // TODO(lazyboy): Implement. |
| 1201 DCHECK(!items); | 1246 DCHECK(!items); |
| 1202 | 1247 |
| 1203 ContextMenuDelegate* menu_delegate = | 1248 ContextMenuDelegate* menu_delegate = |
| 1204 ContextMenuDelegate::FromWebContents(guest_web_contents()); | 1249 ContextMenuDelegate::FromWebContents(guest_web_contents()); |
| 1205 menu_delegate->ShowMenu(pending_menu_.Pass()); | 1250 menu_delegate->ShowMenu(pending_menu_.Pass()); |
| 1206 } | 1251 } |
| 1207 | 1252 |
| 1253 void WebViewGuest::SetName(const std::string& name) { |
| 1254 if (name_ == name) |
| 1255 return; |
| 1256 name_ = name; |
| 1257 |
| 1258 Send(new ChromeViewMsg_SetName(routing_id(), name_)); |
| 1259 } |
| 1260 |
| 1208 void WebViewGuest::Destroy() { | 1261 void WebViewGuest::Destroy() { |
| 1209 if (!attached() && GetOpener()) | 1262 if (!attached() && GetOpener()) |
| 1210 GetOpener()->pending_new_windows_.erase(this); | 1263 GetOpener()->pending_new_windows_.erase(this); |
| 1211 DestroyUnattachedWindows(); | 1264 DestroyUnattachedWindows(); |
| 1212 GuestViewBase::Destroy(); | 1265 GuestViewBase::Destroy(); |
| 1213 } | 1266 } |
| 1214 | 1267 |
| 1215 void WebViewGuest::AddNewContents(content::WebContents* source, | 1268 void WebViewGuest::AddNewContents(content::WebContents* source, |
| 1216 content::WebContents* new_contents, | 1269 content::WebContents* new_contents, |
| 1217 WindowOpenDisposition disposition, | 1270 WindowOpenDisposition disposition, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 | 1309 |
| 1257 void WebViewGuest::WebContentsCreated(WebContents* source_contents, | 1310 void WebViewGuest::WebContentsCreated(WebContents* source_contents, |
| 1258 int opener_render_frame_id, | 1311 int opener_render_frame_id, |
| 1259 const base::string16& frame_name, | 1312 const base::string16& frame_name, |
| 1260 const GURL& target_url, | 1313 const GURL& target_url, |
| 1261 content::WebContents* new_contents) { | 1314 content::WebContents* new_contents) { |
| 1262 WebViewGuest* guest = WebViewGuest::FromWebContents(new_contents); | 1315 WebViewGuest* guest = WebViewGuest::FromWebContents(new_contents); |
| 1263 CHECK(guest); | 1316 CHECK(guest); |
| 1264 guest->SetOpener(this); | 1317 guest->SetOpener(this); |
| 1265 std::string guest_name = base::UTF16ToUTF8(frame_name); | 1318 std::string guest_name = base::UTF16ToUTF8(frame_name); |
| 1319 guest->name_ = guest_name; |
| 1266 pending_new_windows_.insert( | 1320 pending_new_windows_.insert( |
| 1267 std::make_pair(guest, NewWindowInfo(target_url, guest_name))); | 1321 std::make_pair(guest, NewWindowInfo(target_url, guest_name))); |
| 1268 } | 1322 } |
| 1269 | 1323 |
| 1270 void WebViewGuest::LoadURLWithParams(const GURL& url, | 1324 void WebViewGuest::LoadURLWithParams(const GURL& url, |
| 1271 const content::Referrer& referrer, | 1325 const content::Referrer& referrer, |
| 1272 content::PageTransition transition_type, | 1326 content::PageTransition transition_type, |
| 1273 content::WebContents* web_contents) { | 1327 content::WebContents* web_contents) { |
| 1274 content::NavigationController::LoadURLParams load_url_params(url); | 1328 content::NavigationController::LoadURLParams load_url_params(url); |
| 1275 load_url_params.referrer = referrer; | 1329 load_url_params.referrer = referrer; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 bool allow, | 1404 bool allow, |
| 1351 const std::string& user_input) { | 1405 const std::string& user_input) { |
| 1352 WebViewGuest* guest = | 1406 WebViewGuest* guest = |
| 1353 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1407 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
| 1354 if (!guest) | 1408 if (!guest) |
| 1355 return; | 1409 return; |
| 1356 | 1410 |
| 1357 if (!allow) | 1411 if (!allow) |
| 1358 guest->Destroy(); | 1412 guest->Destroy(); |
| 1359 } | 1413 } |
| OLD | NEW |