| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/webstore_inline_installer.h" | 5 #include "chrome/browser/extensions/webstore_inline_installer.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 10 #include "content/public/browser/navigation_details.h" | 11 #include "content/public/browser/navigation_details.h" |
| 11 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 12 | 13 |
| 13 using content::WebContents; | 14 using content::WebContents; |
| 14 | 15 |
| 15 namespace extensions { | 16 namespace extensions { |
| 16 | 17 |
| 17 const char kInvalidWebstoreResponseError[] = | 18 const char kInvalidWebstoreResponseError[] = |
| 18 "Invalid Chrome Web Store response."; | 19 "Invalid Chrome Web Store response."; |
| 19 const char kNoVerifiedSitesError[] = | 20 const char kNoVerifiedSitesError[] = |
| 20 "Inline installs can only be initiated for Chrome Web Store items that " | 21 "Inline installs can only be initiated for Chrome Web Store items that " |
| 21 "have one or more verified sites."; | 22 "have one or more verified sites."; |
| 22 const char kNotFromVerifiedSitesError[] = | 23 const char kNotFromVerifiedSitesError[] = |
| 23 "Installs can only be initiated by one of the Chrome Web Store item's " | 24 "Installs can only be initiated by one of the Chrome Web Store item's " |
| 24 "verified sites."; | 25 "verified sites."; |
| 25 const char kInlineInstallSupportedError[] = | 26 const char kInlineInstallSupportedError[] = |
| 26 "Inline installation is not supported for this item. The user will be " | 27 "Inline installation is not supported for this item. The user will be " |
| 27 "redirected to the Chrome Web Store."; | 28 "redirected to the Chrome Web Store."; |
| 28 const char kInitiatedFromPopupError[] = | 29 const char kInitiatedFromPopupError[] = |
| 29 "Inline installs can not be initiated from pop-up windows."; | 30 "Inline installs can not be initiated from pop-up windows."; |
| 31 const char kInitiatedFromFullscreenError[] = |
| 32 "Inline installs can not be initiated from fullscreen."; |
| 30 | 33 |
| 31 WebstoreInlineInstaller::WebstoreInlineInstaller( | 34 WebstoreInlineInstaller::WebstoreInlineInstaller( |
| 32 content::WebContents* web_contents, | 35 content::WebContents* web_contents, |
| 33 content::RenderFrameHost* host, | 36 content::RenderFrameHost* host, |
| 34 const std::string& webstore_item_id, | 37 const std::string& webstore_item_id, |
| 35 const GURL& requestor_url, | 38 const GURL& requestor_url, |
| 36 const Callback& callback) | 39 const Callback& callback) |
| 37 : WebstoreStandaloneInstaller( | 40 : WebstoreStandaloneInstaller( |
| 38 webstore_item_id, | 41 webstore_item_id, |
| 39 Profile::FromBrowserContext(web_contents->GetBrowserContext()), | 42 Profile::FromBrowserContext(web_contents->GetBrowserContext()), |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 134 |
| 132 bool WebstoreInlineInstaller::CheckInlineInstallPermitted( | 135 bool WebstoreInlineInstaller::CheckInlineInstallPermitted( |
| 133 const base::DictionaryValue& webstore_data, | 136 const base::DictionaryValue& webstore_data, |
| 134 std::string* error) const { | 137 std::string* error) const { |
| 135 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | 138 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
| 136 DCHECK(browser); | 139 DCHECK(browser); |
| 137 if (browser->is_type_popup()) { | 140 if (browser->is_type_popup()) { |
| 138 *error = kInitiatedFromPopupError; | 141 *error = kInitiatedFromPopupError; |
| 139 return false; | 142 return false; |
| 140 } | 143 } |
| 144 FullscreenController* controller = |
| 145 browser->exclusive_access_manager()->fullscreen_controller(); |
| 146 if (controller->IsFullscreenForBrowser() || controller->IsTabFullscreen()) { |
| 147 *error = kInitiatedFromFullscreenError; |
| 148 return false; |
| 149 } |
| 141 // The store may not support inline installs for this item, in which case | 150 // The store may not support inline installs for this item, in which case |
| 142 // we open the store-provided redirect URL in a new tab and abort the | 151 // we open the store-provided redirect URL in a new tab and abort the |
| 143 // installation process. | 152 // installation process. |
| 144 bool inline_install_not_supported = false; | 153 bool inline_install_not_supported = false; |
| 145 if (webstore_data.HasKey(kInlineInstallNotSupportedKey) | 154 if (webstore_data.HasKey(kInlineInstallNotSupportedKey) |
| 146 && !webstore_data.GetBoolean(kInlineInstallNotSupportedKey, | 155 && !webstore_data.GetBoolean(kInlineInstallNotSupportedKey, |
| 147 &inline_install_not_supported)) { | 156 &inline_install_not_supported)) { |
| 148 *error = kInvalidWebstoreResponseError; | 157 *error = kInvalidWebstoreResponseError; |
| 149 return false; | 158 return false; |
| 150 } | 159 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 DLOG(WARNING) << "Could not parse " << verified_site_pattern_spec << | 244 DLOG(WARNING) << "Could not parse " << verified_site_pattern_spec << |
| 236 " as URL pattern " << parse_result; | 245 " as URL pattern " << parse_result; |
| 237 return false; | 246 return false; |
| 238 } | 247 } |
| 239 verified_site_pattern.SetScheme("*"); | 248 verified_site_pattern.SetScheme("*"); |
| 240 | 249 |
| 241 return verified_site_pattern.MatchesURL(requestor_url); | 250 return verified_site_pattern.MatchesURL(requestor_url); |
| 242 } | 251 } |
| 243 | 252 |
| 244 } // namespace extensions | 253 } // namespace extensions |
| OLD | NEW |