diff options
author | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-26 06:11:22 +0000 |
---|---|---|
committer | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-26 06:11:22 +0000 |
commit | b9ba3949a1d29e2950bed1f308d46c0e75e3b6ba (patch) | |
tree | 19a5b75b6d5c47b756dbade4013e5c8b17a313c3 | |
parent | b4cfaa2253999d87e9129e73ac8c645803e3b9c2 (diff) | |
download | chromium_src-b9ba3949a1d29e2950bed1f308d46c0e75e3b6ba.zip chromium_src-b9ba3949a1d29e2950bed1f308d46c0e75e3b6ba.tar.gz chromium_src-b9ba3949a1d29e2950bed1f308d46c0e75e3b6ba.tar.bz2 |
Modify chrome.streamsPrivate to provide a single object as the parameter
BUG=345882
Review URL: https://codereview.chromium.org/175593006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253374 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 50 insertions, 44 deletions
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 a4925e4b..e2f14dc 100644 --- a/chrome/browser/extensions/api/streams_private/streams_private_api.cc +++ b/chrome/browser/extensions/api/streams_private/streams_private_api.cc @@ -13,21 +13,17 @@ #include "chrome/browser/extensions/extension_function_registry.h" #include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/common/extensions/api/streams_private.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" #include "content/public/browser/stream_handle.h" #include "extensions/browser/event_router.h" #include "extensions/browser/extension_system.h" -namespace events { - -const char kOnExecuteMimeTypeHandler[] = - "streamsPrivate.onExecuteMimeTypeHandler"; - -} // namespace events - namespace extensions { +namespace streams_private = api::streams_private; + // static StreamsPrivateAPI* StreamsPrivateAPI::Get(content::BrowserContext* context) { return GetFactoryInstance()->GetForProfile(context); @@ -49,20 +45,20 @@ void StreamsPrivateAPI::ExecuteMimeTypeHandler( scoped_ptr<content::StreamHandle> stream, int64 expected_content_size) { // Create the event's arguments value. - scoped_ptr<base::ListValue> event_args(new base::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())); - event_args->Append( - new base::FundamentalValue(ExtensionTabUtil::GetTabId(web_contents))); + streams_private::StreamInfo info; + info.mime_type = stream->GetMimeType(); + info.original_url = stream->GetOriginalURL().spec(); + info.stream_url = stream->GetURL().spec(); + info.tab_id = ExtensionTabUtil::GetTabId(web_contents); int size = -1; if (expected_content_size <= INT_MAX) size = expected_content_size; - event_args->Append(new base::FundamentalValue(size)); + info.expected_content_size = size; - scoped_ptr<Event> event(new Event(events::kOnExecuteMimeTypeHandler, - event_args.Pass())); + scoped_ptr<Event> event( + new Event(streams_private::OnExecuteMimeTypeHandler::kEventName, + streams_private::OnExecuteMimeTypeHandler::Create(info))); ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( extension_id, event.Pass()); diff --git a/chrome/browser/extensions/api/streams_private/streams_private_apitest.cc b/chrome/browser/extensions/api/streams_private/streams_private_apitest.cc index 333de0f..c49dc7a 100644 --- a/chrome/browser/extensions/api/streams_private/streams_private_apitest.cc +++ b/chrome/browser/extensions/api/streams_private/streams_private_apitest.cc @@ -10,6 +10,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "chrome/common/extensions/api/streams_private.h" #include "chrome/common/extensions/mime_types_handler.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/test_switches.h" @@ -43,6 +44,8 @@ using net::test_server::HttpResponse; using net::test_server::EmbeddedTestServer; using testing::_; +namespace streams_private = extensions::api::streams_private; + namespace { // Test server's request handler. @@ -149,15 +152,16 @@ class StreamsPrivateApiTest : public ExtensionApiTest { // event with the "test/done" MIME type (unless the 'chrome.test.notifyFail' // has already been called). void SendDoneEvent() { - scoped_ptr<base::ListValue> event_args(new base::ListValue()); - event_args->Append(new base::StringValue("test/done")); - event_args->Append(new base::StringValue("http://foo")); - event_args->Append(new base::StringValue("blob://bar")); - event_args->Append(new base::FundamentalValue(10)); - event_args->Append(new base::FundamentalValue(20)); - - scoped_ptr<Event> event(new Event( - "streamsPrivate.onExecuteMimeTypeHandler", event_args.Pass())); + streams_private::StreamInfo info; + info.mime_type = "test/done"; + info.original_url = "http://foo"; + info.stream_url = "blob://bar"; + info.tab_id = 10; + info.expected_content_size = 20; + + scoped_ptr<Event> event( + new Event(streams_private::OnExecuteMimeTypeHandler::kEventName, + streams_private::OnExecuteMimeTypeHandler::Create(info))); ExtensionSystem::Get(browser()->profile())->event_router()-> DispatchEventToExtension(test_extension_id_, event.Pass()); diff --git a/chrome/common/extensions/api/api.gyp b/chrome/common/extensions/api/api.gyp index 26b5460..1d70bbe 100644 --- a/chrome/common/extensions/api/api.gyp +++ b/chrome/common/extensions/api/api.gyp @@ -30,7 +30,6 @@ 'media_player_private.json', 'music_manager_private.idl', 'principals_private.idl', - 'streams_private.idl', 'top_sites.json', ], 'conditions': [ @@ -105,6 +104,7 @@ 'sockets_tcp_server.idl', 'sockets_udp.idl', 'storage.json', + 'streams_private.idl', 'sync_file_system.idl', 'system_cpu.idl', 'system_display.idl', diff --git a/chrome/common/extensions/api/streams_private.idl b/chrome/common/extensions/api/streams_private.idl index 1033e88..f81d99d 100644 --- a/chrome/common/extensions/api/streams_private.idl +++ b/chrome/common/extensions/api/streams_private.idl @@ -4,24 +4,30 @@ // Streams Private API. namespace streamsPrivate { + dictionary StreamInfo { + // The MIME type of the intercepted URL request. + DOMString mimeType; + + // The original URL that was intercepted. + DOMString originalUrl; + + // The URL that the stream can be read from. + DOMString streamUrl; + + // The ID of the tab that opened the stream. If the stream is not opened in + // a tab, it will be -1. + long tabId; + + // The amount of data the Stream should contain, if known. If there is no + // information on the size it will be -1. + long expectedContentSize; + }; + interface Events { // Fired when a resource is fetched which matches a mime type handled by // this extension. The resource request is cancelled, and the extension is // expected to handle the request. The event is restricted to a small number // of white-listed extensions. - static void onExecuteMimeTypeHandler( - // The MIME type of the intercepted URL request. - DOMString mimeType, - // The original URL that was intercepted. - DOMString originalUrl, - // The URL that the stream can be read from. - DOMString streamUrl, - // The ID of the tab that opened the stream. If the stream is not opened - // in a tab, it will be -1. - long tabId, - // The amount of data the Stream should contain, if known. If there is - // no information on the size it will be -1. - long expectedContentSize - ); + static void onExecuteMimeTypeHandler(StreamInfo streamInfo); }; }; diff --git a/chrome/test/data/extensions/api_test/streams_private/handle_mime_type/background.js b/chrome/test/data/extensions/api_test/streams_private/handle_mime_type/background.js index b58d41c..a944906 100644 --- a/chrome/test/data/extensions/api_test/streams_private/handle_mime_type/background.js +++ b/chrome/test/data/extensions/api_test/streams_private/handle_mime_type/background.js @@ -6,11 +6,11 @@ var hasFailed = false; chrome.streamsPrivate.onExecuteMimeTypeHandler.addListener( - function(mime_type, original_url, content_url, tab_id, expected_size) { + function(params) { // The tests are setup so resources with MIME type 'application/msword' are // meant to be handled by the extension. The extension getting an event with // the MIME type 'application/msword' means the test has succeeded. - if (mime_type == 'application/msword') { + if (params.mimeType == 'application/msword') { chrome.test.notifyPass(); return; } @@ -18,7 +18,7 @@ chrome.streamsPrivate.onExecuteMimeTypeHandler.addListener( // The tests are setup so resources with MIME type 'plain/text' are meant to // be handled by the browser (i.e. downloaded). The extension getting event // with MIME type 'plain/text' is thus a failure. - if (mime_type == 'plain/text') { + if (params.mimeType == 'plain/text') { chrome.test.notifyFail( 'Unexpected request to handle "plain/text" MIME type.'); // Set |hasFailed| so notifyPass doesn't get called later (when event with @@ -31,6 +31,6 @@ chrome.streamsPrivate.onExecuteMimeTypeHandler.addListener( // should be raised to notify the extension it's job is done. If the extension // receives the 'test/done' and there were no previous failures, notify that // the test has succeeded. - if (!hasFailed && mime_type == 'test/done') + if (!hasFailed && params.mimeType == 'test/done') chrome.test.notifyPass(); }); |