| 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 "chrome/browser/ui/views/frame/web_app_left_header_view_ash.h" | |
| 6 | |
| 7 #include "ash/common/frame/caption_buttons/frame_caption_button.h" | |
| 8 #include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h
" | |
| 9 #include "chrome/app/chrome_command_ids.h" | |
| 10 #include "chrome/browser/ssl/security_state_tab_helper.h" | |
| 11 #include "chrome/browser/ui/browser_commands.h" | |
| 12 #include "chrome/browser/ui/views/frame/browser_view.h" | |
| 13 #include "components/security_state/core/security_state.h" | |
| 14 #include "components/toolbar/toolbar_model.h" | |
| 15 #include "content/public/browser/navigation_entry.h" | |
| 16 #include "ui/gfx/vector_icons_public.h" | |
| 17 #include "ui/views/layout/box_layout.h" | |
| 18 | |
| 19 // static | |
| 20 const char WebAppLeftHeaderView::kViewClassName[] = "WebAppLeftHeaderView"; | |
| 21 | |
| 22 WebAppLeftHeaderView::WebAppLeftHeaderView(BrowserView* browser_view) | |
| 23 : browser_view_(browser_view) { | |
| 24 SetLayoutManager( | |
| 25 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | |
| 26 | |
| 27 back_button_ = | |
| 28 new ash::FrameCaptionButton(this, ash::CAPTION_BUTTON_ICON_BACK); | |
| 29 back_button_->SetImage(ash::CAPTION_BUTTON_ICON_BACK, | |
| 30 ash::FrameCaptionButton::ANIMATE_NO, | |
| 31 gfx::VectorIconId::WINDOW_CONTROL_BACK); | |
| 32 AddChildView(back_button_); | |
| 33 | |
| 34 location_icon_ = | |
| 35 new ash::FrameCaptionButton(this, ash::CAPTION_BUTTON_ICON_LOCATION); | |
| 36 AddChildView(location_icon_); | |
| 37 | |
| 38 Update(); | |
| 39 } | |
| 40 | |
| 41 WebAppLeftHeaderView::~WebAppLeftHeaderView() { | |
| 42 } | |
| 43 | |
| 44 void WebAppLeftHeaderView::Update() { | |
| 45 location_icon_->SetImage( | |
| 46 ash::CAPTION_BUTTON_ICON_LOCATION, ash::FrameCaptionButton::ANIMATE_NO, | |
| 47 browser_view_->browser()->toolbar_model()->GetVectorIcon()); | |
| 48 | |
| 49 back_button_->SetState( | |
| 50 chrome::IsCommandEnabled(browser_view_->browser(), IDC_BACK) | |
| 51 ? views::Button::STATE_NORMAL | |
| 52 : views::Button::STATE_DISABLED); | |
| 53 } | |
| 54 | |
| 55 void WebAppLeftHeaderView::SetPaintAsActive(bool active) { | |
| 56 // TODO(benwells): Check that the disabled and inactive states should be | |
| 57 // drawn in the same way. | |
| 58 back_button_->set_paint_as_active( | |
| 59 active && chrome::IsCommandEnabled(browser_view_->browser(), IDC_BACK)); | |
| 60 location_icon_->set_paint_as_active(active); | |
| 61 } | |
| 62 | |
| 63 views::View* WebAppLeftHeaderView::GetLocationIconView() const { | |
| 64 return location_icon_; | |
| 65 } | |
| 66 | |
| 67 const char* WebAppLeftHeaderView::GetClassName() const { | |
| 68 return kViewClassName; | |
| 69 } | |
| 70 | |
| 71 void WebAppLeftHeaderView::ButtonPressed(views::Button* sender, | |
| 72 const ui::Event& event) { | |
| 73 if (sender == back_button_) | |
| 74 chrome::ExecuteCommand(browser_view_->browser(), IDC_BACK); | |
| 75 else if (sender == location_icon_) | |
| 76 ShowWebsiteSettings(); | |
| 77 else | |
| 78 NOTREACHED(); | |
| 79 } | |
| 80 | |
| 81 void WebAppLeftHeaderView::ShowWebsiteSettings() const { | |
| 82 content::WebContents* tab = browser_view_->GetActiveWebContents(); | |
| 83 if (!tab) | |
| 84 return; | |
| 85 | |
| 86 // Important to use GetVisibleEntry to match what's showing in the title area. | |
| 87 content::NavigationEntry* nav_entry = tab->GetController().GetVisibleEntry(); | |
| 88 // The visible entry can be NULL in the case of window.open(""). | |
| 89 if (!nav_entry) | |
| 90 return; | |
| 91 | |
| 92 SecurityStateTabHelper* helper = SecurityStateTabHelper::FromWebContents(tab); | |
| 93 DCHECK(helper); | |
| 94 | |
| 95 security_state::SecurityInfo security_info; | |
| 96 helper->GetSecurityInfo(&security_info); | |
| 97 chrome::ShowWebsiteSettings(browser_view_->browser(), tab, | |
| 98 nav_entry->GetVirtualURL(), security_info); | |
| 99 } | |
| OLD | NEW |