Chromium Code Reviews| 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 "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 namespace extensions { | |
| 23 SidebarContainer::SidebarContainer(Browser* browser, | |
| 24 content::WebContents* tab, | |
| 25 const GURL& url) | |
| 26 : host_(extensions::ExtensionViewHostFactory::CreateSidebarHost(url, | |
| 27 browser)), | |
| 28 host_observer_(this), | |
| 29 tab_(tab), | |
| 30 navigate_to_default_page_on_expand_(true) { | |
|
Devlin
2015/06/10 17:25:04
The way this is written, it doesn't seem like this
| |
| 31 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | |
| 32 host_contents()); | |
| 33 host_observer_.Add(host_.get()); | |
| 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 | |
| 41 SidebarContainer::~SidebarContainer() { | |
| 42 } | |
| 43 | |
| 44 void SidebarContainer::Show() { | |
| 45 host_->CreateRenderViewSoon(); | |
| 46 } | |
| 47 | |
| 48 void SidebarContainer::Expand() { | |
| 49 if (navigate_to_default_page_on_expand_) | |
| 50 navigate_to_default_page_on_expand_ = false; | |
| 51 | |
| 52 host_contents()->SetInitialFocus(); | |
| 53 } | |
| 54 | |
| 55 void SidebarContainer::Navigate() { | |
| 56 navigate_to_default_page_on_expand_ = false; | |
| 57 | |
| 58 host_->LoadInitialURL(); | |
| 59 } | |
| 60 | |
| 61 void SidebarContainer::Observe(int type, | |
| 62 const content::NotificationSource& source, | |
| 63 const content::NotificationDetails& details) { | |
| 64 if (type != extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) { | |
| 65 NOTREACHED() << L"Received unexpected notification"; | |
| 66 return; | |
| 67 } | |
| 68 | |
| 69 // If we aren't the host of the popup, then disregard the notification. | |
| 70 if (content::Details<extensions::ExtensionHost>(host_.get()) == details) | |
| 71 extensions::SidebarManager::GetFromContext(host_->browser_context()) | |
| 72 ->HideSidebar(tab_); | |
| 73 } | |
| 74 | |
| 75 } // namespace extensions | |
| OLD | NEW |