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
|
// 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/browser/views/cookie_prompt_view.h"
#include "chrome/common/pref_names.h"
// Cookies
CookiePromptModalDialog::CookiePromptModalDialog(
TabContents* tab_contents,
const GURL& origin,
const std::string& cookie_line,
CookiePromptModalDialogDelegate* delegate)
: AppModalDialog(tab_contents, std::wstring()),
dialog_type_(DIALOG_TYPE_COOKIE),
origin_(origin),
cookie_line_(cookie_line),
delegate_(delegate) {
}
// LocalStorage
CookiePromptModalDialog::CookiePromptModalDialog(
TabContents* tab_contents,
const GURL& origin,
const string16& key,
const string16& value,
CookiePromptModalDialogDelegate* delegate)
: AppModalDialog(tab_contents, std::wstring()),
dialog_type_(DIALOG_TYPE_LOCAL_STORAGE),
origin_(origin),
local_storage_key_(key),
local_storage_value_(value),
delegate_(delegate) {
}
// Database
CookiePromptModalDialog::CookiePromptModalDialog(
TabContents* tab_contents,
const GURL& origin,
const string16& database_name,
CookiePromptModalDialogDelegate* delegate)
: AppModalDialog(tab_contents, std::wstring()),
dialog_type_(DIALOG_TYPE_DATABASE),
origin_(origin),
database_name_(database_name),
delegate_(delegate) {
}
bool CookiePromptModalDialog::IsValid() {
HostContentSettingsMap* host_content_settings_map =
tab_contents()->profile()->GetHostContentSettingsMap();
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) {
AllowSiteData(false, false);
} else {
DCHECK(content_setting == CONTENT_SETTING_BLOCK);
BlockSiteData(false);
}
return false;
}
return true;
}
void CookiePromptModalDialog::AllowSiteData(bool remember,
bool session_expire) {
delegate_->AllowSiteData(remember, session_expire);
delegate_ = NULL; // It can be deleted at any point now.
}
void CookiePromptModalDialog::BlockSiteData(bool remember) {
delegate_->BlockSiteData(remember);
delegate_ = NULL; // It can be deleted at any point now.
}
// static
void CookiePromptModalDialog::RegisterPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(prefs::kCookiePromptExpanded, false);
}
|