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

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: Move AttachToBrowserPlugin to RenderFrame 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/guest_view/guest_view_base.h" 9 #include "chrome/browser/guest_view/guest_view_base.h"
9 #include "chrome/browser/guest_view/guest_view_manager_factory.h" 10 #include "chrome/browser/guest_view/guest_view_manager_factory.h"
10 #include "content/public/browser/browser_context.h" 11 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/render_process_host.h" 12 #include "content/public/browser/render_process_host.h"
13 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/user_metrics.h" 14 #include "content/public/browser/user_metrics.h"
13 #include "content/public/browser/web_contents_observer.h" 15 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/common/result_codes.h" 16 #include "content/public/common/result_codes.h"
15 #include "content/public/common/url_constants.h" 17 #include "content/public/common/url_constants.h"
16 #include "extensions/browser/extension_system.h" 18 #include "extensions/browser/extension_system.h"
17 #include "extensions/browser/guest_view/guest_view_constants.h" 19 #include "extensions/browser/guest_view/guest_view_constants.h"
18 #include "net/base/escape.h" 20 #include "net/base/escape.h"
19 #include "url/gurl.h" 21 #include "url/gurl.h"
20 22
21 using content::BrowserContext; 23 using content::BrowserContext;
(...skipping 29 matching lines...) Expand all
51 content::WebContents* GuestViewManager::GetGuestByInstanceIDSafely( 53 content::WebContents* GuestViewManager::GetGuestByInstanceIDSafely(
52 int guest_instance_id, 54 int guest_instance_id,
53 int embedder_render_process_id) { 55 int embedder_render_process_id) {
54 if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id, 56 if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id,
55 guest_instance_id)) { 57 guest_instance_id)) {
56 return NULL; 58 return NULL;
57 } 59 }
58 return GetGuestByInstanceID(guest_instance_id); 60 return GetGuestByInstanceID(guest_instance_id);
59 } 61 }
60 62
63 void GuestViewManager::SetAttachParamsForGuest(
64 int embedder_render_process_id,
65 int embedder_routing_id,
66 int element_instance_id,
67 int guest_instance_id,
68 const base::DictionaryValue& params) {
69 content::WebContents* guest_web_contents =
70 GetGuestByInstanceIDSafely(guest_instance_id, embedder_render_process_id);
71 if (!guest_web_contents)
72 return;
73
74 GuestViewBase* guest_view =
75 GuestViewBase::FromWebContents(guest_web_contents);
76 DCHECK(guest_view);
77
78 content::RenderViewHost* rvh =
79 content::RenderViewHost::FromID(embedder_render_process_id,
80 embedder_routing_id);
81 content::WebContents* embedder_web_contents =
82 content::WebContents::FromRenderViewHost(rvh);
83 if (!embedder_web_contents)
84 return;
85 ElementInstanceKey key(embedder_web_contents, element_instance_id);
86 instance_id_map_[key] = guest_instance_id;
87 reverse_instance_id_map_.insert(std::make_pair(guest_instance_id, key));
88 guest_view->SetAttachParams(params);
89 }
90
61 int GuestViewManager::GetNextInstanceID() { 91 int GuestViewManager::GetNextInstanceID() {
62 return ++current_instance_id_; 92 return ++current_instance_id_;
63 } 93 }
64 94
65 void GuestViewManager::CreateGuest(const std::string& view_type, 95 void GuestViewManager::CreateGuest(const std::string& view_type,
66 const std::string& embedder_extension_id, 96 const std::string& embedder_extension_id,
67 content::WebContents* embedder_web_contents, 97 content::WebContents* embedder_web_contents,
68 const base::DictionaryValue& create_params, 98 const base::DictionaryValue& create_params,
69 const WebContentsCreatedCallback& callback) { 99 const WebContentsCreatedCallback& callback) {
70 int guest_instance_id = GetNextInstanceID(); 100 int guest_instance_id = GetNextInstanceID();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id, 135 if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id,
106 guest_instance_id)) { 136 guest_instance_id)) {
107 // If we kill the embedder, then don't bother calling back. 137 // If we kill the embedder, then don't bother calling back.
108 return; 138 return;
109 } 139 }
110 content::WebContents* guest_web_contents = 140 content::WebContents* guest_web_contents =
111 GetGuestByInstanceID(guest_instance_id); 141 GetGuestByInstanceID(guest_instance_id);
112 callback.Run(guest_web_contents); 142 callback.Run(guest_web_contents);
113 } 143 }
114 144
145 int GuestViewManager::GetGuestInstanceIDForPluginID(
146 content::WebContents* embedder_web_contents,
147 int element_instance_id) {
148 GuestInstanceIDMap::iterator iter = instance_id_map_.find(
149 ElementInstanceKey(embedder_web_contents, element_instance_id));
150 DCHECK(iter != instance_id_map_.end());
151 int guest_instance_id = iter->second;
152 return guest_instance_id;
153 }
154
115 SiteInstance* GuestViewManager::GetGuestSiteInstance( 155 SiteInstance* GuestViewManager::GetGuestSiteInstance(
116 const GURL& guest_site) { 156 const GURL& guest_site) {
117 for (GuestInstanceMap::const_iterator it = 157 for (GuestInstanceMap::const_iterator it =
118 guest_web_contents_by_instance_id_.begin(); 158 guest_web_contents_by_instance_id_.begin();
119 it != guest_web_contents_by_instance_id_.end(); ++it) { 159 it != guest_web_contents_by_instance_id_.end(); ++it) {
120 if (it->second->GetSiteInstance()->GetSiteURL() == guest_site) 160 if (it->second->GetSiteInstance()->GetSiteURL() == guest_site)
121 return it->second->GetSiteInstance(); 161 return it->second->GetSiteInstance();
122 } 162 }
123 return NULL; 163 return NULL;
124 } 164 }
(...skipping 20 matching lines...) Expand all
145 CHECK(CanUseGuestInstanceID(guest_instance_id)); 185 CHECK(CanUseGuestInstanceID(guest_instance_id));
146 guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents; 186 guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents;
147 } 187 }
148 188
149 void GuestViewManager::RemoveGuest(int guest_instance_id) { 189 void GuestViewManager::RemoveGuest(int guest_instance_id) {
150 GuestInstanceMap::iterator it = 190 GuestInstanceMap::iterator it =
151 guest_web_contents_by_instance_id_.find(guest_instance_id); 191 guest_web_contents_by_instance_id_.find(guest_instance_id);
152 DCHECK(it != guest_web_contents_by_instance_id_.end()); 192 DCHECK(it != guest_web_contents_by_instance_id_.end());
153 guest_web_contents_by_instance_id_.erase(it); 193 guest_web_contents_by_instance_id_.erase(it);
154 194
195 GuestInstanceIDReverseMap::iterator id_iter =
196 reverse_instance_id_map_.find(guest_instance_id);
197 if (id_iter != reverse_instance_id_map_.end()) {
198 const ElementInstanceKey& instance_id_key = id_iter->second;
199 instance_id_map_.erase(instance_id_map_.find(instance_id_key));
200 reverse_instance_id_map_.erase(id_iter);
201 }
202
155 // All the instance IDs that lie within [0, last_instance_id_removed_] 203 // All the instance IDs that lie within [0, last_instance_id_removed_]
156 // are invalid. 204 // are invalid.
157 // The remaining sparse invalid IDs are kept in |removed_instance_ids_| set. 205 // The remaining sparse invalid IDs are kept in |removed_instance_ids_| set.
158 // The following code compacts the set by incrementing 206 // The following code compacts the set by incrementing
159 // |last_instance_id_removed_|. 207 // |last_instance_id_removed_|.
160 if (guest_instance_id == last_instance_id_removed_ + 1) { 208 if (guest_instance_id == last_instance_id_removed_ + 1) {
161 ++last_instance_id_removed_; 209 ++last_instance_id_removed_;
162 // Compact. 210 // Compact.
163 std::set<int>::iterator iter = removed_instance_ids_.begin(); 211 std::set<int>::iterator iter = removed_instance_ids_.begin();
164 while (iter != removed_instance_ids_.end()) { 212 while (iter != removed_instance_ids_.end()) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 guest_web_contents_by_instance_id_.find(guest_instance_id); 277 guest_web_contents_by_instance_id_.find(guest_instance_id);
230 if (it == guest_web_contents_by_instance_id_.end()) 278 if (it == guest_web_contents_by_instance_id_.end())
231 return true; 279 return true;
232 280
233 GuestViewBase* guest_view = GuestViewBase::FromWebContents(it->second); 281 GuestViewBase* guest_view = GuestViewBase::FromWebContents(it->second);
234 if (!guest_view) 282 if (!guest_view)
235 return false; 283 return false;
236 284
237 return embedder_render_process_id == guest_view->embedder_render_process_id(); 285 return embedder_render_process_id == guest_view->embedder_render_process_id();
238 } 286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698