Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell.cc

Issue 2683953007: Support rendering Android Native Pages in VR Shell. (Closed)
Patch Set: Address comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/android/vr_shell/vr_shell.h" 5 #include "chrome/browser/android/vr_shell/vr_shell.h"
6 6
7 #include <android/native_window_jni.h> 7 #include <android/native_window_jni.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 using base::android::JavaRef; 48 using base::android::JavaRef;
49 49
50 namespace vr_shell { 50 namespace vr_shell {
51 51
52 namespace { 52 namespace {
53 vr_shell::VrShell* g_instance; 53 vr_shell::VrShell* g_instance;
54 54
55 static const char kVrShellUIURL[] = "chrome://vr-shell-ui"; 55 static const char kVrShellUIURL[] = "chrome://vr-shell-ui";
56 56
57 void SetIsInVR(content::WebContents* contents, bool is_in_vr) { 57 void SetIsInVR(content::WebContents* contents, bool is_in_vr) {
58 if (contents->GetRenderWidgetHostView()) 58 if (contents && contents->GetRenderWidgetHostView())
59 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr); 59 contents->GetRenderWidgetHostView()->SetIsInVR(is_in_vr);
60 } 60 }
61 61
62 } // namespace 62 } // namespace
63 63
64 VrShell::VrShell(JNIEnv* env, 64 VrShell::VrShell(JNIEnv* env,
65 jobject obj, 65 jobject obj,
66 content::WebContents* main_contents,
67 ui::WindowAndroid* content_window, 66 ui::WindowAndroid* content_window,
68 content::WebContents* ui_contents, 67 content::WebContents* ui_contents,
69 ui::WindowAndroid* ui_window, 68 ui::WindowAndroid* ui_window,
70 bool for_web_vr, 69 bool for_web_vr,
71 VrShellDelegate* delegate, 70 VrShellDelegate* delegate,
72 gvr_context* gvr_api, 71 gvr_context* gvr_api,
73 bool reprojected_rendering) 72 bool reprojected_rendering)
74 : WebContentsObserver(ui_contents), 73 : WebContentsObserver(ui_contents),
75 main_contents_(main_contents), 74 content_window_(content_window),
76 content_compositor_( 75 content_compositor_(
77 base::MakeUnique<VrCompositor>(content_window, false)), 76 base::MakeUnique<VrCompositor>(content_window_, false)),
78 ui_contents_(ui_contents), 77 ui_contents_(ui_contents),
79 ui_compositor_(base::MakeUnique<VrCompositor>(ui_window, true)), 78 ui_compositor_(base::MakeUnique<VrCompositor>(ui_window, true)),
80 delegate_provider_(delegate), 79 delegate_provider_(delegate),
81 metrics_helper_(base::MakeUnique<VrMetricsHelper>(main_contents_)),
82 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), 80 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
83 reprojected_rendering_(reprojected_rendering), 81 reprojected_rendering_(reprojected_rendering),
84 gvr_api_(gvr_api), 82 gvr_api_(gvr_api),
85 weak_ptr_factory_(this) { 83 weak_ptr_factory_(this) {
86 DCHECK(g_instance == nullptr); 84 DCHECK(g_instance == nullptr);
87 g_instance = this; 85 g_instance = this;
88 j_vr_shell_.Reset(env, obj); 86 j_vr_shell_.Reset(env, obj);
89 87
90 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_);
91 ui_input_manager_ = base::MakeUnique<VrInputManager>(ui_contents_); 88 ui_input_manager_ = base::MakeUnique<VrInputManager>(ui_contents_);
92
93 content_compositor_->SetLayer(main_contents_);
94 ui_compositor_->SetLayer(ui_contents_); 89 ui_compositor_->SetLayer(ui_contents_);
95 90
96 gl_thread_ = base::MakeUnique<VrGLThread>( 91 gl_thread_ = base::MakeUnique<VrGLThread>(
97 weak_ptr_factory_.GetWeakPtr(), delegate_provider_->GetWeakPtr(), 92 weak_ptr_factory_.GetWeakPtr(), delegate_provider_->GetWeakPtr(),
98 main_thread_task_runner_, gvr_api, for_web_vr, reprojected_rendering_); 93 main_thread_task_runner_, gvr_api, for_web_vr, reprojected_rendering_);
99 94
100 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0); 95 base::Thread::Options options(base::MessageLoop::TYPE_DEFAULT, 0);
101 options.priority = base::ThreadPriority::DISPLAY; 96 options.priority = base::ThreadPriority::DISPLAY;
102 gl_thread_->StartWithOptions(options); 97 gl_thread_->StartWithOptions(options);
103 98
104 if (for_web_vr)
105 metrics_helper_->SetWebVREnabled(true);
106 html_interface_ = base::MakeUnique<UiInterface>( 99 html_interface_ = base::MakeUnique<UiInterface>(
107 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD, 100 for_web_vr ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD);
108 main_contents_->IsFullscreen());
109 vr_web_contents_observer_ = base::MakeUnique<VrWebContentsObserver>(
110 main_contents_, html_interface_.get(), this);
111
112 SetIsInVR(main_contents_, true);
113 } 101 }
114 102
115 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { 103 void VrShell::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) {
116 delete this; 104 delete this;
117 } 105 }
118 106
119 void VrShell::SwapContents(JNIEnv* env, const JavaParamRef<jobject>& obj, 107 void VrShell::SwapContents(JNIEnv* env, const JavaParamRef<jobject>& obj,
120 const JavaParamRef<jobject>& web_contents) { 108 const JavaParamRef<jobject>& web_contents) {
121 SetIsInVR(main_contents_, false);
122 content::WebContents* contents = 109 content::WebContents* contents =
123 content::WebContents::FromJavaWebContents(web_contents); 110 content::WebContents::FromJavaWebContents(web_contents);
111 if (contents == main_contents_)
112 return;
113
114 SetIsInVR(main_contents_, false);
115
124 main_contents_ = contents; 116 main_contents_ = contents;
117 content_compositor_->SetLayer(main_contents_);
118 SetIsInVR(main_contents_, true);
bshe 2017/02/10 20:15:44 if (main_contents_) before this line?
mthiesse 2017/02/13 15:27:35 No, we just do the check inside SetIsInVR
119 ContentFrameWasResized(false /* unused */);
120 SetUiState();
121
122 if (!main_contents_) {
123 content_input_manager_ = nullptr;
124 vr_web_contents_observer_ = nullptr;
125 metrics_helper_ = nullptr;
126 return;
127 }
125 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_); 128 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_);
126 content_compositor_->SetLayer(main_contents_);
127 vr_web_contents_observer_ = base::MakeUnique<VrWebContentsObserver>( 129 vr_web_contents_observer_ = base::MakeUnique<VrWebContentsObserver>(
128 main_contents_, html_interface_.get(), this); 130 main_contents_, html_interface_.get(), this);
129 SetIsInVR(main_contents_, true);
130
131 // TODO(billorr): Make VrMetricsHelper tab-aware and able to track multiple 131 // TODO(billorr): Make VrMetricsHelper tab-aware and able to track multiple
132 // tabs. crbug.com/684661 132 // tabs. crbug.com/684661
133 metrics_helper_ = base::MakeUnique<VrMetricsHelper>(main_contents_); 133 metrics_helper_ = base::MakeUnique<VrMetricsHelper>(main_contents_);
134 metrics_helper_->SetVRActive(true); 134 metrics_helper_->SetVRActive(true);
135 metrics_helper_->SetWebVREnabled(webvr_mode_); 135 metrics_helper_->SetWebVREnabled(webvr_mode_);
136 } 136 }
137 137
138 void VrShell::SetUiState() {
139 if (!main_contents_) {
140 // TODO(mthiesse): Properly handle native page URLs.
bshe 2017/02/10 20:15:44 nit: file a bug or reference to existing bug?
mthiesse 2017/02/13 15:27:35 Done.
141 html_interface_->SetURL(GURL());
142 html_interface_->SetLoading(false);
143 html_interface_->SetFullscreen(false);
144 } else {
145 html_interface_->SetURL(main_contents_->GetVisibleURL());
146 html_interface_->SetLoading(main_contents_->IsLoading());
147 html_interface_->SetFullscreen(main_contents_->IsFullscreen());
148 }
149 }
150
138 void VrShell::LoadUIContent(JNIEnv* env, const JavaParamRef<jobject>& obj) { 151 void VrShell::LoadUIContent(JNIEnv* env, const JavaParamRef<jobject>& obj) {
139 GURL url(kVrShellUIURL); 152 GURL url(kVrShellUIURL);
140 ui_contents_->GetController().LoadURL( 153 ui_contents_->GetController().LoadURL(
141 url, content::Referrer(), 154 url, content::Referrer(),
142 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string("")); 155 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string(""));
143 } 156 }
144 157
145 bool RegisterVrShell(JNIEnv* env) { 158 bool RegisterVrShell(JNIEnv* env) {
146 return RegisterNativesImpl(env); 159 return RegisterNativesImpl(env);
147 } 160 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 gl_thread_->task_runner()->PostTask( 208 gl_thread_->task_runner()->PostTask(
196 FROM_HERE, 209 FROM_HERE,
197 base::Bind(&VrShellGl::OnTriggerEvent, gl_thread_->GetVrShellGl())); 210 base::Bind(&VrShellGl::OnTriggerEvent, gl_thread_->GetVrShellGl()));
198 } 211 }
199 212
200 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) { 213 void VrShell::OnPause(JNIEnv* env, const JavaParamRef<jobject>& obj) {
201 gl_thread_->task_runner()->PostTask( 214 gl_thread_->task_runner()->PostTask(
202 FROM_HERE, base::Bind(&VrShellGl::OnPause, gl_thread_->GetVrShellGl())); 215 FROM_HERE, base::Bind(&VrShellGl::OnPause, gl_thread_->GetVrShellGl()));
203 216
204 // exit vr session 217 // exit vr session
205 metrics_helper_->SetVRActive(false); 218 if (metrics_helper_)
bshe 2017/02/10 20:15:44 does this mean we may miss recording the metrics?
mthiesse 2017/02/13 15:27:36 Yes, when on a native page.
219 metrics_helper_->SetVRActive(false);
206 SetIsInVR(main_contents_, false); 220 SetIsInVR(main_contents_, false);
207 } 221 }
208 222
209 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) { 223 void VrShell::OnResume(JNIEnv* env, const JavaParamRef<jobject>& obj) {
210 gl_thread_->task_runner()->PostTask( 224 gl_thread_->task_runner()->PostTask(
211 FROM_HERE, base::Bind(&VrShellGl::OnResume, gl_thread_->GetVrShellGl())); 225 FROM_HERE, base::Bind(&VrShellGl::OnResume, gl_thread_->GetVrShellGl()));
212 226
213 metrics_helper_->SetVRActive(true); 227 if (metrics_helper_)
228 metrics_helper_->SetVRActive(true);
214 SetIsInVR(main_contents_, true); 229 SetIsInVR(main_contents_, true);
215 } 230 }
216 231
217 void VrShell::SetSurface(JNIEnv* env, 232 void VrShell::SetSurface(JNIEnv* env,
218 const JavaParamRef<jobject>& obj, 233 const JavaParamRef<jobject>& obj,
219 const JavaParamRef<jobject>& surface) { 234 const JavaParamRef<jobject>& surface) {
220 CHECK(!reprojected_rendering_); 235 CHECK(!reprojected_rendering_);
221 gfx::AcceleratedWidget window = 236 gfx::AcceleratedWidget window =
222 ANativeWindow_fromSurface(base::android::AttachCurrentThread(), surface); 237 ANativeWindow_fromSurface(base::android::AttachCurrentThread(), surface);
223 PostToGlThreadWhenReady(base::Bind(&VrShellGl::InitializeGl, 238 PostToGlThreadWhenReady(base::Bind(&VrShellGl::InitializeGl,
224 gl_thread_->GetVrShellGl(), 239 gl_thread_->GetVrShellGl(),
225 base::Unretained(window))); 240 base::Unretained(window)));
226 } 241 }
227 242
228 base::WeakPtr<VrShell> VrShell::GetWeakPtr( 243 base::WeakPtr<VrShell> VrShell::GetWeakPtr(
229 const content::WebContents* web_contents) { 244 const content::WebContents* web_contents) {
230 // Ensure that the WebContents requesting the VrShell instance is the one 245 // Ensure that the WebContents requesting the VrShell instance is the one
231 // we created. 246 // we created.
232 if (g_instance != nullptr && g_instance->ui_contents_ == web_contents) 247 if (g_instance != nullptr && g_instance->ui_contents_ == web_contents)
233 return g_instance->weak_ptr_factory_.GetWeakPtr(); 248 return g_instance->weak_ptr_factory_.GetWeakPtr();
234 return base::WeakPtr<VrShell>(nullptr); 249 return base::WeakPtr<VrShell>(nullptr);
235 } 250 }
236 251
237 void VrShell::OnDomContentsLoaded() { 252 void VrShell::OnDomContentsLoaded() {
238 html_interface_->SetURL(main_contents_->GetVisibleURL()); 253 SetUiState();
239 html_interface_->SetLoading(main_contents_->IsLoading());
240 html_interface_->OnDomContentsLoaded(); 254 html_interface_->OnDomContentsLoaded();
241 } 255 }
242 256
243 void VrShell::SetWebVrMode(JNIEnv* env, 257 void VrShell::SetWebVrMode(JNIEnv* env,
244 const base::android::JavaParamRef<jobject>& obj, 258 const base::android::JavaParamRef<jobject>& obj,
245 bool enabled) { 259 bool enabled) {
246 webvr_mode_ = enabled; 260 webvr_mode_ = enabled;
247 metrics_helper_->SetWebVREnabled(enabled); 261 if (metrics_helper_)
262 metrics_helper_->SetWebVREnabled(enabled);
248 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetWebVrMode, 263 PostToGlThreadWhenReady(base::Bind(&VrShellGl::SetWebVrMode,
249 gl_thread_->GetVrShellGl(), enabled)); 264 gl_thread_->GetVrShellGl(), enabled));
250 html_interface_->SetMode( 265 html_interface_->SetMode(
251 enabled ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD); 266 enabled ? UiInterface::Mode::WEB_VR : UiInterface::Mode::STANDARD);
252 } 267 }
253 268
254 void VrShell::OnLoadProgressChanged(JNIEnv* env, 269 void VrShell::OnLoadProgressChanged(JNIEnv* env,
255 const JavaParamRef<jobject>& obj, 270 const JavaParamRef<jobject>& obj,
256 double progress) { 271 double progress) {
257 html_interface_->SetLoadProgress(progress); 272 html_interface_->SetLoadProgress(progress);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } 332 }
318 333
319 void VrShell::CreateVRDisplayInfo( 334 void VrShell::CreateVRDisplayInfo(
320 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback, 335 const base::Callback<void(device::mojom::VRDisplayInfoPtr)>& callback,
321 uint32_t device_id) { 336 uint32_t device_id) {
322 PostToGlThreadWhenReady(base::Bind(&VrShellGl::CreateVRDisplayInfo, 337 PostToGlThreadWhenReady(base::Bind(&VrShellGl::CreateVRDisplayInfo,
323 gl_thread_->GetVrShellGl(), 338 gl_thread_->GetVrShellGl(),
324 callback, device_id)); 339 callback, device_id));
325 } 340 }
326 341
327 void VrShell::SurfacesChanged(jobject content_surface, jobject ui_surface) { 342 base::android::ScopedJavaGlobalRef<jobject> VrShell::TakeContentSurface(
328 content_compositor_->SurfaceChanged(content_surface); 343 JNIEnv* env,
329 ui_compositor_->SurfaceChanged(ui_surface); 344 const JavaParamRef<jobject>& obj) {
345 content_compositor_->SurfaceChanged(nullptr);
346 base::android::ScopedJavaGlobalRef<jobject> surface(env, content_surface_);
347 content_surface_ = nullptr;
348 return surface;
349 }
350
351 void VrShell::RestoreContentSurface(JNIEnv* env,
352 const JavaParamRef<jobject>& obj) {
353 PostToGlThreadWhenReady(
354 base::Bind(&VrShellGl::CreateContentSurface, gl_thread_->GetVrShellGl()));
355 }
356
357 void VrShell::UiSurfaceChanged(jobject surface) {
358 ui_compositor_->SurfaceChanged(surface);
359 }
360
361 void VrShell::ContentSurfaceChanged(jobject surface) {
362 content_surface_ = surface;
363 content_compositor_->SurfaceChanged(surface);
364 JNIEnv* env = base::android::AttachCurrentThread();
365 Java_VrShellImpl_contentSurfaceCreated(env, j_vr_shell_.obj());
bshe 2017/02/10 20:15:44 I am not sure I understand correctly here. So cont
mthiesse 2017/02/13 15:27:35 We can't just pass the surface up as a parameter b
330 } 366 }
331 367
332 void VrShell::GvrDelegateReady() { 368 void VrShell::GvrDelegateReady() {
333 delegate_provider_->SetDelegate(this, gvr_api_); 369 delegate_provider_->SetDelegate(this, gvr_api_);
334 } 370 }
335 371
336 void VrShell::AppButtonPressed() { 372 void VrShell::AppButtonPressed() {
337 #if defined(ENABLE_VR_SHELL) 373 #if defined(ENABLE_VR_SHELL)
338 html_interface_->HandleAppButtonClicked(); 374 html_interface_->HandleAppButtonClicked();
339 #endif 375 #endif
(...skipping 24 matching lines...) Expand all
364 } 400 }
365 401
366 void VrShell::UpdateScene(const base::ListValue* args) { 402 void VrShell::UpdateScene(const base::ListValue* args) {
367 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateScene, 403 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateScene,
368 gl_thread_->GetVrShellGl(), 404 gl_thread_->GetVrShellGl(),
369 base::Passed(args->CreateDeepCopy()))); 405 base::Passed(args->CreateDeepCopy())));
370 } 406 }
371 407
372 void VrShell::DoUiAction(const UiAction action, 408 void VrShell::DoUiAction(const UiAction action,
373 const base::DictionaryValue* arguments) { 409 const base::DictionaryValue* arguments) {
410 switch (action) {
411 case OMNIBOX_CONTENT:
bshe 2017/02/10 20:15:44 braces here too? Or remove brances at 414
cjgrant 2017/02/10 20:20:22 The braces on 414 keep "bool paused" in the scope
mthiesse 2017/02/13 15:27:35 Leaving braces as-is.
bshe 2017/02/13 15:56:11 It is not a blocker. It is a suggestion to keep st
412 html_interface_->HandleOmniboxInput(*arguments);
413 return;
414 case SET_CONTENT_PAUSED: {
415 bool paused;
416 CHECK(arguments->GetBoolean("paused", &paused));
417 SetContentPaused(paused);
418 return;
419 }
420 default:
421 break;
422 }
423 // TODO(mthiesse): Handles these in java through the Tab.
424 if (!main_contents_)
425 return;
bshe 2017/02/10 20:15:44 Does this mean we can't use the navigate controls
mthiesse 2017/02/13 15:27:35 No need for a separate bug I think, this is part o
374 content::NavigationController& controller = main_contents_->GetController(); 426 content::NavigationController& controller = main_contents_->GetController();
375 switch (action) { 427 switch (action) {
376 case HISTORY_BACK: 428 case HISTORY_BACK:
377 if (main_contents_->IsFullscreen()) { 429 if (main_contents_->IsFullscreen()) {
378 main_contents_->ExitFullscreen(false); 430 main_contents_->ExitFullscreen(false);
379 } else if (controller.CanGoBack()) { 431 } else if (controller.CanGoBack()) {
380 controller.GoBack(); 432 controller.GoBack();
381 } 433 }
382 break; 434 break;
383 case HISTORY_FORWARD: 435 case HISTORY_FORWARD:
384 if (controller.CanGoForward()) 436 if (controller.CanGoForward())
385 controller.GoForward(); 437 controller.GoForward();
386 break; 438 break;
387 case RELOAD: 439 case RELOAD:
388 controller.Reload(content::ReloadType::NORMAL, false); 440 controller.Reload(content::ReloadType::NORMAL, false);
389 break; 441 break;
390 case LOAD_URL: { 442 case LOAD_URL: {
391 std::string url_string; 443 std::string url_string;
392 CHECK(arguments->GetString("url", &url_string)); 444 CHECK(arguments->GetString("url", &url_string));
393 GURL url(url_string); 445 GURL url(url_string);
394 // TODO(crbug.com/683344): Sanitize the URL and prefix, and pass the 446 // TODO(crbug.com/683344): Sanitize the URL and prefix, and pass the
395 // proper transition type down from the UI. 447 // proper transition type down from the UI.
396 controller.LoadURL(url, content::Referrer(), 448 controller.LoadURL(url, content::Referrer(),
397 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, 449 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL,
398 std::string("")); 450 std::string(""));
399 break; 451 break;
400 } 452 }
401 case OMNIBOX_CONTENT:
402 html_interface_->HandleOmniboxInput(*arguments);
403 break;
404 case SET_CONTENT_PAUSED: {
405 bool paused;
406 CHECK(arguments->GetBoolean("paused", &paused));
407 SetContentPaused(paused);
408 break;
409 }
410 #if defined(ENABLE_VR_SHELL_UI_DEV) 453 #if defined(ENABLE_VR_SHELL_UI_DEV)
411 case RELOAD_UI: 454 case RELOAD_UI:
412 ui_contents_->GetController().Reload(content::ReloadType::NORMAL, false); 455 ui_contents_->GetController().Reload(content::ReloadType::NORMAL, false);
413 html_interface_.reset(new UiInterface(UiInterface::Mode::STANDARD, 456 html_interface_.reset(new UiInterface(UiInterface::Mode::STANDARD));
414 main_contents_->IsFullscreen())); 457 SetUiState();
415 vr_web_contents_observer_->SetUiInterface(html_interface_.get()); 458 vr_web_contents_observer_->SetUiInterface(html_interface_.get());
416 break; 459 break;
417 #endif 460 #endif
418 case ZOOM_OUT: // Not handled yet. 461 case ZOOM_OUT: // Not handled yet.
419 case ZOOM_IN: // Not handled yet. 462 case ZOOM_IN: // Not handled yet.
420 break; 463 break;
421 default: 464 default:
422 NOTREACHED(); 465 NOTREACHED();
423 } 466 }
424 } 467 }
425 468
426 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, 469 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host,
427 content::RenderViewHost* new_host) { 470 content::RenderViewHost* new_host) {
428 new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT); 471 new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT);
429 } 472 }
430 473
431 void VrShell::MainFrameWasResized(bool width_changed) { 474 void VrShell::MainFrameWasResized(bool width_changed) {
432 display::Display display = display::Screen::GetScreen() 475 display::Display display = display::Screen::GetScreen()
433 ->GetDisplayNearestWindow(ui_contents_->GetNativeView()); 476 ->GetDisplayNearestWindow(ui_contents_->GetNativeView());
434 PostToGlThreadWhenReady( 477 PostToGlThreadWhenReady(
435 base::Bind(&VrShellGl::UIBoundsChanged, gl_thread_->GetVrShellGl(), 478 base::Bind(&VrShellGl::UIBoundsChanged, gl_thread_->GetVrShellGl(),
436 display.size().width(), display.size().height())); 479 display.size().width(), display.size().height()));
437 } 480 }
438 481
439 void VrShell::ContentFrameWasResized(bool width_changed) { 482 void VrShell::ContentFrameWasResized(bool width_changed) {
440 display::Display display = display::Screen::GetScreen() 483 display::Display display =
441 ->GetDisplayNearestWindow(main_contents_->GetNativeView()); 484 display::Screen::GetScreen()->GetDisplayNearestWindow(content_window_);
442 PostToGlThreadWhenReady( 485 PostToGlThreadWhenReady(
443 base::Bind(&VrShellGl::ContentBoundsChanged, gl_thread_->GetVrShellGl(), 486 base::Bind(&VrShellGl::ContentBoundsChanged, gl_thread_->GetVrShellGl(),
444 display.size().width(), display.size().height())); 487 display.size().width(), display.size().height()));
445 } 488 }
446 489
447 void VrShell::WebContentsDestroyed() { 490 void VrShell::WebContentsDestroyed() {
448 ui_input_manager_.reset(); 491 ui_input_manager_.reset();
449 ui_contents_ = nullptr; 492 ui_contents_ = nullptr;
450 // TODO(mthiesse): Handle web contents being destroyed. 493 // TODO(mthiesse): Handle web contents being destroyed.
451 ForceExitVr(); 494 ForceExitVr();
452 } 495 }
453 496
454 void VrShell::ContentWebContentsDestroyed() { 497 void VrShell::ContentWebContentsDestroyed() {
455 content_input_manager_.reset(); 498 content_input_manager_.reset();
456 main_contents_ = nullptr; 499 main_contents_ = nullptr;
457 // TODO(mthiesse): Handle web contents being destroyed. 500 // TODO(mthiesse): Handle web contents being destroyed.
458 ForceExitVr(); 501 ForceExitVr();
459 } 502 }
460 503
461 void VrShell::ContentWasHidden() { 504 void VrShell::ContentWasHidden() {
462 // Ensure we don't continue sending input to it. 505 // Ensure we don't continue sending input to it.
463 content_input_manager_ = nullptr; 506 content_input_manager_ = nullptr;
464 } 507 }
465 508
466 void VrShell::ContentWasShown() { 509 void VrShell::ContentWasShown() {
467 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_); 510 if (main_contents_)
511 content_input_manager_ = base::MakeUnique<VrInputManager>(main_contents_);
468 } 512 }
469 513
470 void VrShell::ForceExitVr() { 514 void VrShell::ForceExitVr() {
471 JNIEnv* env = base::android::AttachCurrentThread(); 515 JNIEnv* env = base::android::AttachCurrentThread();
472 Java_VrShellImpl_forceExitVr(env, j_vr_shell_.obj()); 516 Java_VrShellImpl_forceExitVr(env, j_vr_shell_.obj());
473 } 517 }
474 518
475 void VrShell::OnVRVsyncProviderRequest( 519 void VrShell::OnVRVsyncProviderRequest(
476 device::mojom::VRVSyncProviderRequest request) { 520 device::mojom::VRVSyncProviderRequest request) {
477 PostToGlThreadWhenReady(base::Bind(&VrShellGl::OnRequest, 521 PostToGlThreadWhenReady(base::Bind(&VrShellGl::OnRequest,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 eye_params->offset[2] = -eye_mat.m[2][3]; 632 eye_params->offset[2] = -eye_mat.m[2][3];
589 } 633 }
590 634
591 return device; 635 return device;
592 } 636 }
593 637
594 // ---------------------------------------------------------------------------- 638 // ----------------------------------------------------------------------------
595 // Native JNI methods 639 // Native JNI methods
596 // ---------------------------------------------------------------------------- 640 // ----------------------------------------------------------------------------
597 641
598 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj, 642 jlong Init(JNIEnv* env,
599 const JavaParamRef<jobject>& content_web_contents, 643 const JavaParamRef<jobject>& obj,
644 const JavaParamRef<jobject>& ui_web_contents,
600 jlong content_window_android, 645 jlong content_window_android,
601 const JavaParamRef<jobject>& ui_web_contents, 646 jlong ui_window_android,
602 jlong ui_window_android, jboolean for_web_vr, 647 jboolean for_web_vr,
603 const base::android::JavaParamRef<jobject>& delegate, 648 const base::android::JavaParamRef<jobject>& delegate,
604 jlong gvr_api, jboolean reprojected_rendering) { 649 jlong gvr_api,
650 jboolean reprojected_rendering) {
605 return reinterpret_cast<intptr_t>(new VrShell( 651 return reinterpret_cast<intptr_t>(new VrShell(
606 env, obj, content::WebContents::FromJavaWebContents(content_web_contents), 652 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android),
607 reinterpret_cast<ui::WindowAndroid*>(content_window_android),
608 content::WebContents::FromJavaWebContents(ui_web_contents), 653 content::WebContents::FromJavaWebContents(ui_web_contents),
609 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), 654 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr,
610 for_web_vr, VrShellDelegate::GetNativeVrShellDelegate(env, delegate), 655 VrShellDelegate::GetNativeVrShellDelegate(env, delegate),
611 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 656 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
612 } 657 }
613 658
614 } // namespace vr_shell 659 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698