forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chrome_extension_host_delegate.cc
127 lines (106 loc) · 4.76 KB
/
chrome_extension_host_delegate.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2014 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/extensions/chrome_extension_host_delegate.h"
#include <memory>
#include <string>
#include "base/lazy_instance.h"
#include "chrome/browser/apps/platform_apps/audio_focus_web_contents_observer.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/data_use_measurement/data_use_web_contents_observer.h"
#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
#include "chrome/browser/performance_manager/performance_manager.h"
#include "chrome/browser/performance_manager/performance_manager_tab_helper.h"
#include "chrome/browser/picture_in_picture/picture_in_picture_window_manager.h"
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "components/app_modal/javascript_dialog_manager.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/load_monitoring_extension_host_queue.h"
#include "extensions/browser/serial_extension_host_queue.h"
namespace extensions {
namespace {
// Singleton for GetExtensionHostQueue().
struct QueueWrapper {
QueueWrapper() {
queue.reset(new LoadMonitoringExtensionHostQueue(
std::unique_ptr<ExtensionHostQueue>(new SerialExtensionHostQueue())));
}
std::unique_ptr<ExtensionHostQueue> queue;
};
base::LazyInstance<QueueWrapper>::DestructorAtExit g_queue =
LAZY_INSTANCE_INITIALIZER;
} // namespace
ChromeExtensionHostDelegate::ChromeExtensionHostDelegate() {}
ChromeExtensionHostDelegate::~ChromeExtensionHostDelegate() {}
void ChromeExtensionHostDelegate::OnExtensionHostCreated(
content::WebContents* web_contents) {
ChromeExtensionWebContentsObserver::CreateForWebContents(web_contents);
data_use_measurement::DataUseWebContentsObserver::CreateForWebContents(
web_contents);
PrefsTabHelper::CreateForWebContents(web_contents);
apps::AudioFocusWebContentsObserver::CreateForWebContents(web_contents);
if (performance_manager::PerformanceManager::GetInstance()) {
performance_manager::PerformanceManagerTabHelper::CreateForWebContents(
web_contents);
}
}
void ChromeExtensionHostDelegate::OnRenderViewCreatedForBackgroundPage(
ExtensionHost* host) {
ExtensionService* service =
ExtensionSystem::Get(host->browser_context())->extension_service();
if (service)
service->DidCreateRenderViewForBackgroundPage(host);
}
content::JavaScriptDialogManager*
ChromeExtensionHostDelegate::GetJavaScriptDialogManager() {
return app_modal::JavaScriptDialogManager::GetInstance();
}
void ChromeExtensionHostDelegate::CreateTab(
std::unique_ptr<content::WebContents> web_contents,
const std::string& extension_id,
WindowOpenDisposition disposition,
const gfx::Rect& initial_rect,
bool user_gesture) {
// Verify that the browser is not shutting down. It can be the case if the
// call is propagated through a posted task that was already in the queue when
// shutdown started. See crbug.com/625646
if (g_browser_process->IsShuttingDown())
return;
ExtensionTabUtil::CreateTab(std::move(web_contents), extension_id,
disposition, initial_rect, user_gesture);
}
void ChromeExtensionHostDelegate::ProcessMediaAccessRequest(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
content::MediaResponseCallback callback,
const Extension* extension) {
MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest(
web_contents, request, std::move(callback), extension);
}
bool ChromeExtensionHostDelegate::CheckMediaAccessPermission(
content::RenderFrameHost* render_frame_host,
const GURL& security_origin,
blink::MediaStreamType type,
const Extension* extension) {
return MediaCaptureDevicesDispatcher::GetInstance()
->CheckMediaAccessPermission(render_frame_host, security_origin, type,
extension);
}
ExtensionHostQueue* ChromeExtensionHostDelegate::GetExtensionHostQueue() const {
return g_queue.Get().queue.get();
}
gfx::Size ChromeExtensionHostDelegate::EnterPictureInPicture(
content::WebContents* web_contents,
const viz::SurfaceId& surface_id,
const gfx::Size& natural_size) {
return PictureInPictureWindowManager::GetInstance()->EnterPictureInPicture(
web_contents, surface_id, natural_size);
}
void ChromeExtensionHostDelegate::ExitPictureInPicture() {
PictureInPictureWindowManager::GetInstance()->ExitPictureInPicture();
}
} // namespace extensions