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 class SiteInstance; |
| 21 } |
| 22 |
| 23 namespace chromecast { |
| 24 |
| 25 class CastWindowManager; |
| 26 |
| 27 // A simplified interface for loading and displaying WebContents in cast_shell. |
| 28 class CastWebView : content::WebContentsObserver, content::WebContentsDelegate { |
| 29 public: |
| 30 class Delegate : public shell::CastContentWindow::Delegate { |
| 31 public: |
| 32 // Called when the page has stopped. ie: A 404 occured when loading the page |
| 33 // or if the render process crashes. |error_code| will return a net::Error |
| 34 // describing the failure, or net::OK if the page closed naturally. |
| 35 virtual void OnPageStopped(int error_code) = 0; |
| 36 |
| 37 // Called during WebContentsDelegate::LoadingStateChanged. |
| 38 // |loading| indicates if web_contents_ IsLoading or not. |
| 39 virtual void OnLoadingStateChanged(bool loading) = 0; |
| 40 }; |
| 41 |
| 42 // |delegate| and |browser_context| should outlive the lifetime of this |
| 43 // object. |
| 44 CastWebView(Delegate* delegate, |
| 45 content::BrowserContext* browser_context, |
| 46 scoped_refptr<content::SiteInstance> site_instance, |
| 47 bool transparent); |
| 48 ~CastWebView() override; |
| 49 |
| 50 shell::CastContentWindow* window() const { return window_.get(); } |
| 51 |
| 52 content::WebContents* web_contents() const { return web_contents_.get(); } |
| 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); |
| 57 |
| 58 // Begins the close process for this page (ie. triggering document.onunload). |
| 59 // A consumer of the class can be notified when the process has been finished |
| 60 // via Delegate::OnPageStopped(). |
| 61 void ClosePage(); |
| 62 |
| 63 // Makes the page visible to the user. |
| 64 void Show(CastWindowManager* window_manager); |
| 65 |
| 66 private: |
| 67 // WebContentsObserver implementation: |
| 68 void RenderProcessGone(base::TerminationStatus status) override; |
| 69 void RenderViewCreated(content::RenderViewHost* render_view_host) override; |
| 70 void DidFinishNavigation( |
| 71 content::NavigationHandle* navigation_handle) override; |
| 72 void DidFailLoad(content::RenderFrameHost* render_frame_host, |
| 73 const GURL& validated_url, |
| 74 int error_code, |
| 75 const base::string16& error_description, |
| 76 bool was_ignored_by_handler) override; |
| 77 void DidFirstVisuallyNonEmptyPaint() override; |
| 78 void DidStartNavigation( |
| 79 content::NavigationHandle* navigation_handle) override; |
| 80 void MediaStartedPlaying(const MediaPlayerInfo& media_info, |
| 81 const MediaPlayerId& id) override; |
| 82 void MediaStoppedPlaying(const MediaPlayerInfo& media_info, |
| 83 const MediaPlayerId& id) override; |
| 84 |
| 85 // WebContentsDelegate implementation: |
| 86 content::WebContents* OpenURLFromTab( |
| 87 content::WebContents* source, |
| 88 const content::OpenURLParams& params) override; |
| 89 void CloseContents(content::WebContents* source) override; |
| 90 void LoadingStateChanged(content::WebContents* source, |
| 91 bool to_different_document) override; |
| 92 void ActivateContents(content::WebContents* contents) override; |
| 93 #if defined(OS_ANDROID) |
| 94 base::android::ScopedJavaLocalRef<jobject> GetContentVideoViewEmbedder() |
| 95 override; |
| 96 #endif // defined(OS_ANDROID) |
| 97 |
| 98 void DelayedCloseContents(); |
| 99 |
| 100 Delegate* const delegate_; |
| 101 content::BrowserContext* const browser_context_; |
| 102 const scoped_refptr<content::SiteInstance> site_instance_; |
| 103 const bool transparent_; |
| 104 const std::unique_ptr<shell::CastContentWindow> window_; |
| 105 std::unique_ptr<content::WebContents> web_contents_; |
| 106 |
| 107 base::WeakPtrFactory<CastWebView> weak_factory_; |
| 108 |
| 109 DISALLOW_COPY_AND_ASSIGN(CastWebView); |
| 110 }; |
| 111 |
| 112 } // namespace chromecast |
| 113 |
| 114 #endif // CHROMECAST_BROWSER_CAST_WEB_VIEW_H_ |
OLD | NEW |