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 "content/public/browser/stream_info.h"
|
||||||
#include "net/base/escape.h"
|
#include "net/base/escape.h"
|
||||||
#include "net/ssl/client_cert_store.h"
|
#include "net/ssl/client_cert_store.h"
|
||||||
|
#include "net/url_request/url_request.h"
|
||||||
#include "url/gurl.h"
|
#include "url/gurl.h"
|
||||||
|
|
||||||
#if defined(USE_NSS_CERTS)
|
#if defined(USE_NSS_CERTS)
|
||||||
|
@ -60,9 +61,10 @@ void HandleExternalProtocolInUI(
|
||||||
permission_helper->RequestOpenExternalPermission(callback, has_user_gesture);
|
permission_helper->RequestOpenExternalPermission(callback, has_user_gesture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnPdfStreamCreated(const GURL& original_url,
|
void OnPdfResourceIntercepted(
|
||||||
const content::ResourceRequestInfo::WebContentsGetter&
|
const GURL& original_url,
|
||||||
web_contents_getter) {
|
const content::ResourceRequestInfo::WebContentsGetter&
|
||||||
|
web_contents_getter) {
|
||||||
content::WebContents* web_contents = web_contents_getter.Run();
|
content::WebContents* web_contents = web_contents_getter.Run();
|
||||||
if (!web_contents)
|
if (!web_contents)
|
||||||
return;
|
return;
|
||||||
|
@ -124,20 +126,13 @@ bool AtomResourceDispatcherHostDelegate::ShouldInterceptResourceAsStream(
|
||||||
content::ResourceRequestInfo::ForRequest(request);
|
content::ResourceRequestInfo::ForRequest(request);
|
||||||
if (mime_type == "application/pdf" && info->IsMainFrame()) {
|
if (mime_type == "application/pdf" && info->IsMainFrame()) {
|
||||||
*origin = GURL(kPdfViewerUIOrigin);
|
*origin = GURL(kPdfViewerUIOrigin);
|
||||||
|
content::BrowserThread::PostTask(
|
||||||
|
BrowserThread::UI, FROM_HERE,
|
||||||
|
base::Bind(&OnPdfResourceIntercepted, request->url(),
|
||||||
|
info->GetWebContentsGetterForRequest()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
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
|
} // namespace atom
|
||||||
|
|
|
@ -29,8 +29,6 @@ class AtomResourceDispatcherHostDelegate
|
||||||
const std::string& mime_type,
|
const std::string& mime_type,
|
||||||
GURL* origin,
|
GURL* origin,
|
||||||
std::string* payload) override;
|
std::string* payload) override;
|
||||||
void OnStreamCreated(net::URLRequest* request,
|
|
||||||
std::unique_ptr<content::StreamInfo> stream) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DISALLOW_COPY_AND_ASSIGN(AtomResourceDispatcherHostDelegate);
|
DISALLOW_COPY_AND_ASSIGN(AtomResourceDispatcherHostDelegate);
|
||||||
|
|
|
@ -45,8 +45,7 @@ void CreateResponseHeadersDictionary(const net::HttpResponseHeaders* headers,
|
||||||
void PopulateStreamInfo(base::DictionaryValue* stream_info,
|
void PopulateStreamInfo(base::DictionaryValue* stream_info,
|
||||||
content::StreamInfo* stream,
|
content::StreamInfo* stream,
|
||||||
const std::string& original_url) {
|
const std::string& original_url) {
|
||||||
std::unique_ptr<base::DictionaryValue> headers_dict(
|
auto headers_dict = base::MakeUnique<base::DictionaryValue>();
|
||||||
new base::DictionaryValue);
|
|
||||||
auto stream_url = stream->handle->GetURL().spec();
|
auto stream_url = stream->handle->GetURL().spec();
|
||||||
CreateResponseHeadersDictionary(stream->response_headers.get(),
|
CreateResponseHeadersDictionary(stream->response_headers.get(),
|
||||||
headers_dict.get());
|
headers_dict.get());
|
||||||
|
@ -58,17 +57,16 @@ void PopulateStreamInfo(base::DictionaryValue* stream_info,
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
PdfViewerHandler::PdfViewerHandler(const std::string& src)
|
PdfViewerHandler::PdfViewerHandler(const std::string& src)
|
||||||
: stream_(nullptr), original_url_(src), initialized_(true) {}
|
: stream_(nullptr), original_url_(src) {}
|
||||||
|
|
||||||
PdfViewerHandler::~PdfViewerHandler() {}
|
PdfViewerHandler::~PdfViewerHandler() {}
|
||||||
|
|
||||||
void PdfViewerHandler::SetPdfResourceStream(content::StreamInfo* stream) {
|
void PdfViewerHandler::SetPdfResourceStream(content::StreamInfo* stream) {
|
||||||
stream_ = stream;
|
stream_ = stream;
|
||||||
if (!initialized_) {
|
if (!!initialize_callback_id_.get()) {
|
||||||
auto list = base::MakeUnique<base::ListValue>();
|
auto list = base::MakeUnique<base::ListValue>();
|
||||||
list->Set(0, std::move(initialize_callback_id_));
|
list->Set(0, std::move(initialize_callback_id_));
|
||||||
Initialize(list.get());
|
Initialize(list.get());
|
||||||
initialized_ = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,15 +108,14 @@ void PdfViewerHandler::Initialize(const base::ListValue* args) {
|
||||||
CHECK(args->Get(0, &callback_id));
|
CHECK(args->Get(0, &callback_id));
|
||||||
|
|
||||||
if (stream_) {
|
if (stream_) {
|
||||||
|
CHECK(!initialize_callback_id_.get());
|
||||||
AllowJavascript();
|
AllowJavascript();
|
||||||
|
|
||||||
std::unique_ptr<base::DictionaryValue> stream_info(
|
auto stream_info = base::MakeUnique<base::DictionaryValue>();
|
||||||
new base::DictionaryValue);
|
|
||||||
PopulateStreamInfo(stream_info.get(), stream_, original_url_);
|
PopulateStreamInfo(stream_info.get(), stream_, original_url_);
|
||||||
ResolveJavascriptCallback(*callback_id, *stream_info);
|
ResolveJavascriptCallback(*callback_id, *stream_info);
|
||||||
} else {
|
} else {
|
||||||
initialize_callback_id_ = callback_id->CreateDeepCopy();
|
initialize_callback_id_ = callback_id->CreateDeepCopy();
|
||||||
initialized_ = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +169,7 @@ void PdfViewerHandler::GetStrings(const base::ListValue* args) {
|
||||||
const base::Value* callback_id;
|
const base::Value* callback_id;
|
||||||
CHECK(args->Get(0, &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.
|
// TODO(deepak1556): Generate strings from components/pdf_strings.grdp.
|
||||||
#define SET_STRING(id, resource) result->SetString(id, resource)
|
#define SET_STRING(id, resource) result->SetString(id, resource)
|
||||||
SET_STRING("passwordPrompt",
|
SET_STRING("passwordPrompt",
|
||||||
|
|
|
@ -49,7 +49,6 @@ class PdfViewerHandler : public content::WebUIMessageHandler {
|
||||||
std::unique_ptr<base::Value> initialize_callback_id_;
|
std::unique_ptr<base::Value> initialize_callback_id_;
|
||||||
content::StreamInfo* stream_;
|
content::StreamInfo* stream_;
|
||||||
std::string original_url_;
|
std::string original_url_;
|
||||||
bool initialized_;
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(PdfViewerHandler);
|
DISALLOW_COPY_AND_ASSIGN(PdfViewerHandler);
|
||||||
};
|
};
|
||||||
|
|
|
@ -141,9 +141,9 @@ class PdfViewerUI::ResourceRequester
|
||||||
content::StreamContext* stream_context =
|
content::StreamContext* stream_context =
|
||||||
content::GetStreamContextForResourceContext(resource_context);
|
content::GetStreamContextForResourceContext(resource_context);
|
||||||
|
|
||||||
std::unique_ptr<content::ResourceHandler> handler(
|
std::unique_ptr<content::ResourceHandler> handler =
|
||||||
new content::StreamResourceHandler(request.get(),
|
base::MakeUnique<content::StreamResourceHandler>(
|
||||||
stream_context->registry(), origin));
|
request.get(), stream_context->registry(), origin);
|
||||||
info->set_is_stream(true);
|
info->set_is_stream(true);
|
||||||
stream_info_.reset(new content::StreamInfo);
|
stream_info_.reset(new content::StreamInfo);
|
||||||
stream_info_->handle =
|
stream_info_->handle =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue