diff options
Diffstat (limited to 'content/public')
-rw-r--r-- | content/public/browser/DEPS | 1 | ||||
-rw-r--r-- | content/public/browser/web_contents_observer.cc | 65 | ||||
-rw-r--r-- | content/public/browser/web_contents_observer.h | 137 | ||||
-rw-r--r-- | content/public/common/frame_navigate_params.h | 2 |
4 files changed, 204 insertions, 1 deletions
diff --git a/content/public/browser/DEPS b/content/public/browser/DEPS index 2f3c1e2..9e39647 100644 --- a/content/public/browser/DEPS +++ b/content/public/browser/DEPS @@ -7,6 +7,7 @@ include_rules = [ "+content/browser/download/save_package.h", "+content/browser/download/interrupt_reasons.h", "+content/browser/javascript_dialogs.h", + "+content/browser/tab_contents/navigation_controller.h", "+content/browser/tab_contents/navigation_entry.h", "+content/browser/tab_contents/tab_contents.h", "+content/browser/webui/web_ui.h", diff --git a/content/public/browser/web_contents_observer.cc b/content/public/browser/web_contents_observer.cc new file mode 100644 index 0000000..2ec882b --- /dev/null +++ b/content/public/browser/web_contents_observer.cc @@ -0,0 +1,65 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/public/browser/web_contents_observer.h" + +#include "content/browser/renderer_host/render_view_host.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "content/public/browser/navigation_details.h" + +namespace content { + +WebContentsObserver::WebContentsObserver(TabContents* tab_contents) + : tab_contents_(NULL) { + Observe(tab_contents); +} + +WebContentsObserver::WebContentsObserver() + : tab_contents_(NULL) { +} + +WebContentsObserver::~WebContentsObserver() { + if (tab_contents_) + tab_contents_->RemoveObserver(this); +} + +void WebContentsObserver::Observe(TabContents* tab_contents) { + if (tab_contents_) + tab_contents_->RemoveObserver(this); + tab_contents_ = tab_contents; + if (tab_contents_) { + tab_contents_->AddObserver(this); + } +} + +bool WebContentsObserver::OnMessageReceived(const IPC::Message& message) { + return false; +} + +bool WebContentsObserver::Send(IPC::Message* message) { + if (!tab_contents_ || !tab_contents_->GetRenderViewHost()) { + delete message; + return false; + } + + return tab_contents_->GetRenderViewHost()->Send(message); +} + +int WebContentsObserver::routing_id() const { + if (!tab_contents_ || !tab_contents_->GetRenderViewHost()) + return MSG_ROUTING_NONE; + + return tab_contents_->GetRenderViewHost()->routing_id(); +} + +void WebContentsObserver::TabContentsDestroyed() { + // Do cleanup so that 'this' can safely be deleted from + // TabContentsDestroyed. + tab_contents_->RemoveObserver(this); + TabContents* tab = tab_contents_; + tab_contents_ = NULL; + TabContentsDestroyed(tab); +} + +} // namespace content diff --git a/content/public/browser/web_contents_observer.h b/content/public/browser/web_contents_observer.h new file mode 100644 index 0000000..a3d713f --- /dev/null +++ b/content/public/browser/web_contents_observer.h @@ -0,0 +1,137 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ +#define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ + +#include "base/process_util.h" +#include "content/browser/tab_contents/navigation_controller.h" +#include "content/common/content_export.h" +#include "content/public/common/page_transition_types.h" +#include "ipc/ipc_channel.h" +#include "webkit/glue/window_open_disposition.h" + +class RenderViewHost; +class TabContents; + +namespace content { + +struct FrameNavigateParams; +struct Referrer; + +// An observer API implemented by classes which are interested in various page +// load events from TabContents. They also get a chance to filter IPC messages. +class CONTENT_EXPORT WebContentsObserver : public IPC::Channel::Listener, + public IPC::Message::Sender { + public: + virtual void RenderViewCreated(RenderViewHost* render_view_host) {} + virtual void RenderViewDeleted(RenderViewHost* render_view_host) {} + virtual void RenderViewReady() {} + virtual void RenderViewGone(base::TerminationStatus status) {} + virtual void NavigateToPendingEntry( + const GURL& url, + NavigationController::ReloadType reload_type) {} + virtual void DidNavigateMainFrame( + const LoadCommittedDetails& details, + const FrameNavigateParams& params) {} + virtual void DidNavigateAnyFrame( + const LoadCommittedDetails& details, + const FrameNavigateParams& params) {} + // |render_view_host| is the RenderViewHost for which the provisional load is + // happening. + virtual void DidStartProvisionalLoadForFrame( + int64 frame_id, + bool is_main_frame, + const GURL& validated_url, + bool is_error_page, + RenderViewHost* render_view_host) {} + virtual void ProvisionalChangeToMainFrameUrl(const GURL& url, + const GURL& opener_url) {} + virtual void DidCommitProvisionalLoadForFrame( + int64 frame_id, + bool is_main_frame, + const GURL& url, + PageTransition transition_type) {} + virtual void DidFailProvisionalLoad(int64 frame_id, + bool is_main_frame, + const GURL& validated_url, + int error_code, + const string16& error_description) {} + virtual void DocumentAvailableInMainFrame() {} + virtual void DocumentLoadedInFrame(int64 frame_id) {} + virtual void DidFinishLoad(int64 frame_id, + const GURL& validated_url, + bool is_main_frame) {} + virtual void DidFailLoad(int64 frame_id, + const GURL& validated_url, + bool is_main_frame, + int error_code, + const string16& error_description) {} + virtual void DidGetUserGesture() {} + virtual void DidGetIgnoredUIEvent() {} + virtual void DidBecomeSelected() {} + + virtual void DidStartLoading() {} + virtual void DidStopLoading() {} + virtual void StopNavigation() {} + + virtual void DidOpenURL(const GURL& url, + const Referrer& referrer, + WindowOpenDisposition disposition, + PageTransition transition) {} + + virtual void DidOpenRequestedURL(TabContents* new_contents, + const GURL& url, + const Referrer& referrer, + WindowOpenDisposition disposition, + PageTransition transition, + int64 source_frame_id) {} + + virtual void AppCacheAccessed(const GURL& manifest_url, + bool blocked_by_policy) {} + + // Invoked when the TabContents is being destroyed. Gives subclasses a chance + // to cleanup. At the time this is invoked |tab_contents()| returns NULL. + // It is safe to delete 'this' from here. + virtual void TabContentsDestroyed(TabContents* tab) {} + + // IPC::Channel::Listener implementation. + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + + // IPC::Message::Sender implementation. + virtual bool Send(IPC::Message* message) OVERRIDE; + int routing_id() const; + + protected: + // Use this constructor when the object is tied to a single TabContents for + // its entire lifetime. + explicit WebContentsObserver(TabContents* tab_contents); + + // Use this constructor when the object wants to observe a TabContents for + // part of its lifetime. It can then call Observe() to start and stop + // observing. + WebContentsObserver(); + + virtual ~WebContentsObserver(); + + // Start observing a different TabContents; used with the default constructor. + void Observe(TabContents* tab_contents); + + TabContents* tab_contents() const { return tab_contents_; } + + private: + friend class ::TabContents; + + // Invoked from TabContents. Invokes TabContentsDestroyed and NULL out + // |tab_contents_|. + void TabContentsDestroyed(); + + TabContents* tab_contents_; + + DISALLOW_COPY_AND_ASSIGN(WebContentsObserver); +}; + +} // namespace content + +#endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_OBSERVER_H_ diff --git a/content/public/common/frame_navigate_params.h b/content/public/common/frame_navigate_params.h index 56de737..6ae99eb 100644 --- a/content/public/common/frame_navigate_params.h +++ b/content/public/common/frame_navigate_params.h @@ -18,7 +18,7 @@ namespace content { -// Struct used by TabContentsObserver. +// Struct used by WebContentsObserver. struct CONTENT_EXPORT FrameNavigateParams { FrameNavigateParams(); ~FrameNavigateParams(); |