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/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" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 Delegate* delegate, | 88 Delegate* delegate, |
89 WebContents* web_contents, | 89 WebContents* web_contents, |
90 Profile* profile, | 90 Profile* profile, |
91 ContentSettingsType content_type) | 91 ContentSettingsType content_type) |
92 : ContentSettingBubbleModel(web_contents, profile, content_type), | 92 : ContentSettingBubbleModel(web_contents, profile, content_type), |
93 delegate_(delegate) { | 93 delegate_(delegate) { |
94 // Notifications do not have a bubble. | 94 // Notifications do not have a bubble. |
95 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 95 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
96 SetTitle(); | 96 SetTitle(); |
97 SetManageLink(); | 97 SetManageLink(); |
98 SetLearnMoreLink(); | |
98 } | 99 } |
99 | 100 |
100 void ContentSettingTitleAndLinkModel::SetTitle() { | 101 void ContentSettingTitleAndLinkModel::SetTitle() { |
101 static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = { | 102 static const ContentSettingsTypeIdEntry kBlockedTitleIDs[] = { |
102 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, | 103 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_TITLE}, |
103 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, | 104 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_TITLE}, |
104 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE}, | 105 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_TITLE}, |
105 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE}, | 106 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_MESSAGE}, |
106 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE}, | 107 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_TITLE}, |
107 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, | 108 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 }; | 150 }; |
150 set_manage_link(l10n_util::GetStringUTF8( | 151 set_manage_link(l10n_util::GetStringUTF8( |
151 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); | 152 GetIdForContentType(kLinkIDs, arraysize(kLinkIDs), content_type()))); |
152 } | 153 } |
153 | 154 |
154 void ContentSettingTitleAndLinkModel::OnManageLinkClicked() { | 155 void ContentSettingTitleAndLinkModel::OnManageLinkClicked() { |
155 if (delegate_) | 156 if (delegate_) |
156 delegate_->ShowContentSettingsPage(content_type()); | 157 delegate_->ShowContentSettingsPage(content_type()); |
157 } | 158 } |
158 | 159 |
160 void ContentSettingTitleAndLinkModel::SetLearnMoreLink() { | |
161 static const ContentSettingsTypeIdEntry kLearnMoreIDs[] = { | |
162 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_LEARN_MORE}, | |
163 }; | |
164 int learn_more_id = | |
165 GetIdForContentType(kLearnMoreIDs, arraysize(kLearnMoreIDs), | |
166 content_type()); | |
167 if (learn_more_id) | |
168 set_learn_more_link(l10n_util::GetStringUTF8(learn_more_id)); | |
169 } | |
170 | |
171 void ContentSettingTitleAndLinkModel::OnLearnMoreLinkClicked() { | |
172 if (delegate_) | |
173 delegate_->ShowLearnMorePage(content_type()); | |
174 } | |
175 | |
159 class ContentSettingTitleLinkAndCustomModel | 176 class ContentSettingTitleLinkAndCustomModel |
160 : public ContentSettingTitleAndLinkModel { | 177 : public ContentSettingTitleAndLinkModel { |
161 public: | 178 public: |
162 ContentSettingTitleLinkAndCustomModel(Delegate* delegate, | 179 ContentSettingTitleLinkAndCustomModel(Delegate* delegate, |
163 WebContents* web_contents, | 180 WebContents* web_contents, |
164 Profile* profile, | 181 Profile* profile, |
165 ContentSettingsType content_type); | 182 ContentSettingsType content_type); |
166 virtual ~ContentSettingTitleLinkAndCustomModel() {} | 183 virtual ~ContentSettingTitleLinkAndCustomModel() {} |
167 | 184 |
168 private: | 185 private: |
169 void SetCustomLink(); | 186 void SetCustomLink(); |
170 virtual void OnCustomLinkClicked() OVERRIDE {} | 187 virtual void OnCustomLinkClicked() OVERRIDE {} |
171 }; | 188 }; |
172 | 189 |
173 ContentSettingTitleLinkAndCustomModel::ContentSettingTitleLinkAndCustomModel( | 190 ContentSettingTitleLinkAndCustomModel::ContentSettingTitleLinkAndCustomModel( |
174 Delegate* delegate, | 191 Delegate* delegate, |
175 WebContents* web_contents, | 192 WebContents* web_contents, |
176 Profile* profile, | 193 Profile* profile, |
177 ContentSettingsType content_type) | 194 ContentSettingsType content_type) |
178 : ContentSettingTitleAndLinkModel( | 195 : ContentSettingTitleAndLinkModel( |
179 delegate, web_contents, profile, content_type) { | 196 delegate, web_contents, profile, content_type) { |
180 SetCustomLink(); | 197 SetCustomLink(); |
181 } | 198 } |
182 | 199 |
183 void ContentSettingTitleLinkAndCustomModel::SetCustomLink() { | 200 void ContentSettingTitleLinkAndCustomModel::SetCustomLink() { |
184 static const ContentSettingsTypeIdEntry kCustomIDs[] = { | 201 static const ContentSettingsTypeIdEntry kCustomIDs[] = { |
185 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_INFO}, | 202 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_INFO}, |
186 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_LOAD_ALL}, | |
187 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_ALLOW_INSECURE_CONTENT_BUTTON}, | 203 {CONTENT_SETTINGS_TYPE_MIXEDSCRIPT, IDS_ALLOW_INSECURE_CONTENT_BUTTON}, |
188 }; | 204 }; |
189 int custom_link_id = | 205 int custom_link_id = |
190 GetIdForContentType(kCustomIDs, arraysize(kCustomIDs), content_type()); | 206 GetIdForContentType(kCustomIDs, arraysize(kCustomIDs), content_type()); |
191 if (custom_link_id) | 207 if (custom_link_id) |
192 set_custom_link(l10n_util::GetStringUTF8(custom_link_id)); | 208 set_custom_link(l10n_util::GetStringUTF8(custom_link_id)); |
193 } | 209 } |
194 | 210 |
195 class ContentSettingSingleRadioGroup | 211 class ContentSettingSingleRadioGroup |
196 : public ContentSettingTitleLinkAndCustomModel { | 212 : public ContentSettingTitleLinkAndCustomModel { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 DCHECK(!allowed || | 276 DCHECK(!allowed || |
261 content_settings->IsContentAllowed(content_type())); | 277 content_settings->IsContentAllowed(content_type())); |
262 | 278 |
263 RadioGroup radio_group; | 279 RadioGroup radio_group; |
264 radio_group.url = url; | 280 radio_group.url = url; |
265 | 281 |
266 static const ContentSettingsTypeIdEntry kBlockedAllowIDs[] = { | 282 static const ContentSettingsTypeIdEntry kBlockedAllowIDs[] = { |
267 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK}, | 283 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK}, |
268 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK}, | 284 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_UNBLOCK}, |
269 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK}, | 285 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_UNBLOCK}, |
270 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_UNBLOCK_ALL}, | |
271 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK}, | 286 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_UNBLOCK}, |
272 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_UNBLOCK}, | 287 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_UNBLOCK}, |
273 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_UNBLOCK}, | 288 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_UNBLOCK}, |
274 }; | 289 }; |
275 // Fields as for kBlockedAllowIDs, above. | 290 // Fields as for kBlockedAllowIDs, above. |
276 static const ContentSettingsTypeIdEntry kAllowedAllowIDs[] = { | 291 static const ContentSettingsTypeIdEntry kAllowedAllowIDs[] = { |
277 // TODO(bauerb): The string shouldn't be "unblock" (they weren't blocked). | 292 // TODO(bauerb): The string shouldn't be "unblock" (they weren't blocked). |
278 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK}, | 293 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_UNBLOCK}, |
279 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_NO_ACTION}, | 294 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_NO_ACTION}, |
280 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_NO_ACTION}, | 295 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_NO_ACTION}, |
(...skipping 11 matching lines...) Expand all Loading... | |
292 radio_allow_label = l10n_util::GetStringFUTF8( | 307 radio_allow_label = l10n_util::GetStringFUTF8( |
293 GetIdForContentType(kBlockedAllowIDs, arraysize(kBlockedAllowIDs), | 308 GetIdForContentType(kBlockedAllowIDs, arraysize(kBlockedAllowIDs), |
294 content_type()), | 309 content_type()), |
295 display_host); | 310 display_host); |
296 } | 311 } |
297 | 312 |
298 static const ContentSettingsTypeIdEntry kBlockedBlockIDs[] = { | 313 static const ContentSettingsTypeIdEntry kBlockedBlockIDs[] = { |
299 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION}, | 314 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION}, |
300 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_NO_ACTION}, | 315 {CONTENT_SETTINGS_TYPE_IMAGES, IDS_BLOCKED_IMAGES_NO_ACTION}, |
301 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_NO_ACTION}, | 316 {CONTENT_SETTINGS_TYPE_JAVASCRIPT, IDS_BLOCKED_JAVASCRIPT_NO_ACTION}, |
302 {CONTENT_SETTINGS_TYPE_PLUGINS, IDS_BLOCKED_PLUGINS_NO_ACTION}, | |
303 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_NO_ACTION}, | 317 {CONTENT_SETTINGS_TYPE_POPUPS, IDS_BLOCKED_POPUPS_NO_ACTION}, |
304 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_NO_ACTION}, | 318 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_BLOCKED_PPAPI_BROKER_NO_ACTION}, |
305 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_NO_ACTION}, | 319 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_BLOCKED_DOWNLOAD_NO_ACTION}, |
306 }; | 320 }; |
307 static const ContentSettingsTypeIdEntry kAllowedBlockIDs[] = { | 321 static const ContentSettingsTypeIdEntry kAllowedBlockIDs[] = { |
308 // TODO(bauerb): The string should say "block". | 322 // TODO(bauerb): The string should say "block". |
309 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION}, | 323 {CONTENT_SETTINGS_TYPE_COOKIES, IDS_BLOCKED_COOKIES_NO_ACTION}, |
310 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_BLOCK}, | 324 {CONTENT_SETTINGS_TYPE_PPAPI_BROKER, IDS_ALLOWED_PPAPI_BROKER_BLOCK}, |
311 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_BLOCK}, | 325 {CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, IDS_ALLOWED_DOWNLOAD_BLOCK}, |
312 }; | 326 }; |
313 | 327 |
314 std::string radio_block_label; | 328 std::string radio_block_label; |
315 if (allowed) { | 329 if (allowed) { |
316 int resource_id = GetIdForContentType(kAllowedBlockIDs, | 330 int resource_id = GetIdForContentType(kAllowedBlockIDs, |
317 arraysize(kAllowedBlockIDs), | 331 arraysize(kAllowedBlockIDs), |
318 content_type()); | 332 content_type()); |
319 radio_block_label = (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) ? | 333 radio_block_label = (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) ? |
320 l10n_util::GetStringUTF8(resource_id) : | 334 l10n_util::GetStringUTF8(resource_id) : |
321 l10n_util::GetStringFUTF8(resource_id, display_host); | 335 l10n_util::GetStringFUTF8(resource_id, display_host); |
322 } else { | 336 } else { |
323 radio_block_label = l10n_util::GetStringUTF8( | 337 radio_block_label = l10n_util::GetStringUTF8( |
324 GetIdForContentType(kBlockedBlockIDs, arraysize(kBlockedBlockIDs), | 338 GetIdForContentType(kBlockedBlockIDs, arraysize(kBlockedBlockIDs), |
325 content_type())); | 339 content_type())); |
326 } | 340 } |
327 | 341 |
328 radio_group.radio_items.push_back(radio_allow_label); | 342 radio_group.radio_items.push_back(radio_allow_label); |
329 radio_group.radio_items.push_back(radio_block_label); | 343 radio_group.radio_items.push_back(radio_block_label); |
330 ContentSetting setting; | 344 ContentSetting setting; |
331 SettingSource setting_source = SETTING_SOURCE_NONE; | 345 SettingSource setting_source = SETTING_SOURCE_NONE; |
332 bool setting_is_wildcard = false; | |
333 | 346 |
334 if (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) { | 347 if (content_type() == CONTENT_SETTINGS_TYPE_COOKIES) { |
335 CookieSettings* cookie_settings = | 348 CookieSettings* cookie_settings = |
336 CookieSettings::Factory::GetForProfile(profile()).get(); | 349 CookieSettings::Factory::GetForProfile(profile()).get(); |
337 setting = cookie_settings->GetCookieSetting( | 350 setting = cookie_settings->GetCookieSetting( |
338 url, url, true, &setting_source); | 351 url, url, true, &setting_source); |
339 } else { | 352 } else { |
340 SettingInfo info; | 353 SettingInfo info; |
341 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); | 354 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); |
342 scoped_ptr<base::Value> value(map->GetWebsiteSetting( | 355 scoped_ptr<base::Value> value(map->GetWebsiteSetting( |
343 url, url, content_type(), std::string(), &info)); | 356 url, url, content_type(), std::string(), &info)); |
344 setting = content_settings::ValueToContentSetting(value.get()); | 357 setting = content_settings::ValueToContentSetting(value.get()); |
345 setting_source = info.source; | 358 setting_source = info.source; |
346 setting_is_wildcard = | |
347 info.primary_pattern == ContentSettingsPattern::Wildcard() && | |
348 info.secondary_pattern == ContentSettingsPattern::Wildcard(); | |
349 } | 359 } |
350 | 360 |
351 if (content_type() == CONTENT_SETTINGS_TYPE_PLUGINS && | 361 if (setting == CONTENT_SETTING_ALLOW) { |
352 setting == CONTENT_SETTING_ALLOW && | |
353 setting_is_wildcard) { | |
354 // In the corner case of unrecognized plugins (which are now blocked by | |
355 // default) we indicate the blocked state in the UI and allow the user to | |
356 // whitelist. | |
357 radio_group.default_item = 1; | |
358 } else if (setting == CONTENT_SETTING_ALLOW) { | |
359 radio_group.default_item = kAllowButtonIndex; | 362 radio_group.default_item = kAllowButtonIndex; |
360 // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|. | 363 // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|. |
361 } else { | 364 } else { |
362 radio_group.default_item = 1; | 365 radio_group.default_item = 1; |
363 block_setting_ = setting; | 366 block_setting_ = setting; |
364 } | 367 } |
365 | 368 |
366 set_setting_is_managed(setting_source != SETTING_SOURCE_USER); | 369 set_setting_is_managed(setting_source != SETTING_SOURCE_USER); |
367 if (setting_source != SETTING_SOURCE_USER) { | 370 if (setting_source != SETTING_SOURCE_USER) { |
368 set_radio_group_enabled(false); | 371 set_radio_group_enabled(false); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 if (!web_contents()) | 427 if (!web_contents()) |
425 return; | 428 return; |
426 content::NotificationService::current()->Notify( | 429 content::NotificationService::current()->Notify( |
427 chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, | 430 chrome::NOTIFICATION_COLLECTED_COOKIES_SHOWN, |
428 content::Source<TabSpecificContentSettings>( | 431 content::Source<TabSpecificContentSettings>( |
429 TabSpecificContentSettings::FromWebContents(web_contents())), | 432 TabSpecificContentSettings::FromWebContents(web_contents())), |
430 content::NotificationService::NoDetails()); | 433 content::NotificationService::NoDetails()); |
431 delegate()->ShowCollectedCookiesDialog(web_contents()); | 434 delegate()->ShowCollectedCookiesDialog(web_contents()); |
432 } | 435 } |
433 | 436 |
434 class ContentSettingPluginBubbleModel : public ContentSettingSingleRadioGroup { | 437 class ContentSettingPluginBubbleModel : public ContentSettingTitleAndLinkModel { |
435 public: | 438 public: |
436 ContentSettingPluginBubbleModel(Delegate* delegate, | 439 ContentSettingPluginBubbleModel(Delegate* delegate, |
437 WebContents* web_contents, | 440 WebContents* web_contents, |
438 Profile* profile, | 441 Profile* profile, |
439 ContentSettingsType content_type); | 442 ContentSettingsType content_type); |
440 | 443 |
441 virtual ~ContentSettingPluginBubbleModel(); | 444 virtual ~ContentSettingPluginBubbleModel(); |
442 | 445 |
443 private: | 446 private: |
444 virtual void OnCustomLinkClicked() OVERRIDE; | 447 void SetRadioGroup(); |
448 | |
449 // Cookie bubble implementation. | |
450 virtual void OnRadioClicked(int radio_index) OVERRIDE; | |
451 | |
452 // Function to load plugins. | |
453 void OnRunPlugins(); | |
454 | |
455 bool settings_changed() const; | |
456 int selected_item() const { return selected_item_; } | |
457 | |
458 ContentSetting block_setting_; | |
459 int selected_item_; | |
460 int kAllowOnceButtonIndex; | |
445 }; | 461 }; |
446 | 462 |
447 ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel( | 463 ContentSettingPluginBubbleModel::ContentSettingPluginBubbleModel( |
448 Delegate* delegate, | 464 Delegate* delegate, |
449 WebContents* web_contents, | 465 WebContents* web_contents, |
450 Profile* profile, | 466 Profile* profile, |
451 ContentSettingsType content_type) | 467 ContentSettingsType content_type) |
452 : ContentSettingSingleRadioGroup( | 468 : ContentSettingTitleAndLinkModel( |
453 delegate, web_contents, profile, content_type) { | 469 delegate, web_contents, profile, content_type), |
470 block_setting_(CONTENT_SETTING_BLOCK), | |
471 selected_item_(0), | |
472 kAllowOnceButtonIndex(1) { | |
454 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS); | 473 DCHECK_EQ(content_type, CONTENT_SETTINGS_TYPE_PLUGINS); |
455 // Disable the "Run all plugins this time" link if the setting is managed and | 474 SetRadioGroup(); |
456 // can't be controlled by the user or if the user already clicked on the link | |
457 // and ran all plugins. | |
458 set_custom_link_enabled(!setting_is_managed() && | |
459 web_contents && | |
460 TabSpecificContentSettings::FromWebContents( | |
461 web_contents)->load_plugins_link_enabled()); | |
462 } | 475 } |
463 | 476 |
464 ContentSettingPluginBubbleModel::~ContentSettingPluginBubbleModel() { | 477 ContentSettingPluginBubbleModel::~ContentSettingPluginBubbleModel() { |
465 if (settings_changed()) { | 478 // If the user elected to allow all plugins then run plugins at this time. |
felt
2014/06/12 17:18:48
If this comment is about the whole method, put it
radhikabhar
2014/06/12 17:44:20
Done.
| |
466 // If the user elected to allow all plugins then run plugins at this time. | 479 if (!settings_changed()) |
467 if (selected_item() == kAllowButtonIndex) | 480 return; |
468 OnCustomLinkClicked(); | 481 ContentSetting setting; |
482 if (selected_item_ == kAllowButtonIndex) { | |
483 setting = CONTENT_SETTING_ALLOW; | |
484 OnRunPlugins(); | |
485 } else if (selected_item_ == kAllowOnceButtonIndex) { | |
486 setting = CONTENT_SETTING_DEFAULT; | |
487 OnRunPlugins(); | |
488 } else { | |
489 setting = block_setting_; | |
490 } | |
491 TabSpecificContentSettings::FromWebContents(web_contents())-> | |
492 set_plugin_bubble_setting(setting); | |
493 if (profile()) { | |
494 profile()->GetHostContentSettingsMap()->AddExceptionForURL( | |
495 bubble_content().radio_group.url, | |
496 bubble_content().radio_group.url, | |
497 content_type(), | |
498 setting); | |
469 } | 499 } |
470 } | 500 } |
471 | 501 |
472 void ContentSettingPluginBubbleModel::OnCustomLinkClicked() { | 502 bool ContentSettingPluginBubbleModel::settings_changed() const { |
503 return selected_item_ != bubble_content().radio_group.default_item; | |
504 } | |
505 | |
506 void ContentSettingPluginBubbleModel::OnRadioClicked(int radio_index) { | |
507 selected_item_ = radio_index; | |
508 } | |
509 | |
510 void ContentSettingPluginBubbleModel::SetRadioGroup() { | |
511 GURL url = web_contents()->GetURL(); | |
512 TabSpecificContentSettings* content_settings = | |
513 TabSpecificContentSettings::FromWebContents(web_contents()); | |
514 bool allowed = | |
515 !content_settings->IsContentBlocked(content_type()); | |
516 DCHECK(!allowed || | |
517 content_settings->IsContentAllowed(content_type())); | |
518 RadioGroup radio_group; | |
519 radio_group.url = url; | |
520 | |
521 std::string radio_allow_label = | |
522 l10n_util::GetStringUTF8(IDS_BLOCKED_PLUGINS_UNBLOCK_ALL); | |
523 std::string radio_allow_once_label = | |
524 l10n_util::GetStringUTF8(IDS_BLOCKED_PLUGINS_LOAD_ALL); | |
525 std::string radio_block_label = | |
526 l10n_util::GetStringUTF8(IDS_BLOCKED_PLUGINS_NO_ACTION); | |
527 | |
528 radio_group.radio_items.push_back(radio_allow_label); | |
529 radio_group.radio_items.push_back(radio_allow_once_label); | |
530 radio_group.radio_items.push_back(radio_block_label); | |
531 | |
532 ContentSetting setting; | |
533 SettingSource setting_source = SETTING_SOURCE_NONE; | |
534 bool setting_is_wildcard = false; | |
535 SettingInfo info; | |
536 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); | |
537 scoped_ptr<base::Value> value(map->GetWebsiteSetting( | |
538 url, url, content_type(), std::string(), &info)); | |
539 setting = content_settings->plugin_bubble_setting(); | |
540 setting_source = info.source; | |
541 setting_is_wildcard = | |
542 info.primary_pattern == ContentSettingsPattern::Wildcard() && | |
543 info.secondary_pattern == ContentSettingsPattern::Wildcard(); | |
544 | |
545 if (setting == CONTENT_SETTING_ALLOW && setting_is_wildcard) { | |
546 // In the corner case of unrecognized plugins (which are now blocked by | |
547 // default) we indicate the blocked state in the UI and allow the user to | |
548 // whitelist. | |
549 radio_group.default_item = 2; | |
550 } else if (setting == CONTENT_SETTING_ALLOW) { | |
551 radio_group.default_item = kAllowButtonIndex; | |
552 } else if (setting == CONTENT_SETTING_DEFAULT) { | |
553 radio_group.default_item = kAllowOnceButtonIndex; | |
554 // |block_setting_| is already set to |CONTENT_SETTING_BLOCK|. | |
555 } else { | |
556 radio_group.default_item = 2; | |
557 block_setting_ = setting; | |
558 } | |
559 | |
560 set_setting_is_managed(setting_source != SETTING_SOURCE_USER); | |
561 if (setting_source != SETTING_SOURCE_USER) { | |
562 set_radio_group_enabled(false); | |
563 } else { | |
564 set_radio_group_enabled(true); | |
565 } | |
566 selected_item_ = radio_group.default_item; | |
567 set_radio_group(radio_group); | |
568 } | |
569 | |
570 void ContentSettingPluginBubbleModel::OnRunPlugins() { | |
473 content::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble")); | 571 content::RecordAction(UserMetricsAction("ClickToPlay_LoadAll_Bubble")); |
474 DCHECK(web_contents()); | 572 DCHECK(web_contents()); |
475 #if defined(ENABLE_PLUGINS) | 573 #if defined(ENABLE_PLUGINS) |
476 // TODO(bauerb): We should send the identifiers of blocked plug-ins here. | 574 // TODO(bauerb): We should send the identifiers of blocked plug-ins here. |
477 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( | 575 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( |
478 web_contents(), true, std::string()); | 576 web_contents(), true, std::string()); |
479 #endif | 577 #endif |
480 set_custom_link_enabled(false); | |
481 TabSpecificContentSettings::FromWebContents(web_contents())-> | |
482 set_load_plugins_link_enabled(false); | |
483 } | 578 } |
484 | 579 |
485 class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup { | 580 class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup { |
486 public: | 581 public: |
487 ContentSettingPopupBubbleModel(Delegate* delegate, | 582 ContentSettingPopupBubbleModel(Delegate* delegate, |
488 WebContents* web_contents, | 583 WebContents* web_contents, |
489 Profile* profile, | 584 Profile* profile, |
490 ContentSettingsType content_type); | 585 ContentSettingsType content_type); |
491 virtual ~ContentSettingPopupBubbleModel() {} | 586 virtual ~ContentSettingPopupBubbleModel() {} |
492 | 587 |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1306 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { | 1401 if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { |
1307 DCHECK_EQ(web_contents_, | 1402 DCHECK_EQ(web_contents_, |
1308 content::Source<WebContents>(source).ptr()); | 1403 content::Source<WebContents>(source).ptr()); |
1309 web_contents_ = NULL; | 1404 web_contents_ = NULL; |
1310 } else { | 1405 } else { |
1311 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 1406 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); |
1312 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); | 1407 DCHECK_EQ(profile_, content::Source<Profile>(source).ptr()); |
1313 profile_ = NULL; | 1408 profile_ = NULL; |
1314 } | 1409 } |
1315 } | 1410 } |
OLD | NEW |