Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Unified Diff: chromecast/browser/cast_web_view.h

Issue 2626863006: [Chromecast] Add CastWebContents (Closed)
Patch Set: [Chromecast] Add CastWebContents Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromecast/browser/cast_content_window_linux.cc ('k') | chromecast/browser/cast_web_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromecast/browser/cast_web_view.h
diff --git a/chromecast/browser/cast_web_view.h b/chromecast/browser/cast_web_view.h
new file mode 100644
index 0000000000000000000000000000000000000000..26195913024ecd0458fd3790bb97bf5a1ba8e66f
--- /dev/null
+++ b/chromecast/browser/cast_web_view.h
@@ -0,0 +1,114 @@
+// 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_VIEW_H_
+#define CHROMECAST_BROWSER_CAST_WEB_VIEW_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;
+class RenderViewHost;
+class SiteInstance;
+}
+
+namespace chromecast {
+
+class CastWindowManager;
+
+// A simplified interface for loading and displaying WebContents in cast_shell.
+class CastWebView : 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.
+ CastWebView(Delegate* delegate,
+ content::BrowserContext* browser_context,
+ scoped_refptr<content::SiteInstance> site_instance,
+ bool transparent);
+ ~CastWebView() 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);
+
+ // Begins the close process for this page (ie. triggering document.onunload).
+ // A consumer of the class can be notified when the process has been finished
+ // via Delegate::OnPageStopped().
+ void ClosePage();
+
+ // Makes the page visible to the user.
+ void Show(CastWindowManager* window_manager);
+
+ private:
+ // WebContentsObserver implementation:
+ void RenderProcessGone(base::TerminationStatus status) override;
+ void RenderViewCreated(content::RenderViewHost* render_view_host) override;
+ void DidFinishNavigation(
+ content::NavigationHandle* navigation_handle) 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 DidStartNavigation(
+ content::NavigationHandle* navigation_handle) 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 scoped_refptr<content::SiteInstance> site_instance_;
+ const bool transparent_;
+ const std::unique_ptr<shell::CastContentWindow> window_;
+ std::unique_ptr<content::WebContents> web_contents_;
+
+ base::WeakPtrFactory<CastWebView> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(CastWebView);
+};
+
+} // namespace chromecast
+
+#endif // CHROMECAST_BROWSER_CAST_WEB_VIEW_H_
« no previous file with comments | « chromecast/browser/cast_content_window_linux.cc ('k') | chromecast/browser/cast_web_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698