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
|
// 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/renderer_host/database_permission_request.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/message_box_handler.h"
DatabasePermissionRequest::DatabasePermissionRequest(
const GURL& url,
const string16& database_name,
Task* on_allow,
Task* on_block,
HostContentSettingsMap* settings_map)
: url_(url),
database_name_(database_name),
on_allow_(on_allow),
on_block_(on_block),
host_content_settings_map_(settings_map) {
DCHECK(on_allow_.get());
DCHECK(on_block_.get());
}
DatabasePermissionRequest::~DatabasePermissionRequest() {
}
void DatabasePermissionRequest::RequestPermission() {
if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
ChromeThread::PostTask(
ChromeThread::UI, FROM_HERE, NewRunnableMethod(
this, &DatabasePermissionRequest::RequestPermission));
return;
}
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
// Cookie settings may have changed.
ContentSetting setting = host_content_settings_map_->GetContentSetting(
url_, CONTENT_SETTINGS_TYPE_COOKIES);
if (setting != CONTENT_SETTING_ASK) {
SendResponse(setting, false);
return;
}
Browser* browser = BrowserList::GetLastActive();
if (!browser || !browser->GetSelectedTabContents()) {
BlockSiteData(false);
return;
}
#if defined(OS_WIN)
self_ref_ = this;
// Will call either AllowSiteData or BlockSiteData which will NULL out our
// self reference.
RunDatabasePrompt(browser->GetSelectedTabContents(), url_,
database_name_, this);
#else
// TODO(jorlow): Enable prompting for other ports.
BlockSiteData(false);
#endif
}
void DatabasePermissionRequest::AllowSiteData(bool remember,
bool session_expire) {
SendResponse(CONTENT_SETTING_ALLOW, remember);
}
void DatabasePermissionRequest::BlockSiteData(bool remember) {
SendResponse(CONTENT_SETTING_BLOCK, remember);
}
void DatabasePermissionRequest::SendResponse(ContentSetting content_setting,
bool remember) {
if (remember) {
host_content_settings_map_->SetContentSetting(
url_.host(), CONTENT_SETTINGS_TYPE_COOKIES, content_setting);
}
if (content_setting == CONTENT_SETTING_ALLOW) {
ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, on_allow_.release());
} else {
DCHECK(content_setting == CONTENT_SETTING_BLOCK);
ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, on_block_.release());
}
// Release all resources.
on_allow_.reset();
on_block_.reset();
// This seems safer than possibly being deleted while in method(s) related to
// this object. Any thread will do, but UI is always around and can be
// posted without locking, so we'll ask it to do the release.
ChromeThread::ReleaseSoon(ChromeThread::UI, FROM_HERE, self_ref_.release());
}
|