web_contents_observer.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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)
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/process.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/process_util.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/content_export.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/navigation_controller.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/page_transition_types.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ipc/ipc_listener.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ipc/ipc_sender.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/window_open_disposition.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class RenderViewHost;
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContents;
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContentsImpl;
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct FaviconURL;
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct FrameNavigateParams;
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct LoadCommittedDetails;
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct Referrer;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// An observer API implemented by classes which are interested in various page
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// load events from WebContents.  They also get a chance to filter IPC messages.
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Since a WebContents can be a delegate to almost arbitrarly many
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// RenderViewHosts, it is important to check in those WebContentsObserver
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// methods which take a RenderViewHost that the event came from the
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// RenderViewHost the observer cares about.
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Usually, observers should only care about the current RenderViewHost as
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// returned by GetRenderViewHost().
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)//
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// TODO(creis, jochen): Hide the fact that there are several RenderViewHosts
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// from the WebContentsObserver API. http://crbug.com/173325
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CONTENT_EXPORT WebContentsObserver : public IPC::Listener,
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                           public IPC::Sender {
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Only one of the two methods below will be called when a RVH is created for
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // a WebContents, depending on whether it's for an interstitial or not.
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RenderViewCreated(RenderViewHost* render_view_host) {}
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RenderViewForInterstitialPageCreated(
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      RenderViewHost* render_view_host) {}
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method is invoked when the RenderView of the current RenderViewHost
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // is ready, e.g. because we recreated it after a crash.
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RenderViewReady() {}
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method is invoked when a RenderViewHost of the WebContents is
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // deleted. Note that this does not always happen when the WebContents starts
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // to use a different RenderViewHost, as the old RenderViewHost might get
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // just swapped out.
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void RenderViewDeleted(RenderViewHost* render_view_host) {}
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method is invoked when the current RenderView crashes. The WebContents
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // continues to use the RenderViewHost, e.g. when the user reloads the current
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // page.
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // When the RenderViewHost is deleted, the RenderViewDeleted method will be
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // invoked.
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RenderViewGone(base::TerminationStatus status) {}
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method is invoked after the WebContents decided which RenderViewHost
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // to use for the next navigation, but before the navigation starts.
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void AboutToNavigateRenderView(
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      RenderViewHost* render_view_host) {}
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method is invoked right after the navigation was initiated.
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void NavigateToPendingEntry(
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GURL& url,
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      NavigationController::ReloadType reload_type) {}
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |render_view_host| is the RenderViewHost for which the provisional load is
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // happening. |frame_id| is a positive, non-zero integer identifying the
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // navigating frame in the given |render_view_host|. |parent_frame_id| is the
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // frame identifier of the frame containing the navigating frame, or -1 if the
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // frame is not contained in another frame.
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Since the URL validation will strip error URLs, or srcdoc URLs, the boolean
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // flags |is_error_page| and |is_iframe_srcdoc| will indicate that the not
842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // validated URL was either an error page or an iframe srcdoc.
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Note that during a cross-process navigation, several provisional loads
872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // can be on-going in parallel.
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DidStartProvisionalLoadForFrame(
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      int64 frame_id,
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      int64 parent_frame_id,
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      bool is_main_frame,
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GURL& validated_url,
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      bool is_error_page,
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      bool is_iframe_srcdoc,
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      RenderViewHost* render_view_host) {}
962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method is invoked right after the DidStartProvisionalLoadForFrame if
982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // the provisional load affects the main frame, or if the provisional load
992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // was redirected. The latter use case is DEPRECATED. You should listen to
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // instead.
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void ProvisionalChangeToMainFrameUrl(
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GURL& url,
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      RenderViewHost* render_view_host) {}
1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method is invoked when the provisional load was successfully
1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // commited. The |render_view_host| is now the current RenderViewHost of the
1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // WebContents.
1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //
1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // If the navigation only changed the reference fragment, or was triggered
1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // using the history API (e.g. window.history.replaceState), we will receive
1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // this signal without a prior DidStartProvisionalLoadForFrame signal.
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DidCommitProvisionalLoadForFrame(
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      int64 frame_id,
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      bool is_main_frame,
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GURL& url,
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      PageTransition transition_type,
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      RenderViewHost* render_view_host) {}
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method is invoked when the provisional load failed.
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DidFailProvisionalLoad(int64 frame_id,
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                      bool is_main_frame,
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                      const GURL& validated_url,
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                      int error_code,
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                      const string16& error_description,
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                      RenderViewHost* render_view_host) {}
1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // If the provisional load corresponded to the main frame, this method is
1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // invoked in addition to DidCommitProvisionalLoadForFrame.
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void DidNavigateMainFrame(
1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const LoadCommittedDetails& details,
1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const FrameNavigateParams& params) {}
1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // And regardless of what frame navigated, this method is invoked after
1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // DidCommitProvisionalLoadForFrame was invoked.
1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void DidNavigateAnyFrame(
1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const LoadCommittedDetails& details,
1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const FrameNavigateParams& params) {}
1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method is invoked once the window.document object was created.
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DocumentAvailableInMainFrame() {}
1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method is invoked when the document in the given frame finished
1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // loading. At this point, scripts marked as defer were executed, and
1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // content scripts marked "document_end" get injected into the frame.
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DocumentLoadedInFrame(int64 frame_id,
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     RenderViewHost* render_view_host) {}
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method is invoked when the navigation is done, i.e. the spinner of
1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // the tab will stop spinning, and the onload event was dispatched.
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // If the WebContents is displaying replacement content, e.g. network error
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // pages, DidFinishLoad is invoked for frames that were not sending
1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // navigational events before. It is safe to ignore these events.
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DidFinishLoad(int64 frame_id,
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const GURL& validated_url,
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             bool is_main_frame,
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             RenderViewHost* render_view_host) {}
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method is like DidFinishLoad, but when the load failed or was
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // cancelled, e.g. window.stop() is invoked.
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DidFailLoad(int64 frame_id,
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           const GURL& validated_url,
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           bool is_main_frame,
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           int error_code,
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           const string16& error_description,
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           RenderViewHost* render_view_host) {}
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
169868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // This method is invoked when a new non-pending navigation entry is created.
170868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // This corresponds to one NavigationController entry being created
171868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // (in the case of new navigations) or renavigated to (for back/forward
172868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // navigations).
173868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  virtual void NavigationEntryCommitted(
174868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      const LoadCommittedDetails& load_details) {}
175868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method is invoked when a new WebContents was created in response to
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // an action in the observed WebContents, e.g. a link with target=_blank was
1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // clicked. The |source_frame_id| indicates in which frame the action took
1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // place.
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DidOpenRequestedURL(WebContents* new_contents,
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const GURL& url,
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const Referrer& referrer,
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   WindowOpenDisposition disposition,
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   PageTransition transition,
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   int64 source_frame_id) {}
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void FrameDetached(RenderViewHost* render_view_host,
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             int64 frame_id) {}
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // These two methods correspond to the points in time when the spinner of the
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // tab starts and stops spinning.
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void DidStartLoading(RenderViewHost* render_view_host) {}
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void DidStopLoading(RenderViewHost* render_view_host) {}
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method is invoked when the navigation from the browser process. If
1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // there are ongoing navigations, the respective failure methods will also be
1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // invoked.
1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void StopNavigation() {}
1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This indicates that the next navigation was triggered by a user gesture.
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void DidGetUserGesture() {}
2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method is invoked when a RenderViewHost of this WebContents was
2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // configured to ignore UI events, and an UI event took place.
2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void DidGetIgnoredUIEvent() {}
2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This method is invoked every time the WebContents becomes visible.
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void WasShown() {}
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void AppCacheAccessed(const GURL& manifest_url,
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                bool blocked_by_policy) {}
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notification that a plugin has crashed.
2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // |plugin_pid| is the process ID identifying the plugin process. Note that
2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // this ID is supplied by the renderer, so should not be trusted. Besides, the
2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // corresponding process has probably died at this point. The ID may even have
2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // been reused by a new process.
2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void PluginCrashed(const base::FilePath& plugin_path,
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             base::ProcessId plugin_pid) {}
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notication that the given plugin has hung or become unhung. This
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // notification is only for Pepper plugins.
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The plugin_child_id is the unique child process ID from the plugin. Note
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // that this ID is supplied by the renderer, so should be validated before
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // it's used for anything in case there's an exploited renderer.
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void PluginHungStatusChanged(int plugin_child_id,
2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                       const base::FilePath& plugin_path,
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                       bool is_hung) {}
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Invoked when WebContents::Clone() was used to clone a WebContents.
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DidCloneToNewWebContents(WebContents* old_web_contents,
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        WebContents* new_web_contents) {}
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Invoked when the WebContents is being destroyed. Gives subclasses a chance
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to cleanup. At the time this is invoked |web_contents()| returns NULL.
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // It is safe to delete 'this' from here.
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void WebContentsDestroyed(WebContents* web_contents) {}
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when the user agent override for a WebContents has been changed.
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void UserAgentOverrideSet(const std::string& user_agent) {}
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Invoked when new FaviconURL candidates are received from the renderer.
2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void DidUpdateFaviconURL(int32 page_id,
2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                   const std::vector<FaviconURL>& candidates) {}
2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Invoked when a pepper plugin creates and shows or destroys a fullscreen
2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // render widget.
2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void DidShowFullscreenWidget(int routing_id) {}
2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void DidDestroyFullscreenWidget(int routing_id) {}
2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Invoked when visible SSL state (as defined by SSLStatus) changes.
2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void DidChangeVisibleSSLState() {}
2542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Invoked when an interstitial page is attached or detached.
2562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void DidAttachInterstitialPage() {}
2572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void DidDetachInterstitialPage() {}
2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Invoked before a form repost warning is shown.
2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void BeforeFormRepostWarningShow() {}
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Invoked when the before unload fires. The time is from the renderer.
2637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) {}
2647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Invoked when a user cancels a before unload dialog.
2667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  virtual void BeforeUnloadDialogCancelled() {}
2677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // IPC::Listener implementation.
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // IPC::Sender implementation.
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool Send(IPC::Message* message) OVERRIDE;
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int routing_id() const;
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Use this constructor when the object is tied to a single WebContents for
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // its entire lifetime.
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  explicit WebContentsObserver(WebContents* web_contents);
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Use this constructor when the object wants to observe a WebContents for
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // part of its lifetime.  It can then call Observe() to start and stop
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // observing.
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebContentsObserver();
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~WebContentsObserver();
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Start observing a different WebContents; used with the default constructor.
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Observe(WebContents* web_contents);
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebContents* web_contents() const;
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class WebContentsImpl;
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Invoked from WebContentsImpl. Invokes WebContentsDestroyed and NULL out
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |web_contents_|.
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void WebContentsImplDestroyed();
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebContentsImpl* web_contents_;
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(WebContentsObserver);
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace content
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_
307