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

Side by Side Diff: chromecast/browser/cast_web_contents.h

Issue 2626863006: [Chromecast] Add CastWebContents (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROMECAST_BROWSER_CAST_WEB_CONTENTS_H_
6 #define CHROMECAST_BROWSER_CAST_WEB_CONTENTS_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/memory/weak_ptr.h"
12 #include "chromecast/browser/cast_content_window.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/browser/web_contents_delegate.h"
15 #include "content/public/browser/web_contents_observer.h"
16
17 namespace content {
18 class BrowserContext;
19 }
20
21 namespace chromecast {
22
23 // A simplified interface for loading and displaying WebContents in cast_shell.
24 class CastWebContents : content::WebContentsObserver,
25 content::WebContentsDelegate {
26 public:
27 class Delegate : public shell::CastContentWindow::Delegate {
28 public:
29 // Called when the page has stopped. ie: A 404 occured when loading the page
30 // or if the render process crashes. |error_code| will return a net error
31 // describing the failure, or net::OK if the page closed naturally.
32 virtual void OnPageStopped(int error_code) = 0;
33
34 // Called during WebContentsDelegate::LoadingStateChanged.
35 // |loading| indicates if web_contents_ IsLoading or not.
36 virtual void OnLoadingStateChanged(bool loading) = 0;
37 };
38
39 // |delegate| and |browser_context| should outlive the lifetime of this
40 // object.
41 CastWebContents(Delegate* delegate, content::BrowserContext* browser_context);
42 ~CastWebContents() override;
43
44 shell::CastContentWindow* window() const {
45 return window_.get();
46 }
47
48 content::WebContents* web_contents() const {
49 return web_contents_.get();
50 }
51
52 // Navigates to |url|. The loaded page will be preloaded if MakeVisible has
53 // not been called on the object.
54 void LoadUrl(GURL url);
55
56 // Closes the page.
57 void ClosePage();
58
59 // Makes the page visible to the user.
60 void MakeVisible();
61
62 private:
63 // WebContentsObserver implementation:
64 void RenderProcessGone(base::TerminationStatus status) override;
65 void DidFailProvisionalLoad(content::RenderFrameHost* render_frame_host,
66 const GURL& validated_url,
67 int error_code,
68 const base::string16& error_description,
69 bool was_ignored_by_handler) override;
70 void DidFailLoad(content::RenderFrameHost* render_frame_host,
71 const GURL& validated_url,
72 int error_code,
73 const base::string16& error_description,
74 bool was_ignored_by_handler) override;
75 void DidFirstVisuallyNonEmptyPaint() override;
76 void MediaStartedPlaying(const MediaPlayerInfo& media_info,
77 const MediaPlayerId& id) override;
78 void MediaStoppedPlaying(const MediaPlayerInfo& media_info,
79 const MediaPlayerId& id) override;
80
81 // WebContentsDelegate implementation:
82 content::WebContents* OpenURLFromTab(
83 content::WebContents* source,
84 const content::OpenURLParams& params) override;
85 void CloseContents(content::WebContents* source) override;
86 void LoadingStateChanged(content::WebContents* source,
87 bool to_different_document) override;
88 void ActivateContents(content::WebContents* contents) override;
89 #if defined(OS_ANDROID)
90 base::android::ScopedJavaLocalRef<jobject> GetContentVideoViewEmbedder()
91 override;
92 #endif // defined(OS_ANDROID)
93
94 void DelayedCloseContents();
95
96 Delegate* const delegate_;
97 content::BrowserContext* const browser_context_;
98 const std::unique_ptr<shell::CastContentWindow> window_;
99 std::unique_ptr<content::WebContents> web_contents_;
100
101 base::WeakPtrFactory<CastWebContents> weak_factory_;
102
103 DISALLOW_COPY_AND_ASSIGN(CastWebContents);
104 };
105
106 } // namespace chromecast
107
108 #endif // CHROMECAST_BROWSER_CAST_WEB_CONTENTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698