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/infobars/infobar_extension_api.h"
7 #include "base/string_util.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "base/values.h"
10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
11 #include "chrome/browser/extensions/extension_host.h"
12 #include "chrome/browser/extensions/extension_infobar_delegate.h"
13 #include "chrome/browser/extensions/extension_tab_util.h"
14 #include "chrome/browser/extensions/window_controller.h"
15 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
16 #include "chrome/browser/infobars/infobar_service.h"
17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/common/extensions/extension.h"
19 #include "chrome/common/url_constants.h"
20 #include "content/public/browser/web_contents.h"
21 #include "extensions/common/error_utils.h"
22 #include "grit/generated_resources.h"
24 using extensions::Extension
;
28 const char kHtmlPath
[] = "path";
29 const char kTabId
[] = "tabId";
30 const char kHeight
[] = "height";
34 bool InfobarsShowFunction::RunImpl() {
35 DictionaryValue
* args
;
36 EXTENSION_FUNCTION_VALIDATE(args_
->GetDictionary(0, &args
));
39 EXTENSION_FUNCTION_VALIDATE(args
->GetInteger(kTabId
, &tab_id
));
41 std::string html_path
;
42 EXTENSION_FUNCTION_VALIDATE(args
->GetString(kHtmlPath
, &html_path
));
45 if (args
->HasKey(kHeight
))
46 EXTENSION_FUNCTION_VALIDATE(args
->GetInteger(kHeight
, &height
));
48 const Extension
* extension
= GetExtension();
49 GURL url
= extension
->GetResourceURL(extension
->url(), html_path
);
51 Browser
* browser
= NULL
;
52 content::WebContents
* web_contents
= NULL
;
53 if (!ExtensionTabUtil::GetTabById(
61 error_
= extensions::ErrorUtils::FormatErrorMessage(
62 extensions::tabs_constants::kTabNotFoundError
,
63 base::IntToString(tab_id
));
67 ExtensionInfoBarDelegate::Create(
68 InfoBarService::FromWebContents(web_contents
), browser
, GetExtension(),
71 // TODO(finnur): Return the actual DOMWindow object. Bug 26463.
72 DCHECK(browser
->extension_window_controller());
73 SetResult(browser
->extension_window_controller()->CreateWindowValue());