OLD | NEW |
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/mime_handler_view/mime_handler_view_gues
t.h" | 5 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
10 #include "content/public/common/url_constants.h" | 10 #include "content/public/common/url_constants.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 int MimeHandlerViewGuest::GetTaskPrefix() const { | 48 int MimeHandlerViewGuest::GetTaskPrefix() const { |
49 return IDS_EXTENSION_TASK_MANAGER_MIMEHANDLERVIEW_TAG_PREFIX; | 49 return IDS_EXTENSION_TASK_MANAGER_MIMEHANDLERVIEW_TAG_PREFIX; |
50 } | 50 } |
51 | 51 |
52 void MimeHandlerViewGuest::CreateWebContents( | 52 void MimeHandlerViewGuest::CreateWebContents( |
53 const std::string& embedder_extension_id, | 53 const std::string& embedder_extension_id, |
54 int embedder_render_process_id, | 54 int embedder_render_process_id, |
55 const base::DictionaryValue& create_params, | 55 const base::DictionaryValue& create_params, |
56 const WebContentsCreatedCallback& callback) { | 56 const WebContentsCreatedCallback& callback) { |
57 std::string orig_mime_type; | 57 std::string orig_mime_type; |
58 DCHECK( | 58 bool success = |
59 create_params.GetString(mime_handler_view::kMimeType, &orig_mime_type) && | 59 create_params.GetString(mime_handler_view::kMimeType, &orig_mime_type); |
60 !orig_mime_type.empty()); | 60 DCHECK(success && !orig_mime_type.empty()); |
61 std::string guest_site_str; | 61 std::string guest_site_str; |
62 // Note that we put a prefix "mime-" before the mime type so that this | 62 // Note that we put a prefix "mime-" before the mime type so that this |
63 // can never collide with an extension ID. | 63 // can never collide with an extension ID. |
64 guest_site_str = base::StringPrintf( | 64 guest_site_str = base::StringPrintf( |
65 "%s://mime-%s", content::kGuestScheme, orig_mime_type.c_str()); | 65 "%s://mime-%s", content::kGuestScheme, orig_mime_type.c_str()); |
66 GURL guest_site(guest_site_str); | 66 GURL guest_site(guest_site_str); |
67 | 67 |
68 // If we already have a mime handler view for the same mime type, we should | 68 // If we already have a mime handler view for the same mime type, we should |
69 // use the same SiteInstance so they go under same process. | 69 // use the same SiteInstance so they go under same process. |
70 GuestViewManager* guest_view_manager = | 70 GuestViewManager* guest_view_manager = |
71 GuestViewManager::FromBrowserContext(browser_context()); | 71 GuestViewManager::FromBrowserContext(browser_context()); |
72 content::SiteInstance* guest_site_instance = | 72 content::SiteInstance* guest_site_instance = |
73 guest_view_manager->GetGuestSiteInstance(guest_site); | 73 guest_view_manager->GetGuestSiteInstance(guest_site); |
74 if (!guest_site_instance) { | 74 if (!guest_site_instance) { |
75 // Create the SiteInstance in a new BrowsingInstance, which will ensure | 75 // Create the SiteInstance in a new BrowsingInstance, which will ensure |
76 // that guests from different render process are not allowed to send | 76 // that guests from different render process are not allowed to send |
77 // messages to each other. | 77 // messages to each other. |
78 guest_site_instance = | 78 guest_site_instance = |
79 content::SiteInstance::CreateForURL(browser_context(), guest_site); | 79 content::SiteInstance::CreateForURL(browser_context(), guest_site); |
80 } | 80 } |
81 WebContents::CreateParams params(browser_context(), guest_site_instance); | 81 WebContents::CreateParams params(browser_context(), guest_site_instance); |
82 params.guest_delegate = this; | 82 params.guest_delegate = this; |
83 callback.Run(WebContents::Create(params)); | 83 callback.Run(WebContents::Create(params)); |
84 } | 84 } |
85 | 85 |
86 void MimeHandlerViewGuest::DidAttachToEmbedder() { | 86 void MimeHandlerViewGuest::DidAttachToEmbedder() { |
87 std::string src; | 87 std::string src; |
88 DCHECK(attach_params()->GetString(mime_handler_view::kSrc, &src) && | 88 bool success = attach_params()->GetString(mime_handler_view::kSrc, &src); |
89 !src.empty()); | 89 DCHECK(success && !src.empty()); |
90 web_contents()->GetController().LoadURL( | 90 web_contents()->GetController().LoadURL( |
91 GURL(src), | 91 GURL(src), |
92 content::Referrer(), | 92 content::Referrer(), |
93 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 93 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
94 std::string()); | 94 std::string()); |
95 } | 95 } |
96 | 96 |
97 } // namespace extensions | 97 } // namespace extensions |
OLD | NEW |