mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Update to Chromium revision 9ef2aa86 (#550428)
This commit is contained in:
@@ -28,101 +28,6 @@ using content::BrowserThread;
|
||||
using content::SpeechRecognitionManager;
|
||||
using content::WebContents;
|
||||
|
||||
// Simple utility to get notified when a WebContents is closed or crashes.
|
||||
// Both the callback site and the callback thread are passed by the caller in
|
||||
// the constructor. There is no restriction on the constructor, however this
|
||||
// class must be destroyed on the UI thread, due to the NotificationRegistrar
|
||||
// dependency.
|
||||
class CefSpeechRecognitionManagerDelegate::WebContentsWatcher
|
||||
: public base::RefCountedThreadSafe<WebContentsWatcher>,
|
||||
public content::NotificationObserver {
|
||||
public:
|
||||
typedef base::Callback<void(int render_process_id, int render_view_id)>
|
||||
WebContentsClosedCallback;
|
||||
|
||||
WebContentsWatcher(WebContentsClosedCallback web_contents_closed_callback,
|
||||
BrowserThread::ID callback_thread)
|
||||
: web_contents_closed_callback_(web_contents_closed_callback),
|
||||
callback_thread_(callback_thread) {}
|
||||
|
||||
// Starts monitoring the WebContents corresponding to the given
|
||||
// |render_process_id|, |render_view_id| pair, invoking
|
||||
// |web_contents_closed_callback_| if closed/unloaded.
|
||||
void Watch(int render_process_id, int render_view_id) {
|
||||
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
|
||||
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
||||
base::Bind(&WebContentsWatcher::Watch, this,
|
||||
render_process_id, render_view_id));
|
||||
return;
|
||||
}
|
||||
|
||||
WebContents* web_contents = NULL;
|
||||
content::RenderViewHost* render_view_host =
|
||||
content::RenderViewHost::FromID(render_process_id, render_view_id);
|
||||
if (render_view_host)
|
||||
web_contents = WebContents::FromRenderViewHost(render_view_host);
|
||||
DCHECK(web_contents);
|
||||
|
||||
// Avoid multiple registrations on |registrar_| for the same |web_contents|.
|
||||
if (registered_web_contents_.find(web_contents) !=
|
||||
registered_web_contents_.end()) {
|
||||
return;
|
||||
}
|
||||
registered_web_contents_.insert(web_contents);
|
||||
|
||||
// Lazy initialize the registrar.
|
||||
if (!registrar_.get())
|
||||
registrar_.reset(new content::NotificationRegistrar());
|
||||
|
||||
registrar_->Add(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
|
||||
content::Source<WebContents>(web_contents));
|
||||
}
|
||||
|
||||
// content::NotificationObserver implementation.
|
||||
void Observe(int type,
|
||||
const content::NotificationSource& source,
|
||||
const content::NotificationDetails& details) override {
|
||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||
DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, type);
|
||||
|
||||
WebContents* web_contents = content::Source<WebContents>(source).ptr();
|
||||
int render_process_id =
|
||||
web_contents->GetRenderViewHost()->GetProcess()->GetID();
|
||||
int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
|
||||
|
||||
registrar_->Remove(this, content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
|
||||
content::Source<WebContents>(web_contents));
|
||||
registered_web_contents_.erase(web_contents);
|
||||
|
||||
BrowserThread::PostTask(callback_thread_, FROM_HERE,
|
||||
base::Bind(web_contents_closed_callback_,
|
||||
render_process_id, render_view_id));
|
||||
}
|
||||
|
||||
private:
|
||||
friend class base::RefCountedThreadSafe<WebContentsWatcher>;
|
||||
|
||||
~WebContentsWatcher() override {
|
||||
// Must be destroyed on the UI thread due to |registrar_| non thread-safety.
|
||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
||||
}
|
||||
|
||||
// Lazy-initialized and used on the UI thread to handle web contents
|
||||
// notifications (tab closing).
|
||||
std::unique_ptr<content::NotificationRegistrar> registrar_;
|
||||
|
||||
// Keeps track of which WebContent(s) have been registered, in order to avoid
|
||||
// double registrations on |registrar_|
|
||||
std::set<content::WebContents*> registered_web_contents_;
|
||||
|
||||
// Callback used to notify, on the thread specified by |callback_thread_| the
|
||||
// closure of a registered tab.
|
||||
WebContentsClosedCallback web_contents_closed_callback_;
|
||||
content::BrowserThread::ID callback_thread_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(WebContentsWatcher);
|
||||
};
|
||||
|
||||
CefSpeechRecognitionManagerDelegate ::CefSpeechRecognitionManagerDelegate() {
|
||||
const base::CommandLine* command_line =
|
||||
base::CommandLine::ForCurrentProcess();
|
||||
@@ -132,37 +37,7 @@ CefSpeechRecognitionManagerDelegate ::CefSpeechRecognitionManagerDelegate() {
|
||||
|
||||
CefSpeechRecognitionManagerDelegate ::~CefSpeechRecognitionManagerDelegate() {}
|
||||
|
||||
void CefSpeechRecognitionManagerDelegate::WebContentsClosedCallback(
|
||||
int render_process_id,
|
||||
int render_view_id) {
|
||||
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
||||
|
||||
SpeechRecognitionManager* manager = SpeechRecognitionManager::GetInstance();
|
||||
// |manager| becomes NULL if a browser shutdown happens between the post of
|
||||
// this task (from the UI thread) and this call (on the IO thread). In this
|
||||
// case we just return.
|
||||
if (!manager)
|
||||
return;
|
||||
|
||||
manager->AbortAllSessionsForRenderView(render_process_id, render_view_id);
|
||||
}
|
||||
|
||||
void CefSpeechRecognitionManagerDelegate::OnRecognitionStart(int session_id) {
|
||||
const content::SpeechRecognitionSessionContext& context =
|
||||
SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id);
|
||||
|
||||
// Register callback to auto abort session on tab closure.
|
||||
// |web_contents_watcher_| is lazyly istantiated on the first call.
|
||||
if (!web_contents_watcher_.get()) {
|
||||
web_contents_watcher_ = new WebContentsWatcher(
|
||||
base::Bind(
|
||||
&CefSpeechRecognitionManagerDelegate::WebContentsClosedCallback,
|
||||
base::Unretained(this)),
|
||||
BrowserThread::IO);
|
||||
}
|
||||
web_contents_watcher_->Watch(context.render_process_id,
|
||||
context.render_view_id);
|
||||
}
|
||||
void CefSpeechRecognitionManagerDelegate::OnRecognitionStart(int session_id) {}
|
||||
|
||||
void CefSpeechRecognitionManagerDelegate::OnAudioStart(int session_id) {}
|
||||
|
||||
|
Reference in New Issue
Block a user