diff --git a/atom/browser/api/atom_api_protocol.cc b/atom/browser/api/atom_api_protocol.cc index 0bd6728b4c..366b6732d9 100644 --- a/atom/browser/api/atom_api_protocol.cc +++ b/atom/browser/api/atom_api_protocol.cc @@ -7,8 +7,9 @@ #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" @@ -48,6 +49,8 @@ mate::ObjectTemplateBuilder Protocol::GetObjectTemplateBuilder( .SetMethod("registerStandardSchemes", &Protocol::RegisterStandardSchemes) .SetMethod("registerStringProtocol", &Protocol::RegisterProtocol) + .SetMethod("registerBufferProtocol", + &Protocol::RegisterProtocol) .SetMethod("registerFileProtocol", &Protocol::RegisterProtocol); } diff --git a/atom/browser/lib/chrome-extension.coffee b/atom/browser/lib/chrome-extension.coffee index ccb52d37a4..df0d717cd9 100644 --- a/atom/browser/lib/chrome-extension.coffee +++ b/atom/browser/lib/chrome-extension.coffee @@ -72,8 +72,8 @@ app.once 'ready', -> 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)});" diff --git a/atom/browser/net/url_request_buffer_job.cc b/atom/browser/net/url_request_buffer_job.cc index a8233b88da..5cfb60a750 100644 --- a/atom/browser/net/url_request_buffer_job.cc +++ b/atom/browser/net/url_request_buffer_job.cc @@ -13,13 +13,34 @@ namespace atom { URLRequestBufferJob::URLRequestBufferJob( net::URLRequest* request, net::NetworkDelegate* network_delegate, - const std::string& mime_type, - const std::string& charset, - scoped_refptr data) - : net::URLRequestSimpleJob(request, network_delegate), - mime_type_(mime_type), - charset_(charset), - buffer_data_(data) { + v8::Isolate* isolate, + const JavaScriptHandler& handler) + : JsAsker(request, network_delegate, isolate, + handler) { +} + +void URLRequestBufferJob::StartAsync(scoped_ptr options) { + const base::BinaryValue* binary = nullptr; + if (options->IsType(base::Value::TYPE_DICTIONARY)) { + base::DictionaryValue* dict = + static_cast(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(binary->GetBuffer()), + binary->GetSize()); + net::URLRequestSimpleJob::Start(); } int URLRequestBufferJob::GetRefCountedData( @@ -29,7 +50,7 @@ int URLRequestBufferJob::GetRefCountedData( const net::CompletionCallback& callback) const { *mime_type = mime_type_; *charset = charset_; - *data = buffer_data_; + *data = data_; return net::OK; } diff --git a/atom/browser/net/url_request_buffer_job.h b/atom/browser/net/url_request_buffer_job.h index cbdfbfa10d..c72e5b8385 100644 --- a/atom/browser/net/url_request_buffer_job.h +++ b/atom/browser/net/url_request_buffer_job.h @@ -7,19 +7,22 @@ #include +#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 { public: URLRequestBufferJob(net::URLRequest* request, net::NetworkDelegate* network_delegate, - const std::string& mime_type, - const std::string& charset, - scoped_refptr data); + v8::Isolate* isolate, + const JavaScriptHandler& handler); + + // JsAsker: + void StartAsync(scoped_ptr options) override; // URLRequestSimpleJob: int GetRefCountedData(std::string* mime_type, @@ -30,7 +33,7 @@ class URLRequestBufferJob : public net::URLRequestSimpleJob { private: std::string mime_type_; std::string charset_; - scoped_refptr buffer_data_; + scoped_refptr data_; DISALLOW_COPY_AND_ASSIGN(URLRequestBufferJob); };