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

Unified Diff: chromecast/browser/cast_web_view.h

Issue 2626863006: [Chromecast] Add CastWebContents (Closed)
Patch Set: s/CastWebContents/CastWebView/g Created 3 years, 11 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..fce4a3c2aacb16477ed77a45aea57e89891b1942
--- /dev/null
+++ b/chromecast/browser/cast_web_view.h
@@ -0,0 +1,112 @@
+// 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;
+}
+
+namespace chromecast {
+
+// 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
alokp 2017/01/18 05:10:56 nit: "net error" -> net::Error
derekjchow1 2017/01/19 01:22:11 Done.
+ // 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,
+ 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);
alokp 2017/01/18 05:10:56 Can this be called multiple times with a different
derekjchow1 2017/01/19 01:22:11 Done.
+
+ // Closes the page.
+ void ClosePage();
alokp 2017/01/18 05:10:56 Why do we need this API? Can't we just delete the
derekjchow1 2017/01/19 01:22:11 Calling ClosePage begins the closing process, whic
alokp 2017/01/19 05:26:36 In that case this function should take a completio
derekjchow1 2017/01/19 21:59:16 I disagree. We should handle page stops the same w
+
+ // Makes the page visible to the user.
+ void MakeVisible();
alokp 2017/01/18 05:10:56 nit: Show
derekjchow1 2017/01/19 01:22:12 Done.
+
+ private:
+ // WebContentsObserver implementation:
+ void RenderProcessGone(base::TerminationStatus status) override;
+ void RenderViewCreated(content::RenderViewHost* render_view_host) 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 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