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

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

Powered by Google App Engine
This is Rietveld 408576698