Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Add session method to enable Brotli compression
Browse files Browse the repository at this point in the history
This is needed for brave/browser-laptop#2890.
Maybe it should just be on by default instead of as a session method.

Auditors: @bbondy
  • Loading branch information
diracdeltas committed Aug 2, 2016
1 parent 2b096b7 commit 1cfdc7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions atom/browser/api/atom_api_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ void SetUserAgentInIO(scoped_refptr<net::URLRequestContextGetter> getter,
user_agent));
}

void SetEnableBrotliInIO(scoped_refptr<net::URLRequestContextGetter> getter,
bool enabled) {
getter->GetURLRequestContext()->set_enable_brotli(enabled);
}

} // namespace

namespace mate {
Expand Down Expand Up @@ -508,6 +513,13 @@ std::string Session::GetUserAgent() {
return browser_context_->GetUserAgent();
}

void Session::SetEnableBrotli(bool enabled) {
auto getter = browser_context_->GetRequestContext();
getter->GetNetworkTaskRunner()->PostTask(
FROM_HERE,
base::Bind(&SetEnableBrotliInIO, getter, enabled));
}

v8::Local<v8::Value> Session::Cookies(v8::Isolate* isolate) {
if (cookies_.IsEmpty()) {
auto handle = atom::api::Cookies::Create(isolate, browser_context());
Expand Down Expand Up @@ -605,6 +617,7 @@ void Session::BuildPrototype(v8::Isolate* isolate,
&Session::AllowNTLMCredentialsForDomains)
.SetMethod("setUserAgent", &Session::SetUserAgent)
.SetMethod("getUserAgent", &Session::GetUserAgent)
.SetMethod("setEnableBrotli", &Session::SetEnableBrotli)
.SetMethod("equal", &Session::Equal)
.SetProperty("userPrefs", &Session::UserPrefs)
.SetProperty("cookies", &Session::Cookies)
Expand Down
1 change: 1 addition & 0 deletions atom/browser/api/atom_api_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Session: public mate::TrackableObject<Session>,
void AllowNTLMCredentialsForDomains(const std::string& domains);
void SetUserAgent(const std::string& user_agent, mate::Arguments* args);
std::string GetUserAgent();
void SetEnableBrotli(bool enabled);
v8::Local<v8::Value> Cookies(v8::Isolate* isolate);
v8::Local<v8::Value> Protocol(v8::Isolate* isolate);
v8::Local<v8::Value> WebRequest(v8::Isolate* isolate);
Expand Down

0 comments on commit 1cfdc7d

Please sign in to comment.