Chromium Code Reviews| Index: chrome/browser/extensions/api/tab_capture/offscreen_presentation.cc |
| diff --git a/chrome/browser/extensions/api/tab_capture/offscreen_presentation.cc b/chrome/browser/extensions/api/tab_capture/offscreen_presentation.cc |
| index 2ccd614b8035321582aac9c7c12777da22d06bdf..4b70b1605dc35af0c5fb15c094d061c82d305ae9 100644 |
| --- a/chrome/browser/extensions/api/tab_capture/offscreen_presentation.cc |
| +++ b/chrome/browser/extensions/api/tab_capture/offscreen_presentation.cc |
| @@ -7,6 +7,8 @@ |
| #include <algorithm> |
| #include "base/bind.h" |
| +#include "base/rand_util.h" |
| +#include "base/strings/string_number_conversions.h" |
| #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/web_contents_sizer.h" |
| @@ -138,25 +140,27 @@ OffscreenPresentationsOwner* OffscreenPresentationsOwner::Get( |
| return FromWebContents(extension_web_contents); |
| } |
| -OffscreenPresentation* OffscreenPresentationsOwner::FindOrStartPresentation( |
| +OffscreenPresentation* OffscreenPresentationsOwner::StartPresentation( |
| const GURL& start_url, |
| - const std::string& presentation_id, |
| const gfx::Size& initial_size) { |
| - OffscreenPresentation* presentation = |
| - FindPresentation(start_url, presentation_id); |
| - if (presentation) { |
| - DVLOG(1) << "Returning already-running OffscreenPresentation for start_url=" |
| - << presentation->start_url(); |
| - return presentation; |
| - } |
| - |
| if (presentations_.size() >= kMaxPresentationsPerExtension) |
| return nullptr; // Maximum number of presentations reached. |
| - presentation = new OffscreenPresentation(this, start_url, presentation_id); |
| - presentations_.push_back(presentation); |
| - presentation->Start(initial_size); |
| - return presentation; |
| + presentations_.push_back(new OffscreenPresentation( |
| + this, |
| + start_url, |
| + CreateUniqueRandomId())); |
| + presentations_.back()->Start(initial_size); |
| + return presentations_.back(); |
| +} |
| + |
| +OffscreenPresentation* OffscreenPresentationsOwner::FindByOffscreenTabId( |
| + const std::string& offscreen_tab_id) const { |
| + for (OffscreenPresentation* p : presentations_) { |
| + if (p->id() == offscreen_tab_id) |
| + return p; |
| + } |
| + return nullptr; |
| } |
| void OffscreenPresentationsOwner::ClosePresentation( |
| @@ -167,14 +171,14 @@ void OffscreenPresentationsOwner::ClosePresentation( |
| presentations_.erase(it); |
| } |
| -OffscreenPresentation* OffscreenPresentationsOwner::FindPresentation( |
| - const GURL& start_url, const std::string& presentation_id) const { |
| - for (OffscreenPresentation* presentation : presentations_) { |
| - if (presentation->start_url() == start_url && |
| - presentation->presentation_id() == presentation_id) |
| - return presentation; |
| +std::string OffscreenPresentationsOwner::CreateUniqueRandomId() const { |
| + while (true) { |
|
not at google - send to devlin
2015/10/02 01:17:26
Curious: what is the advantage in generating a ran
miu
2015/10/02 18:58:21
No longer applicable.
|
| + const uint64 random_number = base::RandUint64(); |
| + const std::string candidate_id = |
| + base::HexEncode(&random_number, sizeof(random_number)); |
| + if (!FindByOffscreenTabId(candidate_id)) |
| + return candidate_id; |
| } |
| - return nullptr; |
| } |
| OffscreenPresentation::OffscreenPresentation(OffscreenPresentationsOwner* owner, |
| @@ -182,7 +186,7 @@ OffscreenPresentation::OffscreenPresentation(OffscreenPresentationsOwner* owner, |
| const std::string& id) |
| : owner_(owner), |
| start_url_(start_url), |
| - presentation_id_(id), |
| + id_(id), |
| profile_(Profile::FromBrowserContext( |
| owner->extension_web_contents()->GetBrowserContext()) |
| ->CreateOffTheRecordProfile()), |
| @@ -381,14 +385,12 @@ void OffscreenPresentation::RequestMediaAccessPermission( |
| // WebContents. |
| content::BrowserContext* const extension_browser_context = |
| owner_->extension_web_contents()->GetBrowserContext(); |
| - std::string extension_id; |
| - for (const ExtensionHost* host : |
| - ProcessManager::Get(extension_browser_context)->background_hosts()) { |
| - if (host->host_contents() == owner_->extension_web_contents()) { |
| - extension_id = host->extension_id(); |
| - break; |
| - } |
| - } |
| + const extensions::Extension* const extension = |
| + ProcessManager::Get(extension_browser_context)-> |
| + GetExtensionForWebContents(owner_->extension_web_contents()); |
| + const std::string extension_id = extension ? extension->id() : ""; |
| + LOG_IF(DFATAL, extension_id.empty()) |
| + << "Extension that started this OffscreenPresentation was not found."; |
| // If verified, allow any tab capture audio/video devices that were requested. |
| extensions::TabCaptureRegistry* const tab_capture_registry = |