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 SidebarContainer::SidebarContainer(Browser* browser, |
| 23 content::WebContents* tab, |
| 24 const GURL& url) |
| 25 : host_(extensions::ExtensionViewHostFactory::CreateSidebarHost(url, |
| 26 browser)), |
| 27 host_observer_(this), |
| 28 tab_(tab), |
| 29 navigate_to_default_page_on_expand_(true) { |
| 30 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( |
| 31 host_contents()); |
| 32 host_observer_.Add(host_.get()); |
| 33 |
| 34 // Listen for the containing view calling window.close(); |
| 35 registrar_.Add( |
| 36 this, extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| 37 content::Source<content::BrowserContext>(host_->browser_context())); |
| 38 } |
| 39 |
| 40 SidebarContainer::~SidebarContainer() { |
| 41 } |
| 42 |
| 43 void SidebarContainer::Show() { |
| 44 host_->CreateRenderViewSoon(); |
| 45 } |
| 46 |
| 47 void SidebarContainer::Expand() { |
| 48 if (navigate_to_default_page_on_expand_) |
| 49 navigate_to_default_page_on_expand_ = false; |
| 50 |
| 51 host_contents()->SetInitialFocus(); |
| 52 } |
| 53 |
| 54 void SidebarContainer::Navigate(const GURL& url) { |
| 55 navigate_to_default_page_on_expand_ = false; |
| 56 |
| 57 host_contents()->GetController().LoadURL( |
| 58 url, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
| 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_, extension_id()); |
| 73 } |
OLD | NEW |