OLD | NEW |
| (Empty) |
1 // Copyright 2014 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_SHELL_BROWSER_ANDROID_CAST_WINDOW_ANDROID_H_ | |
6 #define CHROMECAST_SHELL_BROWSER_ANDROID_CAST_WINDOW_ANDROID_H_ | |
7 | |
8 #include <jni.h> | |
9 #include <vector> | |
10 | |
11 #include "base/android/jni_string.h" | |
12 #include "base/android/scoped_java_ref.h" | |
13 #include "base/basictypes.h" | |
14 #include "base/callback_forward.h" | |
15 #include "base/command_line.h" | |
16 #include "base/macros.h" | |
17 #include "base/memory/scoped_ptr.h" | |
18 #include "base/memory/weak_ptr.h" | |
19 #include "build/build_config.h" | |
20 #include "content/public/browser/web_contents.h" | |
21 #include "content/public/browser/web_contents_delegate.h" | |
22 #include "content/public/browser/web_contents_observer.h" | |
23 #include "content/public/common/content_switches.h" | |
24 #include "ui/gfx/native_widget_types.h" | |
25 #include "ui/gfx/size.h" | |
26 | |
27 class GURL; | |
28 | |
29 namespace content { | |
30 class BrowserContext; | |
31 class SiteInstance; | |
32 class WebContents; | |
33 } // namespace content | |
34 | |
35 namespace chromecast { | |
36 namespace shell { | |
37 | |
38 class CastWindowAndroid : public content::WebContentsDelegate, | |
39 public content::WebContentsObserver { | |
40 public: | |
41 // Creates a new window and immediately loads the given URL. | |
42 static CastWindowAndroid* CreateNewWindow( | |
43 content::BrowserContext* browser_context, | |
44 const GURL& url); | |
45 | |
46 virtual ~CastWindowAndroid(); | |
47 | |
48 void LoadURL(const GURL& url); | |
49 // Calls RVH::ClosePage() and waits for acknowledgement before closing/ | |
50 // deleting the window. | |
51 void Close(); | |
52 // Destroys this window immediately. | |
53 void Destroy(); | |
54 | |
55 // Registers the JNI methods for CastWindowAndroid. | |
56 static bool RegisterJni(JNIEnv* env); | |
57 | |
58 // content::WebContentsDelegate implementation: | |
59 virtual void AddNewContents(content::WebContents* source, | |
60 content::WebContents* new_contents, | |
61 WindowOpenDisposition disposition, | |
62 const gfx::Rect& initial_pos, | |
63 bool user_gesture, | |
64 bool* was_blocked) override; | |
65 virtual void CloseContents(content::WebContents* source) override; | |
66 virtual bool CanOverscrollContent() const override; | |
67 virtual bool AddMessageToConsole(content::WebContents* source, | |
68 int32 level, | |
69 const base::string16& message, | |
70 int32 line_no, | |
71 const base::string16& source_id) override; | |
72 virtual void ActivateContents(content::WebContents* contents) override; | |
73 virtual void DeactivateContents(content::WebContents* contents) override; | |
74 | |
75 // content::WebContentsObserver implementation: | |
76 virtual void RenderProcessGone(base::TerminationStatus status) override; | |
77 | |
78 private: | |
79 explicit CastWindowAndroid(content::WebContents* web_contents); | |
80 | |
81 // Helper to create a new CastWindowAndroid given a newly created WebContents. | |
82 static CastWindowAndroid* CreateCastWindowAndroid( | |
83 content::WebContents* web_contents, | |
84 const gfx::Size& initial_size); | |
85 | |
86 base::android::ScopedJavaGlobalRef<jobject> java_object_; | |
87 scoped_ptr<content::WebContents> web_contents_; | |
88 | |
89 base::WeakPtrFactory<CastWindowAndroid> weak_factory_; | |
90 | |
91 DISALLOW_COPY_AND_ASSIGN(CastWindowAndroid); | |
92 }; | |
93 | |
94 } // namespace shell | |
95 } // namespace chromecast | |
96 | |
97 #endif // CHROMECAST_SHELL_BROWSER_ANDROID_CAST_WINDOW_ANDROID_H_ | |
OLD | NEW |