Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / renderer / pepper / pepper_url_loader_host.cc
index e6a2b5c..5f70dfa 100644 (file)
 #include "third_party/WebKit/public/platform/WebURLResponse.h"
 #include "third_party/WebKit/public/web/WebDocument.h"
 #include "third_party/WebKit/public/web/WebElement.h"
-#include "third_party/WebKit/public/web/WebFrame.h"
 #include "third_party/WebKit/public/web/WebKit.h"
+#include "third_party/WebKit/public/web/WebLocalFrame.h"
 #include "third_party/WebKit/public/web/WebPluginContainer.h"
 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h"
 
-using blink::WebFrame;
+using blink::WebLocalFrame;
 using blink::WebString;
 using blink::WebURL;
 using blink::WebURLError;
@@ -104,20 +104,17 @@ PepperURLLoaderHost::~PepperURLLoaderHost() {
 int32_t PepperURLLoaderHost::OnResourceMessageReceived(
     const IPC::Message& msg,
     ppapi::host::HostMessageContext* context) {
-  IPC_BEGIN_MESSAGE_MAP(PepperURLLoaderHost, msg)
-    PPAPI_DISPATCH_HOST_RESOURCE_CALL(
-        PpapiHostMsg_URLLoader_Open,
-        OnHostMsgOpen)
-    PPAPI_DISPATCH_HOST_RESOURCE_CALL(
-        PpapiHostMsg_URLLoader_SetDeferLoading,
-        OnHostMsgSetDeferLoading)
-    PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
-        PpapiHostMsg_URLLoader_Close,
-        OnHostMsgClose);
+  PPAPI_BEGIN_MESSAGE_MAP(PepperURLLoaderHost, msg)
+    PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_URLLoader_Open,
+                                      OnHostMsgOpen)
+    PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_URLLoader_SetDeferLoading,
+                                      OnHostMsgSetDeferLoading)
+    PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_URLLoader_Close,
+                                        OnHostMsgClose);
     PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
         PpapiHostMsg_URLLoader_GrantUniversalAccess,
         OnHostMsgGrantUniversalAccess)
-  IPC_END_MESSAGE_MAP()
+  PPAPI_END_MESSAGE_MAP()
   return PP_ERROR_FAILED;
 }
 
@@ -180,7 +177,7 @@ void PepperURLLoaderHost::didFinishLoading(WebURLLoader* loader,
 }
 
 void PepperURLLoaderHost::didFail(WebURLLoader* loader,
-                                 const WebURLError& error) {
+                                  const WebURLError& error) {
   // Note that |loader| will be NULL for document loads.
   int32_t pp_error = PP_ERROR_FAILED;
   if (error.domain.equals(WebString::fromUTF8(net::kErrorDomain))) {
@@ -237,7 +234,9 @@ int32_t PepperURLLoaderHost::InternalOnHostMsgOpen(
   if (URLRequestRequiresUniversalAccess(filled_in_request_data) &&
       !has_universal_access_) {
     ppapi::PpapiGlobals::Get()->LogWithSource(
-        pp_instance(), PP_LOGLEVEL_ERROR, std::string(),
+        pp_instance(),
+        PP_LOGLEVEL_ERROR,
+        std::string(),
         "PPB_URLLoader.Open: The URL you're requesting is "
         " on a different security origin than your plugin. To request "
         " cross-origin resources, see "
@@ -248,20 +247,22 @@ int32_t PepperURLLoaderHost::InternalOnHostMsgOpen(
   if (loader_.get())
     return PP_ERROR_INPROGRESS;
 
-  WebFrame* frame = GetFrame();
+  WebLocalFrame* frame = GetFrame();
   if (!frame)
     return PP_ERROR_FAILED;
 
   WebURLRequest web_request;
-  if (!CreateWebURLRequest(pp_instance(),
-                           &filled_in_request_data,
-                           frame,
-                           &web_request)) {
+  if (!CreateWebURLRequest(
+          pp_instance(), &filled_in_request_data, frame, &web_request)) {
     return PP_ERROR_FAILED;
   }
 
-  web_request.setTargetType(WebURLRequest::TargetIsObject);
+  web_request.setRequestContext(WebURLRequest::RequestContextPlugin);
   web_request.setRequestorProcessID(renderer_ppapi_host_->GetPluginPID());
+  // The requests from the plugins with private permission which can bypass same
+  // origin must skip the ServiceWorker.
+  web_request.setSkipServiceWorker(
+      host()->permissions().HasPermission(ppapi::PERMISSION_PRIVATE));
 
   WebURLLoaderOptions options;
   if (has_universal_access_) {
@@ -362,13 +363,21 @@ void PepperURLLoaderHost::SendOrderedUpdateToPlugin(IPC::Message* message) {
 }
 
 void PepperURLLoaderHost::Close() {
-  if (loader_.get())
+  if (loader_.get()) {
     loader_->cancel();
-  else if (main_document_loader_)
-    GetFrame()->stopLoading();
+  } else if (main_document_loader_) {
+    // TODO(raymes): Calling WebLocalFrame::stopLoading here is incorrect as it
+    // cancels all URL loaders associated with the frame. If a client has opened
+    // other URLLoaders and then closes the main one, the others should still
+    // remain connected. Work out how to only cancel the main request:
+    // crbug.com/384197.
+    blink::WebLocalFrame* frame = GetFrame();
+    if (frame)
+      frame->stopLoading();
+  }
 }
 
-blink::WebFrame* PepperURLLoaderHost::GetFrame() {
+blink::WebLocalFrame* PepperURLLoaderHost::GetFrame() {
   PepperPluginInstance* instance_object =
       renderer_ppapi_host_->GetPluginInstance(pp_instance());
   if (!instance_object)
@@ -402,7 +411,7 @@ void PepperURLLoaderHost::SaveResponse(const WebURLResponse& response) {
         pp_instance(),
         response,
         base::Bind(&PepperURLLoaderHost::DidDataFromWebURLResponse,
-            weak_factory_.GetWeakPtr()));
+                   weak_factory_.GetWeakPtr()));
   }
 }
 
@@ -422,10 +431,10 @@ void PepperURLLoaderHost::UpdateProgress() {
     // flag.
     ppapi::proxy::ResourceMessageReplyParams params;
     SendUpdateToPlugin(new PpapiPluginMsg_URLLoader_UpdateProgress(
-            record_upload ? bytes_sent_ : -1,
-            record_upload ? total_bytes_to_be_sent_ : -1,
-            record_download ? bytes_received_ : -1,
-            record_download ? total_bytes_to_be_received_ : -1));
+        record_upload ? bytes_sent_ : -1,
+        record_upload ? total_bytes_to_be_sent_ : -1,
+        record_download ? bytes_received_ : -1,
+        record_download ? total_bytes_to_be_received_ : -1));
   }
 }