render_frame_host_impl.cc revision 0529e5d033099cbfc42635f6f6183833b09dff6e
1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// found in the LICENSE file. 4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "content/browser/frame_host/render_frame_host_impl.h" 6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 70529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "base/bind.h" 8424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "base/containers/hash_tables.h" 9424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "base/lazy_instance.h" 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/metrics/user_metrics_action.h" 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/browser/child_process_security_policy_impl.h" 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/browser/frame_host/cross_process_frame_connector.h" 13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/browser/frame_host/cross_site_transferring_request.h" 141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "content/browser/frame_host/frame_tree.h" 15a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "content/browser/frame_host/frame_tree_node.h" 16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "content/browser/frame_host/navigator.h" 17a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "content/browser/frame_host/render_frame_host_delegate.h" 18effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "content/browser/renderer_host/input/input_router.h" 19effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "content/browser/renderer_host/input/timeout_monitor.h" 20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/browser/renderer_host/render_view_host_impl.h" 210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "content/common/desktop_notification_messages.h" 224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "content/common/frame_messages.h" 23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/common/input_messages.h" 24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/common/inter_process_time_ticks_converter.h" 2523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "content/common/swapped_out_messages.h" 264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "content/public/browser/browser_thread.h" 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/content_browser_client.h" 280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "content/public/browser/desktop_notification_delegate.h" 294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "content/public/browser/render_process_host.h" 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/render_widget_host_view.h" 31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "content/public/browser/user_metrics.h" 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/common/url_constants.h" 33c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "content/public/common/url_utils.h" 348bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "url/gurl.h" 35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)using base::TimeDelta; 37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace content { 39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochnamespace { 410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 42424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// The (process id, routing id) pair that identifies one RenderFrame. 43424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)typedef std::pair<int32, int32> RenderFrameHostID; 44424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*> 45424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) RoutingIDFrameMap; 460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochbase::LazyInstance<RoutingIDFrameMap> g_routing_id_frame_map = 47424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) LAZY_INSTANCE_INITIALIZER; 48424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 490529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochclass DesktopNotificationDelegateImpl : public DesktopNotificationDelegate { 500529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch public: 510529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch DesktopNotificationDelegateImpl(RenderFrameHost* render_frame_host, 520529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch int notification_id) 530529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch : render_process_id_(render_frame_host->GetProcess()->GetID()), 540529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch render_frame_id_(render_frame_host->GetRoutingID()), 550529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch notification_id_(notification_id) {} 560529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch virtual ~DesktopNotificationDelegateImpl() {} 580529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 590529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch virtual void NotificationDisplayed() OVERRIDE { 600529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch RenderFrameHost* rfh = 610529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch RenderFrameHost::FromID(render_process_id_, render_frame_id_); 620529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (!rfh) 630529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return; 640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 650529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch rfh->Send(new DesktopNotificationMsg_PostDisplay( 660529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch rfh->GetRoutingID(), notification_id_)); 670529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 680529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 690529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch virtual void NotificationError() OVERRIDE { 700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch RenderFrameHost* rfh = 710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch RenderFrameHost::FromID(render_process_id_, render_frame_id_); 720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (!rfh) 730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return; 740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch rfh->Send(new DesktopNotificationMsg_PostError( 760529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch rfh->GetRoutingID(), notification_id_)); 770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch delete this; 780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 790529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 800529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch virtual void NotificationClosed(bool by_user) OVERRIDE { 810529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch RenderFrameHost* rfh = 820529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch RenderFrameHost::FromID(render_process_id_, render_frame_id_); 830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (!rfh) 840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return; 850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch rfh->Send(new DesktopNotificationMsg_PostClose( 870529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch rfh->GetRoutingID(), notification_id_, by_user)); 880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch static_cast<RenderFrameHostImpl*>(rfh)->NotificationClosed( 890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch notification_id_); 900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch delete this; 910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch virtual void NotificationClick() OVERRIDE { 940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch RenderFrameHost* rfh = 950529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch RenderFrameHost::FromID(render_process_id_, render_frame_id_); 960529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (!rfh) 970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return; 980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch rfh->Send(new DesktopNotificationMsg_PostClick( 1000529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch rfh->GetRoutingID(), notification_id_)); 1010529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 1020529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 1030529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch private: 1040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch int render_process_id_; 1050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch int render_frame_id_; 1060529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch int notification_id_; 1070529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}; 1080529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 1090529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} // namespace 1100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)RenderFrameHost* RenderFrameHost::FromID(int render_process_id, 1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int render_frame_id) { 1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return RenderFrameHostImpl::FromID(render_process_id, render_frame_id); 1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 116424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// static 117424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)RenderFrameHostImpl* RenderFrameHostImpl::FromID( 118424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) int process_id, int routing_id) { 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 120424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) RoutingIDFrameMap* frames = g_routing_id_frame_map.Pointer(); 121424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) RoutingIDFrameMap::iterator it = frames->find( 122424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) RenderFrameHostID(process_id, routing_id)); 123424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return it == frames->end() ? NULL : it->second; 124424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 125424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 126868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)RenderFrameHostImpl::RenderFrameHostImpl( 127868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) RenderViewHostImpl* render_view_host, 128a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RenderFrameHostDelegate* delegate, 1294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) FrameTree* frame_tree, 130a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) FrameTreeNode* frame_tree_node, 131868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int routing_id, 132424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) bool is_swapped_out) 133868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) : render_view_host_(render_view_host), 134a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) delegate_(delegate), 1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cross_process_frame_connector_(NULL), 1364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) frame_tree_(frame_tree), 137a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) frame_tree_node_(frame_tree_node), 138424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) routing_id_(routing_id), 1390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch is_swapped_out_(is_swapped_out), 1400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch weak_ptr_factory_(this) { 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) frame_tree_->RegisterRenderFrameHost(this); 142424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) GetProcess()->AddRoute(routing_id_, this); 143424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) g_routing_id_frame_map.Get().insert(std::make_pair( 144424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) RenderFrameHostID(GetProcess()->GetID(), routing_id_), 145424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) this)); 146868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 147868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 148868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)RenderFrameHostImpl::~RenderFrameHostImpl() { 149424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) GetProcess()->RemoveRoute(routing_id_); 150424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) g_routing_id_frame_map.Get().erase( 151424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) RenderFrameHostID(GetProcess()->GetID(), routing_id_)); 152a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (delegate_) 153a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) delegate_->RenderFrameDeleted(this); 1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Notify the FrameTree that this RFH is going away, allowing it to shut down 1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // the corresponding RenderViewHost if it is no longer needed. 1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) frame_tree_->UnregisterRenderFrameHost(this); 1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 160a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)int RenderFrameHostImpl::GetRoutingID() { 161a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return routing_id_; 162a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 163a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SiteInstance* RenderFrameHostImpl::GetSiteInstance() { 1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return render_view_host_->GetSiteInstance(); 1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)RenderProcessHost* RenderFrameHostImpl::GetProcess() { 1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // TODO(nasko): This should return its own process, once we have working 1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // cross-process navigation for subframes. 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return render_view_host_->GetProcess(); 172a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} 173424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 174a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)RenderFrameHost* RenderFrameHostImpl::GetParent() { 175a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FrameTreeNode* parent_node = frame_tree_node_->parent(); 176a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!parent_node) 177a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return NULL; 178a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return parent_node->current_frame_host(); 179a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 180a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 18123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)const std::string& RenderFrameHostImpl::GetFrameName() { 18223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) return frame_tree_node_->frame_name(); 18323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)} 18423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 185a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool RenderFrameHostImpl::IsCrossProcessSubframe() { 186a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) FrameTreeNode* parent_node = frame_tree_node_->parent(); 187a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!parent_node) 188a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return false; 189a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return GetSiteInstance() != 190a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) parent_node->current_frame_host()->GetSiteInstance(); 191a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 192a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 193a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)GURL RenderFrameHostImpl::GetLastCommittedURL() { 194a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return frame_tree_node_->current_url(); 195868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 196868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::NativeView RenderFrameHostImpl::GetNativeView() { 1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RenderWidgetHostView* view = render_view_host_->GetView(); 1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!view) 2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NULL; 2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return view->GetNativeView(); 2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 204a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::ExecuteJavaScript( 205a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const base::string16& javascript) { 206a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_, 207a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) javascript, 208a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 0, false)); 209a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 210a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 211a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::ExecuteJavaScript( 212a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const base::string16& javascript, 213a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const JavaScriptResultCallback& callback) { 214a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) static int next_id = 1; 215a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) int key = next_id++; 216a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_, 217a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) javascript, 218a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) key, true)); 219a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) javascript_callbacks_.insert(std::make_pair(key, callback)); 220a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 221a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 2225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)RenderViewHost* RenderFrameHostImpl::GetRenderViewHost() { 2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return render_view_host_; 2245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 226868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)bool RenderFrameHostImpl::Send(IPC::Message* message) { 227effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (IPC_MESSAGE_ID_CLASS(message->type()) == InputMsgStart) { 228effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return render_view_host_->input_router()->SendInput( 229effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch make_scoped_ptr(message)); 230effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch } 231effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 232424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return GetProcess()->Send(message); 233868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 234868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 235868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) { 23623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // Filter out most IPC messages if this renderer is swapped out. 23723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // We still want to handle certain ACKs to keep our state consistent. 23823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // TODO(nasko): Only check RenderViewHost state, as this object's own state 23923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // isn't yet properly updated. Transition this check once the swapped out 24023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // state is correct in RenderFrameHost itself. 24123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) if (render_view_host_->IsSwappedOut()) { 24223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) if (!SwappedOutMessages::CanHandleWhileSwappedOut(msg)) { 24323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // If this is a synchronous message and we decided not to handle it, 24423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // we must send an error reply, or else the renderer will be stuck 24523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // and won't respond to future requests. 24623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) if (msg.is_sync()) { 24723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); 24823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) reply->set_reply_error(); 24923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) Send(reply); 25023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) } 25123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // Don't continue looking for someone to handle it. 25223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) return true; 25323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) } 25423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) } 25523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 256a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (delegate_->OnMessageReceived(this, msg)) 257a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return true; 258a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 2595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (cross_process_frame_connector_ && 2605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cross_process_frame_connector_->OnMessageReceived(msg)) 2615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 2625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) bool handled = true; 2644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) bool msg_is_ok = true; 2654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) IPC_BEGIN_MESSAGE_MAP_EX(RenderFrameHostImpl, msg, msg_is_ok) 266c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch IPC_MESSAGE_HANDLER(FrameHostMsg_AddMessageToConsole, OnAddMessageToConsole) 2674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) IPC_MESSAGE_HANDLER(FrameHostMsg_Detach, OnDetach) 268a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) IPC_MESSAGE_HANDLER(FrameHostMsg_FrameFocused, OnFrameFocused) 2698bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartProvisionalLoadForFrame, 2708bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) OnDidStartProvisionalLoadForFrame) 2715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailProvisionalLoadWithError, 2725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) OnDidFailProvisionalLoadWithError) 2735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) IPC_MESSAGE_HANDLER(FrameHostMsg_DidRedirectProvisionalLoad, 2745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) OnDidRedirectProvisionalLoad) 2755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailLoadWithError, 2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) OnDidFailLoadWithError) 2775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad, 2785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) OnNavigate(msg)) 2795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading) 2805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading) 281a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) IPC_MESSAGE_HANDLER(FrameHostMsg_OpenURL, OnOpenURL) 282a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnload_ACK, OnBeforeUnloadACK) 2835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) IPC_MESSAGE_HANDLER(FrameHostMsg_SwapOut_ACK, OnSwapOutACK) 2845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) IPC_MESSAGE_HANDLER(FrameHostMsg_ContextMenu, OnContextMenu) 285a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) IPC_MESSAGE_HANDLER(FrameHostMsg_JavaScriptExecuteResponse, 286a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) OnJavaScriptExecuteResponse) 287c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_RunJavaScriptMessage, 288c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch OnRunJavaScriptMessage) 289c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_RunBeforeUnloadConfirm, 290c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch OnRunBeforeUnloadConfirm) 2910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_RequestPermission, 2920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch OnRequestDesktopNotificationPermission) 2930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Show, 2940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch OnShowDesktopNotification) 2950529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Cancel, 2960529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch OnCancelDesktopNotification) 2974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) IPC_END_MESSAGE_MAP_EX() 2984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 299a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (!msg_is_ok) { 300a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // The message had a handler, but its de-serialization failed. 301a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Kill the renderer. 3025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RecordAction(base::UserMetricsAction("BadMessageTerminate_RFH")); 303a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) GetProcess()->ReceivedBadMessage(); 304a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 305a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 3064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return handled; 307424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)} 308424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 309424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void RenderFrameHostImpl::Init() { 3105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetProcess()->ResumeRequestsForView(routing_id_); 311868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} 312868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 313c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochvoid RenderFrameHostImpl::OnAddMessageToConsole( 314c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch int32 level, 315c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch const base::string16& message, 316c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch int32 line_no, 317c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch const base::string16& source_id) { 318c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch if (delegate_->AddMessageToConsole(level, message, line_no, source_id)) 319c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch return; 320c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 321c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Pass through log level only on WebUI pages to limit console spew. 322c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch int32 resolved_level = 323c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch HasWebUIScheme(delegate_->GetMainFrameLastCommittedURL()) ? level : 0; 324c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 325c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch if (resolved_level >= ::logging::GetMinLogLevel()) { 326c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch logging::LogMessage("CONSOLE", line_no, resolved_level).stream() << "\"" << 327c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch message << "\", source: " << source_id << " (" << line_no << ")"; 328c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch } 329c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch} 330c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 331a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::OnCreateChildFrame(int new_routing_id, 3324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const std::string& frame_name) { 333a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) RenderFrameHostImpl* new_frame = frame_tree_->AddFrame( 334a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) frame_tree_node_, new_routing_id, frame_name); 335a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (delegate_) 336a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) delegate_->RenderFrameCreated(new_frame); 3374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 3384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 339a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::OnDetach() { 340a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) frame_tree_->RemoveFrame(frame_tree_node_); 341a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 342a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 343a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::OnFrameFocused() { 344a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) frame_tree_->SetFocusedFrame(frame_tree_node_); 345a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 346a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 347a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::OnOpenURL( 348a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const FrameHostMsg_OpenURL_Params& params) { 349a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GURL validated_url(params.url); 350a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) GetProcess()->FilterURL(false, &validated_url); 351a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 352a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) frame_tree_node_->navigator()->RequestOpenURL( 353a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) this, validated_url, params.referrer, params.disposition, 354a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) params.should_replace_current_entry, params.user_gesture); 3554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 3564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 3578bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void RenderFrameHostImpl::OnDidStartProvisionalLoadForFrame( 358a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) int parent_routing_id, 3598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const GURL& url) { 360a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) frame_tree_node_->navigator()->DidStartProvisionalLoad( 361effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch this, parent_routing_id, url); 3628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)} 3638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 3645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::OnDidFailProvisionalLoadWithError( 3655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) { 3665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) frame_tree_node_->navigator()->DidFailProvisionalLoadWithError(this, params); 3675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::OnDidFailLoadWithError( 3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const GURL& url, 3715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int error_code, 3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::string16& error_description) { 3735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GURL validated_url(url); 3745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetProcess()->FilterURL(false, &validated_url); 3755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) frame_tree_node_->navigator()->DidFailLoadWithError( 377effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch this, validated_url, error_code, error_description); 3785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::OnDidRedirectProvisionalLoad( 3815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int32 page_id, 3825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const GURL& source_url, 3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const GURL& target_url) { 3845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) frame_tree_node_->navigator()->DidRedirectProvisionalLoad( 3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) this, page_id, source_url, target_url); 3865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Called when the renderer navigates. For every frame loaded, we'll get this 3895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// notification containing parameters identifying the navigation. 3905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// 3915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Subframes are identified by the page transition type. For subframes loaded 3925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// as part of a wider page load, the page_id will be the same as for the top 3935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// level frame. If the user explicitly requests a subframe navigation, we will 3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// get a new page_id because we need to create a new navigation entry for that 3955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// action. 3965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::OnNavigate(const IPC::Message& msg) { 3975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Read the parameters out of the IPC message directly to avoid making another 3985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // copy when we filter the URLs. 3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PickleIterator iter(msg); 4005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FrameHostMsg_DidCommitProvisionalLoad_Params validated_params; 4015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!IPC::ParamTraits<FrameHostMsg_DidCommitProvisionalLoad_Params>:: 4025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Read(&msg, &iter, &validated_params)) 4035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 4045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // If we're waiting for a cross-site beforeunload ack from this renderer and 4065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // we receive a Navigate message from the main frame, then the renderer was 4075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // navigating already and sent it before hearing the ViewMsg_Stop message. 4085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We do not want to cancel the pending navigation in this case, since the 4095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // old page will soon be stopped. Instead, treat this as a beforeunload ack 4105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // to allow the pending navigation to continue. 4115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (render_view_host_->is_waiting_for_beforeunload_ack_ && 4125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) render_view_host_->unload_ack_is_for_cross_site_transition_ && 4135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PageTransitionIsMainFrame(validated_params.transition)) { 414a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) OnBeforeUnloadACK(true, send_before_unload_start_time_, 415a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::TimeTicks::Now()); 4165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 4175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // If we're waiting for an unload ack from this renderer and we receive a 4205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Navigate message, then the renderer was navigating before it received the 4215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // unload request. It will either respond to the unload request soon or our 4225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // timer will expire. Either way, we should ignore this message, because we 4235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // have already committed to closing this renderer. 4245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (render_view_host_->IsWaitingForUnloadACK()) 4255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 4265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RenderProcessHost* process = GetProcess(); 4285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Attempts to commit certain off-limits URL should be caught more strictly 4305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // than our FilterURL checks below. If a renderer violates this policy, it 4315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // should be killed. 4325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!CanCommitURL(validated_params.url)) { 4335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) VLOG(1) << "Blocked URL " << validated_params.url.spec(); 4345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) validated_params.url = GURL(kAboutBlankURL); 4355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RecordAction(base::UserMetricsAction("CanCommitURL_BlockedAndKilled")); 4365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Kills the process. 4375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) process->ReceivedBadMessage(); 4385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Now that something has committed, we don't need to track whether the 4415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // initial page has been accessed. 4425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) render_view_host_->has_accessed_initial_document_ = false; 4435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Without this check, an evil renderer can trick the browser into creating 4455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // a navigation entry for a banned URL. If the user clicks the back button 4465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // followed by the forward button (or clicks reload, or round-trips through 4475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // session restore, etc), we'll think that the browser commanded the 4485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // renderer to load the URL and grant the renderer the privileges to request 4495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // the URL. To prevent this attack, we block the renderer from inserting 4505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // banned URLs into the navigation controller in the first place. 4515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) process->FilterURL(false, &validated_params.url); 4525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) process->FilterURL(true, &validated_params.referrer.url); 4535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (std::vector<GURL>::iterator it(validated_params.redirects.begin()); 4545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) it != validated_params.redirects.end(); ++it) { 4555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) process->FilterURL(false, &(*it)); 4565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) process->FilterURL(true, &validated_params.searchable_form_url); 4585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Without this check, the renderer can trick the browser into using 4605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // filenames it can't access in a future session restore. 4615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!render_view_host_->CanAccessFilesOfPageState( 4625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) validated_params.page_state)) { 4635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetProcess()->ReceivedBadMessage(); 4645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 4655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) frame_tree_node()->navigator()->DidNavigate(this, validated_params); 4685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 4695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 470a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)int RenderFrameHostImpl::GetEnabledBindings() { 471a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return render_view_host_->GetEnabledBindings(); 472a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 473a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 474a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::OnCrossSiteResponse( 475a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const GlobalRequestID& global_request_id, 476a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request, 477a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const std::vector<GURL>& transfer_url_chain, 478a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const Referrer& referrer, 479a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) PageTransition page_transition, 480a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool should_replace_current_entry) { 481a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) frame_tree_node_->render_manager()->OnCrossSiteResponse( 482a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) this, global_request_id, cross_site_transferring_request.Pass(), 483a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) transfer_url_chain, referrer, page_transition, 484a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) should_replace_current_entry); 485a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 486a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 4875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::SwapOut() { 488effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // TODO(creis): Move swapped out state to RFH. Until then, only update it 489effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // when swapping out the main frame. 490effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!GetParent()) { 491effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // If this RenderViewHost is not in the default state, it must have already 492effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // gone through this, therefore just return. 493effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (render_view_host_->rvh_state_ != RenderViewHostImpl::STATE_DEFAULT) 494effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch return; 495effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 496effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch render_view_host_->SetState( 497effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch RenderViewHostImpl::STATE_WAITING_FOR_UNLOAD_ACK); 498effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch render_view_host_->unload_event_monitor_timeout_->Start( 499effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch base::TimeDelta::FromMilliseconds( 500effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch RenderViewHostImpl::kUnloadTimeoutMS)); 5015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 502effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 503effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (render_view_host_->IsRenderViewLive()) 504effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Send(new FrameMsg_SwapOut(routing_id_)); 505effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 506effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!GetParent()) 507effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch delegate_->SwappedOut(this); 508effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 509effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Allow the navigation to proceed. 510effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch frame_tree_node_->render_manager()->SwappedOut(this); 5115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 513effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid RenderFrameHostImpl::OnDidStartLoading(bool to_different_document) { 514effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch delegate_->DidStartLoading(this, to_different_document); 5155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::OnDidStopLoading() { 5185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) delegate_->DidStopLoading(this); 5195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 521a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::OnBeforeUnloadACK( 522a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) bool proceed, 523a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const base::TimeTicks& renderer_before_unload_start_time, 524a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const base::TimeTicks& renderer_before_unload_end_time) { 5250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // TODO(creis): Support properly beforeunload on subframes. For now just 5260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch // pretend that the handler ran and allowed the navigation to proceed. 527a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (GetParent()) { 5280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch render_view_host_->is_waiting_for_beforeunload_ack_ = false; 5290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch frame_tree_node_->render_manager()->OnBeforeUnloadACK( 5300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch render_view_host_->unload_ack_is_for_cross_site_transition_, proceed, 5310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch renderer_before_unload_end_time); 532a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 533a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 534a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 535a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) render_view_host_->decrement_in_flight_event_count(); 536a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) render_view_host_->StopHangMonitorTimeout(); 537a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // If this renderer navigated while the beforeunload request was in flight, we 538a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // may have cleared this state in OnNavigate, in which case we can ignore 539a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // this message. 540c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // However renderer might also be swapped out but we still want to proceed 541c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // with navigation, otherwise it would block future navigations. This can 542c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // happen when pending cross-site navigation is canceled by a second one just 543c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // before OnNavigate while current RVH is waiting for commit but second 544c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // navigation is started from the beginning. 545c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch if (!render_view_host_->is_waiting_for_beforeunload_ack_) { 546a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 547a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 548a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 549a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) render_view_host_->is_waiting_for_beforeunload_ack_ = false; 550a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 551a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::TimeTicks before_unload_end_time; 552a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!send_before_unload_start_time_.is_null() && 553a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) !renderer_before_unload_start_time.is_null() && 554a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) !renderer_before_unload_end_time.is_null()) { 555a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // When passing TimeTicks across process boundaries, we need to compensate 556a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // for any skew between the processes. Here we are converting the 557a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // renderer's notion of before_unload_end_time to TimeTicks in the browser 558a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // process. See comments in inter_process_time_ticks_converter.h for more. 559a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) InterProcessTimeTicksConverter converter( 560a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) LocalTimeTicks::FromTimeTicks(send_before_unload_start_time_), 561a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) LocalTimeTicks::FromTimeTicks(base::TimeTicks::Now()), 562a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) RemoteTimeTicks::FromTimeTicks(renderer_before_unload_start_time), 563a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) RemoteTimeTicks::FromTimeTicks(renderer_before_unload_end_time)); 564a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) LocalTimeTicks browser_before_unload_end_time = 565a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) converter.ToLocalTimeTicks( 566a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) RemoteTimeTicks::FromTimeTicks(renderer_before_unload_end_time)); 567a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) before_unload_end_time = browser_before_unload_end_time.ToTimeTicks(); 568a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 569a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) frame_tree_node_->render_manager()->OnBeforeUnloadACK( 570a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) render_view_host_->unload_ack_is_for_cross_site_transition_, proceed, 571a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) before_unload_end_time); 572a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 573a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // If canceled, notify the delegate to cancel its pending navigation entry. 574a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!proceed) 575a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) render_view_host_->GetDelegate()->DidCancelLoading(); 576a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 577a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 5785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::OnSwapOutACK() { 5795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) OnSwappedOut(false); 5805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::OnSwappedOut(bool timed_out) { 583effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // For now, we only need to update the RVH state machine for top-level swaps. 584effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Subframe swaps (in --site-per-process) can just continue via RFHM. 585effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch if (!GetParent()) 586effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch render_view_host_->OnSwappedOut(timed_out); 587effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch else 588effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch frame_tree_node_->render_manager()->SwappedOut(this); 5895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams& params) { 5925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Validate the URLs in |params|. If the renderer can't request the URLs 5935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // directly, don't show them in the context menu. 5945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ContextMenuParams validated_params(params); 5955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RenderProcessHost* process = GetProcess(); 5965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // We don't validate |unfiltered_link_url| so that this field can be used 5985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // when users want to copy the original link URL. 5995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) process->FilterURL(true, &validated_params.link_url); 6005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) process->FilterURL(true, &validated_params.src_url); 6015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) process->FilterURL(false, &validated_params.page_url); 6025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) process->FilterURL(true, &validated_params.frame_url); 6035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) delegate_->ShowContextMenu(this, validated_params); 6055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 6065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 607a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::OnJavaScriptExecuteResponse( 608a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) int id, const base::ListValue& result) { 609a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const base::Value* result_value; 610a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (!result.Get(0, &result_value)) { 611a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Programming error or rogue renderer. 612a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) NOTREACHED() << "Got bad arguments for OnJavaScriptExecuteResponse"; 613a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return; 614a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 615a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 616a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) std::map<int, JavaScriptResultCallback>::iterator it = 617a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) javascript_callbacks_.find(id); 618a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (it != javascript_callbacks_.end()) { 619a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) it->second.Run(result_value); 620a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) javascript_callbacks_.erase(it); 621a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } else { 622a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) NOTREACHED() << "Received script response for unknown request"; 623a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) } 624a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 625a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 626c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochvoid RenderFrameHostImpl::OnRunJavaScriptMessage( 627c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch const base::string16& message, 628c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch const base::string16& default_prompt, 629c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch const GURL& frame_url, 630c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch JavaScriptMessageType type, 631c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch IPC::Message* reply_msg) { 632c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // While a JS message dialog is showing, tabs in the same process shouldn't 633c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // process input events. 634c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch GetProcess()->SetIgnoreInputEvents(true); 635c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch render_view_host_->StopHangMonitorTimeout(); 636c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch delegate_->RunJavaScriptMessage(this, message, default_prompt, 637c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch frame_url, type, reply_msg); 638c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch} 639c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 640c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochvoid RenderFrameHostImpl::OnRunBeforeUnloadConfirm( 641c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch const GURL& frame_url, 642c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch const base::string16& message, 643c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch bool is_reload, 644c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch IPC::Message* reply_msg) { 645c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // While a JS before unload dialog is showing, tabs in the same process 646c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // shouldn't process input events. 647c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch GetProcess()->SetIgnoreInputEvents(true); 648c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch render_view_host_->StopHangMonitorTimeout(); 649c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch delegate_->RunBeforeUnloadConfirm(this, message, is_reload, reply_msg); 650c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch} 651c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 6520529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochvoid RenderFrameHostImpl::OnRequestDesktopNotificationPermission( 6530529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const GURL& source_origin, int callback_context) { 6540529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch base::Closure done_callback = base::Bind( 6550529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch &RenderFrameHostImpl::DesktopNotificationPermissionRequestDone, 6560529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch weak_ptr_factory_.GetWeakPtr(), callback_context); 6570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch GetContentClient()->browser()->RequestDesktopNotificationPermission( 6580529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch source_origin, this, done_callback); 6590529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} 6600529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 6610529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochvoid RenderFrameHostImpl::OnShowDesktopNotification( 6620529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch int notification_id, 6630529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch const ShowDesktopNotificationHostMsgParams& params) { 6640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch base::Closure cancel_callback; 6650529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch GetContentClient()->browser()->ShowDesktopNotification( 6660529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch params, this, 6670529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch new DesktopNotificationDelegateImpl(this, notification_id), 6680529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch &cancel_callback); 6690529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch cancel_notification_callbacks_[notification_id] = cancel_callback; 6700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} 6710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 6720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochvoid RenderFrameHostImpl::OnCancelDesktopNotification(int notification_id) { 6730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (!cancel_notification_callbacks_.count(notification_id)) { 6740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch NOTREACHED(); 6750529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch return; 6760529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch } 6770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch cancel_notification_callbacks_[notification_id].Run(); 6780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch cancel_notification_callbacks_.erase(notification_id); 6790529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} 6800529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 6815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::SetPendingShutdown(const base::Closure& on_swap_out) { 6825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) render_view_host_->SetPendingShutdown(on_swap_out); 6835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 6845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool RenderFrameHostImpl::CanCommitURL(const GURL& url) { 6865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // TODO(creis): We should also check for WebUI pages here. Also, when the 6875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // out-of-process iframes implementation is ready, we should check for 6885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // cross-site URLs that are not allowed to commit in this process. 6895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Give the client a chance to disallow URLs from committing. 6915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return GetContentClient()->browser()->CanCommitURL(GetProcess(), url); 6925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 6935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::Navigate(const FrameMsg_Navigate_Params& params) { 6955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TRACE_EVENT0("frame_host", "RenderFrameHostImpl::Navigate"); 6965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Browser plugin guests are not allowed to navigate outside web-safe schemes, 6975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // so do not grant them the ability to request additional URLs. 6985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!GetProcess()->IsGuest()) { 6995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL( 7005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetProcess()->GetID(), params.url); 7015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (params.url.SchemeIs(kDataScheme) && 7025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.base_url_for_data_url.SchemeIs(kFileScheme)) { 7035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // If 'data:' is used, and we have a 'file:' base url, grant access to 7045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // local files. 7055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL( 7065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetProcess()->GetID(), params.base_url_for_data_url); 7075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 7085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 7095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Only send the message if we aren't suspended at the start of a cross-site 7115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // request. 7125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (render_view_host_->navigations_suspended_) { 7135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Shouldn't be possible to have a second navigation while suspended, since 7145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // navigations will only be suspended during a cross-site request. If a 7155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // second navigation occurs, RenderFrameHostManager will cancel this pending 7165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // RFH and create a new pending RFH. 7175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK(!render_view_host_->suspended_nav_params_.get()); 7185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) render_view_host_->suspended_nav_params_.reset( 7195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new FrameMsg_Navigate_Params(params)); 7205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else { 7215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Get back to a clean state, in case we start a new navigation without 7225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // completing a RVH swap or unload handler. 7235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) render_view_host_->SetState(RenderViewHostImpl::STATE_DEFAULT); 7245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 725a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Send(new FrameMsg_Navigate(routing_id_, params)); 7265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 7275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Force the throbber to start. We do this because Blink's "started 7295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // loading" message will be received asynchronously from the UI of the 7305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // browser. But we want to keep the throbber in sync with what's happening 7315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // in the UI. For example, we want to start throbbing immediately when the 7325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // user naivgates even if the renderer is delayed. There is also an issue 7335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // with the throbber starting because the WebUI (which controls whether the 7345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // favicon is displayed) happens synchronously. If the start loading 7355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // messages was asynchronous, then the default favicon would flash in. 7365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // 7375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Blink doesn't send throb notifications for JavaScript URLs, so we 7385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // don't want to either. 7395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!params.url.SchemeIs(kJavaScriptScheme)) 740effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch delegate_->DidStartLoading(this, true); 7415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 7425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::NavigateToURL(const GURL& url) { 7445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FrameMsg_Navigate_Params params; 7455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.page_id = -1; 7465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.pending_history_list_offset = -1; 7475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.current_history_list_offset = -1; 7485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.current_history_list_length = 0; 7495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.url = url; 7505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.transition = PAGE_TRANSITION_LINK; 7515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.navigation_type = FrameMsg_Navigate_Type::NORMAL; 7525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Navigate(params); 7535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 7545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 755c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochvoid RenderFrameHostImpl::DispatchBeforeUnload(bool for_cross_site_transition) { 756c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // TODO(creis): Support subframes. 7570529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch if (!render_view_host_->IsRenderViewLive() || GetParent()) { 758c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // We don't have a live renderer, so just skip running beforeunload. 759c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch render_view_host_->is_waiting_for_beforeunload_ack_ = true; 760c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch render_view_host_->unload_ack_is_for_cross_site_transition_ = 761c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch for_cross_site_transition; 762c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch base::TimeTicks now = base::TimeTicks::Now(); 763c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch OnBeforeUnloadACK(true, now, now); 764c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch return; 765c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch } 766c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 767c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // This may be called more than once (if the user clicks the tab close button 768c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // several times, or if she clicks the tab close button then the browser close 769c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // button), and we only send the message once. 770c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch if (render_view_host_->is_waiting_for_beforeunload_ack_) { 771c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Some of our close messages could be for the tab, others for cross-site 772c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // transitions. We always want to think it's for closing the tab if any 773c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // of the messages were, since otherwise it might be impossible to close 774c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // (if there was a cross-site "close" request pending when the user clicked 775c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // the close button). We want to keep the "for cross site" flag only if 776c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // both the old and the new ones are also for cross site. 777c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch render_view_host_->unload_ack_is_for_cross_site_transition_ = 778c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch render_view_host_->unload_ack_is_for_cross_site_transition_ && 779c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch for_cross_site_transition; 780c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch } else { 781c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Start the hang monitor in case the renderer hangs in the beforeunload 782c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // handler. 783c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch render_view_host_->is_waiting_for_beforeunload_ack_ = true; 784c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch render_view_host_->unload_ack_is_for_cross_site_transition_ = 785c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch for_cross_site_transition; 786c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Increment the in-flight event count, to ensure that input events won't 787c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // cancel the timeout timer. 788c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch render_view_host_->increment_in_flight_event_count(); 789c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch render_view_host_->StartHangMonitorTimeout( 790c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); 791c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch send_before_unload_start_time_ = base::TimeTicks::Now(); 792c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch Send(new FrameMsg_BeforeUnload(routing_id_)); 793c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch } 794effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 795effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 796effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid RenderFrameHostImpl::ExtendSelectionAndDelete(size_t before, 797effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch size_t after) { 798effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch Send(new FrameMsg_ExtendSelectionAndDelete(routing_id_, before, after)); 799effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch} 800effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 801c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochvoid RenderFrameHostImpl::JavaScriptDialogClosed( 802c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch IPC::Message* reply_msg, 803c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch bool success, 804c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch const base::string16& user_input, 805c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch bool dialog_was_suppressed) { 806c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch GetProcess()->SetIgnoreInputEvents(false); 807c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch bool is_waiting = render_view_host_->is_waiting_for_beforeunload_ack() || 808c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch render_view_host_->IsWaitingForUnloadACK(); 809c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 810c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // If we are executing as part of (before)unload event handling, we don't 811c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // want to use the regular hung_renderer_delay_ms_ if the user has agreed to 812c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // leave the current page. In this case, use the regular timeout value used 813c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // during the (before)unload handling. 814c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch if (is_waiting) { 815c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch render_view_host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds( 816c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch success ? RenderViewHostImpl::kUnloadTimeoutMS 817c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch : render_view_host_->hung_renderer_delay_ms_)); 818c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch } 819c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 820c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch FrameHostMsg_RunJavaScriptMessage::WriteReplyParams(reply_msg, 821c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch success, user_input); 822c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch Send(reply_msg); 823c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 824c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // If we are waiting for an unload or beforeunload ack and the user has 825c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // suppressed messages, kill the tab immediately; a page that's spamming 826c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // alerts in onbeforeunload is presumably malicious, so there's no point in 827c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // continuing to run its script and dragging out the process. 828c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // This must be done after sending the reply since RenderView can't close 829c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // correctly while waiting for a response. 830c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch if (is_waiting && dialog_was_suppressed) 831c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch render_view_host_->delegate_->RendererUnresponsive( 832c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch render_view_host_, 833c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch render_view_host_->is_waiting_for_beforeunload_ack(), 834c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch render_view_host_->IsWaitingForUnloadACK()); 835c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch} 836c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 8370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochvoid RenderFrameHostImpl::NotificationClosed(int notification_id) { 8380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch cancel_notification_callbacks_.erase(notification_id); 8390529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} 8400529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 8410529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochvoid RenderFrameHostImpl::DesktopNotificationPermissionRequestDone( 8420529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch int callback_context) { 8430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch Send(new DesktopNotificationMsg_PermissionRequestDone( 8440529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch routing_id_, callback_context)); 8450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch} 8460529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 847868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)} // namespace content 848