| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/guest_view/guest_view_internal_api.h" | 5 #include "chrome/browser/extensions/api/guest_view/guest_view_internal_api.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/common/extensions/api/guest_view_internal.h" | 8 #include "chrome/common/extensions/api/guest_view_internal.h" |
| 9 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
| 10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 base::DictionaryValue* create_params; | 27 base::DictionaryValue* create_params; |
| 28 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &create_params)); | 28 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &create_params)); |
| 29 | 29 |
| 30 GuestViewManager* guest_view_manager = | 30 GuestViewManager* guest_view_manager = |
| 31 GuestViewManager::FromBrowserContext(browser_context()); | 31 GuestViewManager::FromBrowserContext(browser_context()); |
| 32 | 32 |
| 33 GuestViewManager::WebContentsCreatedCallback callback = | 33 GuestViewManager::WebContentsCreatedCallback callback = |
| 34 base::Bind(&GuestViewInternalCreateGuestFunction::CreateGuestCallback, | 34 base::Bind(&GuestViewInternalCreateGuestFunction::CreateGuestCallback, |
| 35 this); | 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 |
| 36 guest_view_manager->CreateGuest(view_type, | 44 guest_view_manager->CreateGuest(view_type, |
| 37 extension_id(), | 45 extension_id(), |
| 38 GetAssociatedWebContents(), | 46 embedder_web_contents, |
| 39 *create_params, | 47 *create_params, |
| 40 callback); | 48 callback); |
| 41 | |
| 42 return true; | 49 return true; |
| 43 } | 50 } |
| 44 | 51 |
| 45 void GuestViewInternalCreateGuestFunction::CreateGuestCallback( | 52 void GuestViewInternalCreateGuestFunction::CreateGuestCallback( |
| 46 content::WebContents* guest_web_contents) { | 53 content::WebContents* guest_web_contents) { |
| 47 int guest_instance_id = 0; | 54 int guest_instance_id = 0; |
| 48 if (guest_web_contents) { | 55 if (guest_web_contents) { |
| 49 GuestViewBase* guest = GuestViewBase::FromWebContents(guest_web_contents); | 56 GuestViewBase* guest = GuestViewBase::FromWebContents(guest_web_contents); |
| 50 guest_instance_id = guest->GetGuestInstanceID(); | 57 guest_instance_id = guest->GetGuestInstanceID(); |
| 51 } | 58 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 72 guest->SetAutoSize(params->params.enable_auto_size, | 79 guest->SetAutoSize(params->params.enable_auto_size, |
| 73 gfx::Size(params->params.min.width, | 80 gfx::Size(params->params.min.width, |
| 74 params->params.min.height), | 81 params->params.min.height), |
| 75 gfx::Size(params->params.max.width, | 82 gfx::Size(params->params.max.width, |
| 76 params->params.max.height)); | 83 params->params.max.height)); |
| 77 SendResponse(true); | 84 SendResponse(true); |
| 78 return true; | 85 return true; |
| 79 } | 86 } |
| 80 | 87 |
| 81 } // namespace extensions | 88 } // namespace extensions |
| OLD | NEW |