Index: chromecast/browser/cast_web_contents.h |
diff --git a/chromecast/browser/cast_web_contents.h b/chromecast/browser/cast_web_contents.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ce3522242213234858066d55dc3525a0dba34cac |
--- /dev/null |
+++ b/chromecast/browser/cast_web_contents.h |
@@ -0,0 +1,108 @@ |
+// Copyright 2017 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 CHROMECAST_BROWSER_CAST_WEB_CONTENTS_H_ |
+#define CHROMECAST_BROWSER_CAST_WEB_CONTENTS_H_ |
+ |
+#include <memory> |
+#include <string> |
+ |
+#include "base/memory/weak_ptr.h" |
+#include "chromecast/browser/cast_content_window.h" |
+#include "content/public/browser/web_contents.h" |
+#include "content/public/browser/web_contents_delegate.h" |
+#include "content/public/browser/web_contents_observer.h" |
+ |
+namespace content { |
+class BrowserContext; |
+} |
+ |
+namespace chromecast { |
+ |
+// A simplified interface for loading and displaying WebContents in cast_shell. |
+class CastWebContents : content::WebContentsObserver, |
+ content::WebContentsDelegate { |
+ public: |
+ class Delegate : public shell::CastContentWindow::Delegate { |
+ public: |
+ // Called when the page has stopped. ie: A 404 occured when loading the page |
+ // or if the render process crashes. |error_code| will return a net error |
+ // describing the failure, or net::OK if the page closed naturally. |
+ virtual void OnPageStopped(int error_code) = 0; |
+ |
+ // Called during WebContentsDelegate::LoadingStateChanged. |
+ // |loading| indicates if web_contents_ IsLoading or not. |
+ virtual void OnLoadingStateChanged(bool loading) = 0; |
+ }; |
+ |
+ // |delegate| and |browser_context| should outlive the lifetime of this |
+ // object. |
+ CastWebContents(Delegate* delegate, content::BrowserContext* browser_context); |
+ ~CastWebContents() override; |
+ |
+ shell::CastContentWindow* window() const { |
+ return window_.get(); |
+ } |
+ |
+ content::WebContents* web_contents() const { |
+ return web_contents_.get(); |
+ } |
+ |
+ // Navigates to |url|. The loaded page will be preloaded if MakeVisible has |
+ // not been called on the object. |
+ void LoadUrl(GURL url); |
+ |
+ // Closes the page. |
+ void ClosePage(); |
+ |
+ // Makes the page visible to the user. |
+ void MakeVisible(); |
+ |
+ private: |
+ // WebContentsObserver implementation: |
+ void RenderProcessGone(base::TerminationStatus status) override; |
+ void DidFailProvisionalLoad(content::RenderFrameHost* render_frame_host, |
+ const GURL& validated_url, |
+ int error_code, |
+ const base::string16& error_description, |
+ bool was_ignored_by_handler) override; |
+ void DidFailLoad(content::RenderFrameHost* render_frame_host, |
+ const GURL& validated_url, |
+ int error_code, |
+ const base::string16& error_description, |
+ bool was_ignored_by_handler) override; |
+ void DidFirstVisuallyNonEmptyPaint() override; |
+ void MediaStartedPlaying(const MediaPlayerInfo& media_info, |
+ const MediaPlayerId& id) override; |
+ void MediaStoppedPlaying(const MediaPlayerInfo& media_info, |
+ const MediaPlayerId& id) override; |
+ |
+ // WebContentsDelegate implementation: |
+ content::WebContents* OpenURLFromTab( |
+ content::WebContents* source, |
+ const content::OpenURLParams& params) override; |
+ void CloseContents(content::WebContents* source) override; |
+ void LoadingStateChanged(content::WebContents* source, |
+ bool to_different_document) override; |
+ void ActivateContents(content::WebContents* contents) override; |
+#if defined(OS_ANDROID) |
+ base::android::ScopedJavaLocalRef<jobject> GetContentVideoViewEmbedder() |
+ override; |
+#endif // defined(OS_ANDROID) |
+ |
+ void DelayedCloseContents(); |
+ |
+ Delegate* const delegate_; |
+ content::BrowserContext* const browser_context_; |
+ const std::unique_ptr<shell::CastContentWindow> window_; |
+ std::unique_ptr<content::WebContents> web_contents_; |
+ |
+ base::WeakPtrFactory<CastWebContents> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CastWebContents); |
+}; |
+ |
+} // namespace chromecast |
+ |
+#endif // CHROMECAST_BROWSER_CAST_WEB_CONTENTS_H_ |