1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/cookie_modal_dialog.h"
#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/pref_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/pref_names.h"
// Cookies
CookiePromptModalDialog::CookiePromptModalDialog(
TabContents* tab_contents,
HostContentSettingsMap* host_content_settings_map,
const GURL& origin,
const std::string& cookie_line,
CookiePromptModalDialogDelegate* delegate)
: AppModalDialog(tab_contents, std::wstring()),
host_content_settings_map_(host_content_settings_map),
dialog_type_(DIALOG_TYPE_COOKIE),
origin_(origin),
cookie_line_(cookie_line),
delegate_(delegate) {
}
// LocalStorage
CookiePromptModalDialog::CookiePromptModalDialog(
TabContents* tab_contents,
HostContentSettingsMap* host_content_settings_map,
const GURL& origin,
const string16& key,
const string16& value,
CookiePromptModalDialogDelegate* delegate)
: AppModalDialog(tab_contents, std::wstring()),
host_content_settings_map_(host_content_settings_map),
dialog_type_(DIALOG_TYPE_LOCAL_STORAGE),
origin_(origin),
local_storage_key_(key),
local_storage_value_(value),
delegate_(delegate) {
}
// Database
CookiePromptModalDialog::CookiePromptModalDialog(
TabContents* tab_contents,
HostContentSettingsMap* host_content_settings_map,
const GURL& origin,
const string16& database_name,
CookiePromptModalDialogDelegate* delegate)
: AppModalDialog(tab_contents, std::wstring()),
host_content_settings_map_(host_content_settings_map),
dialog_type_(DIALOG_TYPE_DATABASE),
origin_(origin),
database_name_(database_name),
delegate_(delegate) {
}
CookiePromptModalDialog::~CookiePromptModalDialog() {
}
bool CookiePromptModalDialog::IsValid() {
ContentSetting content_setting =
host_content_settings_map_->GetContentSetting(
origin_, CONTENT_SETTINGS_TYPE_COOKIES);
if (content_setting != CONTENT_SETTING_ASK) {
if (content_setting == CONTENT_SETTING_ALLOW) {
// If it's remembered as allow, then we assume session_expire is false.
AllowSiteData(false, false);
} else {
DCHECK(content_setting == CONTENT_SETTING_BLOCK);
BlockSiteData(false);
}
return false;
}
return !skip_this_dialog_;
}
void CookiePromptModalDialog::AllowSiteData(bool remember,
bool session_expire) {
if (remember) {
host_content_settings_map_->SetContentSetting(
origin_.host(), CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_ALLOW);
}
if (delegate_) {
delegate_->AllowSiteData(session_expire);
delegate_ = NULL; // It can be deleted at any point now.
}
}
void CookiePromptModalDialog::BlockSiteData(bool remember) {
if (remember) {
host_content_settings_map_->SetContentSetting(
origin_.host(), CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
}
if (delegate_) {
delegate_->BlockSiteData();
delegate_ = NULL; // It can be deleted at any point now.
}
}
// static
void CookiePromptModalDialog::RegisterPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(prefs::kCookiePromptExpanded, false);
}
|