| 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 "extensions/browser/guest_view/guest_view_manager.h" | 5 #include "extensions/browser/guest_view/guest_view_manager.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
| 9 #include "content/public/browser/render_frame_host.h" | 9 #include "content/public/browser/render_frame_host.h" |
| 10 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 DCHECK(reverse_it != reverse_instance_id_map_.end()); | 133 DCHECK(reverse_it != reverse_instance_id_map_.end()); |
| 134 DCHECK(reverse_it->second == key); | 134 DCHECK(reverse_it->second == key); |
| 135 reverse_instance_id_map_.erase(guest_instance_id); | 135 reverse_instance_id_map_.erase(guest_instance_id); |
| 136 } | 136 } |
| 137 | 137 |
| 138 int GuestViewManager::GetNextInstanceID() { | 138 int GuestViewManager::GetNextInstanceID() { |
| 139 return ++current_instance_id_; | 139 return ++current_instance_id_; |
| 140 } | 140 } |
| 141 | 141 |
| 142 void GuestViewManager::CreateGuest(const std::string& view_type, | 142 void GuestViewManager::CreateGuest(const std::string& view_type, |
| 143 const std::string& owner_extension_id, | |
| 144 content::WebContents* owner_web_contents, | 143 content::WebContents* owner_web_contents, |
| 145 const base::DictionaryValue& create_params, | 144 const base::DictionaryValue& create_params, |
| 146 const WebContentsCreatedCallback& callback) { | 145 const WebContentsCreatedCallback& callback) { |
| 147 int guest_instance_id = GetNextInstanceID(); | 146 int guest_instance_id = GetNextInstanceID(); |
| 148 GuestViewBase* guest = | 147 GuestViewBase* guest = |
| 149 GuestViewBase::Create(context_, | 148 GuestViewBase::Create(context_, |
| 150 owner_web_contents, | 149 owner_web_contents, |
| 151 guest_instance_id, | 150 guest_instance_id, |
| 152 view_type); | 151 view_type); |
| 153 if (!guest) { | 152 if (!guest) { |
| 154 callback.Run(NULL); | 153 callback.Run(NULL); |
| 155 return; | 154 return; |
| 156 } | 155 } |
| 157 guest->Init(owner_extension_id, create_params, callback); | 156 guest->Init(create_params, callback); |
| 158 } | 157 } |
| 159 | 158 |
| 160 content::WebContents* GuestViewManager::CreateGuestWithWebContentsParams( | 159 content::WebContents* GuestViewManager::CreateGuestWithWebContentsParams( |
| 161 const std::string& view_type, | 160 const std::string& view_type, |
| 162 const std::string& owner_extension_id, | |
| 163 content::WebContents* owner_web_contents, | 161 content::WebContents* owner_web_contents, |
| 164 const content::WebContents::CreateParams& create_params) { | 162 const content::WebContents::CreateParams& create_params) { |
| 165 int guest_instance_id = GetNextInstanceID(); | 163 int guest_instance_id = GetNextInstanceID(); |
| 166 GuestViewBase* guest = | 164 GuestViewBase* guest = |
| 167 GuestViewBase::Create(context_, | 165 GuestViewBase::Create(context_, |
| 168 owner_web_contents, | 166 owner_web_contents, |
| 169 guest_instance_id, | 167 guest_instance_id, |
| 170 view_type); | 168 view_type); |
| 171 if (!guest) | 169 if (!guest) |
| 172 return NULL; | 170 return NULL; |
| 173 content::WebContents::CreateParams guest_create_params(create_params); | 171 content::WebContents::CreateParams guest_create_params(create_params); |
| 174 guest_create_params.guest_delegate = guest; | 172 guest_create_params.guest_delegate = guest; |
| 175 content::WebContents* guest_web_contents = | 173 content::WebContents* guest_web_contents = |
| 176 WebContents::Create(guest_create_params); | 174 WebContents::Create(guest_create_params); |
| 177 guest->InitWithWebContents(owner_extension_id, guest_web_contents); | 175 guest->InitWithWebContents(guest_web_contents); |
| 178 return guest_web_contents; | 176 return guest_web_contents; |
| 179 } | 177 } |
| 180 | 178 |
| 181 content::WebContents* GuestViewManager::GetGuestByInstanceID( | 179 content::WebContents* GuestViewManager::GetGuestByInstanceID( |
| 182 content::WebContents* owner_web_contents, | 180 content::WebContents* owner_web_contents, |
| 183 int element_instance_id) { | 181 int element_instance_id) { |
| 184 int guest_instance_id = GetGuestInstanceIDForElementID(owner_web_contents, | 182 int guest_instance_id = GetGuestInstanceIDForElementID(owner_web_contents, |
| 185 element_instance_id); | 183 element_instance_id); |
| 186 if (guest_instance_id == guestview::kInstanceIDNone) | 184 if (guest_instance_id == guestview::kInstanceIDNone) |
| 187 return NULL; | 185 return NULL; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 | 323 |
| 326 GuestViewBase* guest_view = GuestViewBase::FromWebContents(it->second); | 324 GuestViewBase* guest_view = GuestViewBase::FromWebContents(it->second); |
| 327 if (!guest_view) | 325 if (!guest_view) |
| 328 return false; | 326 return false; |
| 329 | 327 |
| 330 return embedder_render_process_id == | 328 return embedder_render_process_id == |
| 331 guest_view->owner_web_contents()->GetRenderProcessHost()->GetID(); | 329 guest_view->owner_web_contents()->GetRenderProcessHost()->GetID(); |
| 332 } | 330 } |
| 333 | 331 |
| 334 } // namespace extensions | 332 } // namespace extensions |
| OLD | NEW |