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

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

Issue 2561673003: Handle per-tab AUTOMATIC_DOWNLOADS setting in DownloadRequestLimiter. (Closed)
Patch Set: Get HostContentSettingsMap directly in DRL tests Created 3 years, 9 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/content_settings/chrome_content_settings_utils.h" 16 #include "chrome/browser/content_settings/chrome_content_settings_utils.h"
17 #include "chrome/browser/content_settings/cookie_settings_factory.h" 17 #include "chrome/browser/content_settings/cookie_settings_factory.h"
18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
19 #include "chrome/browser/content_settings/mixed_content_settings_tab_helper.h" 19 #include "chrome/browser/content_settings/mixed_content_settings_tab_helper.h"
20 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 20 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
21 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 21 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
22 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" 22 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
23 #include "chrome/browser/download/download_request_limiter.h"
23 #include "chrome/browser/infobars/infobar_service.h" 24 #include "chrome/browser/infobars/infobar_service.h"
24 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" 25 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
25 #include "chrome/browser/permissions/permission_uma_util.h" 26 #include "chrome/browser/permissions/permission_uma_util.h"
26 #include "chrome/browser/permissions/permission_util.h" 27 #include "chrome/browser/permissions/permission_util.h"
27 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" 28 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
28 #include "chrome/browser/plugins/plugin_utils.h" 29 #include "chrome/browser/plugins/plugin_utils.h"
29 #include "chrome/browser/profiles/profile.h" 30 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" 31 #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
31 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" 32 #include "chrome/browser/ui/collected_cookies_infobar_delegate.h"
32 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega te.h" 33 #include "chrome/browser/ui/content_settings/content_setting_bubble_model_delega te.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = { 142 static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = {
142 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, 143 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE},
143 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, 144 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE},
144 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE}, 145 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE},
145 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_TITLE}, 146 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_TITLE},
146 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE}, 147 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE},
147 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, 148 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT,
148 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT}, 149 IDS_BLOCKED_DISPLAYING_INSECURE_CONTENT},
149 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, 150 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER,
150 IDS_BLOCKED_PPAPI_BROKER_TITLE}, 151 IDS_BLOCKED_PPAPI_BROKER_TITLE},
151 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_TITLE},
152 }; 152 };
153 // Fields as for kBlockedTitleIDs, above. 153 // Fields as for kBlockedTitleIDs, above.
154 static const ContentSettingsTypeIdEntry kAccessedTitleIDs[] = { 154 static const ContentSettingsTypeIdEntry kAccessedTitleIDs[] = {
155 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE}, 155 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ACCESSED_COOKIES_TITLE},
156 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_TITLE}, 156 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_TITLE},
157 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_TITLE},
158 }; 157 };
159 const ContentSettingsTypeIdEntry* title_ids = kBlockedTitleIDs; 158 const ContentSettingsTypeIdEntry* title_ids = kBlockedTitleIDs;
160 size_t num_title_ids = arraysize(kBlockedTitleIDs); 159 size_t num_title_ids = arraysize(kBlockedTitleIDs);
161 if (content_settings && content_settings->IsContentAllowed(content_type()) && 160 if (content_settings && content_settings->IsContentAllowed(content_type()) &&
162 !content_settings->IsContentBlocked(content_type())) { 161 !content_settings->IsContentBlocked(content_type())) {
163 title_ids = kAccessedTitleIDs; 162 title_ids = kAccessedTitleIDs;
164 num_title_ids = arraysize(kAccessedTitleIDs); 163 num_title_ids = arraysize(kAccessedTitleIDs);
165 } 164 }
166 int title_id = GetIdForContentType(title_ids, num_title_ids, content_type()); 165 int title_id = GetIdForContentType(title_ids, num_title_ids, content_type());
167 if (title_id) 166 if (title_id)
168 set_title(l10n_util::GetStringUTF16(title_id)); 167 set_title(l10n_util::GetStringUTF16(title_id));
169 } 168 }
170 169
171 void ContentSettingSimpleBubbleModel::SetManageText() { 170 void ContentSettingSimpleBubbleModel::SetManageText() {
172 static const ContentSettingsTypeIdEntry kLinkIDs[] = { 171 static const ContentSettingsTypeIdEntry kLinkIDs[] = {
173 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK}, 172 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_LINK},
174 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK}, 173 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_LINK},
175 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK}, 174 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_LINK},
176 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK}, 175 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LINK},
177 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK}, 176 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_LINK},
178 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK}, 177 {CONTENT_SETTINGS_TYPE_GEOLOCATION, IDS_GEOLOCATION_BUBBLE_MANAGE_LINK},
179 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE}, 178 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_LEARN_MORE},
180 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, IDS_HANDLERS_BUBBLE_MANAGE_LINK}, 179 {CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS, IDS_HANDLERS_BUBBLE_MANAGE_LINK},
181 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_PPAPI_BROKER_BUBBLE_MANAGE_LINK}, 180 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_PPAPI_BROKER_BUBBLE_MANAGE_LINK},
182 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOADS_LINK},
183 {CONTENT_SETTINGS_TYPE_MIDI_SYSEX, IDS_MIDI_SYSEX_BUBBLE_MANAGE_LINK}, 181 {CONTENT_SETTINGS_TYPE_MIDI_SYSEX, IDS_MIDI_SYSEX_BUBBLE_MANAGE_LINK},
184 }; 182 };
185 set_manage_text(l10n_util::GetStringUTF8( 183 set_manage_text(l10n_util::GetStringUTF8(
186 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); 184 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type())));
187 } 185 }
188 186
189 void ContentSettingSimpleBubbleModel::OnManageLinkClicked() { 187 void ContentSettingSimpleBubbleModel::OnManageLinkClicked() {
190 if (delegate()) 188 if (delegate())
191 delegate()->ShowContentSettingsPage(content_type()); 189 delegate()->ShowContentSettingsPage(content_type());
192 190
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 RadioGroup radio_group; 283 RadioGroup radio_group;
286 radio_group.url = url; 284 radio_group.url = url;
287 285
288 static const ContentSettingsTypeIdEntry kBlockedAllowIDs[] = { 286 static const ContentSettingsTypeIdEntry kBlockedAllowIDs[] = {
289 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK}, 287 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK},
290 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK}, 288 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK},
291 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK}, 289 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK},
292 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK_ALL}, 290 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK_ALL},
293 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK}, 291 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK},
294 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_UNBLOCK}, 292 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_UNBLOCK},
295 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_UNBLOCK},
296 }; 293 };
297 // Fields as for kBlockedAllowIDs, above. 294 // Fields as for kBlockedAllowIDs, above.
298 static const ContentSettingsTypeIdEntry kAllowedAllowIDs[] = { 295 static const ContentSettingsTypeIdEntry kAllowedAllowIDs[] = {
299 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ALLOWED_COOKIES_NO_ACTION}, 296 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ALLOWED_COOKIES_NO_ACTION},
300 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_NO_ACTION}, 297 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_NO_ACTION},
301 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_NO_ACTION},
302 }; 298 };
303 299
304 std::string radio_allow_label; 300 std::string radio_allow_label;
305 if (allowed) { 301 if (allowed) {
306 int resource_id = GetIdForContentType(kAllowedAllowIDs, 302 int resource_id = GetIdForContentType(kAllowedAllowIDs,
307 arraysize(kAllowedAllowIDs), 303 arraysize(kAllowedAllowIDs),
308 content_type()); 304 content_type());
309 radio_allow_label = l10n_util::GetStringUTF8(resource_id); 305 radio_allow_label = l10n_util::GetStringUTF8(resource_id);
310 } else { 306 } else {
311 radio_allow_label = l10n_util::GetStringFUTF8( 307 radio_allow_label = l10n_util::GetStringFUTF8(
312 GetIdForContentType(kBlockedAllowIDs, arraysize(kBlockedAllowIDs), 308 GetIdForContentType(kBlockedAllowIDs, arraysize(kBlockedAllowIDs),
313 content_type()), 309 content_type()),
314 display_host); 310 display_host);
315 } 311 }
316 312
317 static const ContentSettingsTypeIdEntry kBlockedBlockIDs[] = { 313 static const ContentSettingsTypeIdEntry kBlockedBlockIDs[] = {
318 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION}, 314 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION},
319 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_NO_ACTION}, 315 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_NO_ACTION},
320 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_NO_ACTION}, 316 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_NO_ACTION},
321 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_NO_ACTION}, 317 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_NO_ACTION},
322 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_NO_ACTION}, 318 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_NO_ACTION},
323 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_NO_ACTION}, 319 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_NO_ACTION},
324 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_NO_ACTION},
325 }; 320 };
326 static const ContentSettingsTypeIdEntry kAllowedBlockIDs[] = { 321 static const ContentSettingsTypeIdEntry kAllowedBlockIDs[] = {
327 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ALLOWED_COOKIES_BLOCK}, 322 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_ALLOWED_COOKIES_BLOCK},
328 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_BLOCK}, 323 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_BLOCK},
329 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_BLOCK},
330 }; 324 };
331 325
332 std::string radio_block_label; 326 std::string radio_block_label;
333 if (allowed) { 327 if (allowed) {
334 int resource_id = GetIdForContentType(kAllowedBlockIDs, 328 int resource_id = GetIdForContentType(kAllowedBlockIDs,
335 arraysize(kAllowedBlockIDs), 329 arraysize(kAllowedBlockIDs),
336 content_type()); 330 content_type());
337 radio_block_label = l10n_util::GetStringFUTF8(resource_id, display_host); 331 radio_block_label = l10n_util::GetStringFUTF8(resource_id, display_host);
338 } else { 332 } else {
339 radio_block_label = l10n_util::GetStringUTF8( 333 radio_block_label = l10n_util::GetStringUTF8(
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 for (const std::pair<GURL, ContentSetting>& map_entry : state_map) { 1348 for (const std::pair<GURL, ContentSetting>& map_entry : state_map) {
1355 PermissionUtil::ScopedRevocationReporter( 1349 PermissionUtil::ScopedRevocationReporter(
1356 profile(), map_entry.first, embedder_url, 1350 profile(), map_entry.first, embedder_url,
1357 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, PermissionSourceUI::PAGE_ACTION); 1351 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, PermissionSourceUI::PAGE_ACTION);
1358 map->SetContentSettingDefaultScope(map_entry.first, embedder_url, 1352 map->SetContentSettingDefaultScope(map_entry.first, embedder_url,
1359 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, 1353 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
1360 std::string(), CONTENT_SETTING_DEFAULT); 1354 std::string(), CONTENT_SETTING_DEFAULT);
1361 } 1355 }
1362 } 1356 }
1363 1357
1358 // ContentSettingDownloadsBubbleModel ------------------------------------------
1359
1360 ContentSettingDownloadsBubbleModel::ContentSettingDownloadsBubbleModel(
1361 Delegate* delegate,
1362 WebContents* web_contents,
1363 Profile* profile)
1364 : ContentSettingBubbleModel(delegate, web_contents, profile) {
1365 SetTitle();
1366 SetManageText();
1367 SetRadioGroup();
1368 }
1369
1370 ContentSettingDownloadsBubbleModel::~ContentSettingDownloadsBubbleModel() {
1371 if (profile() &&
1372 selected_item_ != bubble_content().radio_group.default_item) {
1373 ContentSetting setting = selected_item_ == kAllowButtonIndex
1374 ? CONTENT_SETTING_ALLOW
1375 : CONTENT_SETTING_BLOCK;
1376 auto* map = HostContentSettingsMapFactory::GetForProfile(profile());
1377 map->SetNarrowestContentSetting(
1378 bubble_content().radio_group.url, bubble_content().radio_group.url,
1379 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, setting);
1380 }
1381 }
1382
1383 ContentSettingDownloadsBubbleModel*
1384 ContentSettingDownloadsBubbleModel::AsDownloadsBubbleModel() {
1385 return this;
1386 }
1387
1388 // Initialize the radio group by setting the appropriate labels for the
1389 // content type and setting the default value based on the content setting.
1390 void ContentSettingDownloadsBubbleModel::SetRadioGroup() {
1391 GURL url = web_contents()->GetURL();
1392 base::string16 display_host = url_formatter::FormatUrlForSecurityDisplay(url);
1393 if (display_host.empty())
1394 display_host = base::ASCIIToUTF16(url.spec());
1395
1396 DownloadRequestLimiter* download_request_limiter =
1397 g_browser_process->download_request_limiter();
1398 DCHECK(download_request_limiter);
1399
1400 RadioGroup radio_group;
1401 radio_group.url = url;
1402 switch (download_request_limiter->GetDownloadStatus(web_contents())) {
1403 case DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS:
1404 radio_group.radio_items.push_back(
1405 l10n_util::GetStringUTF8(IDS_ALLOWED_DOWNLOAD_NO_ACTION));
1406 radio_group.radio_items.push_back(
1407 l10n_util::GetStringFUTF8(IDS_ALLOWED_DOWNLOAD_BLOCK, display_host));
1408 radio_group.default_item = kAllowButtonIndex;
1409 break;
1410 case DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED:
1411 radio_group.radio_items.push_back(l10n_util::GetStringFUTF8(
1412 IDS_BLOCKED_DOWNLOAD_UNBLOCK, display_host));
1413 radio_group.radio_items.push_back(
1414 l10n_util::GetStringUTF8(IDS_BLOCKED_DOWNLOAD_NO_ACTION));
1415 radio_group.default_item = 1;
1416 break;
1417 default:
1418 NOTREACHED();
1419 return;
1420 }
1421 set_radio_group(radio_group);
1422 selected_item_ = radio_group.default_item;
1423
1424 SettingInfo info;
1425 HostContentSettingsMap* map =
1426 HostContentSettingsMapFactory::GetForProfile(profile());
1427 map->GetWebsiteSetting(url, url, CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
1428 std::string(), &info);
1429
1430 // Prevent creation of content settings for illegal urls like about:blank
1431 bool is_valid = map->CanSetNarrowestContentSetting(
1432 url, url, CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS);
1433
1434 set_radio_group_enabled(is_valid && info.source == SETTING_SOURCE_USER);
1435 }
1436
1437 void ContentSettingDownloadsBubbleModel::OnRadioClicked(int radio_index) {
1438 selected_item_ = radio_index;
1439 }
1440
1441 void ContentSettingDownloadsBubbleModel::SetTitle() {
1442 if (!web_contents())
1443 return;
1444
1445 DownloadRequestLimiter* download_request_limiter =
1446 g_browser_process->download_request_limiter();
1447 DCHECK(download_request_limiter);
1448
1449 switch (download_request_limiter->GetDownloadStatus(web_contents())) {
1450 case DownloadRequestLimiter::ALLOW_ALL_DOWNLOADS:
1451 set_title(l10n_util::GetStringUTF16(IDS_ALLOWED_DOWNLOAD_TITLE));
1452 return;
1453 case DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED:
1454 set_title(l10n_util::GetStringUTF16(IDS_BLOCKED_DOWNLOAD_TITLE));
1455 return;
1456 default:
1457 // No title otherwise.
1458 return;
1459 }
1460 }
1461
1462 void ContentSettingDownloadsBubbleModel::SetManageText() {
1463 set_manage_text(l10n_util::GetStringUTF8(IDS_BLOCKED_DOWNLOADS_LINK));
1464 }
1465
1466 void ContentSettingDownloadsBubbleModel::OnManageLinkClicked() {
1467 if (delegate())
1468 delegate()->ShowContentSettingsPage(
1469 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS);
1470 }
1471
1364 // ContentSettingBubbleModel --------------------------------------------------- 1472 // ContentSettingBubbleModel ---------------------------------------------------
1365 1473
1366 // static 1474 // static
1367 ContentSettingBubbleModel* 1475 ContentSettingBubbleModel*
1368 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 1476 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
1369 Delegate* delegate, 1477 Delegate* delegate,
1370 WebContents* web_contents, 1478 WebContents* web_contents,
1371 Profile* profile, 1479 Profile* profile,
1372 ContentSettingsType content_type) { 1480 ContentSettingsType content_type) {
1373 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { 1481 if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) {
(...skipping 19 matching lines...) Expand all
1393 ProtocolHandlerRegistryFactory::GetForBrowserContext(profile); 1501 ProtocolHandlerRegistryFactory::GetForBrowserContext(profile);
1394 return new ContentSettingRPHBubbleModel(delegate, web_contents, profile, 1502 return new ContentSettingRPHBubbleModel(delegate, web_contents, profile,
1395 registry); 1503 registry);
1396 } 1504 }
1397 if (content_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { 1505 if (content_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {
1398 return new ContentSettingMidiSysExBubbleModel(delegate, web_contents, 1506 return new ContentSettingMidiSysExBubbleModel(delegate, web_contents,
1399 profile); 1507 profile);
1400 } 1508 }
1401 if (content_type == CONTENT_SETTINGS_TYPE_IMAGES || 1509 if (content_type == CONTENT_SETTINGS_TYPE_IMAGES ||
1402 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT || 1510 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT ||
1403 content_type == CONTENT_SETTINGS_TYPE_PPAPI_BROKER || 1511 content_type == CONTENT_SETTINGS_TYPE_PPAPI_BROKER) {
1404 content_type == CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) {
1405 return new ContentSettingSingleRadioGroup(delegate, web_contents, profile, 1512 return new ContentSettingSingleRadioGroup(delegate, web_contents, profile,
1406 content_type); 1513 content_type);
1407 } 1514 }
1515 if (content_type == CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) {
1516 return new ContentSettingDownloadsBubbleModel(delegate, web_contents,
1517 profile);
1518 }
1408 NOTREACHED() << "No bubble for the content type " << content_type << "."; 1519 NOTREACHED() << "No bubble for the content type " << content_type << ".";
1409 return nullptr; 1520 return nullptr;
1410 } 1521 }
1411 1522
1412 ContentSettingBubbleModel::ContentSettingBubbleModel(Delegate* delegate, 1523 ContentSettingBubbleModel::ContentSettingBubbleModel(Delegate* delegate,
1413 WebContents* web_contents, 1524 WebContents* web_contents,
1414 Profile* profile) 1525 Profile* profile)
1415 : web_contents_(web_contents), 1526 : web_contents_(web_contents),
1416 profile_(profile), 1527 profile_(profile),
1417 delegate_(delegate), 1528 delegate_(delegate),
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 ContentSettingMediaStreamBubbleModel* 1585 ContentSettingMediaStreamBubbleModel*
1475 ContentSettingBubbleModel::AsMediaStreamBubbleModel() { 1586 ContentSettingBubbleModel::AsMediaStreamBubbleModel() {
1476 // In general, bubble models might not inherit from the media bubble model. 1587 // In general, bubble models might not inherit from the media bubble model.
1477 return nullptr; 1588 return nullptr;
1478 } 1589 }
1479 1590
1480 ContentSettingSubresourceFilterBubbleModel* 1591 ContentSettingSubresourceFilterBubbleModel*
1481 ContentSettingBubbleModel::AsSubresourceFilterBubbleModel() { 1592 ContentSettingBubbleModel::AsSubresourceFilterBubbleModel() {
1482 return nullptr; 1593 return nullptr;
1483 } 1594 }
1595
1596 ContentSettingDownloadsBubbleModel*
1597 ContentSettingBubbleModel::AsDownloadsBubbleModel() {
1598 return nullptr;
1599 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698