| 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..1018b72455bd2c632accdd6eb8a66ed9728c4c77 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,42 @@ 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) {
|
| + // Create the event's arguments value.
|
| + scoped_ptr<ListValue> event_args(new ListValue());
|
| + event_args->Append(new base::StringValue(stream->GetMimeType()));
|
| + event_args->Append(new base::StringValue(stream->GetOriginalURL().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());
|
| +
|
| + streams_[extension_id][stream->GetURL()] =
|
| + make_linked_ptr(stream.release());
|
| +}
|
| +
|
| static base::LazyInstance<ProfileKeyedAPIFactory<StreamsPrivateAPI> >
|
| g_factory = LAZY_INSTANCE_INITIALIZER;
|
|
|
| @@ -44,4 +73,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) {
|
| + const Extension* extension =
|
| + content::Details<const UnloadedExtensionInfo>(details)->extension;
|
| + streams_.erase(extension->id());
|
| + }
|
| +}
|
| } // namespace extensions
|
|
|