#include "content/public/browser/stream_info.h"
#include "net/base/escape.h"
#include "net/ssl/client_cert_store.h"
+#include "net/url_request/url_request.h"
#include "url/gurl.h"
#if defined(USE_NSS_CERTS)
permission_helper->RequestOpenExternalPermission(callback, has_user_gesture);
}
-void OnPdfStreamCreated(const GURL& original_url,
- const content::ResourceRequestInfo::WebContentsGetter&
- web_contents_getter) {
+void OnPdfResourceIntercepted(
+ const GURL& original_url,
+ const content::ResourceRequestInfo::WebContentsGetter&
+ web_contents_getter) {
content::WebContents* web_contents = web_contents_getter.Run();
if (!web_contents)
return;
content::ResourceRequestInfo::ForRequest(request);
if (mime_type == "application/pdf" && info->IsMainFrame()) {
*origin = GURL(kPdfViewerUIOrigin);
+ content::BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&OnPdfResourceIntercepted, request->url(),
+ info->GetWebContentsGetterForRequest()));
return true;
}
return false;
}
-void AtomResourceDispatcherHostDelegate::OnStreamCreated(
- net::URLRequest* request,
- std::unique_ptr<content::StreamInfo> stream) {
- const content::ResourceRequestInfo* info =
- content::ResourceRequestInfo::ForRequest(request);
- content::BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&OnPdfStreamCreated, stream->original_url,
- info->GetWebContentsGetterForRequest()));
-}
-
} // namespace atom
const std::string& mime_type,
GURL* origin,
std::string* payload) override;
- void OnStreamCreated(net::URLRequest* request,
- std::unique_ptr<content::StreamInfo> stream) override;
private:
DISALLOW_COPY_AND_ASSIGN(AtomResourceDispatcherHostDelegate);
void PopulateStreamInfo(base::DictionaryValue* stream_info,
content::StreamInfo* stream,
const std::string& original_url) {
- std::unique_ptr<base::DictionaryValue> headers_dict(
- new base::DictionaryValue);
+ auto headers_dict = base::MakeUnique<base::DictionaryValue>();
auto stream_url = stream->handle->GetURL().spec();
CreateResponseHeadersDictionary(stream->response_headers.get(),
headers_dict.get());
} // namespace
PdfViewerHandler::PdfViewerHandler(const std::string& src)
- : stream_(nullptr), original_url_(src), initialized_(true) {}
+ : stream_(nullptr), original_url_(src) {}
PdfViewerHandler::~PdfViewerHandler() {}
void PdfViewerHandler::SetPdfResourceStream(content::StreamInfo* stream) {
stream_ = stream;
- if (!initialized_) {
+ if (!!initialize_callback_id_.get()) {
auto list = base::MakeUnique<base::ListValue>();
list->Set(0, std::move(initialize_callback_id_));
Initialize(list.get());
- initialized_ = true;
}
}
CHECK(args->Get(0, &callback_id));
if (stream_) {
+ CHECK(!initialize_callback_id_.get());
AllowJavascript();
- std::unique_ptr<base::DictionaryValue> stream_info(
- new base::DictionaryValue);
+ auto stream_info = base::MakeUnique<base::DictionaryValue>();
PopulateStreamInfo(stream_info.get(), stream_, original_url_);
ResolveJavascriptCallback(*callback_id, *stream_info);
} else {
initialize_callback_id_ = callback_id->CreateDeepCopy();
- initialized_ = false;
}
}
const base::Value* callback_id;
CHECK(args->Get(0, &callback_id));
- std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue);
+ auto result = base::MakeUnique<base::DictionaryValue>();
// TODO(deepak1556): Generate strings from components/pdf_strings.grdp.
#define SET_STRING(id, resource) result->SetString(id, resource)
SET_STRING("passwordPrompt",
std::unique_ptr<base::Value> initialize_callback_id_;
content::StreamInfo* stream_;
std::string original_url_;
- bool initialized_;
DISALLOW_COPY_AND_ASSIGN(PdfViewerHandler);
};
content::StreamContext* stream_context =
content::GetStreamContextForResourceContext(resource_context);
- std::unique_ptr<content::ResourceHandler> handler(
- new content::StreamResourceHandler(request.get(),
- stream_context->registry(), origin));
+ std::unique_ptr<content::ResourceHandler> handler =
+ base::MakeUnique<content::StreamResourceHandler>(
+ request.get(), stream_context->registry(), origin);
info->set_is_stream(true);
stream_info_.reset(new content::StreamInfo);
stream_info_->handle =