Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(714)

Side by Side Diff: chrome/browser/ui/content_settings/content_setting_bubble_model.cc

Issue 1147363005: Create FormatUrlForSecurityDisplay helper function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change testing strategy, respond to comments. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/content_settings/content_setting_bubble_model.h" 5 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/content_settings/chrome_content_settings_utils.h" 11 #include "chrome/browser/content_settings/chrome_content_settings_utils.h"
12 #include "chrome/browser/content_settings/cookie_settings.h" 12 #include "chrome/browser/content_settings/cookie_settings.h"
13 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 13 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
15 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" 15 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
16 #include "chrome/browser/infobars/infobar_service.h" 16 #include "chrome/browser/infobars/infobar_service.h"
17 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 17 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
18 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" 18 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" 20 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
21 #include "chrome/browser/ui/browser_navigator.h" 21 #include "chrome/browser/ui/browser_navigator.h"
22 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" 22 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h"
23 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega te.h" 23 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega te.h"
24 #include "chrome/browser/ui/elide_url.h"
24 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
26 #include "chrome/common/render_messages.h" 27 #include "chrome/common/render_messages.h"
27 #include "chrome/grit/generated_resources.h" 28 #include "chrome/grit/generated_resources.h"
28 #include "components/content_settings/content/common/content_settings_messages.h " 29 #include "components/content_settings/content/common/content_settings_messages.h "
29 #include "components/content_settings/core/browser/content_settings_utils.h" 30 #include "components/content_settings/core/browser/content_settings_utils.h"
30 #include "components/content_settings/core/common/content_settings.h" 31 #include "components/content_settings/core/common/content_settings.h"
31 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
32 #include "content/public/browser/render_frame_host.h" 33 #include "content/public/browser/render_frame_host.h"
33 #include "content/public/browser/render_process_host.h" 34 #include "content/public/browser/render_process_host.h"
34 #include "content/public/browser/render_view_host.h" 35 #include "content/public/browser/render_view_host.h"
35 #include "content/public/browser/user_metrics.h" 36 #include "content/public/browser/user_metrics.h"
36 #include "content/public/browser/web_contents.h" 37 #include "content/public/browser/web_contents.h"
37 #include "content/public/browser/web_contents_delegate.h" 38 #include "content/public/browser/web_contents_delegate.h"
38 #include "content/public/common/origin_util.h" 39 #include "content/public/common/origin_util.h"
39 #include "grit/components_strings.h" 40 #include "grit/components_strings.h"
40 #include "grit/theme_resources.h" 41 #include "grit/theme_resources.h"
41 #include "net/base/net_util.h"
42 #include "ui/base/l10n/l10n_util.h" 42 #include "ui/base/l10n/l10n_util.h"
43 #include "ui/base/resource/resource_bundle.h" 43 #include "ui/base/resource/resource_bundle.h"
44 #include "ui/resources/grit/ui_resources.h" 44 #include "ui/resources/grit/ui_resources.h"
45 45
46 using base::UserMetricsAction; 46 using base::UserMetricsAction;
47 using content::WebContents; 47 using content::WebContents;
48 using content_settings::SettingInfo; 48 using content_settings::SettingInfo;
49 using content_settings::SettingSource; 49 using content_settings::SettingSource;
50 using content_settings::SETTING_SOURCE_USER; 50 using content_settings::SETTING_SOURCE_USER;
51 using content_settings::SETTING_SOURCE_NONE; 51 using content_settings::SETTING_SOURCE_NONE;
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 } 267 }
268 268
269 bool ContentSettingSingleRadioGroup::settings_changed() const { 269 bool ContentSettingSingleRadioGroup::settings_changed() const {
270 return selected_item_ != bubble_content().radio_group.default_item; 270 return selected_item_ != bubble_content().radio_group.default_item;
271 } 271 }
272 272
273 // Initialize the radio group by setting the appropriate labels for the 273 // Initialize the radio group by setting the appropriate labels for the
274 // content type and setting the default value based on the content setting. 274 // content type and setting the default value based on the content setting.
275 void ContentSettingSingleRadioGroup::SetRadioGroup() { 275 void ContentSettingSingleRadioGroup::SetRadioGroup() {
276 GURL url = web_contents()->GetURL(); 276 GURL url = web_contents()->GetURL();
277 base::string16 display_host; 277 base::string16 display_host = FormatUrlForSecurityDisplay(
278 net::AppendFormattedHost( 278 url, profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
279 url,
280 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages),
281 &display_host);
282
283 if (display_host.empty()) 279 if (display_host.empty())
284 display_host = base::ASCIIToUTF16(url.spec()); 280 display_host = base::ASCIIToUTF16(url.spec());
285 281
286 TabSpecificContentSettings* content_settings = 282 TabSpecificContentSettings* content_settings =
287 TabSpecificContentSettings::FromWebContents(web_contents()); 283 TabSpecificContentSettings::FromWebContents(web_contents());
288 bool allowed = 284 bool allowed =
289 !content_settings->IsContentBlocked(content_type()); 285 !content_settings->IsContentBlocked(content_type());
290 DCHECK(!allowed || 286 DCHECK(!allowed ||
291 content_settings->IsContentAllowed(content_type())); 287 content_settings->IsContentAllowed(content_type()));
292 288
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 web_contents, 547 web_contents,
552 profile, 548 profile,
553 CONTENT_SETTINGS_TYPE_POPUPS) { 549 CONTENT_SETTINGS_TYPE_POPUPS) {
554 if (web_contents) { 550 if (web_contents) {
555 // Build blocked popup list. 551 // Build blocked popup list.
556 std::map<int32, GURL> blocked_popups = 552 std::map<int32, GURL> blocked_popups =
557 PopupBlockerTabHelper::FromWebContents(web_contents) 553 PopupBlockerTabHelper::FromWebContents(web_contents)
558 ->GetBlockedPopupRequests(); 554 ->GetBlockedPopupRequests();
559 for (const std::pair<int32, GURL>& blocked_popup : blocked_popups) { 555 for (const std::pair<int32, GURL>& blocked_popup : blocked_popups) {
560 std::string title(blocked_popup.second.spec()); 556 std::string title(blocked_popup.second.spec());
561 // The popup may not have a valid URL. 557 // The pop-up may not have a valid URL.
562 if (title.empty()) 558 if (title.empty())
563 title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE); 559 title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE);
564 ListItem popup_item(ui::ResourceBundle::GetSharedInstance().GetImageNamed( 560 ListItem popup_item(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
565 IDR_DEFAULT_FAVICON), 561 IDR_DEFAULT_FAVICON),
566 title, true, blocked_popup.first); 562 title, true, blocked_popup.first);
567 add_list_item(popup_item); 563 add_list_item(popup_item);
568 } 564 }
569 } 565 }
570 } 566 }
571 567
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 set_title(l10n_util::GetStringUTF8(title_id)); 674 set_title(l10n_util::GetStringUTF8(title_id));
679 } 675 }
680 676
681 void ContentSettingMediaStreamBubbleModel::SetRadioGroup() { 677 void ContentSettingMediaStreamBubbleModel::SetRadioGroup() {
682 TabSpecificContentSettings* content_settings = 678 TabSpecificContentSettings* content_settings =
683 TabSpecificContentSettings::FromWebContents(web_contents()); 679 TabSpecificContentSettings::FromWebContents(web_contents());
684 GURL url = content_settings->media_stream_access_origin(); 680 GURL url = content_settings->media_stream_access_origin();
685 RadioGroup radio_group; 681 RadioGroup radio_group;
686 radio_group.url = url; 682 radio_group.url = url;
687 683
688 base::string16 display_host_utf16; 684 base::string16 display_host_utf16 = FormatUrlForSecurityDisplay(
689 net::AppendFormattedHost( 685 url, profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
690 url,
691 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages),
692 &display_host_utf16);
693 std::string display_host(base::UTF16ToUTF8(display_host_utf16)); 686 std::string display_host(base::UTF16ToUTF8(display_host_utf16));
694 if (display_host.empty()) 687 if (display_host.empty())
695 display_host = url.spec(); 688 display_host = url.spec();
696 689
697 bool is_mic = (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) != 0; 690 bool is_mic = (state_ & TabSpecificContentSettings::MICROPHONE_ACCESSED) != 0;
698 bool is_cam = (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) != 0; 691 bool is_cam = (state_ & TabSpecificContentSettings::CAMERA_ACCESSED) != 0;
699 DCHECK(is_mic || is_cam); 692 DCHECK(is_mic || is_cam);
700 int radio_allow_label_id = 0; 693 int radio_allow_label_id = 0;
701 int radio_block_label_id = 0; 694 int radio_block_label_id = 0;
702 if (state_ & (TabSpecificContentSettings::MICROPHONE_BLOCKED | 695 if (state_ & (TabSpecificContentSettings::MICROPHONE_BLOCKED |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { 1298 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) {
1306 DCHECK_EQ(web_contents_, 1299 DCHECK_EQ(web_contents_,
1307 content::Source<WebContents>(source).ptr()); 1300 content::Source<WebContents>(source).ptr());
1308 web_contents_ = NULL; 1301 web_contents_ = NULL;
1309 } else { 1302 } else {
1310 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); 1303 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
1311 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); 1304 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr());
1312 profile_ = NULL; 1305 profile_ = NULL;
1313 } 1306 }
1314 } 1307 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698