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

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

Issue 376033002: Adding MimeHandlerView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pending-zork-patch2
Patch Set: With the new attach approach Created 6 years, 3 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/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_process_host.h" 9 #include "content/public/browser/render_process_host.h"
10 #include "content/public/browser/render_view_host.h" 10 #include "content/public/browser/render_view_host.h"
11 #include "content/public/browser/user_metrics.h" 11 #include "content/public/browser/user_metrics.h"
12 #include "content/public/browser/web_contents_observer.h" 12 #include "content/public/browser/web_contents_observer.h"
13 #include "content/public/common/result_codes.h" 13 #include "content/public/common/result_codes.h"
14 #include "content/public/common/url_constants.h" 14 #include "content/public/common/url_constants.h"
15 #include "extensions/browser/extension_system.h" 15 #include "extensions/browser/extension_system.h"
16 #include "extensions/browser/guest_view/guest_view_base.h" 16 #include "extensions/browser/guest_view/guest_view_base.h"
17 #include "extensions/browser/guest_view/guest_view_constants.h" 17 #include "extensions/browser/guest_view/guest_view_constants.h"
18 #include "extensions/browser/guest_view/guest_view_manager_factory.h" 18 #include "extensions/browser/guest_view/guest_view_manager_factory.h"
19 #include "extensions/common/extension_messages.h"
19 #include "net/base/escape.h" 20 #include "net/base/escape.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
21 22
22 using content::BrowserContext; 23 using content::BrowserContext;
23 using content::SiteInstance; 24 using content::SiteInstance;
24 using content::WebContents; 25 using content::WebContents;
25 26
26 namespace extensions { 27 namespace extensions {
27 28
28 // static 29 // static
(...skipping 25 matching lines...) Expand all
54 content::WebContents* GuestViewManager::GetGuestByInstanceIDSafely( 55 content::WebContents* GuestViewManager::GetGuestByInstanceIDSafely(
55 int guest_instance_id, 56 int guest_instance_id,
56 int embedder_render_process_id) { 57 int embedder_render_process_id) {
57 if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id, 58 if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id,
58 guest_instance_id)) { 59 guest_instance_id)) {
59 return NULL; 60 return NULL;
60 } 61 }
61 return GetGuestByInstanceID(guest_instance_id); 62 return GetGuestByInstanceID(guest_instance_id);
62 } 63 }
63 64
65 void GuestViewManager::CreateMimeHandlerViewGuest(
66 int embedder_render_process_id,
67 int embedder_routing_id,
68 const std::string& url,
69 const std::string& mime_type,
70 int element_instance_id) {
71 content::RenderViewHost* rvh =
72 content::RenderViewHost::FromID(embedder_render_process_id,
73 embedder_routing_id);
74 content::WebContents* embedder_web_contents =
75 content::WebContents::FromRenderViewHost(rvh);
76 GuestViewManager::WebContentsCreatedCallback callback =
77 base::Bind(&GuestViewManager::OnMimeHandlerViewGuestCreated,
78 // TODO(lazyboy): Use weak ptr.
79 base::Unretained(this),
80 element_instance_id,
81 embedder_render_process_id,
82 embedder_routing_id,
83 url);
84 base::DictionaryValue create_params;
85 create_params.SetString(guestview::kMimeTypeParam, mime_type);
86 // TODO(lazyboy): use MimeHandlerViewGuest::Type, cannot do this as
87 // MimeHandlerViewGuest is under chrome/ not extensions/.
88 CreateGuest("mimehandler",
Fady Samuel 2014/08/29 18:52:32 Can this be done in ExtensionMessageFilter?
lazyboy 2014/08/29 22:08:26 Done.
89 "",
90 embedder_web_contents,
91 create_params,
92 callback);
93 }
94
64 void GuestViewManager::AttachGuest( 95 void GuestViewManager::AttachGuest(
65 int embedder_render_process_id, 96 int embedder_render_process_id,
66 int embedder_routing_id, 97 int embedder_routing_id,
67 int element_instance_id, 98 int element_instance_id,
68 int guest_instance_id, 99 int guest_instance_id,
69 const base::DictionaryValue& attach_params) { 100 const base::DictionaryValue& attach_params) {
70 content::WebContents* guest_web_contents = 101 content::WebContents* guest_web_contents =
71 GetGuestByInstanceIDSafely(guest_instance_id, embedder_render_process_id); 102 GetGuestByInstanceIDSafely(guest_instance_id, embedder_render_process_id);
72 if (!guest_web_contents) 103 if (!guest_web_contents)
73 return; 104 return;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 } 306 }
276 return true; 307 return true;
277 } 308 }
278 309
279 bool GuestViewManager::CanUseGuestInstanceID(int guest_instance_id) { 310 bool GuestViewManager::CanUseGuestInstanceID(int guest_instance_id) {
280 if (guest_instance_id <= last_instance_id_removed_) 311 if (guest_instance_id <= last_instance_id_removed_)
281 return false; 312 return false;
282 return !ContainsKey(removed_instance_ids_, guest_instance_id); 313 return !ContainsKey(removed_instance_ids_, guest_instance_id);
283 } 314 }
284 315
316 void GuestViewManager::OnMimeHandlerViewGuestCreated(
Fady Samuel 2014/08/29 18:52:32 Move this to ExtensionMessageFilter?
lazyboy 2014/08/29 22:08:26 Done.
317 int element_id,
318 int embedder_render_process_id,
319 int embedder_routing_id,
320 const std::string& src,
321 content::WebContents* web_contents) {
322 GuestViewBase* guest_view = GuestViewBase::FromWebContents(web_contents);
323 if (guest_view) {
Fady Samuel 2014/08/29 18:52:32 DCHECK(guest_view);
lazyboy 2014/08/29 22:08:26 Done.
324 int guest_instance_id = guest_view->guest_instance_id();
325
326 base::DictionaryValue attach_params;
327 attach_params.SetString("src", src);
328 AttachGuest(
329 embedder_render_process_id,
330 embedder_routing_id,
331 element_id,
332 guest_instance_id,
333 attach_params);
334 // TODO(lazyboy): guest_instance_id not needed actually.
335 IPC::Message* msg = new ExtensionMsg_CreateMimeHandlerViewGuestACK(
336 element_id, guest_instance_id);
337 msg->set_routing_id(embedder_routing_id);
338 content::RenderViewHost* rvh =
339 content::RenderViewHost::FromID(embedder_render_process_id, embedder_rou ting_id);
340 rvh->Send(msg);
341 }
342 }
343
285 bool GuestViewManager::CanEmbedderAccessInstanceID( 344 bool GuestViewManager::CanEmbedderAccessInstanceID(
286 int embedder_render_process_id, 345 int embedder_render_process_id,
287 int guest_instance_id) { 346 int guest_instance_id) {
288 // The embedder is trying to access a guest with a negative or zero 347 // The embedder is trying to access a guest with a negative or zero
289 // instance ID. 348 // instance ID.
290 if (guest_instance_id <= guestview::kInstanceIDNone) 349 if (guest_instance_id <= guestview::kInstanceIDNone)
291 return false; 350 return false;
292 351
293 // The embedder is trying to access an instance ID that has not yet been 352 // The embedder is trying to access an instance ID that has not yet been
294 // allocated by GuestViewManager. This could cause instance ID 353 // allocated by GuestViewManager. This could cause instance ID
(...skipping 10 matching lines...) Expand all
305 return true; 364 return true;
306 365
307 GuestViewBase* guest_view = GuestViewBase::FromWebContents(it->second); 366 GuestViewBase* guest_view = GuestViewBase::FromWebContents(it->second);
308 if (!guest_view) 367 if (!guest_view)
309 return false; 368 return false;
310 369
311 return embedder_render_process_id == guest_view->embedder_render_process_id(); 370 return embedder_render_process_id == guest_view->embedder_render_process_id();
312 } 371 }
313 372
314 } // namespace extensions 373 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698