OLD | NEW |
| (Empty) |
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 "chrome/browser/extensions/api/guest_view/guest_view_internal_api.h" | |
6 | |
7 #include "chrome/browser/profiles/profile.h" | |
8 #include "chrome/common/extensions/api/guest_view_internal.h" | |
9 #include "content/public/browser/render_process_host.h" | |
10 #include "content/public/browser/render_view_host.h" | |
11 #include "extensions/browser/guest_view/guest_view_base.h" | |
12 #include "extensions/browser/guest_view/guest_view_manager.h" | |
13 #include "extensions/common/permissions/permissions_data.h" | |
14 | |
15 namespace guest_view_internal = extensions::api::guest_view_internal; | |
16 | |
17 namespace extensions { | |
18 | |
19 GuestViewInternalCreateGuestFunction:: | |
20 GuestViewInternalCreateGuestFunction() { | |
21 } | |
22 | |
23 bool GuestViewInternalCreateGuestFunction::RunAsync() { | |
24 std::string view_type; | |
25 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &view_type)); | |
26 | |
27 base::DictionaryValue* create_params; | |
28 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &create_params)); | |
29 | |
30 GuestViewManager* guest_view_manager = | |
31 GuestViewManager::FromBrowserContext(browser_context()); | |
32 | |
33 GuestViewManager::WebContentsCreatedCallback callback = | |
34 base::Bind(&GuestViewInternalCreateGuestFunction::CreateGuestCallback, | |
35 this); | |
36 | |
37 content::WebContents* embedder_web_contents = | |
38 content::WebContents::FromRenderViewHost(render_view_host()); | |
39 if (!embedder_web_contents) { | |
40 error_ = "Guest views can only be embedded in web content"; | |
41 return false; | |
42 } | |
43 // If the guest is an <extensionoptions> to be embedded in a WebUI, then | |
44 // there is no extension, and extension() will be null. Use an empty string | |
45 // instead. | |
46 std::string embedder_extension_id; | |
47 if (extension()) | |
48 embedder_extension_id = extension_id(); | |
49 | |
50 guest_view_manager->CreateGuest(view_type, | |
51 embedder_extension_id, | |
52 embedder_web_contents, | |
53 *create_params, | |
54 callback); | |
55 return true; | |
56 } | |
57 | |
58 void GuestViewInternalCreateGuestFunction::CreateGuestCallback( | |
59 content::WebContents* guest_web_contents) { | |
60 int guest_instance_id = 0; | |
61 if (guest_web_contents) { | |
62 GuestViewBase* guest = GuestViewBase::FromWebContents(guest_web_contents); | |
63 guest_instance_id = guest->guest_instance_id(); | |
64 } | |
65 SetResult(new base::FundamentalValue(guest_instance_id)); | |
66 SendResponse(true); | |
67 } | |
68 | |
69 GuestViewInternalSetAutoSizeFunction:: | |
70 GuestViewInternalSetAutoSizeFunction() { | |
71 } | |
72 | |
73 GuestViewInternalSetAutoSizeFunction:: | |
74 ~GuestViewInternalSetAutoSizeFunction() { | |
75 } | |
76 | |
77 bool GuestViewInternalSetAutoSizeFunction::RunAsync() { | |
78 scoped_ptr<guest_view_internal::SetAutoSize::Params> params( | |
79 guest_view_internal::SetAutoSize::Params::Create(*args_)); | |
80 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
81 GuestViewBase* guest = GuestViewBase::From( | |
82 render_view_host()->GetProcess()->GetID(), params->instance_id); | |
83 if (!guest) | |
84 return false; | |
85 guest->SetAutoSize(params->params.enable_auto_size, | |
86 gfx::Size(params->params.min.width, | |
87 params->params.min.height), | |
88 gfx::Size(params->params.max.width, | |
89 params->params.max.height)); | |
90 SendResponse(true); | |
91 return true; | |
92 } | |
93 | |
94 } // namespace extensions | |
OLD | NEW |