Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / streams_private / streams_private_api.h
blob42081a64fa326f985806cac7800dc03bf457fd40
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_STREAMS_PRIVATE_STREAMS_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_STREAMS_PRIVATE_STREAMS_PRIVATE_API_H_
8 #include <map>
9 #include <string>
11 #include "base/scoped_observer.h"
12 #include "extensions/browser/browser_context_keyed_api_factory.h"
13 #include "extensions/browser/extension_function.h"
14 #include "extensions/browser/extension_registry_observer.h"
16 namespace content {
17 class BrowserContext;
18 class StreamHandle;
19 struct StreamInfo;
22 namespace extensions {
23 class ExtensionRegistry;
25 class StreamsPrivateAPI : public BrowserContextKeyedAPI,
26 public ExtensionRegistryObserver {
27 public:
28 // Convenience method to get the StreamsPrivateAPI for a BrowserContext.
29 static StreamsPrivateAPI* Get(content::BrowserContext* context);
31 explicit StreamsPrivateAPI(content::BrowserContext* context);
32 ~StreamsPrivateAPI() override;
34 // Send the onExecuteMimeTypeHandler event to |extension_id|.
35 // |web_contents| is used to determine the tabId where the document is being
36 // opened. The data for the document will be readable from |stream|, and
37 // should be |expected_content_size| bytes long. If the viewer is being opened
38 // in a BrowserPlugin, specify a non-empty |view_id| of the plugin. |embedded|
39 // should be set to whether the document is embedded within another document.
40 void ExecuteMimeTypeHandler(const std::string& extension_id,
41 content::WebContents* web_contents,
42 scoped_ptr<content::StreamInfo> stream,
43 const std::string& view_id,
44 int64 expected_content_size,
45 bool embedded,
46 int render_process_id,
47 int render_frame_id);
49 void AbortStream(const std::string& extension_id,
50 const GURL& stream_url,
51 const base::Closure& callback);
53 // BrowserContextKeyedAPI implementation.
54 static BrowserContextKeyedAPIFactory<StreamsPrivateAPI>* GetFactoryInstance();
56 private:
57 friend class BrowserContextKeyedAPIFactory<StreamsPrivateAPI>;
58 typedef std::map<std::string,
59 std::map<GURL,
60 linked_ptr<content::StreamHandle> > > StreamMap;
62 // ExtensionRegistryObserver implementation.
63 void OnExtensionUnloaded(content::BrowserContext* browser_context,
64 const Extension* extension,
65 UnloadedExtensionInfo::Reason reason) override;
67 // BrowserContextKeyedAPI implementation.
68 static const char* service_name() {
69 return "StreamsPrivateAPI";
71 static const bool kServiceIsNULLWhileTesting = true;
72 static const bool kServiceRedirectedInIncognito = true;
74 content::BrowserContext* const browser_context_;
75 StreamMap streams_;
77 // Listen to extension unloaded notifications.
78 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
79 extension_registry_observer_;
81 base::WeakPtrFactory<StreamsPrivateAPI> weak_ptr_factory_;
85 class StreamsPrivateAbortFunction : public UIThreadExtensionFunction {
86 public:
87 StreamsPrivateAbortFunction();
88 DECLARE_EXTENSION_FUNCTION("streamsPrivate.abort", STREAMSPRIVATE_ABORT)
90 protected:
91 ~StreamsPrivateAbortFunction() override {}
93 // ExtensionFunction:
94 ExtensionFunction::ResponseAction Run() override;
96 private:
97 void OnClose();
99 std::string stream_url_;
102 } // namespace extensions
104 #endif // CHROME_BROWSER_EXTENSIONS_API_STREAMS_PRIVATE_STREAMS_PRIVATE_API_H_