#include <string>
#include <vector>
+#include "atom/browser/atom_browser_context.h"
+#include "atom/browser/browser.h"
+#include "atom/common/native_mate_converters/file_path_converter.h"
+#include "atom/common/native_mate_converters/gurl_converter.h"
#include "base/values.h"
#include "base/command_line.h"
#include "base/environment.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
-#include "atom/browser/browser.h"
+#include "native_mate/callback.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
+#include "net/proxy/proxy_service.h"
+#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_context_getter.h"
#include "atom/common/node_includes.h"
namespace api {
+namespace {
+
+class ResolveProxyHelper {
+ public:
+ ResolveProxyHelper(const GURL& url, App::ResolveProxyCallback callback)
+ : callback_(callback) {
+ net::ProxyService* proxy_service = AtomBrowserContext::Get()->
+ url_request_context_getter()->GetURLRequestContext()->proxy_service();
+
+ // Start the request.
+ int result = proxy_service->ResolveProxy(
+ url, &proxy_info_,
+ base::Bind(&ResolveProxyHelper::OnResolveProxyCompleted,
+ base::Unretained(this)),
+ &pac_req_, net::BoundNetLog());
+
+ // Completed synchronously.
+ if (result != net::ERR_IO_PENDING)
+ OnResolveProxyCompleted(result);
+ }
+
+ void OnResolveProxyCompleted(int result) {
+ std::string proxy;
+ if (result == net::OK)
+ proxy = proxy_info_.ToPacString();
+ callback_.Run(proxy);
+
+ delete this;
+ }
+
+ private:
+ App::ResolveProxyCallback callback_;
+ net::ProxyInfo proxy_info_;
+ net::ProxyService::PacRequest* pac_req_;
+
+ DISALLOW_COPY_AND_ASSIGN(ResolveProxyHelper);
+};
+
+} // namespace
+
App::App() {
Browser::Get()->AddObserver(this);
}
base::nix::kXdgConfigHomeEnvVar,
base::nix::kDotConfigDir);
#else
- CHECK(PathService::Get(base::DIR_APP_DATA, &path));
+ PathService::Get(base::DIR_APP_DATA, &path);
#endif
return path.Append(base::FilePath::FromUTF8Unsafe(
Browser::Get()->GetName()));
}
+void App::ResolveProxy(const GURL& url, ResolveProxyCallback callback) {
+ new ResolveProxyHelper(url, callback);
+}
+
mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
Browser* browser = Browser::Get();
base::Unretained(browser)))
.SetMethod("setName", base::Bind(&Browser::SetName,
base::Unretained(browser)))
- .SetMethod("getDataPath", &App::GetDataPath);
+ .SetMethod("getDataPath", &App::GetDataPath)
+ .SetMethod("resolveProxy", &App::ResolveProxy);
}
// static
#include <string>
-#include "base/compiler_specific.h"
#include "atom/browser/api/event_emitter.h"
#include "atom/browser/browser_observer.h"
-#include "atom/common/native_mate_converters/file_path_converter.h"
+#include "base/callback.h"
#include "native_mate/handle.h"
+class GURL;
+
+namespace base {
+class FilePath;
+}
+
namespace atom {
namespace api {
class App : public mate::EventEmitter,
public BrowserObserver {
public:
+ typedef base::Callback<void(std::string)> ResolveProxyCallback;
+
static mate::Handle<App> Create(v8::Isolate* isolate);
protected:
virtual void OnActivateWithNoOpenWindows() OVERRIDE;
virtual void OnWillFinishLaunching() OVERRIDE;
virtual void OnFinishLaunching() OVERRIDE;
- virtual base::FilePath GetDataPath();
// mate::Wrappable implementations:
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
v8::Isolate* isolate);
private:
+ base::FilePath GetDataPath();
+ void ResolveProxy(const GURL& url, ResolveProxyCallback callback);
+
DISALLOW_COPY_AND_ASSIGN(App);
};