| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/web_contents/web_contents_impl.h" | 5 #include "content/browser/web_contents/web_contents_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 173 |
| 174 const char kDotGoogleDotCom[] = ".google.com"; | 174 const char kDotGoogleDotCom[] = ".google.com"; |
| 175 | 175 |
| 176 #if defined(OS_ANDROID) | 176 #if defined(OS_ANDROID) |
| 177 const char kWebContentsAndroidKey[] = "web_contents_android"; | 177 const char kWebContentsAndroidKey[] = "web_contents_android"; |
| 178 #endif // OS_ANDROID | 178 #endif // OS_ANDROID |
| 179 | 179 |
| 180 base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> > | 180 base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> > |
| 181 g_created_callbacks = LAZY_INSTANCE_INITIALIZER; | 181 g_created_callbacks = LAZY_INSTANCE_INITIALIZER; |
| 182 | 182 |
| 183 static int StartDownload(content::RenderFrameHost* rfh, | 183 static int StartDownload(RenderFrameHost* rfh, |
| 184 const GURL& url, | 184 const GURL& url, |
| 185 bool is_favicon, | 185 bool is_favicon, |
| 186 uint32_t max_bitmap_size) { | 186 uint32_t max_bitmap_size) { |
| 187 static int g_next_image_download_id = 0; | 187 static int g_next_image_download_id = 0; |
| 188 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(), | 188 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(), |
| 189 ++g_next_image_download_id, | 189 ++g_next_image_download_id, |
| 190 url, | 190 url, |
| 191 is_favicon, | 191 is_favicon, |
| 192 max_bitmap_size)); | 192 max_bitmap_size)); |
| 193 return g_next_image_download_id; | 193 return g_next_image_download_id; |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) | 569 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) |
| 570 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits) | 570 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits) |
| 571 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory) | 571 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory) |
| 572 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler, | 572 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler, |
| 573 OnRegisterProtocolHandler) | 573 OnRegisterProtocolHandler) |
| 574 IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterProtocolHandler, | 574 IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterProtocolHandler, |
| 575 OnUnregisterProtocolHandler) | 575 OnUnregisterProtocolHandler) |
| 576 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply) | 576 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply) |
| 577 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) | 577 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) |
| 578 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) | 578 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) |
| 579 #if defined(ENABLE_PLUGINS) |
| 579 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, | 580 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, |
| 580 OnRequestPpapiBrokerPermission) | 581 OnRequestPpapiBrokerPermission) |
| 581 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach, | 582 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach, |
| 582 OnBrowserPluginMessage(message)) | 583 OnBrowserPluginMessage(message)) |
| 584 #endif |
| 583 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage) | 585 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage) |
| 584 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) | 586 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) |
| 585 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage, | 587 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage, |
| 586 OnShowValidationMessage) | 588 OnShowValidationMessage) |
| 587 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage, | 589 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage, |
| 588 OnHideValidationMessage) | 590 OnHideValidationMessage) |
| 589 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage, | 591 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage, |
| 590 OnMoveValidationMessage) | 592 OnMoveValidationMessage) |
| 591 #if defined(OS_ANDROID) | 593 #if defined(OS_ANDROID) |
| 592 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply, | 594 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 accessibility_mode_ = mode; | 723 accessibility_mode_ = mode; |
| 722 frame_tree_.ForEach( | 724 frame_tree_.ForEach( |
| 723 base::Bind(&ForEachFrameInternal, | 725 base::Bind(&ForEachFrameInternal, |
| 724 base::Bind(&SetAccessibilityModeOnFrame, mode))); | 726 base::Bind(&SetAccessibilityModeOnFrame, mode))); |
| 725 frame_tree_.ForEach( | 727 frame_tree_.ForEach( |
| 726 base::Bind(&ForEachPendingFrameInternal, | 728 base::Bind(&ForEachPendingFrameInternal, |
| 727 base::Bind(&SetAccessibilityModeOnFrame, mode))); | 729 base::Bind(&SetAccessibilityModeOnFrame, mode))); |
| 728 } | 730 } |
| 729 | 731 |
| 730 void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) { | 732 void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) { |
| 731 SetAccessibilityMode( | 733 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode)); |
| 732 content::AddAccessibilityModeTo(accessibility_mode_, mode)); | |
| 733 } | 734 } |
| 734 | 735 |
| 735 void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) { | 736 void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) { |
| 736 SetAccessibilityMode( | 737 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode)); |
| 737 content::RemoveAccessibilityModeFrom(accessibility_mode_, mode)); | |
| 738 } | 738 } |
| 739 | 739 |
| 740 WebUI* WebContentsImpl::CreateWebUI(const GURL& url) { | 740 WebUI* WebContentsImpl::CreateWebUI(const GURL& url) { |
| 741 WebUIImpl* web_ui = new WebUIImpl(this); | 741 WebUIImpl* web_ui = new WebUIImpl(this); |
| 742 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()-> | 742 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()-> |
| 743 CreateWebUIControllerForURL(web_ui, url); | 743 CreateWebUIControllerForURL(web_ui, url); |
| 744 if (controller) { | 744 if (controller) { |
| 745 web_ui->AddMessageHandler(new GenericHandler()); | 745 web_ui->AddMessageHandler(new GenericHandler()); |
| 746 web_ui->SetController(controller); | 746 web_ui->SetController(controller); |
| 747 return web_ui; | 747 return web_ui; |
| (...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1452 | 1452 |
| 1453 // A message to create a new window can only come from the active process for | 1453 // A message to create a new window can only come from the active process for |
| 1454 // this WebContentsImpl instance. If any other process sends the request, | 1454 // this WebContentsImpl instance. If any other process sends the request, |
| 1455 // it is invalid and the process must be terminated. | 1455 // it is invalid and the process must be terminated. |
| 1456 if (GetRenderProcessHost()->GetID() != render_process_id) { | 1456 if (GetRenderProcessHost()->GetID() != render_process_id) { |
| 1457 base::ProcessHandle process_handle = | 1457 base::ProcessHandle process_handle = |
| 1458 RenderProcessHost::FromID(render_process_id)->GetHandle(); | 1458 RenderProcessHost::FromID(render_process_id)->GetHandle(); |
| 1459 if (process_handle != base::kNullProcessHandle) { | 1459 if (process_handle != base::kNullProcessHandle) { |
| 1460 RecordAction( | 1460 RecordAction( |
| 1461 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow")); | 1461 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow")); |
| 1462 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false); | 1462 base::KillProcess(process_handle, RESULT_CODE_KILLED, false); |
| 1463 } | 1463 } |
| 1464 return; | 1464 return; |
| 1465 } | 1465 } |
| 1466 | 1466 |
| 1467 // We must assign the SessionStorageNamespace before calling Init(). | 1467 // We must assign the SessionStorageNamespace before calling Init(). |
| 1468 // | 1468 // |
| 1469 // http://crbug.com/142685 | 1469 // http://crbug.com/142685 |
| 1470 const std::string& partition_id = | 1470 const std::string& partition_id = |
| 1471 GetContentClient()->browser()-> | 1471 GetContentClient()->browser()-> |
| 1472 GetStoragePartitionIdForSite(GetBrowserContext(), | 1472 GetStoragePartitionIdForSite(GetBrowserContext(), |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1586 RenderProcessHost* process = GetRenderProcessHost(); | 1586 RenderProcessHost* process = GetRenderProcessHost(); |
| 1587 // A message to create a new widget can only come from the active process for | 1587 // A message to create a new widget can only come from the active process for |
| 1588 // this WebContentsImpl instance. If any other process sends the request, | 1588 // this WebContentsImpl instance. If any other process sends the request, |
| 1589 // it is invalid and the process must be terminated. | 1589 // it is invalid and the process must be terminated. |
| 1590 if (process->GetID() != render_process_id) { | 1590 if (process->GetID() != render_process_id) { |
| 1591 base::ProcessHandle process_handle = | 1591 base::ProcessHandle process_handle = |
| 1592 RenderProcessHost::FromID(render_process_id)->GetHandle(); | 1592 RenderProcessHost::FromID(render_process_id)->GetHandle(); |
| 1593 if (process_handle != base::kNullProcessHandle) { | 1593 if (process_handle != base::kNullProcessHandle) { |
| 1594 RecordAction( | 1594 RecordAction( |
| 1595 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget")); | 1595 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget")); |
| 1596 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false); | 1596 base::KillProcess(process_handle, RESULT_CODE_KILLED, false); |
| 1597 } | 1597 } |
| 1598 return; | 1598 return; |
| 1599 } | 1599 } |
| 1600 | 1600 |
| 1601 RenderWidgetHostImpl* widget_host = | 1601 RenderWidgetHostImpl* widget_host = |
| 1602 new RenderWidgetHostImpl(this, process, route_id, IsHidden()); | 1602 new RenderWidgetHostImpl(this, process, route_id, IsHidden()); |
| 1603 created_widgets_.insert(widget_host); | 1603 created_widgets_.insert(widget_host); |
| 1604 | 1604 |
| 1605 RenderWidgetHostViewBase* widget_view = | 1605 RenderWidgetHostViewBase* widget_view = |
| 1606 static_cast<RenderWidgetHostViewBase*>( | 1606 static_cast<RenderWidgetHostViewBase*>( |
| (...skipping 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2930 | 2930 |
| 2931 // This exists for render views that don't have a WebUI, but do have WebUI | 2931 // This exists for render views that don't have a WebUI, but do have WebUI |
| 2932 // bindings enabled. | 2932 // bindings enabled. |
| 2933 void WebContentsImpl::OnWebUISend(const GURL& source_url, | 2933 void WebContentsImpl::OnWebUISend(const GURL& source_url, |
| 2934 const std::string& name, | 2934 const std::string& name, |
| 2935 const base::ListValue& args) { | 2935 const base::ListValue& args) { |
| 2936 if (delegate_) | 2936 if (delegate_) |
| 2937 delegate_->WebUISend(this, source_url, name, args); | 2937 delegate_->WebUISend(this, source_url, name, args); |
| 2938 } | 2938 } |
| 2939 | 2939 |
| 2940 #if defined(ENABLE_PLUGINS) |
| 2940 void WebContentsImpl::OnRequestPpapiBrokerPermission( | 2941 void WebContentsImpl::OnRequestPpapiBrokerPermission( |
| 2941 int routing_id, | 2942 int routing_id, |
| 2942 const GURL& url, | 2943 const GURL& url, |
| 2943 const base::FilePath& plugin_path) { | 2944 const base::FilePath& plugin_path) { |
| 2944 if (!delegate_) { | 2945 if (!delegate_) { |
| 2945 OnPpapiBrokerPermissionResult(routing_id, false); | 2946 OnPpapiBrokerPermissionResult(routing_id, false); |
| 2946 return; | 2947 return; |
| 2947 } | 2948 } |
| 2948 | 2949 |
| 2949 if (!delegate_->RequestPpapiBrokerPermission( | 2950 if (!delegate_->RequestPpapiBrokerPermission( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2963 void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) { | 2964 void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) { |
| 2964 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin | 2965 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin |
| 2965 // specific messages for this WebContents. This means that any message from | 2966 // specific messages for this WebContents. This means that any message from |
| 2966 // a BrowserPlugin prior to this will be ignored. | 2967 // a BrowserPlugin prior to this will be ignored. |
| 2967 // For more info, see comment above classes BrowserPluginEmbedder and | 2968 // For more info, see comment above classes BrowserPluginEmbedder and |
| 2968 // BrowserPluginGuest. | 2969 // BrowserPluginGuest. |
| 2969 CHECK(!browser_plugin_embedder_.get()); | 2970 CHECK(!browser_plugin_embedder_.get()); |
| 2970 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this)); | 2971 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this)); |
| 2971 browser_plugin_embedder_->OnMessageReceived(message); | 2972 browser_plugin_embedder_->OnMessageReceived(message); |
| 2972 } | 2973 } |
| 2974 #endif |
| 2973 | 2975 |
| 2974 void WebContentsImpl::OnDidDownloadImage( | 2976 void WebContentsImpl::OnDidDownloadImage( |
| 2975 int id, | 2977 int id, |
| 2976 int http_status_code, | 2978 int http_status_code, |
| 2977 const GURL& image_url, | 2979 const GURL& image_url, |
| 2978 const std::vector<SkBitmap>& bitmaps, | 2980 const std::vector<SkBitmap>& bitmaps, |
| 2979 const std::vector<gfx::Size>& original_bitmap_sizes) { | 2981 const std::vector<gfx::Size>& original_bitmap_sizes) { |
| 2980 if (bitmaps.size() != original_bitmap_sizes.size()) | 2982 if (bitmaps.size() != original_bitmap_sizes.size()) |
| 2981 return; | 2983 return; |
| 2982 | 2984 |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3659 void WebContentsImpl::DidAccessInitialDocument() { | 3661 void WebContentsImpl::DidAccessInitialDocument() { |
| 3660 has_accessed_initial_document_ = true; | 3662 has_accessed_initial_document_ = true; |
| 3661 | 3663 |
| 3662 // We may have left a failed browser-initiated navigation in the address bar | 3664 // We may have left a failed browser-initiated navigation in the address bar |
| 3663 // to let the user edit it and try again. Clear it now that content might | 3665 // to let the user edit it and try again. Clear it now that content might |
| 3664 // show up underneath it. | 3666 // show up underneath it. |
| 3665 if (!IsLoading() && controller_.GetPendingEntry()) | 3667 if (!IsLoading() && controller_.GetPendingEntry()) |
| 3666 controller_.DiscardPendingEntry(); | 3668 controller_.DiscardPendingEntry(); |
| 3667 | 3669 |
| 3668 // Update the URL display. | 3670 // Update the URL display. |
| 3669 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL); | 3671 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
| 3670 } | 3672 } |
| 3671 | 3673 |
| 3672 void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) { | 3674 void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) { |
| 3673 // No action is necessary if the opener has already been cleared. | 3675 // No action is necessary if the opener has already been cleared. |
| 3674 if (!opener_) | 3676 if (!opener_) |
| 3675 return; | 3677 return; |
| 3676 | 3678 |
| 3677 // Clear our opener so that future cross-process navigations don't have an | 3679 // Clear our opener so that future cross-process navigations don't have an |
| 3678 // opener assigned. | 3680 // opener assigned. |
| 3679 RemoveDestructionObserver(opener_); | 3681 RemoveDestructionObserver(opener_); |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4244 node->render_manager()->ResumeResponseDeferredAtStart(); | 4246 node->render_manager()->ResumeResponseDeferredAtStart(); |
| 4245 } | 4247 } |
| 4246 | 4248 |
| 4247 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4249 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 4248 force_disable_overscroll_content_ = force_disable; | 4250 force_disable_overscroll_content_ = force_disable; |
| 4249 if (view_) | 4251 if (view_) |
| 4250 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4252 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 4251 } | 4253 } |
| 4252 | 4254 |
| 4253 } // namespace content | 4255 } // namespace content |
| OLD | NEW |