Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: chrome/browser/extensions/sidebar_container.cc

Issue 1168383002: Implement sidebar support for extension action popups Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/sidebar_container.h"
6
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_view_host_factory.h"
10 #include "chrome/browser/extensions/sidebar_manager.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "content/public/browser/notification_details.h"
14 #include "content/public/browser/notification_source.h"
15 #include "content/public/browser/web_contents.h"
16 #include "url/gurl.h"
17
18 namespace extensions {
19 SidebarContainer::SidebarContainer(Browser* browser,
20 content::WebContents* tab,
21 const GURL& url)
22 : host_(extensions::ExtensionViewHostFactory::CreateSidebarHost(url,
23 browser)),
24 tab_(tab),
25 browser_(browser),
26 tab_strip_model_observer_(this) {
27 // Listen for the containing view calling window.close();
28 registrar_.Add(
29 this, extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
30 content::Source<content::BrowserContext>(host_->browser_context()));
31
32 host_->CreateRenderViewSoon();
33 sidebar_contents()->SetInitialFocus();
34
35 tab_strip_model_observer_.Add(browser_->tab_strip_model());
36 }
37
38 SidebarContainer::~SidebarContainer() {
39 tab_strip_model_observer_.Remove(browser_->tab_strip_model());
40 }
41
42 void SidebarContainer::TabClosingAt(TabStripModel* tab_strip_model,
43 content::WebContents* contents,
44 int index) {
45 if (tab_ == contents)
46 extensions::SidebarManager::GetFromContext(host_->browser_context())
47 ->HideSidebar(tab_);
48 }
49
50 void SidebarContainer::Observe(int type,
51 const content::NotificationSource& source,
52 const content::NotificationDetails& details) {
53 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE)
54 << "Received unexpected notification";
55
56 // If we aren't the host of the popup, then disregard the notification.
57 if (content::Details<extensions::ExtensionHost>(host_.get()) == details)
58 extensions::SidebarManager::GetFromContext(host_->browser_context())
59 ->HideSidebar(tab_);
60 }
61
62 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698