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

Side by Side Diff: chrome/browser/extensions/extension_install_prompt.cc

Issue 10699057: Move application creation and extension install prompt showing off Browser and onto ExtensionTabHel… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months 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 | Annotate | Revision Log
OLDNEW
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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 251
255 return Extension::Create( 252 return Extension::Create(
256 FilePath(), 253 FilePath(),
257 Extension::INTERNAL, 254 Extension::INTERNAL,
258 localized_manifest.get() ? *localized_manifest.get() : *manifest, 255 localized_manifest.get() ? *localized_manifest.get() : *manifest,
259 Extension::NO_FLAGS, 256 Extension::NO_FLAGS,
260 id, 257 id,
261 error); 258 error);
262 } 259 }
263 260
264 ExtensionInstallPrompt::ExtensionInstallPrompt(Browser* browser) 261 ExtensionInstallPrompt::ExtensionInstallPrompt(
262 gfx::NativeWindow parent,
263 content::PageNavigator* navigator,
264 Profile* profile)
265 : record_oauth2_grant_(ShouldAutomaticallyApproveScopes()), 265 : record_oauth2_grant_(ShouldAutomaticallyApproveScopes()),
266 browser_(browser), 266 parent_(parent),
267 navigator_(navigator),
267 ui_loop_(MessageLoop::current()), 268 ui_loop_(MessageLoop::current()),
268 extension_(NULL), 269 extension_(NULL),
269 install_ui_(ExtensionInstallUI::Create(browser)), 270 install_ui_(ExtensionInstallUI::Create(profile)),
270 delegate_(NULL), 271 delegate_(NULL),
271 prompt_(UNSET_PROMPT_TYPE), 272 prompt_(UNSET_PROMPT_TYPE),
272 prompt_type_(UNSET_PROMPT_TYPE), 273 prompt_type_(UNSET_PROMPT_TYPE),
273 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { 274 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) {
274 } 275 }
275 276
276 ExtensionInstallPrompt::~ExtensionInstallPrompt() { 277 ExtensionInstallPrompt::~ExtensionInstallPrompt() {
277 } 278 }
278 279
279 void ExtensionInstallPrompt::ConfirmBundleInstall( 280 void ExtensionInstallPrompt::ConfirmBundleInstall(
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 if (ShouldAutomaticallyApproveScopes() || 429 if (ShouldAutomaticallyApproveScopes() ||
429 prompt_.GetOAuthIssueCount() != 0U || 430 prompt_.GetOAuthIssueCount() != 0U ||
430 oauth2_info.client_id.empty() || 431 oauth2_info.client_id.empty() ||
431 permissions_->scopes().empty() || 432 permissions_->scopes().empty() ||
432 prompt_type_ == BUNDLE_INSTALL_PROMPT || 433 prompt_type_ == BUNDLE_INSTALL_PROMPT ||
433 prompt_type_ == INLINE_INSTALL_PROMPT) { 434 prompt_type_ == INLINE_INSTALL_PROMPT) {
434 ShowConfirmation(); 435 ShowConfirmation();
435 return; 436 return;
436 } 437 }
437 438
438 Profile* profile = install_ui_->browser()->profile(); 439 Profile* profile = install_ui_->profile();
439 TokenService* token_service = TokenServiceFactory::GetForProfile(profile); 440 TokenService* token_service = TokenServiceFactory::GetForProfile(profile);
440 std::vector<std::string> scopes; 441 std::vector<std::string> scopes;
441 scopes.assign(permissions_->scopes().begin(), permissions_->scopes().end()); 442 scopes.assign(permissions_->scopes().begin(), permissions_->scopes().end());
442 443
443 token_flow_.reset(new OAuth2MintTokenFlow( 444 token_flow_.reset(new OAuth2MintTokenFlow(
444 profile->GetRequestContext(), 445 profile->GetRequestContext(),
445 this, 446 this,
446 OAuth2MintTokenFlow::Parameters( 447 OAuth2MintTokenFlow::Parameters(
447 token_service->GetOAuth2LoginRefreshToken(), 448 token_service->GetOAuth2LoginRefreshToken(),
448 extension_->id(), 449 extension_->id(),
(...skipping 21 matching lines...) Expand all
470 if (permissions_) 471 if (permissions_)
471 prompt_.SetPermissions(permissions_->GetWarningMessages()); 472 prompt_.SetPermissions(permissions_->GetWarningMessages());
472 473
473 switch (prompt_type_) { 474 switch (prompt_type_) {
474 case PERMISSIONS_PROMPT: 475 case PERMISSIONS_PROMPT:
475 case RE_ENABLE_PROMPT: 476 case RE_ENABLE_PROMPT:
476 case INLINE_INSTALL_PROMPT: 477 case INLINE_INSTALL_PROMPT:
477 case INSTALL_PROMPT: { 478 case INSTALL_PROMPT: {
478 prompt_.set_extension(extension_); 479 prompt_.set_extension(extension_);
479 prompt_.set_icon(gfx::Image(icon_)); 480 prompt_.set_icon(gfx::Image(icon_));
480 ShowExtensionInstallDialog(browser_, delegate_, prompt_); 481 ShowExtensionInstallDialog(parent_, navigator_, delegate_, prompt_);
481 break; 482 break;
482 } 483 }
483 case BUNDLE_INSTALL_PROMPT: { 484 case BUNDLE_INSTALL_PROMPT: {
484 prompt_.set_bundle(bundle_); 485 prompt_.set_bundle(bundle_);
485 ShowExtensionInstallDialog(browser_, delegate_, prompt_); 486 ShowExtensionInstallDialog(parent_, navigator_, delegate_, prompt_);
486 break; 487 break;
487 } 488 }
488 default: 489 default:
489 NOTREACHED() << "Unknown message"; 490 NOTREACHED() << "Unknown message";
490 break; 491 break;
491 } 492 }
492 } 493 }
493 494
494 // static 495 // static
495 bool ExtensionInstallPrompt::ShouldAutomaticallyApproveScopes() { 496 bool ExtensionInstallPrompt::ShouldAutomaticallyApproveScopes() {
496 return !CommandLine::ForCurrentProcess()->HasSwitch( 497 return !CommandLine::ForCurrentProcess()->HasSwitch(
497 switches::kDemandUserScopeApproval); 498 switches::kDemandUserScopeApproval);
498 } 499 }
500
501 namespace chrome {
502
503 ExtensionInstallPrompt* CreateExtensionInstallPromptWithBrowser(
504 Browser* browser) {
505 // |browser| can be NULL in unit tests.
506 if (!browser)
507 return new ExtensionInstallPrompt(NULL, NULL, NULL);
508 gfx::NativeWindow parent =
509 browser->window() ? browser->window()->GetNativeWindow() : NULL;
510 return new ExtensionInstallPrompt(parent, browser, browser->profile());
511 }
512
513 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_install_prompt.h ('k') | chrome/browser/extensions/extension_install_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698