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
|
// 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,
const string16& display_name,
unsigned long estimated_size,
Task* on_allow,
Task* on_block,
HostContentSettingsMap* settings_map)
: url_(url),
database_name_(database_name),
display_name_(display_name),
estimated_size_(estimated_size),
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);
return;
}
Browser* browser = BrowserList::GetLastActive();
if (!browser || !browser->GetSelectedTabContents()) {
BlockSiteData();
return;
}
self_ref_ = this;
// Will call either AllowSiteData or BlockSiteData which will NULL out our
// self reference.
RunDatabasePrompt(browser->GetSelectedTabContents(),
host_content_settings_map_, url_, database_name_,
display_name_, estimated_size_, this);
}
void DatabasePermissionRequest::AllowSiteData(bool session_expire) {
SendResponse(CONTENT_SETTING_ALLOW);
}
void DatabasePermissionRequest::BlockSiteData() {
SendResponse(CONTENT_SETTING_BLOCK);
}
void DatabasePermissionRequest::SendResponse(ContentSetting 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());
}
|