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

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

Issue 3299020: Remove vestigial cookie/web app permissions prompting UI now that the async U... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/cookie_modal_dialog.h"
6
7 #include "app/message_box_flags.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/host_content_settings_map.h"
10 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/profile.h"
12 #include "chrome/browser/tab_contents/tab_contents.h"
13 #include "chrome/common/pref_names.h"
14
15 // Cookies
16 CookiePromptModalDialog::CookiePromptModalDialog(
17 TabContents* tab_contents,
18 HostContentSettingsMap* host_content_settings_map,
19 const GURL& origin,
20 const std::string& cookie_line,
21 CookiePromptModalDialogDelegate* delegate)
22 : AppModalDialog(tab_contents, std::wstring()),
23 host_content_settings_map_(host_content_settings_map),
24 dialog_type_(DIALOG_TYPE_COOKIE),
25 origin_(origin),
26 cookie_line_(cookie_line),
27 estimated_size_(0),
28 delegate_(delegate) {
29 }
30
31 // LocalStorage
32 CookiePromptModalDialog::CookiePromptModalDialog(
33 TabContents* tab_contents,
34 HostContentSettingsMap* host_content_settings_map,
35 const GURL& origin,
36 const string16& key,
37 const string16& value,
38 CookiePromptModalDialogDelegate* delegate)
39 : AppModalDialog(tab_contents, std::wstring()),
40 host_content_settings_map_(host_content_settings_map),
41 dialog_type_(DIALOG_TYPE_LOCAL_STORAGE),
42 origin_(origin),
43 local_storage_key_(key),
44 local_storage_value_(value),
45 estimated_size_(0),
46 delegate_(delegate) {
47 }
48
49 // Database
50 CookiePromptModalDialog::CookiePromptModalDialog(
51 TabContents* tab_contents,
52 HostContentSettingsMap* host_content_settings_map,
53 const GURL& origin,
54 const string16& database_name,
55 const string16& display_name,
56 unsigned long estimated_size,
57 CookiePromptModalDialogDelegate* delegate)
58 : AppModalDialog(tab_contents, std::wstring()),
59 host_content_settings_map_(host_content_settings_map),
60 dialog_type_(DIALOG_TYPE_DATABASE),
61 origin_(origin),
62 database_name_(database_name),
63 display_name_(display_name),
64 estimated_size_(estimated_size),
65 delegate_(delegate) {
66 }
67
68 // AppCache
69 CookiePromptModalDialog::CookiePromptModalDialog(
70 TabContents* tab_contents,
71 HostContentSettingsMap* host_content_settings_map,
72 const GURL& appcache_manifest_url,
73 CookiePromptModalDialogDelegate* delegate)
74 : AppModalDialog(tab_contents, std::wstring()),
75 host_content_settings_map_(host_content_settings_map),
76 dialog_type_(DIALOG_TYPE_APPCACHE),
77 origin_(appcache_manifest_url.GetOrigin()),
78 estimated_size_(0),
79 appcache_manifest_url_(appcache_manifest_url),
80 delegate_(delegate) {
81 }
82
83 CookiePromptModalDialog::~CookiePromptModalDialog() {
84 }
85
86 bool CookiePromptModalDialog::IsValid() {
87 ContentSetting content_setting =
88 host_content_settings_map_->GetContentSetting(
89 origin_, CONTENT_SETTINGS_TYPE_COOKIES, "");
90 if (content_setting != CONTENT_SETTING_ASK) {
91 if (content_setting == CONTENT_SETTING_ALLOW) {
92 AllowSiteData(false, false);
93 } else if (content_setting == CONTENT_SETTING_SESSION_ONLY) {
94 AllowSiteData(false, true);
95 } else {
96 DCHECK(content_setting == CONTENT_SETTING_BLOCK);
97 BlockSiteData(false);
98 }
99 return false;
100 }
101 return !skip_this_dialog_;
102 }
103
104 void CookiePromptModalDialog::AllowSiteData(bool remember,
105 bool session_expire) {
106 if (remember) {
107 // Make sure there is no entry that would override the pattern we are about
108 // to insert for exactly this URL.
109 host_content_settings_map_->SetContentSetting(
110 HostContentSettingsMap::Pattern::FromURLNoWildcard(origin_),
111 CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_DEFAULT);
112 host_content_settings_map_->SetContentSetting(
113 HostContentSettingsMap::Pattern::FromURL(origin_),
114 CONTENT_SETTINGS_TYPE_COOKIES,
115 "",
116 session_expire ? CONTENT_SETTING_SESSION_ONLY : CONTENT_SETTING_ALLOW);
117 }
118
119 if (delegate_) {
120 delegate_->AllowSiteData(session_expire);
121 delegate_ = NULL; // It can be deleted at any point now.
122 }
123 }
124
125 void CookiePromptModalDialog::BlockSiteData(bool remember) {
126 if (remember) {
127 // Make sure there is no entry that would override the pattern we are about
128 // to insert for exactly this URL.
129 host_content_settings_map_->SetContentSetting(
130 HostContentSettingsMap::Pattern::FromURLNoWildcard(origin_),
131 CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_DEFAULT);
132 host_content_settings_map_->SetContentSetting(
133 HostContentSettingsMap::Pattern::FromURL(origin_),
134 CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_BLOCK);
135 }
136
137 if (delegate_) {
138 delegate_->BlockSiteData();
139 delegate_ = NULL; // It can be deleted at any point now.
140 }
141 }
142
143 // static
144 void CookiePromptModalDialog::RegisterUserPrefs(PrefService* prefs) {
145 prefs->RegisterBooleanPref(prefs::kCookiePromptExpanded, false);
146 }
147
148 int CookiePromptModalDialog::GetDialogButtons() {
149 // Enable the automation interface to accept/dismiss this dialog.
150 return MessageBoxFlags::DIALOGBUTTON_OK |
151 MessageBoxFlags::DIALOGBUTTON_CANCEL;
152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698