#include "atom/browser/atom_browser_client.h"
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/atom_browser_main_parts.h"
-#include "atom/browser/net/url_request_string_job.h"
#include "atom/browser/net/url_request_async_asar_job.h"
+#include "atom/browser/net/url_request_buffer_job.h"
+#include "atom/browser/net/url_request_string_job.h"
#include "atom/common/native_mate_converters/callback.h"
#include "native_mate/dictionary.h"
.SetMethod("registerStandardSchemes", &Protocol::RegisterStandardSchemes)
.SetMethod("registerStringProtocol",
&Protocol::RegisterProtocol<URLRequestStringJob>)
+ .SetMethod("registerBufferProtocol",
+ &Protocol::RegisterProtocol<URLRequestBufferJob>)
.SetMethod("registerFileProtocol",
&Protocol::RegisterProtocol<UrlRequestAsyncAsarJob>);
}
directory = getPathForHost parsed.hostname
return callback() unless directory?
callback path.join(directory, parsed.path)
- protocol.registerFileProtocol 'chrome-extension', chromeExtensionHandler, ->
- console.error 'Unable to register chrome-extension protocol'
+ protocol.registerFileProtocol 'chrome-extension', chromeExtensionHandler, (error) ->
+ console.error 'Unable to register chrome-extension protocol' if error
BrowserWindow::_loadDevToolsExtensions = (extensionInfoArray) ->
@devToolsWebContents?.executeJavaScript "DevToolsAPI.addExtensions(#{JSON.stringify(extensionInfoArray)});"
URLRequestBufferJob::URLRequestBufferJob(
net::URLRequest* request,
net::NetworkDelegate* network_delegate,
- const std::string& mime_type,
- const std::string& charset,
- scoped_refptr<base::RefCountedBytes> data)
- : net::URLRequestSimpleJob(request, network_delegate),
- mime_type_(mime_type),
- charset_(charset),
- buffer_data_(data) {
+ v8::Isolate* isolate,
+ const JavaScriptHandler& handler)
+ : JsAsker<net::URLRequestSimpleJob>(request, network_delegate, isolate,
+ handler) {
+}
+
+void URLRequestBufferJob::StartAsync(scoped_ptr<base::Value> options) {
+ const base::BinaryValue* binary = nullptr;
+ if (options->IsType(base::Value::TYPE_DICTIONARY)) {
+ base::DictionaryValue* dict =
+ static_cast<base::DictionaryValue*>(options.get());
+ dict->GetString("mimeType", &mime_type_);
+ dict->GetString("charset", &charset_);
+ dict->GetBinary("data", &binary);
+ } else if (options->IsType(base::Value::TYPE_BINARY)) {
+ options->GetAsBinary(&binary);
+ }
+
+ if (!binary) {
+ NotifyStartError(net::URLRequestStatus(
+ net::URLRequestStatus::FAILED, net::ERR_NOT_IMPLEMENTED));
+ return;
+ }
+
+ data_ = new base::RefCountedBytes(
+ reinterpret_cast<const unsigned char*>(binary->GetBuffer()),
+ binary->GetSize());
+ net::URLRequestSimpleJob::Start();
}
int URLRequestBufferJob::GetRefCountedData(
const net::CompletionCallback& callback) const {
*mime_type = mime_type_;
*charset = charset_;
- *data = buffer_data_;
+ *data = data_;
return net::OK;
}
#include <string>
+#include "atom/browser/net/js_asker.h"
+#include "atom/common/node_includes.h"
#include "base/memory/ref_counted_memory.h"
#include "net/url_request/url_request_simple_job.h"
-#include "atom/common/node_includes.h"
namespace atom {
-class URLRequestBufferJob : public net::URLRequestSimpleJob {
+class URLRequestBufferJob : public JsAsker<net::URLRequestSimpleJob> {
public:
URLRequestBufferJob(net::URLRequest* request,
net::NetworkDelegate* network_delegate,
- const std::string& mime_type,
- const std::string& charset,
- scoped_refptr<base::RefCountedBytes> data);
+ v8::Isolate* isolate,
+ const JavaScriptHandler& handler);
+
+ // JsAsker:
+ void StartAsync(scoped_ptr<base::Value> options) override;
// URLRequestSimpleJob:
int GetRefCountedData(std::string* mime_type,
private:
std::string mime_type_;
std::string charset_;
- scoped_refptr<base::RefCountedBytes> buffer_data_;
+ scoped_refptr<base::RefCountedBytes> data_;
DISALLOW_COPY_AND_ASSIGN(URLRequestBufferJob);
};