This commit is contained in:
Cheng Zhao 2015-12-11 21:14:13 +08:00
Родитель 79a627014c
Коммит 67886cf513
4 изменённых файлов: 27 добавлений и 25 удалений

Просмотреть файл

@ -15,6 +15,21 @@
using content::BrowserThread;
namespace mate {
template<>
struct Converter<extensions::URLPattern> {
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
extensions::URLPattern* out) {
std::string pattern;
if (!ConvertFromV8(isolate, val, &pattern))
return false;
return out->Parse(pattern) == extensions::URLPattern::PARSE_SUCCESS;
}
};
} // namespace mate
namespace atom {
namespace api {
@ -28,9 +43,12 @@ WebRequest::~WebRequest() {
template<AtomNetworkDelegate::EventType type>
void WebRequest::SetListener(mate::Arguments* args) {
scoped_ptr<base::DictionaryValue> filter(new base::DictionaryValue);
args->GetNext(filter.get());
// { urls }.
URLPatterns patterns;
mate::Dictionary dict;
args->GetNext(&dict) && dict.Get("urls", &patterns);
// Function or null.
v8::Local<v8::Value> value;
AtomNetworkDelegate::Listener callback;
if (!args->GetNext(&callback) &&
@ -43,7 +61,7 @@ void WebRequest::SetListener(mate::Arguments* args) {
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&AtomNetworkDelegate::SetListenerInIO,
base::Unretained(delegate),
type, base::Passed(&filter), callback));
type, patterns, callback));
}
// static

Просмотреть файл

@ -167,31 +167,15 @@ AtomNetworkDelegate::AtomNetworkDelegate() {
AtomNetworkDelegate::~AtomNetworkDelegate() {
}
void AtomNetworkDelegate::SetListenerInIO(
EventType type,
scoped_ptr<base::DictionaryValue> filter,
const Listener& callback) {
void AtomNetworkDelegate::SetListenerInIO(EventType type,
const URLPatterns& patterns,
const Listener& callback) {
if (callback.is_null()) {
event_listener_map_.erase(type);
return;
}
ListenerInfo info;
info.callback = callback;
const base::ListValue* url_list = nullptr;
if (filter->GetList("urls", &url_list)) {
for (size_t i = 0; i < url_list->GetSize(); ++i) {
std::string url;
extensions::URLPattern pattern;
if (url_list->GetString(i, &url) &&
pattern.Parse(url) == extensions::URLPattern::PARSE_SUCCESS) {
info.url_patterns.insert(pattern);
}
}
}
event_listener_map_[type] = info;
event_listener_map_[type] = { patterns, callback };
}
int AtomNetworkDelegate::OnBeforeURLRequest(

Просмотреть файл

@ -65,7 +65,7 @@ class AtomNetworkDelegate : public brightray::NetworkDelegate {
~AtomNetworkDelegate() override;
void SetListenerInIO(EventType type,
scoped_ptr<base::DictionaryValue> filter,
const URLPatterns& patterns,
const Listener& callback);
protected:

2
vendor/native_mate поставляемый

@ -1 +1 @@
Subproject commit 5e70868fd0c005dc2c43bea15ca6e93da0b68741
Subproject commit a3dcf8ced663e974ac94ad5e50a1d25a43995a9d