OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "chrome/browser/extensions/api/tab_capture/offscreen_tab.h" | 5 #include "chrome/browser/extensions/api/tab_capture/offscreen_tab.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" |
11 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" | 12 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/web_contents_sizer.h" | 14 #include "chrome/browser/ui/web_contents_sizer.h" |
14 #include "content/public/browser/render_widget_host_view.h" | 15 #include "content/public/browser/render_widget_host_view.h" |
15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
16 #include "extensions/browser/extension_host.h" | 17 #include "extensions/browser/extension_host.h" |
17 #include "extensions/browser/process_manager.h" | 18 #include "extensions/browser/process_manager.h" |
18 | 19 |
19 using content::WebContents; | 20 using content::WebContents; |
20 | 21 |
(...skipping 29 matching lines...) Expand all Loading... |
50 return FromWebContents(extension_web_contents); | 51 return FromWebContents(extension_web_contents); |
51 } | 52 } |
52 | 53 |
53 OffscreenTab* OffscreenTabsOwner::OpenNewTab( | 54 OffscreenTab* OffscreenTabsOwner::OpenNewTab( |
54 const GURL& start_url, | 55 const GURL& start_url, |
55 const gfx::Size& initial_size, | 56 const gfx::Size& initial_size, |
56 const std::string& optional_presentation_id) { | 57 const std::string& optional_presentation_id) { |
57 if (tabs_.size() >= kMaxOffscreenTabsPerExtension) | 58 if (tabs_.size() >= kMaxOffscreenTabsPerExtension) |
58 return nullptr; // Maximum number of offscreen tabs reached. | 59 return nullptr; // Maximum number of offscreen tabs reached. |
59 | 60 |
60 tabs_.push_back(new OffscreenTab(this)); | 61 // OffscreenTab cannot be created with MakeUnique<OffscreenTab> since the |
| 62 // constructor is protected. So create it separately, and then move it to |
| 63 // |tabs_| below. |
| 64 std::unique_ptr<OffscreenTab> offscreen_tab(new OffscreenTab(this)); |
| 65 tabs_.push_back(std::move(offscreen_tab)); |
61 tabs_.back()->Start(start_url, initial_size, optional_presentation_id); | 66 tabs_.back()->Start(start_url, initial_size, optional_presentation_id); |
62 return tabs_.back(); | 67 return tabs_.back().get(); |
63 } | 68 } |
64 | 69 |
65 void OffscreenTabsOwner::DestroyTab(OffscreenTab* tab) { | 70 void OffscreenTabsOwner::DestroyTab(OffscreenTab* tab) { |
66 const auto it = std::find(tabs_.begin(), tabs_.end(), tab); | 71 for (std::vector<std::unique_ptr<OffscreenTab>>::iterator iter = |
67 if (it != tabs_.end()) | 72 tabs_.begin(); |
68 tabs_.erase(it); | 73 iter != tabs_.end(); ++iter) { |
| 74 if (iter->get() == tab) { |
| 75 tabs_.erase(iter); |
| 76 break; |
| 77 } |
| 78 } |
69 } | 79 } |
70 | 80 |
71 OffscreenTab::OffscreenTab(OffscreenTabsOwner* owner) | 81 OffscreenTab::OffscreenTab(OffscreenTabsOwner* owner) |
72 : owner_(owner), | 82 : owner_(owner), |
73 profile_(Profile::FromBrowserContext( | 83 profile_(Profile::FromBrowserContext( |
74 owner->extension_web_contents()->GetBrowserContext()) | 84 owner->extension_web_contents()->GetBrowserContext()) |
75 ->CreateOffTheRecordProfile()), | 85 ->CreateOffTheRecordProfile()), |
76 capture_poll_timer_(false, false), | 86 capture_poll_timer_(false, false), |
77 content_capture_was_detected_(false) { | 87 content_capture_was_detected_(false) { |
78 DCHECK(profile_); | 88 DCHECK(profile_); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 | 362 |
353 // Schedule the timer to check again in a second. | 363 // Schedule the timer to check again in a second. |
354 capture_poll_timer_.Start( | 364 capture_poll_timer_.Start( |
355 FROM_HERE, | 365 FROM_HERE, |
356 base::TimeDelta::FromSeconds(kPollIntervalInSeconds), | 366 base::TimeDelta::FromSeconds(kPollIntervalInSeconds), |
357 base::Bind(&OffscreenTab::DieIfContentCaptureEnded, | 367 base::Bind(&OffscreenTab::DieIfContentCaptureEnded, |
358 base::Unretained(this))); | 368 base::Unretained(this))); |
359 } | 369 } |
360 | 370 |
361 } // namespace extensions | 371 } // namespace extensions |
OLD | NEW |