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/task_manager/web_contents_tags.h" | 5 #include "chrome/browser/task_manager/web_contents_tags.h" |
6 | 6 |
7 #include "chrome/browser/task_manager/providers/web_contents/background_contents
_tag.h" | 7 #include "chrome/browser/task_manager/providers/web_contents/background_contents
_tag.h" |
8 #include "chrome/browser/task_manager/providers/web_contents/devtools_tag.h" | 8 #include "chrome/browser/task_manager/providers/web_contents/devtools_tag.h" |
9 #include "chrome/browser/task_manager/providers/web_contents/extension_tag.h" | 9 #include "chrome/browser/task_manager/providers/web_contents/extension_tag.h" |
10 #include "chrome/browser/task_manager/providers/web_contents/guest_tag.h" | 10 #include "chrome/browser/task_manager/providers/web_contents/guest_tag.h" |
11 #include "chrome/browser/task_manager/providers/web_contents/prerender_tag.h" | 11 #include "chrome/browser/task_manager/providers/web_contents/prerender_tag.h" |
12 #include "chrome/browser/task_manager/providers/web_contents/printing_tag.h" | 12 #include "chrome/browser/task_manager/providers/web_contents/printing_tag.h" |
13 #include "chrome/browser/task_manager/providers/web_contents/tab_contents_tag.h" | 13 #include "chrome/browser/task_manager/providers/web_contents/tab_contents_tag.h" |
14 #include "chrome/browser/task_manager/providers/web_contents/web_contents_tags_m
anager.h" | 14 #include "chrome/browser/task_manager/providers/web_contents/web_contents_tags_m
anager.h" |
15 #include "components/guest_view/browser/guest_view_base.h" | 15 #include "components/guest_view/browser/guest_view_base.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "extensions/browser/view_type_utils.h" | 17 #include "extensions/browser/view_type_utils.h" |
| 18 #include "extensions/features/features.h" |
18 #include "printing/features/features.h" | 19 #include "printing/features/features.h" |
19 | 20 |
20 #if defined(ENABLE_EXTENSIONS) | 21 #if BUILDFLAG(ENABLE_EXTENSIONS) |
21 #include "extensions/browser/process_manager.h" | 22 #include "extensions/browser/process_manager.h" |
22 #endif | 23 #endif |
23 | 24 |
24 namespace task_manager { | 25 namespace task_manager { |
25 | 26 |
26 #if defined(ENABLE_TASK_MANAGER) | 27 #if defined(ENABLE_TASK_MANAGER) |
27 namespace { | 28 namespace { |
28 | 29 |
29 // Adds the |tag| to |contents|. It also adds the |tag| to the | 30 // Adds the |tag| to |contents|. It also adds the |tag| to the |
30 // |WebContentsTagsManager|. | 31 // |WebContentsTagsManager|. |
31 // Note: This will fail if |contents| is already tagged by |tag|. | 32 // Note: This will fail if |contents| is already tagged by |tag|. |
32 void TagWebContents(content::WebContents* contents, | 33 void TagWebContents(content::WebContents* contents, |
33 WebContentsTag* tag, | 34 WebContentsTag* tag, |
34 void* tag_key) { | 35 void* tag_key) { |
35 DCHECK(contents); | 36 DCHECK(contents); |
36 DCHECK(tag); | 37 DCHECK(tag); |
37 DCHECK(WebContentsTag::FromWebContents(contents) == nullptr); | 38 DCHECK(WebContentsTag::FromWebContents(contents) == nullptr); |
38 contents->SetUserData(tag_key, tag); | 39 contents->SetUserData(tag_key, tag); |
39 WebContentsTagsManager::GetInstance()->AddTag(tag); | 40 WebContentsTagsManager::GetInstance()->AddTag(tag); |
40 } | 41 } |
41 | 42 |
42 #if defined(ENABLE_EXTENSIONS) | 43 #if BUILDFLAG(ENABLE_EXTENSIONS) |
43 | 44 |
44 bool IsExtensionWebContents(content::WebContents* contents) { | 45 bool IsExtensionWebContents(content::WebContents* contents) { |
45 DCHECK(contents); | 46 DCHECK(contents); |
46 | 47 |
47 if (guest_view::GuestViewBase::IsGuest(contents)) | 48 if (guest_view::GuestViewBase::IsGuest(contents)) |
48 return false; | 49 return false; |
49 | 50 |
50 extensions::ViewType view_type = extensions::GetViewType(contents); | 51 extensions::ViewType view_type = extensions::GetViewType(contents); |
51 return (view_type != extensions::VIEW_TYPE_INVALID && | 52 return (view_type != extensions::VIEW_TYPE_INVALID && |
52 view_type != extensions::VIEW_TYPE_TAB_CONTENTS && | 53 view_type != extensions::VIEW_TYPE_TAB_CONTENTS && |
53 view_type != extensions::VIEW_TYPE_BACKGROUND_CONTENTS); | 54 view_type != extensions::VIEW_TYPE_BACKGROUND_CONTENTS); |
54 } | 55 } |
55 | 56 |
56 #endif // defined(ENABLE_EXTENSIONS) | 57 #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
57 | 58 |
58 } // namespace | 59 } // namespace |
59 #endif // defined(ENABLE_TASK_MANAGER) | 60 #endif // defined(ENABLE_TASK_MANAGER) |
60 | 61 |
61 // static | 62 // static |
62 void WebContentsTags::CreateForBackgroundContents( | 63 void WebContentsTags::CreateForBackgroundContents( |
63 content::WebContents* web_contents, | 64 content::WebContents* web_contents, |
64 BackgroundContents* background_contents) { | 65 BackgroundContents* background_contents) { |
65 #if defined(ENABLE_TASK_MANAGER) | 66 #if defined(ENABLE_TASK_MANAGER) |
66 if (!WebContentsTag::FromWebContents(web_contents)) { | 67 if (!WebContentsTag::FromWebContents(web_contents)) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 TagWebContents(web_contents, | 129 TagWebContents(web_contents, |
129 new GuestTag(web_contents), | 130 new GuestTag(web_contents), |
130 WebContentsTag::kTagKey); | 131 WebContentsTag::kTagKey); |
131 } | 132 } |
132 #endif // defined(ENABLE_TASK_MANAGER) | 133 #endif // defined(ENABLE_TASK_MANAGER) |
133 } | 134 } |
134 | 135 |
135 // static | 136 // static |
136 void WebContentsTags::CreateForExtension(content::WebContents* web_contents, | 137 void WebContentsTags::CreateForExtension(content::WebContents* web_contents, |
137 extensions::ViewType view_type) { | 138 extensions::ViewType view_type) { |
138 #if defined(ENABLE_TASK_MANAGER) && defined(ENABLE_EXTENSIONS) | 139 #if defined(ENABLE_TASK_MANAGER) && BUILDFLAG(ENABLE_EXTENSIONS) |
139 DCHECK(IsExtensionWebContents(web_contents)); | 140 DCHECK(IsExtensionWebContents(web_contents)); |
140 | 141 |
141 if (!WebContentsTag::FromWebContents(web_contents)) { | 142 if (!WebContentsTag::FromWebContents(web_contents)) { |
142 TagWebContents(web_contents, | 143 TagWebContents(web_contents, |
143 new ExtensionTag(web_contents, view_type), | 144 new ExtensionTag(web_contents, view_type), |
144 WebContentsTag::kTagKey); | 145 WebContentsTag::kTagKey); |
145 } | 146 } |
146 #endif // defined(ENABLE_TASK_MANAGER) && defined(ENABLE_EXTENSIONS) | 147 #endif // defined(ENABLE_TASK_MANAGER) && BUILDFLAG(ENABLE_EXTENSIONS) |
147 } | 148 } |
148 | 149 |
149 // static | 150 // static |
150 void WebContentsTags::ClearTag(content::WebContents* web_contents) { | 151 void WebContentsTags::ClearTag(content::WebContents* web_contents) { |
151 #if defined(ENABLE_TASK_MANAGER) | 152 #if defined(ENABLE_TASK_MANAGER) |
152 const WebContentsTag* tag = WebContentsTag::FromWebContents(web_contents); | 153 const WebContentsTag* tag = WebContentsTag::FromWebContents(web_contents); |
153 WebContentsTagsManager::GetInstance()->ClearFromProvider(tag); | 154 WebContentsTagsManager::GetInstance()->ClearFromProvider(tag); |
154 web_contents->RemoveUserData(WebContentsTag::kTagKey); | 155 web_contents->RemoveUserData(WebContentsTag::kTagKey); |
155 #endif // defined(ENABLE_TASK_MANAGER) | 156 #endif // defined(ENABLE_TASK_MANAGER) |
156 } | 157 } |
157 | 158 |
158 } // namespace task_manager | 159 } // namespace task_manager |
159 | 160 |
OLD | NEW |