| OLD | NEW |
| 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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 } | 401 } |
| 402 | 402 |
| 403 void VrShell::UpdateScene(const base::ListValue* args) { | 403 void VrShell::UpdateScene(const base::ListValue* args) { |
| 404 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateScene, | 404 PostToGlThreadWhenReady(base::Bind(&VrShellGl::UpdateScene, |
| 405 gl_thread_->GetVrShellGl(), | 405 gl_thread_->GetVrShellGl(), |
| 406 base::Passed(args->CreateDeepCopy()))); | 406 base::Passed(args->CreateDeepCopy()))); |
| 407 } | 407 } |
| 408 | 408 |
| 409 void VrShell::DoUiAction(const UiAction action, | 409 void VrShell::DoUiAction(const UiAction action, |
| 410 const base::DictionaryValue* arguments) { | 410 const base::DictionaryValue* arguments) { |
| 411 // Actions that can be handled natively. |
| 411 switch (action) { | 412 switch (action) { |
| 412 case OMNIBOX_CONTENT: | 413 case OMNIBOX_CONTENT: |
| 413 html_interface_->HandleOmniboxInput(*arguments); | 414 html_interface_->HandleOmniboxInput(*arguments); |
| 414 return; | 415 return; |
| 415 case SET_CONTENT_PAUSED: { | 416 case SET_CONTENT_PAUSED: { |
| 416 bool paused; | 417 bool paused; |
| 417 CHECK(arguments->GetBoolean("paused", &paused)); | 418 CHECK(arguments->GetBoolean("paused", &paused)); |
| 418 SetContentPaused(paused); | 419 SetContentPaused(paused); |
| 419 return; | 420 return; |
| 420 } | 421 } |
| 421 default: | 422 case HISTORY_BACK: |
| 423 if (main_contents_ && main_contents_->IsFullscreen()) { |
| 424 main_contents_->ExitFullscreen(false); |
| 425 return; |
| 426 } |
| 427 // Otherwise handle in java. |
| 422 break; | 428 break; |
| 423 } | 429 case ZOOM_OUT: // Not handled yet. |
| 424 // TODO(mthiesse): Handles these in java through the Tab. | 430 case ZOOM_IN: // Not handled yet. |
| 425 if (!main_contents_) | 431 return; |
| 426 return; | |
| 427 content::NavigationController& controller = main_contents_->GetController(); | |
| 428 switch (action) { | |
| 429 case HISTORY_BACK: | |
| 430 if (main_contents_->IsFullscreen()) { | |
| 431 main_contents_->ExitFullscreen(false); | |
| 432 } else if (controller.CanGoBack()) { | |
| 433 controller.GoBack(); | |
| 434 } | |
| 435 break; | |
| 436 case HISTORY_FORWARD: | |
| 437 if (controller.CanGoForward()) | |
| 438 controller.GoForward(); | |
| 439 break; | |
| 440 case RELOAD: | |
| 441 controller.Reload(content::ReloadType::NORMAL, false); | |
| 442 break; | |
| 443 case LOAD_URL: { | |
| 444 std::string url_string; | |
| 445 CHECK(arguments->GetString("url", &url_string)); | |
| 446 GURL url(url_string); | |
| 447 // TODO(crbug.com/683344): Sanitize the URL and prefix, and pass the | |
| 448 // proper transition type down from the UI. | |
| 449 controller.LoadURL(url, content::Referrer(), | |
| 450 ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
| 451 std::string("")); | |
| 452 break; | |
| 453 } | |
| 454 #if defined(ENABLE_VR_SHELL_UI_DEV) | 432 #if defined(ENABLE_VR_SHELL_UI_DEV) |
| 455 case RELOAD_UI: | 433 case RELOAD_UI: |
| 456 ui_contents_->GetController().Reload(content::ReloadType::NORMAL, false); | 434 ui_contents_->GetController().Reload(content::ReloadType::NORMAL, false); |
| 457 html_interface_.reset(new UiInterface(UiInterface::Mode::STANDARD)); | 435 html_interface_.reset(new UiInterface(UiInterface::Mode::STANDARD)); |
| 458 SetUiState(); | 436 SetUiState(); |
| 459 vr_web_contents_observer_->SetUiInterface(html_interface_.get()); | 437 vr_web_contents_observer_->SetUiInterface(html_interface_.get()); |
| 438 return; |
| 439 #endif |
| 440 default: |
| 460 break; | 441 break; |
| 461 #endif | 442 } |
| 462 case ZOOM_OUT: // Not handled yet. | 443 // Actions that are handled in java. |
| 463 case ZOOM_IN: // Not handled yet. | 444 JNIEnv* env = base::android::AttachCurrentThread(); |
| 445 switch (action) { |
| 446 case HISTORY_BACK: |
| 447 Java_VrShellImpl_navigateBack(env, j_vr_shell_.obj()); |
| 464 break; | 448 break; |
| 449 case HISTORY_FORWARD: |
| 450 Java_VrShellImpl_navigateForward(env, j_vr_shell_.obj()); |
| 451 break; |
| 452 case RELOAD: |
| 453 Java_VrShellImpl_reload(env, j_vr_shell_.obj()); |
| 454 break; |
| 455 case LOAD_URL: { |
| 456 base::string16 url_string; |
| 457 CHECK(arguments->GetString("url", &url_string)); |
| 458 base::android::ScopedJavaLocalRef<jstring> string = |
| 459 base::android::ConvertUTF16ToJavaString(env, url_string); |
| 460 Java_VrShellImpl_loadURL(env, j_vr_shell_.obj(), string, |
| 461 ui::PageTransition::PAGE_TRANSITION_TYPED); |
| 462 break; |
| 463 } |
| 465 default: | 464 default: |
| 466 NOTREACHED(); | 465 NOTREACHED(); |
| 467 } | 466 } |
| 468 } | 467 } |
| 469 | 468 |
| 470 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, | 469 void VrShell::RenderViewHostChanged(content::RenderViewHost* old_host, |
| 471 content::RenderViewHost* new_host) { | 470 content::RenderViewHost* new_host) { |
| 472 new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT); | 471 new_host->GetWidget()->GetView()->SetBackgroundColor(SK_ColorTRANSPARENT); |
| 473 } | 472 } |
| 474 | 473 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 jboolean reprojected_rendering) { | 650 jboolean reprojected_rendering) { |
| 652 return reinterpret_cast<intptr_t>(new VrShell( | 651 return reinterpret_cast<intptr_t>(new VrShell( |
| 653 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), | 652 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), |
| 654 content::WebContents::FromJavaWebContents(ui_web_contents), | 653 content::WebContents::FromJavaWebContents(ui_web_contents), |
| 655 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, | 654 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, |
| 656 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), | 655 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), |
| 657 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); | 656 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); |
| 658 } | 657 } |
| 659 | 658 |
| 660 } // namespace vr_shell | 659 } // namespace vr_shell |
| OLD | NEW |