Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/extensions/bookmark_app_browser_controller.h" | 5 #include "chrome/browser/ui/extensions/hosted_app_browser_controller.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ssl/connection_security_helper.h" | 9 #include "chrome/browser/ssl/connection_security_helper.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "chrome/browser/ui/host_desktop.h" | 12 #include "chrome/browser/ui/host_desktop.h" |
| 13 #include "chrome/browser/ui/location_bar/location_bar.h" | 13 #include "chrome/browser/ui/location_bar/location_bar.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/browser/web_applications/web_app.h" | 15 #include "chrome/browser/web_applications/web_app.h" |
| 16 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
| 20 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 21 #include "net/base/net_util.h" | |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| 23 namespace extensions { | 24 namespace extensions { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 bool IsSameOriginOrMoreSecure(const GURL& app_url, const GURL& page_url) { | 28 bool IsSameOriginOrMoreSecure(const GURL& app_url, const GURL& page_url) { |
| 29 const std::string www("www."); | |
| 28 return (app_url.scheme() == page_url.scheme() || | 30 return (app_url.scheme() == page_url.scheme() || |
| 29 page_url.scheme() == url::kHttpsScheme) && | 31 page_url.scheme() == url::kHttpsScheme) && |
| 30 app_url.host() == page_url.host() && | 32 (app_url.host() == page_url.host() || |
| 33 www + app_url.host() == page_url.host()) && | |
|
felt
2015/06/04 19:21:34
why single out www as the one allowable subdomain?
benwells
2015/06/04 23:54:42
It shoudn't be all subdomains as benfredwells.gith
felt
2015/06/04 23:58:37
ok, special casing www sounds reasonable to me. (a
| |
| 31 app_url.port() == page_url.port(); | 34 app_url.port() == page_url.port(); |
| 32 } | 35 } |
| 33 | 36 |
| 34 bool IsWebAppFrameEnabled() { | 37 bool IsWebAppFrameEnabled() { |
| 35 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 38 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 36 switches::kEnableWebAppFrame); | 39 switches::kEnableWebAppFrame); |
| 37 } | 40 } |
| 38 | 41 |
| 39 } // namespace | 42 } // namespace |
| 40 | 43 |
| 41 // static | 44 // static |
| 42 bool BookmarkAppBrowserController::IsForBookmarkApp(Browser* browser) { | 45 bool HostedAppBrowserController::IsForHostedApp(Browser* browser) { |
| 43 const std::string extension_id = | 46 const std::string extension_id = |
| 44 web_app::GetExtensionIdFromApplicationName(browser->app_name()); | 47 web_app::GetExtensionIdFromApplicationName(browser->app_name()); |
| 45 const Extension* extension = | 48 const Extension* extension = |
| 46 ExtensionRegistry::Get(browser->profile())->GetExtensionById( | 49 ExtensionRegistry::Get(browser->profile())->GetExtensionById( |
| 47 extension_id, ExtensionRegistry::EVERYTHING); | 50 extension_id, ExtensionRegistry::EVERYTHING); |
| 48 return extension && extension->from_bookmark(); | 51 return extension && extension->is_hosted_app(); |
| 49 } | 52 } |
| 50 | 53 |
| 51 BookmarkAppBrowserController::BookmarkAppBrowserController(Browser* browser) | 54 HostedAppBrowserController::HostedAppBrowserController(Browser* browser) |
| 52 : browser_(browser), | 55 : browser_(browser), |
| 53 extension_id_( | 56 extension_id_( |
| 54 web_app::GetExtensionIdFromApplicationName(browser->app_name())), | 57 web_app::GetExtensionIdFromApplicationName(browser->app_name())), |
| 55 should_use_web_app_frame_(browser->host_desktop_type() == | 58 should_use_web_app_frame_(false) { |
| 56 chrome::HOST_DESKTOP_TYPE_ASH && | 59 const Extension* extension = |
| 57 IsWebAppFrameEnabled()) { | 60 ExtensionRegistry::Get(browser->profile())->GetExtensionById( |
| 61 extension_id_, ExtensionRegistry::EVERYTHING); | |
| 62 should_use_web_app_frame_ = | |
| 63 extension && extension->from_bookmark() && | |
|
felt
2015/06/04 19:21:33
should this be a DCHECK(extension)? can extension
benwells
2015/06/05 01:20:44
Done.
| |
| 64 browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH && | |
| 65 IsWebAppFrameEnabled(); | |
| 58 } | 66 } |
| 59 | 67 |
| 60 BookmarkAppBrowserController::~BookmarkAppBrowserController() { | 68 HostedAppBrowserController::~HostedAppBrowserController() { |
| 61 } | 69 } |
| 62 | 70 |
| 63 bool BookmarkAppBrowserController::SupportsLocationBar() { | 71 bool HostedAppBrowserController::SupportsLocationBar() const { |
| 64 return !should_use_web_app_frame(); | 72 return !should_use_web_app_frame(); |
| 65 } | 73 } |
| 66 | 74 |
| 67 bool BookmarkAppBrowserController::ShouldShowLocationBar() { | 75 bool HostedAppBrowserController::ShouldShowLocationBar() const { |
| 68 const Extension* extension = | 76 const Extension* extension = |
| 69 ExtensionRegistry::Get(browser_->profile())->GetExtensionById( | 77 ExtensionRegistry::Get(browser_->profile())->GetExtensionById( |
| 70 extension_id_, ExtensionRegistry::EVERYTHING); | 78 extension_id_, ExtensionRegistry::EVERYTHING); |
| 71 | 79 |
| 72 const content::WebContents* web_contents = | 80 const content::WebContents* web_contents = |
| 73 browser_->tab_strip_model()->GetActiveWebContents(); | 81 browser_->tab_strip_model()->GetActiveWebContents(); |
| 74 | 82 |
| 75 // Default to not showing the location bar if either |extension| or | 83 // Default to not showing the location bar if either |extension| or |
| 76 // |web_contents| are null. |extension| is null for the dev tools. | 84 // |web_contents| are null. |extension| is null for the dev tools. |
| 77 if (!extension || !web_contents) | 85 if (!extension || !web_contents) |
| 78 return false; | 86 return false; |
| 79 | 87 |
| 80 if (!extension->from_bookmark()) | 88 if (!extension->is_hosted_app()) |
| 81 return false; | 89 return false; |
| 82 | 90 |
| 83 // Don't show a location bar until a navigation has occurred. | 91 // Don't show a location bar until a navigation has occurred. |
| 84 if (web_contents->GetLastCommittedURL().is_empty()) | 92 if (web_contents->GetLastCommittedURL().is_empty()) |
| 85 return false; | 93 return false; |
| 86 | 94 |
| 87 ConnectionSecurityHelper::SecurityLevel security_level = | 95 ConnectionSecurityHelper::SecurityLevel security_level = |
| 88 ConnectionSecurityHelper::GetSecurityLevelForWebContents(web_contents); | 96 ConnectionSecurityHelper::GetSecurityLevelForWebContents(web_contents); |
| 89 if (security_level == ConnectionSecurityHelper::SECURITY_ERROR) | 97 if (security_level == ConnectionSecurityHelper::SECURITY_ERROR) |
| 90 return true; | 98 return true; |
| 91 | 99 |
| 92 GURL launch_url = AppLaunchInfo::GetLaunchWebURL(extension); | 100 GURL launch_url = AppLaunchInfo::GetLaunchWebURL(extension); |
| 93 return !(IsSameOriginOrMoreSecure(launch_url, | 101 return !(IsSameOriginOrMoreSecure(launch_url, |
| 94 web_contents->GetVisibleURL()) && | 102 web_contents->GetVisibleURL()) && |
| 95 IsSameOriginOrMoreSecure(launch_url, | 103 IsSameOriginOrMoreSecure(launch_url, |
| 96 web_contents->GetLastCommittedURL())); | 104 web_contents->GetLastCommittedURL())); |
| 97 } | 105 } |
| 98 | 106 |
| 99 void BookmarkAppBrowserController::UpdateLocationBarVisibility(bool animate) { | 107 void HostedAppBrowserController::UpdateLocationBarVisibility( |
| 108 bool animate) const { | |
| 100 if (!SupportsLocationBar()) | 109 if (!SupportsLocationBar()) |
| 101 return; | 110 return; |
| 102 | 111 |
| 103 browser_->window()->GetLocationBar()->UpdateLocationBarVisibility( | 112 browser_->window()->GetLocationBar()->UpdateLocationBarVisibility( |
| 104 ShouldShowLocationBar(), animate); | 113 ShouldShowLocationBar(), animate); |
| 105 } | 114 } |
| 106 | 115 |
| 107 } // namespace extensions | 116 } // namespace extensions |
| OLD | NEW |