/chrome/browser/extensions/api/streams_private/streams_private_api.h

https://gitlab.com/jonnialva90/iridium-browser · C Header · 104 lines · 65 code · 24 blank · 15 comment · 0 complexity · a695a59880763c8935fee05dd58cb48b MD5 · raw file

  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.
  4. #ifndef CHROME_BROWSER_EXTENSIONS_API_STREAMS_PRIVATE_STREAMS_PRIVATE_API_H_
  5. #define CHROME_BROWSER_EXTENSIONS_API_STREAMS_PRIVATE_STREAMS_PRIVATE_API_H_
  6. #include <map>
  7. #include <string>
  8. #include "base/scoped_observer.h"
  9. #include "extensions/browser/browser_context_keyed_api_factory.h"
  10. #include "extensions/browser/extension_function.h"
  11. #include "extensions/browser/extension_registry_observer.h"
  12. namespace content {
  13. class BrowserContext;
  14. class StreamHandle;
  15. struct StreamInfo;
  16. }
  17. namespace extensions {
  18. class ExtensionRegistry;
  19. class StreamsPrivateAPI : public BrowserContextKeyedAPI,
  20. public ExtensionRegistryObserver {
  21. public:
  22. // Convenience method to get the StreamsPrivateAPI for a BrowserContext.
  23. static StreamsPrivateAPI* Get(content::BrowserContext* context);
  24. explicit StreamsPrivateAPI(content::BrowserContext* context);
  25. ~StreamsPrivateAPI() override;
  26. // Send the onExecuteMimeTypeHandler event to |extension_id|.
  27. // |web_contents| is used to determine the tabId where the document is being
  28. // opened. The data for the document will be readable from |stream|, and
  29. // should be |expected_content_size| bytes long. If the viewer is being opened
  30. // in a BrowserPlugin, specify a non-empty |view_id| of the plugin. |embedded|
  31. // should be set to whether the document is embedded within another document.
  32. void ExecuteMimeTypeHandler(const std::string& extension_id,
  33. content::WebContents* web_contents,
  34. scoped_ptr<content::StreamInfo> stream,
  35. const std::string& view_id,
  36. int64 expected_content_size,
  37. bool embedded,
  38. int render_process_id,
  39. int render_frame_id);
  40. void AbortStream(const std::string& extension_id,
  41. const GURL& stream_url,
  42. const base::Closure& callback);
  43. // BrowserContextKeyedAPI implementation.
  44. static BrowserContextKeyedAPIFactory<StreamsPrivateAPI>* GetFactoryInstance();
  45. private:
  46. friend class BrowserContextKeyedAPIFactory<StreamsPrivateAPI>;
  47. typedef std::map<std::string,
  48. std::map<GURL,
  49. linked_ptr<content::StreamHandle> > > StreamMap;
  50. // ExtensionRegistryObserver implementation.
  51. void OnExtensionUnloaded(content::BrowserContext* browser_context,
  52. const Extension* extension,
  53. UnloadedExtensionInfo::Reason reason) override;
  54. // BrowserContextKeyedAPI implementation.
  55. static const char* service_name() {
  56. return "StreamsPrivateAPI";
  57. }
  58. static const bool kServiceIsNULLWhileTesting = true;
  59. static const bool kServiceRedirectedInIncognito = true;
  60. content::BrowserContext* const browser_context_;
  61. StreamMap streams_;
  62. // Listen to extension unloaded notifications.
  63. ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
  64. extension_registry_observer_;
  65. base::WeakPtrFactory<StreamsPrivateAPI> weak_ptr_factory_;
  66. };
  67. class StreamsPrivateAbortFunction : public UIThreadExtensionFunction {
  68. public:
  69. StreamsPrivateAbortFunction();
  70. DECLARE_EXTENSION_FUNCTION("streamsPrivate.abort", STREAMSPRIVATE_ABORT)
  71. protected:
  72. ~StreamsPrivateAbortFunction() override {}
  73. // ExtensionFunction:
  74. ExtensionFunction::ResponseAction Run() override;
  75. private:
  76. void OnClose();
  77. std::string stream_url_;
  78. };
  79. } // namespace extensions
  80. #endif // CHROME_BROWSER_EXTENSIONS_API_STREAMS_PRIVATE_STREAMS_PRIVATE_API_H_