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

Side by Side Diff: chrome/browser/ui/extensions/hosted_app_browser_controller.cc

Issue 2552903003: Remove unreleased web app frame code from ChromeOS (Closed)
Patch Set: Nits Created 4 years 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
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/hosted_app_browser_controller.h" 5 #include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
6 6
7 #include "base/command_line.h"
8 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ssl/security_state_tab_helper.h" 8 #include "chrome/browser/ssl/security_state_tab_helper.h"
10 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_window.h" 10 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/location_bar/location_bar.h" 11 #include "chrome/browser/ui/location_bar/location_bar.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/browser/web_applications/web_app.h" 13 #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" 14 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
17 #include "components/security_state/core/security_state.h" 15 #include "components/security_state/core/security_state.h"
18 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
19 #include "extensions/browser/extension_registry.h" 17 #include "extensions/browser/extension_registry.h"
20 #include "extensions/common/extension.h" 18 #include "extensions/common/extension.h"
21 #include "url/gurl.h" 19 #include "url/gurl.h"
22 20
23 namespace extensions { 21 namespace extensions {
24 22
25 namespace { 23 namespace {
26 24
27 bool IsSameOriginOrMoreSecure(const GURL& app_url, const GURL& page_url) { 25 bool IsSameOriginOrMoreSecure(const GURL& app_url, const GURL& page_url) {
28 const std::string www("www."); 26 const std::string www("www.");
29 return (app_url.scheme_piece() == page_url.scheme_piece() || 27 return (app_url.scheme_piece() == page_url.scheme_piece() ||
30 page_url.scheme_piece() == url::kHttpsScheme) && 28 page_url.scheme_piece() == url::kHttpsScheme) &&
31 (app_url.host_piece() == page_url.host_piece() || 29 (app_url.host_piece() == page_url.host_piece() ||
32 www + app_url.host() == page_url.host_piece()) && 30 www + app_url.host() == page_url.host_piece()) &&
33 app_url.port() == page_url.port(); 31 app_url.port() == page_url.port();
34 } 32 }
35
36 #if defined(USE_ASH)
37 bool IsWebAppFrameEnabled() {
38 return base::CommandLine::ForCurrentProcess()->HasSwitch(
39 switches::kEnableWebAppFrame);
40 }
41 #endif // USE_ASH
42
43 } // namespace 33 } // namespace
44 34
45 // static 35 // static
46 bool HostedAppBrowserController::IsForHostedApp(Browser* browser) { 36 bool HostedAppBrowserController::IsForHostedApp(Browser* browser) {
47 const std::string extension_id = 37 const std::string extension_id =
48 web_app::GetExtensionIdFromApplicationName(browser->app_name()); 38 web_app::GetExtensionIdFromApplicationName(browser->app_name());
49 const Extension* extension = 39 const Extension* extension =
50 ExtensionRegistry::Get(browser->profile())->GetExtensionById( 40 ExtensionRegistry::Get(browser->profile())->GetExtensionById(
51 extension_id, ExtensionRegistry::EVERYTHING); 41 extension_id, ExtensionRegistry::EVERYTHING);
52 return extension && extension->is_hosted_app(); 42 return extension && extension->is_hosted_app();
53 } 43 }
54 44
55 HostedAppBrowserController::HostedAppBrowserController(Browser* browser) 45 HostedAppBrowserController::HostedAppBrowserController(Browser* browser)
56 : browser_(browser), 46 : browser_(browser),
57 extension_id_( 47 extension_id_(
58 web_app::GetExtensionIdFromApplicationName(browser->app_name())) { 48 web_app::GetExtensionIdFromApplicationName(browser->app_name())) {}
59 const Extension* extension =
60 ExtensionRegistry::Get(browser->profile())->GetExtensionById(
61 extension_id_, ExtensionRegistry::EVERYTHING);
62 DCHECK(extension);
63 #if defined(USE_ASH)
64 should_use_web_app_frame_ =
65 extension->from_bookmark() && IsWebAppFrameEnabled();
66 #else
67 should_use_web_app_frame_ = false;
68 #endif
69 }
70 49
71 HostedAppBrowserController::~HostedAppBrowserController() { 50 HostedAppBrowserController::~HostedAppBrowserController() {}
72 }
73
74 bool HostedAppBrowserController::SupportsLocationBar() const {
75 return !should_use_web_app_frame();
76 }
77 51
78 bool HostedAppBrowserController::ShouldShowLocationBar() const { 52 bool HostedAppBrowserController::ShouldShowLocationBar() const {
79 const Extension* extension = 53 const Extension* extension =
80 ExtensionRegistry::Get(browser_->profile())->GetExtensionById( 54 ExtensionRegistry::Get(browser_->profile())->GetExtensionById(
81 extension_id_, ExtensionRegistry::EVERYTHING); 55 extension_id_, ExtensionRegistry::EVERYTHING);
82 56
83 const content::WebContents* web_contents = 57 const content::WebContents* web_contents =
84 browser_->tab_strip_model()->GetActiveWebContents(); 58 browser_->tab_strip_model()->GetActiveWebContents();
85 59
86 // Default to not showing the location bar if either |extension| or 60 // Default to not showing the location bar if either |extension| or
(...skipping 19 matching lines...) Expand all
106 80
107 GURL launch_url = AppLaunchInfo::GetLaunchWebURL(extension); 81 GURL launch_url = AppLaunchInfo::GetLaunchWebURL(extension);
108 return !(IsSameOriginOrMoreSecure(launch_url, 82 return !(IsSameOriginOrMoreSecure(launch_url,
109 web_contents->GetVisibleURL()) && 83 web_contents->GetVisibleURL()) &&
110 IsSameOriginOrMoreSecure(launch_url, 84 IsSameOriginOrMoreSecure(launch_url,
111 web_contents->GetLastCommittedURL())); 85 web_contents->GetLastCommittedURL()));
112 } 86 }
113 87
114 void HostedAppBrowserController::UpdateLocationBarVisibility( 88 void HostedAppBrowserController::UpdateLocationBarVisibility(
115 bool animate) const { 89 bool animate) const {
116 if (!SupportsLocationBar())
117 return;
118
119 browser_->window()->GetLocationBar()->UpdateLocationBarVisibility( 90 browser_->window()->GetLocationBar()->UpdateLocationBarVisibility(
120 ShouldShowLocationBar(), animate); 91 ShouldShowLocationBar(), animate);
121 } 92 }
122 93
123 } // namespace extensions 94 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698