| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/views/page_info/page_info_bubble_view.h" | 5 #include "chrome/browser/ui/views/page_info/page_info_bubble_view.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" | 9 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
| 10 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" | 10 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 Profile* profile, | 37 Profile* profile, |
| 38 content::WebContents* web_contents) | 38 content::WebContents* web_contents) |
| 39 : view_(nullptr), | 39 : view_(nullptr), |
| 40 parent_(parent), | 40 parent_(parent), |
| 41 profile_(profile), | 41 profile_(profile), |
| 42 web_contents_(web_contents) { | 42 web_contents_(web_contents) { |
| 43 CreateView(); | 43 CreateView(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void CreateView() { | 46 void CreateView() { |
| 47 if (view_) | 47 if (view_) { |
| 48 view_->GetWidget()->CloseNow(); | 48 view_->GetWidget()->CloseNow(); |
| 49 } |
| 49 | 50 |
| 50 security_state::SecurityInfo security_info; | 51 security_state::SecurityInfo security_info; |
| 51 views::View* anchor_view = nullptr; | 52 views::View* anchor_view = nullptr; |
| 52 view_ = new PageInfoBubbleView(anchor_view, parent_, profile_, | 53 view_ = new PageInfoBubbleView(anchor_view, parent_, profile_, |
| 53 web_contents_, GURL(kUrl), security_info); | 54 web_contents_, GURL(kUrl), security_info); |
| 54 } | 55 } |
| 55 | 56 |
| 56 PageInfoBubbleView* view() { return view_; } | 57 PageInfoBubbleView* view() { return view_; } |
| 57 views::View* permissions_view() { return view_->permissions_view_; } | 58 views::View* permissions_view() { return view_->permissions_view_; } |
| 58 | 59 |
| 59 PermissionSelectorRow* GetPermissionSelectorAt(int index) { | 60 PermissionSelectorRow* GetPermissionSelectorAt(int index) { |
| 60 return view_->selector_rows_[index].get(); | 61 return view_->selector_rows_[index].get(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 // Returns the permission label text of the |index|th permission selector row. | 64 // Returns the permission label text of the |index|th permission selector row. |
| 64 // This function returns an empty string if the permission selector row's | 65 // This function returns an empty string if the permission selector row's |
| 65 // |label_| element isn't actually a |views::Label|. | 66 // |label_| element isn't actually a |views::Label|. |
| 66 base::string16 GetPermissionLabelTextAt(int index) { | 67 base::string16 GetPermissionLabelTextAt(int index) { |
| 67 views::View* view = GetPermissionSelectorAt(index)->label_; | 68 views::View* view = GetPermissionSelectorAt(index)->label_; |
| 68 if (view->GetClassName() == views::Label::kViewClassName) | 69 if (view->GetClassName() == views::Label::kViewClassName) { |
| 69 return static_cast<views::Label*>(view)->text(); | 70 return static_cast<views::Label*>(view)->text(); |
| 71 } |
| 70 return base::string16(); | 72 return base::string16(); |
| 71 } | 73 } |
| 72 | 74 |
| 73 base::string16 GetPermissionButtonTextAt(int index) { | 75 base::string16 GetPermissionButtonTextAt(int index) { |
| 74 views::View* view = GetPermissionSelectorAt(index)->button(); | 76 views::View* view = GetPermissionSelectorAt(index)->button(); |
| 75 if (view->GetClassName() == views::MenuButton::kViewClassName) { | 77 if (view->GetClassName() == views::MenuButton::kViewClassName) { |
| 76 return static_cast<views::MenuButton*>(view)->GetText(); | 78 return static_cast<views::MenuButton*>(view)->GetText(); |
| 77 } else if (view->GetClassName() == views::Combobox::kViewClassName) { | 79 } else if (view->GetClassName() == views::Combobox::kViewClassName) { |
| 78 views::Combobox* combobox = static_cast<views::Combobox*>(view); | 80 views::Combobox* combobox = static_cast<views::Combobox*>(view); |
| 79 return combobox->GetTextForRow(combobox->GetSelectedRow()); | 81 return combobox->GetTextForRow(combobox->GetSelectedRow()); |
| 80 } else { | 82 } else { |
| 81 NOTREACHED() << "Unknown class " << view->GetClassName(); | 83 NOTREACHED() << "Unknown class " << view->GetClassName(); |
| 82 return base::string16(); | 84 return base::string16(); |
| 83 } | 85 } |
| 84 } | 86 } |
| 85 | 87 |
| 86 // Simulates recreating the dialog with a new PermissionInfoList. | 88 // Simulates recreating the dialog with a new PermissionInfoList. |
| 87 void SetPermissionInfo(const PermissionInfoList& list) { | 89 void SetPermissionInfo(const PermissionInfoList& list) { |
| 88 for (const PageInfoBubbleView::PermissionInfo& info : list) | 90 for (const PageInfoBubbleView::PermissionInfo& info : list) { |
| 89 view_->presenter_->OnSitePermissionChanged(info.type, info.setting); | 91 view_->presenter_->OnSitePermissionChanged(info.type, info.setting); |
| 92 } |
| 90 CreateView(); | 93 CreateView(); |
| 91 } | 94 } |
| 92 | 95 |
| 93 private: | 96 private: |
| 94 PageInfoBubbleView* view_; // Weak. Owned by its Widget. | 97 PageInfoBubbleView* view_; // Weak. Owned by its Widget. |
| 95 | 98 |
| 96 // For recreating the view. | 99 // For recreating the view. |
| 97 gfx::NativeView parent_; | 100 gfx::NativeView parent_; |
| 98 Profile* profile_; | 101 Profile* profile_; |
| 99 content::WebContents* web_contents_; | 102 content::WebContents* web_contents_; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 265 |
| 263 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 266 const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 264 ui::EventTimeForNow(), 0, 0); | 267 ui::EventTimeForNow(), 0, 0); |
| 265 views::ButtonListener* button_listener = | 268 views::ButtonListener* button_listener = |
| 266 static_cast<views::ButtonListener*>(object_view); | 269 static_cast<views::ButtonListener*>(object_view); |
| 267 button_listener->ButtonPressed(button, event); | 270 button_listener->ButtonPressed(button, event); |
| 268 api_->SetPermissionInfo(list); | 271 api_->SetPermissionInfo(list); |
| 269 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); | 272 EXPECT_EQ(kExpectedChildren, api_->permissions_view()->child_count()); |
| 270 EXPECT_FALSE(store->HasDevicePermission(origin, origin, device)); | 273 EXPECT_FALSE(store->HasDevicePermission(origin, origin, device)); |
| 271 } | 274 } |
| OLD | NEW |