Index: chrome/browser/extensions/api/streams_private/streams_private_api.cc |
diff --git a/chrome/browser/extensions/api/streams_private/streams_private_api.cc b/chrome/browser/extensions/api/streams_private/streams_private_api.cc |
index db22e8e2a03b611fa67b5f6f9f2e07cdc2566a04..c65f954c1702b4f58f4061ff2b146d0c61b1a507 100644 |
--- a/chrome/browser/extensions/api/streams_private/streams_private_api.cc |
+++ b/chrome/browser/extensions/api/streams_private/streams_private_api.cc |
@@ -15,6 +15,7 @@ |
#include "chrome/browser/extensions/extension_system.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/common/extensions/mime_types_handler.h" |
+#include "content/public/browser/stream_handle.h" |
namespace keys = extension_input_module_constants; |
@@ -27,14 +28,53 @@ const char kOnExecuteMimeTypeHandler[] = |
namespace extensions { |
+// static |
+StreamsPrivateAPI* StreamsPrivateAPI::Get(Profile* profile) { |
+ return GetFactoryInstance()->GetForProfile(profile); |
+} |
+ |
StreamsPrivateAPI::StreamsPrivateAPI(Profile* profile) |
- : profile_(profile) { |
+ : profile_(profile), |
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
(new MimeTypesHandlerParser)->Register(); |
+ |
+ registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
+ content::Source<Profile>(profile)); |
} |
StreamsPrivateAPI::~StreamsPrivateAPI() { |
} |
+void StreamsPrivateAPI::ExecuteMimeTypeHandler( |
+ const std::string& extension_id, |
+ scoped_ptr<content::StreamHandle> stream, |
+ const std::string& mime_type, |
+ const GURL& original_url) { |
+ // Create the event's arguments value. |
+ scoped_ptr<ListValue> event_args(new ListValue()); |
+ event_args->Append(new base::StringValue(mime_type)); |
darin (slow to review)
2013/03/19 06:12:51
it feels like these could be parameters of the Str
Zachary Kuznia
2013/03/19 06:59:35
Done.
|
+ event_args->Append(new base::StringValue(original_url.spec())); |
+ event_args->Append(new base::StringValue(stream->GetUrl().spec())); |
+ |
+ scoped_ptr<Event> event(new Event(events::kOnExecuteMimeTypeHandler, |
+ event_args.Pass())); |
+ |
+ ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( |
+ extension_id, event.Pass()); |
+ |
+ stream->RegisterCloseCallback(base::Bind(&StreamsPrivateAPI::OnStreamClosed, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ extension_id, |
+ stream->GetUrl())); |
+ streams_[extension_id][stream->GetUrl()] = |
+ make_linked_ptr(stream.release()); |
+} |
+ |
+void StreamsPrivateAPI::OnStreamClosed(const std::string& extension_id, |
+ const GURL& url) { |
+ streams_[extension_id].erase(url); |
+} |
+ |
static base::LazyInstance<ProfileKeyedAPIFactory<StreamsPrivateAPI> > |
g_factory = LAZY_INSTANCE_INITIALIZER; |
@@ -44,4 +84,13 @@ ProfileKeyedAPIFactory<StreamsPrivateAPI>* |
return &g_factory.Get(); |
} |
+void StreamsPrivateAPI::Observe(int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { |
kinuko
2013/03/18 00:28:17
(drive-by) UNLOADED event is dispatched when an ex
Zachary Kuznia
2013/03/18 01:06:55
This is where chrome.omnibox, chrome.push_messagin
kinuko
2013/03/18 01:46:17
I agree that we should handle this case too... and
|
+ const Extension* extension = |
+ content::Details<const UnloadedExtensionInfo>(details)->extension; |
+ streams_.erase(extension->id()); |
+ } |
+} |
} // namespace extensions |