| 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/renderer_host/render_view_host_impl.h" | 5 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 | 236 |
| 237 RenderViewHostDelegate* RenderViewHostImpl::GetDelegate() const { | 237 RenderViewHostDelegate* RenderViewHostImpl::GetDelegate() const { |
| 238 return delegate_; | 238 return delegate_; |
| 239 } | 239 } |
| 240 | 240 |
| 241 SiteInstance* RenderViewHostImpl::GetSiteInstance() const { | 241 SiteInstance* RenderViewHostImpl::GetSiteInstance() const { |
| 242 return instance_.get(); | 242 return instance_.get(); |
| 243 } | 243 } |
| 244 | 244 |
| 245 bool RenderViewHostImpl::CreateRenderView( | 245 bool RenderViewHostImpl::CreateRenderView( |
| 246 const string16& frame_name, | 246 const base::string16& frame_name, |
| 247 int opener_route_id, | 247 int opener_route_id, |
| 248 int32 max_page_id) { | 248 int32 max_page_id) { |
| 249 TRACE_EVENT0("renderer_host", "RenderViewHostImpl::CreateRenderView"); | 249 TRACE_EVENT0("renderer_host", "RenderViewHostImpl::CreateRenderView"); |
| 250 DCHECK(!IsRenderViewLive()) << "Creating view twice"; | 250 DCHECK(!IsRenderViewLive()) << "Creating view twice"; |
| 251 | 251 |
| 252 // The process may (if we're sharing a process with another host that already | 252 // The process may (if we're sharing a process with another host that already |
| 253 // initialized it) or may not (we have our own process or the old process | 253 // initialized it) or may not (we have our own process or the old process |
| 254 // crashed) have been initialized. Calling Init multiple times will be | 254 // crashed) have been initialized. Calling Init multiple times will be |
| 255 // ignored, so this is safe. | 255 // ignored, so this is safe. |
| 256 if (!GetProcess()->Init()) | 256 if (!GetProcess()->Init()) |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 int callback_context) { | 941 int callback_context) { |
| 942 Send(new DesktopNotificationMsg_PermissionRequestDone( | 942 Send(new DesktopNotificationMsg_PermissionRequestDone( |
| 943 GetRoutingID(), callback_context)); | 943 GetRoutingID(), callback_context)); |
| 944 } | 944 } |
| 945 | 945 |
| 946 void RenderViewHostImpl::DesktopNotificationPostDisplay(int callback_context) { | 946 void RenderViewHostImpl::DesktopNotificationPostDisplay(int callback_context) { |
| 947 Send(new DesktopNotificationMsg_PostDisplay(GetRoutingID(), | 947 Send(new DesktopNotificationMsg_PostDisplay(GetRoutingID(), |
| 948 callback_context)); | 948 callback_context)); |
| 949 } | 949 } |
| 950 | 950 |
| 951 void RenderViewHostImpl::DesktopNotificationPostError(int notification_id, | 951 void RenderViewHostImpl::DesktopNotificationPostError( |
| 952 const string16& message) { | 952 int notification_id, |
| 953 const base::string16& message) { |
| 953 Send(new DesktopNotificationMsg_PostError( | 954 Send(new DesktopNotificationMsg_PostError( |
| 954 GetRoutingID(), notification_id, message)); | 955 GetRoutingID(), notification_id, message)); |
| 955 } | 956 } |
| 956 | 957 |
| 957 void RenderViewHostImpl::DesktopNotificationPostClose(int notification_id, | 958 void RenderViewHostImpl::DesktopNotificationPostClose(int notification_id, |
| 958 bool by_user) { | 959 bool by_user) { |
| 959 Send(new DesktopNotificationMsg_PostClose( | 960 Send(new DesktopNotificationMsg_PostClose( |
| 960 GetRoutingID(), notification_id, by_user)); | 961 GetRoutingID(), notification_id, by_user)); |
| 961 } | 962 } |
| 962 | 963 |
| 963 void RenderViewHostImpl::DesktopNotificationPostClick(int notification_id) { | 964 void RenderViewHostImpl::DesktopNotificationPostClick(int notification_id) { |
| 964 Send(new DesktopNotificationMsg_PostClick(GetRoutingID(), notification_id)); | 965 Send(new DesktopNotificationMsg_PostClick(GetRoutingID(), notification_id)); |
| 965 } | 966 } |
| 966 | 967 |
| 967 void RenderViewHostImpl::ExecuteJavascriptInWebFrame( | 968 void RenderViewHostImpl::ExecuteJavascriptInWebFrame( |
| 968 const string16& frame_xpath, | 969 const base::string16& frame_xpath, |
| 969 const string16& jscript) { | 970 const base::string16& jscript) { |
| 970 Send(new ViewMsg_ScriptEvalRequest(GetRoutingID(), frame_xpath, jscript, | 971 Send(new ViewMsg_ScriptEvalRequest(GetRoutingID(), frame_xpath, jscript, |
| 971 0, false)); | 972 0, false)); |
| 972 } | 973 } |
| 973 | 974 |
| 974 void RenderViewHostImpl::ExecuteJavascriptInWebFrameCallbackResult( | 975 void RenderViewHostImpl::ExecuteJavascriptInWebFrameCallbackResult( |
| 975 const string16& frame_xpath, | 976 const base::string16& frame_xpath, |
| 976 const string16& jscript, | 977 const base::string16& jscript, |
| 977 const JavascriptResultCallback& callback) { | 978 const JavascriptResultCallback& callback) { |
| 978 static int next_id = 1; | 979 static int next_id = 1; |
| 979 int key = next_id++; | 980 int key = next_id++; |
| 980 Send(new ViewMsg_ScriptEvalRequest(GetRoutingID(), frame_xpath, jscript, | 981 Send(new ViewMsg_ScriptEvalRequest(GetRoutingID(), frame_xpath, jscript, |
| 981 key, true)); | 982 key, true)); |
| 982 javascript_callbacks_.insert(std::make_pair(key, callback)); | 983 javascript_callbacks_.insert(std::make_pair(key, callback)); |
| 983 } | 984 } |
| 984 | 985 |
| 985 void RenderViewHostImpl::JavaScriptDialogClosed(IPC::Message* reply_msg, | 986 void RenderViewHostImpl::JavaScriptDialogClosed( |
| 986 bool success, | 987 IPC::Message* reply_msg, |
| 987 const string16& user_input) { | 988 bool success, |
| 989 const base::string16& user_input) { |
| 988 GetProcess()->SetIgnoreInputEvents(false); | 990 GetProcess()->SetIgnoreInputEvents(false); |
| 989 bool is_waiting = | 991 bool is_waiting = |
| 990 is_waiting_for_beforeunload_ack_ || is_waiting_for_unload_ack_; | 992 is_waiting_for_beforeunload_ack_ || is_waiting_for_unload_ack_; |
| 991 | 993 |
| 992 // If we are executing as part of (before)unload event handling, we don't | 994 // If we are executing as part of (before)unload event handling, we don't |
| 993 // want to use the regular hung_renderer_delay_ms_ if the user has agreed to | 995 // want to use the regular hung_renderer_delay_ms_ if the user has agreed to |
| 994 // leave the current page. In this case, use the regular timeout value used | 996 // leave the current page. In this case, use the regular timeout value used |
| 995 // during the (before)unload handling. | 997 // during the (before)unload handling. |
| 996 if (is_waiting) { | 998 if (is_waiting) { |
| 997 StartHangMonitorTimeout(TimeDelta::FromMilliseconds( | 999 StartHangMonitorTimeout(TimeDelta::FromMilliseconds( |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 if (!CanAccessFilesOfPageState(state)) { | 1530 if (!CanAccessFilesOfPageState(state)) { |
| 1529 GetProcess()->ReceivedBadMessage(); | 1531 GetProcess()->ReceivedBadMessage(); |
| 1530 return; | 1532 return; |
| 1531 } | 1533 } |
| 1532 | 1534 |
| 1533 delegate_->UpdateState(this, page_id, state); | 1535 delegate_->UpdateState(this, page_id, state); |
| 1534 } | 1536 } |
| 1535 | 1537 |
| 1536 void RenderViewHostImpl::OnUpdateTitle( | 1538 void RenderViewHostImpl::OnUpdateTitle( |
| 1537 int32 page_id, | 1539 int32 page_id, |
| 1538 const string16& title, | 1540 const base::string16& title, |
| 1539 blink::WebTextDirection title_direction) { | 1541 blink::WebTextDirection title_direction) { |
| 1540 if (title.length() > kMaxTitleChars) { | 1542 if (title.length() > kMaxTitleChars) { |
| 1541 NOTREACHED() << "Renderer sent too many characters in title."; | 1543 NOTREACHED() << "Renderer sent too many characters in title."; |
| 1542 return; | 1544 return; |
| 1543 } | 1545 } |
| 1544 | 1546 |
| 1545 delegate_->UpdateTitle(this, page_id, title, | 1547 delegate_->UpdateTitle(this, page_id, title, |
| 1546 WebTextDirectionToChromeTextDirection( | 1548 WebTextDirectionToChromeTextDirection( |
| 1547 title_direction)); | 1549 title_direction)); |
| 1548 } | 1550 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1662 | 1664 |
| 1663 void RenderViewHostImpl::OnDidChangeScrollOffsetPinningForMainFrame( | 1665 void RenderViewHostImpl::OnDidChangeScrollOffsetPinningForMainFrame( |
| 1664 bool is_pinned_to_left, bool is_pinned_to_right) { | 1666 bool is_pinned_to_left, bool is_pinned_to_right) { |
| 1665 if (view_) | 1667 if (view_) |
| 1666 view_->SetScrollOffsetPinning(is_pinned_to_left, is_pinned_to_right); | 1668 view_->SetScrollOffsetPinning(is_pinned_to_left, is_pinned_to_right); |
| 1667 } | 1669 } |
| 1668 | 1670 |
| 1669 void RenderViewHostImpl::OnDidChangeNumWheelEvents(int count) { | 1671 void RenderViewHostImpl::OnDidChangeNumWheelEvents(int count) { |
| 1670 } | 1672 } |
| 1671 | 1673 |
| 1672 void RenderViewHostImpl::OnSelectionChanged(const string16& text, | 1674 void RenderViewHostImpl::OnSelectionChanged(const base::string16& text, |
| 1673 size_t offset, | 1675 size_t offset, |
| 1674 const gfx::Range& range) { | 1676 const gfx::Range& range) { |
| 1675 if (view_) | 1677 if (view_) |
| 1676 view_->SelectionChanged(text, offset, range); | 1678 view_->SelectionChanged(text, offset, range); |
| 1677 } | 1679 } |
| 1678 | 1680 |
| 1679 void RenderViewHostImpl::OnSelectionBoundsChanged( | 1681 void RenderViewHostImpl::OnSelectionBoundsChanged( |
| 1680 const ViewHostMsg_SelectionBounds_Params& params) { | 1682 const ViewHostMsg_SelectionBounds_Params& params) { |
| 1681 if (view_) { | 1683 if (view_) { |
| 1682 view_->SelectionBoundsChanged(params); | 1684 view_->SelectionBoundsChanged(params); |
| 1683 } | 1685 } |
| 1684 } | 1686 } |
| 1685 | 1687 |
| 1686 void RenderViewHostImpl::OnRouteCloseEvent() { | 1688 void RenderViewHostImpl::OnRouteCloseEvent() { |
| 1687 // Have the delegate route this to the active RenderViewHost. | 1689 // Have the delegate route this to the active RenderViewHost. |
| 1688 delegate_->RouteCloseEvent(this); | 1690 delegate_->RouteCloseEvent(this); |
| 1689 } | 1691 } |
| 1690 | 1692 |
| 1691 void RenderViewHostImpl::OnRouteMessageEvent( | 1693 void RenderViewHostImpl::OnRouteMessageEvent( |
| 1692 const ViewMsg_PostMessage_Params& params) { | 1694 const ViewMsg_PostMessage_Params& params) { |
| 1693 // Give to the delegate to route to the active RenderViewHost. | 1695 // Give to the delegate to route to the active RenderViewHost. |
| 1694 delegate_->RouteMessageEvent(this, params); | 1696 delegate_->RouteMessageEvent(this, params); |
| 1695 } | 1697 } |
| 1696 | 1698 |
| 1697 void RenderViewHostImpl::OnRunJavaScriptMessage( | 1699 void RenderViewHostImpl::OnRunJavaScriptMessage( |
| 1698 const string16& message, | 1700 const base::string16& message, |
| 1699 const string16& default_prompt, | 1701 const base::string16& default_prompt, |
| 1700 const GURL& frame_url, | 1702 const GURL& frame_url, |
| 1701 JavaScriptMessageType type, | 1703 JavaScriptMessageType type, |
| 1702 IPC::Message* reply_msg) { | 1704 IPC::Message* reply_msg) { |
| 1703 // While a JS message dialog is showing, tabs in the same process shouldn't | 1705 // While a JS message dialog is showing, tabs in the same process shouldn't |
| 1704 // process input events. | 1706 // process input events. |
| 1705 GetProcess()->SetIgnoreInputEvents(true); | 1707 GetProcess()->SetIgnoreInputEvents(true); |
| 1706 StopHangMonitorTimeout(); | 1708 StopHangMonitorTimeout(); |
| 1707 delegate_->RunJavaScriptMessage(this, message, default_prompt, frame_url, | 1709 delegate_->RunJavaScriptMessage(this, message, default_prompt, frame_url, |
| 1708 type, reply_msg, | 1710 type, reply_msg, |
| 1709 &are_javascript_messages_suppressed_); | 1711 &are_javascript_messages_suppressed_); |
| 1710 } | 1712 } |
| 1711 | 1713 |
| 1712 void RenderViewHostImpl::OnRunBeforeUnloadConfirm(const GURL& frame_url, | 1714 void RenderViewHostImpl::OnRunBeforeUnloadConfirm(const GURL& frame_url, |
| 1713 const string16& message, | 1715 const base::string16& message, |
| 1714 bool is_reload, | 1716 bool is_reload, |
| 1715 IPC::Message* reply_msg) { | 1717 IPC::Message* reply_msg) { |
| 1716 // While a JS before unload dialog is showing, tabs in the same process | 1718 // While a JS before unload dialog is showing, tabs in the same process |
| 1717 // shouldn't process input events. | 1719 // shouldn't process input events. |
| 1718 GetProcess()->SetIgnoreInputEvents(true); | 1720 GetProcess()->SetIgnoreInputEvents(true); |
| 1719 StopHangMonitorTimeout(); | 1721 StopHangMonitorTimeout(); |
| 1720 delegate_->RunBeforeUnloadConfirm(this, message, is_reload, reply_msg); | 1722 delegate_->RunBeforeUnloadConfirm(this, message, is_reload, reply_msg); |
| 1721 } | 1723 } |
| 1722 | 1724 |
| 1723 void RenderViewHostImpl::OnStartDragging( | 1725 void RenderViewHostImpl::OnStartDragging( |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1782 | 1784 |
| 1783 void RenderViewHostImpl::OnFocusedNodeChanged(bool is_editable_node) { | 1785 void RenderViewHostImpl::OnFocusedNodeChanged(bool is_editable_node) { |
| 1784 NotificationService::current()->Notify( | 1786 NotificationService::current()->Notify( |
| 1785 NOTIFICATION_FOCUS_CHANGED_IN_PAGE, | 1787 NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
| 1786 Source<RenderViewHost>(this), | 1788 Source<RenderViewHost>(this), |
| 1787 Details<const bool>(&is_editable_node)); | 1789 Details<const bool>(&is_editable_node)); |
| 1788 } | 1790 } |
| 1789 | 1791 |
| 1790 void RenderViewHostImpl::OnAddMessageToConsole( | 1792 void RenderViewHostImpl::OnAddMessageToConsole( |
| 1791 int32 level, | 1793 int32 level, |
| 1792 const string16& message, | 1794 const base::string16& message, |
| 1793 int32 line_no, | 1795 int32 line_no, |
| 1794 const string16& source_id) { | 1796 const base::string16& source_id) { |
| 1795 if (delegate_->AddMessageToConsole(level, message, line_no, source_id)) | 1797 if (delegate_->AddMessageToConsole(level, message, line_no, source_id)) |
| 1796 return; | 1798 return; |
| 1797 | 1799 |
| 1798 // Pass through log level only on WebUI pages to limit console spew. | 1800 // Pass through log level only on WebUI pages to limit console spew. |
| 1799 int32 resolved_level = HasWebUIScheme(delegate_->GetURL()) ? level : 0; | 1801 int32 resolved_level = HasWebUIScheme(delegate_->GetURL()) ? level : 0; |
| 1800 | 1802 |
| 1801 if (resolved_level >= ::logging::GetMinLogLevel()) { | 1803 if (resolved_level >= ::logging::GetMinLogLevel()) { |
| 1802 logging::LogMessage("CONSOLE", line_no, resolved_level).stream() << "\"" << | 1804 logging::LogMessage("CONSOLE", line_no, resolved_level).stream() << "\"" << |
| 1803 message << "\", source: " << source_id << " (" << line_no << ")"; | 1805 message << "\", source: " << source_id << " (" << line_no << ")"; |
| 1804 } | 1806 } |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2069 | 2071 |
| 2070 void RenderViewHostImpl::Zoom(PageZoom zoom) { | 2072 void RenderViewHostImpl::Zoom(PageZoom zoom) { |
| 2071 Send(new ViewMsg_Zoom(GetRoutingID(), zoom)); | 2073 Send(new ViewMsg_Zoom(GetRoutingID(), zoom)); |
| 2072 } | 2074 } |
| 2073 | 2075 |
| 2074 void RenderViewHostImpl::ReloadFrame() { | 2076 void RenderViewHostImpl::ReloadFrame() { |
| 2075 Send(new ViewMsg_ReloadFrame(GetRoutingID())); | 2077 Send(new ViewMsg_ReloadFrame(GetRoutingID())); |
| 2076 } | 2078 } |
| 2077 | 2079 |
| 2078 void RenderViewHostImpl::Find(int request_id, | 2080 void RenderViewHostImpl::Find(int request_id, |
| 2079 const string16& search_text, | 2081 const base::string16& search_text, |
| 2080 const blink::WebFindOptions& options) { | 2082 const blink::WebFindOptions& options) { |
| 2081 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options)); | 2083 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options)); |
| 2082 } | 2084 } |
| 2083 | 2085 |
| 2084 void RenderViewHostImpl::InsertCSS(const string16& frame_xpath, | 2086 void RenderViewHostImpl::InsertCSS(const base::string16& frame_xpath, |
| 2085 const std::string& css) { | 2087 const std::string& css) { |
| 2086 Send(new ViewMsg_CSSInsertRequest(GetRoutingID(), frame_xpath, css)); | 2088 Send(new ViewMsg_CSSInsertRequest(GetRoutingID(), frame_xpath, css)); |
| 2087 } | 2089 } |
| 2088 | 2090 |
| 2089 void RenderViewHostImpl::DisableScrollbarsForThreshold(const gfx::Size& size) { | 2091 void RenderViewHostImpl::DisableScrollbarsForThreshold(const gfx::Size& size) { |
| 2090 Send(new ViewMsg_DisableScrollbarsForSmallWindows(GetRoutingID(), size)); | 2092 Send(new ViewMsg_DisableScrollbarsForSmallWindows(GetRoutingID(), size)); |
| 2091 } | 2093 } |
| 2092 | 2094 |
| 2093 void RenderViewHostImpl::EnablePreferredSizeMode() { | 2095 void RenderViewHostImpl::EnablePreferredSizeMode() { |
| 2094 Send(new ViewMsg_EnablePreferredSizeChangedMode(GetRoutingID())); | 2096 Send(new ViewMsg_EnablePreferredSizeChangedMode(GetRoutingID())); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2291 void RenderViewHostImpl::AttachToFrameTree() { | 2293 void RenderViewHostImpl::AttachToFrameTree() { |
| 2292 FrameTree* frame_tree = delegate_->GetFrameTree(); | 2294 FrameTree* frame_tree = delegate_->GetFrameTree(); |
| 2293 | 2295 |
| 2294 frame_tree->SwapMainFrame(main_render_frame_host_.get()); | 2296 frame_tree->SwapMainFrame(main_render_frame_host_.get()); |
| 2295 if (main_frame_id() != FrameTreeNode::kInvalidFrameId) { | 2297 if (main_frame_id() != FrameTreeNode::kInvalidFrameId) { |
| 2296 frame_tree->OnFirstNavigationAfterSwap(main_frame_id()); | 2298 frame_tree->OnFirstNavigationAfterSwap(main_frame_id()); |
| 2297 } | 2299 } |
| 2298 } | 2300 } |
| 2299 | 2301 |
| 2300 } // namespace content | 2302 } // namespace content |
| OLD | NEW |