OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromecast/browser/android/cast_window_android.h" | 5 #include "chromecast/browser/android/cast_window_android.h" |
6 | 6 |
7 #include "base/message_loop/message_loop_proxy.h" | 7 #include "base/message_loop/message_loop_proxy.h" |
8 #include "chromecast/browser/android/cast_window_manager.h" | 8 #include "chromecast/browser/android/cast_window_manager.h" |
9 #include "chromecast/browser/cast_content_window.h" | |
9 #include "content/public/browser/devtools_agent_host.h" | 10 #include "content/public/browser/devtools_agent_host.h" |
10 #include "content/public/browser/navigation_controller.h" | 11 #include "content/public/browser/navigation_controller.h" |
11 #include "content/public/browser/navigation_entry.h" | 12 #include "content/public/browser/navigation_entry.h" |
12 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
13 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
14 #include "content/public/common/renderer_preferences.h" | 15 #include "content/public/common/renderer_preferences.h" |
15 #include "jni/CastWindowAndroid_jni.h" | 16 #include "jni/CastWindowAndroid_jni.h" |
16 | 17 |
17 namespace chromecast { | 18 namespace chromecast { |
18 namespace shell { | 19 namespace shell { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // The time (in milliseconds) we wait for after a page is closed (i.e. | 23 // The time (in milliseconds) we wait for after a page is closed (i.e. |
23 // after an app is stopped) before we delete the corresponding WebContents. | 24 // after an app is stopped) before we delete the corresponding WebContents. |
24 const int kWebContentsDestructionDelayInMs = 50; | 25 const int kWebContentsDestructionDelayInMs = 50; |
25 | 26 |
26 } // namespace | 27 } // namespace |
27 | 28 |
28 // static | 29 // static |
29 bool CastWindowAndroid::RegisterJni(JNIEnv* env) { | 30 bool CastWindowAndroid::RegisterJni(JNIEnv* env) { |
30 return RegisterNativesImpl(env); | 31 return RegisterNativesImpl(env); |
31 } | 32 } |
32 | 33 |
33 CastWindowAndroid::CastWindowAndroid(content::WebContents* web_contents) | |
34 : content::WebContentsObserver(web_contents), | |
35 weak_factory_(this) { | |
36 } | |
37 | |
38 CastWindowAndroid::~CastWindowAndroid() { | |
39 } | |
40 | |
41 // static | 34 // static |
42 CastWindowAndroid* CastWindowAndroid::CreateNewWindow( | 35 CastWindowAndroid* CastWindowAndroid::CreateNewWindow( |
43 content::BrowserContext* browser_context, | 36 content::BrowserContext* browser_context, |
44 const GURL& url) { | 37 const GURL& url) { |
45 content::WebContents::CreateParams create_params(browser_context); | 38 CastWindowAndroid* window = new CastWindowAndroid(browser_context); |
46 create_params.routing_id = MSG_ROUTING_NONE; | 39 window->Initialize(); |
47 content::WebContents* web_contents = | 40 |
48 content::WebContents::Create(create_params); | |
49 CastWindowAndroid* shell = CreateCastWindowAndroid( | |
50 web_contents, | |
51 create_params.initial_size); | |
52 if (!url.is_empty()) | 41 if (!url.is_empty()) |
53 shell->LoadURL(url); | 42 window->LoadURL(url); |
54 return shell; | 43 return window; |
55 } | 44 } |
56 | 45 |
57 // static | 46 CastWindowAndroid::CastWindowAndroid(content::BrowserContext* browser_context) |
58 CastWindowAndroid* CastWindowAndroid::CreateCastWindowAndroid( | 47 : browser_context_(browser_context), |
59 content::WebContents* web_contents, | 48 window_(new CastContentWindow), |
lcwu1
2015/02/04 00:28:31
Given that you renamed 'shell' to 'window' for Cas
gunsch
2015/02/04 00:38:36
Oof, the naming did get rough. Renamed a couple th
| |
60 const gfx::Size& initial_size) { | 49 weak_factory_(this) { |
61 CastWindowAndroid* shell = new CastWindowAndroid(web_contents); | 50 } |
51 | |
52 void CastWindowAndroid::Initialize() { | |
53 web_contents_ = window_->CreateWebContents(gfx::Size(), browser_context_); | |
54 web_contents_->SetDelegate(this); | |
55 content::WebContentsObserver::Observe(web_contents_.get()); | |
62 | 56 |
63 JNIEnv* env = base::android::AttachCurrentThread(); | 57 JNIEnv* env = base::android::AttachCurrentThread(); |
64 base::android::ScopedJavaLocalRef<jobject> shell_android( | 58 base::android::ScopedJavaLocalRef<jobject> window_android( |
65 CreateCastWindowView(shell)); | 59 CreateCastWindowView(this)); |
66 | 60 java_object_.Reset(env, window_android.Release()); |
67 shell->java_object_.Reset(env, shell_android.Release()); | |
68 shell->web_contents_.reset(web_contents); | |
69 web_contents->SetDelegate(shell); | |
70 | 61 |
71 Java_CastWindowAndroid_initFromNativeWebContents( | 62 Java_CastWindowAndroid_initFromNativeWebContents( |
72 env, shell->java_object_.obj(), web_contents->GetJavaWebContents().obj(), | 63 env, java_object_.obj(), web_contents_->GetJavaWebContents().obj(), |
73 web_contents->GetRenderProcessHost()->GetID()); | 64 web_contents_->GetRenderProcessHost()->GetID()); |
74 | 65 |
75 // Enabling hole-punching also requires runtime renderer preference | 66 // Enabling hole-punching also requires runtime renderer preference |
76 web_contents->GetMutableRendererPrefs()-> | 67 web_contents_->GetMutableRendererPrefs()-> |
77 use_video_overlay_for_embedded_encrypted_video = true; | 68 use_video_overlay_for_embedded_encrypted_video = true; |
78 web_contents->GetRenderViewHost()->SyncRendererPrefs(); | 69 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); |
70 } | |
79 | 71 |
80 return shell; | 72 CastWindowAndroid::~CastWindowAndroid() { |
81 } | 73 } |
82 | 74 |
83 void CastWindowAndroid::Close() { | 75 void CastWindowAndroid::Close() { |
84 // Close page first, which fires the window.unload event. The WebContents | 76 // Close page first, which fires the window.unload event. The WebContents |
85 // itself will be destroyed after browser-process has received renderer | 77 // itself will be destroyed after browser-process has received renderer |
86 // notification that the page is closed. | 78 // notification that the page is closed. |
87 web_contents_->GetRenderViewHost()->ClosePage(); | 79 web_contents_->GetRenderViewHost()->ClosePage(); |
88 } | 80 } |
89 | 81 |
90 void CastWindowAndroid::Destroy() { | 82 void CastWindowAndroid::Destroy() { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 contents->GetRenderViewHost()->Blur(); | 157 contents->GetRenderViewHost()->Blur(); |
166 } | 158 } |
167 | 159 |
168 void CastWindowAndroid::RenderProcessGone(base::TerminationStatus status) { | 160 void CastWindowAndroid::RenderProcessGone(base::TerminationStatus status) { |
169 LOG(ERROR) << "Render process gone: status=" << status; | 161 LOG(ERROR) << "Render process gone: status=" << status; |
170 Destroy(); | 162 Destroy(); |
171 } | 163 } |
172 | 164 |
173 } // namespace shell | 165 } // namespace shell |
174 } // namespace chromecast | 166 } // namespace chromecast |
OLD | NEW |