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

Unified Diff: chrome/browser/extensions/api/streams_private/streams_private_api.cc

Issue 12645004: Add Resource Handler for creating Streams to forward to extensions (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Disable Stream Resource Throttle Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698