Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Side by Side Diff: components/guest_view/browser/guest_view_manager.cc

Issue 2110663002: components: Change auto to not deduce raw pointers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase+one fix Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/guest_view/browser/guest_view_manager.h" 5 #include "components/guest_view/browser/guest_view_manager.h"
6 6
7 #include <tuple> 7 #include <tuple>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 guest_instance_id)) { 106 guest_instance_id)) {
107 return nullptr; 107 return nullptr;
108 } 108 }
109 return GetGuestByInstanceID(guest_instance_id); 109 return GetGuestByInstanceID(guest_instance_id);
110 } 110 }
111 111
112 void GuestViewManager::AttachGuest(int embedder_process_id, 112 void GuestViewManager::AttachGuest(int embedder_process_id,
113 int element_instance_id, 113 int element_instance_id,
114 int guest_instance_id, 114 int guest_instance_id,
115 const base::DictionaryValue& attach_params) { 115 const base::DictionaryValue& attach_params) {
116 auto guest_view = GuestViewBase::From(embedder_process_id, guest_instance_id); 116 auto* guest_view =
117 GuestViewBase::From(embedder_process_id, guest_instance_id);
117 if (!guest_view) 118 if (!guest_view)
118 return; 119 return;
119 120
120 ElementInstanceKey key(embedder_process_id, element_instance_id); 121 ElementInstanceKey key(embedder_process_id, element_instance_id);
121 auto it = instance_id_map_.find(key); 122 auto it = instance_id_map_.find(key);
122 // If there is an existing guest attached to the element, then destroy the 123 // If there is an existing guest attached to the element, then destroy the
123 // existing guest. 124 // existing guest.
124 if (it != instance_id_map_.end()) { 125 if (it != instance_id_map_.end()) {
125 int old_guest_instance_id = it->second; 126 int old_guest_instance_id = it->second;
126 if (old_guest_instance_id == guest_instance_id) 127 if (old_guest_instance_id == guest_instance_id)
127 return; 128 return;
128 129
129 auto old_guest_view = GuestViewBase::From(embedder_process_id, 130 auto* old_guest_view =
130 old_guest_instance_id); 131 GuestViewBase::From(embedder_process_id, old_guest_instance_id);
131 old_guest_view->Destroy(); 132 old_guest_view->Destroy();
132 } 133 }
133 instance_id_map_[key] = guest_instance_id; 134 instance_id_map_[key] = guest_instance_id;
134 reverse_instance_id_map_[guest_instance_id] = key; 135 reverse_instance_id_map_[guest_instance_id] = key;
135 guest_view->SetAttachParams(attach_params); 136 guest_view->SetAttachParams(attach_params);
136 } 137 }
137 138
138 void GuestViewManager::DetachGuest(GuestViewBase* guest) { 139 void GuestViewManager::DetachGuest(GuestViewBase* guest) {
139 if (!guest->attached()) 140 if (!guest->attached())
140 return; 141 return;
(...skipping 28 matching lines...) Expand all
169 callback.Run(nullptr); 170 callback.Run(nullptr);
170 return; 171 return;
171 } 172 }
172 guest->Init(create_params, callback); 173 guest->Init(create_params, callback);
173 } 174 }
174 175
175 content::WebContents* GuestViewManager::CreateGuestWithWebContentsParams( 176 content::WebContents* GuestViewManager::CreateGuestWithWebContentsParams(
176 const std::string& view_type, 177 const std::string& view_type,
177 content::WebContents* owner_web_contents, 178 content::WebContents* owner_web_contents,
178 const content::WebContents::CreateParams& create_params) { 179 const content::WebContents::CreateParams& create_params) {
179 auto guest = CreateGuestInternal(owner_web_contents, view_type); 180 auto* guest = CreateGuestInternal(owner_web_contents, view_type);
180 if (!guest) 181 if (!guest)
181 return nullptr; 182 return nullptr;
182 content::WebContents::CreateParams guest_create_params(create_params); 183 content::WebContents::CreateParams guest_create_params(create_params);
183 guest_create_params.guest_delegate = guest; 184 guest_create_params.guest_delegate = guest;
184 auto guest_web_contents = WebContents::Create(guest_create_params); 185 auto* guest_web_contents = WebContents::Create(guest_create_params);
185 guest->InitWithWebContents(base::DictionaryValue(), guest_web_contents); 186 guest->InitWithWebContents(base::DictionaryValue(), guest_web_contents);
186 return guest_web_contents; 187 return guest_web_contents;
187 } 188 }
188 189
189 content::WebContents* GuestViewManager::GetGuestByInstanceID( 190 content::WebContents* GuestViewManager::GetGuestByInstanceID(
190 int owner_process_id, 191 int owner_process_id,
191 int element_instance_id) { 192 int element_instance_id) {
192 int guest_instance_id = GetGuestInstanceIDForElementID(owner_process_id, 193 int guest_instance_id = GetGuestInstanceIDForElementID(owner_process_id,
193 element_instance_id); 194 element_instance_id);
194 if (guest_instance_id == kInstanceIDNone) 195 if (guest_instance_id == kInstanceIDNone)
(...skipping 16 matching lines...) Expand all
211 for (const auto& guest : guest_web_contents_by_instance_id_) { 212 for (const auto& guest : guest_web_contents_by_instance_id_) {
212 if (guest.second->GetSiteInstance()->GetSiteURL() == guest_site) 213 if (guest.second->GetSiteInstance()->GetSiteURL() == guest_site)
213 return guest.second->GetSiteInstance(); 214 return guest.second->GetSiteInstance();
214 } 215 }
215 return nullptr; 216 return nullptr;
216 } 217 }
217 218
218 bool GuestViewManager::ForEachGuest(WebContents* owner_web_contents, 219 bool GuestViewManager::ForEachGuest(WebContents* owner_web_contents,
219 const GuestCallback& callback) { 220 const GuestCallback& callback) {
220 for (const auto& guest : guest_web_contents_by_instance_id_) { 221 for (const auto& guest : guest_web_contents_by_instance_id_) {
221 auto guest_view = GuestViewBase::FromWebContents(guest.second); 222 auto* guest_view = GuestViewBase::FromWebContents(guest.second);
222 if (guest_view->owner_web_contents() != owner_web_contents) 223 if (guest_view->owner_web_contents() != owner_web_contents)
223 continue; 224 continue;
224 225
225 if (callback.Run(guest_view->web_contents())) 226 if (callback.Run(guest_view->web_contents()))
226 return true; 227 return true;
227 } 228 }
228 return false; 229 return false;
229 } 230 }
230 231
231 WebContents* GuestViewManager::GetFullPageGuest( 232 WebContents* GuestViewManager::GetFullPageGuest(
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 bool GuestViewManager::CanUseGuestInstanceID(int guest_instance_id) { 422 bool GuestViewManager::CanUseGuestInstanceID(int guest_instance_id) {
422 if (guest_instance_id <= last_instance_id_removed_) 423 if (guest_instance_id <= last_instance_id_removed_)
423 return false; 424 return false;
424 return !ContainsKey(removed_instance_ids_, guest_instance_id); 425 return !ContainsKey(removed_instance_ids_, guest_instance_id);
425 } 426 }
426 427
427 // static 428 // static
428 bool GuestViewManager::GetFullPageGuestHelper( 429 bool GuestViewManager::GetFullPageGuestHelper(
429 content::WebContents** result, 430 content::WebContents** result,
430 content::WebContents* guest_web_contents) { 431 content::WebContents* guest_web_contents) {
431 auto guest_view = GuestViewBase::FromWebContents(guest_web_contents); 432 auto* guest_view = GuestViewBase::FromWebContents(guest_web_contents);
432 if (guest_view && guest_view->is_full_page_plugin()) { 433 if (guest_view && guest_view->is_full_page_plugin()) {
433 *result = guest_web_contents; 434 *result = guest_web_contents;
434 return true; 435 return true;
435 } 436 }
436 return false; 437 return false;
437 } 438 }
438 439
439 bool GuestViewManager::CanEmbedderAccessInstanceID( 440 bool GuestViewManager::CanEmbedderAccessInstanceID(
440 int embedder_render_process_id, 441 int embedder_render_process_id,
441 int guest_instance_id) { 442 int guest_instance_id) {
442 // The embedder is trying to access a guest with a negative or zero 443 // The embedder is trying to access a guest with a negative or zero
443 // instance ID. 444 // instance ID.
444 if (guest_instance_id <= kInstanceIDNone) 445 if (guest_instance_id <= kInstanceIDNone)
445 return false; 446 return false;
446 447
447 // The embedder is trying to access an instance ID that has not yet been 448 // The embedder is trying to access an instance ID that has not yet been
448 // allocated by GuestViewManager. This could cause instance ID 449 // allocated by GuestViewManager. This could cause instance ID
449 // collisions in the future, and potentially give one embedder access to a 450 // collisions in the future, and potentially give one embedder access to a
450 // guest it does not own. 451 // guest it does not own.
451 if (guest_instance_id > current_instance_id_) 452 if (guest_instance_id > current_instance_id_)
452 return false; 453 return false;
453 454
454 // We might get some late arriving messages at tear down. Let's let the 455 // We might get some late arriving messages at tear down. Let's let the
455 // embedder tear down in peace. 456 // embedder tear down in peace.
456 auto it = guest_web_contents_by_instance_id_.find(guest_instance_id); 457 auto it = guest_web_contents_by_instance_id_.find(guest_instance_id);
457 if (it == guest_web_contents_by_instance_id_.end()) 458 if (it == guest_web_contents_by_instance_id_.end())
458 return true; 459 return true;
459 460
460 auto guest_view = GuestViewBase::FromWebContents(it->second); 461 auto* guest_view = GuestViewBase::FromWebContents(it->second);
461 if (!guest_view) 462 if (!guest_view)
462 return false; 463 return false;
463 464
464 return embedder_render_process_id == 465 return embedder_render_process_id ==
465 guest_view->owner_web_contents()->GetRenderProcessHost()->GetID(); 466 guest_view->owner_web_contents()->GetRenderProcessHost()->GetID();
466 } 467 }
467 468
468 GuestViewManager::ElementInstanceKey::ElementInstanceKey() 469 GuestViewManager::ElementInstanceKey::ElementInstanceKey()
469 : embedder_process_id(content::ChildProcessHost::kInvalidUniqueID), 470 : embedder_process_id(content::ChildProcessHost::kInvalidUniqueID),
470 element_instance_id(content::ChildProcessHost::kInvalidUniqueID) { 471 element_instance_id(content::ChildProcessHost::kInvalidUniqueID) {
(...skipping 22 matching lines...) Expand all
493 const GuestViewCreateFunction& create_function, 494 const GuestViewCreateFunction& create_function,
494 const GuestViewCleanUpFunction& cleanup_function) 495 const GuestViewCleanUpFunction& cleanup_function)
495 : create_function(create_function), cleanup_function(cleanup_function) {} 496 : create_function(create_function), cleanup_function(cleanup_function) {}
496 497
497 GuestViewManager::GuestViewData::GuestViewData(const GuestViewData& other) = 498 GuestViewManager::GuestViewData::GuestViewData(const GuestViewData& other) =
498 default; 499 default;
499 500
500 GuestViewManager::GuestViewData::~GuestViewData() {} 501 GuestViewManager::GuestViewData::~GuestViewData() {}
501 502
502 } // namespace guest_view 503 } // namespace guest_view
OLDNEW
« no previous file with comments | « components/guest_view/browser/guest_view_base.cc ('k') | components/guest_view/browser/guest_view_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698