| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/content_setting_bubble_contents.h" | 5 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "components/content_settings/core/browser/host_content_settings_map.h" | 22 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 23 #include "components/strings/grit/components_strings.h" | 23 #include "components/strings/grit/components_strings.h" |
| 24 #include "content/public/browser/plugin_service.h" | 24 #include "content/public/browser/plugin_service.h" |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "ui/base/cursor/cursor.h" | 26 #include "ui/base/cursor/cursor.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/models/simple_menu_model.h" | 28 #include "ui/base/models/simple_menu_model.h" |
| 29 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 30 #include "ui/gfx/font_list.h" | 30 #include "ui/gfx/font_list.h" |
| 31 #include "ui/gfx/text_utils.h" | 31 #include "ui/gfx/text_utils.h" |
| 32 #include "ui/views/controls/button/md_text_button.h" |
| 32 #include "ui/views/controls/button/menu_button.h" | 33 #include "ui/views/controls/button/menu_button.h" |
| 33 #include "ui/views/controls/button/radio_button.h" | 34 #include "ui/views/controls/button/radio_button.h" |
| 34 #include "ui/views/controls/combobox/combobox.h" | 35 #include "ui/views/controls/combobox/combobox.h" |
| 35 #include "ui/views/controls/image_view.h" | 36 #include "ui/views/controls/image_view.h" |
| 36 #include "ui/views/controls/label.h" | 37 #include "ui/views/controls/label.h" |
| 37 #include "ui/views/controls/link.h" | 38 #include "ui/views/controls/link.h" |
| 38 #include "ui/views/controls/menu/menu_config.h" | 39 #include "ui/views/controls/menu/menu_config.h" |
| 39 #include "ui/views/controls/menu/menu_runner.h" | 40 #include "ui/views/controls/menu/menu_runner.h" |
| 40 #include "ui/views/controls/separator.h" | 41 #include "ui/views/controls/separator.h" |
| 41 #include "ui/views/layout/grid_layout.h" | 42 #include "ui/views/layout/grid_layout.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // ContentSettingBubbleContents ----------------------------------------------- | 153 // ContentSettingBubbleContents ----------------------------------------------- |
| 153 | 154 |
| 154 ContentSettingBubbleContents::ContentSettingBubbleContents( | 155 ContentSettingBubbleContents::ContentSettingBubbleContents( |
| 155 ContentSettingBubbleModel* content_setting_bubble_model, | 156 ContentSettingBubbleModel* content_setting_bubble_model, |
| 156 content::WebContents* web_contents, | 157 content::WebContents* web_contents, |
| 157 views::View* anchor_view, | 158 views::View* anchor_view, |
| 158 views::BubbleBorder::Arrow arrow) | 159 views::BubbleBorder::Arrow arrow) |
| 159 : content::WebContentsObserver(web_contents), | 160 : content::WebContentsObserver(web_contents), |
| 160 BubbleDialogDelegateView(anchor_view, arrow), | 161 BubbleDialogDelegateView(anchor_view, arrow), |
| 161 content_setting_bubble_model_(content_setting_bubble_model), | 162 content_setting_bubble_model_(content_setting_bubble_model), |
| 162 custom_link_(NULL), | 163 custom_link_(nullptr), |
| 163 manage_link_(NULL), | 164 manage_link_(nullptr), |
| 164 learn_more_link_(NULL) { | 165 manage_button_(nullptr), |
| 166 learn_more_link_(nullptr) { |
| 165 // Compensate for built-in vertical padding in the anchor view's image. | 167 // Compensate for built-in vertical padding in the anchor view's image. |
| 166 set_anchor_view_insets(gfx::Insets( | 168 set_anchor_view_insets(gfx::Insets( |
| 167 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); | 169 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); |
| 168 } | 170 } |
| 169 | 171 |
| 170 ContentSettingBubbleContents::~ContentSettingBubbleContents() { | 172 ContentSettingBubbleContents::~ContentSettingBubbleContents() { |
| 171 // Must remove the children here so the comboboxes get destroyed before | 173 // Must remove the children here so the comboboxes get destroyed before |
| 172 // their associated models. | 174 // their associated models. |
| 173 RemoveAllChildViews(true); | 175 RemoveAllChildViews(true); |
| 174 } | 176 } |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 if (!bubble_content_empty) { | 376 if (!bubble_content_empty) { |
| 375 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 377 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 376 layout->StartRow(0, kSingleColumnSetId); | 378 layout->StartRow(0, kSingleColumnSetId); |
| 377 layout->AddView(new views::Separator(views::Separator::HORIZONTAL), 1, 1, | 379 layout->AddView(new views::Separator(views::Separator::HORIZONTAL), 1, 1, |
| 378 GridLayout::FILL, GridLayout::FILL); | 380 GridLayout::FILL, GridLayout::FILL); |
| 379 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 381 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 380 } | 382 } |
| 381 } | 383 } |
| 382 | 384 |
| 383 views::View* ContentSettingBubbleContents::CreateExtraView() { | 385 views::View* ContentSettingBubbleContents::CreateExtraView() { |
| 384 manage_link_ = new views::Link(base::UTF8ToUTF16( | 386 if (content_setting_bubble_model_->bubble_content() |
| 385 content_setting_bubble_model_->bubble_content().manage_link)); | 387 .show_manage_text_as_button) { |
| 386 manage_link_->set_listener(this); | 388 manage_button_ = views::MdTextButton::CreateSecondaryUiButton( |
| 387 return manage_link_; | 389 this, base::UTF8ToUTF16( |
| 390 content_setting_bubble_model_->bubble_content().manage_text)); |
| 391 return manage_button_; |
| 392 } else { |
| 393 manage_link_ = new views::Link(base::UTF8ToUTF16( |
| 394 content_setting_bubble_model_->bubble_content().manage_text)); |
| 395 manage_link_->set_listener(this); |
| 396 return manage_link_; |
| 397 } |
| 388 } | 398 } |
| 389 | 399 |
| 390 bool ContentSettingBubbleContents::Accept() { | 400 bool ContentSettingBubbleContents::Accept() { |
| 391 content_setting_bubble_model_->OnDoneClicked(); | 401 content_setting_bubble_model_->OnDoneClicked(); |
| 392 return true; | 402 return true; |
| 393 } | 403 } |
| 394 | 404 |
| 395 bool ContentSettingBubbleContents::Close() { | 405 bool ContentSettingBubbleContents::Close() { |
| 396 return true; | 406 return true; |
| 397 } | 407 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 408 void ContentSettingBubbleContents::DidNavigateMainFrame( | 418 void ContentSettingBubbleContents::DidNavigateMainFrame( |
| 409 const content::LoadCommittedDetails& details, | 419 const content::LoadCommittedDetails& details, |
| 410 const content::FrameNavigateParams& params) { | 420 const content::FrameNavigateParams& params) { |
| 411 // Content settings are based on the main frame, so if it switches then | 421 // Content settings are based on the main frame, so if it switches then |
| 412 // close up shop. | 422 // close up shop. |
| 413 GetWidget()->Close(); | 423 GetWidget()->Close(); |
| 414 } | 424 } |
| 415 | 425 |
| 416 void ContentSettingBubbleContents::ButtonPressed(views::Button* sender, | 426 void ContentSettingBubbleContents::ButtonPressed(views::Button* sender, |
| 417 const ui::Event& event) { | 427 const ui::Event& event) { |
| 418 RadioGroup::const_iterator i( | 428 if (manage_button_ == sender) { |
| 419 std::find(radio_group_.begin(), radio_group_.end(), sender)); | 429 GetWidget()->Close(); |
| 420 DCHECK(i != radio_group_.end()); | 430 content_setting_bubble_model_->OnManageLinkClicked(); |
| 421 content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin()); | 431 } else { |
| 432 RadioGroup::const_iterator i( |
| 433 std::find(radio_group_.begin(), radio_group_.end(), sender)); |
| 434 DCHECK(i != radio_group_.end()); |
| 435 content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin()); |
| 436 } |
| 422 } | 437 } |
| 423 | 438 |
| 424 void ContentSettingBubbleContents::LinkClicked(views::Link* source, | 439 void ContentSettingBubbleContents::LinkClicked(views::Link* source, |
| 425 int event_flags) { | 440 int event_flags) { |
| 426 if (source == learn_more_link_) { | 441 if (source == learn_more_link_) { |
| 427 content_setting_bubble_model_->OnLearnMoreLinkClicked(); | 442 content_setting_bubble_model_->OnLearnMoreLinkClicked(); |
| 428 GetWidget()->Close(); | 443 GetWidget()->Close(); |
| 429 return; | 444 return; |
| 430 } | 445 } |
| 431 if (source == custom_link_) { | 446 if (source == custom_link_) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 445 DCHECK(i != list_item_links_.end()); | 460 DCHECK(i != list_item_links_.end()); |
| 446 content_setting_bubble_model_->OnListItemClicked(i->second); | 461 content_setting_bubble_model_->OnListItemClicked(i->second); |
| 447 } | 462 } |
| 448 | 463 |
| 449 void ContentSettingBubbleContents::OnPerformAction(views::Combobox* combobox) { | 464 void ContentSettingBubbleContents::OnPerformAction(views::Combobox* combobox) { |
| 450 MediaComboboxModel* model = | 465 MediaComboboxModel* model = |
| 451 static_cast<MediaComboboxModel*>(combobox->model()); | 466 static_cast<MediaComboboxModel*>(combobox->model()); |
| 452 content_setting_bubble_model_->OnMediaMenuClicked( | 467 content_setting_bubble_model_->OnMediaMenuClicked( |
| 453 model->type(), model->GetDevices()[combobox->selected_index()].id); | 468 model->type(), model->GetDevices()[combobox->selected_index()].id); |
| 454 } | 469 } |
| OLD | NEW |