Chromium Code Reviews| 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_web_contents_observer.h" | 5 #include "chrome/browser/android/vr_shell/vr_web_contents_observer.h" |
| 6 | 6 |
| 7 #include "chrome/browser/android/vr_shell/ui_interface.h" | 7 #include "chrome/browser/android/vr_shell/ui_interface.h" |
| 8 #include "chrome/browser/ssl/security_state_tab_helper.h" | |
| 9 #include "components/security_state/core/security_state.h" | |
| 8 #include "content/public/browser/navigation_handle.h" | 10 #include "content/public/browser/navigation_handle.h" |
| 9 | 11 |
| 10 namespace vr_shell { | 12 namespace vr_shell { |
| 11 | 13 |
| 12 VrWebContentsObserver::VrWebContentsObserver(content::WebContents* web_contents, | 14 VrWebContentsObserver::VrWebContentsObserver(content::WebContents* web_contents, |
| 13 UiInterface* ui_interface) | 15 UiInterface* ui_interface) |
| 14 : WebContentsObserver(web_contents), | 16 : WebContentsObserver(web_contents), |
| 15 ui_interface_(ui_interface) {} | 17 ui_interface_(ui_interface) { |
| 18 ui_interface_->SetURL(web_contents->GetVisibleURL()); | |
| 19 SetSecurityLevel(); | |
| 20 } | |
| 16 | 21 |
| 17 VrWebContentsObserver::~VrWebContentsObserver() {} | 22 VrWebContentsObserver::~VrWebContentsObserver() {} |
| 18 | 23 |
| 19 void VrWebContentsObserver::SetUiInterface(UiInterface* ui_interface) { | 24 void VrWebContentsObserver::SetUiInterface(UiInterface* ui_interface) { |
| 20 ui_interface_ = ui_interface; | 25 ui_interface_ = ui_interface; |
| 21 } | 26 } |
| 22 | 27 |
| 23 void VrWebContentsObserver::DidStartLoading() { | 28 void VrWebContentsObserver::DidStartLoading() { |
| 24 ui_interface_->SetLoading(true); | 29 ui_interface_->SetLoading(true); |
| 25 } | 30 } |
| 26 | 31 |
| 27 void VrWebContentsObserver::DidStopLoading() { | 32 void VrWebContentsObserver::DidStopLoading() { |
| 28 ui_interface_->SetLoading(false); | 33 ui_interface_->SetLoading(false); |
| 29 } | 34 } |
| 30 | 35 |
| 31 void VrWebContentsObserver::DidStartNavigation( | 36 void VrWebContentsObserver::DidStartNavigation( |
| 32 content::NavigationHandle* navigation_handle) { | 37 content::NavigationHandle* navigation_handle) { |
| 33 ui_interface_->SetURL(navigation_handle->GetURL()); | 38 if (navigation_handle->IsInMainFrame()) { |
| 39 ui_interface_->SetURL(navigation_handle->GetURL()); | |
| 40 SetSecurityLevel(); | |
| 41 } | |
| 34 } | 42 } |
| 35 | 43 |
| 36 void VrWebContentsObserver::DidRedirectNavigation( | 44 void VrWebContentsObserver::DidRedirectNavigation( |
| 37 content::NavigationHandle* navigation_handle) { | 45 content::NavigationHandle* navigation_handle) { |
| 38 ui_interface_->SetURL(navigation_handle->GetURL()); | 46 if (navigation_handle->IsInMainFrame()) { |
| 47 ui_interface_->SetURL(navigation_handle->GetURL()); | |
| 48 SetSecurityLevel(); | |
| 49 } | |
| 39 } | 50 } |
| 40 | 51 |
| 41 void VrWebContentsObserver::DidFinishNavigation( | 52 void VrWebContentsObserver::DidFinishNavigation( |
| 42 content::NavigationHandle* navigation_handle) { | 53 content::NavigationHandle* navigation_handle) { |
| 43 ui_interface_->SetURL(navigation_handle->GetURL()); | 54 if (navigation_handle->IsInMainFrame()) { |
| 55 ui_interface_->SetURL(navigation_handle->GetURL()); | |
| 56 SetSecurityLevel(); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 void VrWebContentsObserver::SetSecurityLevel() { | |
| 61 const auto* helper = SecurityStateTabHelper::FromWebContents(web_contents()); | |
|
cjgrant
2016/11/29 16:33:52
dcheng@ and clamy@:
This bit of code works for de
| |
| 62 CHECK(helper); | |
| 63 security_state::SecurityInfo security_info; | |
| 64 helper->GetSecurityInfo(&security_info); | |
| 65 const security_state::SecurityLevel level = security_info.security_level; | |
| 66 | |
| 67 // TODO(cjgrant): Pass the level to the HTML UI instead. | |
| 68 if (level == security_state::SecurityLevel::EV_SECURE || | |
| 69 level == security_state::SecurityLevel::SECURE) { | |
| 70 ui_interface_->SetSecureOrigin(true); | |
| 71 } else { | |
| 72 ui_interface_->SetSecureOrigin(false); | |
| 73 } | |
| 44 } | 74 } |
| 45 | 75 |
| 46 void VrWebContentsObserver::DidToggleFullscreenModeForTab( | 76 void VrWebContentsObserver::DidToggleFullscreenModeForTab( |
| 47 bool entered_fullscreen, bool will_cause_resize) { | 77 bool entered_fullscreen, bool will_cause_resize) { |
| 48 // TODO(amp): Use will_cause_resize to signal ui of pending size changes. | 78 // TODO(amp): Use will_cause_resize to signal ui of pending size changes. |
| 49 int mode = ui_interface_->GetMode(); | 79 int mode = ui_interface_->GetMode(); |
| 50 if (entered_fullscreen && mode == UiInterface::Mode::STANDARD) { | 80 if (entered_fullscreen && mode == UiInterface::Mode::STANDARD) { |
| 51 ui_interface_->SetMode(UiInterface::Mode::CINEMA); | 81 ui_interface_->SetMode(UiInterface::Mode::CINEMA); |
| 52 } | 82 } |
| 53 if (!entered_fullscreen && mode == UiInterface::Mode::CINEMA) { | 83 if (!entered_fullscreen && mode == UiInterface::Mode::CINEMA) { |
| 54 ui_interface_->SetMode(UiInterface::Mode::STANDARD); | 84 ui_interface_->SetMode(UiInterface::Mode::STANDARD); |
| 55 } | 85 } |
| 56 } | 86 } |
| 57 | 87 |
| 58 } // namespace vr_shell | 88 } // namespace vr_shell |
| OLD | NEW |