Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / chrome / browser / extensions / extension_error_ui_default.cc
blobeec4a436adfa756870a049b196e94410cbe0a39c
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
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/extension_error_ui_default.h"
7 #include "base/logging.h"
8 #include "base/strings/string_util.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/chrome_pages.h"
14 #include "chrome/browser/ui/global_error/global_error_bubble_view_base.h"
16 namespace extensions {
18 ExtensionErrorUIDefault::ExtensionErrorUIDefault(
19 ExtensionErrorUI::Delegate* delegate)
20 : ExtensionErrorUI(delegate),
21 profile_(Profile::FromBrowserContext(delegate->GetContext())),
22 browser_(NULL),
23 global_error_(new ExtensionGlobalError(this)) {
26 ExtensionErrorUIDefault::~ExtensionErrorUIDefault() {
29 bool ExtensionErrorUIDefault::ShowErrorInBubbleView() {
30 Browser* browser =
31 chrome::FindLastActiveWithProfile(profile_, chrome::GetActiveDesktop());
32 if (!browser)
33 return false;
35 browser_ = browser;
36 global_error_->ShowBubbleView(browser);
37 return true;
40 void ExtensionErrorUIDefault::ShowExtensions() {
41 DCHECK(browser_);
42 chrome::ShowExtensions(browser_, std::string());
45 void ExtensionErrorUIDefault::Close() {
46 if (global_error_->HasShownBubbleView()) {
47 // Will end up calling into |global_error_|->OnBubbleViewDidClose,
48 // possibly synchronously.
49 global_error_->GetBubbleView()->CloseBubbleView();
53 ExtensionErrorUIDefault::ExtensionGlobalError::ExtensionGlobalError(
54 ExtensionErrorUIDefault* error_ui)
55 : error_ui_(error_ui) {
58 bool ExtensionErrorUIDefault::ExtensionGlobalError::HasMenuItem() {
59 return false;
62 int ExtensionErrorUIDefault::ExtensionGlobalError::MenuItemCommandID() {
63 NOTREACHED();
64 return 0;
67 base::string16 ExtensionErrorUIDefault::ExtensionGlobalError::MenuItemLabel() {
68 NOTREACHED();
69 return NULL;
72 void ExtensionErrorUIDefault::ExtensionGlobalError::ExecuteMenuItem(
73 Browser* browser) {
74 NOTREACHED();
77 base::string16
78 ExtensionErrorUIDefault::ExtensionGlobalError::GetBubbleViewTitle() {
79 return error_ui_->GetBubbleViewTitle();
82 std::vector<base::string16>
83 ExtensionErrorUIDefault::ExtensionGlobalError::GetBubbleViewMessages() {
84 return error_ui_->GetBubbleViewMessages();
87 base::string16 ExtensionErrorUIDefault::ExtensionGlobalError::
88 GetBubbleViewAcceptButtonLabel() {
89 return error_ui_->GetBubbleViewAcceptButtonLabel();
92 base::string16 ExtensionErrorUIDefault::ExtensionGlobalError::
93 GetBubbleViewCancelButtonLabel() {
94 return error_ui_->GetBubbleViewCancelButtonLabel();
97 void ExtensionErrorUIDefault::ExtensionGlobalError::OnBubbleViewDidClose(
98 Browser* browser) {
99 error_ui_->BubbleViewDidClose();
102 void ExtensionErrorUIDefault::ExtensionGlobalError::
103 BubbleViewAcceptButtonPressed(Browser* browser) {
104 error_ui_->BubbleViewAcceptButtonPressed();
107 void ExtensionErrorUIDefault::ExtensionGlobalError::
108 BubbleViewCancelButtonPressed(Browser* browser) {
109 error_ui_->BubbleViewCancelButtonPressed();
112 // static
113 ExtensionErrorUI* ExtensionErrorUI::Create(
114 ExtensionErrorUI::Delegate* delegate) {
115 return new ExtensionErrorUIDefault(delegate);
118 } // namespace extensions