1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "extensions/browser/api/guest_view/app_view/app_view_guest_internal_api.h"
6 
7 #include "content/public/browser/render_frame_host.h"
8 #include "extensions/browser/guest_view/app_view/app_view_guest.h"
9 #include "extensions/common/api/app_view_guest_internal.h"
10 
11 namespace extensions {
12 
13 namespace appview = api::app_view_guest_internal;
14 
15 AppViewGuestInternalAttachFrameFunction::
AppViewGuestInternalAttachFrameFunction()16     AppViewGuestInternalAttachFrameFunction() {
17 }
18 
19 ExtensionFunction::ResponseAction
Run()20 AppViewGuestInternalAttachFrameFunction::Run() {
21   std::unique_ptr<appview::AttachFrame::Params> params(
22       appview::AttachFrame::Params::Create(*args_));
23   EXTENSION_FUNCTION_VALIDATE(params.get());
24 
25   GURL url = extension()->GetResourceURL(params->url);
26   EXTENSION_FUNCTION_VALIDATE(url.is_valid());
27 
28   ResponseValue response;
29   if (AppViewGuest::CompletePendingRequest(
30           browser_context(), url, params->guest_instance_id, extension_id(),
31           render_frame_host()->GetProcess())) {
32     response = NoArguments();
33   } else {
34     response = Error("could not complete");
35   }
36   return RespondNow(std::move(response));
37 }
38 
39 AppViewGuestInternalDenyRequestFunction::
AppViewGuestInternalDenyRequestFunction()40     AppViewGuestInternalDenyRequestFunction() {
41 }
42 
43 ExtensionFunction::ResponseAction
Run()44 AppViewGuestInternalDenyRequestFunction::Run() {
45   std::unique_ptr<appview::DenyRequest::Params> params(
46       appview::DenyRequest::Params::Create(*args_));
47   EXTENSION_FUNCTION_VALIDATE(params.get());
48 
49   // Since the URL passed into AppViewGuest:::CompletePendingRequest is invalid,
50   // a new <appview> WebContents will not be created.
51   ResponseValue response;
52   if (AppViewGuest::CompletePendingRequest(
53           browser_context(), GURL(), params->guest_instance_id, extension_id(),
54           render_frame_host()->GetProcess())) {
55     response = NoArguments();
56   } else {
57     response = Error("could not complete");
58   }
59   return RespondNow(std::move(response));
60 }
61 
62 }  // namespace extensions
63