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

Side by Side Diff: chrome/browser/cookie_modal_dialog.cc

Issue 651023: Pass in the HostContentSettingsMap to the CookieModalDialog so IsValid can ma... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/cookie_modal_dialog.h" 5 #include "chrome/browser/cookie_modal_dialog.h"
6 6
7 #include "chrome/browser/host_content_settings_map.h" 7 #include "chrome/browser/host_content_settings_map.h"
8 #include "chrome/browser/pref_service.h" 8 #include "chrome/browser/pref_service.h"
9 #include "chrome/browser/profile.h" 9 #include "chrome/browser/profile.h"
10 #include "chrome/browser/tab_contents/tab_contents.h" 10 #include "chrome/browser/tab_contents/tab_contents.h"
11 #include "chrome/browser/views/cookie_prompt_view.h" 11 #include "chrome/browser/views/cookie_prompt_view.h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 13
14 // Cookies 14 // Cookies
15 CookiePromptModalDialog::CookiePromptModalDialog( 15 CookiePromptModalDialog::CookiePromptModalDialog(
16 TabContents* tab_contents, 16 TabContents* tab_contents,
17 HostContentSettingsMap* host_content_settings_map,
17 const GURL& origin, 18 const GURL& origin,
18 const std::string& cookie_line, 19 const std::string& cookie_line,
19 CookiePromptModalDialogDelegate* delegate) 20 CookiePromptModalDialogDelegate* delegate)
20 : AppModalDialog(tab_contents, std::wstring()), 21 : AppModalDialog(tab_contents, std::wstring()),
22 host_content_settings_map_(host_content_settings_map),
21 dialog_type_(DIALOG_TYPE_COOKIE), 23 dialog_type_(DIALOG_TYPE_COOKIE),
22 origin_(origin), 24 origin_(origin),
23 cookie_line_(cookie_line), 25 cookie_line_(cookie_line),
24 delegate_(delegate) { 26 delegate_(delegate) {
25 } 27 }
26 28
27 // LocalStorage 29 // LocalStorage
28 CookiePromptModalDialog::CookiePromptModalDialog( 30 CookiePromptModalDialog::CookiePromptModalDialog(
29 TabContents* tab_contents, 31 TabContents* tab_contents,
32 HostContentSettingsMap* host_content_settings_map,
30 const GURL& origin, 33 const GURL& origin,
31 const string16& key, 34 const string16& key,
32 const string16& value, 35 const string16& value,
33 CookiePromptModalDialogDelegate* delegate) 36 CookiePromptModalDialogDelegate* delegate)
34 : AppModalDialog(tab_contents, std::wstring()), 37 : AppModalDialog(tab_contents, std::wstring()),
38 host_content_settings_map_(host_content_settings_map),
35 dialog_type_(DIALOG_TYPE_LOCAL_STORAGE), 39 dialog_type_(DIALOG_TYPE_LOCAL_STORAGE),
36 origin_(origin), 40 origin_(origin),
37 local_storage_key_(key), 41 local_storage_key_(key),
38 local_storage_value_(value), 42 local_storage_value_(value),
39 delegate_(delegate) { 43 delegate_(delegate) {
40 } 44 }
41 45
42 // Database 46 // Database
43 CookiePromptModalDialog::CookiePromptModalDialog( 47 CookiePromptModalDialog::CookiePromptModalDialog(
44 TabContents* tab_contents, 48 TabContents* tab_contents,
49 HostContentSettingsMap* host_content_settings_map,
45 const GURL& origin, 50 const GURL& origin,
46 const string16& database_name, 51 const string16& database_name,
47 CookiePromptModalDialogDelegate* delegate) 52 CookiePromptModalDialogDelegate* delegate)
48 : AppModalDialog(tab_contents, std::wstring()), 53 : AppModalDialog(tab_contents, std::wstring()),
54 host_content_settings_map_(host_content_settings_map),
49 dialog_type_(DIALOG_TYPE_DATABASE), 55 dialog_type_(DIALOG_TYPE_DATABASE),
50 origin_(origin), 56 origin_(origin),
51 database_name_(database_name), 57 database_name_(database_name),
52 delegate_(delegate) { 58 delegate_(delegate) {
53 } 59 }
54 60
61 CookiePromptModalDialog::~CookiePromptModalDialog() {
62 }
63
55 bool CookiePromptModalDialog::IsValid() { 64 bool CookiePromptModalDialog::IsValid() {
56 HostContentSettingsMap* host_content_settings_map =
57 tab_contents()->profile()->GetHostContentSettingsMap();
58 ContentSetting content_setting = 65 ContentSetting content_setting =
59 host_content_settings_map->GetContentSetting( 66 host_content_settings_map_->GetContentSetting(
60 origin(), 67 origin_, CONTENT_SETTINGS_TYPE_COOKIES);
61 CONTENT_SETTINGS_TYPE_COOKIES);
62 if (content_setting != CONTENT_SETTING_ASK) { 68 if (content_setting != CONTENT_SETTING_ASK) {
63 if (content_setting == CONTENT_SETTING_ALLOW) { 69 if (content_setting == CONTENT_SETTING_ALLOW) {
70 // If it's remembered as allow, then we assume session_expire is false.
64 AllowSiteData(false, false); 71 AllowSiteData(false, false);
65 } else { 72 } else {
66 DCHECK(content_setting == CONTENT_SETTING_BLOCK); 73 DCHECK(content_setting == CONTENT_SETTING_BLOCK);
67 BlockSiteData(false); 74 BlockSiteData(false);
68 } 75 }
69 return false; 76 return false;
70 } 77 }
71 return true; 78 return !skip_this_dialog_;
72 } 79 }
73 80
74 void CookiePromptModalDialog::AllowSiteData(bool remember, 81 void CookiePromptModalDialog::AllowSiteData(bool remember,
75 bool session_expire) { 82 bool session_expire) {
83 if (remember) {
84 host_content_settings_map_->SetContentSetting(
85 origin_.host(), CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_ALLOW);
86 }
87
76 if (delegate_) { 88 if (delegate_) {
77 delegate_->AllowSiteData(remember, session_expire); 89 delegate_->AllowSiteData(session_expire);
78 delegate_ = NULL; // It can be deleted at any point now. 90 delegate_ = NULL; // It can be deleted at any point now.
79 } 91 }
80 } 92 }
81 93
82 void CookiePromptModalDialog::BlockSiteData(bool remember) { 94 void CookiePromptModalDialog::BlockSiteData(bool remember) {
95 if (remember) {
96 host_content_settings_map_->SetContentSetting(
97 origin_.host(), CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
98 }
99
83 if (delegate_) { 100 if (delegate_) {
84 delegate_->BlockSiteData(remember); 101 delegate_->BlockSiteData();
85 delegate_ = NULL; // It can be deleted at any point now. 102 delegate_ = NULL; // It can be deleted at any point now.
86 } 103 }
87 } 104 }
88 105
89 // static 106 // static
90 void CookiePromptModalDialog::RegisterPrefs(PrefService* prefs) { 107 void CookiePromptModalDialog::RegisterPrefs(PrefService* prefs) {
91 prefs->RegisterBooleanPref(prefs::kCookiePromptExpanded, false); 108 prefs->RegisterBooleanPref(prefs::kCookiePromptExpanded, false);
92 } 109 }
OLDNEW
« no previous file with comments | « chrome/browser/cookie_modal_dialog.h ('k') | chrome/browser/cookie_prompt_modal_dialog_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698