Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/ui/extensions/bookmark_app_browser_controller.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "chrome/browser/profiles/profile.h" | |
| 9 #include "chrome/browser/ui/browser.h" | |
| 10 #include "chrome/browser/ui/browser_window.h" | |
| 11 #include "chrome/browser/ui/host_desktop.h" | |
| 12 #include "chrome/browser/ui/location_bar/location_bar.h" | |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 14 #include "chrome/browser/web_applications/web_app.h" | |
| 15 #include "chrome/common/chrome_switches.h" | |
| 16 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | |
| 17 #include "content/public/browser/web_contents.h" | |
| 18 #include "extensions/browser/extension_registry.h" | |
| 19 #include "extensions/common/extension.h" | |
| 20 #include "url/gurl.h" | |
| 21 | |
| 22 namespace extensions { | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 bool IsSameOriginOrMoreSecure(const GURL& app_url, const GURL& page_url) { | |
| 27 return (app_url.scheme() == page_url.scheme() || | |
| 28 page_url.scheme() == url::kHttpsScheme) && | |
| 29 app_url.host() == page_url.host() && | |
| 30 app_url.port() == page_url.port(); | |
| 31 } | |
| 32 | |
| 33 bool IsWebAppFrameEnabled() { | |
| 34 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 35 switches::kEnableWebAppFrame); | |
| 36 } | |
| 37 | |
| 38 } // namespace | |
| 39 | |
| 40 // static | |
| 41 bool BookmarkAppBrowserController::IsForBookmarkApp(Browser* browser) { | |
| 42 const std::string extension_id = | |
| 43 web_app::GetExtensionIdFromApplicationName(browser->app_name()); | |
| 44 const extensions::Extension* extension = | |
| 45 extensions::ExtensionRegistry::Get(browser->profile())->GetExtensionById( | |
| 46 extension_id, extensions::ExtensionRegistry::EVERYTHING); | |
| 47 return extension && extension->from_bookmark(); | |
| 48 } | |
| 49 | |
| 50 BookmarkAppBrowserController::BookmarkAppBrowserController(Browser* browser) | |
| 51 : browser_(browser), | |
| 52 extension_id_( | |
| 53 web_app::GetExtensionIdFromApplicationName(browser->app_name())), | |
| 54 should_use_web_app_frame_(browser->host_desktop_type() == | |
| 55 chrome::HOST_DESKTOP_TYPE_ASH && | |
| 56 IsWebAppFrameEnabled()) { | |
| 57 } | |
| 58 | |
| 59 BookmarkAppBrowserController::~BookmarkAppBrowserController() { | |
| 60 } | |
| 61 | |
| 62 bool BookmarkAppBrowserController::SupportsLocationBar() { | |
| 63 return !should_use_web_app_frame(); | |
| 64 } | |
| 65 | |
| 66 bool BookmarkAppBrowserController::ShouldShowLocationBar() { | |
| 67 const extensions::Extension* extension = | |
| 68 extensions::ExtensionRegistry::Get(browser_->profile())->GetExtensionById( | |
|
Lei Zhang
2015/03/30 22:17:54
you can omit extensions:: inside the extensions na
benwells
2015/03/31 06:02:59
Done.
| |
| 69 extension_id_, extensions::ExtensionRegistry::EVERYTHING); | |
| 70 | |
| 71 const content::WebContents* web_contents = | |
| 72 browser_->tab_strip_model()->GetActiveWebContents(); | |
| 73 | |
| 74 // Default to not showing the location bar if either |extension| or | |
| 75 // |web_contents| are null. |extension| is null for the dev tools. | |
| 76 if (!extension || !web_contents) | |
| 77 return false; | |
| 78 | |
| 79 if (!extension->from_bookmark()) | |
| 80 return false; | |
| 81 | |
| 82 // Don't show a location bar until a navigation has occurred. | |
| 83 if (web_contents->GetLastCommittedURL().is_empty()) | |
| 84 return false; | |
| 85 | |
| 86 GURL launch_url = AppLaunchInfo::GetLaunchWebURL(extension); | |
| 87 return !(IsSameOriginOrMoreSecure(launch_url, | |
| 88 web_contents->GetVisibleURL()) && | |
| 89 IsSameOriginOrMoreSecure(launch_url, | |
| 90 web_contents->GetLastCommittedURL())); | |
| 91 } | |
| 92 | |
| 93 void BookmarkAppBrowserController::UpdateLocationBarState(bool animate) { | |
| 94 if (!SupportsLocationBar()) | |
| 95 return; | |
| 96 | |
| 97 browser_->window()->GetLocationBar()->UpdateLocationBarState( | |
| 98 ShouldShowLocationBar(), animate); | |
| 99 } | |
| 100 | |
| 101 } // namespace extensions | |
| OLD | NEW |