web_contents_observer.h revision 23730a6e56a168d1879203e4b3819bb36e3d8f1f
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 57dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ 67dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/process/kill.h" 97dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/process/process_handle.h" 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/common/content_export.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/navigation_controller.h" 12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "content/public/common/frame_navigate_params.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/page_transition_types.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ipc/ipc_listener.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ipc/ipc_sender.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/window_open_disposition.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NavigationEntry; 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class RenderFrameHost; 22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class RenderViewHost; 23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class WebContents; 24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class WebContentsImpl; 25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)struct AXEventNotificationDetails; 26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)struct FaviconURL; 27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)struct FrameNavigateParams; 28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)struct LoadCommittedDetails; 29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)struct LoadFromMemoryCacheDetails; 30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)struct Referrer; 31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)struct ResourceRedirectDetails; 32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)struct ResourceRequestDetails; 33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// An observer API implemented by classes which are interested in various page 35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// load events from WebContents. They also get a chance to filter IPC messages. 36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// 37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Since a WebContents can be a delegate to almost arbitrarily many 38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// RenderViewHosts, it is important to check in those WebContentsObserver 39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// methods which take a RenderViewHost that the event came from the 40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// RenderViewHost the observer cares about. 41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// 42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Usually, observers should only care about the current RenderViewHost as 43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// returned by GetRenderViewHost(). 44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// 45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// TODO(creis, jochen): Hide the fact that there are several RenderViewHosts 46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// from the WebContentsObserver API. http://crbug.com/173325 47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class CONTENT_EXPORT WebContentsObserver : public IPC::Listener, 48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public IPC::Sender { 49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public: 50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Called when a RenderFrameHost associated with this WebContents is created. 515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) {} 52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 53a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Called whenever a RenderFrameHost associated with this WebContents is 54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // deleted. 55a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) {} 56a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // This is called when a RVH is created for a WebContents, but not if it's an 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // interstitial. 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void RenderViewCreated(RenderViewHost* render_view_host) {} 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Called for every RenderFrameHost that's created for an interstitial. 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void RenderFrameForInterstitialPageCreated( 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderFrameHost* render_frame_host) {} 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This method is invoked when the RenderView of the current RenderViewHost 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is ready, e.g. because we recreated it after a crash. 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void RenderViewReady() {} 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 69a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // This method is invoked when a RenderViewHost of the WebContents is 70a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // deleted. Note that this does not always happen when the WebContents starts 71a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // to use a different RenderViewHost, as the old RenderViewHost might get 72a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // just swapped out. 73a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void RenderViewDeleted(RenderViewHost* render_view_host) {} 74a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 75a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // This method is invoked when the process for the current RenderView crashes. 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The WebContents continues to use the RenderViewHost, e.g. when the user 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // reloads the current page. When the RenderViewHost itself is deleted, the 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // RenderViewDeleted method will be invoked. 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Note that this is equivalent to 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // RenderProcessHostObserver::RenderProcessExited(). 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void RenderProcessGone(base::TerminationStatus status) {} 837dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 847dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // This method is invoked when a WebContents swaps its render view host with 857dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // another one, possibly changing processes. The RenderViewHost that has 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // been replaced is in |old_render_view_host|, which is NULL if the old RVH 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // was shut down. 88a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void RenderViewHostChanged(RenderViewHost* old_host, 89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) RenderViewHost* new_host) {} 90a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 91a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // This method is invoked after the WebContents decided which RenderViewHost 92a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // to use for the next navigation, but before the navigation starts. 93a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void AboutToNavigateRenderView( 94a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) RenderViewHost* render_view_host) {} 95a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This method is invoked after the browser process starts a navigation to a 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // pending NavigationEntry. It is not called for renderer-initiated 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // navigations unless they are sent to the browser process via OpenURL. It may 99a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // be called multiple times for a given navigation, such as a typed URL 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // followed by a cross-process client or server redirect. 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DidStartNavigationToPendingEntry( 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GURL& url, 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NavigationController::ReloadType reload_type) {} 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |render_view_host| is the RenderViewHost for which the provisional load is 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // happening. |frame_id| is a positive, non-zero integer identifying the 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // navigating frame in the given |render_view_host|. |parent_frame_id| is the 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // frame identifier of the frame containing the navigating frame, or -1 if the 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // frame is not contained in another frame. 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Since the URL validation will strip error URLs, or srcdoc URLs, the boolean 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // flags |is_error_page| and |is_iframe_srcdoc| will indicate that the not 1137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // validated URL was either an error page or an iframe srcdoc. 1147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Note that during a cross-process navigation, several provisional loads 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // can be on-going in parallel. 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidStartProvisionalLoadForFrame( 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 frame_id, 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 parent_frame_id, 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool is_main_frame, 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& validated_url, 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_error_page, 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_iframe_srcdoc, 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderViewHost* render_view_host) {} 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method is invoked right after the DidStartProvisionalLoadForFrame if 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the provisional load affects the main frame, or if the provisional load 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // was redirected. The latter use case is DEPRECATED. You should listen to 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // WebContentsObserver::DidGetRedirectForResourceRequest instead. 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ProvisionalChangeToMainFrameUrl( 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& url, 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderFrameHost* render_frame_host) {} 133868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method is invoked when the provisional load was successfully 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // committed. The |render_view_host| is now the current RenderViewHost of the 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // WebContents. 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If the navigation only changed the reference fragment, or was triggered 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // using the history API (e.g. window.history.replaceState), we will receive 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // this signal without a prior DidStartProvisionalLoadForFrame signal. 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidCommitProvisionalLoadForFrame( 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 frame_id, 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::string16& frame_unique_name, 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_main_frame, 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& url, 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PageTransition transition_type, 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderViewHost* render_view_host) {} 148a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This method is invoked when the provisional load failed. 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DidFailProvisionalLoad(int64 frame_id, 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::string16& frame_unique_name, 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool is_main_frame, 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const GURL& validated_url, 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int error_code, 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::string16& error_description, 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderViewHost* render_view_host) {} 1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If the provisional load corresponded to the main frame, this method is 1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // invoked in addition to DidCommitProvisionalLoadForFrame. 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DidNavigateMainFrame( 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const LoadCommittedDetails& details, 1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const FrameNavigateParams& params) {} 1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // And regardless of what frame navigated, this method is invoked after 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // DidCommitProvisionalLoadForFrame was invoked. 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidNavigateAnyFrame( 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const LoadCommittedDetails& details, 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const FrameNavigateParams& params) {} 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method is invoked once the window.document object of the main frame 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // was created. 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DocumentAvailableInMainFrame() {} 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method is invoked once the onload handler of the main frame has 1754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // completed. 1764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void DocumentOnLoadCompletedInMainFrame(int32 page_id) {} 1774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // This method is invoked when the document in the given frame finished 1794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // loading. At this point, scripts marked as defer were executed, and 1804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // content scripts marked "document_end" get injected into the frame. 1814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void DocumentLoadedInFrame(int64 frame_id, 1824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) RenderViewHost* render_view_host) {} 1834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method is invoked when the navigation is done, i.e. the spinner of 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the tab will stop spinning, and the onload event was dispatched. 1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If the WebContents is displaying replacement content, e.g. network error 1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // pages, DidFinishLoad is invoked for frames that were not sending 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // navigational events before. It is safe to ignore these events. 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidFinishLoad(int64 frame_id, 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& validated_url, 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_main_frame, 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderViewHost* render_view_host) {} 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method is like DidFinishLoad, but when the load failed or was 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cancelled, e.g. window.stop() is invoked. 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidFailLoad(int64 frame_id, 1987dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const GURL& validated_url, 1997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch bool is_main_frame, 2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int error_code, 2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::string16& error_description, 2027dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch RenderViewHost* render_view_host) {} 203a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method is invoked when content was loaded from an in-memory cache. 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidLoadResourceFromMemoryCache( 206a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const LoadFromMemoryCacheDetails& details) {} 207a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 208a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // This method is invoked when a response has been received for a resource 209a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // request. 210a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void DidGetResourceResponseStart( 211a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const ResourceRequestDetails& details) {} 212a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 213a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // This method is invoked when a redirect was received while requesting a 214a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // resource. 215a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void DidGetRedirectForResourceRequest( 216a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) RenderViewHost* render_view_host, 217a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const ResourceRedirectDetails& details) {} 218a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 219a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // This method is invoked when a new non-pending navigation entry is created. 220a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // This corresponds to one NavigationController entry being created 221a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // (in the case of new navigations) or renavigated to (for back/forward 222a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // navigations). 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void NavigationEntryCommitted( 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const LoadCommittedDetails& load_details) {} 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method is invoked when a new WebContents was created in response to 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // an action in the observed WebContents, e.g. a link with target=_blank was 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // clicked. The |source_frame_id| indicates in which frame the action took 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // place. 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidOpenRequestedURL(WebContents* new_contents, 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& url, 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Referrer& referrer, 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowOpenDisposition disposition, 2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PageTransition transition, 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 source_frame_id) {} 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void FrameDetached(RenderViewHost* render_view_host, 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 frame_id) {} 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This method is invoked when the renderer has completed its first paint 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // after a non-empty layout. 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidFirstVisuallyNonEmptyPaint(int32 page_id) {} 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // These two methods correspond to the points in time when the spinner of the 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // tab starts and stops spinning. 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidStartLoading(RenderViewHost* render_view_host) {} 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidStopLoading(RenderViewHost* render_view_host) {} 2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // When WebContents::Stop() is called, the WebContents stops loading and then 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // invokes this method. If there are ongoing navigations, their respective 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // failure methods will also be invoked. 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void NavigationStopped() {} 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This indicates that the next navigation was triggered by a user gesture. 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidGetUserGesture() {} 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method is invoked when a RenderViewHost of this WebContents was 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // configured to ignore UI events, and an UI event took place. 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidGetIgnoredUIEvent() {} 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // These methods are invoked every time the WebContents changes visibility. 2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void WasShown() {} 2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void WasHidden() {} 2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This methods is invoked when the title of the WebContents is set. If the 2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // title was explicitly set, |explicit_set| is true, otherwise the title was 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // synthesized and |explicit_set| is false. 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void TitleWasSet(NavigationEntry* entry, bool explicit_set) {} 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void AppCacheAccessed(const GURL& manifest_url, 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool blocked_by_policy) {} 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Notification that a plugin has crashed. 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |plugin_pid| is the process ID identifying the plugin process. Note that 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // this ID is supplied by the renderer, so should not be trusted. Besides, the 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // corresponding process has probably died at this point. The ID may even have 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // been reused by a new process. 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void PluginCrashed(const base::FilePath& plugin_path, 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::ProcessId plugin_pid) {} 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Notification that the given plugin has hung or become unhung. This 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // notification is only for Pepper plugins. 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The plugin_child_id is the unique child process ID from the plugin. Note 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that this ID is supplied by the renderer, so should be validated before 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // it's used for anything in case there's an exploited renderer. 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void PluginHungStatusChanged(int plugin_child_id, 2882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& plugin_path, 2892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool is_hung) {} 2902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Invoked when WebContents::Clone() was used to clone a WebContents. 2922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DidCloneToNewWebContents(WebContents* old_web_contents, 2932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WebContents* new_web_contents) {} 2942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Invoked when the WebContents is being destroyed. Gives subclasses a chance 2962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // to cleanup. At the time this is invoked |web_contents()| returns NULL. 2972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // It is safe to delete 'this' from here. 2982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void WebContentsDestroyed(WebContents* web_contents) {} 2992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Called when the user agent override for a WebContents has been changed. 3012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void UserAgentOverrideSet(const std::string& user_agent) {} 3022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Invoked when new FaviconURL candidates are received from the renderer. 3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DidUpdateFaviconURL(int32 page_id, 3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::vector<FaviconURL>& candidates) {} 3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Invoked when a pepper plugin creates and shows or destroys a fullscreen 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // render widget. 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidShowFullscreenWidget(int routing_id) {} 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidDestroyFullscreenWidget(int routing_id) {} 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invoked when the renderer has toggled the tab into/out of fullscreen mode. 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidToggleFullscreenModeForTab(bool entered_fullscreen) {} 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invoked when visible SSL state (as defined by SSLStatus) changes. 3162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DidChangeVisibleSSLState() {} 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invoked when an interstitial page is attached or detached. 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidAttachInterstitialPage() {} 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidDetachInterstitialPage() {} 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invoked before a form repost warning is shown. 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void BeforeFormRepostWarningShow() {} 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invoked when the beforeunload handler fires. The time is from the renderer. 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) {} 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Invoked when a user cancels a before unload dialog. 3292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void BeforeUnloadDialogCancelled() {} 3302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Invoked when an accessibility event is received from the renderer. 3322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void AccessibilityEventReceived( 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::vector<AXEventNotificationDetails>& details) {} 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // IPC::Listener implementation. 3362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // IPC::Sender implementation. 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool Send(IPC::Message* message) OVERRIDE; 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int routing_id() const; 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Use this constructor when the object is tied to a single WebContents for 3442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // its entire lifetime. 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit WebContentsObserver(WebContents* web_contents); 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Use this constructor when the object wants to observe a WebContents for 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // part of its lifetime. It can then call Observe() to start and stop 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // observing. 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebContentsObserver(); 3512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WebContentsObserver(); 3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Start observing a different WebContents; used with the default constructor. 3552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void Observe(WebContents* web_contents); 3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WebContents* web_contents() const; 3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 3602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) friend class WebContentsImpl; 3612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Invoked from WebContentsImpl. Invokes WebContentsDestroyed and NULL out 3632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |web_contents_|. 3642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void WebContentsImplDestroyed(); 3652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WebContentsImpl* web_contents_; 3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(WebContentsObserver); 3692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 3702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace content 372868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ 3742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)