| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_STREAMS_PRIVATE_STREAMS_PRIVATE_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_STREAMS_PRIVATE_STREAMS_PRIVATE_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_STREAMS_PRIVATE_STREAMS_PRIVATE_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_STREAMS_PRIVATE_STREAMS_PRIVATE_API_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 namespace extensions { | 22 namespace extensions { |
| 23 class ExtensionRegistry; | 23 class ExtensionRegistry; |
| 24 | 24 |
| 25 class StreamsPrivateAPI : public BrowserContextKeyedAPI, | 25 class StreamsPrivateAPI : public BrowserContextKeyedAPI, |
| 26 public ExtensionRegistryObserver { | 26 public ExtensionRegistryObserver { |
| 27 public: | 27 public: |
| 28 // Convenience method to get the StreamsPrivateAPI for a BrowserContext. | 28 // Convenience method to get the StreamsPrivateAPI for a BrowserContext. |
| 29 static StreamsPrivateAPI* Get(content::BrowserContext* context); | 29 static StreamsPrivateAPI* Get(content::BrowserContext* context); |
| 30 | 30 |
| 31 explicit StreamsPrivateAPI(content::BrowserContext* context); | 31 explicit StreamsPrivateAPI(content::BrowserContext* context); |
| 32 virtual ~StreamsPrivateAPI(); | 32 ~StreamsPrivateAPI() override; |
| 33 | 33 |
| 34 // Send the onExecuteMimeTypeHandler event to |extension_id|. | 34 // Send the onExecuteMimeTypeHandler event to |extension_id|. |
| 35 // |web_contents| is used to determine the tabId where the document is being | 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 | 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 | 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. | 38 // in a BrowserPlugin, specify a non-empty |view_id| of the plugin. |
| 39 void ExecuteMimeTypeHandler(const std::string& extension_id, | 39 void ExecuteMimeTypeHandler(const std::string& extension_id, |
| 40 content::WebContents* web_contents, | 40 content::WebContents* web_contents, |
| 41 scoped_ptr<content::StreamInfo> stream, | 41 scoped_ptr<content::StreamInfo> stream, |
| 42 const std::string& view_id, | 42 const std::string& view_id, |
| 43 int64 expected_content_size); | 43 int64 expected_content_size); |
| 44 | 44 |
| 45 void AbortStream(const std::string& extension_id, | 45 void AbortStream(const std::string& extension_id, |
| 46 const GURL& stream_url, | 46 const GURL& stream_url, |
| 47 const base::Closure& callback); | 47 const base::Closure& callback); |
| 48 | 48 |
| 49 // BrowserContextKeyedAPI implementation. | 49 // BrowserContextKeyedAPI implementation. |
| 50 static BrowserContextKeyedAPIFactory<StreamsPrivateAPI>* GetFactoryInstance(); | 50 static BrowserContextKeyedAPIFactory<StreamsPrivateAPI>* GetFactoryInstance(); |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 friend class BrowserContextKeyedAPIFactory<StreamsPrivateAPI>; | 53 friend class BrowserContextKeyedAPIFactory<StreamsPrivateAPI>; |
| 54 typedef std::map<std::string, | 54 typedef std::map<std::string, |
| 55 std::map<GURL, | 55 std::map<GURL, |
| 56 linked_ptr<content::StreamHandle> > > StreamMap; | 56 linked_ptr<content::StreamHandle> > > StreamMap; |
| 57 | 57 |
| 58 // ExtensionRegistryObserver implementation. | 58 // ExtensionRegistryObserver implementation. |
| 59 virtual void OnExtensionUnloaded( | 59 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 60 content::BrowserContext* browser_context, | 60 const Extension* extension, |
| 61 const Extension* extension, | 61 UnloadedExtensionInfo::Reason reason) override; |
| 62 UnloadedExtensionInfo::Reason reason) override; | |
| 63 | 62 |
| 64 // BrowserContextKeyedAPI implementation. | 63 // BrowserContextKeyedAPI implementation. |
| 65 static const char* service_name() { | 64 static const char* service_name() { |
| 66 return "StreamsPrivateAPI"; | 65 return "StreamsPrivateAPI"; |
| 67 } | 66 } |
| 68 static const bool kServiceIsNULLWhileTesting = true; | 67 static const bool kServiceIsNULLWhileTesting = true; |
| 69 static const bool kServiceRedirectedInIncognito = true; | 68 static const bool kServiceRedirectedInIncognito = true; |
| 70 | 69 |
| 71 content::BrowserContext* const browser_context_; | 70 content::BrowserContext* const browser_context_; |
| 72 StreamMap streams_; | 71 StreamMap streams_; |
| 73 | 72 |
| 74 // Listen to extension unloaded notifications. | 73 // Listen to extension unloaded notifications. |
| 75 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 74 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 76 extension_registry_observer_; | 75 extension_registry_observer_; |
| 77 | 76 |
| 78 base::WeakPtrFactory<StreamsPrivateAPI> weak_ptr_factory_; | 77 base::WeakPtrFactory<StreamsPrivateAPI> weak_ptr_factory_; |
| 79 | 78 |
| 80 }; | 79 }; |
| 81 | 80 |
| 82 class StreamsPrivateAbortFunction : public UIThreadExtensionFunction { | 81 class StreamsPrivateAbortFunction : public UIThreadExtensionFunction { |
| 83 public: | 82 public: |
| 84 StreamsPrivateAbortFunction(); | 83 StreamsPrivateAbortFunction(); |
| 85 DECLARE_EXTENSION_FUNCTION("streamsPrivate.abort", STREAMSPRIVATE_ABORT) | 84 DECLARE_EXTENSION_FUNCTION("streamsPrivate.abort", STREAMSPRIVATE_ABORT) |
| 86 | 85 |
| 87 protected: | 86 protected: |
| 88 virtual ~StreamsPrivateAbortFunction() {} | 87 ~StreamsPrivateAbortFunction() override {} |
| 89 | 88 |
| 90 // ExtensionFunction: | 89 // ExtensionFunction: |
| 91 virtual ExtensionFunction::ResponseAction Run() override; | 90 ExtensionFunction::ResponseAction Run() override; |
| 92 | 91 |
| 93 private: | 92 private: |
| 94 void OnClose(); | 93 void OnClose(); |
| 95 | 94 |
| 96 std::string stream_url_; | 95 std::string stream_url_; |
| 97 }; | 96 }; |
| 98 | 97 |
| 99 } // namespace extensions | 98 } // namespace extensions |
| 100 | 99 |
| 101 #endif // CHROME_BROWSER_EXTENSIONS_API_STREAMS_PRIVATE_STREAMS_PRIVATE_API_H_ | 100 #endif // CHROME_BROWSER_EXTENSIONS_API_STREAMS_PRIVATE_STREAMS_PRIVATE_API_H_ |
| OLD | NEW |