| 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/extension_install_prompt.h" | 5 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/extensions/bundle_installer.h" | 16 #include "chrome/browser/extensions/bundle_installer.h" |
| 17 #include "chrome/browser/extensions/extension_install_dialog.h" | 17 #include "chrome/browser/extensions/extension_install_dialog.h" |
| 18 #include "chrome/browser/extensions/extension_install_ui.h" | 18 #include "chrome/browser/extensions/extension_install_ui.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/signin/token_service.h" | 20 #include "chrome/browser/signin/token_service.h" |
| 21 #include "chrome/browser/signin/token_service_factory.h" | 21 #include "chrome/browser/signin/token_service_factory.h" |
| 22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_navigator.h" | 23 #include "chrome/browser/ui/browser_window.h" |
| 24 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
| 27 #include "chrome/common/extensions/extension_icon_set.h" | 27 #include "chrome/common/extensions/extension_icon_set.h" |
| 28 #include "chrome/common/extensions/extension_manifest_constants.h" | 28 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 29 #include "chrome/common/extensions/extension_resource.h" | 29 #include "chrome/common/extensions/extension_resource.h" |
| 30 #include "chrome/common/extensions/extension_switch_utils.h" | 30 #include "chrome/common/extensions/extension_switch_utils.h" |
| 31 #include "chrome/common/extensions/url_pattern.h" | 31 #include "chrome/common/extensions/url_pattern.h" |
| 32 #include "content/public/browser/page_navigator.h" |
| 32 #include "grit/chromium_strings.h" | 33 #include "grit/chromium_strings.h" |
| 33 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
| 34 #include "grit/theme_resources_standard.h" | 35 #include "grit/theme_resources_standard.h" |
| 35 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 36 #include "ui/base/resource/resource_bundle.h" | 37 #include "ui/base/resource/resource_bundle.h" |
| 37 #include "ui/gfx/image/image.h" | 38 #include "ui/gfx/image/image.h" |
| 38 | 39 |
| 39 #if defined(USE_ASH) | |
| 40 #include "ash/shell.h" | |
| 41 #endif | |
| 42 | |
| 43 using extensions::BundleInstaller; | 40 using extensions::BundleInstaller; |
| 44 using extensions::Extension; | 41 using extensions::Extension; |
| 45 using extensions::PermissionSet; | 42 using extensions::PermissionSet; |
| 46 | 43 |
| 47 static const int kTitleIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { | 44 static const int kTitleIds[ExtensionInstallPrompt::NUM_PROMPT_TYPES] = { |
| 48 0, // The regular install prompt depends on what's being installed. | 45 0, // The regular install prompt depends on what's being installed. |
| 49 IDS_EXTENSION_INLINE_INSTALL_PROMPT_TITLE, | 46 IDS_EXTENSION_INLINE_INSTALL_PROMPT_TITLE, |
| 50 IDS_EXTENSION_INSTALL_PROMPT_TITLE, | 47 IDS_EXTENSION_INSTALL_PROMPT_TITLE, |
| 51 IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE, | 48 IDS_EXTENSION_RE_ENABLE_PROMPT_TITLE, |
| 52 IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE | 49 IDS_EXTENSION_PERMISSIONS_PROMPT_TITLE |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 246 |
| 250 return Extension::Create( | 247 return Extension::Create( |
| 251 FilePath(), | 248 FilePath(), |
| 252 Extension::INTERNAL, | 249 Extension::INTERNAL, |
| 253 localized_manifest.get() ? *localized_manifest.get() : *manifest, | 250 localized_manifest.get() ? *localized_manifest.get() : *manifest, |
| 254 Extension::NO_FLAGS, | 251 Extension::NO_FLAGS, |
| 255 id, | 252 id, |
| 256 error); | 253 error); |
| 257 } | 254 } |
| 258 | 255 |
| 259 ExtensionInstallPrompt::ExtensionInstallPrompt(Browser* browser) | 256 ExtensionInstallPrompt::ExtensionInstallPrompt( |
| 257 gfx::NativeWindow parent, |
| 258 content::PageNavigator* navigator, |
| 259 Profile* profile) |
| 260 : record_oauth2_grant_(ShouldAutomaticallyApproveScopes()), | 260 : record_oauth2_grant_(ShouldAutomaticallyApproveScopes()), |
| 261 browser_(browser), | 261 parent_(parent), |
| 262 navigator_(navigator), |
| 262 ui_loop_(MessageLoop::current()), | 263 ui_loop_(MessageLoop::current()), |
| 263 extension_(NULL), | 264 extension_(NULL), |
| 264 install_ui_(ExtensionInstallUI::Create(browser)), | 265 install_ui_(ExtensionInstallUI::Create(profile)), |
| 265 delegate_(NULL), | 266 delegate_(NULL), |
| 266 prompt_(UNSET_PROMPT_TYPE), | 267 prompt_(UNSET_PROMPT_TYPE), |
| 267 prompt_type_(UNSET_PROMPT_TYPE), | 268 prompt_type_(UNSET_PROMPT_TYPE), |
| 268 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { | 269 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { |
| 269 } | 270 } |
| 270 | 271 |
| 271 ExtensionInstallPrompt::~ExtensionInstallPrompt() { | 272 ExtensionInstallPrompt::~ExtensionInstallPrompt() { |
| 272 } | 273 } |
| 273 | 274 |
| 274 void ExtensionInstallPrompt::ConfirmBundleInstall( | 275 void ExtensionInstallPrompt::ConfirmBundleInstall( |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 const Extension::OAuth2Info& oauth2_info = extension_->oauth2_info(); | 408 const Extension::OAuth2Info& oauth2_info = extension_->oauth2_info(); |
| 408 if (ShouldAutomaticallyApproveScopes() || | 409 if (ShouldAutomaticallyApproveScopes() || |
| 409 oauth2_info.client_id.empty() || | 410 oauth2_info.client_id.empty() || |
| 410 permissions_->scopes().empty() || | 411 permissions_->scopes().empty() || |
| 411 prompt_type_ == BUNDLE_INSTALL_PROMPT || | 412 prompt_type_ == BUNDLE_INSTALL_PROMPT || |
| 412 prompt_type_ == INLINE_INSTALL_PROMPT) { | 413 prompt_type_ == INLINE_INSTALL_PROMPT) { |
| 413 ShowConfirmation(); | 414 ShowConfirmation(); |
| 414 return; | 415 return; |
| 415 } | 416 } |
| 416 | 417 |
| 417 Profile* profile = install_ui_->browser()->profile(); | 418 Profile* profile = install_ui_->profile(); |
| 418 TokenService* token_service = TokenServiceFactory::GetForProfile(profile); | 419 TokenService* token_service = TokenServiceFactory::GetForProfile(profile); |
| 419 std::vector<std::string> scopes; | 420 std::vector<std::string> scopes; |
| 420 scopes.assign(permissions_->scopes().begin(), permissions_->scopes().end()); | 421 scopes.assign(permissions_->scopes().begin(), permissions_->scopes().end()); |
| 421 | 422 |
| 422 token_flow_.reset(new OAuth2MintTokenFlow( | 423 token_flow_.reset(new OAuth2MintTokenFlow( |
| 423 profile->GetRequestContext(), | 424 profile->GetRequestContext(), |
| 424 this, | 425 this, |
| 425 OAuth2MintTokenFlow::Parameters( | 426 OAuth2MintTokenFlow::Parameters( |
| 426 token_service->GetOAuth2LoginRefreshToken(), | 427 token_service->GetOAuth2LoginRefreshToken(), |
| 427 extension_->id(), | 428 extension_->id(), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 447 prompt_.set_type(prompt_type_); | 448 prompt_.set_type(prompt_type_); |
| 448 prompt_.SetPermissions(permissions_->GetWarningMessages()); | 449 prompt_.SetPermissions(permissions_->GetWarningMessages()); |
| 449 | 450 |
| 450 switch (prompt_type_) { | 451 switch (prompt_type_) { |
| 451 case PERMISSIONS_PROMPT: | 452 case PERMISSIONS_PROMPT: |
| 452 case RE_ENABLE_PROMPT: | 453 case RE_ENABLE_PROMPT: |
| 453 case INLINE_INSTALL_PROMPT: | 454 case INLINE_INSTALL_PROMPT: |
| 454 case INSTALL_PROMPT: { | 455 case INSTALL_PROMPT: { |
| 455 prompt_.set_extension(extension_); | 456 prompt_.set_extension(extension_); |
| 456 prompt_.set_icon(gfx::Image(icon_)); | 457 prompt_.set_icon(gfx::Image(icon_)); |
| 457 ShowExtensionInstallDialog(browser_, delegate_, prompt_); | 458 ShowExtensionInstallDialog(parent_, navigator_, delegate_, prompt_); |
| 458 break; | 459 break; |
| 459 } | 460 } |
| 460 case BUNDLE_INSTALL_PROMPT: { | 461 case BUNDLE_INSTALL_PROMPT: { |
| 461 prompt_.set_bundle(bundle_); | 462 prompt_.set_bundle(bundle_); |
| 462 ShowExtensionInstallDialog(browser_, delegate_, prompt_); | 463 ShowExtensionInstallDialog(parent_, navigator_, delegate_, prompt_); |
| 463 break; | 464 break; |
| 464 } | 465 } |
| 465 default: | 466 default: |
| 466 NOTREACHED() << "Unknown message"; | 467 NOTREACHED() << "Unknown message"; |
| 467 break; | 468 break; |
| 468 } | 469 } |
| 469 } | 470 } |
| 470 | 471 |
| 471 // static | 472 // static |
| 472 bool ExtensionInstallPrompt::ShouldAutomaticallyApproveScopes() { | 473 bool ExtensionInstallPrompt::ShouldAutomaticallyApproveScopes() { |
| 473 return !CommandLine::ForCurrentProcess()->HasSwitch( | 474 return !CommandLine::ForCurrentProcess()->HasSwitch( |
| 474 switches::kDemandUserScopeApproval); | 475 switches::kDemandUserScopeApproval); |
| 475 } | 476 } |
| 477 |
| 478 namespace chrome { |
| 479 |
| 480 ExtensionInstallPrompt* CreateExtensionInstallPromptWithBrowser( |
| 481 Browser* browser) { |
| 482 // |browser| can be NULL in unit tests. |
| 483 if (!browser) |
| 484 return new ExtensionInstallPrompt(NULL, NULL, NULL); |
| 485 gfx::NativeWindow parent = |
| 486 browser->window() ? browser->window()->GetNativeWindow() : NULL; |
| 487 return new ExtensionInstallPrompt(parent, browser, browser->profile()); |
| 488 } |
| 489 |
| 490 } // namespace chrome |
| OLD | NEW |