OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/extensions/sidebar_container.h" | |
6 | |
7 #include "base/strings/utf_string_conversions.h" | |
8 #include "chrome/browser/chrome_notification_types.h" | |
9 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | |
10 #include "chrome/browser/extensions/extension_service.h" | |
11 #include "chrome/browser/extensions/extension_view_host_factory.h" | |
12 #include "chrome/browser/extensions/sidebar_manager.h" | |
13 #include "chrome/browser/profiles/profile.h" | |
14 #include "chrome/browser/ui/browser.h" | |
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
16 #include "components/app_modal/javascript_dialog_manager.h" | |
17 #include "content/public/browser/notification_details.h" | |
18 #include "content/public/browser/notification_source.h" | |
19 #include "content/public/browser/web_contents.h" | |
20 #include "extensions/common/extension.h" | |
21 #include "extensions/common/extension_resource.h" | |
22 #include "url/gurl.h" | |
23 | |
24 namespace extensions { | |
25 SidebarContainer::SidebarContainer(Browser* browser, | |
26 content::WebContents* tab, | |
27 const GURL& url) | |
28 : host_(extensions::ExtensionViewHostFactory::CreateSidebarHost(url, | |
29 browser)), | |
30 tab_(tab), | |
31 browser_(browser) { | |
32 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | |
Devlin
2015/06/19 19:56:09
Isn't this done as part of the ExtensionHost initi
ltilve
2015/06/28 22:44:19
Done.
| |
33 host_contents()); | |
34 | |
35 // Listen for the containing view calling window.close(); | |
36 registrar_.Add( | |
37 this, extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | |
38 content::Source<content::BrowserContext>(host_->browser_context())); | |
39 | |
40 host_->CreateRenderViewSoon(); | |
41 host_contents()->SetInitialFocus(); | |
42 browser_->tab_strip_model()->AddObserver(this); | |
Devlin
2015/06/19 19:56:09
Use a ScopedObserver.
ltilve
2015/06/28 22:44:19
Done.
| |
43 } | |
44 | |
45 SidebarContainer::~SidebarContainer() { | |
46 browser_->tab_strip_model()->RemoveObserver(this); | |
47 } | |
48 | |
49 void SidebarContainer::TabClosingAt(TabStripModel* tab_strip_model, | |
50 content::WebContents* contents, | |
51 int index) { | |
52 if (tab_ == contents) | |
53 extensions::SidebarManager::GetFromContext(host_->browser_context()) | |
54 ->HideSidebar(tab_); | |
55 } | |
56 | |
57 void SidebarContainer::Observe(int type, | |
58 const content::NotificationSource& source, | |
59 const content::NotificationDetails& details) { | |
60 if (type != extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) { | |
Devlin
2015/06/19 19:56:09
instead DCHECK_EQ()
ltilve
2015/06/28 22:44:19
Done.
| |
61 NOTREACHED() << L"Received unexpected notification"; | |
62 return; | |
63 } | |
64 | |
65 // If we aren't the host of the popup, then disregard the notification. | |
66 if (content::Details<extensions::ExtensionHost>(host_.get()) == details) | |
67 extensions::SidebarManager::GetFromContext(host_->browser_context()) | |
68 ->HideSidebar(tab_); | |
69 } | |
70 | |
71 } // namespace extensions | |
OLD | NEW |