Chromium Code Reviews| 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 #include "chromecast/shell/browser/android/cast_window_android.h" | |
| 6 | |
| 7 #include "base/message_loop/message_loop.h" | |
| 8 #include "base/path_service.h" | |
| 9 #include "chromecast/shell/browser/android/cast_window_manager.h" | |
| 10 #include "content/public/browser/devtools_agent_host.h" | |
| 11 #include "content/public/browser/navigation_controller.h" | |
| 12 #include "content/public/browser/navigation_entry.h" | |
| 13 #include "content/public/browser/render_view_host.h" | |
| 14 #include "content/public/common/renderer_preferences.h" | |
| 15 #include "jni/CastWindowAndroid_jni.h" | |
| 16 | |
| 17 namespace chromecast { | |
| 18 namespace shell { | |
| 19 | |
| 20 // static | |
| 21 bool CastWindowAndroid::RegisterJni(JNIEnv* env) { | |
| 22 return RegisterNativesImpl(env); | |
| 23 } | |
| 24 | |
| 25 CastWindowAndroid::CastWindowAndroid(content::WebContents* web_contents) | |
| 26 : content::WebContentsObserver(web_contents) { | |
| 27 } | |
| 28 | |
| 29 CastWindowAndroid::~CastWindowAndroid() { | |
| 30 } | |
| 31 | |
| 32 // static | |
| 33 CastWindowAndroid* CastWindowAndroid::CreateNewWindow( | |
| 34 content::BrowserContext* browser_context, | |
| 35 const GURL& url) { | |
| 36 content::WebContents::CreateParams create_params(browser_context); | |
| 37 create_params.routing_id = MSG_ROUTING_NONE; | |
| 38 content::WebContents* web_contents = | |
| 39 content::WebContents::Create(create_params); | |
| 40 CastWindowAndroid* shell = CreateCastWindowAndroid( | |
| 41 web_contents, | |
| 42 create_params.initial_size); | |
| 43 if (!url.is_empty()) | |
| 44 shell->LoadURL(url); | |
| 45 return shell; | |
| 46 } | |
| 47 | |
| 48 // static | |
| 49 CastWindowAndroid* CastWindowAndroid::CreateCastWindowAndroid( | |
| 50 content::WebContents* web_contents, | |
| 51 const gfx::Size& initial_size) { | |
| 52 CastWindowAndroid* shell = new CastWindowAndroid(web_contents); | |
| 53 | |
| 54 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 55 base::android::ScopedJavaLocalRef<jobject> shell_android( | |
| 56 CreateCastWindowView(shell)); | |
| 57 | |
| 58 shell->java_object_.Reset(env, shell_android.Release()); | |
| 59 shell->web_contents_.reset(web_contents); | |
| 60 web_contents->SetDelegate(shell); | |
| 61 | |
| 62 Java_CastWindowAndroid_initFromNativeTabContents( | |
|
Yaron
2014/08/20 18:11:02
initFromNativeWebContents
gunsch
2014/08/22 22:44:30
Done.
| |
| 63 env, shell->java_object_.obj(), reinterpret_cast<jint>(web_contents)); | |
| 64 | |
| 65 // Enabling hole-punching also requires runtime renderer preference | |
| 66 web_contents->GetMutableRendererPrefs()-> | |
| 67 use_video_overlay_for_embedded_encrypted_video = true; | |
| 68 web_contents->GetRenderViewHost()->SyncRendererPrefs(); | |
| 69 | |
| 70 return shell; | |
| 71 } | |
| 72 | |
| 73 void CastWindowAndroid::Close() { | |
| 74 // Note: if multiple windows becomes supported, this may close other devtools | |
| 75 // sessions. | |
| 76 content::DevToolsAgentHost::DetachAllClients(); | |
| 77 CloseCastWindowView(java_object_.obj()); | |
| 78 delete this; | |
| 79 } | |
| 80 | |
| 81 void CastWindowAndroid::LoadURL(const GURL& url) { | |
| 82 content::NavigationController::LoadURLParams params(url); | |
| 83 params.transition_type = content::PageTransitionFromInt( | |
| 84 content::PAGE_TRANSITION_TYPED | | |
| 85 content::PAGE_TRANSITION_FROM_ADDRESS_BAR); | |
| 86 web_contents_->GetController().LoadURLWithParams(params); | |
| 87 web_contents_->Focus(); | |
| 88 } | |
| 89 | |
| 90 void CastWindowAndroid::AddNewContents(content::WebContents* source, | |
| 91 content::WebContents* new_contents, | |
| 92 WindowOpenDisposition disposition, | |
| 93 const gfx::Rect& initial_pos, | |
| 94 bool user_gesture, | |
| 95 bool* was_blocked) { | |
| 96 NOTIMPLEMENTED(); | |
| 97 if (was_blocked) { | |
| 98 *was_blocked = true; | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 void CastWindowAndroid::CloseContents(content::WebContents* source) { | |
| 103 DCHECK_EQ(source, web_contents_.get()); | |
| 104 Close(); | |
| 105 } | |
| 106 | |
| 107 bool CastWindowAndroid::CanOverscrollContent() const { | |
| 108 return false; | |
| 109 } | |
| 110 | |
| 111 bool CastWindowAndroid::AddMessageToConsole(content::WebContents* source, | |
| 112 int32 level, | |
| 113 const base::string16& message, | |
| 114 int32 line_no, | |
| 115 const base::string16& source_id) { | |
| 116 return false; | |
| 117 } | |
| 118 | |
| 119 void CastWindowAndroid::ActivateContents(content::WebContents* contents) { | |
| 120 DCHECK_EQ(contents, web_contents_.get()); | |
| 121 contents->GetRenderViewHost()->Focus(); | |
| 122 } | |
| 123 | |
| 124 void CastWindowAndroid::DeactivateContents(content::WebContents* contents) { | |
| 125 DCHECK_EQ(contents, web_contents_.get()); | |
| 126 contents->GetRenderViewHost()->Blur(); | |
| 127 } | |
| 128 | |
| 129 } // namespace shell | |
| 130 } // namespace chromecast | |
| OLD | NEW |