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

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

Issue 444813002: Remove BrowserPlugin's -internal-attach method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 "chrome/browser/guest_view/guest_view_manager.h" 5 #include "chrome/browser/guest_view/guest_view_manager.h"
6 6
7 #include "base/debug/stack_trace.h"
7 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/guest_view/guest_view_base.h" 10 #include "chrome/browser/guest_view/guest_view_base.h"
10 #include "chrome/browser/guest_view/guest_view_constants.h" 11 #include "chrome/browser/guest_view/guest_view_constants.h"
11 #include "chrome/browser/guest_view/guest_view_manager_factory.h" 12 #include "chrome/browser/guest_view/guest_view_manager_factory.h"
12 #include "chrome/browser/guest_view/web_view/web_view_guest.h" 13 #include "chrome/browser/guest_view/web_view/web_view_guest.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "content/public/browser/browser_context.h" 15 #include "content/public/browser/browser_context.h"
15 #include "content/public/browser/render_process_host.h" 16 #include "content/public/browser/render_process_host.h"
17 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/user_metrics.h" 18 #include "content/public/browser/user_metrics.h"
17 #include "content/public/browser/web_contents_observer.h" 19 #include "content/public/browser/web_contents_observer.h"
18 #include "content/public/common/result_codes.h" 20 #include "content/public/common/result_codes.h"
19 #include "content/public/common/url_constants.h" 21 #include "content/public/common/url_constants.h"
20 #include "extensions/browser/extension_system.h" 22 #include "extensions/browser/extension_system.h"
21 #include "net/base/escape.h" 23 #include "net/base/escape.h"
22 #include "url/gurl.h" 24 #include "url/gurl.h"
23 25
24 using content::BrowserContext; 26 using content::BrowserContext;
25 using content::SiteInstance; 27 using content::SiteInstance;
(...skipping 28 matching lines...) Expand all
54 content::WebContents* GuestViewManager::GetGuestByInstanceIDSafely( 56 content::WebContents* GuestViewManager::GetGuestByInstanceIDSafely(
55 int guest_instance_id, 57 int guest_instance_id,
56 int embedder_render_process_id) { 58 int embedder_render_process_id) {
57 if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id, 59 if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id,
58 guest_instance_id)) { 60 guest_instance_id)) {
59 return NULL; 61 return NULL;
60 } 62 }
61 return GetGuestByInstanceID(guest_instance_id); 63 return GetGuestByInstanceID(guest_instance_id);
62 } 64 }
63 65
66 void GuestViewManager::SetAttachParamsForGuest(
67 int embedder_render_process_id,
68 int embedder_routing_id,
69 int element_instance_id,
70 int guest_instance_id,
71 const base::DictionaryValue& params) {
72 content::WebContents* guest_web_contents =
73 GetGuestByInstanceIDSafely(guest_instance_id, embedder_render_process_id);
74 if (!guest_web_contents)
75 return;
76
77 GuestViewBase* guest_view =
78 GuestViewBase::FromWebContents(guest_web_contents);
79 DCHECK(guest_view);
80
81 content::RenderViewHost* rvh =
82 content::RenderViewHost::FromID(embedder_render_process_id,
83 embedder_routing_id);
84 content::WebContents* embedder_web_contents =
85 content::WebContents::FromRenderViewHost(rvh);
86 if (!embedder_web_contents)
87 return;
88 ElementInstanceKey key(embedder_web_contents, element_instance_id);
89 instance_id_map_[key] = guest_instance_id;
90 reverse_instance_id_map_.insert(std::make_pair(guest_instance_id, key));
91 guest_view->SetAttachParams(params);
92 }
93
64 int GuestViewManager::GetNextInstanceID() { 94 int GuestViewManager::GetNextInstanceID() {
65 return ++current_instance_id_; 95 return ++current_instance_id_;
66 } 96 }
67 97
68 void GuestViewManager::CreateGuest( 98 void GuestViewManager::CreateGuest(
69 const std::string& view_type, 99 const std::string& view_type,
70 const std::string& embedder_extension_id, 100 const std::string& embedder_extension_id,
71 int embedder_render_process_id, 101 int embedder_render_process_id,
72 const base::DictionaryValue& create_params, 102 const base::DictionaryValue& create_params,
73 const WebContentsCreatedCallback& callback) { 103 const WebContentsCreatedCallback& callback) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id, 141 if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id,
112 guest_instance_id)) { 142 guest_instance_id)) {
113 // If we kill the embedder, then don't bother calling back. 143 // If we kill the embedder, then don't bother calling back.
114 return; 144 return;
115 } 145 }
116 content::WebContents* guest_web_contents = 146 content::WebContents* guest_web_contents =
117 GetGuestByInstanceID(guest_instance_id); 147 GetGuestByInstanceID(guest_instance_id);
118 callback.Run(guest_web_contents); 148 callback.Run(guest_web_contents);
119 } 149 }
120 150
151 int GuestViewManager::GetGuestInstanceIDForPluginID(
152 content::WebContents* embedder_web_contents,
153 int element_instance_id) {
154 GuestInstanceIDMap::iterator iter = instance_id_map_.find(
155 ElementInstanceKey(embedder_web_contents, element_instance_id));
156 DCHECK(iter != instance_id_map_.end());
157 int guest_instance_id = iter->second;
158 return guest_instance_id;
159 }
160
121 SiteInstance* GuestViewManager::GetGuestSiteInstance( 161 SiteInstance* GuestViewManager::GetGuestSiteInstance(
122 const GURL& guest_site) { 162 const GURL& guest_site) {
123 for (GuestInstanceMap::const_iterator it = 163 for (GuestInstanceMap::const_iterator it =
124 guest_web_contents_by_instance_id_.begin(); 164 guest_web_contents_by_instance_id_.begin();
125 it != guest_web_contents_by_instance_id_.end(); ++it) { 165 it != guest_web_contents_by_instance_id_.end(); ++it) {
126 if (it->second->GetSiteInstance()->GetSiteURL() == guest_site) 166 if (it->second->GetSiteInstance()->GetSiteURL() == guest_site)
127 return it->second->GetSiteInstance(); 167 return it->second->GetSiteInstance();
128 } 168 }
129 return NULL; 169 return NULL;
130 } 170 }
(...skipping 20 matching lines...) Expand all
151 CHECK(CanUseGuestInstanceID(guest_instance_id)); 191 CHECK(CanUseGuestInstanceID(guest_instance_id));
152 guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents; 192 guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents;
153 } 193 }
154 194
155 void GuestViewManager::RemoveGuest(int guest_instance_id) { 195 void GuestViewManager::RemoveGuest(int guest_instance_id) {
156 GuestInstanceMap::iterator it = 196 GuestInstanceMap::iterator it =
157 guest_web_contents_by_instance_id_.find(guest_instance_id); 197 guest_web_contents_by_instance_id_.find(guest_instance_id);
158 DCHECK(it != guest_web_contents_by_instance_id_.end()); 198 DCHECK(it != guest_web_contents_by_instance_id_.end());
159 guest_web_contents_by_instance_id_.erase(it); 199 guest_web_contents_by_instance_id_.erase(it);
160 200
201 GuestInstanceIDReverseMap::iterator id_iter =
202 reverse_instance_id_map_.find(guest_instance_id);
203 if (id_iter != reverse_instance_id_map_.end()) {
204 const ElementInstanceKey& instance_id_key = id_iter->second;
205 instance_id_map_.erase(instance_id_map_.find(instance_id_key));
206 reverse_instance_id_map_.erase(id_iter);
207 }
208
161 // All the instance IDs that lie within [0, last_instance_id_removed_] 209 // All the instance IDs that lie within [0, last_instance_id_removed_]
162 // are invalid. 210 // are invalid.
163 // The remaining sparse invalid IDs are kept in |removed_instance_ids_| set. 211 // The remaining sparse invalid IDs are kept in |removed_instance_ids_| set.
164 // The following code compacts the set by incrementing 212 // The following code compacts the set by incrementing
165 // |last_instance_id_removed_|. 213 // |last_instance_id_removed_|.
166 if (guest_instance_id == last_instance_id_removed_ + 1) { 214 if (guest_instance_id == last_instance_id_removed_ + 1) {
167 ++last_instance_id_removed_; 215 ++last_instance_id_removed_;
168 // Compact. 216 // Compact.
169 std::set<int>::iterator iter = removed_instance_ids_.begin(); 217 std::set<int>::iterator iter = removed_instance_ids_.begin();
170 while (iter != removed_instance_ids_.end()) { 218 while (iter != removed_instance_ids_.end()) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 guest_web_contents_by_instance_id_.find(guest_instance_id); 283 guest_web_contents_by_instance_id_.find(guest_instance_id);
236 if (it == guest_web_contents_by_instance_id_.end()) 284 if (it == guest_web_contents_by_instance_id_.end())
237 return true; 285 return true;
238 286
239 GuestViewBase* guest_view = GuestViewBase::FromWebContents(it->second); 287 GuestViewBase* guest_view = GuestViewBase::FromWebContents(it->second);
240 if (!guest_view) 288 if (!guest_view)
241 return false; 289 return false;
242 290
243 return embedder_render_process_id == guest_view->embedder_render_process_id(); 291 return embedder_render_process_id == guest_view->embedder_render_process_id();
244 } 292 }
OLDNEW
« no previous file with comments | « chrome/browser/guest_view/guest_view_manager.h ('k') | chrome/browser/guest_view/web_view/web_view_guest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698