13551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 23551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 33551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// found in the LICENSE file. 43551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 53551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#ifndef CHROME_BROWSER_EXTENSIONS_API_DESKTOP_CAPTURE_DESKTOP_CAPTURE_API_H_ 63551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#define CHROME_BROWSER_EXTENSIONS_API_DESKTOP_CAPTURE_DESKTOP_CAPTURE_API_H_ 73551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 84e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include <map> 94e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/memory/singleton.h" 111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/extensions/chrome_extension_function.h" 12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/media/desktop_media_list.h" 133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/media/desktop_media_picker.h" 14a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/media/native_desktop_media_list.h" 153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/common/extensions/api/desktop_capture.h" 163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "url/gurl.h" 173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace extensions { 193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class DesktopCaptureChooseDesktopMediaFunction 211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) : public ChromeAsyncExtensionFunction { 223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) public: 233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DECLARE_EXTENSION_FUNCTION("desktopCapture.chooseDesktopMedia", 243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DESKTOPCAPTURE_CHOOSEDESKTOPMEDIA) 253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 26a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Factory creating DesktopMediaList and DesktopMediaPicker instances. 273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Used for tests to supply fake picker. 283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) class PickerFactory { 293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) public: 30a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual scoped_ptr<DesktopMediaList> CreateModel(bool show_screens, 31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool show_windows) = 0; 323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual scoped_ptr<DesktopMediaPicker> CreatePicker() = 0; 333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) protected: 343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual ~PickerFactory() {} 353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) }; 363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Used to set PickerFactory used to create mock DesktopMediaPicker instances 383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // for tests. Calling tests keep ownership of the factory. Can be called with 393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // |factory| set to NULL at the end of the test. 403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) static void SetPickerFactoryForTests(PickerFactory* factory); 413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) DesktopCaptureChooseDesktopMediaFunction(); 433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void Cancel(); 454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) private: 473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual ~DesktopCaptureChooseDesktopMediaFunction(); 483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // ExtensionFunction overrides. 503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual bool RunImpl() OVERRIDE; 513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void OnPickerDialogResults(content::DesktopMediaID source); 533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int request_id_; 554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Parameters of the tab the stream is requested for. 574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int render_process_id_; 584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int render_view_id_; 593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) GURL origin_; 603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) scoped_ptr<DesktopMediaPicker> picker_; 623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}; 633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class DesktopCaptureCancelChooseDesktopMediaFunction 651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) : public ChromeSyncExtensionFunction { 664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) public: 674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DECLARE_EXTENSION_FUNCTION("desktopCapture.cancelChooseDesktopMedia", 684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DESKTOPCAPTURE_CANCELCHOOSEDESKTOPMEDIA) 694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DesktopCaptureCancelChooseDesktopMediaFunction(); 714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) private: 734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual ~DesktopCaptureCancelChooseDesktopMediaFunction(); 744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 754e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // ExtensionFunction overrides. 764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual bool RunImpl() OVERRIDE; 774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}; 784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class DesktopCaptureRequestsRegistry { 804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) public: 814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DesktopCaptureRequestsRegistry(); 824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ~DesktopCaptureRequestsRegistry(); 834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) static DesktopCaptureRequestsRegistry* GetInstance(); 854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void AddRequest(int process_id, 874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int request_id, 884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DesktopCaptureChooseDesktopMediaFunction* handler); 894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void RemoveRequest(int process_id, int request_id); 904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void CancelRequest(int process_id, int request_id); 914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) private: 934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) friend struct DefaultSingletonTraits<DesktopCaptureRequestsRegistry>; 944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) struct RequestId { 964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) RequestId(int process_id, int request_id); 974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Need to use RequestId as a key in std::map<>. 994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) bool operator<(const RequestId& other) const; 1004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int process_id; 1024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) int request_id; 1034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) }; 1044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1054e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) typedef std::map<RequestId, 1064e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DesktopCaptureChooseDesktopMediaFunction*> RequestsMap; 1074e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) RequestsMap requests_; 1094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(DesktopCaptureRequestsRegistry); 1114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}; 1124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} // namespace extensions 1143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#endif // CHROME_BROWSER_EXTENSIONS_API_DESKTOP_CAPTURE_DESKTOP_CAPTURE_API_H_ 116