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

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

Issue 1152613003: Implement sidebar support for extension action popups (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 (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/sidebar/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/profiles/profile.h"
13 #include "chrome/browser/sidebar/sidebar_manager.h"
14 #include "components/app_modal/javascript_dialog_manager.h"
15 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_source.h"
17 #include "content/public/browser/web_contents.h"
18 #include "extensions/common/extension.h"
19 #include "extensions/common/extension_resource.h"
20 #include "url/gurl.h"
21
22 SidebarContainer::SidebarContainer(Browser* browser,
23 content::WebContents* tab,
24 const GURL& url,
25 Delegate* delegate)
26 : host_(extensions::ExtensionViewHostFactory::CreateSidebarHost(url,
27 browser)),
28 host_observer_(this),
29 tab_(tab),
30 delegate_(delegate),
31 navigate_to_default_page_on_expand_(true) {
32 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
33 host_contents());
34 host_observer_.Add(host_.get());
35
36 // Listen for the containing view calling window.close();
37 registrar_.Add(
38 this, extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
39 content::Source<content::BrowserContext>(host_->browser_context()));
40 }
41
42 SidebarContainer::~SidebarContainer() {
43 }
44
45 void SidebarContainer::SidebarClosing() {
46 delegate_->UpdateSidebar(this);
47 }
48
49 void SidebarContainer::Show() {
50 host_->CreateRenderViewSoon();
51 delegate_->UpdateSidebar(this);
52 }
53
54 void SidebarContainer::Expand() {
55 if (navigate_to_default_page_on_expand_)
56 navigate_to_default_page_on_expand_ = false;
57
58 delegate_->UpdateSidebar(this);
59 host_contents()->SetInitialFocus();
60 }
61
62 void SidebarContainer::Navigate(const GURL& url) {
63 navigate_to_default_page_on_expand_ = false;
64
65 host_contents()->GetController().LoadURL(
66 url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
67 }
68
69 void SidebarContainer::Collapse() {
70 delegate_->UpdateSidebar(this);
71 }
72
73 void SidebarContainer::Observe(int type,
74 const content::NotificationSource& source,
75 const content::NotificationDetails& details) {
76 if (type != extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) {
77 NOTREACHED() << L"Received unexpected notification";
78 return;
79 }
80
81 // If we aren't the host of the popup, then disregard the notification.
82 if (content::Details<extensions::ExtensionHost>(host_.get()) == details)
83 SidebarManager::GetInstance()->HideSidebar(tab_, extension_id());
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698