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

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: Make sure things are called on the right thread. 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..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

Powered by Google App Engine
This is Rietveld 408576698