diff options
author | Pierre Rossi <pierre.rossi@digia.com> | 2014-04-16 16:20:19 +0200 |
---|---|---|
committer | Pierre Rossi <pierre.rossi@gmail.com> | 2014-04-29 11:47:48 +0200 |
commit | 5a97ad8d88cd71d70f5ff30eb37446ac5cea32fd (patch) | |
tree | c8e82e61105f478be1f038905cbc7d97ee033fbe | |
parent | a6a44c1dcae097eeac597b688fb6b08d35188553 (diff) | |
download | qtwebengine-chromium-5a97ad8d88cd71d70f5ff30eb37446ac5cea32fd.tar.gz |
Add files needed for WebRTC to the snapshot.
The desktop/screen capture in WebRTC is implemented in a self contained
way in the chrome layer, and there is no point in copying it. We just need
to ensure we ship it in our snapshot.
Change-Id: Ia17b905317fb0c2b142c672a0c79d33e0ee01f68
Reviewed-by: Andras Becsi <andras.becsi@digia.com>
3 files changed, 199 insertions, 0 deletions
diff --git a/chromium/chrome/browser/media/desktop_media_list.h b/chromium/chrome/browser/media/desktop_media_list.h new file mode 100644 index 00000000000..fa0dbd81574 --- /dev/null +++ b/chromium/chrome/browser/media/desktop_media_list.h @@ -0,0 +1,60 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_LIST_H_ +#define CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_LIST_H_ + +#include "base/basictypes.h" +#include "base/time/time.h" +#include "content/public/browser/desktop_media_id.h" +#include "ui/gfx/image/image_skia.h" + +class DesktopMediaListObserver; + +// DesktopMediaList provides the list of desktop media source (screens, windows, +// tabs), and their thumbnails, to the desktop media picker dialog. It +// transparently updates the list in the background, and notifies the desktop +// media picker when something changes. +class DesktopMediaList { + public: + // Struct used to represent each entry in the list. + struct Source { + // Id of the source. + content::DesktopMediaID id; + + // Name of the source that should be shown to the user. + base::string16 name; + + // The thumbnail for the source. + gfx::ImageSkia thumbnail; + }; + + virtual ~DesktopMediaList() {} + + // Sets time interval between updates. By default list of sources and their + // thumbnail are updated once per second. If called after StartUpdating() then + // it will take effect only after the next update. + virtual void SetUpdatePeriod(base::TimeDelta period) = 0; + + // Sets size to which the thumbnails should be scaled. If called after + // StartUpdating() then some thumbnails may be still scaled to the old size + // until they are updated. + virtual void SetThumbnailSize(const gfx::Size& thumbnail_size) = 0; + + // Sets ID of the hosting desktop picker dialog. The window with this ID will + // be filtered out from the list of sources. + virtual void SetViewDialogWindowId(content::DesktopMediaID::Id dialog_id) = 0; + + // Starts updating the model. The model is initially empty, so OnSourceAdded() + // notifications will be generated for each existing source as it is + // enumerated. After the initial enumeration the model will be refreshed based + // on the update period, and notifications generated only for changes in the + // model. + virtual void StartUpdating(DesktopMediaListObserver* observer) = 0; + + virtual int GetSourceCount() const = 0; + virtual const Source& GetSource(int index) const = 0; +}; + +#endif // CHROME_BROWSER_MEDIA_DESKTOP_MEDIA_LIST_H_ diff --git a/chromium/chrome/browser/media/desktop_streams_registry.cc b/chromium/chrome/browser/media/desktop_streams_registry.cc new file mode 100644 index 00000000000..05c2ba007ce --- /dev/null +++ b/chromium/chrome/browser/media/desktop_streams_registry.cc @@ -0,0 +1,82 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/media/desktop_streams_registry.h" + +#include "base/base64.h" +#include "base/location.h" +#include "base/time/time.h" +#include "content/public/browser/browser_thread.h" +#include "crypto/random.h" + +namespace { + +const int kStreamIdLengthBytes = 16; + +const int kApprovedStreamTimeToLiveSeconds = 10; + +std::string GenerateRandomStreamId() { + char buffer[kStreamIdLengthBytes]; + crypto::RandBytes(buffer, arraysize(buffer)); + std::string result; + base::Base64Encode(base::StringPiece(buffer, arraysize(buffer)), + &result); + return result; +} + +} // namespace + +DesktopStreamsRegistry::DesktopStreamsRegistry() {} +DesktopStreamsRegistry::~DesktopStreamsRegistry() {} + +std::string DesktopStreamsRegistry::RegisterStream( + int render_process_id, + int render_view_id, + const GURL& origin, + const content::DesktopMediaID& source) { + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + + std::string id = GenerateRandomStreamId(); + ApprovedDesktopMediaStream& stream = approved_streams_[id]; + stream.render_process_id = render_process_id; + stream.render_view_id = render_view_id; + stream.origin = origin; + stream.source = source; + + content::BrowserThread::PostDelayedTask( + content::BrowserThread::UI, FROM_HERE, + base::Bind(&DesktopStreamsRegistry::CleanupStream, + base::Unretained(this), id), + base::TimeDelta::FromSeconds(kApprovedStreamTimeToLiveSeconds)); + + return id; +} + +content::DesktopMediaID DesktopStreamsRegistry::RequestMediaForStreamId( + const std::string& id, + int render_process_id, + int render_view_id, + const GURL& origin) { + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + + StreamsMap::iterator it = approved_streams_.find(id); + + // Verify that if there is a request with the specified ID it was created for + // the same origin and the same renderer. + if (it == approved_streams_.end() || + render_process_id != it->second.render_process_id || + render_view_id != it->second.render_view_id || + origin != it->second.origin) { + return content::DesktopMediaID(); + } + + content::DesktopMediaID result = it->second.source; + approved_streams_.erase(it); + return result; +} + +void DesktopStreamsRegistry::CleanupStream(const std::string& id) { + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + approved_streams_.erase(id); +} diff --git a/chromium/chrome/browser/media/desktop_streams_registry.h b/chromium/chrome/browser/media/desktop_streams_registry.h new file mode 100644 index 00000000000..f2735ae71f6 --- /dev/null +++ b/chromium/chrome/browser/media/desktop_streams_registry.h @@ -0,0 +1,57 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_MEDIA_DESKTOP_STREAMS_REGISTRY_H_ +#define CHROME_BROWSER_MEDIA_DESKTOP_STREAMS_REGISTRY_H_ + +#include <map> +#include <string> + +#include "chrome/browser/media/desktop_media_list.h" +#include "url/gurl.h" + +// DesktopStreamsRegistry is used to store accepted desktop media streams for +// Desktop Capture API. Single instance of this class is created per browser in +// MediaCaptureDevicesDispatcher. +class DesktopStreamsRegistry { + public: + DesktopStreamsRegistry(); + ~DesktopStreamsRegistry(); + + // Adds new stream to the registry. Called by the implementation of + // desktopCapture.chooseDesktopMedia() API after user has approved access to + // |source| for the |origin|. Returns identifier of the new stream. + std::string RegisterStream(int render_process_id, + int render_view_id, + const GURL& origin, + const content::DesktopMediaID& source); + + // Validates stream identifier specified in getUserMedia(). Returns null + // DesktopMediaID if the specified |id| is invalid, i.e. wasn't generated + // using RegisterStream() or if it was generated for a different origin. + // Otherwise returns ID of the source and removes it from the registry. + content::DesktopMediaID RequestMediaForStreamId(const std::string& id, + int render_process_id, + int render_view_id, + const GURL& origin); + + private: + // Type used to store list of accepted desktop media streams. + struct ApprovedDesktopMediaStream { + int render_process_id; + int render_view_id; + GURL origin; + content::DesktopMediaID source; + }; + typedef std::map<std::string, ApprovedDesktopMediaStream> StreamsMap; + + // Helper function that removes an expired stream from the registry. + void CleanupStream(const std::string& id); + + StreamsMap approved_streams_; + + DISALLOW_COPY_AND_ASSIGN(DesktopStreamsRegistry); +}; + +#endif // CHROME_BROWSER_MEDIA_DESKTOP_STREAMS_REGISTRY_H_ |