Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_VIEW_H_ | |
| 6 #define CHROMECAST_BROWSER_CAST_WEB_VIEW_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 class RenderViewHost; | |
| 20 } | |
| 21 | |
| 22 namespace chromecast { | |
| 23 | |
| 24 // A simplified interface for loading and displaying WebContents in cast_shell. | |
| 25 class CastWebView : content::WebContentsObserver, | |
| 26 content::WebContentsDelegate { | |
| 27 public: | |
| 28 class Delegate : public shell::CastContentWindow::Delegate { | |
| 29 public: | |
| 30 // Called when the page has stopped. ie: A 404 occured when loading the page | |
| 31 // 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.
| |
| 32 // describing the failure, or net::OK if the page closed naturally. | |
| 33 virtual void OnPageStopped(int error_code) = 0; | |
| 34 | |
| 35 // Called during WebContentsDelegate::LoadingStateChanged. | |
| 36 // |loading| indicates if web_contents_ IsLoading or not. | |
| 37 virtual void OnLoadingStateChanged(bool loading) = 0; | |
| 38 }; | |
| 39 | |
| 40 // |delegate| and |browser_context| should outlive the lifetime of this | |
| 41 // object. | |
| 42 CastWebView(Delegate* delegate, content::BrowserContext* browser_context, | |
| 43 bool transparent); | |
| 44 ~CastWebView() override; | |
| 45 | |
| 46 shell::CastContentWindow* window() const { | |
| 47 return window_.get(); | |
| 48 } | |
| 49 | |
| 50 content::WebContents* web_contents() const { | |
| 51 return web_contents_.get(); | |
| 52 } | |
| 53 | |
| 54 // Navigates to |url|. The loaded page will be preloaded if MakeVisible has | |
| 55 // not been called on the object. | |
| 56 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.
| |
| 57 | |
| 58 // Closes the page. | |
| 59 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
| |
| 60 | |
| 61 // Makes the page visible to the user. | |
| 62 void MakeVisible(); | |
|
alokp
2017/01/18 05:10:56
nit: Show
derekjchow1
2017/01/19 01:22:12
Done.
| |
| 63 | |
| 64 private: | |
| 65 // WebContentsObserver implementation: | |
| 66 void RenderProcessGone(base::TerminationStatus status) override; | |
| 67 void RenderViewCreated(content::RenderViewHost* render_view_host) override; | |
| 68 void DidFailProvisionalLoad(content::RenderFrameHost* render_frame_host, | |
| 69 const GURL& validated_url, | |
| 70 int error_code, | |
| 71 const base::string16& error_description, | |
| 72 bool was_ignored_by_handler) override; | |
| 73 void DidFailLoad(content::RenderFrameHost* render_frame_host, | |
| 74 const GURL& validated_url, | |
| 75 int error_code, | |
| 76 const base::string16& error_description, | |
| 77 bool was_ignored_by_handler) override; | |
| 78 void DidFirstVisuallyNonEmptyPaint() override; | |
| 79 void MediaStartedPlaying(const MediaPlayerInfo& media_info, | |
| 80 const MediaPlayerId& id) override; | |
| 81 void MediaStoppedPlaying(const MediaPlayerInfo& media_info, | |
| 82 const MediaPlayerId& id) override; | |
| 83 | |
| 84 // WebContentsDelegate implementation: | |
| 85 content::WebContents* OpenURLFromTab( | |
| 86 content::WebContents* source, | |
| 87 const content::OpenURLParams& params) override; | |
| 88 void CloseContents(content::WebContents* source) override; | |
| 89 void LoadingStateChanged(content::WebContents* source, | |
| 90 bool to_different_document) override; | |
| 91 void ActivateContents(content::WebContents* contents) override; | |
| 92 #if defined(OS_ANDROID) | |
| 93 base::android::ScopedJavaLocalRef<jobject> GetContentVideoViewEmbedder() | |
| 94 override; | |
| 95 #endif // defined(OS_ANDROID) | |
| 96 | |
| 97 void DelayedCloseContents(); | |
| 98 | |
| 99 Delegate* const delegate_; | |
| 100 content::BrowserContext* const browser_context_; | |
| 101 const bool transparent_; | |
| 102 const std::unique_ptr<shell::CastContentWindow> window_; | |
| 103 std::unique_ptr<content::WebContents> web_contents_; | |
| 104 | |
| 105 base::WeakPtrFactory<CastWebView> weak_factory_; | |
| 106 | |
| 107 DISALLOW_COPY_AND_ASSIGN(CastWebView); | |
| 108 }; | |
| 109 | |
| 110 } // namespace chromecast | |
| 111 | |
| 112 #endif // CHROMECAST_BROWSER_CAST_WEB_VIEW_H_ | |
| OLD | NEW |