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/browser/stream_handle.h" | 10 #include "content/public/browser/stream_handle.h" |
11 #include "content/public/browser/stream_info.h" | 11 #include "content/public/browser/stream_info.h" |
| 12 #include "content/public/common/service_registry.h" |
12 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
13 #include "extensions/browser/api/extensions_api_client.h" | 14 #include "extensions/browser/api/extensions_api_client.h" |
| 15 #include "extensions/browser/api/mime_handler_private/mime_handler_private.h" |
14 #include "extensions/browser/extension_registry.h" | 16 #include "extensions/browser/extension_registry.h" |
15 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_stream_ma
nager.h" | 17 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_stream_ma
nager.h" |
16 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_cons
tants.h" | 18 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_cons
tants.h" |
17 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t_delegate.h" | 19 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t_delegate.h" |
18 #include "extensions/browser/process_manager.h" | 20 #include "extensions/browser/process_manager.h" |
19 #include "extensions/common/extension_messages.h" | 21 #include "extensions/common/extension_messages.h" |
20 #include "extensions/common/guest_view/guest_view_constants.h" | 22 #include "extensions/common/guest_view/guest_view_constants.h" |
21 #include "extensions/strings/grit/extensions_strings.h" | 23 #include "extensions/strings/grit/extensions_strings.h" |
22 #include "ipc/ipc_message_macros.h" | 24 #include "ipc/ipc_message_macros.h" |
23 #include "net/base/url_util.h" | 25 #include "net/base/url_util.h" |
24 | 26 |
25 using content::WebContents; | 27 using content::WebContents; |
26 | 28 |
27 namespace extensions { | 29 namespace extensions { |
28 | 30 |
29 StreamContainer::StreamContainer(scoped_ptr<content::StreamInfo> stream, | 31 StreamContainer::StreamContainer(scoped_ptr<content::StreamInfo> stream, |
| 32 int tab_id, |
| 33 bool embedded, |
30 const GURL& handler_url, | 34 const GURL& handler_url, |
31 const std::string& extension_id) | 35 const std::string& extension_id) |
32 : stream_(stream.Pass()), | 36 : stream_(stream.Pass()), |
| 37 embedded_(embedded), |
| 38 tab_id_(tab_id), |
33 handler_url_(handler_url), | 39 handler_url_(handler_url), |
34 extension_id_(extension_id), | 40 extension_id_(extension_id), |
35 weak_factory_(this) { | 41 weak_factory_(this) { |
36 } | 42 } |
37 | 43 |
38 StreamContainer::~StreamContainer() { | 44 StreamContainer::~StreamContainer() { |
39 } | 45 } |
40 | 46 |
41 void StreamContainer::Abort() { | 47 void StreamContainer::Abort(const base::Closure& callback) { |
| 48 if (!stream_) { |
| 49 callback.Run(); |
| 50 return; |
| 51 } |
| 52 stream_->handle->AddCloseListener(callback); |
42 stream_->handle.reset(); | 53 stream_->handle.reset(); |
43 } | 54 } |
44 | 55 |
45 base::WeakPtr<StreamContainer> StreamContainer::GetWeakPtr() { | 56 base::WeakPtr<StreamContainer> StreamContainer::GetWeakPtr() { |
46 return weak_factory_.GetWeakPtr(); | 57 return weak_factory_.GetWeakPtr(); |
47 } | 58 } |
48 | 59 |
49 // static | 60 // static |
50 const char MimeHandlerViewGuest::Type[] = "mimehandler"; | 61 const char MimeHandlerViewGuest::Type[] = "mimehandler"; |
51 | 62 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 130 |
120 WebContents::CreateParams params(browser_context(), guest_site_instance); | 131 WebContents::CreateParams params(browser_context(), guest_site_instance); |
121 params.guest_delegate = this; | 132 params.guest_delegate = this; |
122 callback.Run(WebContents::Create(params)); | 133 callback.Run(WebContents::Create(params)); |
123 } | 134 } |
124 | 135 |
125 void MimeHandlerViewGuest::DidAttachToEmbedder() { | 136 void MimeHandlerViewGuest::DidAttachToEmbedder() { |
126 web_contents()->GetController().LoadURL( | 137 web_contents()->GetController().LoadURL( |
127 stream_->handler_url(), content::Referrer(), | 138 stream_->handler_url(), content::Referrer(), |
128 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); | 139 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); |
| 140 web_contents()->GetMainFrame()->GetServiceRegistry()->AddService( |
| 141 base::Bind(&MimeHandlerServiceImpl::Create, stream_->GetWeakPtr())); |
129 } | 142 } |
130 | 143 |
131 void MimeHandlerViewGuest::DidInitialize( | 144 void MimeHandlerViewGuest::DidInitialize( |
132 const base::DictionaryValue& create_params) { | 145 const base::DictionaryValue& create_params) { |
133 extension_function_dispatcher_.reset( | 146 extension_function_dispatcher_.reset( |
134 new ExtensionFunctionDispatcher(browser_context(), this)); | 147 new ExtensionFunctionDispatcher(browser_context(), this)); |
135 if (delegate_) | 148 if (delegate_) |
136 delegate_->AttachHelpers(); | 149 delegate_->AttachHelpers(); |
137 } | 150 } |
138 | 151 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 228 |
216 void MimeHandlerViewGuest::OnRequest( | 229 void MimeHandlerViewGuest::OnRequest( |
217 const ExtensionHostMsg_Request_Params& params) { | 230 const ExtensionHostMsg_Request_Params& params) { |
218 if (extension_function_dispatcher_) { | 231 if (extension_function_dispatcher_) { |
219 extension_function_dispatcher_->Dispatch( | 232 extension_function_dispatcher_->Dispatch( |
220 params, web_contents()->GetRenderViewHost()); | 233 params, web_contents()->GetRenderViewHost()); |
221 } | 234 } |
222 } | 235 } |
223 | 236 |
224 } // namespace extensions | 237 } // namespace extensions |
OLD | NEW |