Upstream version 8.37.183.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / android / net / android_stream_reader_url_request_job.cc
index 3cb1227..43e0c3b 100644 (file)
@@ -96,9 +96,11 @@ class InputStreamReaderWrapper
 AndroidStreamReaderURLRequestJob::AndroidStreamReaderURLRequestJob(
     net::URLRequest* request,
     net::NetworkDelegate* network_delegate,
-    scoped_ptr<Delegate> delegate)
+    scoped_ptr<Delegate> delegate,
+    const std::string& content_security_policy)
     : URLRequestJob(request, network_delegate),
       delegate_(delegate.Pass()),
+      content_security_policy_(content_security_policy),
       weak_factory_(this) {
   DCHECK(delegate_);
 }
@@ -220,7 +222,7 @@ void AndroidStreamReaderURLRequestJob::OnInputStreamOpened(
       CreateStreamReader(input_stream.get()));
   DCHECK(input_stream_reader);
 
-  DCHECK(!input_stream_reader_wrapper_);
+  DCHECK(!input_stream_reader_wrapper_.get());
   input_stream_reader_wrapper_ = new InputStreamReaderWrapper(
       input_stream.Pass(), input_stream_reader.Pass());
 
@@ -275,7 +277,7 @@ bool AndroidStreamReaderURLRequestJob::ReadRawData(net::IOBuffer* dest,
                                                    int dest_size,
                                                    int* bytes_read) {
   DCHECK(thread_checker_.CalledOnValidThread());
-  if (!input_stream_reader_wrapper_) {
+  if (!input_stream_reader_wrapper_.get()) {
     // This will happen if opening the InputStream fails in which case the
     // error is communicated by setting the HTTP response status header rather
     // than failing the request during the header fetch phase.
@@ -304,7 +306,7 @@ bool AndroidStreamReaderURLRequestJob::GetMimeType(
   JNIEnv* env = AttachCurrentThread();
   DCHECK(env);
 
-  if (!input_stream_reader_wrapper_)
+  if (!input_stream_reader_wrapper_.get())
     return false;
 
   // Since it's possible for this call to alter the InputStream a
@@ -320,7 +322,7 @@ bool AndroidStreamReaderURLRequestJob::GetCharset(std::string* charset) {
   JNIEnv* env = AttachCurrentThread();
   DCHECK(env);
 
-  if (!input_stream_reader_wrapper_)
+  if (!input_stream_reader_wrapper_.get())
     return false;
 
   // Since it's possible for this call to alter the InputStream a
@@ -359,6 +361,12 @@ void AndroidStreamReaderURLRequestJob::HeadersComplete(
       content_type_header.append(mime_type);
       headers->AddHeader(content_type_header);
     }
+
+    if (!content_security_policy_.empty()) {
+      std::string content_security_policy("Content-Security-Policy: ");
+      content_security_policy.append(content_security_policy_);
+      headers->AddHeader(content_security_policy);
+    }
   }
 
   response_info_.reset(new net::HttpResponseInfo());