address review comments
This commit is contained in:
parent
80ce60f644
commit
15e2b2335f
5 changed files with 18 additions and 29 deletions
|
@ -14,6 +14,7 @@
|
|||
#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)
|
||||
|
@ -60,9 +61,10 @@ void HandleExternalProtocolInUI(
|
|||
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;
|
||||
|
@ -124,20 +126,13 @@ bool AtomResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
|
|||
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
|
||||
|
|
|
@ -29,8 +29,6 @@ class AtomResourceDispatcherHostDelegate
|
|||
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);
|
||||
|
|
|
@ -45,8 +45,7 @@ void CreateResponseHeadersDictionary(const net::HttpResponseHeaders* headers,
|
|||
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());
|
||||
|
@ -58,17 +57,16 @@ void PopulateStreamInfo(base::DictionaryValue* stream_info,
|
|||
} // 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,15 +108,14 @@ void PdfViewerHandler::Initialize(const base::ListValue* args) {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,7 +169,7 @@ void PdfViewerHandler::GetStrings(const base::ListValue* args) {
|
|||
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",
|
||||
|
|
|
@ -49,7 +49,6 @@ class PdfViewerHandler : public content::WebUIMessageHandler {
|
|||
std::unique_ptr<base::Value> initialize_callback_id_;
|
||||
content::StreamInfo* stream_;
|
||||
std::string original_url_;
|
||||
bool initialized_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PdfViewerHandler);
|
||||
};
|
||||
|
|
|
@ -141,9 +141,9 @@ class PdfViewerUI::ResourceRequester
|
|||
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 =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue