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"
803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "base/command_line.h"
9424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "base/containers/hash_tables.h"
10424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "base/lazy_instance.h"
1103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "base/metrics/histogram.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/metrics/user_metrics_action.h"
13116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "base/time/time.h"
14116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/browser/accessibility/accessibility_mode_helper.h"
15116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/browser/accessibility/browser_accessibility_manager.h"
16116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/browser/accessibility/browser_accessibility_state_impl.h"
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/browser/child_process_security_policy_impl.h"
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/browser/frame_host/cross_process_frame_connector.h"
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/browser/frame_host/cross_site_transferring_request.h"
201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/browser/frame_host/frame_accessibility.h"
211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "content/browser/frame_host/frame_tree.h"
22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "content/browser/frame_host/frame_tree_node.h"
23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "content/browser/frame_host/navigator.h"
24a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "content/browser/frame_host/render_frame_host_delegate.h"
25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "content/browser/frame_host/render_frame_proxy_host.h"
261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
27effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "content/browser/renderer_host/input/input_router.h"
28effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "content/browser/renderer_host/input/timeout_monitor.h"
29116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/browser/renderer_host/render_process_host_impl.h"
301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/browser/renderer_host/render_view_host_delegate.h"
311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/browser/renderer_host/render_view_host_delegate_view.h"
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/browser/renderer_host/render_view_host_impl.h"
33cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "content/browser/renderer_host/render_widget_host_impl.h"
34116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/browser/renderer_host/render_widget_host_view_base.h"
35116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/browser/transition_request_manager.h"
36116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/common/accessibility_messages.h"
370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "content/common/desktop_notification_messages.h"
384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "content/common/frame_messages.h"
39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/common/input_messages.h"
40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/common/inter_process_time_ticks_converter.h"
415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "content/common/platform_notification_messages.h"
42116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/common/render_frame_setup.mojom.h"
4323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "content/common/swapped_out_messages.h"
44116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/public/browser/ax_event_notification_details.h"
45116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "content/public/browser/browser_accessibility_state.h"
461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/public/browser/browser_context.h"
471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/public/browser/browser_plugin_guest_manager.h"
484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "content/public/browser/browser_thread.h"
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/content_browser_client.h"
500529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "content/public/browser/desktop_notification_delegate.h"
514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "content/public/browser/render_process_host.h"
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/render_widget_host_view.h"
53a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "content/public/browser/user_metrics.h"
54cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "content/public/common/content_constants.h"
5503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "content/public/common/content_switches.h"
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/common/url_constants.h"
57c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "content/public/common/url_utils.h"
58116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ui/accessibility/ax_tree.h"
598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "url/gurl.h"
60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#if defined(OS_MACOSX)
621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/browser/frame_host/popup_menu_helper_mac.h"
631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif
641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
65a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)using base::TimeDelta;
66a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)namespace content {
68868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
690529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochnamespace {
700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
7129b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch// The next value to use for the accessibility reset token.
7229b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdochint g_next_accessibility_reset_token = 1;
7329b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch
74424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// The (process id, routing id) pair that identifies one RenderFrame.
75424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)typedef std::pair<int32, int32> RenderFrameHostID;
76424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*>
77424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    RoutingIDFrameMap;
780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochbase::LazyInstance<RoutingIDFrameMap> g_routing_id_frame_map =
79424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    LAZY_INSTANCE_INITIALIZER;
80424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
810529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochclass DesktopNotificationDelegateImpl : public DesktopNotificationDelegate {
820529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch public:
830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  DesktopNotificationDelegateImpl(RenderFrameHost* render_frame_host,
840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                                  int notification_id)
850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      : render_process_id_(render_frame_host->GetProcess()->GetID()),
860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        render_frame_id_(render_frame_host->GetRoutingID()),
870529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        notification_id_(notification_id) {}
880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  virtual ~DesktopNotificationDelegateImpl() {}
900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  virtual void NotificationDisplayed() OVERRIDE {
920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    RenderFrameHost* rfh =
930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        RenderFrameHost::FromID(render_process_id_, render_frame_id_);
940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    if (!rfh)
950529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      return;
960529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    rfh->Send(new DesktopNotificationMsg_PostDisplay(
980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        rfh->GetRoutingID(), notification_id_));
990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  }
1000529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1010529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  virtual void NotificationError() OVERRIDE {
1020529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    RenderFrameHost* rfh =
1030529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        RenderFrameHost::FromID(render_process_id_, render_frame_id_);
1040529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    if (!rfh)
1050529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      return;
1060529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1070529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    rfh->Send(new DesktopNotificationMsg_PostError(
1080529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        rfh->GetRoutingID(), notification_id_));
1090529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  }
1100529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1110529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  virtual void NotificationClosed(bool by_user) OVERRIDE {
1120529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    RenderFrameHost* rfh =
1130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        RenderFrameHost::FromID(render_process_id_, render_frame_id_);
1140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    if (!rfh)
1150529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      return;
1160529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1170529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    rfh->Send(new DesktopNotificationMsg_PostClose(
1180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        rfh->GetRoutingID(), notification_id_, by_user));
1190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    static_cast<RenderFrameHostImpl*>(rfh)->NotificationClosed(
1200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        notification_id_);
1210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  }
1220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  virtual void NotificationClick() OVERRIDE {
1240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    RenderFrameHost* rfh =
1250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        RenderFrameHost::FromID(render_process_id_, render_frame_id_);
1260529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    if (!rfh)
1270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      return;
1280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1290529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    rfh->Send(new DesktopNotificationMsg_PostClick(
1300529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        rfh->GetRoutingID(), notification_id_));
1310529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  }
1320529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1330529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch private:
1340529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  int render_process_id_;
1350529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  int render_frame_id_;
1360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  int notification_id_;
1370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch};
1380529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
139cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Translate a WebKit text direction into a base::i18n one.
140cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)base::i18n::TextDirection WebTextDirectionToChromeTextDirection(
141cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    blink::WebTextDirection dir) {
142cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  switch (dir) {
143cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    case blink::WebTextDirectionLeftToRight:
144cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      return base::i18n::LEFT_TO_RIGHT;
145cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    case blink::WebTextDirectionRightToLeft:
146cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      return base::i18n::RIGHT_TO_LEFT;
147cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    default:
148cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      NOTREACHED();
149cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      return base::i18n::UNKNOWN_DIRECTION;
150cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
151cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
152cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
1530529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}  // namespace
1540529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)RenderFrameHost* RenderFrameHost::FromID(int render_process_id,
1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                         int render_frame_id) {
1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return RenderFrameHostImpl::FromID(render_process_id, render_frame_id);
1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
160424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// static
1615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)RenderFrameHostImpl* RenderFrameHostImpl::FromID(int process_id,
1625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                                 int routing_id) {
1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
164424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  RoutingIDFrameMap* frames = g_routing_id_frame_map.Pointer();
165424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  RoutingIDFrameMap::iterator it = frames->find(
166424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      RenderFrameHostID(process_id, routing_id));
167424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  return it == frames->end() ? NULL : it->second;
168424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)}
169424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
1705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)RenderFrameHostImpl::RenderFrameHostImpl(RenderViewHostImpl* render_view_host,
1715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                         RenderFrameHostDelegate* delegate,
1725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                         FrameTree* frame_tree,
1735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                         FrameTreeNode* frame_tree_node,
1745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                         int routing_id,
1755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                         bool is_swapped_out)
176868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    : render_view_host_(render_view_host),
177a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      delegate_(delegate),
1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      cross_process_frame_connector_(NULL),
179cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      render_frame_proxy_host_(NULL),
1804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      frame_tree_(frame_tree),
181a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      frame_tree_node_(frame_tree_node),
182424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      routing_id_(routing_id),
1830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      is_swapped_out_(is_swapped_out),
1841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      render_frame_created_(false),
1856e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      navigations_suspended_(false),
18629b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch      accessibility_reset_token_(0),
18729b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch      accessibility_reset_count_(0),
18829b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch      disallow_browser_accessibility_manager_for_testing_(false),
1890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      weak_ptr_factory_(this) {
1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  frame_tree_->RegisterRenderFrameHost(this);
191424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  GetProcess()->AddRoute(routing_id_, this);
192424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  g_routing_id_frame_map.Get().insert(std::make_pair(
193424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      RenderFrameHostID(GetProcess()->GetID(), routing_id_),
194424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      this));
195116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
196116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (GetProcess()->GetServiceRegistry()) {
197116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    RenderFrameSetupPtr setup;
198116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    GetProcess()->GetServiceRegistry()->ConnectToRemoteService(&setup);
199116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    mojo::ServiceProviderPtr service_provider;
200116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    setup->GetServiceProviderForFrame(routing_id_,
201116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                      mojo::Get(&service_provider));
202116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    service_registry_.BindRemoteServiceProvider(
203116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch        service_provider.PassMessagePipe());
204116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  }
205868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
206868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
207868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)RenderFrameHostImpl::~RenderFrameHostImpl() {
208424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  GetProcess()->RemoveRoute(routing_id_);
209424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  g_routing_id_frame_map.Get().erase(
210424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      RenderFrameHostID(GetProcess()->GetID(), routing_id_));
2116e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
212a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (delegate_)
213a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    delegate_->RenderFrameDeleted(this);
2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  FrameAccessibility::GetInstance()->OnRenderFrameHostDestroyed(this);
2161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Notify the FrameTree that this RFH is going away, allowing it to shut down
2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // the corresponding RenderViewHost if it is no longer needed.
2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  frame_tree_->UnregisterRenderFrameHost(this);
2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
222a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)int RenderFrameHostImpl::GetRoutingID() {
223a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return routing_id_;
224a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
225a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SiteInstance* RenderFrameHostImpl::GetSiteInstance() {
2275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return render_view_host_->GetSiteInstance();
2285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)RenderProcessHost* RenderFrameHostImpl::GetProcess() {
2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(nasko): This should return its own process, once we have working
2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // cross-process navigation for subframes.
2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return render_view_host_->GetProcess();
234a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
235424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
236a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)RenderFrameHost* RenderFrameHostImpl::GetParent() {
237a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  FrameTreeNode* parent_node = frame_tree_node_->parent();
238a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!parent_node)
239a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return NULL;
240a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return parent_node->current_frame_host();
241a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
242a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
24323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)const std::string& RenderFrameHostImpl::GetFrameName() {
24423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  return frame_tree_node_->frame_name();
24523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)}
24623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
247a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool RenderFrameHostImpl::IsCrossProcessSubframe() {
248a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  FrameTreeNode* parent_node = frame_tree_node_->parent();
249a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!parent_node)
250a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return false;
251a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return GetSiteInstance() !=
252a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      parent_node->current_frame_host()->GetSiteInstance();
253a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
254a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
255a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)GURL RenderFrameHostImpl::GetLastCommittedURL() {
256a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return frame_tree_node_->current_url();
257868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
258868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::NativeView RenderFrameHostImpl::GetNativeView() {
2605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RenderWidgetHostView* view = render_view_host_->GetView();
2615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!view)
2625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return NULL;
2635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return view->GetNativeView();
2645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
266a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::ExecuteJavaScript(
267a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    const base::string16& javascript) {
268a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_,
269a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                             javascript,
270a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                             0, false));
271a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
272a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
273a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::ExecuteJavaScript(
274a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)     const base::string16& javascript,
275a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)     const JavaScriptResultCallback& callback) {
276a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static int next_id = 1;
277a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  int key = next_id++;
278a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_,
279a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                             javascript,
280a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                             key, true));
281a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  javascript_callbacks_.insert(std::make_pair(key, callback));
282a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
283a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
2841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccivoid RenderFrameHostImpl::ExecuteJavaScriptForTests(
2851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    const base::string16& javascript) {
2861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  Send(new FrameMsg_JavaScriptExecuteRequestForTests(routing_id_,
2871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                                     javascript,
2881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                                     0, false));
2891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
2901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)RenderViewHost* RenderFrameHostImpl::GetRenderViewHost() {
2925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return render_view_host_;
2935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
295116680a4aac90f2aa7413d9095a592090648e557Ben MurdochServiceRegistry* RenderFrameHostImpl::GetServiceRegistry() {
296116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  static_cast<RenderProcessHostImpl*>(GetProcess())->EnsureMojoActivated();
297116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  return &service_registry_;
298116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
299116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
300868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)bool RenderFrameHostImpl::Send(IPC::Message* message) {
301effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  if (IPC_MESSAGE_ID_CLASS(message->type()) == InputMsgStart) {
302effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    return render_view_host_->input_router()->SendInput(
303effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch        make_scoped_ptr(message));
304effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  }
305effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
3065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Route IPCs through the RenderFrameProxyHost when in swapped out state.
3075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Note: For subframes in --site-per-process mode, we don't use swapped out
3085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // RenderFrameHosts.
3095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (frame_tree_node_->IsMainFrame() && render_view_host_->IsSwappedOut()) {
310cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    DCHECK(render_frame_proxy_host_);
311cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    return render_frame_proxy_host_->Send(message);
312cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  }
313cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
314424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  return GetProcess()->Send(message);
315868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
316868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
317868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) {
31823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // Filter out most IPC messages if this renderer is swapped out.
31923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // We still want to handle certain ACKs to keep our state consistent.
32023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // TODO(nasko): Only check RenderViewHost state, as this object's own state
32123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // isn't yet properly updated. Transition this check once the swapped out
32223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  // state is correct in RenderFrameHost itself.
32323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  if (render_view_host_->IsSwappedOut()) {
32423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)    if (!SwappedOutMessages::CanHandleWhileSwappedOut(msg)) {
32523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)      // If this is a synchronous message and we decided not to handle it,
32623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)      // we must send an error reply, or else the renderer will be stuck
32723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)      // and won't respond to future requests.
32823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)      if (msg.is_sync()) {
32923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)        IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg);
33023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)        reply->set_reply_error();
33123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)        Send(reply);
33223730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)      }
33323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)      // Don't continue looking for someone to handle it.
33423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)      return true;
33523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)    }
33623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  }
33723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
338a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (delegate_->OnMessageReceived(this, msg))
339a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return true;
340a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
3416d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  RenderFrameProxyHost* proxy =
3426d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      frame_tree_node_->render_manager()->GetProxyToParent();
3436d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)  if (proxy && proxy->cross_process_frame_connector() &&
3446d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)      proxy->cross_process_frame_connector()->OnMessageReceived(msg))
3455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return true;
3465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool handled = true;
348cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  IPC_BEGIN_MESSAGE_MAP(RenderFrameHostImpl, msg)
349c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    IPC_MESSAGE_HANDLER(FrameHostMsg_AddMessageToConsole, OnAddMessageToConsole)
3504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_Detach, OnDetach)
351a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_FrameFocused, OnFrameFocused)
3528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartProvisionalLoadForFrame,
3538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                        OnDidStartProvisionalLoadForFrame)
3545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailProvisionalLoadWithError,
3555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                        OnDidFailProvisionalLoadWithError)
3565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailLoadWithError,
3575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                        OnDidFailLoadWithError)
3585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad,
3591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                OnDidCommitProvisionalLoad(msg))
360a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_OpenURL, OnOpenURL)
361010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_DocumentOnLoadCompleted,
362010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                        OnDocumentOnLoadCompleted)
363a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnload_ACK, OnBeforeUnloadACK)
3645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_SwapOut_ACK, OnSwapOutACK)
3655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_ContextMenu, OnContextMenu)
366a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_JavaScriptExecuteResponse,
367a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                        OnJavaScriptExecuteResponse)
368c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_RunJavaScriptMessage,
369c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                                    OnRunJavaScriptMessage)
370c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_RunBeforeUnloadConfirm,
371c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                                    OnRunBeforeUnloadConfirm)
3725c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    IPC_MESSAGE_HANDLER(FrameHostMsg_DidAccessInitialDocument,
3735c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                        OnDidAccessInitialDocument)
374010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisownOpener, OnDidDisownOpener)
3751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    IPC_MESSAGE_HANDLER(FrameHostMsg_DidAssignPageId, OnDidAssignPageId)
376cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle)
377cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding)
378116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation,
379116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                        OnBeginNavigation)
3805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    IPC_MESSAGE_HANDLER(PlatformNotificationHostMsg_RequestPermission,
3815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                        OnRequestPlatformNotificationPermission)
3820529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Show,
3830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                        OnShowDesktopNotification)
3840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Cancel,
3850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch                        OnCancelDesktopNotification)
386f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse,
387f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                        OnTextSurroundingSelectionResponse)
388116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents)
389116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges,
390116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                        OnAccessibilityLocationChanges)
3911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#if defined(OS_MACOSX) || defined(OS_ANDROID)
3921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    IPC_MESSAGE_HANDLER(FrameHostMsg_ShowPopup, OnShowPopup)
3931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    IPC_MESSAGE_HANDLER(FrameHostMsg_HidePopup, OnHidePopup)
3941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif
395cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  IPC_END_MESSAGE_MAP()
396a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
3974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return handled;
398424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)}
399424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
400116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid RenderFrameHostImpl::AccessibilitySetFocus(int object_id) {
401116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  Send(new AccessibilityMsg_SetFocus(routing_id_, object_id));
402116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
403116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
404116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid RenderFrameHostImpl::AccessibilityDoDefaultAction(int object_id) {
405116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  Send(new AccessibilityMsg_DoDefaultAction(routing_id_, object_id));
406116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
407116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
408116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid RenderFrameHostImpl::AccessibilityShowMenu(
409116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    const gfx::Point& global_point) {
410116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
411116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      render_view_host_->GetView());
412116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (view)
413116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    view->AccessibilityShowMenu(global_point);
414116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
415116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
416116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid RenderFrameHostImpl::AccessibilityScrollToMakeVisible(
417116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    int acc_obj_id, const gfx::Rect& subfocus) {
418116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  Send(new AccessibilityMsg_ScrollToMakeVisible(
419116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      routing_id_, acc_obj_id, subfocus));
420116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
421116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
422116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid RenderFrameHostImpl::AccessibilityScrollToPoint(
423116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    int acc_obj_id, const gfx::Point& point) {
424116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  Send(new AccessibilityMsg_ScrollToPoint(
425116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      routing_id_, acc_obj_id, point));
426116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
427116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
428116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid RenderFrameHostImpl::AccessibilitySetTextSelection(
429116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    int object_id, int start_offset, int end_offset) {
430116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  Send(new AccessibilityMsg_SetTextSelection(
431116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      routing_id_, object_id, start_offset, end_offset));
432116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
433116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
434116680a4aac90f2aa7413d9095a592090648e557Ben Murdochbool RenderFrameHostImpl::AccessibilityViewHasFocus() const {
435116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  RenderWidgetHostView* view = render_view_host_->GetView();
436116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (view)
437116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return view->HasFocus();
438116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  return false;
439116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
440116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
441116680a4aac90f2aa7413d9095a592090648e557Ben Murdochgfx::Rect RenderFrameHostImpl::AccessibilityGetViewBounds() const {
442116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  RenderWidgetHostView* view = render_view_host_->GetView();
443116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (view)
444116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return view->GetViewBounds();
445116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  return gfx::Rect();
446116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
447116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
448116680a4aac90f2aa7413d9095a592090648e557Ben Murdochgfx::Point RenderFrameHostImpl::AccessibilityOriginInScreen(
449116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    const gfx::Rect& bounds) const {
450116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
451116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      render_view_host_->GetView());
452116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (view)
453116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    return view->AccessibilityOriginInScreen(bounds);
454116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  return gfx::Point();
455116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
456116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
457116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid RenderFrameHostImpl::AccessibilityHitTest(const gfx::Point& point) {
458116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  Send(new AccessibilityMsg_HitTest(routing_id_, point));
459116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
460116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
461116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid RenderFrameHostImpl::AccessibilityFatalError() {
462116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  browser_accessibility_manager_.reset(NULL);
46329b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch  if (accessibility_reset_token_)
46429b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch    return;
46529b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch
46629b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch  accessibility_reset_count_++;
46729b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch  if (accessibility_reset_count_ >= kMaxAccessibilityResets) {
46829b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch    Send(new AccessibilityMsg_FatalError(routing_id_));
46929b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch  } else {
47029b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch    accessibility_reset_token_ = g_next_accessibility_reset_token++;
47129b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch    UMA_HISTOGRAM_COUNTS("Accessibility.FrameResetCount", 1);
47229b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch    Send(new AccessibilityMsg_Reset(routing_id_, accessibility_reset_token_));
47329b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch  }
474116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
475116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
4765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)gfx::AcceleratedWidget
4775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    RenderFrameHostImpl::AccessibilityGetAcceleratedWidget() {
4785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
4795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      render_view_host_->GetView());
4805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (view)
4815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    return view->AccessibilityGetAcceleratedWidget();
4825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  return gfx::kNullAcceleratedWidget;
4835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
4845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
4855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)gfx::NativeViewAccessible
4865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    RenderFrameHostImpl::AccessibilityGetNativeViewAccessible() {
4875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
4885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      render_view_host_->GetView());
4895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (view)
4905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    return view->AccessibilityGetNativeViewAccessible();
4915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  return NULL;
4925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
4935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
4941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciBrowserAccessibilityManager* RenderFrameHostImpl::AccessibilityGetChildFrame(
4951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    int accessibility_node_id) {
4961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  RenderFrameHostImpl* child_frame =
4971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      FrameAccessibility::GetInstance()->GetChild(this, accessibility_node_id);
4981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!child_frame)
4991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    return NULL;
5001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Return NULL if this isn't an out-of-process iframe. Same-process iframes
5021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // are already part of the accessibility tree.
5031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (child_frame->GetProcess()->GetID() == GetProcess()->GetID())
5041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    return NULL;
5051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // As a sanity check, make sure the frame we're going to return belongs
5071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // to the same BrowserContext.
5081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (GetSiteInstance()->GetBrowserContext() !=
5091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      child_frame->GetSiteInstance()->GetBrowserContext()) {
5101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    NOTREACHED();
5111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    return NULL;
5121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
5131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return child_frame->GetOrCreateBrowserAccessibilityManager();
5151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
5161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano TucciBrowserAccessibility* RenderFrameHostImpl::AccessibilityGetParentFrame() {
5181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  RenderFrameHostImpl* parent_frame = NULL;
5191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  int parent_node_id = 0;
5201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!FrameAccessibility::GetInstance()->GetParent(
5211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      this, &parent_frame, &parent_node_id)) {
5221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    return NULL;
5231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
5241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // As a sanity check, make sure the frame we're going to return belongs
5261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // to the same BrowserContext.
5271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (GetSiteInstance()->GetBrowserContext() !=
5281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      parent_frame->GetSiteInstance()->GetBrowserContext()) {
5291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    NOTREACHED();
5301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    return NULL;
5311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  }
5321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  BrowserAccessibilityManager* manager =
5341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      parent_frame->browser_accessibility_manager();
5351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!manager)
5361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    return NULL;
5371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return manager->GetFromID(parent_node_id);
5391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
5401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)bool RenderFrameHostImpl::CreateRenderFrame(int parent_routing_id) {
5421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame");
5435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DCHECK(!IsRenderFrameLive()) << "Creating frame twice";
5445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
5455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // The process may (if we're sharing a process with another host that already
5465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // initialized it) or may not (we have our own process or the old process
5475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // crashed) have been initialized. Calling Init multiple times will be
5485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // ignored, so this is safe.
5495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (!GetProcess()->Init())
5505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    return false;
5515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
5525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  DCHECK(GetProcess()->HasConnection());
5535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
5545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  Send(new FrameMsg_NewFrame(routing_id_, parent_routing_id));
5555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
5561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // The renderer now has a RenderFrame for this RenderFrameHost.  Note that
5571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // this path is only used for out-of-process iframes.  Main frame RenderFrames
5581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // are created with their RenderView, and same-site iframes are created at the
5591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // time of OnCreateChildFrame.
5601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  set_render_frame_created(true);
5611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  return true;
5635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
5645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
5655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)bool RenderFrameHostImpl::IsRenderFrameLive() {
5661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // RenderFrames are created for main frames at the same time as RenderViews,
5671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // so we rely on IsRenderViewLive.  For subframes, we keep track of each
5681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // RenderFrame individually with render_frame_created_.
5691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  bool is_live = !GetParent() ?
5701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      render_view_host_->IsRenderViewLive() :
5711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      GetProcess()->HasConnection() && render_frame_created_;
5721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Sanity check: the RenderView should always be live if the RenderFrame is.
5741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  DCHECK(!is_live || render_view_host_->IsRenderViewLive());
5751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
5761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return is_live;
5775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
5785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
579424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)void RenderFrameHostImpl::Init() {
5805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetProcess()->ResumeRequestsForView(routing_id_);
581868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
582868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
583c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochvoid RenderFrameHostImpl::OnAddMessageToConsole(
584c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    int32 level,
585c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    const base::string16& message,
586c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    int32 line_no,
587c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    const base::string16& source_id) {
588c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  if (delegate_->AddMessageToConsole(level, message, line_no, source_id))
589c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    return;
590c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
591c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // Pass through log level only on WebUI pages to limit console spew.
592c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  int32 resolved_level =
593c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch      HasWebUIScheme(delegate_->GetMainFrameLastCommittedURL()) ? level : 0;
594c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
595c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  if (resolved_level >= ::logging::GetMinLogLevel()) {
596c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    logging::LogMessage("CONSOLE", line_no, resolved_level).stream() << "\"" <<
597c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch        message << "\", source: " << source_id << " (" << line_no << ")";
598c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  }
599c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch}
600c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
601a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::OnCreateChildFrame(int new_routing_id,
6024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                                             const std::string& frame_name) {
603a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  RenderFrameHostImpl* new_frame = frame_tree_->AddFrame(
6041675a649fd7a8b3cb80ffddae2dc181f122353c5Ben Murdoch      frame_tree_node_, GetProcess()->GetID(), new_routing_id, frame_name);
6051675a649fd7a8b3cb80ffddae2dc181f122353c5Ben Murdoch  if (!new_frame)
6061675a649fd7a8b3cb80ffddae2dc181f122353c5Ben Murdoch    return;
6071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
6081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // We know that the RenderFrame has been created in this case, immediately
6091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // after the CreateChildFrame IPC was sent.
6101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  new_frame->set_render_frame_created(true);
6111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
612a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (delegate_)
613a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    delegate_->RenderFrameCreated(new_frame);
6144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
6154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
616a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::OnDetach() {
617a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  frame_tree_->RemoveFrame(frame_tree_node_);
618a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
619a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
620a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::OnFrameFocused() {
621a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  frame_tree_->SetFocusedFrame(frame_tree_node_);
622a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
623a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
624a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::OnOpenURL(
625a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    const FrameHostMsg_OpenURL_Params& params) {
626a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GURL validated_url(params.url);
627a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetProcess()->FilterURL(false, &validated_url);
628a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
6291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  TRACE_EVENT1("navigation", "RenderFrameHostImpl::OnOpenURL",
6301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci               "url", validated_url.possibly_invalid_spec());
631a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  frame_tree_node_->navigator()->RequestOpenURL(
632a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      this, validated_url, params.referrer, params.disposition,
633a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      params.should_replace_current_entry, params.user_gesture);
6344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
6354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
636010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void RenderFrameHostImpl::OnDocumentOnLoadCompleted() {
637010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // This message is only sent for top-level frames. TODO(avi): when frame tree
638010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // mirroring works correctly, add a check here to enforce it.
639010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  delegate_->DocumentOnLoadCompleted(this);
640010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
641010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
6428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)void RenderFrameHostImpl::OnDidStartProvisionalLoadForFrame(
6435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    const GURL& url,
6445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    bool is_transition_navigation) {
6455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  frame_tree_node_->navigator()->DidStartProvisionalLoad(
6465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      this, url, is_transition_navigation);
6478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)}
6488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
6495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::OnDidFailProvisionalLoadWithError(
6505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
6515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  frame_tree_node_->navigator()->DidFailProvisionalLoadWithError(this, params);
6525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::OnDidFailLoadWithError(
6555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const GURL& url,
6565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    int error_code,
6575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const base::string16& error_description) {
6585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GURL validated_url(url);
6595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetProcess()->FilterURL(false, &validated_url);
6605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  frame_tree_node_->navigator()->DidFailLoadWithError(
662effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      this, validated_url, error_code, error_description);
6635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Called when the renderer navigates.  For every frame loaded, we'll get this
6665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// notification containing parameters identifying the navigation.
6675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//
6685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Subframes are identified by the page transition type.  For subframes loaded
6695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// as part of a wider page load, the page_id will be the same as for the top
6705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// level frame.  If the user explicitly requests a subframe navigation, we will
6715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// get a new page_id because we need to create a new navigation entry for that
6725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// action.
6731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccivoid RenderFrameHostImpl::OnDidCommitProvisionalLoad(const IPC::Message& msg) {
6745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Read the parameters out of the IPC message directly to avoid making another
6755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // copy when we filter the URLs.
6765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  PickleIterator iter(msg);
6775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  FrameHostMsg_DidCommitProvisionalLoad_Params validated_params;
6785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!IPC::ParamTraits<FrameHostMsg_DidCommitProvisionalLoad_Params>::
6795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      Read(&msg, &iter, &validated_params))
6805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
6811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  TRACE_EVENT1("navigation", "RenderFrameHostImpl::OnDidCommitProvisionalLoad",
6821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci               "url", validated_params.url.possibly_invalid_spec());
6835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // If we're waiting for a cross-site beforeunload ack from this renderer and
6855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // we receive a Navigate message from the main frame, then the renderer was
68603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // navigating already and sent it before hearing the FrameMsg_Stop message.
6875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We do not want to cancel the pending navigation in this case, since the
6885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // old page will soon be stopped.  Instead, treat this as a beforeunload ack
6895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to allow the pending navigation to continue.
6905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (render_view_host_->is_waiting_for_beforeunload_ack_ &&
6915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      render_view_host_->unload_ack_is_for_cross_site_transition_ &&
6921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      ui::PageTransitionIsMainFrame(validated_params.transition)) {
693a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    OnBeforeUnloadACK(true, send_before_unload_start_time_,
694a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                      base::TimeTicks::Now());
6955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
6965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
6975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // If we're waiting for an unload ack from this renderer and we receive a
6995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Navigate message, then the renderer was navigating before it received the
7005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // unload request.  It will either respond to the unload request soon or our
7015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // timer will expire.  Either way, we should ignore this message, because we
7025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // have already committed to closing this renderer.
7035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (render_view_host_->IsWaitingForUnloadACK())
7045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
7055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RenderProcessHost* process = GetProcess();
7075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Attempts to commit certain off-limits URL should be caught more strictly
7095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // than our FilterURL checks below.  If a renderer violates this policy, it
7105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // should be killed.
7115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!CanCommitURL(validated_params.url)) {
7125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    VLOG(1) << "Blocked URL " << validated_params.url.spec();
713f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    validated_params.url = GURL(url::kAboutBlankURL);
7145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    RecordAction(base::UserMetricsAction("CanCommitURL_BlockedAndKilled"));
7155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Kills the process.
7165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    process->ReceivedBadMessage();
7175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
7185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Without this check, an evil renderer can trick the browser into creating
7205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // a navigation entry for a banned URL.  If the user clicks the back button
7215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // followed by the forward button (or clicks reload, or round-trips through
7225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // session restore, etc), we'll think that the browser commanded the
7235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // renderer to load the URL and grant the renderer the privileges to request
7245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // the URL.  To prevent this attack, we block the renderer from inserting
7255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // banned URLs into the navigation controller in the first place.
7265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  process->FilterURL(false, &validated_params.url);
7275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  process->FilterURL(true, &validated_params.referrer.url);
7285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  for (std::vector<GURL>::iterator it(validated_params.redirects.begin());
7295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      it != validated_params.redirects.end(); ++it) {
7305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    process->FilterURL(false, &(*it));
7315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
7325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  process->FilterURL(true, &validated_params.searchable_form_url);
7335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Without this check, the renderer can trick the browser into using
7355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // filenames it can't access in a future session restore.
7365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!render_view_host_->CanAccessFilesOfPageState(
7375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          validated_params.page_state)) {
7385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    GetProcess()->ReceivedBadMessage();
7395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
7405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
7415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
74229b820f8d84e3bc97d62552e54923c42407f2f29Ben Murdoch  accessibility_reset_count_ = 0;
7435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  frame_tree_node()->navigator()->DidNavigate(this, validated_params);
7445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
746cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)RenderWidgetHostImpl* RenderFrameHostImpl::GetRenderWidgetHost() {
747cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  return static_cast<RenderWidgetHostImpl*>(render_view_host_);
748cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}
749cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
750a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)int RenderFrameHostImpl::GetEnabledBindings() {
751a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return render_view_host_->GetEnabledBindings();
752a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
753a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
754a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::OnCrossSiteResponse(
755a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    const GlobalRequestID& global_request_id,
756a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request,
757a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    const std::vector<GURL>& transfer_url_chain,
758a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    const Referrer& referrer,
7591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    ui::PageTransition page_transition,
760a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    bool should_replace_current_entry) {
761a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  frame_tree_node_->render_manager()->OnCrossSiteResponse(
762a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      this, global_request_id, cross_site_transferring_request.Pass(),
763a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      transfer_url_chain, referrer, page_transition,
764a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      should_replace_current_entry);
765a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
766a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
767116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid RenderFrameHostImpl::OnDeferredAfterResponseStarted(
7685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    const GlobalRequestID& global_request_id,
7696e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    const TransitionLayerData& transition_data) {
770116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  frame_tree_node_->render_manager()->OnDeferredAfterResponseStarted(
771116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      global_request_id, this);
772116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
773116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  if (GetParent() || !delegate_->WillHandleDeferAfterResponseStarted())
774116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    frame_tree_node_->render_manager()->ResumeResponseDeferredAtStart();
775116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  else
7766e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    delegate_->DidDeferAfterResponseStarted(transition_data);
777116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
778116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
779cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)void RenderFrameHostImpl::SwapOut(RenderFrameProxyHost* proxy) {
7801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // The end of this event is in OnSwapOutACK when the RenderFrame has completed
7811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // the operation and sends back an IPC message.
7821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // The trace event may not end properly if the ACK times out.  We expect this
7831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // to be fixed when RenderViewHostImpl::OnSwapOut moves to RenderFrameHost.
7841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  TRACE_EVENT_ASYNC_BEGIN0("navigation", "RenderFrameHostImpl::SwapOut", this);
7851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
786effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // TODO(creis): Move swapped out state to RFH.  Until then, only update it
787effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // when swapping out the main frame.
788effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  if (!GetParent()) {
789effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    // If this RenderViewHost is not in the default state, it must have already
790effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    // gone through this, therefore just return.
791effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    if (render_view_host_->rvh_state_ != RenderViewHostImpl::STATE_DEFAULT)
792effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      return;
793effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
794effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    render_view_host_->SetState(
79503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        RenderViewHostImpl::STATE_PENDING_SWAP_OUT);
796effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    render_view_host_->unload_event_monitor_timeout_->Start(
797effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch        base::TimeDelta::FromMilliseconds(
798effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch            RenderViewHostImpl::kUnloadTimeoutMS));
7995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
800effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
801cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  set_render_frame_proxy_host(proxy);
802cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
8031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (IsRenderFrameLive())
804cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    Send(new FrameMsg_SwapOut(routing_id_, proxy->GetRoutingID()));
805effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
806effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  if (!GetParent())
807effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    delegate_->SwappedOut(this);
80803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  else
80903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    set_swapped_out(true);
8105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
812a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::OnBeforeUnloadACK(
813a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    bool proceed,
814a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    const base::TimeTicks& renderer_before_unload_start_time,
815a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    const base::TimeTicks& renderer_before_unload_end_time) {
8161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  TRACE_EVENT_ASYNC_END0(
8171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      "navigation", "RenderFrameHostImpl::BeforeUnload", this);
8180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // TODO(creis): Support properly beforeunload on subframes. For now just
8190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // pretend that the handler ran and allowed the navigation to proceed.
820a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (GetParent()) {
8210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    render_view_host_->is_waiting_for_beforeunload_ack_ = false;
8220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    frame_tree_node_->render_manager()->OnBeforeUnloadACK(
8230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        render_view_host_->unload_ack_is_for_cross_site_transition_, proceed,
8240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch        renderer_before_unload_end_time);
825a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
826a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
827a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
828a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  render_view_host_->decrement_in_flight_event_count();
829a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  render_view_host_->StopHangMonitorTimeout();
830a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // If this renderer navigated while the beforeunload request was in flight, we
8311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // may have cleared this state in OnDidCommitProvisionalLoad, in which case we
8321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // can ignore this message.
833c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // However renderer might also be swapped out but we still want to proceed
834c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // with navigation, otherwise it would block future navigations. This can
835c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // happen when pending cross-site navigation is canceled by a second one just
8361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // before OnDidCommitProvisionalLoad while current RVH is waiting for commit
8371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // but second navigation is started from the beginning.
838c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  if (!render_view_host_->is_waiting_for_beforeunload_ack_) {
839a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
840a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
841a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
842a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  render_view_host_->is_waiting_for_beforeunload_ack_ = false;
843a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
844a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  base::TimeTicks before_unload_end_time;
845a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!send_before_unload_start_time_.is_null() &&
846a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      !renderer_before_unload_start_time.is_null() &&
847a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      !renderer_before_unload_end_time.is_null()) {
848a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // When passing TimeTicks across process boundaries, we need to compensate
849a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // for any skew between the processes. Here we are converting the
850a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // renderer's notion of before_unload_end_time to TimeTicks in the browser
851a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // process. See comments in inter_process_time_ticks_converter.h for more.
852a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    InterProcessTimeTicksConverter converter(
853a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        LocalTimeTicks::FromTimeTicks(send_before_unload_start_time_),
854a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        LocalTimeTicks::FromTimeTicks(base::TimeTicks::Now()),
855a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        RemoteTimeTicks::FromTimeTicks(renderer_before_unload_start_time),
856a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        RemoteTimeTicks::FromTimeTicks(renderer_before_unload_end_time));
857a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    LocalTimeTicks browser_before_unload_end_time =
858a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        converter.ToLocalTimeTicks(
859a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)            RemoteTimeTicks::FromTimeTicks(renderer_before_unload_end_time));
860a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    before_unload_end_time = browser_before_unload_end_time.ToTimeTicks();
86103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
86203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    // Collect UMA on the inter-process skew.
86303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    bool is_skew_additive = false;
86403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    if (converter.IsSkewAdditiveForMetrics()) {
86503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      is_skew_additive = true;
86603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      base::TimeDelta skew = converter.GetSkewForMetrics();
86703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      if (skew >= base::TimeDelta()) {
86803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        UMA_HISTOGRAM_TIMES(
86903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)            "InterProcessTimeTicks.BrowserBehind_RendererToBrowser", skew);
87003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      } else {
87103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        UMA_HISTOGRAM_TIMES(
87203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)            "InterProcessTimeTicks.BrowserAhead_RendererToBrowser", -skew);
87303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      }
87403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    }
87503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    UMA_HISTOGRAM_BOOLEAN(
87603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        "InterProcessTimeTicks.IsSkewAdditive_RendererToBrowser",
87703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        is_skew_additive);
878a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
879a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  frame_tree_node_->render_manager()->OnBeforeUnloadACK(
880a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      render_view_host_->unload_ack_is_for_cross_site_transition_, proceed,
881a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      before_unload_end_time);
882a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
883a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // If canceled, notify the delegate to cancel its pending navigation entry.
884a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!proceed)
885a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    render_view_host_->GetDelegate()->DidCancelLoading();
886a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
887a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
8885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::OnSwapOutACK() {
8895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  OnSwappedOut(false);
8901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  TRACE_EVENT_ASYNC_END0("navigation", "RenderFrameHostImpl::SwapOut", this);
8915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::OnSwappedOut(bool timed_out) {
894effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // For now, we only need to update the RVH state machine for top-level swaps.
895effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  if (!GetParent())
896effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    render_view_host_->OnSwappedOut(timed_out);
8975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams& params) {
9005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Validate the URLs in |params|.  If the renderer can't request the URLs
9015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // directly, don't show them in the context menu.
9025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ContextMenuParams validated_params(params);
9035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RenderProcessHost* process = GetProcess();
9045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
9055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We don't validate |unfiltered_link_url| so that this field can be used
9065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // when users want to copy the original link URL.
9075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  process->FilterURL(true, &validated_params.link_url);
9085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  process->FilterURL(true, &validated_params.src_url);
9095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  process->FilterURL(false, &validated_params.page_url);
9105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  process->FilterURL(true, &validated_params.frame_url);
9115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
9125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  delegate_->ShowContextMenu(this, validated_params);
9135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
9145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
915a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void RenderFrameHostImpl::OnJavaScriptExecuteResponse(
916a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    int id, const base::ListValue& result) {
917a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  const base::Value* result_value;
918a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!result.Get(0, &result_value)) {
919a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // Programming error or rogue renderer.
920a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    NOTREACHED() << "Got bad arguments for OnJavaScriptExecuteResponse";
921a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
922a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
923a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
924a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  std::map<int, JavaScriptResultCallback>::iterator it =
925a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      javascript_callbacks_.find(id);
926a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (it != javascript_callbacks_.end()) {
927a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    it->second.Run(result_value);
928a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    javascript_callbacks_.erase(it);
929a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  } else {
930a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    NOTREACHED() << "Received script response for unknown request";
931a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
932a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
933a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
934c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochvoid RenderFrameHostImpl::OnRunJavaScriptMessage(
935c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    const base::string16& message,
936c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    const base::string16& default_prompt,
937c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    const GURL& frame_url,
938c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    JavaScriptMessageType type,
939c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    IPC::Message* reply_msg) {
940c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // While a JS message dialog is showing, tabs in the same process shouldn't
941c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // process input events.
942c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  GetProcess()->SetIgnoreInputEvents(true);
943c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  render_view_host_->StopHangMonitorTimeout();
944c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  delegate_->RunJavaScriptMessage(this, message, default_prompt,
945c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                                  frame_url, type, reply_msg);
946c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch}
947c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
948c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochvoid RenderFrameHostImpl::OnRunBeforeUnloadConfirm(
949c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    const GURL& frame_url,
950c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    const base::string16& message,
951c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    bool is_reload,
952c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    IPC::Message* reply_msg) {
953c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // While a JS before unload dialog is showing, tabs in the same process
954c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // shouldn't process input events.
955c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  GetProcess()->SetIgnoreInputEvents(true);
956c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  render_view_host_->StopHangMonitorTimeout();
957c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  delegate_->RunBeforeUnloadConfirm(this, message, is_reload, reply_msg);
958c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch}
959c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
9605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void RenderFrameHostImpl::OnRequestPlatformNotificationPermission(
9615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    const GURL& origin, int request_id) {
9625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  base::Callback<void(blink::WebNotificationPermission)> done_callback =
9635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      base::Bind(
9645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)          &RenderFrameHostImpl::PlatformNotificationPermissionRequestDone,
9655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)          weak_ptr_factory_.GetWeakPtr(),
9665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)          request_id);
9675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
9680529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  GetContentClient()->browser()->RequestDesktopNotificationPermission(
9695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      origin, this, done_callback);
9700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
9710529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
9720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochvoid RenderFrameHostImpl::OnShowDesktopNotification(
9730529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    int notification_id,
9740529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    const ShowDesktopNotificationHostMsgParams& params) {
9755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  scoped_ptr<DesktopNotificationDelegateImpl> delegate(
9765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      new DesktopNotificationDelegateImpl(this, notification_id));
9775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
9780529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  base::Closure cancel_callback;
9790529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  GetContentClient()->browser()->ShowDesktopNotification(
9805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      params,
9815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      this,
9825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      delegate.PassAs<DesktopNotificationDelegate>(),
9830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      &cancel_callback);
9840529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  cancel_notification_callbacks_[notification_id] = cancel_callback;
9850529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
9860529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
9870529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochvoid RenderFrameHostImpl::OnCancelDesktopNotification(int notification_id) {
9880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  if (!cancel_notification_callbacks_.count(notification_id)) {
9890529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    NOTREACHED();
9900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    return;
9910529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  }
9920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  cancel_notification_callbacks_[notification_id].Run();
9930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  cancel_notification_callbacks_.erase(notification_id);
9940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch}
9950529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
996f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)void RenderFrameHostImpl::OnTextSurroundingSelectionResponse(
997f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    const base::string16& content,
998f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    size_t start_offset,
999f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    size_t end_offset) {
1000f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  render_view_host_->OnTextSurroundingSelectionResponse(
1001f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      content, start_offset, end_offset);
1002f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)}
1003f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
10045c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuvoid RenderFrameHostImpl::OnDidAccessInitialDocument() {
10055c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  delegate_->DidAccessInitialDocument();
10065c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu}
10075c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1008010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)void RenderFrameHostImpl::OnDidDisownOpener() {
1009010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // This message is only sent for top-level frames. TODO(avi): when frame tree
1010010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // mirroring works correctly, add a check here to enforce it.
1011010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  delegate_->DidDisownOpener(this);
1012010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)}
1013010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
10141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccivoid RenderFrameHostImpl::OnDidAssignPageId(int32 page_id) {
10151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Update the RVH's current page ID so that future IPCs from the renderer
10161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // correspond to the new page.
10171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  render_view_host_->page_id_ = page_id;
10181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
1019