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) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 858e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch#include "base/process/kill.h" 958e6fbe4ee35d65e14b626c557d37565bf8ad179Ben Murdoch#include "base/process/process_handle.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/content_export.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/navigation_controller.h" 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/common/frame_navigate_params.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ipc/ipc_listener.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ipc/ipc_sender.h" 156d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "third_party/skia/include/core/SkColor.h" 161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ui/base/page_transition_types.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/window_open_disposition.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class NavigationEntry; 22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class RenderFrameHost; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RenderViewHost; 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContents; 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContentsImpl; 26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)struct AXEventNotificationDetails; 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct FaviconURL; 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct FrameNavigateParams; 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct LoadCommittedDetails; 3058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)struct LoadFromMemoryCacheDetails; 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct Referrer; 3258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)struct ResourceRedirectDetails; 3358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)struct ResourceRequestDetails; 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// An observer API implemented by classes which are interested in various page 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// load events from WebContents. They also get a chance to filter IPC messages. 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// 383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Since a WebContents can be a delegate to almost arbitrarily many 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// RenderViewHosts, it is important to check in those WebContentsObserver 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// methods which take a RenderViewHost that the event came from the 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// RenderViewHost the observer cares about. 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Usually, observers should only care about the current RenderViewHost as 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// returned by GetRenderViewHost(). 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// TODO(creis, jochen): Hide the fact that there are several RenderViewHosts 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// from the WebContentsObserver API. http://crbug.com/173325 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CONTENT_EXPORT WebContentsObserver : public IPC::Listener, 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public IPC::Sender { 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 51a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Called when a RenderFrameHost associated with this WebContents is created. 52a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) {} 53a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 54a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Called whenever a RenderFrameHost associated with this WebContents is 55a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // deleted. 56a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) {} 57a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // This is called when a RVH is created for a WebContents, but not if it's an 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // interstitial. 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void RenderViewCreated(RenderViewHost* render_view_host) {} 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Called for every RenderFrameHost that's created for an interstitial. 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void RenderFrameForInterstitialPageCreated( 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RenderFrameHost* render_frame_host) {} 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This method is invoked when the RenderView of the current RenderViewHost 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // is ready, e.g. because we recreated it after a crash. 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void RenderViewReady() {} 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This method is invoked when a RenderViewHost of the WebContents is 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // deleted. Note that this does not always happen when the WebContents starts 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // to use a different RenderViewHost, as the old RenderViewHost might get 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // just swapped out. 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void RenderViewDeleted(RenderViewHost* render_view_host) {} 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 767dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // This method is invoked when the process for the current RenderView crashes. 777dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // The WebContents continues to use the RenderViewHost, e.g. when the user 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // reloads the current page. When the RenderViewHost itself is deleted, the 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // RenderViewDeleted method will be invoked. 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Note that this is equivalent to 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // RenderProcessHostObserver::RenderProcessExited(). 837dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual void RenderProcessGone(base::TerminationStatus status) {} 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 85116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // This method is invoked when a WebContents swaps its visible RenderViewHost 86116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // with another one, possibly changing processes. The RenderViewHost that has 87116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // been replaced is in |old_host|, which is NULL if the old RVH was shut down. 884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void RenderViewHostChanged(RenderViewHost* old_host, 894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) RenderViewHost* new_host) {} 9058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 91116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // This method is invoked whenever one of the current frames of a WebContents 92116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // swaps its RenderFrameHost with another one; for example because that frame 93116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // navigated and the new content is in a different process. The 94116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // RenderFrameHost that has been replaced is in |old_host|, which can be NULL 95116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // if the old RFH was shut down. 96116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // 97116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // This method, in combination with RenderFrameDeleted, is appropriate for 98116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // observers wishing to track the set of active RenderFrameHosts -- i.e., 99116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // those hosts that would be visited by calling WebContents::ForEachFrame. 100116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void RenderFrameHostChanged(RenderFrameHost* old_host, 101116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch RenderFrameHost* new_host) {} 102116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This method is invoked after the WebContents decided which RenderViewHost 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // to use for the next navigation, but before the navigation starts. 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void AboutToNavigateRenderView( 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RenderViewHost* render_view_host) {} 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 108f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // This method is invoked after the browser process starts a navigation to a 109f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // pending NavigationEntry. It is not called for renderer-initiated 110f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // navigations unless they are sent to the browser process via OpenURL. It may 111f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // be called multiple times for a given navigation, such as a typed URL 112f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // followed by a cross-process client or server redirect. 113f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual void DidStartNavigationToPendingEntry( 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& url, 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NavigationController::ReloadType reload_type) {} 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 117116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // |render_frame_host| is the RenderFrameHost for which the provisional load 118116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // is happening. 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Since the URL validation will strip error URLs, or srcdoc URLs, the boolean 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // flags |is_error_page| and |is_iframe_srcdoc| will indicate that the not 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // validated URL was either an error page or an iframe srcdoc. 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Note that during a cross-process navigation, several provisional loads 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // can be on-going in parallel. 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidStartProvisionalLoadForFrame( 127116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch RenderFrameHost* render_frame_host, 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& validated_url, 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_error_page, 130116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool is_iframe_srcdoc) {} 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This method is invoked when the provisional load was successfully 133116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // committed. 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If the navigation only changed the reference fragment, or was triggered 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // using the history API (e.g. window.history.replaceState), we will receive 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // this signal without a prior DidStartProvisionalLoadForFrame signal. 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidCommitProvisionalLoadForFrame( 139116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch RenderFrameHost* render_frame_host, 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& url, 1411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::PageTransition transition_type) {} 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This method is invoked when the provisional load failed. 144116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void DidFailProvisionalLoad( 145116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch RenderFrameHost* render_frame_host, 146116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const GURL& validated_url, 147116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch int error_code, 148116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const base::string16& error_description) {} 1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If the provisional load corresponded to the main frame, this method is 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // invoked in addition to DidCommitProvisionalLoadForFrame. 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DidNavigateMainFrame( 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const LoadCommittedDetails& details, 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const FrameNavigateParams& params) {} 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // And regardless of what frame navigated, this method is invoked after 1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // DidCommitProvisionalLoadForFrame was invoked. 1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DidNavigateAnyFrame( 1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const LoadCommittedDetails& details, 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const FrameNavigateParams& params) {} 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // This method is invoked once the window.document object of the main frame 1634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // was created. 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DocumentAvailableInMainFrame() {} 1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // This method is invoked once the onload handler of the main frame has 1674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // completed. 168010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual void DocumentOnLoadCompletedInMainFrame() {} 1694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This method is invoked when the document in the given frame finished 1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // loading. At this point, scripts marked as defer were executed, and 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // content scripts marked "document_end" get injected into the frame. 173116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void DocumentLoadedInFrame(RenderFrameHost* render_frame_host) {} 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This method is invoked when the navigation is done, i.e. the spinner of 1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the tab will stop spinning, and the onload event was dispatched. 1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If the WebContents is displaying replacement content, e.g. network error 1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // pages, DidFinishLoad is invoked for frames that were not sending 1802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // navigational events before. It is safe to ignore these events. 181116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void DidFinishLoad(RenderFrameHost* render_frame_host, 182116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const GURL& validated_url) {} 1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This method is like DidFinishLoad, but when the load failed or was 1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // cancelled, e.g. window.stop() is invoked. 186116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void DidFailLoad(RenderFrameHost* render_frame_host, 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& validated_url, 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int error_code, 189116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const base::string16& error_description) {} 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 19158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // This method is invoked when content was loaded from an in-memory cache. 19258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual void DidLoadResourceFromMemoryCache( 19358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const LoadFromMemoryCacheDetails& details) {} 19458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 19558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // This method is invoked when a response has been received for a resource 19658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // request. 19758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual void DidGetResourceResponseStart( 19858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const ResourceRequestDetails& details) {} 19958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 20058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // This method is invoked when a redirect was received while requesting a 20158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // resource. 20258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual void DidGetRedirectForResourceRequest( 2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RenderViewHost* render_view_host, 20458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const ResourceRedirectDetails& details) {} 20558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 206868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // This method is invoked when a new non-pending navigation entry is created. 207868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // This corresponds to one NavigationController entry being created 208868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // (in the case of new navigations) or renavigated to (for back/forward 209868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // navigations). 210868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) virtual void NavigationEntryCommitted( 211868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const LoadCommittedDetails& load_details) {} 212868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This method is invoked when a new WebContents was created in response to 2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // an action in the observed WebContents, e.g. a link with target=_blank was 2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // clicked. The |source_frame_id| indicates in which frame the action took 2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // place. 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidOpenRequestedURL(WebContents* new_contents, 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& url, 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Referrer& referrer, 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowOpenDisposition disposition, 2211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ui::PageTransition transition, 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 source_frame_id) {} 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 224116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void FrameDetached(RenderFrameHost* render_frame_host) {} 2252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 226f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // This method is invoked when the renderer has completed its first paint 227f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // after a non-empty layout. 228010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual void DidFirstVisuallyNonEmptyPaint() {} 229f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // These two methods correspond to the points in time when the spinner of the 2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // tab starts and stops spinning. 2322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DidStartLoading(RenderViewHost* render_view_host) {} 2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DidStopLoading(RenderViewHost* render_view_host) {} 2342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // When WebContents::Stop() is called, the WebContents stops loading and then 2363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // invokes this method. If there are ongoing navigations, their respective 2373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // failure methods will also be invoked. 2383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void NavigationStopped() {} 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This indicates that the next navigation was triggered by a user gesture. 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DidGetUserGesture() {} 2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This method is invoked when a RenderViewHost of this WebContents was 2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // configured to ignore UI events, and an UI event took place. 2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DidGetIgnoredUIEvent() {} 2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // These methods are invoked every time the WebContents changes visibility. 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void WasShown() {} 2494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void WasHidden() {} 2504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 2514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // This methods is invoked when the title of the WebContents is set. If the 2524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // title was explicitly set, |explicit_set| is true, otherwise the title was 2534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // synthesized and |explicit_set| is false. 2544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void TitleWasSet(NavigationEntry* entry, bool explicit_set) {} 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void AppCacheAccessed(const GURL& manifest_url, 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool blocked_by_policy) {} 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Notification that a plugin has crashed. 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |plugin_pid| is the process ID identifying the plugin process. Note that 2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // this ID is supplied by the renderer, so should not be trusted. Besides, the 2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // corresponding process has probably died at this point. The ID may even have 2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // been reused by a new process. 2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void PluginCrashed(const base::FilePath& plugin_path, 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::ProcessId plugin_pid) {} 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Notification that the given plugin has hung or become unhung. This 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // notification is only for Pepper plugins. 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The plugin_child_id is the unique child process ID from the plugin. Note 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that this ID is supplied by the renderer, so should be validated before 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // it's used for anything in case there's an exploited renderer. 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void PluginHungStatusChanged(int plugin_child_id, 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& plugin_path, 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_hung) {} 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invoked when WebContents::Clone() was used to clone a WebContents. 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidCloneToNewWebContents(WebContents* old_web_contents, 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebContents* new_web_contents) {} 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Invoked when the WebContents is being destroyed. Gives subclasses a chance 282010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // to cleanup. After the whole loop over all WebContentsObservers has been 283010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // finished, web_contents() returns NULL. 284010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual void WebContentsDestroyed() {} 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the user agent override for a WebContents has been changed. 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void UserAgentOverrideSet(const std::string& user_agent) {} 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Invoked when new FaviconURL candidates are received from the renderer. 290010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) virtual void DidUpdateFaviconURL(const std::vector<FaviconURL>& candidates) {} 2912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Invoked when a pepper plugin creates and shows or destroys a fullscreen 2932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // render widget. 2942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DidShowFullscreenWidget(int routing_id) {} 2952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DidDestroyFullscreenWidget(int routing_id) {} 2962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 29723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) // Invoked when the renderer has toggled the tab into/out of fullscreen mode. 29823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) virtual void DidToggleFullscreenModeForTab(bool entered_fullscreen) {} 29923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles) 3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Invoked when an interstitial page is attached or detached. 3012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DidAttachInterstitialPage() {} 3022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void DidDetachInterstitialPage() {} 3032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Invoked before a form repost warning is shown. 3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void BeforeFormRepostWarningShow() {} 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 307eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Invoked when the beforeunload handler fires. The time is from the renderer. 3087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) {} 3097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 3107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Invoked when a user cancels a before unload dialog. 3117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual void BeforeUnloadDialogCancelled() {} 3127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 313a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Invoked when an accessibility event is received from the renderer. 314a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) virtual void AccessibilityEventReceived( 315a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) const std::vector<AXEventNotificationDetails>& details) {} 316a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 317116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Invoked when theme color is changed to |theme_color|. 318116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void DidChangeThemeColor(SkColor theme_color) {} 3196d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) 320cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Invoked if an IPC message is coming from a specific RenderFrameHost. 321cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual bool OnMessageReceived(const IPC::Message& message, 322cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) RenderFrameHost* render_frame_host); 323cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // IPC::Listener implementation. 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // IPC::Sender implementation. 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool Send(IPC::Message* message) OVERRIDE; 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int routing_id() const; 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci WebContents* web_contents() const; 3321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Use this constructor when the object is tied to a single WebContents for 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // its entire lifetime. 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit WebContentsObserver(WebContents* web_contents); 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Use this constructor when the object wants to observe a WebContents for 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // part of its lifetime. It can then call Observe() to start and stop 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // observing. 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebContentsObserver(); 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~WebContentsObserver(); 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Start observing a different WebContents; used with the default constructor. 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Observe(WebContents* web_contents); 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class WebContentsImpl; 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 351010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) void ResetWebContents(); 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebContentsImpl* web_contents_; 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(WebContentsObserver); 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace content 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ 361