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 |
| 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 // Begins the close process for this page (ie. triggering document.onunload). |
| 55 // A consumer of the class can be notified when the process has been finished |
| 56 // via Delegate::OnPageStopped(). |
| 57 void ClosePage(); |
| 58 |
| 59 // Makes the page visible to the user. |
| 60 void Show(); |
| 61 |
| 62 private: |
| 63 // WebContentsObserver implementation: |
| 64 void RenderProcessGone(base::TerminationStatus status) override; |
| 65 void RenderViewCreated(content::RenderViewHost* render_view_host) override; |
| 66 void DidFailProvisionalLoad(content::RenderFrameHost* render_frame_host, |
| 67 const GURL& validated_url, |
| 68 int error_code, |
| 69 const base::string16& error_description, |
| 70 bool was_ignored_by_handler) override; |
| 71 void DidFailLoad(content::RenderFrameHost* render_frame_host, |
| 72 const GURL& validated_url, |
| 73 int error_code, |
| 74 const base::string16& error_description, |
| 75 bool was_ignored_by_handler) override; |
| 76 void DidFirstVisuallyNonEmptyPaint() override; |
| 77 void MediaStartedPlaying(const MediaPlayerInfo& media_info, |
| 78 const MediaPlayerId& id) override; |
| 79 void MediaStoppedPlaying(const MediaPlayerInfo& media_info, |
| 80 const MediaPlayerId& id) override; |
| 81 |
| 82 // WebContentsDelegate implementation: |
| 83 content::WebContents* OpenURLFromTab( |
| 84 content::WebContents* source, |
| 85 const content::OpenURLParams& params) override; |
| 86 void CloseContents(content::WebContents* source) override; |
| 87 void LoadingStateChanged(content::WebContents* source, |
| 88 bool to_different_document) override; |
| 89 void ActivateContents(content::WebContents* contents) override; |
| 90 #if defined(OS_ANDROID) |
| 91 base::android::ScopedJavaLocalRef<jobject> GetContentVideoViewEmbedder() |
| 92 override; |
| 93 #endif // defined(OS_ANDROID) |
| 94 |
| 95 void DelayedCloseContents(); |
| 96 |
| 97 Delegate* const delegate_; |
| 98 content::BrowserContext* const browser_context_; |
| 99 const bool transparent_; |
| 100 const std::unique_ptr<shell::CastContentWindow> window_; |
| 101 std::unique_ptr<content::WebContents> web_contents_; |
| 102 |
| 103 base::WeakPtrFactory<CastWebView> weak_factory_; |
| 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(CastWebView); |
| 106 }; |
| 107 |
| 108 } // namespace chromecast |
| 109 |
| 110 #endif // CHROMECAST_BROWSER_CAST_WEB_VIEW_H_ |
OLD | NEW |